blob: 9a63aa3dc27e97c16fe0fde4c39414c83a66e35b [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.
451 */
452 private HashMap<IBinder, IVideoCallback> mVideoCallbacks = new HashMap<>();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700453
454 /**
455 * Default handler used to consolidate binder method calls onto a single thread.
456 */
457 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700458 public VideoProviderHandler() {
459 super();
460 }
461
462 public VideoProviderHandler(Looper looper) {
463 super(looper);
464 }
465
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700466 @Override
467 public void handleMessage(Message msg) {
468 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700469 case MSG_ADD_VIDEO_CALLBACK: {
470 IBinder binder = (IBinder) msg.obj;
471 IVideoCallback callback = IVideoCallback.Stub
472 .asInterface((IBinder) msg.obj);
473 if (mVideoCallbacks.containsKey(binder)) {
474 Log.i(this, "addVideoProvider - skipped; already present.");
475 break;
476 }
477 mVideoCallbacks.put(binder, callback);
478 Log.i(this, "addVideoProvider "+ mVideoCallbacks.size());
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700479 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700480 }
481 case MSG_REMOVE_VIDEO_CALLBACK: {
482 IBinder binder = (IBinder) msg.obj;
483 IVideoCallback callback = IVideoCallback.Stub
484 .asInterface((IBinder) msg.obj);
485 if (!mVideoCallbacks.containsKey(binder)) {
486 Log.i(this, "removeVideoProvider - skipped; not present.");
487 break;
488 }
489 mVideoCallbacks.remove(binder);
490 break;
491 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700492 case MSG_SET_CAMERA:
493 onSetCamera((String) msg.obj);
494 break;
495 case MSG_SET_PREVIEW_SURFACE:
496 onSetPreviewSurface((Surface) msg.obj);
497 break;
498 case MSG_SET_DISPLAY_SURFACE:
499 onSetDisplaySurface((Surface) msg.obj);
500 break;
501 case MSG_SET_DEVICE_ORIENTATION:
502 onSetDeviceOrientation(msg.arg1);
503 break;
504 case MSG_SET_ZOOM:
505 onSetZoom((Float) msg.obj);
506 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700507 case MSG_SEND_SESSION_MODIFY_REQUEST: {
508 SomeArgs args = (SomeArgs) msg.obj;
509 try {
510 onSendSessionModifyRequest((VideoProfile) args.arg1,
511 (VideoProfile) args.arg2);
512 } finally {
513 args.recycle();
514 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700515 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700516 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700517 case MSG_SEND_SESSION_MODIFY_RESPONSE:
518 onSendSessionModifyResponse((VideoProfile) msg.obj);
519 break;
520 case MSG_REQUEST_CAMERA_CAPABILITIES:
521 onRequestCameraCapabilities();
522 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800523 case MSG_REQUEST_CONNECTION_DATA_USAGE:
524 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700525 break;
526 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700527 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700528 break;
529 default:
530 break;
531 }
532 }
533 }
534
535 /**
536 * IVideoProvider stub implementation.
537 */
538 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700539 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700540 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700541 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
542 }
543
544 public void removeVideoCallback(IBinder videoCallbackBinder) {
545 mMessageHandler.obtainMessage(
546 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700547 }
548
549 public void setCamera(String cameraId) {
550 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
551 }
552
553 public void setPreviewSurface(Surface surface) {
554 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
555 }
556
557 public void setDisplaySurface(Surface surface) {
558 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
559 }
560
561 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700562 mMessageHandler.obtainMessage(
563 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700564 }
565
566 public void setZoom(float value) {
567 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
568 }
569
Tyler Gunn45382162015-05-06 08:52:27 -0700570 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
571 SomeArgs args = SomeArgs.obtain();
572 args.arg1 = fromProfile;
573 args.arg2 = toProfile;
574 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700575 }
576
577 public void sendSessionModifyResponse(VideoProfile responseProfile) {
578 mMessageHandler.obtainMessage(
579 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
580 }
581
582 public void requestCameraCapabilities() {
583 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
584 }
585
586 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800587 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700588 }
589
Yorke Lee32f24732015-05-12 16:18:03 -0700590 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700591 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
592 }
593 }
594
595 public VideoProvider() {
596 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700597 mMessageHandler = new VideoProvider.VideoProviderHandler();
598 }
599
600 /**
601 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
602 *
603 * @param looper The looper.
604 * @hide
605 */
606 public VideoProvider(Looper looper) {
607 mBinder = new VideoProvider.VideoProviderBinder();
608 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700609 }
610
611 /**
612 * Returns binder object which can be used across IPC methods.
613 * @hide
614 */
615 public final IVideoProvider getInterface() {
616 return mBinder;
617 }
618
619 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700620 * Sets the camera to be used for the outgoing video.
621 * <p>
622 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
623 * camera via
624 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
625 * <p>
626 * Sent from the {@link InCallService} via
627 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700628 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700629 * @param cameraId The id of the camera (use ids as reported by
630 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700631 */
632 public abstract void onSetCamera(String cameraId);
633
634 /**
635 * Sets the surface to be used for displaying a preview of what the user's camera is
636 * currently capturing. When video transmission is enabled, this is the video signal which
637 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700638 * <p>
639 * Sent from the {@link InCallService} via
640 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700641 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700642 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700643 */
644 public abstract void onSetPreviewSurface(Surface surface);
645
646 /**
647 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700648 * <p>
649 * Sent from the {@link InCallService} via
650 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700651 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700652 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700653 */
654 public abstract void onSetDisplaySurface(Surface surface);
655
656 /**
657 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
658 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700659 * <p>
660 * Sent from the {@link InCallService} via
661 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700662 *
663 * @param rotation The device orientation, in degrees.
664 */
665 public abstract void onSetDeviceOrientation(int rotation);
666
667 /**
668 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700669 * <p>
670 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700671 *
672 * @param value The camera zoom ratio.
673 */
674 public abstract void onSetZoom(float value);
675
676 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700677 * Issues a request to modify the properties of the current video session.
678 * <p>
679 * Example scenarios include: requesting an audio-only call to be upgraded to a
680 * bi-directional video call, turning on or off the user's camera, sending a pause signal
681 * when the {@link InCallService} is no longer the foreground application.
682 * <p>
683 * If the {@link VideoProvider} determines a request to be invalid, it should call
684 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
685 * invalid request back to the {@link InCallService}.
686 * <p>
687 * Where a request requires confirmation from the user of the peer device, the
688 * {@link VideoProvider} must communicate the request to the peer device and handle the
689 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
690 * is used to inform the {@link InCallService} of the result of the request.
691 * <p>
692 * Sent from the {@link InCallService} via
693 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700694 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700695 * @param fromProfile The video profile prior to the request.
696 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700697 */
Tyler Gunn45382162015-05-06 08:52:27 -0700698 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
699 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700700
Tyler Gunnb702ef82015-05-29 11:51:53 -0700701 /**
702 * Provides a response to a request to change the current video session properties.
703 * <p>
704 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
705 * video call, could decline the request and keep the call as audio-only.
706 * In such a scenario, the {@code responseProfile} would have a video state of
707 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
708 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
709 * <p>
710 * Sent from the {@link InCallService} via
711 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
712 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
713 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700714 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700715 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700716 */
717 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
718
719 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700720 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
721 * <p>
722 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
723 * camera via
724 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
725 * <p>
726 * Sent from the {@link InCallService} via
727 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700728 */
729 public abstract void onRequestCameraCapabilities();
730
731 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700732 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
733 * video component of the current {@link Connection}.
734 * <p>
735 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
736 * via {@link VideoProvider#setCallDataUsage(long)}.
737 * <p>
738 * Sent from the {@link InCallService} via
739 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700740 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800741 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700742
743 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700744 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
745 * the peer device when the video signal is paused.
746 * <p>
747 * Sent from the {@link InCallService} via
748 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700749 *
750 * @param uri URI of image to display.
751 */
Yorke Lee32f24732015-05-12 16:18:03 -0700752 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700753
754 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700755 * Used to inform listening {@link InCallService} implementations when the
756 * {@link VideoProvider} receives a session modification request.
757 * <p>
758 * Received by the {@link InCallService} via
759 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700760 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700761 * @param videoProfile The requested video profile.
762 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700763 */
764 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700765 if (mVideoCallbacks != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700766 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700767 for (IVideoCallback callback : mVideoCallbacks.values()) {
768 callback.receiveSessionModifyRequest(videoProfile);
769 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700770 } catch (RemoteException ignored) {
771 }
772 }
773 }
774
775 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700776 * Used to inform listening {@link InCallService} implementations when the
777 * {@link VideoProvider} receives a response to a session modification request.
778 * <p>
779 * Received by the {@link InCallService} via
780 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
781 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700782 *
783 * @param status Status of the session modify request. Valid values are
784 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
785 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -0700786 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
787 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
788 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
789 * @param requestedProfile The original request which was sent to the peer device.
790 * @param responseProfile The actual profile changes agreed to by the peer device.
791 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700792 */
793 public void receiveSessionModifyResponse(int status,
794 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700795 if (mVideoCallbacks != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700796 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700797 for (IVideoCallback callback : mVideoCallbacks.values()) {
798 callback.receiveSessionModifyResponse(status, requestedProfile,
799 responseProfile);
800 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700801 } catch (RemoteException ignored) {
802 }
803 }
804 }
805
806 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700807 * Used to inform listening {@link InCallService} implementations when the
808 * {@link VideoProvider} reports a call session event.
809 * <p>
810 * Received by the {@link InCallService} via
811 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700812 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700813 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
814 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
815 * {@link VideoProvider#SESSION_EVENT_TX_START},
816 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
817 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
818 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700819 */
820 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -0700821 if (mVideoCallbacks != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700822 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700823 for (IVideoCallback callback : mVideoCallbacks.values()) {
824 callback.handleCallSessionEvent(event);
825 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700826 } catch (RemoteException ignored) {
827 }
828 }
829 }
830
831 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700832 * Used to inform listening {@link InCallService} implementations when the dimensions of the
833 * peer's video have changed.
834 * <p>
835 * This could occur if, for example, the peer rotates their device, changing the aspect
836 * ratio of the video, or if the user switches between the back and front cameras.
837 * <p>
838 * Received by the {@link InCallService} via
839 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700840 *
841 * @param width The updated peer video width.
842 * @param height The updated peer video height.
843 */
844 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -0700845 if (mVideoCallbacks != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700846 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700847 for (IVideoCallback callback : mVideoCallbacks.values()) {
848 callback.changePeerDimensions(width, height);
849 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700850 } catch (RemoteException ignored) {
851 }
852 }
853 }
854
855 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700856 * Used to inform listening {@link InCallService} implementations when the data usage of the
857 * video associated with the current {@link Connection} has changed.
858 * <p>
859 * This could be in response to a preview request via
860 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -0700861 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
862 * 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 -0700863 * <p>
864 * Received by the {@link InCallService} via
865 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700866 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700867 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
868 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700869 */
Yorke Lee32f24732015-05-12 16:18:03 -0700870 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -0700871 if (mVideoCallbacks != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700872 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700873 for (IVideoCallback callback : mVideoCallbacks.values()) {
874 callback.changeCallDataUsage(dataUsage);
875 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700876 } catch (RemoteException ignored) {
877 }
878 }
879 }
880
881 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700882 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700883 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700884 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -0700885 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
886 * @hide
887 */
888 public void changeCallDataUsage(long dataUsage) {
889 setCallDataUsage(dataUsage);
890 }
891
892 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700893 * Used to inform listening {@link InCallService} implementations when the capabilities of
894 * the current camera have changed.
895 * <p>
896 * The {@link VideoProvider} should call this in response to
897 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
898 * changed via {@link VideoProvider#onSetCamera(String)}.
899 * <p>
900 * Received by the {@link InCallService} via
901 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
902 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -0700903 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700904 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700905 */
Yorke Lee400470f2015-05-12 13:31:25 -0700906 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -0700907 if (mVideoCallbacks != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700908 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700909 for (IVideoCallback callback : mVideoCallbacks.values()) {
910 callback.changeCameraCapabilities(cameraCapabilities);
911 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700912 } catch (RemoteException ignored) {
913 }
914 }
915 }
Rekha Kumar07366812015-03-24 16:42:31 -0700916
917 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700918 * Used to inform listening {@link InCallService} implementations when the video quality
919 * of the call has changed.
920 * <p>
921 * Received by the {@link InCallService} via
922 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -0700923 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700924 * @param videoQuality The updated video quality. Valid values:
925 * {@link VideoProfile#QUALITY_HIGH},
926 * {@link VideoProfile#QUALITY_MEDIUM},
927 * {@link VideoProfile#QUALITY_LOW},
928 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -0700929 */
930 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -0700931 if (mVideoCallbacks != null) {
Rekha Kumar07366812015-03-24 16:42:31 -0700932 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700933 for (IVideoCallback callback : mVideoCallbacks.values()) {
934 callback.changeVideoQuality(videoQuality);
935 }
Rekha Kumar07366812015-03-24 16:42:31 -0700936 } catch (RemoteException ignored) {
937 }
938 }
939 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700940 }
941
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700942 private final Listener mConnectionDeathListener = new Listener() {
943 @Override
944 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800945 if (mConferenceables.remove(c)) {
946 fireOnConferenceableConnectionsChanged();
947 }
948 }
949 };
950
951 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
952 @Override
953 public void onDestroyed(Conference c) {
954 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700955 fireOnConferenceableConnectionsChanged();
956 }
957 }
958 };
959
Jay Shrauner229e3822014-08-15 09:23:07 -0700960 /**
961 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
962 * load factor before resizing, 1 means we only expect a single thread to
963 * access the map so make only a single shard
964 */
965 private final Set<Listener> mListeners = Collections.newSetFromMap(
966 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700967 private final List<Conferenceable> mConferenceables = new ArrayList<>();
968 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800969 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -0700970
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700971 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -0700972 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -0700973 private Uri mAddress;
974 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700975 private String mCallerDisplayName;
976 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700977 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800978 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700979 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700980 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700981 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700982 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700983 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700984 private Conference mConference;
985 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700986 private Bundle mExtras;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700987
988 /**
989 * Create a new Connection.
990 */
Santos Cordonf2951102014-07-20 19:06:29 -0700991 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700992
993 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700994 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700995 */
Andrew Lee100e2932014-09-08 15:34:24 -0700996 public final Uri getAddress() {
997 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700998 }
999
1000 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001001 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001002 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001003 */
Andrew Lee100e2932014-09-08 15:34:24 -07001004 public final int getAddressPresentation() {
1005 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001006 }
1007
1008 /**
1009 * @return The caller display name (CNAP).
1010 */
1011 public final String getCallerDisplayName() {
1012 return mCallerDisplayName;
1013 }
1014
1015 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001016 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001017 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001018 */
1019 public final int getCallerDisplayNamePresentation() {
1020 return mCallerDisplayNamePresentation;
1021 }
1022
1023 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001024 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001025 */
1026 public final int getState() {
1027 return mState;
1028 }
1029
1030 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001031 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001032 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1033 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1034 * {@link VideoProfile#STATE_TX_ENABLED},
1035 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001036 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001037 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001038 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001039 */
1040 public final int getVideoState() {
1041 return mVideoState;
1042 }
1043
1044 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001045 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001046 * being routed by the system. This is {@code null} if this Connection
1047 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001048 * @deprecated Use {@link #getCallAudioState()} instead.
1049 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001050 */
Yorke Lee4af59352015-05-13 14:14:54 -07001051 @SystemApi
1052 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001053 public final AudioState getAudioState() {
Yorke Lee4af59352015-05-13 14:14:54 -07001054 return new AudioState(mCallAudioState);
1055 }
1056
1057 /**
1058 * @return The audio state of the connection, describing how its audio is currently
1059 * being routed by the system. This is {@code null} if this Connection
1060 * does not directly know about its audio state.
1061 */
1062 public final CallAudioState getCallAudioState() {
1063 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001064 }
1065
1066 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001067 * @return The conference that this connection is a part of. Null if it is not part of any
1068 * conference.
1069 */
1070 public final Conference getConference() {
1071 return mConference;
1072 }
1073
1074 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001075 * Returns whether this connection is requesting that the system play a ringback tone
1076 * on its behalf.
1077 */
Andrew Lee100e2932014-09-08 15:34:24 -07001078 public final boolean isRingbackRequested() {
1079 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001080 }
1081
1082 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001083 * @return True if the connection's audio mode is VOIP.
1084 */
1085 public final boolean getAudioModeIsVoip() {
1086 return mAudioModeIsVoip;
1087 }
1088
1089 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001090 * @return The status hints for this connection.
1091 */
1092 public final StatusHints getStatusHints() {
1093 return mStatusHints;
1094 }
1095
1096 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001097 * @return The extras associated with this connection.
1098 */
1099 public final Bundle getExtras() {
1100 return mExtras;
1101 }
1102
1103 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001104 * Assign a listener to be notified of state changes.
1105 *
1106 * @param l A listener.
1107 * @return This Connection.
1108 *
1109 * @hide
1110 */
1111 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001112 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001113 return this;
1114 }
1115
1116 /**
1117 * Remove a previously assigned listener that was being notified of state changes.
1118 *
1119 * @param l A Listener.
1120 * @return This Connection.
1121 *
1122 * @hide
1123 */
1124 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001125 if (l != null) {
1126 mListeners.remove(l);
1127 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001128 return this;
1129 }
1130
1131 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001132 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001133 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001134 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001135 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001136 }
1137
1138 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001139 * Inform this Connection that the state of its audio output has been changed externally.
1140 *
1141 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001142 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001143 */
Yorke Lee4af59352015-05-13 14:14:54 -07001144 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001145 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001146 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001147 mCallAudioState = state;
1148 onAudioStateChanged(getAudioState());
1149 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001150 }
1151
1152 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001153 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001154 * @return A string representation of the value.
1155 */
1156 public static String stateToString(int state) {
1157 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001158 case STATE_INITIALIZING:
1159 return "STATE_INITIALIZING";
1160 case STATE_NEW:
1161 return "STATE_NEW";
1162 case STATE_RINGING:
1163 return "STATE_RINGING";
1164 case STATE_DIALING:
1165 return "STATE_DIALING";
1166 case STATE_ACTIVE:
1167 return "STATE_ACTIVE";
1168 case STATE_HOLDING:
1169 return "STATE_HOLDING";
1170 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001171 return "DISCONNECTED";
1172 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001173 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001174 return "UNKNOWN";
1175 }
1176 }
1177
1178 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001179 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001180 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001181 public final int getConnectionCapabilities() {
1182 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001183 }
1184
1185 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001186 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001187 *
Andrew Lee100e2932014-09-08 15:34:24 -07001188 * @param address The new address.
1189 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001190 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001191 */
Andrew Lee100e2932014-09-08 15:34:24 -07001192 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001193 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001194 Log.d(this, "setAddress %s", address);
1195 mAddress = address;
1196 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001197 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001198 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001199 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001200 }
1201
1202 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001203 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001204 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001205 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001206 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001207 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001208 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001209 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001210 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001211 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001212 mCallerDisplayName = callerDisplayName;
1213 mCallerDisplayNamePresentation = presentation;
1214 for (Listener l : mListeners) {
1215 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1216 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001217 }
1218
1219 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001220 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001221 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1222 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1223 * {@link VideoProfile#STATE_TX_ENABLED},
1224 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001225 *
1226 * @param videoState The new video state.
1227 */
1228 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001229 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001230 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001231 mVideoState = videoState;
1232 for (Listener l : mListeners) {
1233 l.onVideoStateChanged(this, mVideoState);
1234 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001235 }
1236
1237 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001238 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001239 * communicate).
1240 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001241 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001242 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001243 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001244 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001245 }
1246
1247 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001248 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001249 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001250 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001251 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001252 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001253 }
1254
1255 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001256 * Sets state to initializing (this Connection is not yet ready to be used).
1257 */
1258 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001259 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001260 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001261 }
1262
1263 /**
1264 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1265 */
1266 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001267 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001268 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001269 }
1270
1271 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001272 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001273 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001274 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001275 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001276 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001277 }
1278
1279 /**
1280 * Sets state to be on hold.
1281 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001282 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001283 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001284 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001285 }
1286
1287 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001288 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001289 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001290 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001291 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001292 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001293 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001294 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001295 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001296 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001297 }
1298
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001299 public final VideoProvider getVideoProvider() {
1300 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001301 }
1302
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001303 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001304 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001305 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001306 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001307 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001308 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001309 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001310 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001311 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001312 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001313 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001314 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001315 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001316 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001317 }
1318
1319 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001320 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1321 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1322 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1323 * to send an {@link #onPostDialContinue(boolean)} signal.
1324 *
1325 * @param remaining The DTMF character sequence remaining to be emitted once the
1326 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1327 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001328 */
1329 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001330 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001331 for (Listener l : mListeners) {
1332 l.onPostDialWait(this, remaining);
1333 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001334 }
1335
1336 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001337 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1338 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001339 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001340 *
1341 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001342 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001343 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001344 checkImmutable();
1345 for (Listener l : mListeners) {
1346 l.onPostDialChar(this, nextChar);
1347 }
1348 }
1349
1350 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001351 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001352 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001353 *
1354 * @param ringback Whether the ringback tone is to be played.
1355 */
Andrew Lee100e2932014-09-08 15:34:24 -07001356 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001357 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001358 if (mRingbackRequested != ringback) {
1359 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001360 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001361 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001362 }
1363 }
Ihab Awadf8358972014-05-28 16:46:42 -07001364 }
1365
1366 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001367 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001368 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001369 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001370 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001371 public final void setConnectionCapabilities(int connectionCapabilities) {
1372 checkImmutable();
1373 if (mConnectionCapabilities != connectionCapabilities) {
1374 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001375 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001376 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001377 }
1378 }
Santos Cordonb6939982014-06-04 20:20:58 -07001379 }
1380
1381 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001382 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001383 */
Evan Charlton36a71342014-07-19 16:31:02 -07001384 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001385 for (Listener l : mListeners) {
1386 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001387 }
Santos Cordonb6939982014-06-04 20:20:58 -07001388 }
1389
1390 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001391 * Requests that the framework use VOIP audio mode for this connection.
1392 *
1393 * @param isVoip True if the audio mode is VOIP.
1394 */
1395 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001396 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001397 mAudioModeIsVoip = isVoip;
1398 for (Listener l : mListeners) {
1399 l.onAudioModeIsVoipChanged(this, isVoip);
1400 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001401 }
1402
1403 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001404 * Sets the label and icon status to display in the in-call UI.
1405 *
1406 * @param statusHints The status label and icon to set.
1407 */
1408 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001409 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001410 mStatusHints = statusHints;
1411 for (Listener l : mListeners) {
1412 l.onStatusHintsChanged(this, statusHints);
1413 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001414 }
1415
1416 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001417 * Sets the connections with which this connection can be conferenced.
1418 *
1419 * @param conferenceableConnections The set of connections this connection can conference with.
1420 */
1421 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001422 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001423 clearConferenceableList();
1424 for (Connection c : conferenceableConnections) {
1425 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1426 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001427 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001428 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001429 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001430 }
1431 }
1432 fireOnConferenceableConnectionsChanged();
1433 }
1434
1435 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001436 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1437 * or conferences with which this connection can be conferenced.
1438 *
1439 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001440 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001441 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001442 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001443 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001444 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1445 // small amount of items here.
1446 if (!mConferenceables.contains(c)) {
1447 if (c instanceof Connection) {
1448 Connection connection = (Connection) c;
1449 connection.addConnectionListener(mConnectionDeathListener);
1450 } else if (c instanceof Conference) {
1451 Conference conference = (Conference) c;
1452 conference.addListener(mConferenceDeathListener);
1453 }
1454 mConferenceables.add(c);
1455 }
1456 }
1457 fireOnConferenceableConnectionsChanged();
1458 }
1459
1460 /**
1461 * Returns the connections or conferences with which this connection can be conferenced.
1462 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001463 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001464 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001465 }
1466
Evan Charlton8635c572014-09-24 14:04:51 -07001467 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -07001468 * @hide
1469 */
1470 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001471 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001472 if (mConnectionService != null) {
1473 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1474 "which is already associated with another ConnectionService.");
1475 } else {
1476 mConnectionService = connectionService;
1477 }
1478 }
1479
1480 /**
1481 * @hide
1482 */
1483 public final void unsetConnectionService(ConnectionService connectionService) {
1484 if (mConnectionService != connectionService) {
1485 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1486 "that does not belong to the ConnectionService.");
1487 } else {
1488 mConnectionService = null;
1489 }
1490 }
1491
1492 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001493 * @hide
1494 */
1495 public final ConnectionService getConnectionService() {
1496 return mConnectionService;
1497 }
1498
1499 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001500 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001501 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001502 *
1503 * @param conference The conference.
1504 * @return {@code true} if the conference was successfully set.
1505 * @hide
1506 */
1507 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001508 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001509 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001510 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001511 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001512 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1513 fireConferenceChanged();
1514 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001515 return true;
1516 }
1517 return false;
1518 }
1519
1520 /**
1521 * Resets the conference that this connection is a part of.
1522 * @hide
1523 */
1524 public final void resetConference() {
1525 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001526 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001527 mConference = null;
1528 fireConferenceChanged();
1529 }
1530 }
1531
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001532 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001533 * Set some extras that can be associated with this {@code Connection}. No assumptions should
1534 * be made as to how an In-Call UI or service will handle these extras.
1535 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1536 *
1537 * @param extras The extras associated with this {@code Connection}.
1538 */
1539 public final void setExtras(@Nullable Bundle extras) {
1540 checkImmutable();
1541 mExtras = extras;
1542 for (Listener l : mListeners) {
1543 l.onExtrasChanged(this, extras);
1544 }
1545 }
1546
1547 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001548 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001549 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001550 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001551 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
1552 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07001553 */
Yorke Lee4af59352015-05-13 14:14:54 -07001554 @SystemApi
1555 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07001556 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001557
1558 /**
Yorke Lee4af59352015-05-13 14:14:54 -07001559 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
1560 *
1561 * @param state The new connection audio state.
1562 */
1563 public void onCallAudioStateChanged(CallAudioState state) {}
1564
1565 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001566 * Notifies this Connection of an internal state change. This method is called after the
1567 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001568 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001569 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001570 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001571 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001572
1573 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001574 * Notifies this Connection of a request to play a DTMF tone.
1575 *
1576 * @param c A DTMF character.
1577 */
Santos Cordonf2951102014-07-20 19:06:29 -07001578 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001579
1580 /**
1581 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1582 */
Santos Cordonf2951102014-07-20 19:06:29 -07001583 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001584
1585 /**
1586 * Notifies this Connection of a request to disconnect.
1587 */
Santos Cordonf2951102014-07-20 19:06:29 -07001588 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001589
1590 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001591 * Notifies this Connection of a request to disconnect a participant of the conference managed
1592 * by the connection.
1593 *
1594 * @param endpoint the {@link Uri} of the participant to disconnect.
1595 * @hide
1596 */
1597 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1598
1599 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001600 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001601 */
Santos Cordonf2951102014-07-20 19:06:29 -07001602 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001603
1604 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001605 * Notifies this Connection of a request to abort.
1606 */
Santos Cordonf2951102014-07-20 19:06:29 -07001607 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001608
1609 /**
1610 * Notifies this Connection of a request to hold.
1611 */
Santos Cordonf2951102014-07-20 19:06:29 -07001612 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001613
1614 /**
1615 * Notifies this Connection of a request to exit a hold state.
1616 */
Santos Cordonf2951102014-07-20 19:06:29 -07001617 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001618
1619 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001620 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001621 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001622 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001623 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001624 */
Santos Cordonf2951102014-07-20 19:06:29 -07001625 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001626
1627 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001628 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001629 * a request to accept.
1630 */
1631 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07001632 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07001633 }
1634
1635 /**
1636 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001637 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001638 */
Santos Cordonf2951102014-07-20 19:06:29 -07001639 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001640
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001641 /**
1642 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1643 */
Santos Cordonf2951102014-07-20 19:06:29 -07001644 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001645
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001646 static String toLogSafePhoneNumber(String number) {
1647 // For unknown number, log empty string.
1648 if (number == null) {
1649 return "";
1650 }
1651
1652 if (PII_DEBUG) {
1653 // When PII_DEBUG is true we emit PII.
1654 return number;
1655 }
1656
1657 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1658 // sanitized phone numbers.
1659 StringBuilder builder = new StringBuilder();
1660 for (int i = 0; i < number.length(); i++) {
1661 char c = number.charAt(i);
1662 if (c == '-' || c == '@' || c == '.') {
1663 builder.append(c);
1664 } else {
1665 builder.append('x');
1666 }
1667 }
1668 return builder.toString();
1669 }
1670
Ihab Awad542e0ea2014-05-16 10:22:16 -07001671 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001672 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001673 if (mState == STATE_DISCONNECTED && mState != state) {
1674 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001675 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001676 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001677 if (mState != state) {
1678 Log.d(this, "setState: %s", stateToString(state));
1679 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001680 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001681 for (Listener l : mListeners) {
1682 l.onStateChanged(this, state);
1683 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001684 }
1685 }
1686
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001687 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001688 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001689 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1690 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001691 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001692 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001693
1694 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001695 if (mImmutable) {
1696 throw new UnsupportedOperationException("Connection is immutable");
1697 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001698 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001699 }
1700
Evan Charltonbf11f982014-07-20 22:06:28 -07001701 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001702 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001703 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1704 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001705 * <p>
1706 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1707 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001708 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001709 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001710 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001711 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001712 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1713 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001714 }
1715
Evan Charltonbf11f982014-07-20 22:06:28 -07001716 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001717 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1718 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1719 * this should never be un-@hide-den.
1720 *
1721 * @hide
1722 */
1723 public void checkImmutable() {}
1724
1725 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001726 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1727 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1728 * that state. This connection should not be used for anything, and no other
1729 * {@code Connection}s should be attempted.
1730 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001731 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001732 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001733 * @return A {@code Connection} which indicates that the underlying connection should
1734 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001735 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001736 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001737 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001738 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001739
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001740 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001741 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001742 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001743 }
1744 }
1745
Santos Cordon823fd3c2014-08-07 18:35:18 -07001746 private final void fireConferenceChanged() {
1747 for (Listener l : mListeners) {
1748 l.onConferenceChanged(this, mConference);
1749 }
1750 }
1751
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001752 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001753 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001754 if (c instanceof Connection) {
1755 Connection connection = (Connection) c;
1756 connection.removeConnectionListener(mConnectionDeathListener);
1757 } else if (c instanceof Conference) {
1758 Conference conference = (Conference) c;
1759 conference.removeListener(mConferenceDeathListener);
1760 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001761 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001762 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001763 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001764
1765 /**
Anthony Lee17455a32015-04-24 15:25:29 -07001766 * Notifies listeners that the merge request failed.
1767 *
1768 * @hide
1769 */
1770 protected final void notifyConferenceMergeFailed() {
1771 for (Listener l : mListeners) {
1772 l.onConferenceMergeFailed(this);
1773 }
1774 }
1775
1776 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001777 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001778 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001779 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001780 * @hide
1781 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001782 protected final void updateConferenceParticipants(
1783 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001784 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001785 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001786 }
1787 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001788
1789 /**
1790 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07001791 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001792 */
1793 protected void notifyConferenceStarted() {
1794 for (Listener l : mListeners) {
1795 l.onConferenceStarted();
1796 }
1797 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001798}