blob: 3e690b997b29575ae4cc97a5dc4a263f507af3a5 [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Tyler Gunn45382162015-05-06 08:52:27 -070019import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070020import com.android.internal.telecom.IVideoCallback;
21import com.android.internal.telecom.IVideoProvider;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070022
Tyler Gunndee56a82016-03-23 16:06:34 -070023import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070024import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070025import android.annotation.SystemApi;
Tyler Gunnb702ef82015-05-29 11:51:53 -070026import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070027import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080028import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070029import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070030import android.os.Handler;
31import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070032import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070033import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080034import android.os.ParcelFileDescriptor;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070035import android.os.RemoteException;
Tyler Gunndee56a82016-03-23 16:06:34 -070036import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070037import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070038
Hall Liu95d55872017-01-25 17:12:49 -080039import java.io.IOException;
40import java.io.InputStreamReader;
41import java.io.OutputStreamWriter;
Santos Cordonb6939982014-06-04 20:20:58 -070042import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070043import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070044import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070045import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070046import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070047import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070048
49/**
Santos Cordon895d4b82015-06-25 16:41:48 -070050 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
51 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070052 * <p>
53 * Implementations create a custom subclass of {@code Connection} and return it to the framework
54 * as the return value of
55 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
56 * or
57 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
58 * Implementations are then responsible for updating the state of the {@code Connection}, and
59 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
60 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070061 * <p>
62 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
63 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
64 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
65 * {@code Connection} instance.
66 * <p>
67 * Basic call support requires overriding the following methods: {@link #onAnswer()},
68 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
69 * <p>
70 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
71 * {@link #onUnhold()} methods should be overridden to provide hold support for the
72 * {@code Connection}.
73 * <p>
74 * Where a {@code Connection} supports a variation of video calling (e.g. the
75 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
76 * to support answering a call as a video call.
77 * <p>
78 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
79 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
80 * support for pulling the external call.
81 * <p>
82 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
83 * overridden.
84 * <p>
85 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
86 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
87 * for example, call events from a {@link InCallService} are handled,
88 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
89 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
90 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
91 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -070092 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070093public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070094
Santos Cordon895d4b82015-06-25 16:41:48 -070095 /**
96 * The connection is initializing. This is generally the first state for a {@code Connection}
97 * returned by a {@link ConnectionService}.
98 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070099 public static final int STATE_INITIALIZING = 0;
100
Santos Cordon895d4b82015-06-25 16:41:48 -0700101 /**
102 * The connection is new and not connected.
103 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700104 public static final int STATE_NEW = 1;
105
Santos Cordon895d4b82015-06-25 16:41:48 -0700106 /**
107 * An incoming connection is in the ringing state. During this state, the user's ringer or
108 * vibration feature will be activated.
109 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700110 public static final int STATE_RINGING = 2;
111
Santos Cordon895d4b82015-06-25 16:41:48 -0700112 /**
113 * An outgoing connection is in the dialing state. In this state the other party has not yet
114 * answered the call and the user traditionally hears a ringback tone.
115 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700116 public static final int STATE_DIALING = 3;
117
Santos Cordon895d4b82015-06-25 16:41:48 -0700118 /**
119 * A connection is active. Both parties are connected to the call and can actively communicate.
120 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700121 public static final int STATE_ACTIVE = 4;
122
Santos Cordon895d4b82015-06-25 16:41:48 -0700123 /**
124 * A connection is on hold.
125 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700126 public static final int STATE_HOLDING = 5;
127
Santos Cordon895d4b82015-06-25 16:41:48 -0700128 /**
129 * A connection has been disconnected. This is the final state once the user has been
130 * disconnected from a call either locally, remotely or by an error in the service.
131 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700132 public static final int STATE_DISCONNECTED = 6;
133
Santos Cordon895d4b82015-06-25 16:41:48 -0700134 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700135 * The state of an external connection which is in the process of being pulled from a remote
136 * device to the local device.
137 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700138 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700139 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
140 */
141 public static final int STATE_PULLING_CALL = 7;
142
143 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700144 * Connection can currently be put on hold or unheld. This is distinct from
145 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
146 * it does not at the moment support the function. This can be true while the call is in the
147 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
148 * display a disabled 'hold' button.
149 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800150 public static final int CAPABILITY_HOLD = 0x00000001;
151
152 /** Connection supports the hold feature. */
153 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
154
155 /**
156 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
157 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
158 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
159 * capability allows a merge button to be shown while the conference is in the foreground
160 * of the in-call UI.
161 * <p>
162 * This is only intended for use by a {@link Conference}.
163 */
164 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
165
166 /**
167 * Connections within a conference can be swapped between foreground and background.
168 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
169 * <p>
170 * This is only intended for use by a {@link Conference}.
171 */
172 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
173
174 /**
175 * @hide
176 */
177 public static final int CAPABILITY_UNUSED = 0x00000010;
178
179 /** Connection supports responding via text option. */
180 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
181
182 /** Connection can be muted. */
183 public static final int CAPABILITY_MUTE = 0x00000040;
184
185 /**
186 * Connection supports conference management. This capability only applies to
187 * {@link Conference}s which can have {@link Connection}s as children.
188 */
189 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
190
191 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700192 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800193 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700194 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800195
196 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700197 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800198 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700199 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800200
201 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700202 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800203 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700204 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700205 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800206
207 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700208 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800209 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700210 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
211
212 /**
213 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700214 */
215 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
216
217 /**
218 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700219 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700220 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700221 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800222
223 /**
224 * Connection is able to be separated from its parent {@code Conference}, if any.
225 */
226 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
227
228 /**
229 * Connection is able to be individually disconnected when in a {@code Conference}.
230 */
231 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
232
233 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700234 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800235 * @hide
236 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700237 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800238
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700239 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700240 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700241 * @hide
242 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700243 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700244
245 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700246 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700247 * @hide
248 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700249 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700250
Tyler Gunn068085b2015-02-06 13:56:52 -0800251 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700252 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800253 * @hide
254 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700255 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800256
Tyler Gunn96d6c402015-03-18 12:39:23 -0700257 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500258 * Speed up audio setup for MT call.
259 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700260 */
261 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800262
Rekha Kumar07366812015-03-24 16:42:31 -0700263 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700264 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700265 */
266 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
267
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700268 /**
269 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700270 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700271 */
272 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
273
Tyler Gunnd4091732015-06-29 09:15:37 -0700274 /**
275 * For a conference, indicates the conference will not have child connections.
276 * <p>
277 * An example of a conference with child connections is a GSM conference call, where the radio
278 * retains connections to the individual participants of the conference. Another example is an
279 * IMS conference call where conference event package functionality is supported; in this case
280 * the conference server ensures the radio is aware of the participants in the conference, which
281 * are represented by child connections.
282 * <p>
283 * An example of a conference with no child connections is an IMS conference call with no
284 * conference event package support. Such a conference is represented by the radio as a single
285 * connection to the IMS conference server.
286 * <p>
287 * Indicating whether a conference has children or not is important to help user interfaces
288 * visually represent a conference. A conference with no children, for example, will have the
289 * conference connection shown in the list of calls on a Bluetooth device, where if the
290 * conference has children, only the children will be shown in the list of calls on a Bluetooth
291 * device.
292 * @hide
293 */
294 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
295
Bryce Lee81901682015-08-28 16:38:02 -0700296 /**
297 * Indicates that the connection itself wants to handle any sort of reply response, rather than
298 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700299 */
300 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
301
Tyler Gunnf97a0092016-01-19 15:59:34 -0800302 /**
303 * When set, prevents a video call from being downgraded to an audio-only call.
304 * <p>
305 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
306 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
307 * downgraded from a video call back to a VideoState of
308 * {@link VideoProfile#STATE_AUDIO_ONLY}.
309 * <p>
310 * Intuitively, a call which can be downgraded to audio should also have local and remote
311 * video
312 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
313 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
314 */
315 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
316
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700317 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700318 * When set for an external connection, indicates that this {@code Connection} can be pulled
319 * from a remote device to the current device.
320 * <p>
321 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
322 * is set.
323 */
324 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
325
326 //**********************************************************************************************
327 // Next CAPABILITY value: 0x02000000
328 //**********************************************************************************************
329
330 /**
331 * Indicates that the current device callback number should be shown.
332 *
333 * @hide
334 */
Hall Liu25c7c4d2016-08-30 13:41:02 -0700335 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700336
337 /**
338 * Whether the call is a generic conference, where we do not know the precise state of
339 * participants in the conference (eg. on CDMA).
340 *
341 * @hide
342 */
343 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
344
345 /**
346 * Connection is using high definition audio.
347 * @hide
348 */
349 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
350
351 /**
352 * Connection is using WIFI.
353 * @hide
354 */
355 public static final int PROPERTY_WIFI = 1<<3;
356
357 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700358 * When set, indicates that the {@code Connection} does not actually exist locally for the
359 * {@link ConnectionService}.
360 * <p>
361 * Consider, for example, a scenario where a user has two devices with the same phone number.
362 * When a user places a call on one devices, the telephony stack can represent that call on the
363 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700364 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700365 * <p>
366 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
367 * external connections. Only those {@link InCallService}s which have the
368 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
369 * manifest will see external connections.
370 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700371 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700372
Brad Ebinger15847072016-05-18 11:08:36 -0700373 /**
374 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
375 */
376 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700377
Hall Liu9f332c72016-07-14 15:37:37 -0700378 /**
379 * Indicates that the connection represents a downgraded IMS conference.
380 * @hide
381 */
382 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
383
Tyler Gunnf5035432017-01-09 09:43:12 -0800384 /**
385 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
386 * {@link ConnectionService}.
387 * <p>
388 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
389 */
390 public static final int PROPERTY_SELF_MANAGED = 1<<7;
391
Hall Liu95d55872017-01-25 17:12:49 -0800392 /**
393 * When set, indicates that a connection has an active RTT session associated with it.
394 * @hide
395 */
396 public static final int PROPERTY_IS_RTT = 1 << 8;
397
Tyler Gunn96d6c402015-03-18 12:39:23 -0700398 //**********************************************************************************************
Hall Liu95d55872017-01-25 17:12:49 -0800399 // Next PROPERTY value: 1<<9
Tyler Gunn96d6c402015-03-18 12:39:23 -0700400 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800401
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700402 /**
403 * Connection extra key used to store the last forwarded number associated with the current
404 * connection. Used to communicate to the user interface that the connection was forwarded via
405 * the specified number.
406 */
407 public static final String EXTRA_LAST_FORWARDED_NUMBER =
408 "android.telecom.extra.LAST_FORWARDED_NUMBER";
409
410 /**
411 * Connection extra key used to store a child number associated with the current connection.
412 * Used to communicate to the user interface that the connection was received via
413 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
414 * address.
415 */
416 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
417
418 /**
419 * Connection extra key used to store the subject for an incoming call. The user interface can
420 * query this extra and display its contents for incoming calls. Will only be used if the
421 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
422 */
423 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
424
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800425 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700426 * Boolean connection extra key set on a {@link Connection} in
427 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
428 * current active foreground call to be dropped.
429 */
430 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
431 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
432
433 /**
Hall Liu10208662016-06-15 17:55:00 -0700434 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700435 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700436 * @hide
437 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700438 public static final String EXTRA_DISABLE_ADD_CALL =
439 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700440
441 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700442 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
443 * original Connection ID associated with the connection. Used in
444 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
445 * connection/conference added via
446 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
447 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
448 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
449 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
450 * be a way to ensure that we don't add the connection again as a duplicate.
451 * <p>
452 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
453 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
454 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
455 * in a new {@link Connection} which it adds to Telecom via
456 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
457 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
458 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
459 * ID it originally referred to the connection as. Thus Telecom needs to know that the
460 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
461 * @hide
462 */
463 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
464 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
465
466 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800467 * Connection event used to inform Telecom that it should play the on hold tone. This is used
468 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700469 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800470 * @hide
471 */
472 public static final String EVENT_ON_HOLD_TONE_START =
473 "android.telecom.event.ON_HOLD_TONE_START";
474
475 /**
476 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
477 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700478 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800479 * @hide
480 */
481 public static final String EVENT_ON_HOLD_TONE_END =
482 "android.telecom.event.ON_HOLD_TONE_END";
483
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700484 /**
485 * Connection event used to inform {@link InCallService}s when pulling of an external call has
486 * failed. The user interface should inform the user of the error.
487 * <p>
488 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
489 * API is called on a {@link Call} with the properties
490 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
491 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
492 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700493 * <p>
494 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
495 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700496 */
497 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
498
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700499 /**
500 * Connection event used to inform {@link InCallService}s when the merging of two calls has
501 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700502 * <p>
503 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
504 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700505 */
506 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
507
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700508 /**
509 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
510 * the remote party.
511 * <p>
512 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
513 * call is being held locally on the device. When a capable {@link ConnectionService} receives
514 * signalling to indicate that the remote party has put the call on hold, it can send this
515 * connection event.
516 * @hide
517 */
518 public static final String EVENT_CALL_REMOTELY_HELD =
519 "android.telecom.event.CALL_REMOTELY_HELD";
520
521 /**
522 * Connection event used to inform {@link InCallService}s when a call which was remotely held
523 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
524 * <p>
525 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
526 * call is being held locally on the device. When a capable {@link ConnectionService} receives
527 * signalling to indicate that the remote party has taken the call off hold, it can send this
528 * connection event.
529 * @hide
530 */
531 public static final String EVENT_CALL_REMOTELY_UNHELD =
532 "android.telecom.event.CALL_REMOTELY_UNHELD";
533
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700534 // Flag controlling whether PII is emitted into the logs
535 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
536
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800537 /**
538 * Whether the given capabilities support the specified capability.
539 *
540 * @param capabilities A capability bit field.
541 * @param capability The capability to check capabilities for.
542 * @return Whether the specified capability is supported.
543 * @hide
544 */
545 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800546 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800547 }
548
549 /**
550 * Whether the capabilities of this {@code Connection} supports the specified capability.
551 *
552 * @param capability The capability to check capabilities for.
553 * @return Whether the specified capability is supported.
554 * @hide
555 */
556 public boolean can(int capability) {
557 return can(mConnectionCapabilities, capability);
558 }
559
560 /**
561 * Removes the specified capability from the set of capabilities of this {@code Connection}.
562 *
563 * @param capability The capability to remove from the set.
564 * @hide
565 */
566 public void removeCapability(int capability) {
567 mConnectionCapabilities &= ~capability;
568 }
569
570 /**
571 * Adds the specified capability to the set of capabilities of this {@code Connection}.
572 *
573 * @param capability The capability to add to the set.
574 * @hide
575 */
576 public void addCapability(int capability) {
577 mConnectionCapabilities |= capability;
578 }
579
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700580 /**
581 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
582 *
583 * @param capabilities A capability bit field.
584 * @return A human readable string representation.
585 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800586 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700587 return capabilitiesToStringInternal(capabilities, true /* isLong */);
588 }
589
590 /**
591 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
592 * string.
593 *
594 * @param capabilities A capability bit field.
595 * @return A human readable string representation.
596 * @hide
597 */
598 public static String capabilitiesToStringShort(int capabilities) {
599 return capabilitiesToStringInternal(capabilities, false /* isLong */);
600 }
601
602 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800603 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700604 builder.append("[");
605 if (isLong) {
606 builder.append("Capabilities:");
607 }
608
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800609 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700610 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800611 }
612 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700613 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800614 }
615 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700616 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800617 }
618 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700619 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800620 }
621 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700622 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800623 }
624 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700625 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800626 }
627 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700628 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800629 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700630 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700631 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700632 }
633 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700634 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700635 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700636 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700637 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800638 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700639 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700640 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700641 }
642 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700643 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700644 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700645 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700646 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800647 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800648 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700649 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800650 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500651 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700652 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500653 }
Rekha Kumar07366812015-03-24 16:42:31 -0700654 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700655 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700656 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700657 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700658 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700659 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700660 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700661 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700662 }
Bryce Lee81901682015-08-28 16:38:02 -0700663 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700664 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700665 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700666 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700667 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700668 }
Bryce Lee81901682015-08-28 16:38:02 -0700669
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800670 builder.append("]");
671 return builder.toString();
672 }
673
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700674 /**
675 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
676 *
677 * @param properties A property bit field.
678 * @return A human readable string representation.
679 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700680 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700681 return propertiesToStringInternal(properties, true /* isLong */);
682 }
683
684 /**
685 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
686 *
687 * @param properties A property bit field.
688 * @return A human readable string representation.
689 * @hide
690 */
691 public static String propertiesToStringShort(int properties) {
692 return propertiesToStringInternal(properties, false /* isLong */);
693 }
694
695 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700696 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700697 builder.append("[");
698 if (isLong) {
699 builder.append("Properties:");
700 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700701
Tyler Gunnf5035432017-01-09 09:43:12 -0800702 if (can(properties, PROPERTY_SELF_MANAGED)) {
703 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
704 }
705
Hall Liu25c7c4d2016-08-30 13:41:02 -0700706 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
707 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700708 }
709
710 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700711 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700712 }
713
714 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700715 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700716 }
717
718 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700719 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700720 }
721
722 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700723 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700724 }
725
Brad Ebinger15847072016-05-18 11:08:36 -0700726 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700727 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700728 }
729
Tyler Gunn720c6642016-03-22 09:02:47 -0700730 builder.append("]");
731 return builder.toString();
732 }
733
Sailesh Nepal091768c2014-06-30 15:15:23 -0700734 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700735 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700736 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700737 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700738 public void onCallerDisplayNameChanged(
739 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700740 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700741 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700742 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800743 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700744 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700745 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800746 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700747 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800748 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700749 public void onVideoProviderChanged(
750 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700751 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
752 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800753 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700754 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700755 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700756 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800757 public void onConferenceParticipantsChanged(Connection c,
758 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800759 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700760 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700761 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700762 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700763 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700764 /** @hide */
765 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Tyler Gunnf5035432017-01-09 09:43:12 -0800766 public void onAudioRouteChanged(Connection c, int audioRoute) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700767 }
768
Tyler Gunnb702ef82015-05-29 11:51:53 -0700769 /**
Hall Liu95d55872017-01-25 17:12:49 -0800770 * Provides methods to read and write RTT data to/from the in-call app.
771 * @hide
772 */
773 public static final class RttTextStream {
774 private static final int READ_BUFFER_SIZE = 1000;
775 private final InputStreamReader mPipeFromInCall;
776 private final OutputStreamWriter mPipeToInCall;
777 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
778
779 /**
780 * @hide
781 */
782 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
783 mPipeFromInCall = new InputStreamReader(
784 new ParcelFileDescriptor.AutoCloseInputStream(fromInCall));
785 mPipeToInCall = new OutputStreamWriter(
786 new ParcelFileDescriptor.AutoCloseOutputStream(toInCall));
787 }
788
789 /**
790 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
791 * RTT transmits text in real-time, this method should be called as often as text snippets
792 * are received from the remote user, even if it is only one character.
793 *
794 * This method is not thread-safe -- calling it from multiple threads simultaneously may
795 * lead to interleaved text.
796 * @param input The message to send to the in-call app.
797 */
798 public void write(String input) throws IOException {
799 mPipeToInCall.write(input);
800 mPipeToInCall.flush();
801 }
802
803
804 /**
805 * Reads a string from the in-call app, blocking if there is no data available. Returns
806 * {@code null} if the RTT conversation has been terminated and there is no further data
807 * to read.
808 *
809 * This method is not thread-safe -- calling it from multiple threads simultaneously may
810 * lead to interleaved text.
811 * @return A string containing text entered by the user, or {@code null} if the
812 * conversation has been terminated or if there was an error while reading.
813 */
814 public String read() {
815 try {
816 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
817 if (numRead < 0) {
818 return null;
819 }
820 return new String(mReadBuffer, 0, numRead);
821 } catch (IOException e) {
822 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
823 return null;
824 }
825 }
826 }
827
828 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700829 * Provides a means of controlling the video session associated with a {@link Connection}.
830 * <p>
831 * Implementations create a custom subclass of {@link VideoProvider} and the
832 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
833 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
834 * should set the {@link VideoProvider}.
835 * <p>
836 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
837 * {@link InCallService} implementations to issue requests related to the video session;
838 * it provides a means for the {@link ConnectionService} to report events and information
839 * related to the video session to Telecom and the {@link InCallService} implementations.
840 * <p>
841 * {@link InCallService} implementations interact with the {@link VideoProvider} via
842 * {@link android.telecom.InCallService.VideoCall}.
843 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700844 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700845 /**
846 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700847 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700848 */
849 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700850
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700851 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700852 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
853 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700854 */
855 public static final int SESSION_EVENT_RX_RESUME = 2;
856
857 /**
858 * Video transmission has begun. This occurs after a negotiated start of video transmission
859 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700860 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700861 */
862 public static final int SESSION_EVENT_TX_START = 3;
863
864 /**
865 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
866 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700867 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700868 */
869 public static final int SESSION_EVENT_TX_STOP = 4;
870
871 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800872 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -0700873 * this as a cue to inform the user the camera is not available.
874 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700875 */
876 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
877
878 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700879 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800880 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -0700881 * the camera has become available again.
882 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700883 */
884 public static final int SESSION_EVENT_CAMERA_READY = 6;
885
886 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800887 * Session event raised by Telecom when
888 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
889 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
890 * @see #handleCallSessionEvent(int)
891 */
892 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
893
894 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700895 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700896 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700897 */
898 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
899
900 /**
901 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700902 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700903 */
904 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
905
906 /**
907 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700908 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700909 */
910 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
911
Rekha Kumar07366812015-03-24 16:42:31 -0700912 /**
913 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700914 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700915 */
916 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
917
918 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700919 * Session modify request rejected by remote user.
920 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700921 */
922 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
923
Tyler Gunn75958422015-04-15 14:23:42 -0700924 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700925 private static final int MSG_SET_CAMERA = 2;
926 private static final int MSG_SET_PREVIEW_SURFACE = 3;
927 private static final int MSG_SET_DISPLAY_SURFACE = 4;
928 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
929 private static final int MSG_SET_ZOOM = 6;
930 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
931 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
932 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800933 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700934 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700935 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700936
Tyler Gunn6f657ee2016-09-02 09:55:25 -0700937 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
938 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
939 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
940 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
941 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
942 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800943 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
944 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -0700945 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
946
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700947 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700948 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700949
950 /**
951 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700952 *
953 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
954 * load factor before resizing, 1 means we only expect a single thread to
955 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700956 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700957 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
958 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700959
960 /**
961 * Default handler used to consolidate binder method calls onto a single thread.
962 */
963 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700964 public VideoProviderHandler() {
965 super();
966 }
967
968 public VideoProviderHandler(Looper looper) {
969 super(looper);
970 }
971
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700972 @Override
973 public void handleMessage(Message msg) {
974 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700975 case MSG_ADD_VIDEO_CALLBACK: {
976 IBinder binder = (IBinder) msg.obj;
977 IVideoCallback callback = IVideoCallback.Stub
978 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700979 if (callback == null) {
980 Log.w(this, "addVideoProvider - skipped; callback is null.");
981 break;
982 }
983
Tyler Gunn75958422015-04-15 14:23:42 -0700984 if (mVideoCallbacks.containsKey(binder)) {
985 Log.i(this, "addVideoProvider - skipped; already present.");
986 break;
987 }
988 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700989 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700990 }
991 case MSG_REMOVE_VIDEO_CALLBACK: {
992 IBinder binder = (IBinder) msg.obj;
993 IVideoCallback callback = IVideoCallback.Stub
994 .asInterface((IBinder) msg.obj);
995 if (!mVideoCallbacks.containsKey(binder)) {
996 Log.i(this, "removeVideoProvider - skipped; not present.");
997 break;
998 }
999 mVideoCallbacks.remove(binder);
1000 break;
1001 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001002 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001003 {
1004 SomeArgs args = (SomeArgs) msg.obj;
1005 try {
1006 onSetCamera((String) args.arg1);
1007 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
1008 args.argi2);
1009 } finally {
1010 args.recycle();
1011 }
1012 }
1013 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001014 case MSG_SET_PREVIEW_SURFACE:
1015 onSetPreviewSurface((Surface) msg.obj);
1016 break;
1017 case MSG_SET_DISPLAY_SURFACE:
1018 onSetDisplaySurface((Surface) msg.obj);
1019 break;
1020 case MSG_SET_DEVICE_ORIENTATION:
1021 onSetDeviceOrientation(msg.arg1);
1022 break;
1023 case MSG_SET_ZOOM:
1024 onSetZoom((Float) msg.obj);
1025 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001026 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1027 SomeArgs args = (SomeArgs) msg.obj;
1028 try {
1029 onSendSessionModifyRequest((VideoProfile) args.arg1,
1030 (VideoProfile) args.arg2);
1031 } finally {
1032 args.recycle();
1033 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001034 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001035 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001036 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1037 onSendSessionModifyResponse((VideoProfile) msg.obj);
1038 break;
1039 case MSG_REQUEST_CAMERA_CAPABILITIES:
1040 onRequestCameraCapabilities();
1041 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001042 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1043 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001044 break;
1045 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001046 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001047 break;
1048 default:
1049 break;
1050 }
1051 }
1052 }
1053
1054 /**
1055 * IVideoProvider stub implementation.
1056 */
1057 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001058 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001059 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001060 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1061 }
1062
1063 public void removeVideoCallback(IBinder videoCallbackBinder) {
1064 mMessageHandler.obtainMessage(
1065 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001066 }
1067
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001068 public void setCamera(String cameraId, String callingPackageName) {
1069 SomeArgs args = SomeArgs.obtain();
1070 args.arg1 = cameraId;
1071 // Propagate the calling package; originally determined in
1072 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1073 // process.
1074 args.arg2 = callingPackageName;
1075 // Pass along the uid and pid of the calling app; this gets lost when we put the
1076 // message onto the handler. These are required for Telecom to perform a permission
1077 // check to see if the calling app is able to use the camera.
1078 args.argi1 = Binder.getCallingUid();
1079 args.argi2 = Binder.getCallingPid();
1080 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001081 }
1082
1083 public void setPreviewSurface(Surface surface) {
1084 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1085 }
1086
1087 public void setDisplaySurface(Surface surface) {
1088 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1089 }
1090
1091 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001092 mMessageHandler.obtainMessage(
1093 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001094 }
1095
1096 public void setZoom(float value) {
1097 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1098 }
1099
Tyler Gunn45382162015-05-06 08:52:27 -07001100 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1101 SomeArgs args = SomeArgs.obtain();
1102 args.arg1 = fromProfile;
1103 args.arg2 = toProfile;
1104 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001105 }
1106
1107 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1108 mMessageHandler.obtainMessage(
1109 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1110 }
1111
1112 public void requestCameraCapabilities() {
1113 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1114 }
1115
1116 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001117 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001118 }
1119
Yorke Lee32f24732015-05-12 16:18:03 -07001120 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001121 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1122 }
1123 }
1124
1125 public VideoProvider() {
1126 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001127 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001128 }
1129
1130 /**
1131 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1132 *
1133 * @param looper The looper.
1134 * @hide
1135 */
1136 public VideoProvider(Looper looper) {
1137 mBinder = new VideoProvider.VideoProviderBinder();
1138 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001139 }
1140
1141 /**
1142 * Returns binder object which can be used across IPC methods.
1143 * @hide
1144 */
1145 public final IVideoProvider getInterface() {
1146 return mBinder;
1147 }
1148
1149 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001150 * Sets the camera to be used for the outgoing video.
1151 * <p>
1152 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1153 * camera via
1154 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1155 * <p>
1156 * Sent from the {@link InCallService} via
1157 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001158 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001159 * @param cameraId The id of the camera (use ids as reported by
1160 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001161 */
1162 public abstract void onSetCamera(String cameraId);
1163
1164 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001165 * Sets the camera to be used for the outgoing video.
1166 * <p>
1167 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1168 * camera via
1169 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1170 * <p>
1171 * This prototype is used internally to ensure that the calling package name, UID and PID
1172 * are sent to Telecom so that can perform a camera permission check on the caller.
1173 * <p>
1174 * Sent from the {@link InCallService} via
1175 * {@link InCallService.VideoCall#setCamera(String)}.
1176 *
1177 * @param cameraId The id of the camera (use ids as reported by
1178 * {@link CameraManager#getCameraIdList()}).
1179 * @param callingPackageName The AppOpps package name of the caller.
1180 * @param callingUid The UID of the caller.
1181 * @param callingPid The PID of the caller.
1182 * @hide
1183 */
1184 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
1185 int callingPid) {}
1186
1187 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001188 * Sets the surface to be used for displaying a preview of what the user's camera is
1189 * currently capturing. When video transmission is enabled, this is the video signal which
1190 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001191 * <p>
1192 * Sent from the {@link InCallService} via
1193 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001194 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001195 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001196 */
1197 public abstract void onSetPreviewSurface(Surface surface);
1198
1199 /**
1200 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001201 * <p>
1202 * Sent from the {@link InCallService} via
1203 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001204 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001205 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001206 */
1207 public abstract void onSetDisplaySurface(Surface surface);
1208
1209 /**
1210 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1211 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001212 * <p>
1213 * Sent from the {@link InCallService} via
1214 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001215 *
1216 * @param rotation The device orientation, in degrees.
1217 */
1218 public abstract void onSetDeviceOrientation(int rotation);
1219
1220 /**
1221 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001222 * <p>
1223 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001224 *
1225 * @param value The camera zoom ratio.
1226 */
1227 public abstract void onSetZoom(float value);
1228
1229 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001230 * Issues a request to modify the properties of the current video session.
1231 * <p>
1232 * Example scenarios include: requesting an audio-only call to be upgraded to a
1233 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1234 * when the {@link InCallService} is no longer the foreground application.
1235 * <p>
1236 * If the {@link VideoProvider} determines a request to be invalid, it should call
1237 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1238 * invalid request back to the {@link InCallService}.
1239 * <p>
1240 * Where a request requires confirmation from the user of the peer device, the
1241 * {@link VideoProvider} must communicate the request to the peer device and handle the
1242 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1243 * is used to inform the {@link InCallService} of the result of the request.
1244 * <p>
1245 * Sent from the {@link InCallService} via
1246 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001247 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001248 * @param fromProfile The video profile prior to the request.
1249 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001250 */
Tyler Gunn45382162015-05-06 08:52:27 -07001251 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1252 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001253
Tyler Gunnb702ef82015-05-29 11:51:53 -07001254 /**
1255 * Provides a response to a request to change the current video session properties.
1256 * <p>
1257 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1258 * video call, could decline the request and keep the call as audio-only.
1259 * In such a scenario, the {@code responseProfile} would have a video state of
1260 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1261 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1262 * <p>
1263 * Sent from the {@link InCallService} via
1264 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1265 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1266 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001267 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001268 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001269 */
1270 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1271
1272 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001273 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1274 * <p>
1275 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1276 * camera via
1277 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1278 * <p>
1279 * Sent from the {@link InCallService} via
1280 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001281 */
1282 public abstract void onRequestCameraCapabilities();
1283
1284 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001285 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1286 * video component of the current {@link Connection}.
1287 * <p>
1288 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1289 * via {@link VideoProvider#setCallDataUsage(long)}.
1290 * <p>
1291 * Sent from the {@link InCallService} via
1292 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001293 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001294 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001295
1296 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001297 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1298 * the peer device when the video signal is paused.
1299 * <p>
1300 * Sent from the {@link InCallService} via
1301 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001302 *
1303 * @param uri URI of image to display.
1304 */
Yorke Lee32f24732015-05-12 16:18:03 -07001305 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001306
1307 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001308 * Used to inform listening {@link InCallService} implementations when the
1309 * {@link VideoProvider} receives a session modification request.
1310 * <p>
1311 * Received by the {@link InCallService} via
1312 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001313 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001314 * @param videoProfile The requested video profile.
1315 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001316 */
1317 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001318 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001319 for (IVideoCallback callback : mVideoCallbacks.values()) {
1320 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001321 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001322 } catch (RemoteException ignored) {
1323 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001324 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001325 }
1326 }
1327 }
1328
1329 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001330 * Used to inform listening {@link InCallService} implementations when the
1331 * {@link VideoProvider} receives a response to a session modification request.
1332 * <p>
1333 * Received by the {@link InCallService} via
1334 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1335 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001336 *
1337 * @param status Status of the session modify request. Valid values are
1338 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1339 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001340 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1341 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1342 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1343 * @param requestedProfile The original request which was sent to the peer device.
1344 * @param responseProfile The actual profile changes agreed to by the peer device.
1345 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001346 */
1347 public void receiveSessionModifyResponse(int status,
1348 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001349 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001350 for (IVideoCallback callback : mVideoCallbacks.values()) {
1351 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001352 callback.receiveSessionModifyResponse(status, requestedProfile,
1353 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001354 } catch (RemoteException ignored) {
1355 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001356 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001357 }
1358 }
1359 }
1360
1361 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001362 * Used to inform listening {@link InCallService} implementations when the
1363 * {@link VideoProvider} reports a call session event.
1364 * <p>
1365 * Received by the {@link InCallService} via
1366 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001367 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001368 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1369 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1370 * {@link VideoProvider#SESSION_EVENT_TX_START},
1371 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1372 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001373 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1374 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001375 */
1376 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001377 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001378 for (IVideoCallback callback : mVideoCallbacks.values()) {
1379 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001380 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001381 } catch (RemoteException ignored) {
1382 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001383 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001384 }
1385 }
1386 }
1387
1388 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001389 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1390 * peer's video have changed.
1391 * <p>
1392 * This could occur if, for example, the peer rotates their device, changing the aspect
1393 * ratio of the video, or if the user switches between the back and front cameras.
1394 * <p>
1395 * Received by the {@link InCallService} via
1396 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001397 *
1398 * @param width The updated peer video width.
1399 * @param height The updated peer video height.
1400 */
1401 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001402 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001403 for (IVideoCallback callback : mVideoCallbacks.values()) {
1404 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001405 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001406 } catch (RemoteException ignored) {
1407 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001408 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001409 }
1410 }
1411 }
1412
1413 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001414 * Used to inform listening {@link InCallService} implementations when the data usage of the
1415 * video associated with the current {@link Connection} has changed.
1416 * <p>
1417 * This could be in response to a preview request via
1418 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001419 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1420 * 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 -07001421 * <p>
1422 * Received by the {@link InCallService} via
1423 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001424 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001425 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1426 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001427 */
Yorke Lee32f24732015-05-12 16:18:03 -07001428 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001429 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001430 for (IVideoCallback callback : mVideoCallbacks.values()) {
1431 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001432 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001433 } catch (RemoteException ignored) {
1434 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001435 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001436 }
1437 }
1438 }
1439
1440 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001441 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001442 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001443 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001444 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1445 * @hide
1446 */
1447 public void changeCallDataUsage(long dataUsage) {
1448 setCallDataUsage(dataUsage);
1449 }
1450
1451 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001452 * Used to inform listening {@link InCallService} implementations when the capabilities of
1453 * the current camera have changed.
1454 * <p>
1455 * The {@link VideoProvider} should call this in response to
1456 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1457 * changed via {@link VideoProvider#onSetCamera(String)}.
1458 * <p>
1459 * Received by the {@link InCallService} via
1460 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1461 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001462 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001463 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001464 */
Yorke Lee400470f2015-05-12 13:31:25 -07001465 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001466 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001467 for (IVideoCallback callback : mVideoCallbacks.values()) {
1468 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001469 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001470 } catch (RemoteException ignored) {
1471 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001472 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001473 }
1474 }
1475 }
Rekha Kumar07366812015-03-24 16:42:31 -07001476
1477 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001478 * Used to inform listening {@link InCallService} implementations when the video quality
1479 * of the call has changed.
1480 * <p>
1481 * Received by the {@link InCallService} via
1482 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001483 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001484 * @param videoQuality The updated video quality. Valid values:
1485 * {@link VideoProfile#QUALITY_HIGH},
1486 * {@link VideoProfile#QUALITY_MEDIUM},
1487 * {@link VideoProfile#QUALITY_LOW},
1488 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001489 */
1490 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001491 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001492 for (IVideoCallback callback : mVideoCallbacks.values()) {
1493 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001494 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001495 } catch (RemoteException ignored) {
1496 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001497 }
Rekha Kumar07366812015-03-24 16:42:31 -07001498 }
1499 }
1500 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001501
1502 /**
1503 * Returns a string representation of a call session event.
1504 *
1505 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1506 * @return String representation of the call session event.
1507 * @hide
1508 */
1509 public static String sessionEventToString(int event) {
1510 switch (event) {
1511 case SESSION_EVENT_CAMERA_FAILURE:
1512 return SESSION_EVENT_CAMERA_FAILURE_STR;
1513 case SESSION_EVENT_CAMERA_READY:
1514 return SESSION_EVENT_CAMERA_READY_STR;
1515 case SESSION_EVENT_RX_PAUSE:
1516 return SESSION_EVENT_RX_PAUSE_STR;
1517 case SESSION_EVENT_RX_RESUME:
1518 return SESSION_EVENT_RX_RESUME_STR;
1519 case SESSION_EVENT_TX_START:
1520 return SESSION_EVENT_TX_START_STR;
1521 case SESSION_EVENT_TX_STOP:
1522 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001523 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1524 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001525 default:
1526 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1527 }
1528 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001529 }
1530
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001531 private final Listener mConnectionDeathListener = new Listener() {
1532 @Override
1533 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001534 if (mConferenceables.remove(c)) {
1535 fireOnConferenceableConnectionsChanged();
1536 }
1537 }
1538 };
1539
1540 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1541 @Override
1542 public void onDestroyed(Conference c) {
1543 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001544 fireOnConferenceableConnectionsChanged();
1545 }
1546 }
1547 };
1548
Jay Shrauner229e3822014-08-15 09:23:07 -07001549 /**
1550 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1551 * load factor before resizing, 1 means we only expect a single thread to
1552 * access the map so make only a single shard
1553 */
1554 private final Set<Listener> mListeners = Collections.newSetFromMap(
1555 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001556 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1557 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001558 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001559
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001560 // The internal telecom call ID associated with this connection.
1561 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001562 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001563 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001564 private Uri mAddress;
1565 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001566 private String mCallerDisplayName;
1567 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001568 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001569 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001570 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001571 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001572 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001573 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001574 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001575 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001576 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001577 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001578 private Conference mConference;
1579 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001580 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001581 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001582
1583 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001584 * Tracks the key set for the extras bundle provided on the last invocation of
1585 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1586 * keys which were set previously but are no longer present in the replacement Bundle.
1587 */
1588 private Set<String> mPreviousExtraKeys;
1589
1590 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001591 * Create a new Connection.
1592 */
Santos Cordonf2951102014-07-20 19:06:29 -07001593 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001594
1595 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001596 * Returns the Telecom internal call ID associated with this connection. Should only be used
1597 * for debugging and tracing purposes.
1598 *
1599 * @return The Telecom call ID.
1600 * @hide
1601 */
1602 public final String getTelecomCallId() {
1603 return mTelecomCallId;
1604 }
1605
1606 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001607 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001608 */
Andrew Lee100e2932014-09-08 15:34:24 -07001609 public final Uri getAddress() {
1610 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001611 }
1612
1613 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001614 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001615 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001616 */
Andrew Lee100e2932014-09-08 15:34:24 -07001617 public final int getAddressPresentation() {
1618 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001619 }
1620
1621 /**
1622 * @return The caller display name (CNAP).
1623 */
1624 public final String getCallerDisplayName() {
1625 return mCallerDisplayName;
1626 }
1627
1628 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001629 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001630 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001631 */
1632 public final int getCallerDisplayNamePresentation() {
1633 return mCallerDisplayNamePresentation;
1634 }
1635
1636 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001637 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001638 */
1639 public final int getState() {
1640 return mState;
1641 }
1642
1643 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001644 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001645 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1646 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1647 * {@link VideoProfile#STATE_TX_ENABLED},
1648 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001649 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001650 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001651 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001652 */
1653 public final int getVideoState() {
1654 return mVideoState;
1655 }
1656
1657 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001658 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001659 * being routed by the system. This is {@code null} if this Connection
1660 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001661 * @deprecated Use {@link #getCallAudioState()} instead.
1662 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001663 */
Yorke Lee4af59352015-05-13 14:14:54 -07001664 @SystemApi
1665 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001666 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001667 if (mCallAudioState == null) {
1668 return null;
1669 }
Yorke Lee4af59352015-05-13 14:14:54 -07001670 return new AudioState(mCallAudioState);
1671 }
1672
1673 /**
1674 * @return The audio state of the connection, describing how its audio is currently
1675 * being routed by the system. This is {@code null} if this Connection
1676 * does not directly know about its audio state.
1677 */
1678 public final CallAudioState getCallAudioState() {
1679 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001680 }
1681
1682 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001683 * @return The conference that this connection is a part of. Null if it is not part of any
1684 * conference.
1685 */
1686 public final Conference getConference() {
1687 return mConference;
1688 }
1689
1690 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001691 * Returns whether this connection is requesting that the system play a ringback tone
1692 * on its behalf.
1693 */
Andrew Lee100e2932014-09-08 15:34:24 -07001694 public final boolean isRingbackRequested() {
1695 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001696 }
1697
1698 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001699 * @return True if the connection's audio mode is VOIP.
1700 */
1701 public final boolean getAudioModeIsVoip() {
1702 return mAudioModeIsVoip;
1703 }
1704
1705 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001706 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1707 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1708 * start time of the conference.
1709 *
1710 * @return The time at which the {@code Connnection} was connected.
1711 *
1712 * @hide
1713 */
1714 public final long getConnectTimeMillis() {
1715 return mConnectTimeMillis;
1716 }
1717
1718 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001719 * @return The status hints for this connection.
1720 */
1721 public final StatusHints getStatusHints() {
1722 return mStatusHints;
1723 }
1724
1725 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001726 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001727 * <p>
1728 * Extras should be updated using {@link #putExtras(Bundle)}.
1729 * <p>
1730 * Telecom or an {@link InCallService} can also update the extras via
1731 * {@link android.telecom.Call#putExtras(Bundle)}, and
1732 * {@link Call#removeExtras(List)}.
1733 * <p>
1734 * The connection is notified of changes to the extras made by Telecom or an
1735 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001736 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001737 * @return The extras associated with this connection.
1738 */
1739 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001740 Bundle extras = null;
1741 synchronized (mExtrasLock) {
1742 if (mExtras != null) {
1743 extras = new Bundle(mExtras);
1744 }
1745 }
1746 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001747 }
1748
1749 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001750 * Assign a listener to be notified of state changes.
1751 *
1752 * @param l A listener.
1753 * @return This Connection.
1754 *
1755 * @hide
1756 */
1757 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001758 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001759 return this;
1760 }
1761
1762 /**
1763 * Remove a previously assigned listener that was being notified of state changes.
1764 *
1765 * @param l A Listener.
1766 * @return This Connection.
1767 *
1768 * @hide
1769 */
1770 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001771 if (l != null) {
1772 mListeners.remove(l);
1773 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001774 return this;
1775 }
1776
1777 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001778 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001779 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001780 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001781 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001782 }
1783
1784 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001785 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1786 * ONLY for debugging purposes.
1787 *
1788 * @param callId The telecom call ID.
1789 * @hide
1790 */
1791 public void setTelecomCallId(String callId) {
1792 mTelecomCallId = callId;
1793 }
1794
1795 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001796 * Inform this Connection that the state of its audio output has been changed externally.
1797 *
1798 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001799 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001800 */
Yorke Lee4af59352015-05-13 14:14:54 -07001801 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001802 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001803 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001804 mCallAudioState = state;
1805 onAudioStateChanged(getAudioState());
1806 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001807 }
1808
1809 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001810 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001811 * @return A string representation of the value.
1812 */
1813 public static String stateToString(int state) {
1814 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001815 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001816 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001817 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001818 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001819 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001820 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001821 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001822 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001823 case STATE_PULLING_CALL:
1824 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001825 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001826 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001827 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001828 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001829 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001830 return "DISCONNECTED";
1831 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001832 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001833 return "UNKNOWN";
1834 }
1835 }
1836
1837 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001838 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001839 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001840 public final int getConnectionCapabilities() {
1841 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001842 }
1843
1844 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001845 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1846 */
1847 public final int getConnectionProperties() {
1848 return mConnectionProperties;
1849 }
1850
1851 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001852 * Returns the connection's supported audio routes.
1853 *
1854 * @hide
1855 */
1856 public final int getSupportedAudioRoutes() {
1857 return mSupportedAudioRoutes;
1858 }
1859
1860 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001861 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001862 *
Andrew Lee100e2932014-09-08 15:34:24 -07001863 * @param address The new address.
1864 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001865 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001866 */
Andrew Lee100e2932014-09-08 15:34:24 -07001867 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001868 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001869 Log.d(this, "setAddress %s", address);
1870 mAddress = address;
1871 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001872 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001873 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001874 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001875 }
1876
1877 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001878 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001879 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001880 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001881 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001882 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001883 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001884 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001885 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001886 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001887 mCallerDisplayName = callerDisplayName;
1888 mCallerDisplayNamePresentation = presentation;
1889 for (Listener l : mListeners) {
1890 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1891 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001892 }
1893
1894 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001895 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001896 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1897 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1898 * {@link VideoProfile#STATE_TX_ENABLED},
1899 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001900 *
1901 * @param videoState The new video state.
1902 */
1903 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001904 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001905 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001906 mVideoState = videoState;
1907 for (Listener l : mListeners) {
1908 l.onVideoStateChanged(this, mVideoState);
1909 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001910 }
1911
1912 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001913 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001914 * communicate).
1915 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001916 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001917 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001918 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001919 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001920 }
1921
1922 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001923 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001924 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001925 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001926 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001927 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001928 }
1929
1930 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001931 * Sets state to initializing (this Connection is not yet ready to be used).
1932 */
1933 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001934 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001935 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001936 }
1937
1938 /**
1939 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1940 */
1941 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001942 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001943 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001944 }
1945
1946 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001947 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001948 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001949 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001950 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001951 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001952 }
1953
1954 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07001955 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
1956 * device). Only applicable for {@link Connection}s with
1957 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
1958 */
1959 public final void setPulling() {
1960 checkImmutable();
1961 setState(STATE_PULLING_CALL);
1962 }
1963
1964 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001965 * Sets state to be on hold.
1966 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001967 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001968 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001969 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001970 }
1971
1972 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001973 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001974 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001975 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001976 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001977 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001978 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001979 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001980 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001981 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001982 }
1983
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001984 public final VideoProvider getVideoProvider() {
1985 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001986 }
1987
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001988 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001989 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001990 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001991 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001992 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001993 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001994 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001995 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001996 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001997 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001998 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001999 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002000 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002001 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002002 }
2003
2004 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002005 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2006 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2007 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2008 * to send an {@link #onPostDialContinue(boolean)} signal.
2009 *
2010 * @param remaining The DTMF character sequence remaining to be emitted once the
2011 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2012 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002013 */
2014 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002015 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002016 for (Listener l : mListeners) {
2017 l.onPostDialWait(this, remaining);
2018 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002019 }
2020
2021 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002022 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2023 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002024 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002025 *
2026 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002027 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002028 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002029 checkImmutable();
2030 for (Listener l : mListeners) {
2031 l.onPostDialChar(this, nextChar);
2032 }
2033 }
2034
2035 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002036 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002037 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002038 *
2039 * @param ringback Whether the ringback tone is to be played.
2040 */
Andrew Lee100e2932014-09-08 15:34:24 -07002041 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002042 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002043 if (mRingbackRequested != ringback) {
2044 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002045 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002046 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002047 }
2048 }
Ihab Awadf8358972014-05-28 16:46:42 -07002049 }
2050
2051 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002052 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002053 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002054 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002055 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002056 public final void setConnectionCapabilities(int connectionCapabilities) {
2057 checkImmutable();
2058 if (mConnectionCapabilities != connectionCapabilities) {
2059 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002060 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002061 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002062 }
2063 }
Santos Cordonb6939982014-06-04 20:20:58 -07002064 }
2065
2066 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002067 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2068 *
2069 * @param connectionProperties The new connection properties.
2070 */
2071 public final void setConnectionProperties(int connectionProperties) {
2072 checkImmutable();
2073 if (mConnectionProperties != connectionProperties) {
2074 mConnectionProperties = connectionProperties;
2075 for (Listener l : mListeners) {
2076 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2077 }
2078 }
2079 }
2080
2081 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002082 * Sets the supported audio routes.
2083 *
2084 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2085 * See {@link CallAudioState}
2086 * @hide
2087 */
2088 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2089 if ((supportedAudioRoutes
2090 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2091 throw new IllegalArgumentException(
2092 "supported audio routes must include either speaker or earpiece");
2093 }
2094
2095 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2096 mSupportedAudioRoutes = supportedAudioRoutes;
2097 for (Listener l : mListeners) {
2098 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2099 }
2100 }
2101 }
2102
2103 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002104 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002105 */
Evan Charlton36a71342014-07-19 16:31:02 -07002106 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002107 for (Listener l : mListeners) {
2108 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002109 }
Santos Cordonb6939982014-06-04 20:20:58 -07002110 }
2111
2112 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002113 * Requests that the framework use VOIP audio mode for this connection.
2114 *
2115 * @param isVoip True if the audio mode is VOIP.
2116 */
2117 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002118 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002119 mAudioModeIsVoip = isVoip;
2120 for (Listener l : mListeners) {
2121 l.onAudioModeIsVoipChanged(this, isVoip);
2122 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002123 }
2124
2125 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002126 * Sets the time at which a call became active on this Connection. This is set only
2127 * when a conference call becomes active on this connection.
2128 *
2129 * @param connectionTimeMillis The connection time, in milliseconds.
2130 *
2131 * @hide
2132 */
2133 public final void setConnectTimeMillis(long connectTimeMillis) {
2134 mConnectTimeMillis = connectTimeMillis;
2135 }
2136
2137 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002138 * Sets the label and icon status to display in the in-call UI.
2139 *
2140 * @param statusHints The status label and icon to set.
2141 */
2142 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002143 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002144 mStatusHints = statusHints;
2145 for (Listener l : mListeners) {
2146 l.onStatusHintsChanged(this, statusHints);
2147 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002148 }
2149
2150 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002151 * Sets the connections with which this connection can be conferenced.
2152 *
2153 * @param conferenceableConnections The set of connections this connection can conference with.
2154 */
2155 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002156 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002157 clearConferenceableList();
2158 for (Connection c : conferenceableConnections) {
2159 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2160 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002161 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002162 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002163 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002164 }
2165 }
2166 fireOnConferenceableConnectionsChanged();
2167 }
2168
2169 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002170 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2171 * or conferences with which this connection can be conferenced.
2172 *
2173 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002174 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002175 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002176 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002177 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002178 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2179 // small amount of items here.
2180 if (!mConferenceables.contains(c)) {
2181 if (c instanceof Connection) {
2182 Connection connection = (Connection) c;
2183 connection.addConnectionListener(mConnectionDeathListener);
2184 } else if (c instanceof Conference) {
2185 Conference conference = (Conference) c;
2186 conference.addListener(mConferenceDeathListener);
2187 }
2188 mConferenceables.add(c);
2189 }
2190 }
2191 fireOnConferenceableConnectionsChanged();
2192 }
2193
2194 /**
2195 * Returns the connections or conferences with which this connection can be conferenced.
2196 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002197 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002198 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002199 }
2200
Yorke Lee53463962015-08-04 16:07:19 -07002201 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002202 * @hide
2203 */
2204 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002205 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002206 if (mConnectionService != null) {
2207 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2208 "which is already associated with another ConnectionService.");
2209 } else {
2210 mConnectionService = connectionService;
2211 }
2212 }
2213
2214 /**
2215 * @hide
2216 */
2217 public final void unsetConnectionService(ConnectionService connectionService) {
2218 if (mConnectionService != connectionService) {
2219 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2220 "that does not belong to the ConnectionService.");
2221 } else {
2222 mConnectionService = null;
2223 }
2224 }
2225
2226 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002227 * @hide
2228 */
2229 public final ConnectionService getConnectionService() {
2230 return mConnectionService;
2231 }
2232
2233 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002234 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002235 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002236 *
2237 * @param conference The conference.
2238 * @return {@code true} if the conference was successfully set.
2239 * @hide
2240 */
2241 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002242 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002243 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002244 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002245 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002246 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2247 fireConferenceChanged();
2248 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002249 return true;
2250 }
2251 return false;
2252 }
2253
2254 /**
2255 * Resets the conference that this connection is a part of.
2256 * @hide
2257 */
2258 public final void resetConference() {
2259 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002260 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002261 mConference = null;
2262 fireConferenceChanged();
2263 }
2264 }
2265
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002266 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002267 * Set some extras that can be associated with this {@code Connection}.
2268 * <p>
2269 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2270 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2271 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002272 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2273 * {@link #removeExtras(String...)} methods to modify the extras.
2274 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002275 * 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 -07002276 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2277 *
2278 * @param extras The extras associated with this {@code Connection}.
2279 */
2280 public final void setExtras(@Nullable Bundle extras) {
2281 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002282
2283 // Add/replace any new or changed extras values.
2284 putExtras(extras);
2285
2286 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2287 // the current one and remove any keys that went away.
2288 if (mPreviousExtraKeys != null) {
2289 List<String> toRemove = new ArrayList<String>();
2290 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002291 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002292 toRemove.add(oldKey);
2293 }
2294 }
2295 if (!toRemove.isEmpty()) {
2296 removeExtras(toRemove);
2297 }
2298 }
2299
2300 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2301 // called we can see if the caller has removed any extras values.
2302 if (mPreviousExtraKeys == null) {
2303 mPreviousExtraKeys = new ArraySet<String>();
2304 }
2305 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002306 if (extras != null) {
2307 mPreviousExtraKeys.addAll(extras.keySet());
2308 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002309 }
2310
2311 /**
2312 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2313 * added.
2314 * <p>
2315 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2316 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2317 *
2318 * @param extras The extras to add.
2319 */
2320 public final void putExtras(@NonNull Bundle extras) {
2321 checkImmutable();
2322 if (extras == null) {
2323 return;
2324 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002325 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2326 // the listeners.
2327 Bundle listenerExtras;
2328 synchronized (mExtrasLock) {
2329 if (mExtras == null) {
2330 mExtras = new Bundle();
2331 }
2332 mExtras.putAll(extras);
2333 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002334 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002335 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002336 // Create a new clone of the extras for each listener so that they don't clobber
2337 // each other
2338 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002339 }
2340 }
2341
2342 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002343 * Adds a boolean extra to this {@code Connection}.
2344 *
2345 * @param key The extra key.
2346 * @param value The value.
2347 * @hide
2348 */
2349 public final void putExtra(String key, boolean value) {
2350 Bundle newExtras = new Bundle();
2351 newExtras.putBoolean(key, value);
2352 putExtras(newExtras);
2353 }
2354
2355 /**
2356 * Adds an integer extra to this {@code Connection}.
2357 *
2358 * @param key The extra key.
2359 * @param value The value.
2360 * @hide
2361 */
2362 public final void putExtra(String key, int value) {
2363 Bundle newExtras = new Bundle();
2364 newExtras.putInt(key, value);
2365 putExtras(newExtras);
2366 }
2367
2368 /**
2369 * Adds a string extra to this {@code Connection}.
2370 *
2371 * @param key The extra key.
2372 * @param value The value.
2373 * @hide
2374 */
2375 public final void putExtra(String key, String value) {
2376 Bundle newExtras = new Bundle();
2377 newExtras.putString(key, value);
2378 putExtras(newExtras);
2379 }
2380
2381 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002382 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002383 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002384 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002385 */
2386 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002387 synchronized (mExtrasLock) {
2388 if (mExtras != null) {
2389 for (String key : keys) {
2390 mExtras.remove(key);
2391 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002392 }
2393 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002394 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002395 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002396 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002397 }
2398 }
2399
2400 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002401 * Removes extras from this {@code Connection}.
2402 *
2403 * @param keys The keys of the extras to remove.
2404 */
2405 public final void removeExtras(String ... keys) {
2406 removeExtras(Arrays.asList(keys));
2407 }
2408
2409 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002410 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2411 * be change to the {@link #getCallAudioState()}.
2412 * <p>
2413 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2414 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2415 * <p>
2416 * See also {@link InCallService#setAudioRoute(int)}.
2417 *
2418 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2419 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2420 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2421 */
2422 public final void setAudioRoute(int route) {
2423 for (Listener l : mListeners) {
2424 l.onAudioRouteChanged(this, route);
2425 }
2426 }
2427
2428 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002429 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002430 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002431 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002432 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2433 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002434 */
Yorke Lee4af59352015-05-13 14:14:54 -07002435 @SystemApi
2436 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002437 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002438
2439 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002440 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2441 *
2442 * @param state The new connection audio state.
2443 */
2444 public void onCallAudioStateChanged(CallAudioState state) {}
2445
2446 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002447 * Notifies this Connection of an internal state change. This method is called after the
2448 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002449 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002450 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002451 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002452 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002453
2454 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002455 * Notifies this Connection of a request to play a DTMF tone.
2456 *
2457 * @param c A DTMF character.
2458 */
Santos Cordonf2951102014-07-20 19:06:29 -07002459 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002460
2461 /**
2462 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2463 */
Santos Cordonf2951102014-07-20 19:06:29 -07002464 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002465
2466 /**
2467 * Notifies this Connection of a request to disconnect.
2468 */
Santos Cordonf2951102014-07-20 19:06:29 -07002469 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002470
2471 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002472 * Notifies this Connection of a request to disconnect a participant of the conference managed
2473 * by the connection.
2474 *
2475 * @param endpoint the {@link Uri} of the participant to disconnect.
2476 * @hide
2477 */
2478 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2479
2480 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002481 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002482 */
Santos Cordonf2951102014-07-20 19:06:29 -07002483 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002484
2485 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002486 * Notifies this Connection of a request to abort.
2487 */
Santos Cordonf2951102014-07-20 19:06:29 -07002488 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002489
2490 /**
2491 * Notifies this Connection of a request to hold.
2492 */
Santos Cordonf2951102014-07-20 19:06:29 -07002493 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002494
2495 /**
2496 * Notifies this Connection of a request to exit a hold state.
2497 */
Santos Cordonf2951102014-07-20 19:06:29 -07002498 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002499
2500 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002501 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002502 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002503 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002504 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002505 */
Santos Cordonf2951102014-07-20 19:06:29 -07002506 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002507
2508 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002509 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002510 * a request to accept.
2511 */
2512 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002513 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002514 }
2515
2516 /**
2517 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002518 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002519 */
Santos Cordonf2951102014-07-20 19:06:29 -07002520 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002521
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002522 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002523 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2524 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002525 */
2526 public void onReject(String replyMessage) {}
2527
2528 /**
Bryce Leecac50772015-11-17 15:13:29 -08002529 * Notifies the Connection of a request to silence the ringer.
2530 *
2531 * @hide
2532 */
2533 public void onSilence() {}
2534
2535 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002536 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2537 */
Santos Cordonf2951102014-07-20 19:06:29 -07002538 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002539
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002540 /**
2541 * Notifies this Connection of a request to pull an external call to the local device.
2542 * <p>
2543 * The {@link InCallService} issues a request to pull an external call to the local device via
2544 * {@link Call#pullExternalCall()}.
2545 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002546 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2547 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002548 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002549 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002550 */
2551 public void onPullExternalCall() {}
2552
2553 /**
2554 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2555 * <p>
2556 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2557 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002558 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2559 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2560 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2561 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2562 * not aware of.
2563 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002564 * See also {@link Call#sendCallEvent(String, Bundle)}.
2565 *
2566 * @param event The call event.
2567 * @param extras Extras associated with the call event.
2568 */
2569 public void onCallEvent(String event, Bundle extras) {}
2570
Tyler Gunndee56a82016-03-23 16:06:34 -07002571 /**
2572 * Notifies this {@link Connection} of a change to the extras made outside the
2573 * {@link ConnectionService}.
2574 * <p>
2575 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2576 * the {@link android.telecom.Call#putExtras(Bundle)} and
2577 * {@link Call#removeExtras(List)}.
2578 *
2579 * @param extras The new extras bundle.
2580 */
2581 public void onExtrasChanged(Bundle extras) {}
2582
Tyler Gunnf5035432017-01-09 09:43:12 -08002583 /**
2584 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2585 * displaying its incoming call user interface for the {@link Connection}.
2586 * <p>
2587 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2588 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2589 * should show its own incoming call user interface.
2590 * <p>
2591 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
2592 * regular {@link ConnectionService}, the Telecom framework will display its own incoming call
2593 * user interface to allow the user to choose whether to answer the new incoming call and
2594 * disconnect other ongoing calls, or to reject the new incoming call.
2595 */
2596 public void onShowIncomingCallUi() {}
2597
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002598 static String toLogSafePhoneNumber(String number) {
2599 // For unknown number, log empty string.
2600 if (number == null) {
2601 return "";
2602 }
2603
2604 if (PII_DEBUG) {
2605 // When PII_DEBUG is true we emit PII.
2606 return number;
2607 }
2608
2609 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2610 // sanitized phone numbers.
2611 StringBuilder builder = new StringBuilder();
2612 for (int i = 0; i < number.length(); i++) {
2613 char c = number.charAt(i);
2614 if (c == '-' || c == '@' || c == '.') {
2615 builder.append(c);
2616 } else {
2617 builder.append('x');
2618 }
2619 }
2620 return builder.toString();
2621 }
2622
Ihab Awad542e0ea2014-05-16 10:22:16 -07002623 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002624 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002625 if (mState == STATE_DISCONNECTED && mState != state) {
2626 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002627 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002628 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002629 if (mState != state) {
2630 Log.d(this, "setState: %s", stateToString(state));
2631 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002632 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002633 for (Listener l : mListeners) {
2634 l.onStateChanged(this, state);
2635 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002636 }
2637 }
2638
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002639 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002640 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002641 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2642 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002643 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002644 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002645
2646 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002647 if (mImmutable) {
2648 throw new UnsupportedOperationException("Connection is immutable");
2649 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002650 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002651 }
2652
Evan Charltonbf11f982014-07-20 22:06:28 -07002653 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002654 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002655 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2656 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002657 * <p>
2658 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2659 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002660 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002661 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002662 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002663 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002664 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2665 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002666 }
2667
Evan Charltonbf11f982014-07-20 22:06:28 -07002668 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002669 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2670 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2671 * this should never be un-@hide-den.
2672 *
2673 * @hide
2674 */
2675 public void checkImmutable() {}
2676
2677 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002678 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2679 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2680 * that state. This connection should not be used for anything, and no other
2681 * {@code Connection}s should be attempted.
2682 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002683 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002684 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002685 * @return A {@code Connection} which indicates that the underlying connection should
2686 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002687 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002688 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002689 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002690 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002691
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002692 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002693 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002694 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002695 }
2696 }
2697
Santos Cordon823fd3c2014-08-07 18:35:18 -07002698 private final void fireConferenceChanged() {
2699 for (Listener l : mListeners) {
2700 l.onConferenceChanged(this, mConference);
2701 }
2702 }
2703
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002704 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002705 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002706 if (c instanceof Connection) {
2707 Connection connection = (Connection) c;
2708 connection.removeConnectionListener(mConnectionDeathListener);
2709 } else if (c instanceof Conference) {
2710 Conference conference = (Conference) c;
2711 conference.removeListener(mConferenceDeathListener);
2712 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002713 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002714 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002715 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002716
2717 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002718 * Handles a change to extras received from Telecom.
2719 *
2720 * @param extras The new extras.
2721 * @hide
2722 */
2723 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002724 Bundle b = null;
2725 synchronized (mExtrasLock) {
2726 mExtras = extras;
2727 if (mExtras != null) {
2728 b = new Bundle(mExtras);
2729 }
2730 }
2731 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07002732 }
2733
2734 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002735 * Notifies listeners that the merge request failed.
2736 *
2737 * @hide
2738 */
2739 protected final void notifyConferenceMergeFailed() {
2740 for (Listener l : mListeners) {
2741 l.onConferenceMergeFailed(this);
2742 }
2743 }
2744
2745 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002746 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002747 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002748 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002749 * @hide
2750 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002751 protected final void updateConferenceParticipants(
2752 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002753 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002754 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002755 }
2756 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002757
2758 /**
2759 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002760 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002761 */
2762 protected void notifyConferenceStarted() {
2763 for (Listener l : mListeners) {
2764 l.onConferenceStarted();
2765 }
2766 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002767
2768 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07002769 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
2770 * be a part of a conference call.
2771 * @param isConferenceSupported {@code true} if the connection supports being part of a
2772 * conference call, {@code false} otherwise.
2773 * @hide
2774 */
2775 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
2776 for (Listener l : mListeners) {
2777 l.onConferenceSupportedChanged(this, isConferenceSupported);
2778 }
2779 }
2780
2781 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002782 * Sends an event associated with this {@code Connection} with associated event extras to the
2783 * {@link InCallService}.
2784 * <p>
2785 * Connection events are used to communicate point in time information from a
2786 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
2787 * custom connection event includes notifying the UI when a WIFI call has been handed over to
2788 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
2789 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
2790 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
2791 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
2792 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
2793 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
2794 * <p>
2795 * Events are exposed to {@link InCallService} implementations via
2796 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
2797 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002798 * 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 -07002799 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
2800 * some events altogether.
2801 * <p>
2802 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
2803 * conflicts between {@link ConnectionService} implementations. Further, custom
2804 * {@link ConnectionService} implementations shall not re-purpose events in the
2805 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
2806 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
2807 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
2808 * {@code com.example.extra.MY_EXTRA}).
2809 * <p>
2810 * When defining events and the associated extras, it is important to keep their behavior
2811 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
2812 * events/extras should me maintained to ensure backwards compatibility with older
2813 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002814 *
2815 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002816 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002817 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002818 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002819 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002820 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002821 }
2822 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002823}