blob: bf78712295d2292545fbd7564300d685636ddf20 [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
Santos Cordon6b7f9552015-05-27 17:21:45 -070023import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070024import android.annotation.SystemApi;
Tyler Gunnb702ef82015-05-29 11:51:53 -070025import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070026import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070027import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070028import android.os.Handler;
29import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070030import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070031import android.os.Message;
32import android.os.RemoteException;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070033import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070034
Santos Cordonb6939982014-06-04 20:20:58 -070035import java.util.ArrayList;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070036import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070037import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070038import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070039import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070040
41/**
Santos Cordon895d4b82015-06-25 16:41:48 -070042 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
43 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070044 * <p>
45 * Implementations create a custom subclass of {@code Connection} and return it to the framework
46 * as the return value of
47 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
48 * or
49 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
50 * Implementations are then responsible for updating the state of the {@code Connection}, and
51 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
52 * longer used and associated resources may be recovered.
Ihab Awad542e0ea2014-05-16 10:22:16 -070053 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070054public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070055
Santos Cordon895d4b82015-06-25 16:41:48 -070056 /**
57 * The connection is initializing. This is generally the first state for a {@code Connection}
58 * returned by a {@link ConnectionService}.
59 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070060 public static final int STATE_INITIALIZING = 0;
61
Santos Cordon895d4b82015-06-25 16:41:48 -070062 /**
63 * The connection is new and not connected.
64 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070065 public static final int STATE_NEW = 1;
66
Santos Cordon895d4b82015-06-25 16:41:48 -070067 /**
68 * An incoming connection is in the ringing state. During this state, the user's ringer or
69 * vibration feature will be activated.
70 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070071 public static final int STATE_RINGING = 2;
72
Santos Cordon895d4b82015-06-25 16:41:48 -070073 /**
74 * An outgoing connection is in the dialing state. In this state the other party has not yet
75 * answered the call and the user traditionally hears a ringback tone.
76 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070077 public static final int STATE_DIALING = 3;
78
Santos Cordon895d4b82015-06-25 16:41:48 -070079 /**
80 * A connection is active. Both parties are connected to the call and can actively communicate.
81 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070082 public static final int STATE_ACTIVE = 4;
83
Santos Cordon895d4b82015-06-25 16:41:48 -070084 /**
85 * A connection is on hold.
86 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070087 public static final int STATE_HOLDING = 5;
88
Santos Cordon895d4b82015-06-25 16:41:48 -070089 /**
90 * A connection has been disconnected. This is the final state once the user has been
91 * disconnected from a call either locally, remotely or by an error in the service.
92 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070093 public static final int STATE_DISCONNECTED = 6;
94
Santos Cordon895d4b82015-06-25 16:41:48 -070095 /**
96 * Connection can currently be put on hold or unheld. This is distinct from
97 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
98 * it does not at the moment support the function. This can be true while the call is in the
99 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
100 * display a disabled 'hold' button.
101 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800102 public static final int CAPABILITY_HOLD = 0x00000001;
103
104 /** Connection supports the hold feature. */
105 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
106
107 /**
108 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
109 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
110 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
111 * capability allows a merge button to be shown while the conference is in the foreground
112 * of the in-call UI.
113 * <p>
114 * This is only intended for use by a {@link Conference}.
115 */
116 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
117
118 /**
119 * Connections within a conference can be swapped between foreground and background.
120 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
121 * <p>
122 * This is only intended for use by a {@link Conference}.
123 */
124 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
125
126 /**
127 * @hide
128 */
129 public static final int CAPABILITY_UNUSED = 0x00000010;
130
131 /** Connection supports responding via text option. */
132 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
133
134 /** Connection can be muted. */
135 public static final int CAPABILITY_MUTE = 0x00000040;
136
137 /**
138 * Connection supports conference management. This capability only applies to
139 * {@link Conference}s which can have {@link Connection}s as children.
140 */
141 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
142
143 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700144 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800145 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700146 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800147
148 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700149 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800150 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700151 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800152
153 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700154 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800155 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700156 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700157 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800158
159 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700160 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800161 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700162 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
163
164 /**
165 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700166 */
167 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
168
169 /**
170 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700171 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700172 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700173 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800174
175 /**
176 * Connection is able to be separated from its parent {@code Conference}, if any.
177 */
178 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
179
180 /**
181 * Connection is able to be individually disconnected when in a {@code Conference}.
182 */
183 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
184
185 /**
186 * Whether the call is a generic conference, where we do not know the precise state of
187 * participants in the conference (eg. on CDMA).
188 *
189 * @hide
190 */
191 public static final int CAPABILITY_GENERIC_CONFERENCE = 0x00004000;
192
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700193 /**
194 * Connection is using high definition audio.
195 * @hide
196 */
197 public static final int CAPABILITY_HIGH_DEF_AUDIO = 0x00008000;
198
199 /**
200 * Connection is using WIFI.
201 * @hide
202 */
Tyler Gunnd11a3152015-03-18 13:09:14 -0700203 public static final int CAPABILITY_WIFI = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700204
Tyler Gunn068085b2015-02-06 13:56:52 -0800205 /**
206 * Indicates that the current device callback number should be shown.
207 *
208 * @hide
209 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700210 public static final int CAPABILITY_SHOW_CALLBACK_NUMBER = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800211
Tyler Gunn96d6c402015-03-18 12:39:23 -0700212 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500213 * Speed up audio setup for MT call.
214 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700215 */
216 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800217
Rekha Kumar07366812015-03-24 16:42:31 -0700218 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700219 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700220 */
221 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
222
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700223 /**
224 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700225 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700226 */
227 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
228
Tyler Gunnd4091732015-06-29 09:15:37 -0700229 /**
230 * For a conference, indicates the conference will not have child connections.
231 * <p>
232 * An example of a conference with child connections is a GSM conference call, where the radio
233 * retains connections to the individual participants of the conference. Another example is an
234 * IMS conference call where conference event package functionality is supported; in this case
235 * the conference server ensures the radio is aware of the participants in the conference, which
236 * are represented by child connections.
237 * <p>
238 * An example of a conference with no child connections is an IMS conference call with no
239 * conference event package support. Such a conference is represented by the radio as a single
240 * connection to the IMS conference server.
241 * <p>
242 * Indicating whether a conference has children or not is important to help user interfaces
243 * visually represent a conference. A conference with no children, for example, will have the
244 * conference connection shown in the list of calls on a Bluetooth device, where if the
245 * conference has children, only the children will be shown in the list of calls on a Bluetooth
246 * device.
247 * @hide
248 */
249 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
250
Tyler Gunn96d6c402015-03-18 12:39:23 -0700251 //**********************************************************************************************
Tyler Gunnd4091732015-06-29 09:15:37 -0700252 // Next CAPABILITY value: 0x00400000
Tyler Gunn96d6c402015-03-18 12:39:23 -0700253 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800254
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700255 // Flag controlling whether PII is emitted into the logs
256 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
257
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800258 /**
259 * Whether the given capabilities support the specified capability.
260 *
261 * @param capabilities A capability bit field.
262 * @param capability The capability to check capabilities for.
263 * @return Whether the specified capability is supported.
264 * @hide
265 */
266 public static boolean can(int capabilities, int capability) {
267 return (capabilities & capability) != 0;
268 }
269
270 /**
271 * Whether the capabilities of this {@code Connection} supports the specified capability.
272 *
273 * @param capability The capability to check capabilities for.
274 * @return Whether the specified capability is supported.
275 * @hide
276 */
277 public boolean can(int capability) {
278 return can(mConnectionCapabilities, capability);
279 }
280
281 /**
282 * Removes the specified capability from the set of capabilities of this {@code Connection}.
283 *
284 * @param capability The capability to remove from the set.
285 * @hide
286 */
287 public void removeCapability(int capability) {
288 mConnectionCapabilities &= ~capability;
289 }
290
291 /**
292 * Adds the specified capability to the set of capabilities of this {@code Connection}.
293 *
294 * @param capability The capability to add to the set.
295 * @hide
296 */
297 public void addCapability(int capability) {
298 mConnectionCapabilities |= capability;
299 }
300
301
302 public static String capabilitiesToString(int capabilities) {
303 StringBuilder builder = new StringBuilder();
304 builder.append("[Capabilities:");
305 if (can(capabilities, CAPABILITY_HOLD)) {
306 builder.append(" CAPABILITY_HOLD");
307 }
308 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
309 builder.append(" CAPABILITY_SUPPORT_HOLD");
310 }
311 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
312 builder.append(" CAPABILITY_MERGE_CONFERENCE");
313 }
314 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
315 builder.append(" CAPABILITY_SWAP_CONFERENCE");
316 }
317 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
318 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
319 }
320 if (can(capabilities, CAPABILITY_MUTE)) {
321 builder.append(" CAPABILITY_MUTE");
322 }
323 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
324 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
325 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700326 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
327 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
328 }
329 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
330 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
331 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700332 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
333 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800334 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700335 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
336 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
337 }
338 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
339 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
340 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700341 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
342 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800343 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800344 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
345 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800346 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800347 if (can(capabilities, CAPABILITY_WIFI)) {
348 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800349 }
350 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
351 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
352 }
Tyler Gunn068085b2015-02-06 13:56:52 -0800353 if (can(capabilities, CAPABILITY_SHOW_CALLBACK_NUMBER)) {
354 builder.append(" CAPABILITY_SHOW_CALLBACK_NUMBER");
355 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500356 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700357 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500358 }
Rekha Kumar07366812015-03-24 16:42:31 -0700359 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
360 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
361 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700362 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
363 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
364 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700365 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
366 builder.append(" CAPABILITY_SINGLE_PARTY_CONFERENCE");
367 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800368 builder.append("]");
369 return builder.toString();
370 }
371
Sailesh Nepal091768c2014-06-30 15:15:23 -0700372 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700373 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700374 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700375 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700376 public void onCallerDisplayNameChanged(
377 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700378 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700379 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700380 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800381 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700382 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700383 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800384 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700385 public void onVideoProviderChanged(
386 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700387 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
388 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800389 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700390 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700391 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700392 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800393 public void onConferenceParticipantsChanged(Connection c,
394 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800395 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700396 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700397 public void onExtrasChanged(Connection c, Bundle extras) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700398 }
399
Tyler Gunnb702ef82015-05-29 11:51:53 -0700400 /**
401 * Provides a means of controlling the video session associated with a {@link Connection}.
402 * <p>
403 * Implementations create a custom subclass of {@link VideoProvider} and the
404 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
405 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
406 * should set the {@link VideoProvider}.
407 * <p>
408 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
409 * {@link InCallService} implementations to issue requests related to the video session;
410 * it provides a means for the {@link ConnectionService} to report events and information
411 * related to the video session to Telecom and the {@link InCallService} implementations.
412 * <p>
413 * {@link InCallService} implementations interact with the {@link VideoProvider} via
414 * {@link android.telecom.InCallService.VideoCall}.
415 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700416 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700417
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700418 /**
419 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700420 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700421 */
422 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700423
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700424 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700425 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
426 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700427 */
428 public static final int SESSION_EVENT_RX_RESUME = 2;
429
430 /**
431 * Video transmission has begun. This occurs after a negotiated start of video transmission
432 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700433 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700434 */
435 public static final int SESSION_EVENT_TX_START = 3;
436
437 /**
438 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
439 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700440 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700441 */
442 public static final int SESSION_EVENT_TX_STOP = 4;
443
444 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700445 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
446 * this as a cue to inform the user the camera is not available.
447 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700448 */
449 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
450
451 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700452 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
453 * for operation. The {@link InCallService} can use this as a cue to inform the user that
454 * the camera has become available again.
455 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700456 */
457 public static final int SESSION_EVENT_CAMERA_READY = 6;
458
459 /**
460 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700461 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700462 */
463 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
464
465 /**
466 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700467 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700468 */
469 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
470
471 /**
472 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700473 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700474 */
475 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
476
Rekha Kumar07366812015-03-24 16:42:31 -0700477 /**
478 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700479 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700480 */
481 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
482
483 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700484 * Session modify request rejected by remote user.
485 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700486 */
487 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
488
Tyler Gunn75958422015-04-15 14:23:42 -0700489 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700490 private static final int MSG_SET_CAMERA = 2;
491 private static final int MSG_SET_PREVIEW_SURFACE = 3;
492 private static final int MSG_SET_DISPLAY_SURFACE = 4;
493 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
494 private static final int MSG_SET_ZOOM = 6;
495 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
496 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
497 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800498 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700499 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700500 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700501
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700502 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700503 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700504
505 /**
506 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700507 *
508 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
509 * load factor before resizing, 1 means we only expect a single thread to
510 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700511 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700512 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
513 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700514
515 /**
516 * Default handler used to consolidate binder method calls onto a single thread.
517 */
518 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700519 public VideoProviderHandler() {
520 super();
521 }
522
523 public VideoProviderHandler(Looper looper) {
524 super(looper);
525 }
526
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700527 @Override
528 public void handleMessage(Message msg) {
529 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700530 case MSG_ADD_VIDEO_CALLBACK: {
531 IBinder binder = (IBinder) msg.obj;
532 IVideoCallback callback = IVideoCallback.Stub
533 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700534 if (callback == null) {
535 Log.w(this, "addVideoProvider - skipped; callback is null.");
536 break;
537 }
538
Tyler Gunn75958422015-04-15 14:23:42 -0700539 if (mVideoCallbacks.containsKey(binder)) {
540 Log.i(this, "addVideoProvider - skipped; already present.");
541 break;
542 }
543 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700544 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700545 }
546 case MSG_REMOVE_VIDEO_CALLBACK: {
547 IBinder binder = (IBinder) msg.obj;
548 IVideoCallback callback = IVideoCallback.Stub
549 .asInterface((IBinder) msg.obj);
550 if (!mVideoCallbacks.containsKey(binder)) {
551 Log.i(this, "removeVideoProvider - skipped; not present.");
552 break;
553 }
554 mVideoCallbacks.remove(binder);
555 break;
556 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700557 case MSG_SET_CAMERA:
558 onSetCamera((String) msg.obj);
559 break;
560 case MSG_SET_PREVIEW_SURFACE:
561 onSetPreviewSurface((Surface) msg.obj);
562 break;
563 case MSG_SET_DISPLAY_SURFACE:
564 onSetDisplaySurface((Surface) msg.obj);
565 break;
566 case MSG_SET_DEVICE_ORIENTATION:
567 onSetDeviceOrientation(msg.arg1);
568 break;
569 case MSG_SET_ZOOM:
570 onSetZoom((Float) msg.obj);
571 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700572 case MSG_SEND_SESSION_MODIFY_REQUEST: {
573 SomeArgs args = (SomeArgs) msg.obj;
574 try {
575 onSendSessionModifyRequest((VideoProfile) args.arg1,
576 (VideoProfile) args.arg2);
577 } finally {
578 args.recycle();
579 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700580 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700581 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700582 case MSG_SEND_SESSION_MODIFY_RESPONSE:
583 onSendSessionModifyResponse((VideoProfile) msg.obj);
584 break;
585 case MSG_REQUEST_CAMERA_CAPABILITIES:
586 onRequestCameraCapabilities();
587 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800588 case MSG_REQUEST_CONNECTION_DATA_USAGE:
589 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700590 break;
591 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700592 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700593 break;
594 default:
595 break;
596 }
597 }
598 }
599
600 /**
601 * IVideoProvider stub implementation.
602 */
603 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700604 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700605 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700606 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
607 }
608
609 public void removeVideoCallback(IBinder videoCallbackBinder) {
610 mMessageHandler.obtainMessage(
611 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700612 }
613
614 public void setCamera(String cameraId) {
615 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
616 }
617
618 public void setPreviewSurface(Surface surface) {
619 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
620 }
621
622 public void setDisplaySurface(Surface surface) {
623 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
624 }
625
626 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700627 mMessageHandler.obtainMessage(
628 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700629 }
630
631 public void setZoom(float value) {
632 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
633 }
634
Tyler Gunn45382162015-05-06 08:52:27 -0700635 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
636 SomeArgs args = SomeArgs.obtain();
637 args.arg1 = fromProfile;
638 args.arg2 = toProfile;
639 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700640 }
641
642 public void sendSessionModifyResponse(VideoProfile responseProfile) {
643 mMessageHandler.obtainMessage(
644 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
645 }
646
647 public void requestCameraCapabilities() {
648 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
649 }
650
651 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800652 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700653 }
654
Yorke Lee32f24732015-05-12 16:18:03 -0700655 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700656 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
657 }
658 }
659
660 public VideoProvider() {
661 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700662 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700663 }
664
665 /**
666 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
667 *
668 * @param looper The looper.
669 * @hide
670 */
671 public VideoProvider(Looper looper) {
672 mBinder = new VideoProvider.VideoProviderBinder();
673 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700674 }
675
676 /**
677 * Returns binder object which can be used across IPC methods.
678 * @hide
679 */
680 public final IVideoProvider getInterface() {
681 return mBinder;
682 }
683
684 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700685 * Sets the camera to be used for the outgoing video.
686 * <p>
687 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
688 * camera via
689 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
690 * <p>
691 * Sent from the {@link InCallService} via
692 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700693 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700694 * @param cameraId The id of the camera (use ids as reported by
695 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700696 */
697 public abstract void onSetCamera(String cameraId);
698
699 /**
700 * Sets the surface to be used for displaying a preview of what the user's camera is
701 * currently capturing. When video transmission is enabled, this is the video signal which
702 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700703 * <p>
704 * Sent from the {@link InCallService} via
705 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700706 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700707 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700708 */
709 public abstract void onSetPreviewSurface(Surface surface);
710
711 /**
712 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700713 * <p>
714 * Sent from the {@link InCallService} via
715 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700716 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700717 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700718 */
719 public abstract void onSetDisplaySurface(Surface surface);
720
721 /**
722 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
723 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700724 * <p>
725 * Sent from the {@link InCallService} via
726 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700727 *
728 * @param rotation The device orientation, in degrees.
729 */
730 public abstract void onSetDeviceOrientation(int rotation);
731
732 /**
733 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700734 * <p>
735 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700736 *
737 * @param value The camera zoom ratio.
738 */
739 public abstract void onSetZoom(float value);
740
741 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700742 * Issues a request to modify the properties of the current video session.
743 * <p>
744 * Example scenarios include: requesting an audio-only call to be upgraded to a
745 * bi-directional video call, turning on or off the user's camera, sending a pause signal
746 * when the {@link InCallService} is no longer the foreground application.
747 * <p>
748 * If the {@link VideoProvider} determines a request to be invalid, it should call
749 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
750 * invalid request back to the {@link InCallService}.
751 * <p>
752 * Where a request requires confirmation from the user of the peer device, the
753 * {@link VideoProvider} must communicate the request to the peer device and handle the
754 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
755 * is used to inform the {@link InCallService} of the result of the request.
756 * <p>
757 * Sent from the {@link InCallService} via
758 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700759 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700760 * @param fromProfile The video profile prior to the request.
761 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700762 */
Tyler Gunn45382162015-05-06 08:52:27 -0700763 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
764 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700765
Tyler Gunnb702ef82015-05-29 11:51:53 -0700766 /**
767 * Provides a response to a request to change the current video session properties.
768 * <p>
769 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
770 * video call, could decline the request and keep the call as audio-only.
771 * In such a scenario, the {@code responseProfile} would have a video state of
772 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
773 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
774 * <p>
775 * Sent from the {@link InCallService} via
776 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
777 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
778 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700779 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700780 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700781 */
782 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
783
784 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700785 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
786 * <p>
787 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
788 * camera via
789 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
790 * <p>
791 * Sent from the {@link InCallService} via
792 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700793 */
794 public abstract void onRequestCameraCapabilities();
795
796 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700797 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
798 * video component of the current {@link Connection}.
799 * <p>
800 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
801 * via {@link VideoProvider#setCallDataUsage(long)}.
802 * <p>
803 * Sent from the {@link InCallService} via
804 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700805 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800806 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700807
808 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700809 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
810 * the peer device when the video signal is paused.
811 * <p>
812 * Sent from the {@link InCallService} via
813 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700814 *
815 * @param uri URI of image to display.
816 */
Yorke Lee32f24732015-05-12 16:18:03 -0700817 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700818
819 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700820 * Used to inform listening {@link InCallService} implementations when the
821 * {@link VideoProvider} receives a session modification request.
822 * <p>
823 * Received by the {@link InCallService} via
824 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700825 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700826 * @param videoProfile The requested video profile.
827 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700828 */
829 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700830 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700831 for (IVideoCallback callback : mVideoCallbacks.values()) {
832 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700833 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700834 } catch (RemoteException ignored) {
835 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700836 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700837 }
838 }
839 }
840
841 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700842 * Used to inform listening {@link InCallService} implementations when the
843 * {@link VideoProvider} receives a response to a session modification request.
844 * <p>
845 * Received by the {@link InCallService} via
846 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
847 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700848 *
849 * @param status Status of the session modify request. Valid values are
850 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
851 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -0700852 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
853 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
854 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
855 * @param requestedProfile The original request which was sent to the peer device.
856 * @param responseProfile The actual profile changes agreed to by the peer device.
857 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700858 */
859 public void receiveSessionModifyResponse(int status,
860 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700861 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700862 for (IVideoCallback callback : mVideoCallbacks.values()) {
863 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700864 callback.receiveSessionModifyResponse(status, requestedProfile,
865 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700866 } catch (RemoteException ignored) {
867 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700868 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700869 }
870 }
871 }
872
873 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700874 * Used to inform listening {@link InCallService} implementations when the
875 * {@link VideoProvider} reports a call session event.
876 * <p>
877 * Received by the {@link InCallService} via
878 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700879 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700880 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
881 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
882 * {@link VideoProvider#SESSION_EVENT_TX_START},
883 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
884 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
885 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700886 */
887 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -0700888 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700889 for (IVideoCallback callback : mVideoCallbacks.values()) {
890 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700891 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700892 } catch (RemoteException ignored) {
893 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700894 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700895 }
896 }
897 }
898
899 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700900 * Used to inform listening {@link InCallService} implementations when the dimensions of the
901 * peer's video have changed.
902 * <p>
903 * This could occur if, for example, the peer rotates their device, changing the aspect
904 * ratio of the video, or if the user switches between the back and front cameras.
905 * <p>
906 * Received by the {@link InCallService} via
907 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700908 *
909 * @param width The updated peer video width.
910 * @param height The updated peer video height.
911 */
912 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -0700913 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700914 for (IVideoCallback callback : mVideoCallbacks.values()) {
915 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700916 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700917 } catch (RemoteException ignored) {
918 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700919 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700920 }
921 }
922 }
923
924 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700925 * Used to inform listening {@link InCallService} implementations when the data usage of the
926 * video associated with the current {@link Connection} has changed.
927 * <p>
928 * This could be in response to a preview request via
929 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -0700930 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
931 * 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 -0700932 * <p>
933 * Received by the {@link InCallService} via
934 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700935 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700936 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
937 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700938 */
Yorke Lee32f24732015-05-12 16:18:03 -0700939 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -0700940 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700941 for (IVideoCallback callback : mVideoCallbacks.values()) {
942 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700943 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700944 } catch (RemoteException ignored) {
945 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700946 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700947 }
948 }
949 }
950
951 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700952 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700953 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700954 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -0700955 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
956 * @hide
957 */
958 public void changeCallDataUsage(long dataUsage) {
959 setCallDataUsage(dataUsage);
960 }
961
962 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700963 * Used to inform listening {@link InCallService} implementations when the capabilities of
964 * the current camera have changed.
965 * <p>
966 * The {@link VideoProvider} should call this in response to
967 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
968 * changed via {@link VideoProvider#onSetCamera(String)}.
969 * <p>
970 * Received by the {@link InCallService} via
971 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
972 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -0700973 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700974 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700975 */
Yorke Lee400470f2015-05-12 13:31:25 -0700976 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -0700977 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700978 for (IVideoCallback callback : mVideoCallbacks.values()) {
979 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700980 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700981 } catch (RemoteException ignored) {
982 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700983 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700984 }
985 }
986 }
Rekha Kumar07366812015-03-24 16:42:31 -0700987
988 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700989 * Used to inform listening {@link InCallService} implementations when the video quality
990 * of the call has changed.
991 * <p>
992 * Received by the {@link InCallService} via
993 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -0700994 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700995 * @param videoQuality The updated video quality. Valid values:
996 * {@link VideoProfile#QUALITY_HIGH},
997 * {@link VideoProfile#QUALITY_MEDIUM},
998 * {@link VideoProfile#QUALITY_LOW},
999 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001000 */
1001 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001002 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001003 for (IVideoCallback callback : mVideoCallbacks.values()) {
1004 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001005 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001006 } catch (RemoteException ignored) {
1007 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001008 }
Rekha Kumar07366812015-03-24 16:42:31 -07001009 }
1010 }
1011 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001012 }
1013
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001014 private final Listener mConnectionDeathListener = new Listener() {
1015 @Override
1016 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001017 if (mConferenceables.remove(c)) {
1018 fireOnConferenceableConnectionsChanged();
1019 }
1020 }
1021 };
1022
1023 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1024 @Override
1025 public void onDestroyed(Conference c) {
1026 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001027 fireOnConferenceableConnectionsChanged();
1028 }
1029 }
1030 };
1031
Jay Shrauner229e3822014-08-15 09:23:07 -07001032 /**
1033 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1034 * load factor before resizing, 1 means we only expect a single thread to
1035 * access the map so make only a single shard
1036 */
1037 private final Set<Listener> mListeners = Collections.newSetFromMap(
1038 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001039 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1040 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001041 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001042
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001043 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001044 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001045 private Uri mAddress;
1046 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001047 private String mCallerDisplayName;
1048 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001049 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001050 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001051 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001052 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001053 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001054 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001055 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001056 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001057 private Conference mConference;
1058 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001059 private Bundle mExtras;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001060
1061 /**
1062 * Create a new Connection.
1063 */
Santos Cordonf2951102014-07-20 19:06:29 -07001064 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001065
1066 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001067 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001068 */
Andrew Lee100e2932014-09-08 15:34:24 -07001069 public final Uri getAddress() {
1070 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001071 }
1072
1073 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001074 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001075 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001076 */
Andrew Lee100e2932014-09-08 15:34:24 -07001077 public final int getAddressPresentation() {
1078 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001079 }
1080
1081 /**
1082 * @return The caller display name (CNAP).
1083 */
1084 public final String getCallerDisplayName() {
1085 return mCallerDisplayName;
1086 }
1087
1088 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001089 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001090 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001091 */
1092 public final int getCallerDisplayNamePresentation() {
1093 return mCallerDisplayNamePresentation;
1094 }
1095
1096 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001097 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001098 */
1099 public final int getState() {
1100 return mState;
1101 }
1102
1103 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001104 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001105 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1106 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1107 * {@link VideoProfile#STATE_TX_ENABLED},
1108 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001109 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001110 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001111 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001112 */
1113 public final int getVideoState() {
1114 return mVideoState;
1115 }
1116
1117 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001118 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001119 * being routed by the system. This is {@code null} if this Connection
1120 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001121 * @deprecated Use {@link #getCallAudioState()} instead.
1122 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001123 */
Yorke Lee4af59352015-05-13 14:14:54 -07001124 @SystemApi
1125 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001126 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001127 if (mCallAudioState == null) {
1128 return null;
1129 }
Yorke Lee4af59352015-05-13 14:14:54 -07001130 return new AudioState(mCallAudioState);
1131 }
1132
1133 /**
1134 * @return The audio state of the connection, describing how its audio is currently
1135 * being routed by the system. This is {@code null} if this Connection
1136 * does not directly know about its audio state.
1137 */
1138 public final CallAudioState getCallAudioState() {
1139 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001140 }
1141
1142 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001143 * @return The conference that this connection is a part of. Null if it is not part of any
1144 * conference.
1145 */
1146 public final Conference getConference() {
1147 return mConference;
1148 }
1149
1150 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001151 * Returns whether this connection is requesting that the system play a ringback tone
1152 * on its behalf.
1153 */
Andrew Lee100e2932014-09-08 15:34:24 -07001154 public final boolean isRingbackRequested() {
1155 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001156 }
1157
1158 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001159 * @return True if the connection's audio mode is VOIP.
1160 */
1161 public final boolean getAudioModeIsVoip() {
1162 return mAudioModeIsVoip;
1163 }
1164
1165 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001166 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1167 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1168 * start time of the conference.
1169 *
1170 * @return The time at which the {@code Connnection} was connected.
1171 *
1172 * @hide
1173 */
1174 public final long getConnectTimeMillis() {
1175 return mConnectTimeMillis;
1176 }
1177
1178 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001179 * @return The status hints for this connection.
1180 */
1181 public final StatusHints getStatusHints() {
1182 return mStatusHints;
1183 }
1184
1185 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001186 * @return The extras associated with this connection.
1187 */
1188 public final Bundle getExtras() {
1189 return mExtras;
1190 }
1191
1192 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001193 * Assign a listener to be notified of state changes.
1194 *
1195 * @param l A listener.
1196 * @return This Connection.
1197 *
1198 * @hide
1199 */
1200 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001201 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001202 return this;
1203 }
1204
1205 /**
1206 * Remove a previously assigned listener that was being notified of state changes.
1207 *
1208 * @param l A Listener.
1209 * @return This Connection.
1210 *
1211 * @hide
1212 */
1213 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001214 if (l != null) {
1215 mListeners.remove(l);
1216 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001217 return this;
1218 }
1219
1220 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001221 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001222 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001223 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001224 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001225 }
1226
1227 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001228 * Inform this Connection that the state of its audio output has been changed externally.
1229 *
1230 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001231 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001232 */
Yorke Lee4af59352015-05-13 14:14:54 -07001233 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001234 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001235 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001236 mCallAudioState = state;
1237 onAudioStateChanged(getAudioState());
1238 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001239 }
1240
1241 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001242 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001243 * @return A string representation of the value.
1244 */
1245 public static String stateToString(int state) {
1246 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001247 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001248 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001249 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001250 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001251 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001252 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001253 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001254 return "DIALING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001255 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001256 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001257 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001258 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001259 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001260 return "DISCONNECTED";
1261 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001262 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001263 return "UNKNOWN";
1264 }
1265 }
1266
1267 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001268 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001269 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001270 public final int getConnectionCapabilities() {
1271 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001272 }
1273
1274 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001275 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001276 *
Andrew Lee100e2932014-09-08 15:34:24 -07001277 * @param address The new address.
1278 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001279 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001280 */
Andrew Lee100e2932014-09-08 15:34:24 -07001281 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001282 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001283 Log.d(this, "setAddress %s", address);
1284 mAddress = address;
1285 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001286 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001287 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001288 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001289 }
1290
1291 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001292 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001293 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001294 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001295 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001296 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001297 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001298 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001299 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001300 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001301 mCallerDisplayName = callerDisplayName;
1302 mCallerDisplayNamePresentation = presentation;
1303 for (Listener l : mListeners) {
1304 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1305 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001306 }
1307
1308 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001309 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001310 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1311 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1312 * {@link VideoProfile#STATE_TX_ENABLED},
1313 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001314 *
1315 * @param videoState The new video state.
1316 */
1317 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001318 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001319 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001320 mVideoState = videoState;
1321 for (Listener l : mListeners) {
1322 l.onVideoStateChanged(this, mVideoState);
1323 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001324 }
1325
1326 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001327 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001328 * communicate).
1329 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001330 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001331 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001332 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001333 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001334 }
1335
1336 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001337 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001338 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001339 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001340 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001341 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001342 }
1343
1344 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001345 * Sets state to initializing (this Connection is not yet ready to be used).
1346 */
1347 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001348 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001349 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001350 }
1351
1352 /**
1353 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1354 */
1355 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001356 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001357 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001358 }
1359
1360 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001361 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001362 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001363 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001364 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001365 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001366 }
1367
1368 /**
1369 * Sets state to be on hold.
1370 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001371 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001372 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001373 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001374 }
1375
1376 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001377 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001378 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001379 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001380 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001381 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001382 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001383 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001384 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001385 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001386 }
1387
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001388 public final VideoProvider getVideoProvider() {
1389 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001390 }
1391
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001392 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001393 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001394 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001395 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001396 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001397 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001398 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001399 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001400 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001401 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001402 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001403 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001404 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001405 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001406 }
1407
1408 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001409 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1410 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1411 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1412 * to send an {@link #onPostDialContinue(boolean)} signal.
1413 *
1414 * @param remaining The DTMF character sequence remaining to be emitted once the
1415 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1416 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001417 */
1418 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001419 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001420 for (Listener l : mListeners) {
1421 l.onPostDialWait(this, remaining);
1422 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001423 }
1424
1425 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001426 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1427 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001428 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001429 *
1430 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001431 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001432 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001433 checkImmutable();
1434 for (Listener l : mListeners) {
1435 l.onPostDialChar(this, nextChar);
1436 }
1437 }
1438
1439 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001440 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001441 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001442 *
1443 * @param ringback Whether the ringback tone is to be played.
1444 */
Andrew Lee100e2932014-09-08 15:34:24 -07001445 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001446 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001447 if (mRingbackRequested != ringback) {
1448 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001449 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001450 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001451 }
1452 }
Ihab Awadf8358972014-05-28 16:46:42 -07001453 }
1454
1455 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001456 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001457 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001458 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001459 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001460 public final void setConnectionCapabilities(int connectionCapabilities) {
1461 checkImmutable();
1462 if (mConnectionCapabilities != connectionCapabilities) {
1463 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001464 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001465 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001466 }
1467 }
Santos Cordonb6939982014-06-04 20:20:58 -07001468 }
1469
1470 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001471 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001472 */
Evan Charlton36a71342014-07-19 16:31:02 -07001473 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001474 for (Listener l : mListeners) {
1475 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001476 }
Santos Cordonb6939982014-06-04 20:20:58 -07001477 }
1478
1479 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001480 * Requests that the framework use VOIP audio mode for this connection.
1481 *
1482 * @param isVoip True if the audio mode is VOIP.
1483 */
1484 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001485 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001486 mAudioModeIsVoip = isVoip;
1487 for (Listener l : mListeners) {
1488 l.onAudioModeIsVoipChanged(this, isVoip);
1489 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001490 }
1491
1492 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001493 * Sets the time at which a call became active on this Connection. This is set only
1494 * when a conference call becomes active on this connection.
1495 *
1496 * @param connectionTimeMillis The connection time, in milliseconds.
1497 *
1498 * @hide
1499 */
1500 public final void setConnectTimeMillis(long connectTimeMillis) {
1501 mConnectTimeMillis = connectTimeMillis;
1502 }
1503
1504 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001505 * Sets the label and icon status to display in the in-call UI.
1506 *
1507 * @param statusHints The status label and icon to set.
1508 */
1509 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001510 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001511 mStatusHints = statusHints;
1512 for (Listener l : mListeners) {
1513 l.onStatusHintsChanged(this, statusHints);
1514 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001515 }
1516
1517 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001518 * Sets the connections with which this connection can be conferenced.
1519 *
1520 * @param conferenceableConnections The set of connections this connection can conference with.
1521 */
1522 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001523 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001524 clearConferenceableList();
1525 for (Connection c : conferenceableConnections) {
1526 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1527 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001528 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001529 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001530 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001531 }
1532 }
1533 fireOnConferenceableConnectionsChanged();
1534 }
1535
1536 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001537 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1538 * or conferences with which this connection can be conferenced.
1539 *
1540 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001541 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001542 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001543 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001544 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001545 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1546 // small amount of items here.
1547 if (!mConferenceables.contains(c)) {
1548 if (c instanceof Connection) {
1549 Connection connection = (Connection) c;
1550 connection.addConnectionListener(mConnectionDeathListener);
1551 } else if (c instanceof Conference) {
1552 Conference conference = (Conference) c;
1553 conference.addListener(mConferenceDeathListener);
1554 }
1555 mConferenceables.add(c);
1556 }
1557 }
1558 fireOnConferenceableConnectionsChanged();
1559 }
1560
1561 /**
1562 * Returns the connections or conferences with which this connection can be conferenced.
1563 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001564 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001565 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001566 }
1567
Evan Charlton8635c572014-09-24 14:04:51 -07001568 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -07001569 * @hide
1570 */
1571 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001572 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001573 if (mConnectionService != null) {
1574 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1575 "which is already associated with another ConnectionService.");
1576 } else {
1577 mConnectionService = connectionService;
1578 }
1579 }
1580
1581 /**
1582 * @hide
1583 */
1584 public final void unsetConnectionService(ConnectionService connectionService) {
1585 if (mConnectionService != connectionService) {
1586 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1587 "that does not belong to the ConnectionService.");
1588 } else {
1589 mConnectionService = null;
1590 }
1591 }
1592
1593 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001594 * @hide
1595 */
1596 public final ConnectionService getConnectionService() {
1597 return mConnectionService;
1598 }
1599
1600 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001601 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001602 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001603 *
1604 * @param conference The conference.
1605 * @return {@code true} if the conference was successfully set.
1606 * @hide
1607 */
1608 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001609 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001610 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001611 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001612 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001613 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1614 fireConferenceChanged();
1615 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001616 return true;
1617 }
1618 return false;
1619 }
1620
1621 /**
1622 * Resets the conference that this connection is a part of.
1623 * @hide
1624 */
1625 public final void resetConference() {
1626 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001627 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001628 mConference = null;
1629 fireConferenceChanged();
1630 }
1631 }
1632
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001633 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001634 * Set some extras that can be associated with this {@code Connection}. No assumptions should
1635 * be made as to how an In-Call UI or service will handle these extras.
1636 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1637 *
1638 * @param extras The extras associated with this {@code Connection}.
1639 */
1640 public final void setExtras(@Nullable Bundle extras) {
1641 checkImmutable();
1642 mExtras = extras;
1643 for (Listener l : mListeners) {
1644 l.onExtrasChanged(this, extras);
1645 }
1646 }
1647
1648 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001649 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001650 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001651 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001652 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
1653 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07001654 */
Yorke Lee4af59352015-05-13 14:14:54 -07001655 @SystemApi
1656 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07001657 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001658
1659 /**
Yorke Lee4af59352015-05-13 14:14:54 -07001660 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
1661 *
1662 * @param state The new connection audio state.
1663 */
1664 public void onCallAudioStateChanged(CallAudioState state) {}
1665
1666 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001667 * Notifies this Connection of an internal state change. This method is called after the
1668 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001669 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001670 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001671 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001672 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001673
1674 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001675 * Notifies this Connection of a request to play a DTMF tone.
1676 *
1677 * @param c A DTMF character.
1678 */
Santos Cordonf2951102014-07-20 19:06:29 -07001679 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001680
1681 /**
1682 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1683 */
Santos Cordonf2951102014-07-20 19:06:29 -07001684 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001685
1686 /**
1687 * Notifies this Connection of a request to disconnect.
1688 */
Santos Cordonf2951102014-07-20 19:06:29 -07001689 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001690
1691 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001692 * Notifies this Connection of a request to disconnect a participant of the conference managed
1693 * by the connection.
1694 *
1695 * @param endpoint the {@link Uri} of the participant to disconnect.
1696 * @hide
1697 */
1698 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1699
1700 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001701 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001702 */
Santos Cordonf2951102014-07-20 19:06:29 -07001703 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001704
1705 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001706 * Notifies this Connection of a request to abort.
1707 */
Santos Cordonf2951102014-07-20 19:06:29 -07001708 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001709
1710 /**
1711 * Notifies this Connection of a request to hold.
1712 */
Santos Cordonf2951102014-07-20 19:06:29 -07001713 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001714
1715 /**
1716 * Notifies this Connection of a request to exit a hold state.
1717 */
Santos Cordonf2951102014-07-20 19:06:29 -07001718 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001719
1720 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001721 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001722 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001723 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001724 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001725 */
Santos Cordonf2951102014-07-20 19:06:29 -07001726 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001727
1728 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001729 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001730 * a request to accept.
1731 */
1732 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07001733 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07001734 }
1735
1736 /**
1737 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001738 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001739 */
Santos Cordonf2951102014-07-20 19:06:29 -07001740 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001741
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001742 /**
1743 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1744 */
Santos Cordonf2951102014-07-20 19:06:29 -07001745 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001746
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001747 static String toLogSafePhoneNumber(String number) {
1748 // For unknown number, log empty string.
1749 if (number == null) {
1750 return "";
1751 }
1752
1753 if (PII_DEBUG) {
1754 // When PII_DEBUG is true we emit PII.
1755 return number;
1756 }
1757
1758 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1759 // sanitized phone numbers.
1760 StringBuilder builder = new StringBuilder();
1761 for (int i = 0; i < number.length(); i++) {
1762 char c = number.charAt(i);
1763 if (c == '-' || c == '@' || c == '.') {
1764 builder.append(c);
1765 } else {
1766 builder.append('x');
1767 }
1768 }
1769 return builder.toString();
1770 }
1771
Ihab Awad542e0ea2014-05-16 10:22:16 -07001772 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001773 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001774 if (mState == STATE_DISCONNECTED && mState != state) {
1775 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001776 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001777 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001778 if (mState != state) {
1779 Log.d(this, "setState: %s", stateToString(state));
1780 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001781 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001782 for (Listener l : mListeners) {
1783 l.onStateChanged(this, state);
1784 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001785 }
1786 }
1787
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001788 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001789 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001790 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1791 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001792 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001793 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001794
1795 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001796 if (mImmutable) {
1797 throw new UnsupportedOperationException("Connection is immutable");
1798 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001799 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001800 }
1801
Evan Charltonbf11f982014-07-20 22:06:28 -07001802 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001803 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001804 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1805 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001806 * <p>
1807 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1808 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001809 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001810 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001811 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001812 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001813 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1814 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001815 }
1816
Evan Charltonbf11f982014-07-20 22:06:28 -07001817 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001818 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1819 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1820 * this should never be un-@hide-den.
1821 *
1822 * @hide
1823 */
1824 public void checkImmutable() {}
1825
1826 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001827 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1828 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1829 * that state. This connection should not be used for anything, and no other
1830 * {@code Connection}s should be attempted.
1831 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001832 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001833 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001834 * @return A {@code Connection} which indicates that the underlying connection should
1835 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001836 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001837 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001838 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001839 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001840
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001841 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001842 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001843 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001844 }
1845 }
1846
Santos Cordon823fd3c2014-08-07 18:35:18 -07001847 private final void fireConferenceChanged() {
1848 for (Listener l : mListeners) {
1849 l.onConferenceChanged(this, mConference);
1850 }
1851 }
1852
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001853 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001854 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001855 if (c instanceof Connection) {
1856 Connection connection = (Connection) c;
1857 connection.removeConnectionListener(mConnectionDeathListener);
1858 } else if (c instanceof Conference) {
1859 Conference conference = (Conference) c;
1860 conference.removeListener(mConferenceDeathListener);
1861 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001862 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001863 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001864 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001865
1866 /**
Anthony Lee17455a32015-04-24 15:25:29 -07001867 * Notifies listeners that the merge request failed.
1868 *
1869 * @hide
1870 */
1871 protected final void notifyConferenceMergeFailed() {
1872 for (Listener l : mListeners) {
1873 l.onConferenceMergeFailed(this);
1874 }
1875 }
1876
1877 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001878 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001879 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001880 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001881 * @hide
1882 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001883 protected final void updateConferenceParticipants(
1884 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001885 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001886 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001887 }
1888 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001889
1890 /**
1891 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07001892 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001893 */
1894 protected void notifyConferenceStarted() {
1895 for (Listener l : mListeners) {
1896 l.onConferenceStarted();
1897 }
1898 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001899}