blob: 6055211a600ab42e38f90f65079304233f0eda3f [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;
Tyler Gunn75958422015-04-15 14:23:42 -070037import java.util.HashMap;
Santos Cordonb6939982014-06-04 20:20:58 -070038import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070039import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070040import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070041
42/**
43 * Represents a connection to a remote endpoint that carries voice 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
Ihab Awadb19a0bc2014-08-07 19:46:01 -070056 public static final int STATE_INITIALIZING = 0;
57
58 public static final int STATE_NEW = 1;
59
60 public static final int STATE_RINGING = 2;
61
62 public static final int STATE_DIALING = 3;
63
64 public static final int STATE_ACTIVE = 4;
65
66 public static final int STATE_HOLDING = 5;
67
68 public static final int STATE_DISCONNECTED = 6;
69
Ihab Awad5c9c86e2014-11-12 13:41:16 -080070 /** Connection can currently be put on hold or unheld. */
71 public static final int CAPABILITY_HOLD = 0x00000001;
72
73 /** Connection supports the hold feature. */
74 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
75
76 /**
77 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
78 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
79 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
80 * capability allows a merge button to be shown while the conference is in the foreground
81 * of the in-call UI.
82 * <p>
83 * This is only intended for use by a {@link Conference}.
84 */
85 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
86
87 /**
88 * Connections within a conference can be swapped between foreground and background.
89 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
90 * <p>
91 * This is only intended for use by a {@link Conference}.
92 */
93 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
94
95 /**
96 * @hide
97 */
98 public static final int CAPABILITY_UNUSED = 0x00000010;
99
100 /** Connection supports responding via text option. */
101 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
102
103 /** Connection can be muted. */
104 public static final int CAPABILITY_MUTE = 0x00000040;
105
106 /**
107 * Connection supports conference management. This capability only applies to
108 * {@link Conference}s which can have {@link Connection}s as children.
109 */
110 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
111
112 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700113 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800114 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700115 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800116
117 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700118 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800119 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700120 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800121
122 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700123 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800124 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700125 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700126 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800127
128 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700129 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800130 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700131 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
132
133 /**
134 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700135 */
136 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
137
138 /**
139 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700140 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700141 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700142 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800143
144 /**
145 * Connection is able to be separated from its parent {@code Conference}, if any.
146 */
147 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
148
149 /**
150 * Connection is able to be individually disconnected when in a {@code Conference}.
151 */
152 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
153
154 /**
155 * Whether the call is a generic conference, where we do not know the precise state of
156 * participants in the conference (eg. on CDMA).
157 *
158 * @hide
159 */
160 public static final int CAPABILITY_GENERIC_CONFERENCE = 0x00004000;
161
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700162 /**
163 * Connection is using high definition audio.
164 * @hide
165 */
166 public static final int CAPABILITY_HIGH_DEF_AUDIO = 0x00008000;
167
168 /**
169 * Connection is using WIFI.
170 * @hide
171 */
Tyler Gunnd11a3152015-03-18 13:09:14 -0700172 public static final int CAPABILITY_WIFI = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700173
Tyler Gunn068085b2015-02-06 13:56:52 -0800174 /**
175 * Indicates that the current device callback number should be shown.
176 *
177 * @hide
178 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700179 public static final int CAPABILITY_SHOW_CALLBACK_NUMBER = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800180
Tyler Gunn96d6c402015-03-18 12:39:23 -0700181 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500182 * Speed up audio setup for MT call.
183 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700184 */
185 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800186
Rekha Kumar07366812015-03-24 16:42:31 -0700187 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700188 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700189 */
190 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
191
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700192 /**
193 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700194 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700195 */
196 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
197
Tyler Gunn96d6c402015-03-18 12:39:23 -0700198 //**********************************************************************************************
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700199 // Next CAPABILITY value: 0x00200000
Tyler Gunn96d6c402015-03-18 12:39:23 -0700200 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800201
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700202 // Flag controlling whether PII is emitted into the logs
203 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
204
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800205 /**
206 * Whether the given capabilities support the specified capability.
207 *
208 * @param capabilities A capability bit field.
209 * @param capability The capability to check capabilities for.
210 * @return Whether the specified capability is supported.
211 * @hide
212 */
213 public static boolean can(int capabilities, int capability) {
214 return (capabilities & capability) != 0;
215 }
216
217 /**
218 * Whether the capabilities of this {@code Connection} supports the specified capability.
219 *
220 * @param capability The capability to check capabilities for.
221 * @return Whether the specified capability is supported.
222 * @hide
223 */
224 public boolean can(int capability) {
225 return can(mConnectionCapabilities, capability);
226 }
227
228 /**
229 * Removes the specified capability from the set of capabilities of this {@code Connection}.
230 *
231 * @param capability The capability to remove from the set.
232 * @hide
233 */
234 public void removeCapability(int capability) {
235 mConnectionCapabilities &= ~capability;
236 }
237
238 /**
239 * Adds the specified capability to the set of capabilities of this {@code Connection}.
240 *
241 * @param capability The capability to add to the set.
242 * @hide
243 */
244 public void addCapability(int capability) {
245 mConnectionCapabilities |= capability;
246 }
247
248
249 public static String capabilitiesToString(int capabilities) {
250 StringBuilder builder = new StringBuilder();
251 builder.append("[Capabilities:");
252 if (can(capabilities, CAPABILITY_HOLD)) {
253 builder.append(" CAPABILITY_HOLD");
254 }
255 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
256 builder.append(" CAPABILITY_SUPPORT_HOLD");
257 }
258 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
259 builder.append(" CAPABILITY_MERGE_CONFERENCE");
260 }
261 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
262 builder.append(" CAPABILITY_SWAP_CONFERENCE");
263 }
264 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
265 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
266 }
267 if (can(capabilities, CAPABILITY_MUTE)) {
268 builder.append(" CAPABILITY_MUTE");
269 }
270 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
271 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
272 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700273 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
274 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
275 }
276 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
277 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
278 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700279 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
280 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800281 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700282 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
283 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
284 }
285 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
286 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
287 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700288 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
289 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800290 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800291 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
292 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800293 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800294 if (can(capabilities, CAPABILITY_WIFI)) {
295 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800296 }
297 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
298 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
299 }
Tyler Gunn068085b2015-02-06 13:56:52 -0800300 if (can(capabilities, CAPABILITY_SHOW_CALLBACK_NUMBER)) {
301 builder.append(" CAPABILITY_SHOW_CALLBACK_NUMBER");
302 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500303 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700304 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500305 }
Rekha Kumar07366812015-03-24 16:42:31 -0700306 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
307 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
308 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700309 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
310 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
311 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800312 builder.append("]");
313 return builder.toString();
314 }
315
Sailesh Nepal091768c2014-06-30 15:15:23 -0700316 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700317 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700318 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700319 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700320 public void onCallerDisplayNameChanged(
321 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700322 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700323 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700324 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800325 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700326 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700327 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800328 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700329 public void onVideoProviderChanged(
330 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700331 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
332 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800333 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700334 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700335 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700336 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800337 public void onConferenceParticipantsChanged(Connection c,
338 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800339 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700340 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700341 public void onExtrasChanged(Connection c, Bundle extras) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700342 }
343
Tyler Gunnb702ef82015-05-29 11:51:53 -0700344 /**
345 * Provides a means of controlling the video session associated with a {@link Connection}.
346 * <p>
347 * Implementations create a custom subclass of {@link VideoProvider} and the
348 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
349 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
350 * should set the {@link VideoProvider}.
351 * <p>
352 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
353 * {@link InCallService} implementations to issue requests related to the video session;
354 * it provides a means for the {@link ConnectionService} to report events and information
355 * related to the video session to Telecom and the {@link InCallService} implementations.
356 * <p>
357 * {@link InCallService} implementations interact with the {@link VideoProvider} via
358 * {@link android.telecom.InCallService.VideoCall}.
359 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700360 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700361
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700362 /**
363 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700364 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700365 */
366 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700367
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700368 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700369 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
370 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700371 */
372 public static final int SESSION_EVENT_RX_RESUME = 2;
373
374 /**
375 * Video transmission has begun. This occurs after a negotiated start of video transmission
376 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700377 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700378 */
379 public static final int SESSION_EVENT_TX_START = 3;
380
381 /**
382 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
383 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700384 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700385 */
386 public static final int SESSION_EVENT_TX_STOP = 4;
387
388 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700389 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
390 * this as a cue to inform the user the camera is not available.
391 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700392 */
393 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
394
395 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700396 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
397 * for operation. The {@link InCallService} can use this as a cue to inform the user that
398 * the camera has become available again.
399 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700400 */
401 public static final int SESSION_EVENT_CAMERA_READY = 6;
402
403 /**
404 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700405 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700406 */
407 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
408
409 /**
410 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700411 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700412 */
413 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
414
415 /**
416 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700417 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700418 */
419 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
420
Rekha Kumar07366812015-03-24 16:42:31 -0700421 /**
422 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700423 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700424 */
425 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
426
427 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700428 * Session modify request rejected by remote user.
429 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700430 */
431 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
432
Tyler Gunn75958422015-04-15 14:23:42 -0700433 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700434 private static final int MSG_SET_CAMERA = 2;
435 private static final int MSG_SET_PREVIEW_SURFACE = 3;
436 private static final int MSG_SET_DISPLAY_SURFACE = 4;
437 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
438 private static final int MSG_SET_ZOOM = 6;
439 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
440 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
441 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800442 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700443 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700444 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700445
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700446 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700447 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700448
449 /**
450 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700451 *
452 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
453 * load factor before resizing, 1 means we only expect a single thread to
454 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700455 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700456 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
457 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700458
459 /**
460 * Default handler used to consolidate binder method calls onto a single thread.
461 */
462 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700463 public VideoProviderHandler() {
464 super();
465 }
466
467 public VideoProviderHandler(Looper looper) {
468 super(looper);
469 }
470
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700471 @Override
472 public void handleMessage(Message msg) {
473 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700474 case MSG_ADD_VIDEO_CALLBACK: {
475 IBinder binder = (IBinder) msg.obj;
476 IVideoCallback callback = IVideoCallback.Stub
477 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700478 if (callback == null) {
479 Log.w(this, "addVideoProvider - skipped; callback is null.");
480 break;
481 }
482
Tyler Gunn75958422015-04-15 14:23:42 -0700483 if (mVideoCallbacks.containsKey(binder)) {
484 Log.i(this, "addVideoProvider - skipped; already present.");
485 break;
486 }
487 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700488 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700489 }
490 case MSG_REMOVE_VIDEO_CALLBACK: {
491 IBinder binder = (IBinder) msg.obj;
492 IVideoCallback callback = IVideoCallback.Stub
493 .asInterface((IBinder) msg.obj);
494 if (!mVideoCallbacks.containsKey(binder)) {
495 Log.i(this, "removeVideoProvider - skipped; not present.");
496 break;
497 }
498 mVideoCallbacks.remove(binder);
499 break;
500 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700501 case MSG_SET_CAMERA:
502 onSetCamera((String) msg.obj);
503 break;
504 case MSG_SET_PREVIEW_SURFACE:
505 onSetPreviewSurface((Surface) msg.obj);
506 break;
507 case MSG_SET_DISPLAY_SURFACE:
508 onSetDisplaySurface((Surface) msg.obj);
509 break;
510 case MSG_SET_DEVICE_ORIENTATION:
511 onSetDeviceOrientation(msg.arg1);
512 break;
513 case MSG_SET_ZOOM:
514 onSetZoom((Float) msg.obj);
515 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700516 case MSG_SEND_SESSION_MODIFY_REQUEST: {
517 SomeArgs args = (SomeArgs) msg.obj;
518 try {
519 onSendSessionModifyRequest((VideoProfile) args.arg1,
520 (VideoProfile) args.arg2);
521 } finally {
522 args.recycle();
523 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700524 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700525 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700526 case MSG_SEND_SESSION_MODIFY_RESPONSE:
527 onSendSessionModifyResponse((VideoProfile) msg.obj);
528 break;
529 case MSG_REQUEST_CAMERA_CAPABILITIES:
530 onRequestCameraCapabilities();
531 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800532 case MSG_REQUEST_CONNECTION_DATA_USAGE:
533 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700534 break;
535 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700536 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700537 break;
538 default:
539 break;
540 }
541 }
542 }
543
544 /**
545 * IVideoProvider stub implementation.
546 */
547 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700548 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700549 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700550 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
551 }
552
553 public void removeVideoCallback(IBinder videoCallbackBinder) {
554 mMessageHandler.obtainMessage(
555 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700556 }
557
558 public void setCamera(String cameraId) {
559 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
560 }
561
562 public void setPreviewSurface(Surface surface) {
563 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
564 }
565
566 public void setDisplaySurface(Surface surface) {
567 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
568 }
569
570 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700571 mMessageHandler.obtainMessage(
572 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700573 }
574
575 public void setZoom(float value) {
576 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
577 }
578
Tyler Gunn45382162015-05-06 08:52:27 -0700579 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
580 SomeArgs args = SomeArgs.obtain();
581 args.arg1 = fromProfile;
582 args.arg2 = toProfile;
583 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700584 }
585
586 public void sendSessionModifyResponse(VideoProfile responseProfile) {
587 mMessageHandler.obtainMessage(
588 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
589 }
590
591 public void requestCameraCapabilities() {
592 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
593 }
594
595 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800596 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700597 }
598
Yorke Lee32f24732015-05-12 16:18:03 -0700599 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700600 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
601 }
602 }
603
604 public VideoProvider() {
605 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700606 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700607 }
608
609 /**
610 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
611 *
612 * @param looper The looper.
613 * @hide
614 */
615 public VideoProvider(Looper looper) {
616 mBinder = new VideoProvider.VideoProviderBinder();
617 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700618 }
619
620 /**
621 * Returns binder object which can be used across IPC methods.
622 * @hide
623 */
624 public final IVideoProvider getInterface() {
625 return mBinder;
626 }
627
628 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700629 * Sets the camera to be used for the outgoing video.
630 * <p>
631 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
632 * camera via
633 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
634 * <p>
635 * Sent from the {@link InCallService} via
636 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700637 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700638 * @param cameraId The id of the camera (use ids as reported by
639 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700640 */
641 public abstract void onSetCamera(String cameraId);
642
643 /**
644 * Sets the surface to be used for displaying a preview of what the user's camera is
645 * currently capturing. When video transmission is enabled, this is the video signal which
646 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700647 * <p>
648 * Sent from the {@link InCallService} via
649 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700650 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700651 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700652 */
653 public abstract void onSetPreviewSurface(Surface surface);
654
655 /**
656 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700657 * <p>
658 * Sent from the {@link InCallService} via
659 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700660 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700661 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700662 */
663 public abstract void onSetDisplaySurface(Surface surface);
664
665 /**
666 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
667 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700668 * <p>
669 * Sent from the {@link InCallService} via
670 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700671 *
672 * @param rotation The device orientation, in degrees.
673 */
674 public abstract void onSetDeviceOrientation(int rotation);
675
676 /**
677 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700678 * <p>
679 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700680 *
681 * @param value The camera zoom ratio.
682 */
683 public abstract void onSetZoom(float value);
684
685 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700686 * Issues a request to modify the properties of the current video session.
687 * <p>
688 * Example scenarios include: requesting an audio-only call to be upgraded to a
689 * bi-directional video call, turning on or off the user's camera, sending a pause signal
690 * when the {@link InCallService} is no longer the foreground application.
691 * <p>
692 * If the {@link VideoProvider} determines a request to be invalid, it should call
693 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
694 * invalid request back to the {@link InCallService}.
695 * <p>
696 * Where a request requires confirmation from the user of the peer device, the
697 * {@link VideoProvider} must communicate the request to the peer device and handle the
698 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
699 * is used to inform the {@link InCallService} of the result of the request.
700 * <p>
701 * Sent from the {@link InCallService} via
702 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700703 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700704 * @param fromProfile The video profile prior to the request.
705 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700706 */
Tyler Gunn45382162015-05-06 08:52:27 -0700707 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
708 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700709
Tyler Gunnb702ef82015-05-29 11:51:53 -0700710 /**
711 * Provides a response to a request to change the current video session properties.
712 * <p>
713 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
714 * video call, could decline the request and keep the call as audio-only.
715 * In such a scenario, the {@code responseProfile} would have a video state of
716 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
717 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
718 * <p>
719 * Sent from the {@link InCallService} via
720 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
721 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
722 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700723 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700724 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700725 */
726 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
727
728 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700729 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
730 * <p>
731 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
732 * camera via
733 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
734 * <p>
735 * Sent from the {@link InCallService} via
736 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700737 */
738 public abstract void onRequestCameraCapabilities();
739
740 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700741 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
742 * video component of the current {@link Connection}.
743 * <p>
744 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
745 * via {@link VideoProvider#setCallDataUsage(long)}.
746 * <p>
747 * Sent from the {@link InCallService} via
748 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700749 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800750 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700751
752 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700753 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
754 * the peer device when the video signal is paused.
755 * <p>
756 * Sent from the {@link InCallService} via
757 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700758 *
759 * @param uri URI of image to display.
760 */
Yorke Lee32f24732015-05-12 16:18:03 -0700761 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700762
763 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700764 * Used to inform listening {@link InCallService} implementations when the
765 * {@link VideoProvider} receives a session modification request.
766 * <p>
767 * Received by the {@link InCallService} via
768 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700769 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700770 * @param videoProfile The requested video profile.
771 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700772 */
773 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700774 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700775 for (IVideoCallback callback : mVideoCallbacks.values()) {
776 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700777 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700778 } catch (RemoteException ignored) {
779 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700780 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700781 }
782 }
783 }
784
785 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700786 * Used to inform listening {@link InCallService} implementations when the
787 * {@link VideoProvider} receives a response to a session modification request.
788 * <p>
789 * Received by the {@link InCallService} via
790 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
791 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700792 *
793 * @param status Status of the session modify request. Valid values are
794 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
795 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -0700796 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
797 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
798 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
799 * @param requestedProfile The original request which was sent to the peer device.
800 * @param responseProfile The actual profile changes agreed to by the peer device.
801 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700802 */
803 public void receiveSessionModifyResponse(int status,
804 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700805 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700806 for (IVideoCallback callback : mVideoCallbacks.values()) {
807 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700808 callback.receiveSessionModifyResponse(status, requestedProfile,
809 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700810 } catch (RemoteException ignored) {
811 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700812 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700813 }
814 }
815 }
816
817 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700818 * Used to inform listening {@link InCallService} implementations when the
819 * {@link VideoProvider} reports a call session event.
820 * <p>
821 * Received by the {@link InCallService} via
822 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700823 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700824 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
825 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
826 * {@link VideoProvider#SESSION_EVENT_TX_START},
827 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
828 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
829 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700830 */
831 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -0700832 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700833 for (IVideoCallback callback : mVideoCallbacks.values()) {
834 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700835 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700836 } catch (RemoteException ignored) {
837 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700838 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700839 }
840 }
841 }
842
843 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700844 * Used to inform listening {@link InCallService} implementations when the dimensions of the
845 * peer's video have changed.
846 * <p>
847 * This could occur if, for example, the peer rotates their device, changing the aspect
848 * ratio of the video, or if the user switches between the back and front cameras.
849 * <p>
850 * Received by the {@link InCallService} via
851 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700852 *
853 * @param width The updated peer video width.
854 * @param height The updated peer video height.
855 */
856 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -0700857 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700858 for (IVideoCallback callback : mVideoCallbacks.values()) {
859 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700860 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700861 } catch (RemoteException ignored) {
862 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700863 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700864 }
865 }
866 }
867
868 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700869 * Used to inform listening {@link InCallService} implementations when the data usage of the
870 * video associated with the current {@link Connection} has changed.
871 * <p>
872 * This could be in response to a preview request via
873 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -0700874 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
875 * 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 -0700876 * <p>
877 * Received by the {@link InCallService} via
878 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700879 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700880 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
881 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700882 */
Yorke Lee32f24732015-05-12 16:18:03 -0700883 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -0700884 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700885 for (IVideoCallback callback : mVideoCallbacks.values()) {
886 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700887 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700888 } catch (RemoteException ignored) {
889 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700890 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700891 }
892 }
893 }
894
895 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700896 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700897 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700898 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -0700899 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
900 * @hide
901 */
902 public void changeCallDataUsage(long dataUsage) {
903 setCallDataUsage(dataUsage);
904 }
905
906 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700907 * Used to inform listening {@link InCallService} implementations when the capabilities of
908 * the current camera have changed.
909 * <p>
910 * The {@link VideoProvider} should call this in response to
911 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
912 * changed via {@link VideoProvider#onSetCamera(String)}.
913 * <p>
914 * Received by the {@link InCallService} via
915 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
916 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -0700917 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700918 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700919 */
Yorke Lee400470f2015-05-12 13:31:25 -0700920 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -0700921 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700922 for (IVideoCallback callback : mVideoCallbacks.values()) {
923 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700924 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700925 } catch (RemoteException ignored) {
926 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700927 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700928 }
929 }
930 }
Rekha Kumar07366812015-03-24 16:42:31 -0700931
932 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700933 * Used to inform listening {@link InCallService} implementations when the video quality
934 * of the call has changed.
935 * <p>
936 * Received by the {@link InCallService} via
937 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -0700938 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700939 * @param videoQuality The updated video quality. Valid values:
940 * {@link VideoProfile#QUALITY_HIGH},
941 * {@link VideoProfile#QUALITY_MEDIUM},
942 * {@link VideoProfile#QUALITY_LOW},
943 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -0700944 */
945 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -0700946 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700947 for (IVideoCallback callback : mVideoCallbacks.values()) {
948 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700949 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700950 } catch (RemoteException ignored) {
951 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700952 }
Rekha Kumar07366812015-03-24 16:42:31 -0700953 }
954 }
955 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700956 }
957
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700958 private final Listener mConnectionDeathListener = new Listener() {
959 @Override
960 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800961 if (mConferenceables.remove(c)) {
962 fireOnConferenceableConnectionsChanged();
963 }
964 }
965 };
966
967 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
968 @Override
969 public void onDestroyed(Conference c) {
970 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700971 fireOnConferenceableConnectionsChanged();
972 }
973 }
974 };
975
Jay Shrauner229e3822014-08-15 09:23:07 -0700976 /**
977 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
978 * load factor before resizing, 1 means we only expect a single thread to
979 * access the map so make only a single shard
980 */
981 private final Set<Listener> mListeners = Collections.newSetFromMap(
982 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700983 private final List<Conferenceable> mConferenceables = new ArrayList<>();
984 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800985 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -0700986
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700987 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -0700988 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -0700989 private Uri mAddress;
990 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700991 private String mCallerDisplayName;
992 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700993 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800994 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700995 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700996 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700997 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700998 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700999 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001000 private Conference mConference;
1001 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001002 private Bundle mExtras;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001003
1004 /**
1005 * Create a new Connection.
1006 */
Santos Cordonf2951102014-07-20 19:06:29 -07001007 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001008
1009 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001010 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001011 */
Andrew Lee100e2932014-09-08 15:34:24 -07001012 public final Uri getAddress() {
1013 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001014 }
1015
1016 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001017 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001018 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001019 */
Andrew Lee100e2932014-09-08 15:34:24 -07001020 public final int getAddressPresentation() {
1021 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001022 }
1023
1024 /**
1025 * @return The caller display name (CNAP).
1026 */
1027 public final String getCallerDisplayName() {
1028 return mCallerDisplayName;
1029 }
1030
1031 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001032 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001033 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001034 */
1035 public final int getCallerDisplayNamePresentation() {
1036 return mCallerDisplayNamePresentation;
1037 }
1038
1039 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001040 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001041 */
1042 public final int getState() {
1043 return mState;
1044 }
1045
1046 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001047 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001048 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1049 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1050 * {@link VideoProfile#STATE_TX_ENABLED},
1051 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001052 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001053 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001054 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001055 */
1056 public final int getVideoState() {
1057 return mVideoState;
1058 }
1059
1060 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001061 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001062 * being routed by the system. This is {@code null} if this Connection
1063 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001064 * @deprecated Use {@link #getCallAudioState()} instead.
1065 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001066 */
Yorke Lee4af59352015-05-13 14:14:54 -07001067 @SystemApi
1068 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001069 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001070 if (mCallAudioState == null) {
1071 return null;
1072 }
Yorke Lee4af59352015-05-13 14:14:54 -07001073 return new AudioState(mCallAudioState);
1074 }
1075
1076 /**
1077 * @return The audio state of the connection, describing how its audio is currently
1078 * being routed by the system. This is {@code null} if this Connection
1079 * does not directly know about its audio state.
1080 */
1081 public final CallAudioState getCallAudioState() {
1082 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001083 }
1084
1085 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001086 * @return The conference that this connection is a part of. Null if it is not part of any
1087 * conference.
1088 */
1089 public final Conference getConference() {
1090 return mConference;
1091 }
1092
1093 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001094 * Returns whether this connection is requesting that the system play a ringback tone
1095 * on its behalf.
1096 */
Andrew Lee100e2932014-09-08 15:34:24 -07001097 public final boolean isRingbackRequested() {
1098 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001099 }
1100
1101 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001102 * @return True if the connection's audio mode is VOIP.
1103 */
1104 public final boolean getAudioModeIsVoip() {
1105 return mAudioModeIsVoip;
1106 }
1107
1108 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001109 * @return The status hints for this connection.
1110 */
1111 public final StatusHints getStatusHints() {
1112 return mStatusHints;
1113 }
1114
1115 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001116 * @return The extras associated with this connection.
1117 */
1118 public final Bundle getExtras() {
1119 return mExtras;
1120 }
1121
1122 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001123 * Assign a listener to be notified of state changes.
1124 *
1125 * @param l A listener.
1126 * @return This Connection.
1127 *
1128 * @hide
1129 */
1130 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001131 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001132 return this;
1133 }
1134
1135 /**
1136 * Remove a previously assigned listener that was being notified of state changes.
1137 *
1138 * @param l A Listener.
1139 * @return This Connection.
1140 *
1141 * @hide
1142 */
1143 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001144 if (l != null) {
1145 mListeners.remove(l);
1146 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001147 return this;
1148 }
1149
1150 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001151 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001152 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001153 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001154 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001155 }
1156
1157 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001158 * Inform this Connection that the state of its audio output has been changed externally.
1159 *
1160 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001161 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001162 */
Yorke Lee4af59352015-05-13 14:14:54 -07001163 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001164 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001165 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001166 mCallAudioState = state;
1167 onAudioStateChanged(getAudioState());
1168 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001169 }
1170
1171 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001172 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001173 * @return A string representation of the value.
1174 */
1175 public static String stateToString(int state) {
1176 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001177 case STATE_INITIALIZING:
1178 return "STATE_INITIALIZING";
1179 case STATE_NEW:
1180 return "STATE_NEW";
1181 case STATE_RINGING:
1182 return "STATE_RINGING";
1183 case STATE_DIALING:
1184 return "STATE_DIALING";
1185 case STATE_ACTIVE:
1186 return "STATE_ACTIVE";
1187 case STATE_HOLDING:
1188 return "STATE_HOLDING";
1189 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001190 return "DISCONNECTED";
1191 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001192 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001193 return "UNKNOWN";
1194 }
1195 }
1196
1197 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001198 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001199 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001200 public final int getConnectionCapabilities() {
1201 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001202 }
1203
1204 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001205 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001206 *
Andrew Lee100e2932014-09-08 15:34:24 -07001207 * @param address The new address.
1208 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001209 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001210 */
Andrew Lee100e2932014-09-08 15:34:24 -07001211 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001212 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001213 Log.d(this, "setAddress %s", address);
1214 mAddress = address;
1215 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001216 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001217 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001218 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001219 }
1220
1221 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001222 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001223 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001224 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001225 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001226 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001227 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001228 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001229 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001230 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001231 mCallerDisplayName = callerDisplayName;
1232 mCallerDisplayNamePresentation = presentation;
1233 for (Listener l : mListeners) {
1234 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1235 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001236 }
1237
1238 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001239 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001240 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1241 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1242 * {@link VideoProfile#STATE_TX_ENABLED},
1243 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001244 *
1245 * @param videoState The new video state.
1246 */
1247 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001248 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001249 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001250 mVideoState = videoState;
1251 for (Listener l : mListeners) {
1252 l.onVideoStateChanged(this, mVideoState);
1253 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001254 }
1255
1256 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001257 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001258 * communicate).
1259 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001260 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001261 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001262 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001263 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001264 }
1265
1266 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001267 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001268 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001269 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001270 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001271 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001272 }
1273
1274 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001275 * Sets state to initializing (this Connection is not yet ready to be used).
1276 */
1277 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001278 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001279 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001280 }
1281
1282 /**
1283 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1284 */
1285 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001286 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001287 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001288 }
1289
1290 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001291 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001292 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001293 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001294 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001295 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001296 }
1297
1298 /**
1299 * Sets state to be on hold.
1300 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001301 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001302 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001303 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001304 }
1305
1306 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001307 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001308 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001309 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001310 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001311 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001312 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001313 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001314 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001315 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001316 }
1317
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001318 public final VideoProvider getVideoProvider() {
1319 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001320 }
1321
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001322 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001323 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001324 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001325 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001326 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001327 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001328 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001329 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001330 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001331 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001332 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001333 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001334 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001335 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001336 }
1337
1338 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001339 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1340 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1341 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1342 * to send an {@link #onPostDialContinue(boolean)} signal.
1343 *
1344 * @param remaining The DTMF character sequence remaining to be emitted once the
1345 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1346 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001347 */
1348 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001349 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001350 for (Listener l : mListeners) {
1351 l.onPostDialWait(this, remaining);
1352 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001353 }
1354
1355 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001356 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1357 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001358 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001359 *
1360 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001361 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001362 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001363 checkImmutable();
1364 for (Listener l : mListeners) {
1365 l.onPostDialChar(this, nextChar);
1366 }
1367 }
1368
1369 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001370 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001371 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001372 *
1373 * @param ringback Whether the ringback tone is to be played.
1374 */
Andrew Lee100e2932014-09-08 15:34:24 -07001375 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001376 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001377 if (mRingbackRequested != ringback) {
1378 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001379 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001380 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001381 }
1382 }
Ihab Awadf8358972014-05-28 16:46:42 -07001383 }
1384
1385 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001386 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001387 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001388 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001389 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001390 public final void setConnectionCapabilities(int connectionCapabilities) {
1391 checkImmutable();
1392 if (mConnectionCapabilities != connectionCapabilities) {
1393 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001394 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001395 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001396 }
1397 }
Santos Cordonb6939982014-06-04 20:20:58 -07001398 }
1399
1400 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001401 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001402 */
Evan Charlton36a71342014-07-19 16:31:02 -07001403 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001404 for (Listener l : mListeners) {
1405 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001406 }
Santos Cordonb6939982014-06-04 20:20:58 -07001407 }
1408
1409 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001410 * Requests that the framework use VOIP audio mode for this connection.
1411 *
1412 * @param isVoip True if the audio mode is VOIP.
1413 */
1414 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001415 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001416 mAudioModeIsVoip = isVoip;
1417 for (Listener l : mListeners) {
1418 l.onAudioModeIsVoipChanged(this, isVoip);
1419 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001420 }
1421
1422 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001423 * Sets the label and icon status to display in the in-call UI.
1424 *
1425 * @param statusHints The status label and icon to set.
1426 */
1427 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001428 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001429 mStatusHints = statusHints;
1430 for (Listener l : mListeners) {
1431 l.onStatusHintsChanged(this, statusHints);
1432 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001433 }
1434
1435 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001436 * Sets the connections with which this connection can be conferenced.
1437 *
1438 * @param conferenceableConnections The set of connections this connection can conference with.
1439 */
1440 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001441 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001442 clearConferenceableList();
1443 for (Connection c : conferenceableConnections) {
1444 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1445 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001446 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001447 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001448 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001449 }
1450 }
1451 fireOnConferenceableConnectionsChanged();
1452 }
1453
1454 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001455 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1456 * or conferences with which this connection can be conferenced.
1457 *
1458 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001459 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001460 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001461 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001462 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001463 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1464 // small amount of items here.
1465 if (!mConferenceables.contains(c)) {
1466 if (c instanceof Connection) {
1467 Connection connection = (Connection) c;
1468 connection.addConnectionListener(mConnectionDeathListener);
1469 } else if (c instanceof Conference) {
1470 Conference conference = (Conference) c;
1471 conference.addListener(mConferenceDeathListener);
1472 }
1473 mConferenceables.add(c);
1474 }
1475 }
1476 fireOnConferenceableConnectionsChanged();
1477 }
1478
1479 /**
1480 * Returns the connections or conferences with which this connection can be conferenced.
1481 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001482 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001483 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001484 }
1485
Evan Charlton8635c572014-09-24 14:04:51 -07001486 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -07001487 * @hide
1488 */
1489 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001490 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001491 if (mConnectionService != null) {
1492 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1493 "which is already associated with another ConnectionService.");
1494 } else {
1495 mConnectionService = connectionService;
1496 }
1497 }
1498
1499 /**
1500 * @hide
1501 */
1502 public final void unsetConnectionService(ConnectionService connectionService) {
1503 if (mConnectionService != connectionService) {
1504 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1505 "that does not belong to the ConnectionService.");
1506 } else {
1507 mConnectionService = null;
1508 }
1509 }
1510
1511 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001512 * @hide
1513 */
1514 public final ConnectionService getConnectionService() {
1515 return mConnectionService;
1516 }
1517
1518 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001519 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001520 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001521 *
1522 * @param conference The conference.
1523 * @return {@code true} if the conference was successfully set.
1524 * @hide
1525 */
1526 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001527 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001528 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001529 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001530 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001531 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1532 fireConferenceChanged();
1533 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001534 return true;
1535 }
1536 return false;
1537 }
1538
1539 /**
1540 * Resets the conference that this connection is a part of.
1541 * @hide
1542 */
1543 public final void resetConference() {
1544 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001545 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001546 mConference = null;
1547 fireConferenceChanged();
1548 }
1549 }
1550
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001551 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001552 * Set some extras that can be associated with this {@code Connection}. No assumptions should
1553 * be made as to how an In-Call UI or service will handle these extras.
1554 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1555 *
1556 * @param extras The extras associated with this {@code Connection}.
1557 */
1558 public final void setExtras(@Nullable Bundle extras) {
1559 checkImmutable();
1560 mExtras = extras;
1561 for (Listener l : mListeners) {
1562 l.onExtrasChanged(this, extras);
1563 }
1564 }
1565
1566 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001567 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001568 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001569 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001570 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
1571 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07001572 */
Yorke Lee4af59352015-05-13 14:14:54 -07001573 @SystemApi
1574 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07001575 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001576
1577 /**
Yorke Lee4af59352015-05-13 14:14:54 -07001578 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
1579 *
1580 * @param state The new connection audio state.
1581 */
1582 public void onCallAudioStateChanged(CallAudioState state) {}
1583
1584 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001585 * Notifies this Connection of an internal state change. This method is called after the
1586 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001587 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001588 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001589 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001590 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001591
1592 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001593 * Notifies this Connection of a request to play a DTMF tone.
1594 *
1595 * @param c A DTMF character.
1596 */
Santos Cordonf2951102014-07-20 19:06:29 -07001597 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001598
1599 /**
1600 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1601 */
Santos Cordonf2951102014-07-20 19:06:29 -07001602 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001603
1604 /**
1605 * Notifies this Connection of a request to disconnect.
1606 */
Santos Cordonf2951102014-07-20 19:06:29 -07001607 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001608
1609 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001610 * Notifies this Connection of a request to disconnect a participant of the conference managed
1611 * by the connection.
1612 *
1613 * @param endpoint the {@link Uri} of the participant to disconnect.
1614 * @hide
1615 */
1616 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1617
1618 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001619 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001620 */
Santos Cordonf2951102014-07-20 19:06:29 -07001621 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001622
1623 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001624 * Notifies this Connection of a request to abort.
1625 */
Santos Cordonf2951102014-07-20 19:06:29 -07001626 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001627
1628 /**
1629 * Notifies this Connection of a request to hold.
1630 */
Santos Cordonf2951102014-07-20 19:06:29 -07001631 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001632
1633 /**
1634 * Notifies this Connection of a request to exit a hold state.
1635 */
Santos Cordonf2951102014-07-20 19:06:29 -07001636 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001637
1638 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001639 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001640 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001641 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001642 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001643 */
Santos Cordonf2951102014-07-20 19:06:29 -07001644 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001645
1646 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001647 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001648 * a request to accept.
1649 */
1650 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07001651 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07001652 }
1653
1654 /**
1655 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001656 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001657 */
Santos Cordonf2951102014-07-20 19:06:29 -07001658 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001659
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001660 /**
1661 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1662 */
Santos Cordonf2951102014-07-20 19:06:29 -07001663 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001664
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001665 static String toLogSafePhoneNumber(String number) {
1666 // For unknown number, log empty string.
1667 if (number == null) {
1668 return "";
1669 }
1670
1671 if (PII_DEBUG) {
1672 // When PII_DEBUG is true we emit PII.
1673 return number;
1674 }
1675
1676 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1677 // sanitized phone numbers.
1678 StringBuilder builder = new StringBuilder();
1679 for (int i = 0; i < number.length(); i++) {
1680 char c = number.charAt(i);
1681 if (c == '-' || c == '@' || c == '.') {
1682 builder.append(c);
1683 } else {
1684 builder.append('x');
1685 }
1686 }
1687 return builder.toString();
1688 }
1689
Ihab Awad542e0ea2014-05-16 10:22:16 -07001690 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001691 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001692 if (mState == STATE_DISCONNECTED && mState != state) {
1693 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001694 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001695 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001696 if (mState != state) {
1697 Log.d(this, "setState: %s", stateToString(state));
1698 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001699 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001700 for (Listener l : mListeners) {
1701 l.onStateChanged(this, state);
1702 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001703 }
1704 }
1705
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001706 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001707 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001708 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1709 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001710 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001711 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001712
1713 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001714 if (mImmutable) {
1715 throw new UnsupportedOperationException("Connection is immutable");
1716 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001717 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001718 }
1719
Evan Charltonbf11f982014-07-20 22:06:28 -07001720 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001721 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001722 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1723 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001724 * <p>
1725 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1726 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001727 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001728 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001729 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001730 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001731 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1732 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001733 }
1734
Evan Charltonbf11f982014-07-20 22:06:28 -07001735 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001736 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1737 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1738 * this should never be un-@hide-den.
1739 *
1740 * @hide
1741 */
1742 public void checkImmutable() {}
1743
1744 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001745 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1746 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1747 * that state. This connection should not be used for anything, and no other
1748 * {@code Connection}s should be attempted.
1749 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001750 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001751 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001752 * @return A {@code Connection} which indicates that the underlying connection should
1753 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001754 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001755 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001756 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001757 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001758
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001759 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001760 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001761 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001762 }
1763 }
1764
Santos Cordon823fd3c2014-08-07 18:35:18 -07001765 private final void fireConferenceChanged() {
1766 for (Listener l : mListeners) {
1767 l.onConferenceChanged(this, mConference);
1768 }
1769 }
1770
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001771 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001772 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001773 if (c instanceof Connection) {
1774 Connection connection = (Connection) c;
1775 connection.removeConnectionListener(mConnectionDeathListener);
1776 } else if (c instanceof Conference) {
1777 Conference conference = (Conference) c;
1778 conference.removeListener(mConferenceDeathListener);
1779 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001780 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001781 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001782 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001783
1784 /**
Anthony Lee17455a32015-04-24 15:25:29 -07001785 * Notifies listeners that the merge request failed.
1786 *
1787 * @hide
1788 */
1789 protected final void notifyConferenceMergeFailed() {
1790 for (Listener l : mListeners) {
1791 l.onConferenceMergeFailed(this);
1792 }
1793 }
1794
1795 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001796 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001797 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001798 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001799 * @hide
1800 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001801 protected final void updateConferenceParticipants(
1802 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001803 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001804 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001805 }
1806 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001807
1808 /**
1809 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07001810 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001811 */
1812 protected void notifyConferenceStarted() {
1813 for (Listener l : mListeners) {
1814 l.onConferenceStarted();
1815 }
1816 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001817}