blob: 93cea97ea5fe5bebffdd10da8fa3e955758247c5 [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
Shriram Ganeshddf570e2015-05-31 09:18:48 -0700255 /**
256 * Call extras key to pack/unpack call history info.
257 * The value for this key should be an ArrayList of Strings.
258 * @hide
259 */
260 public static final String EXTRA_CALL_HISTORY_INFO = "EXTRA_CALL_HISTORY_INFO";
261
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700262 // Flag controlling whether PII is emitted into the logs
263 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
264
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800265 /**
266 * Whether the given capabilities support the specified capability.
267 *
268 * @param capabilities A capability bit field.
269 * @param capability The capability to check capabilities for.
270 * @return Whether the specified capability is supported.
271 * @hide
272 */
273 public static boolean can(int capabilities, int capability) {
274 return (capabilities & capability) != 0;
275 }
276
277 /**
278 * Whether the capabilities of this {@code Connection} supports the specified capability.
279 *
280 * @param capability The capability to check capabilities for.
281 * @return Whether the specified capability is supported.
282 * @hide
283 */
284 public boolean can(int capability) {
285 return can(mConnectionCapabilities, capability);
286 }
287
288 /**
289 * Removes the specified capability from the set of capabilities of this {@code Connection}.
290 *
291 * @param capability The capability to remove from the set.
292 * @hide
293 */
294 public void removeCapability(int capability) {
295 mConnectionCapabilities &= ~capability;
296 }
297
298 /**
299 * Adds the specified capability to the set of capabilities of this {@code Connection}.
300 *
301 * @param capability The capability to add to the set.
302 * @hide
303 */
304 public void addCapability(int capability) {
305 mConnectionCapabilities |= capability;
306 }
307
308
309 public static String capabilitiesToString(int capabilities) {
310 StringBuilder builder = new StringBuilder();
311 builder.append("[Capabilities:");
312 if (can(capabilities, CAPABILITY_HOLD)) {
313 builder.append(" CAPABILITY_HOLD");
314 }
315 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
316 builder.append(" CAPABILITY_SUPPORT_HOLD");
317 }
318 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
319 builder.append(" CAPABILITY_MERGE_CONFERENCE");
320 }
321 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
322 builder.append(" CAPABILITY_SWAP_CONFERENCE");
323 }
324 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
325 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
326 }
327 if (can(capabilities, CAPABILITY_MUTE)) {
328 builder.append(" CAPABILITY_MUTE");
329 }
330 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
331 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
332 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700333 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
334 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
335 }
336 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
337 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
338 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700339 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
340 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800341 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700342 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
343 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
344 }
345 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
346 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
347 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700348 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
349 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800350 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800351 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
352 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800353 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800354 if (can(capabilities, CAPABILITY_WIFI)) {
355 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800356 }
357 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
358 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
359 }
Tyler Gunn068085b2015-02-06 13:56:52 -0800360 if (can(capabilities, CAPABILITY_SHOW_CALLBACK_NUMBER)) {
361 builder.append(" CAPABILITY_SHOW_CALLBACK_NUMBER");
362 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500363 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700364 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500365 }
Rekha Kumar07366812015-03-24 16:42:31 -0700366 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
367 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
368 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700369 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
370 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
371 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700372 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
373 builder.append(" CAPABILITY_SINGLE_PARTY_CONFERENCE");
374 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800375 builder.append("]");
376 return builder.toString();
377 }
378
Sailesh Nepal091768c2014-06-30 15:15:23 -0700379 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700380 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700381 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700382 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700383 public void onCallerDisplayNameChanged(
384 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700385 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700386 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700387 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800388 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700389 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700390 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800391 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700392 public void onVideoProviderChanged(
393 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700394 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
395 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800396 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700397 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700398 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700399 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800400 public void onConferenceParticipantsChanged(Connection c,
401 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800402 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700403 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700404 public void onExtrasChanged(Connection c, Bundle extras) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700405 }
406
Tyler Gunnb702ef82015-05-29 11:51:53 -0700407 /**
408 * Provides a means of controlling the video session associated with a {@link Connection}.
409 * <p>
410 * Implementations create a custom subclass of {@link VideoProvider} and the
411 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
412 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
413 * should set the {@link VideoProvider}.
414 * <p>
415 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
416 * {@link InCallService} implementations to issue requests related to the video session;
417 * it provides a means for the {@link ConnectionService} to report events and information
418 * related to the video session to Telecom and the {@link InCallService} implementations.
419 * <p>
420 * {@link InCallService} implementations interact with the {@link VideoProvider} via
421 * {@link android.telecom.InCallService.VideoCall}.
422 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700423 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700424
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700425 /**
426 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700427 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700428 */
429 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700430
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700431 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700432 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
433 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700434 */
435 public static final int SESSION_EVENT_RX_RESUME = 2;
436
437 /**
438 * Video transmission has begun. This occurs after a negotiated start of video transmission
439 * when the underlying protocol has actually begun 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_START = 3;
443
444 /**
445 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
446 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700447 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700448 */
449 public static final int SESSION_EVENT_TX_STOP = 4;
450
451 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700452 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
453 * this as a cue to inform the user the camera is not available.
454 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700455 */
456 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
457
458 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700459 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
460 * for operation. The {@link InCallService} can use this as a cue to inform the user that
461 * the camera has become available again.
462 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700463 */
464 public static final int SESSION_EVENT_CAMERA_READY = 6;
465
466 /**
467 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700468 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700469 */
470 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
471
472 /**
473 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700474 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700475 */
476 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
477
478 /**
479 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700480 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700481 */
482 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
483
Rekha Kumar07366812015-03-24 16:42:31 -0700484 /**
485 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700486 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700487 */
488 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
489
490 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700491 * Session modify request rejected by remote user.
492 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700493 */
494 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
495
Tyler Gunn75958422015-04-15 14:23:42 -0700496 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700497 private static final int MSG_SET_CAMERA = 2;
498 private static final int MSG_SET_PREVIEW_SURFACE = 3;
499 private static final int MSG_SET_DISPLAY_SURFACE = 4;
500 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
501 private static final int MSG_SET_ZOOM = 6;
502 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
503 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
504 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800505 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700506 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700507 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700508
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700509 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700510 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700511
512 /**
513 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700514 *
515 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
516 * load factor before resizing, 1 means we only expect a single thread to
517 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700518 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700519 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
520 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700521
522 /**
523 * Default handler used to consolidate binder method calls onto a single thread.
524 */
525 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700526 public VideoProviderHandler() {
527 super();
528 }
529
530 public VideoProviderHandler(Looper looper) {
531 super(looper);
532 }
533
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700534 @Override
535 public void handleMessage(Message msg) {
536 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700537 case MSG_ADD_VIDEO_CALLBACK: {
538 IBinder binder = (IBinder) msg.obj;
539 IVideoCallback callback = IVideoCallback.Stub
540 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700541 if (callback == null) {
542 Log.w(this, "addVideoProvider - skipped; callback is null.");
543 break;
544 }
545
Tyler Gunn75958422015-04-15 14:23:42 -0700546 if (mVideoCallbacks.containsKey(binder)) {
547 Log.i(this, "addVideoProvider - skipped; already present.");
548 break;
549 }
550 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700551 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700552 }
553 case MSG_REMOVE_VIDEO_CALLBACK: {
554 IBinder binder = (IBinder) msg.obj;
555 IVideoCallback callback = IVideoCallback.Stub
556 .asInterface((IBinder) msg.obj);
557 if (!mVideoCallbacks.containsKey(binder)) {
558 Log.i(this, "removeVideoProvider - skipped; not present.");
559 break;
560 }
561 mVideoCallbacks.remove(binder);
562 break;
563 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700564 case MSG_SET_CAMERA:
565 onSetCamera((String) msg.obj);
566 break;
567 case MSG_SET_PREVIEW_SURFACE:
568 onSetPreviewSurface((Surface) msg.obj);
569 break;
570 case MSG_SET_DISPLAY_SURFACE:
571 onSetDisplaySurface((Surface) msg.obj);
572 break;
573 case MSG_SET_DEVICE_ORIENTATION:
574 onSetDeviceOrientation(msg.arg1);
575 break;
576 case MSG_SET_ZOOM:
577 onSetZoom((Float) msg.obj);
578 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700579 case MSG_SEND_SESSION_MODIFY_REQUEST: {
580 SomeArgs args = (SomeArgs) msg.obj;
581 try {
582 onSendSessionModifyRequest((VideoProfile) args.arg1,
583 (VideoProfile) args.arg2);
584 } finally {
585 args.recycle();
586 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700587 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700588 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700589 case MSG_SEND_SESSION_MODIFY_RESPONSE:
590 onSendSessionModifyResponse((VideoProfile) msg.obj);
591 break;
592 case MSG_REQUEST_CAMERA_CAPABILITIES:
593 onRequestCameraCapabilities();
594 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800595 case MSG_REQUEST_CONNECTION_DATA_USAGE:
596 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700597 break;
598 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700599 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700600 break;
601 default:
602 break;
603 }
604 }
605 }
606
607 /**
608 * IVideoProvider stub implementation.
609 */
610 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700611 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700612 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700613 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
614 }
615
616 public void removeVideoCallback(IBinder videoCallbackBinder) {
617 mMessageHandler.obtainMessage(
618 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700619 }
620
621 public void setCamera(String cameraId) {
622 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
623 }
624
625 public void setPreviewSurface(Surface surface) {
626 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
627 }
628
629 public void setDisplaySurface(Surface surface) {
630 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
631 }
632
633 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700634 mMessageHandler.obtainMessage(
635 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700636 }
637
638 public void setZoom(float value) {
639 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
640 }
641
Tyler Gunn45382162015-05-06 08:52:27 -0700642 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
643 SomeArgs args = SomeArgs.obtain();
644 args.arg1 = fromProfile;
645 args.arg2 = toProfile;
646 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700647 }
648
649 public void sendSessionModifyResponse(VideoProfile responseProfile) {
650 mMessageHandler.obtainMessage(
651 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
652 }
653
654 public void requestCameraCapabilities() {
655 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
656 }
657
658 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800659 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700660 }
661
Yorke Lee32f24732015-05-12 16:18:03 -0700662 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700663 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
664 }
665 }
666
667 public VideoProvider() {
668 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700669 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700670 }
671
672 /**
673 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
674 *
675 * @param looper The looper.
676 * @hide
677 */
678 public VideoProvider(Looper looper) {
679 mBinder = new VideoProvider.VideoProviderBinder();
680 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700681 }
682
683 /**
684 * Returns binder object which can be used across IPC methods.
685 * @hide
686 */
687 public final IVideoProvider getInterface() {
688 return mBinder;
689 }
690
691 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700692 * Sets the camera to be used for the outgoing video.
693 * <p>
694 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
695 * camera via
696 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
697 * <p>
698 * Sent from the {@link InCallService} via
699 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700700 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700701 * @param cameraId The id of the camera (use ids as reported by
702 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700703 */
704 public abstract void onSetCamera(String cameraId);
705
706 /**
707 * Sets the surface to be used for displaying a preview of what the user's camera is
708 * currently capturing. When video transmission is enabled, this is the video signal which
709 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700710 * <p>
711 * Sent from the {@link InCallService} via
712 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700713 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700714 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700715 */
716 public abstract void onSetPreviewSurface(Surface surface);
717
718 /**
719 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700720 * <p>
721 * Sent from the {@link InCallService} via
722 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700723 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700724 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700725 */
726 public abstract void onSetDisplaySurface(Surface surface);
727
728 /**
729 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
730 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700731 * <p>
732 * Sent from the {@link InCallService} via
733 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700734 *
735 * @param rotation The device orientation, in degrees.
736 */
737 public abstract void onSetDeviceOrientation(int rotation);
738
739 /**
740 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700741 * <p>
742 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700743 *
744 * @param value The camera zoom ratio.
745 */
746 public abstract void onSetZoom(float value);
747
748 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700749 * Issues a request to modify the properties of the current video session.
750 * <p>
751 * Example scenarios include: requesting an audio-only call to be upgraded to a
752 * bi-directional video call, turning on or off the user's camera, sending a pause signal
753 * when the {@link InCallService} is no longer the foreground application.
754 * <p>
755 * If the {@link VideoProvider} determines a request to be invalid, it should call
756 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
757 * invalid request back to the {@link InCallService}.
758 * <p>
759 * Where a request requires confirmation from the user of the peer device, the
760 * {@link VideoProvider} must communicate the request to the peer device and handle the
761 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
762 * is used to inform the {@link InCallService} of the result of the request.
763 * <p>
764 * Sent from the {@link InCallService} via
765 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700766 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700767 * @param fromProfile The video profile prior to the request.
768 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700769 */
Tyler Gunn45382162015-05-06 08:52:27 -0700770 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
771 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700772
Tyler Gunnb702ef82015-05-29 11:51:53 -0700773 /**
774 * Provides a response to a request to change the current video session properties.
775 * <p>
776 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
777 * video call, could decline the request and keep the call as audio-only.
778 * In such a scenario, the {@code responseProfile} would have a video state of
779 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
780 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
781 * <p>
782 * Sent from the {@link InCallService} via
783 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
784 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
785 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700786 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700787 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700788 */
789 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
790
791 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700792 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
793 * <p>
794 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
795 * camera via
796 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
797 * <p>
798 * Sent from the {@link InCallService} via
799 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700800 */
801 public abstract void onRequestCameraCapabilities();
802
803 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700804 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
805 * video component of the current {@link Connection}.
806 * <p>
807 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
808 * via {@link VideoProvider#setCallDataUsage(long)}.
809 * <p>
810 * Sent from the {@link InCallService} via
811 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700812 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800813 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700814
815 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700816 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
817 * the peer device when the video signal is paused.
818 * <p>
819 * Sent from the {@link InCallService} via
820 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700821 *
822 * @param uri URI of image to display.
823 */
Yorke Lee32f24732015-05-12 16:18:03 -0700824 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700825
826 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700827 * Used to inform listening {@link InCallService} implementations when the
828 * {@link VideoProvider} receives a session modification request.
829 * <p>
830 * Received by the {@link InCallService} via
831 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700832 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700833 * @param videoProfile The requested video profile.
834 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700835 */
836 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700837 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700838 for (IVideoCallback callback : mVideoCallbacks.values()) {
839 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700840 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700841 } catch (RemoteException ignored) {
842 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700843 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700844 }
845 }
846 }
847
848 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700849 * Used to inform listening {@link InCallService} implementations when the
850 * {@link VideoProvider} receives a response to a session modification request.
851 * <p>
852 * Received by the {@link InCallService} via
853 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
854 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700855 *
856 * @param status Status of the session modify request. Valid values are
857 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
858 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -0700859 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
860 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
861 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
862 * @param requestedProfile The original request which was sent to the peer device.
863 * @param responseProfile The actual profile changes agreed to by the peer device.
864 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700865 */
866 public void receiveSessionModifyResponse(int status,
867 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700868 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700869 for (IVideoCallback callback : mVideoCallbacks.values()) {
870 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700871 callback.receiveSessionModifyResponse(status, requestedProfile,
872 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700873 } catch (RemoteException ignored) {
874 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700875 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700876 }
877 }
878 }
879
880 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700881 * Used to inform listening {@link InCallService} implementations when the
882 * {@link VideoProvider} reports a call session event.
883 * <p>
884 * Received by the {@link InCallService} via
885 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700886 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700887 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
888 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
889 * {@link VideoProvider#SESSION_EVENT_TX_START},
890 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
891 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
892 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700893 */
894 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -0700895 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700896 for (IVideoCallback callback : mVideoCallbacks.values()) {
897 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700898 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700899 } catch (RemoteException ignored) {
900 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700901 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700902 }
903 }
904 }
905
906 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700907 * Used to inform listening {@link InCallService} implementations when the dimensions of the
908 * peer's video have changed.
909 * <p>
910 * This could occur if, for example, the peer rotates their device, changing the aspect
911 * ratio of the video, or if the user switches between the back and front cameras.
912 * <p>
913 * Received by the {@link InCallService} via
914 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700915 *
916 * @param width The updated peer video width.
917 * @param height The updated peer video height.
918 */
919 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -0700920 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700921 for (IVideoCallback callback : mVideoCallbacks.values()) {
922 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700923 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700924 } catch (RemoteException ignored) {
925 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700926 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700927 }
928 }
929 }
930
931 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700932 * Used to inform listening {@link InCallService} implementations when the data usage of the
933 * video associated with the current {@link Connection} has changed.
934 * <p>
935 * This could be in response to a preview request via
936 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -0700937 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
938 * 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 -0700939 * <p>
940 * Received by the {@link InCallService} via
941 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700942 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700943 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
944 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700945 */
Yorke Lee32f24732015-05-12 16:18:03 -0700946 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -0700947 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700948 for (IVideoCallback callback : mVideoCallbacks.values()) {
949 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700950 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700951 } catch (RemoteException ignored) {
952 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700953 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700954 }
955 }
956 }
957
958 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700959 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700960 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700961 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -0700962 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
963 * @hide
964 */
965 public void changeCallDataUsage(long dataUsage) {
966 setCallDataUsage(dataUsage);
967 }
968
969 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700970 * Used to inform listening {@link InCallService} implementations when the capabilities of
971 * the current camera have changed.
972 * <p>
973 * The {@link VideoProvider} should call this in response to
974 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
975 * changed via {@link VideoProvider#onSetCamera(String)}.
976 * <p>
977 * Received by the {@link InCallService} via
978 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
979 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -0700980 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700981 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700982 */
Yorke Lee400470f2015-05-12 13:31:25 -0700983 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -0700984 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700985 for (IVideoCallback callback : mVideoCallbacks.values()) {
986 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700987 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700988 } catch (RemoteException ignored) {
989 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700990 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700991 }
992 }
993 }
Rekha Kumar07366812015-03-24 16:42:31 -0700994
995 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700996 * Used to inform listening {@link InCallService} implementations when the video quality
997 * of the call has changed.
998 * <p>
999 * Received by the {@link InCallService} via
1000 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001001 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001002 * @param videoQuality The updated video quality. Valid values:
1003 * {@link VideoProfile#QUALITY_HIGH},
1004 * {@link VideoProfile#QUALITY_MEDIUM},
1005 * {@link VideoProfile#QUALITY_LOW},
1006 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001007 */
1008 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001009 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001010 for (IVideoCallback callback : mVideoCallbacks.values()) {
1011 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001012 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001013 } catch (RemoteException ignored) {
1014 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001015 }
Rekha Kumar07366812015-03-24 16:42:31 -07001016 }
1017 }
1018 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001019 }
1020
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001021 private final Listener mConnectionDeathListener = new Listener() {
1022 @Override
1023 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001024 if (mConferenceables.remove(c)) {
1025 fireOnConferenceableConnectionsChanged();
1026 }
1027 }
1028 };
1029
1030 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1031 @Override
1032 public void onDestroyed(Conference c) {
1033 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001034 fireOnConferenceableConnectionsChanged();
1035 }
1036 }
1037 };
1038
Jay Shrauner229e3822014-08-15 09:23:07 -07001039 /**
1040 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1041 * load factor before resizing, 1 means we only expect a single thread to
1042 * access the map so make only a single shard
1043 */
1044 private final Set<Listener> mListeners = Collections.newSetFromMap(
1045 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001046 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1047 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001048 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001049
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001050 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001051 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001052 private Uri mAddress;
1053 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001054 private String mCallerDisplayName;
1055 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001056 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001057 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001058 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001059 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001060 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001061 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001062 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001063 private Conference mConference;
1064 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001065 private Bundle mExtras;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001066
1067 /**
1068 * Create a new Connection.
1069 */
Santos Cordonf2951102014-07-20 19:06:29 -07001070 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001071
1072 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001073 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001074 */
Andrew Lee100e2932014-09-08 15:34:24 -07001075 public final Uri getAddress() {
1076 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001077 }
1078
1079 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001080 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001081 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001082 */
Andrew Lee100e2932014-09-08 15:34:24 -07001083 public final int getAddressPresentation() {
1084 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001085 }
1086
1087 /**
1088 * @return The caller display name (CNAP).
1089 */
1090 public final String getCallerDisplayName() {
1091 return mCallerDisplayName;
1092 }
1093
1094 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001095 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001096 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001097 */
1098 public final int getCallerDisplayNamePresentation() {
1099 return mCallerDisplayNamePresentation;
1100 }
1101
1102 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001103 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001104 */
1105 public final int getState() {
1106 return mState;
1107 }
1108
1109 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001110 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001111 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1112 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1113 * {@link VideoProfile#STATE_TX_ENABLED},
1114 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001115 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001116 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001117 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001118 */
1119 public final int getVideoState() {
1120 return mVideoState;
1121 }
1122
1123 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001124 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001125 * being routed by the system. This is {@code null} if this Connection
1126 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001127 * @deprecated Use {@link #getCallAudioState()} instead.
1128 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001129 */
Yorke Lee4af59352015-05-13 14:14:54 -07001130 @SystemApi
1131 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001132 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001133 if (mCallAudioState == null) {
1134 return null;
1135 }
Yorke Lee4af59352015-05-13 14:14:54 -07001136 return new AudioState(mCallAudioState);
1137 }
1138
1139 /**
1140 * @return The audio state of the connection, describing how its audio is currently
1141 * being routed by the system. This is {@code null} if this Connection
1142 * does not directly know about its audio state.
1143 */
1144 public final CallAudioState getCallAudioState() {
1145 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001146 }
1147
1148 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001149 * @return The conference that this connection is a part of. Null if it is not part of any
1150 * conference.
1151 */
1152 public final Conference getConference() {
1153 return mConference;
1154 }
1155
1156 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001157 * Returns whether this connection is requesting that the system play a ringback tone
1158 * on its behalf.
1159 */
Andrew Lee100e2932014-09-08 15:34:24 -07001160 public final boolean isRingbackRequested() {
1161 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001162 }
1163
1164 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001165 * @return True if the connection's audio mode is VOIP.
1166 */
1167 public final boolean getAudioModeIsVoip() {
1168 return mAudioModeIsVoip;
1169 }
1170
1171 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001172 * @return The status hints for this connection.
1173 */
1174 public final StatusHints getStatusHints() {
1175 return mStatusHints;
1176 }
1177
1178 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001179 * @return The extras associated with this connection.
1180 */
1181 public final Bundle getExtras() {
1182 return mExtras;
1183 }
1184
1185 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001186 * Assign a listener to be notified of state changes.
1187 *
1188 * @param l A listener.
1189 * @return This Connection.
1190 *
1191 * @hide
1192 */
1193 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001194 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001195 return this;
1196 }
1197
1198 /**
1199 * Remove a previously assigned listener that was being notified of state changes.
1200 *
1201 * @param l A Listener.
1202 * @return This Connection.
1203 *
1204 * @hide
1205 */
1206 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001207 if (l != null) {
1208 mListeners.remove(l);
1209 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001210 return this;
1211 }
1212
1213 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001214 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001215 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001216 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001217 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001218 }
1219
1220 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001221 * Inform this Connection that the state of its audio output has been changed externally.
1222 *
1223 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001224 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001225 */
Yorke Lee4af59352015-05-13 14:14:54 -07001226 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001227 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001228 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001229 mCallAudioState = state;
1230 onAudioStateChanged(getAudioState());
1231 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001232 }
1233
1234 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001235 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001236 * @return A string representation of the value.
1237 */
1238 public static String stateToString(int state) {
1239 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001240 case STATE_INITIALIZING:
1241 return "STATE_INITIALIZING";
1242 case STATE_NEW:
1243 return "STATE_NEW";
1244 case STATE_RINGING:
1245 return "STATE_RINGING";
1246 case STATE_DIALING:
1247 return "STATE_DIALING";
1248 case STATE_ACTIVE:
1249 return "STATE_ACTIVE";
1250 case STATE_HOLDING:
1251 return "STATE_HOLDING";
1252 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001253 return "DISCONNECTED";
1254 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001255 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001256 return "UNKNOWN";
1257 }
1258 }
1259
1260 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001261 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001262 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001263 public final int getConnectionCapabilities() {
1264 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001265 }
1266
1267 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001268 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001269 *
Andrew Lee100e2932014-09-08 15:34:24 -07001270 * @param address The new address.
1271 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001272 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001273 */
Andrew Lee100e2932014-09-08 15:34:24 -07001274 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001275 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001276 Log.d(this, "setAddress %s", address);
1277 mAddress = address;
1278 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001279 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001280 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001281 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001282 }
1283
1284 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001285 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001286 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001287 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001288 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001289 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001290 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001291 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001292 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001293 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001294 mCallerDisplayName = callerDisplayName;
1295 mCallerDisplayNamePresentation = presentation;
1296 for (Listener l : mListeners) {
1297 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1298 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001299 }
1300
1301 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001302 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001303 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1304 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1305 * {@link VideoProfile#STATE_TX_ENABLED},
1306 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001307 *
1308 * @param videoState The new video state.
1309 */
1310 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001311 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001312 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001313 mVideoState = videoState;
1314 for (Listener l : mListeners) {
1315 l.onVideoStateChanged(this, mVideoState);
1316 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001317 }
1318
1319 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001320 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001321 * communicate).
1322 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001323 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001324 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001325 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001326 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001327 }
1328
1329 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001330 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001331 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001332 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001333 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001334 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001335 }
1336
1337 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001338 * Sets state to initializing (this Connection is not yet ready to be used).
1339 */
1340 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001341 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001342 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001343 }
1344
1345 /**
1346 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1347 */
1348 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001349 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001350 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001351 }
1352
1353 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001354 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001355 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001356 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001357 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001358 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001359 }
1360
1361 /**
1362 * Sets state to be on hold.
1363 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001364 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001365 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001366 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001367 }
1368
1369 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001370 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001371 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001372 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001373 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001374 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001375 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001376 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001377 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001378 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001379 }
1380
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001381 public final VideoProvider getVideoProvider() {
1382 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001383 }
1384
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001385 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001386 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001387 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001388 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001389 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001390 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001391 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001392 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001393 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001394 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001395 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001396 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001397 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001398 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001399 }
1400
1401 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001402 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1403 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1404 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1405 * to send an {@link #onPostDialContinue(boolean)} signal.
1406 *
1407 * @param remaining The DTMF character sequence remaining to be emitted once the
1408 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1409 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001410 */
1411 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001412 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001413 for (Listener l : mListeners) {
1414 l.onPostDialWait(this, remaining);
1415 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001416 }
1417
1418 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001419 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1420 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001421 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001422 *
1423 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001424 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001425 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001426 checkImmutable();
1427 for (Listener l : mListeners) {
1428 l.onPostDialChar(this, nextChar);
1429 }
1430 }
1431
1432 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001433 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001434 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001435 *
1436 * @param ringback Whether the ringback tone is to be played.
1437 */
Andrew Lee100e2932014-09-08 15:34:24 -07001438 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001439 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001440 if (mRingbackRequested != ringback) {
1441 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001442 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001443 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001444 }
1445 }
Ihab Awadf8358972014-05-28 16:46:42 -07001446 }
1447
1448 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001449 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001450 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001451 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001452 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001453 public final void setConnectionCapabilities(int connectionCapabilities) {
1454 checkImmutable();
1455 if (mConnectionCapabilities != connectionCapabilities) {
1456 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001457 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001458 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001459 }
1460 }
Santos Cordonb6939982014-06-04 20:20:58 -07001461 }
1462
1463 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001464 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001465 */
Evan Charlton36a71342014-07-19 16:31:02 -07001466 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001467 for (Listener l : mListeners) {
1468 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001469 }
Santos Cordonb6939982014-06-04 20:20:58 -07001470 }
1471
1472 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001473 * Requests that the framework use VOIP audio mode for this connection.
1474 *
1475 * @param isVoip True if the audio mode is VOIP.
1476 */
1477 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001478 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001479 mAudioModeIsVoip = isVoip;
1480 for (Listener l : mListeners) {
1481 l.onAudioModeIsVoipChanged(this, isVoip);
1482 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001483 }
1484
1485 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001486 * Sets the label and icon status to display in the in-call UI.
1487 *
1488 * @param statusHints The status label and icon to set.
1489 */
1490 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001491 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001492 mStatusHints = statusHints;
1493 for (Listener l : mListeners) {
1494 l.onStatusHintsChanged(this, statusHints);
1495 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001496 }
1497
1498 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001499 * Sets the connections with which this connection can be conferenced.
1500 *
1501 * @param conferenceableConnections The set of connections this connection can conference with.
1502 */
1503 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001504 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001505 clearConferenceableList();
1506 for (Connection c : conferenceableConnections) {
1507 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1508 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001509 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001510 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001511 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001512 }
1513 }
1514 fireOnConferenceableConnectionsChanged();
1515 }
1516
1517 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001518 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1519 * or conferences with which this connection can be conferenced.
1520 *
1521 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001522 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001523 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001524 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001525 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001526 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1527 // small amount of items here.
1528 if (!mConferenceables.contains(c)) {
1529 if (c instanceof Connection) {
1530 Connection connection = (Connection) c;
1531 connection.addConnectionListener(mConnectionDeathListener);
1532 } else if (c instanceof Conference) {
1533 Conference conference = (Conference) c;
1534 conference.addListener(mConferenceDeathListener);
1535 }
1536 mConferenceables.add(c);
1537 }
1538 }
1539 fireOnConferenceableConnectionsChanged();
1540 }
1541
1542 /**
1543 * Returns the connections or conferences with which this connection can be conferenced.
1544 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001545 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001546 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001547 }
1548
Evan Charlton8635c572014-09-24 14:04:51 -07001549 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -07001550 * @hide
1551 */
1552 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001553 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001554 if (mConnectionService != null) {
1555 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1556 "which is already associated with another ConnectionService.");
1557 } else {
1558 mConnectionService = connectionService;
1559 }
1560 }
1561
1562 /**
1563 * @hide
1564 */
1565 public final void unsetConnectionService(ConnectionService connectionService) {
1566 if (mConnectionService != connectionService) {
1567 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1568 "that does not belong to the ConnectionService.");
1569 } else {
1570 mConnectionService = null;
1571 }
1572 }
1573
1574 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001575 * @hide
1576 */
1577 public final ConnectionService getConnectionService() {
1578 return mConnectionService;
1579 }
1580
1581 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001582 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001583 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001584 *
1585 * @param conference The conference.
1586 * @return {@code true} if the conference was successfully set.
1587 * @hide
1588 */
1589 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001590 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001591 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001592 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001593 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001594 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1595 fireConferenceChanged();
1596 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001597 return true;
1598 }
1599 return false;
1600 }
1601
1602 /**
1603 * Resets the conference that this connection is a part of.
1604 * @hide
1605 */
1606 public final void resetConference() {
1607 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001608 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001609 mConference = null;
1610 fireConferenceChanged();
1611 }
1612 }
1613
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001614 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001615 * Set some extras that can be associated with this {@code Connection}. No assumptions should
1616 * be made as to how an In-Call UI or service will handle these extras.
1617 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1618 *
1619 * @param extras The extras associated with this {@code Connection}.
1620 */
1621 public final void setExtras(@Nullable Bundle extras) {
1622 checkImmutable();
1623 mExtras = extras;
1624 for (Listener l : mListeners) {
1625 l.onExtrasChanged(this, extras);
1626 }
1627 }
1628
1629 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001630 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001631 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001632 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001633 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
1634 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07001635 */
Yorke Lee4af59352015-05-13 14:14:54 -07001636 @SystemApi
1637 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07001638 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001639
1640 /**
Yorke Lee4af59352015-05-13 14:14:54 -07001641 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
1642 *
1643 * @param state The new connection audio state.
1644 */
1645 public void onCallAudioStateChanged(CallAudioState state) {}
1646
1647 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001648 * Notifies this Connection of an internal state change. This method is called after the
1649 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001650 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001651 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001652 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001653 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001654
1655 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001656 * Notifies this Connection of a request to play a DTMF tone.
1657 *
1658 * @param c A DTMF character.
1659 */
Santos Cordonf2951102014-07-20 19:06:29 -07001660 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001661
1662 /**
1663 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1664 */
Santos Cordonf2951102014-07-20 19:06:29 -07001665 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001666
1667 /**
1668 * Notifies this Connection of a request to disconnect.
1669 */
Santos Cordonf2951102014-07-20 19:06:29 -07001670 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001671
1672 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001673 * Notifies this Connection of a request to disconnect a participant of the conference managed
1674 * by the connection.
1675 *
1676 * @param endpoint the {@link Uri} of the participant to disconnect.
1677 * @hide
1678 */
1679 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1680
1681 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001682 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001683 */
Santos Cordonf2951102014-07-20 19:06:29 -07001684 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001685
1686 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001687 * Notifies this Connection of a request to abort.
1688 */
Santos Cordonf2951102014-07-20 19:06:29 -07001689 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001690
1691 /**
1692 * Notifies this Connection of a request to hold.
1693 */
Santos Cordonf2951102014-07-20 19:06:29 -07001694 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001695
1696 /**
1697 * Notifies this Connection of a request to exit a hold state.
1698 */
Santos Cordonf2951102014-07-20 19:06:29 -07001699 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001700
1701 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001702 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001703 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001704 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001705 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001706 */
Santos Cordonf2951102014-07-20 19:06:29 -07001707 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001708
1709 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001710 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001711 * a request to accept.
1712 */
1713 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07001714 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07001715 }
1716
1717 /**
1718 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001719 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001720 */
Santos Cordonf2951102014-07-20 19:06:29 -07001721 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001722
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001723 /**
1724 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1725 */
Santos Cordonf2951102014-07-20 19:06:29 -07001726 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001727
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001728 static String toLogSafePhoneNumber(String number) {
1729 // For unknown number, log empty string.
1730 if (number == null) {
1731 return "";
1732 }
1733
1734 if (PII_DEBUG) {
1735 // When PII_DEBUG is true we emit PII.
1736 return number;
1737 }
1738
1739 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1740 // sanitized phone numbers.
1741 StringBuilder builder = new StringBuilder();
1742 for (int i = 0; i < number.length(); i++) {
1743 char c = number.charAt(i);
1744 if (c == '-' || c == '@' || c == '.') {
1745 builder.append(c);
1746 } else {
1747 builder.append('x');
1748 }
1749 }
1750 return builder.toString();
1751 }
1752
Ihab Awad542e0ea2014-05-16 10:22:16 -07001753 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001754 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001755 if (mState == STATE_DISCONNECTED && mState != state) {
1756 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001757 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001758 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001759 if (mState != state) {
1760 Log.d(this, "setState: %s", stateToString(state));
1761 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001762 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001763 for (Listener l : mListeners) {
1764 l.onStateChanged(this, state);
1765 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001766 }
1767 }
1768
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001769 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001770 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001771 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1772 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001773 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001774 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001775
1776 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001777 if (mImmutable) {
1778 throw new UnsupportedOperationException("Connection is immutable");
1779 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001780 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001781 }
1782
Evan Charltonbf11f982014-07-20 22:06:28 -07001783 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001784 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001785 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1786 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001787 * <p>
1788 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1789 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001790 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001791 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001792 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001793 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001794 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1795 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001796 }
1797
Evan Charltonbf11f982014-07-20 22:06:28 -07001798 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001799 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1800 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1801 * this should never be un-@hide-den.
1802 *
1803 * @hide
1804 */
1805 public void checkImmutable() {}
1806
1807 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001808 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1809 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1810 * that state. This connection should not be used for anything, and no other
1811 * {@code Connection}s should be attempted.
1812 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001813 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001814 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001815 * @return A {@code Connection} which indicates that the underlying connection should
1816 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001817 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001818 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001819 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001820 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001821
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001822 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001823 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001824 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001825 }
1826 }
1827
Santos Cordon823fd3c2014-08-07 18:35:18 -07001828 private final void fireConferenceChanged() {
1829 for (Listener l : mListeners) {
1830 l.onConferenceChanged(this, mConference);
1831 }
1832 }
1833
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001834 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001835 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001836 if (c instanceof Connection) {
1837 Connection connection = (Connection) c;
1838 connection.removeConnectionListener(mConnectionDeathListener);
1839 } else if (c instanceof Conference) {
1840 Conference conference = (Conference) c;
1841 conference.removeListener(mConferenceDeathListener);
1842 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001843 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001844 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001845 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001846
1847 /**
Anthony Lee17455a32015-04-24 15:25:29 -07001848 * Notifies listeners that the merge request failed.
1849 *
1850 * @hide
1851 */
1852 protected final void notifyConferenceMergeFailed() {
1853 for (Listener l : mListeners) {
1854 l.onConferenceMergeFailed(this);
1855 }
1856 }
1857
1858 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001859 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001860 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001861 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001862 * @hide
1863 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001864 protected final void updateConferenceParticipants(
1865 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001866 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001867 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001868 }
1869 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001870
1871 /**
1872 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07001873 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001874 */
1875 protected void notifyConferenceStarted() {
1876 for (Listener l : mListeners) {
1877 l.onConferenceStarted();
1878 }
1879 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001880}