blob: f9e48b6ff61d5d84f7be744702f9f96c85ff7e08 [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;
Ihab Awad542e0ea2014-05-16 10:22:16 -070025import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070026import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070027import android.os.Handler;
28import android.os.IBinder;
29import android.os.Message;
30import android.os.RemoteException;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070031import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070032
Santos Cordonb6939982014-06-04 20:20:58 -070033import java.util.ArrayList;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070034import java.util.Collections;
Tyler Gunn75958422015-04-15 14:23:42 -070035import java.util.HashMap;
Santos Cordonb6939982014-06-04 20:20:58 -070036import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070037import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070038import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070039
40/**
41 * Represents a connection to a remote endpoint that carries voice traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070042 * <p>
43 * Implementations create a custom subclass of {@code Connection} and return it to the framework
44 * as the return value of
45 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
46 * or
47 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
48 * Implementations are then responsible for updating the state of the {@code Connection}, and
49 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
50 * longer used and associated resources may be recovered.
Ihab Awad542e0ea2014-05-16 10:22:16 -070051 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070052public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070053
Ihab Awadb19a0bc2014-08-07 19:46:01 -070054 public static final int STATE_INITIALIZING = 0;
55
56 public static final int STATE_NEW = 1;
57
58 public static final int STATE_RINGING = 2;
59
60 public static final int STATE_DIALING = 3;
61
62 public static final int STATE_ACTIVE = 4;
63
64 public static final int STATE_HOLDING = 5;
65
66 public static final int STATE_DISCONNECTED = 6;
67
Ihab Awad5c9c86e2014-11-12 13:41:16 -080068 /** Connection can currently be put on hold or unheld. */
69 public static final int CAPABILITY_HOLD = 0x00000001;
70
71 /** Connection supports the hold feature. */
72 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
73
74 /**
75 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
76 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
77 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
78 * capability allows a merge button to be shown while the conference is in the foreground
79 * of the in-call UI.
80 * <p>
81 * This is only intended for use by a {@link Conference}.
82 */
83 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
84
85 /**
86 * Connections within a conference can be swapped between foreground and background.
87 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
88 * <p>
89 * This is only intended for use by a {@link Conference}.
90 */
91 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
92
93 /**
94 * @hide
95 */
96 public static final int CAPABILITY_UNUSED = 0x00000010;
97
98 /** Connection supports responding via text option. */
99 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
100
101 /** Connection can be muted. */
102 public static final int CAPABILITY_MUTE = 0x00000040;
103
104 /**
105 * Connection supports conference management. This capability only applies to
106 * {@link Conference}s which can have {@link Connection}s as children.
107 */
108 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
109
110 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700111 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800112 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700113 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800114
115 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700116 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800117 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700118 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800119
120 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700121 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800122 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700123 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700124 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800125
126 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700127 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800128 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700129 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
130
131 /**
132 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700133 */
134 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
135
136 /**
137 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700138 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700139 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700140 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800141
142 /**
143 * Connection is able to be separated from its parent {@code Conference}, if any.
144 */
145 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
146
147 /**
148 * Connection is able to be individually disconnected when in a {@code Conference}.
149 */
150 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
151
152 /**
153 * Whether the call is a generic conference, where we do not know the precise state of
154 * participants in the conference (eg. on CDMA).
155 *
156 * @hide
157 */
158 public static final int CAPABILITY_GENERIC_CONFERENCE = 0x00004000;
159
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700160 /**
161 * Connection is using high definition audio.
162 * @hide
163 */
164 public static final int CAPABILITY_HIGH_DEF_AUDIO = 0x00008000;
165
166 /**
167 * Connection is using WIFI.
168 * @hide
169 */
Tyler Gunnd11a3152015-03-18 13:09:14 -0700170 public static final int CAPABILITY_WIFI = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700171
Tyler Gunn068085b2015-02-06 13:56:52 -0800172 /**
173 * Indicates that the current device callback number should be shown.
174 *
175 * @hide
176 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700177 public static final int CAPABILITY_SHOW_CALLBACK_NUMBER = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800178
Tyler Gunn96d6c402015-03-18 12:39:23 -0700179 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500180 * Speed up audio setup for MT call.
181 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700182 */
183 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800184
Rekha Kumar07366812015-03-24 16:42:31 -0700185 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700186 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700187 */
188 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
189
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700190 /**
191 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700192 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700193 */
194 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
195
Tyler Gunn96d6c402015-03-18 12:39:23 -0700196 //**********************************************************************************************
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700197 // Next CAPABILITY value: 0x00200000
Tyler Gunn96d6c402015-03-18 12:39:23 -0700198 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800199
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700200 // Flag controlling whether PII is emitted into the logs
201 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
202
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800203 /**
204 * Whether the given capabilities support the specified capability.
205 *
206 * @param capabilities A capability bit field.
207 * @param capability The capability to check capabilities for.
208 * @return Whether the specified capability is supported.
209 * @hide
210 */
211 public static boolean can(int capabilities, int capability) {
212 return (capabilities & capability) != 0;
213 }
214
215 /**
216 * Whether the capabilities of this {@code Connection} supports the specified capability.
217 *
218 * @param capability The capability to check capabilities for.
219 * @return Whether the specified capability is supported.
220 * @hide
221 */
222 public boolean can(int capability) {
223 return can(mConnectionCapabilities, capability);
224 }
225
226 /**
227 * Removes the specified capability from the set of capabilities of this {@code Connection}.
228 *
229 * @param capability The capability to remove from the set.
230 * @hide
231 */
232 public void removeCapability(int capability) {
233 mConnectionCapabilities &= ~capability;
234 }
235
236 /**
237 * Adds the specified capability to the set of capabilities of this {@code Connection}.
238 *
239 * @param capability The capability to add to the set.
240 * @hide
241 */
242 public void addCapability(int capability) {
243 mConnectionCapabilities |= capability;
244 }
245
246
247 public static String capabilitiesToString(int capabilities) {
248 StringBuilder builder = new StringBuilder();
249 builder.append("[Capabilities:");
250 if (can(capabilities, CAPABILITY_HOLD)) {
251 builder.append(" CAPABILITY_HOLD");
252 }
253 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
254 builder.append(" CAPABILITY_SUPPORT_HOLD");
255 }
256 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
257 builder.append(" CAPABILITY_MERGE_CONFERENCE");
258 }
259 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
260 builder.append(" CAPABILITY_SWAP_CONFERENCE");
261 }
262 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
263 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
264 }
265 if (can(capabilities, CAPABILITY_MUTE)) {
266 builder.append(" CAPABILITY_MUTE");
267 }
268 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
269 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
270 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700271 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
272 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
273 }
274 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
275 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
276 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700277 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
278 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800279 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700280 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
281 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
282 }
283 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
284 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
285 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700286 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
287 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800288 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800289 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
290 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800291 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800292 if (can(capabilities, CAPABILITY_WIFI)) {
293 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800294 }
295 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
296 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
297 }
Tyler Gunn068085b2015-02-06 13:56:52 -0800298 if (can(capabilities, CAPABILITY_SHOW_CALLBACK_NUMBER)) {
299 builder.append(" CAPABILITY_SHOW_CALLBACK_NUMBER");
300 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500301 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700302 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500303 }
Rekha Kumar07366812015-03-24 16:42:31 -0700304 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
305 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
306 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700307 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
308 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
309 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800310 builder.append("]");
311 return builder.toString();
312 }
313
Sailesh Nepal091768c2014-06-30 15:15:23 -0700314 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700315 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700316 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700317 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700318 public void onCallerDisplayNameChanged(
319 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700320 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700321 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700322 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800323 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700324 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700325 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800326 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700327 public void onVideoProviderChanged(
328 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700329 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
330 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800331 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700332 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700333 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700334 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800335 public void onConferenceParticipantsChanged(Connection c,
336 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800337 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700338 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700339 public void onExtrasChanged(Connection c, Bundle extras) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700340 }
341
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700342 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700343
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700344 /**
345 * Video is not being received (no protocol pause was issued).
346 */
347 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700348
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700349 /**
350 * Video reception has resumed after a SESSION_EVENT_RX_PAUSE.
351 */
352 public static final int SESSION_EVENT_RX_RESUME = 2;
353
354 /**
355 * Video transmission has begun. This occurs after a negotiated start of video transmission
356 * when the underlying protocol has actually begun transmitting video to the remote party.
357 */
358 public static final int SESSION_EVENT_TX_START = 3;
359
360 /**
361 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
362 * when the underlying protocol has actually stopped transmitting video to the remote party.
363 */
364 public static final int SESSION_EVENT_TX_STOP = 4;
365
366 /**
367 * A camera failure has occurred for the selected camera. The In-Call UI can use this as a
368 * cue to inform the user the camera is not available.
369 */
370 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
371
372 /**
373 * Issued after {@code SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready for
374 * operation. The In-Call UI can use this as a cue to inform the user that the camera has
375 * become available again.
376 */
377 public static final int SESSION_EVENT_CAMERA_READY = 6;
378
379 /**
380 * Session modify request was successful.
381 */
382 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
383
384 /**
385 * Session modify request failed.
386 */
387 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
388
389 /**
390 * Session modify request ignored due to invalid parameters.
391 */
392 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
393
Rekha Kumar07366812015-03-24 16:42:31 -0700394 /**
395 * Session modify request timed out.
396 */
397 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
398
399 /**
400 * Session modify request rejected by remote UE.
401 */
402 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
403
Tyler Gunn75958422015-04-15 14:23:42 -0700404 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700405 private static final int MSG_SET_CAMERA = 2;
406 private static final int MSG_SET_PREVIEW_SURFACE = 3;
407 private static final int MSG_SET_DISPLAY_SURFACE = 4;
408 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
409 private static final int MSG_SET_ZOOM = 6;
410 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
411 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
412 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800413 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700414 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700415 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700416
417 private final VideoProvider.VideoProviderHandler
418 mMessageHandler = new VideoProvider.VideoProviderHandler();
419 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700420
421 /**
422 * Stores a list of the video callbacks, keyed by IBinder.
423 */
424 private HashMap<IBinder, IVideoCallback> mVideoCallbacks = new HashMap<>();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700425
426 /**
427 * Default handler used to consolidate binder method calls onto a single thread.
428 */
429 private final class VideoProviderHandler extends Handler {
430 @Override
431 public void handleMessage(Message msg) {
432 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700433 case MSG_ADD_VIDEO_CALLBACK: {
434 IBinder binder = (IBinder) msg.obj;
435 IVideoCallback callback = IVideoCallback.Stub
436 .asInterface((IBinder) msg.obj);
437 if (mVideoCallbacks.containsKey(binder)) {
438 Log.i(this, "addVideoProvider - skipped; already present.");
439 break;
440 }
441 mVideoCallbacks.put(binder, callback);
442 Log.i(this, "addVideoProvider "+ mVideoCallbacks.size());
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700443 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700444 }
445 case MSG_REMOVE_VIDEO_CALLBACK: {
446 IBinder binder = (IBinder) msg.obj;
447 IVideoCallback callback = IVideoCallback.Stub
448 .asInterface((IBinder) msg.obj);
449 if (!mVideoCallbacks.containsKey(binder)) {
450 Log.i(this, "removeVideoProvider - skipped; not present.");
451 break;
452 }
453 mVideoCallbacks.remove(binder);
454 break;
455 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700456 case MSG_SET_CAMERA:
457 onSetCamera((String) msg.obj);
458 break;
459 case MSG_SET_PREVIEW_SURFACE:
460 onSetPreviewSurface((Surface) msg.obj);
461 break;
462 case MSG_SET_DISPLAY_SURFACE:
463 onSetDisplaySurface((Surface) msg.obj);
464 break;
465 case MSG_SET_DEVICE_ORIENTATION:
466 onSetDeviceOrientation(msg.arg1);
467 break;
468 case MSG_SET_ZOOM:
469 onSetZoom((Float) msg.obj);
470 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700471 case MSG_SEND_SESSION_MODIFY_REQUEST: {
472 SomeArgs args = (SomeArgs) msg.obj;
473 try {
474 onSendSessionModifyRequest((VideoProfile) args.arg1,
475 (VideoProfile) args.arg2);
476 } finally {
477 args.recycle();
478 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700479 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700480 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700481 case MSG_SEND_SESSION_MODIFY_RESPONSE:
482 onSendSessionModifyResponse((VideoProfile) msg.obj);
483 break;
484 case MSG_REQUEST_CAMERA_CAPABILITIES:
485 onRequestCameraCapabilities();
486 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800487 case MSG_REQUEST_CONNECTION_DATA_USAGE:
488 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700489 break;
490 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700491 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700492 break;
493 default:
494 break;
495 }
496 }
497 }
498
499 /**
500 * IVideoProvider stub implementation.
501 */
502 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700503 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700504 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700505 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
506 }
507
508 public void removeVideoCallback(IBinder videoCallbackBinder) {
509 mMessageHandler.obtainMessage(
510 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700511 }
512
513 public void setCamera(String cameraId) {
514 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
515 }
516
517 public void setPreviewSurface(Surface surface) {
518 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
519 }
520
521 public void setDisplaySurface(Surface surface) {
522 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
523 }
524
525 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700526 mMessageHandler.obtainMessage(
527 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700528 }
529
530 public void setZoom(float value) {
531 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
532 }
533
Tyler Gunn45382162015-05-06 08:52:27 -0700534 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
535 SomeArgs args = SomeArgs.obtain();
536 args.arg1 = fromProfile;
537 args.arg2 = toProfile;
538 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700539 }
540
541 public void sendSessionModifyResponse(VideoProfile responseProfile) {
542 mMessageHandler.obtainMessage(
543 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
544 }
545
546 public void requestCameraCapabilities() {
547 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
548 }
549
550 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800551 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700552 }
553
Yorke Lee32f24732015-05-12 16:18:03 -0700554 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700555 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
556 }
557 }
558
559 public VideoProvider() {
560 mBinder = new VideoProvider.VideoProviderBinder();
561 }
562
563 /**
564 * Returns binder object which can be used across IPC methods.
565 * @hide
566 */
567 public final IVideoProvider getInterface() {
568 return mBinder;
569 }
570
571 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800572 * Sets the camera to be used for video recording in a video connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700573 *
574 * @param cameraId The id of the camera.
575 */
576 public abstract void onSetCamera(String cameraId);
577
578 /**
579 * Sets the surface to be used for displaying a preview of what the user's camera is
580 * currently capturing. When video transmission is enabled, this is the video signal which
581 * is sent to the remote device.
582 *
583 * @param surface The surface.
584 */
585 public abstract void onSetPreviewSurface(Surface surface);
586
587 /**
588 * Sets the surface to be used for displaying the video received from the remote device.
589 *
590 * @param surface The surface.
591 */
592 public abstract void onSetDisplaySurface(Surface surface);
593
594 /**
595 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
596 * the device is 0 degrees.
597 *
598 * @param rotation The device orientation, in degrees.
599 */
600 public abstract void onSetDeviceOrientation(int rotation);
601
602 /**
603 * Sets camera zoom ratio.
604 *
605 * @param value The camera zoom ratio.
606 */
607 public abstract void onSetZoom(float value);
608
609 /**
610 * Issues a request to modify the properties of the current session. The request is
611 * sent to the remote device where it it handled by the In-Call UI.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800612 * Some examples of session modification requests: upgrade connection from audio to video,
613 * downgrade connection from video to audio, pause video.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700614 *
Tyler Gunn45382162015-05-06 08:52:27 -0700615 * @param fromProfile The video properties prior to the request.
616 * @param toProfile The video properties with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700617 */
Tyler Gunn45382162015-05-06 08:52:27 -0700618 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
619 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700620
621 /**te
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800622 * Provides a response to a request to change the current connection session video
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700623 * properties.
624 * This is in response to a request the InCall UI has received via the InCall UI.
625 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800626 * @param responseProfile The response connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700627 */
628 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
629
630 /**
631 * Issues a request to the video provider to retrieve the camera capabilities.
632 * Camera capabilities are reported back to the caller via the In-Call UI.
633 */
634 public abstract void onRequestCameraCapabilities();
635
636 /**
637 * Issues a request to the video telephony framework to retrieve the cumulative data usage
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800638 * for the current connection. Data usage is reported back to the caller via the
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700639 * InCall UI.
640 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800641 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700642
643 /**
644 * Provides the video telephony framework with the URI of an image to be displayed to remote
645 * devices when the video signal is paused.
646 *
647 * @param uri URI of image to display.
648 */
Yorke Lee32f24732015-05-12 16:18:03 -0700649 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700650
651 /**
Tyler Gunn75958422015-04-15 14:23:42 -0700652 * Invokes callback method defined in listening {@link InCallService} implementations.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700653 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800654 * @param videoProfile The requested video connection profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700655 */
656 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700657 if (mVideoCallbacks != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700658 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700659 for (IVideoCallback callback : mVideoCallbacks.values()) {
660 callback.receiveSessionModifyRequest(videoProfile);
661 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700662 } catch (RemoteException ignored) {
663 }
664 }
665 }
666
667 /**
Tyler Gunn75958422015-04-15 14:23:42 -0700668 * Invokes callback method defined in listening {@link InCallService} implementations.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700669 *
670 * @param status Status of the session modify request. Valid values are
671 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
672 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
673 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID}
674 * @param requestedProfile The original request which was sent to the remote device.
675 * @param responseProfile The actual profile changes made by the remote device.
676 */
677 public void receiveSessionModifyResponse(int status,
678 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700679 if (mVideoCallbacks != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700680 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700681 for (IVideoCallback callback : mVideoCallbacks.values()) {
682 callback.receiveSessionModifyResponse(status, requestedProfile,
683 responseProfile);
684 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700685 } catch (RemoteException ignored) {
686 }
687 }
688 }
689
690 /**
Tyler Gunn75958422015-04-15 14:23:42 -0700691 * Invokes callback method defined in listening {@link InCallService} implementations.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700692 *
693 * Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
694 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
695 * {@link VideoProvider#SESSION_EVENT_TX_START},
696 * {@link VideoProvider#SESSION_EVENT_TX_STOP}
697 *
698 * @param event The event.
699 */
700 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -0700701 if (mVideoCallbacks != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700702 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700703 for (IVideoCallback callback : mVideoCallbacks.values()) {
704 callback.handleCallSessionEvent(event);
705 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700706 } catch (RemoteException ignored) {
707 }
708 }
709 }
710
711 /**
Tyler Gunn75958422015-04-15 14:23:42 -0700712 * Invokes callback method defined in listening {@link InCallService} implementations.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700713 *
714 * @param width The updated peer video width.
715 * @param height The updated peer video height.
716 */
717 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -0700718 if (mVideoCallbacks != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700719 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700720 for (IVideoCallback callback : mVideoCallbacks.values()) {
721 callback.changePeerDimensions(width, height);
722 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700723 } catch (RemoteException ignored) {
724 }
725 }
726 }
727
728 /**
Tyler Gunn75958422015-04-15 14:23:42 -0700729 * Invokes callback method defined in listening {@link InCallService} implementations.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700730 *
731 * @param dataUsage The updated data usage.
732 */
Yorke Lee32f24732015-05-12 16:18:03 -0700733 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -0700734 if (mVideoCallbacks != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700735 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700736 for (IVideoCallback callback : mVideoCallbacks.values()) {
737 callback.changeCallDataUsage(dataUsage);
738 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700739 } catch (RemoteException ignored) {
740 }
741 }
742 }
743
744 /**
Tyler Gunn75958422015-04-15 14:23:42 -0700745 * Invokes callback method defined in listening {@link InCallService} implementations.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700746 *
Yorke Lee32f24732015-05-12 16:18:03 -0700747 * @param dataUsage The updated data usage.
748 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
749 * @hide
750 */
751 public void changeCallDataUsage(long dataUsage) {
752 setCallDataUsage(dataUsage);
753 }
754
755 /**
756 * Invokes callback method defined in listening {@link InCallService} implementations.
757 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700758 * @param cameraCapabilities The changed camera capabilities.
759 */
Yorke Lee400470f2015-05-12 13:31:25 -0700760 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -0700761 if (mVideoCallbacks != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700762 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700763 for (IVideoCallback callback : mVideoCallbacks.values()) {
764 callback.changeCameraCapabilities(cameraCapabilities);
765 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700766 } catch (RemoteException ignored) {
767 }
768 }
769 }
Rekha Kumar07366812015-03-24 16:42:31 -0700770
771 /**
Tyler Gunn75958422015-04-15 14:23:42 -0700772 * Invokes callback method defined in listening {@link InCallService} implementations.
Rekha Kumar07366812015-03-24 16:42:31 -0700773 *
Yorke Lee32f24732015-05-12 16:18:03 -0700774 * Allowed values:
775 * {@link VideoProfile#QUALITY_HIGH},
776 * {@link VideoProfile#QUALITY_MEDIUM},
777 * {@link VideoProfile#QUALITY_LOW},
778 * {@link VideoProfile#QUALITY_DEFAULT}.
779 *
Rekha Kumar07366812015-03-24 16:42:31 -0700780 * @param videoQuality The updated video quality.
781 */
782 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -0700783 if (mVideoCallbacks != null) {
Rekha Kumar07366812015-03-24 16:42:31 -0700784 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700785 for (IVideoCallback callback : mVideoCallbacks.values()) {
786 callback.changeVideoQuality(videoQuality);
787 }
Rekha Kumar07366812015-03-24 16:42:31 -0700788 } catch (RemoteException ignored) {
789 }
790 }
791 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700792 }
793
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700794 private final Listener mConnectionDeathListener = new Listener() {
795 @Override
796 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800797 if (mConferenceables.remove(c)) {
798 fireOnConferenceableConnectionsChanged();
799 }
800 }
801 };
802
803 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
804 @Override
805 public void onDestroyed(Conference c) {
806 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700807 fireOnConferenceableConnectionsChanged();
808 }
809 }
810 };
811
Jay Shrauner229e3822014-08-15 09:23:07 -0700812 /**
813 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
814 * load factor before resizing, 1 means we only expect a single thread to
815 * access the map so make only a single shard
816 */
817 private final Set<Listener> mListeners = Collections.newSetFromMap(
818 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700819 private final List<Conferenceable> mConferenceables = new ArrayList<>();
820 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800821 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -0700822
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700823 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -0700824 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -0700825 private Uri mAddress;
826 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700827 private String mCallerDisplayName;
828 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700829 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800830 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700831 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700832 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700833 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700834 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700835 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700836 private Conference mConference;
837 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700838 private Bundle mExtras;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700839
840 /**
841 * Create a new Connection.
842 */
Santos Cordonf2951102014-07-20 19:06:29 -0700843 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700844
845 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700846 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700847 */
Andrew Lee100e2932014-09-08 15:34:24 -0700848 public final Uri getAddress() {
849 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700850 }
851
852 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700853 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700854 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700855 */
Andrew Lee100e2932014-09-08 15:34:24 -0700856 public final int getAddressPresentation() {
857 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700858 }
859
860 /**
861 * @return The caller display name (CNAP).
862 */
863 public final String getCallerDisplayName() {
864 return mCallerDisplayName;
865 }
866
867 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700868 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700869 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700870 */
871 public final int getCallerDisplayNamePresentation() {
872 return mCallerDisplayNamePresentation;
873 }
874
875 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700876 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700877 */
878 public final int getState() {
879 return mState;
880 }
881
882 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800883 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -0700884 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
885 * {@link VideoProfile#STATE_BIDIRECTIONAL},
886 * {@link VideoProfile#STATE_TX_ENABLED},
887 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700888 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800889 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700890 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700891 */
892 public final int getVideoState() {
893 return mVideoState;
894 }
895
896 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800897 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -0700898 * being routed by the system. This is {@code null} if this Connection
899 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700900 * @deprecated Use {@link #getCallAudioState()} instead.
901 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -0700902 */
Yorke Lee4af59352015-05-13 14:14:54 -0700903 @SystemApi
904 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700905 public final AudioState getAudioState() {
Yorke Lee4af59352015-05-13 14:14:54 -0700906 return new AudioState(mCallAudioState);
907 }
908
909 /**
910 * @return The audio state of the connection, describing how its audio is currently
911 * being routed by the system. This is {@code null} if this Connection
912 * does not directly know about its audio state.
913 */
914 public final CallAudioState getCallAudioState() {
915 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700916 }
917
918 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700919 * @return The conference that this connection is a part of. Null if it is not part of any
920 * conference.
921 */
922 public final Conference getConference() {
923 return mConference;
924 }
925
926 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700927 * Returns whether this connection is requesting that the system play a ringback tone
928 * on its behalf.
929 */
Andrew Lee100e2932014-09-08 15:34:24 -0700930 public final boolean isRingbackRequested() {
931 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700932 }
933
934 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700935 * @return True if the connection's audio mode is VOIP.
936 */
937 public final boolean getAudioModeIsVoip() {
938 return mAudioModeIsVoip;
939 }
940
941 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700942 * @return The status hints for this connection.
943 */
944 public final StatusHints getStatusHints() {
945 return mStatusHints;
946 }
947
948 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700949 * @return The extras associated with this connection.
950 */
951 public final Bundle getExtras() {
952 return mExtras;
953 }
954
955 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700956 * Assign a listener to be notified of state changes.
957 *
958 * @param l A listener.
959 * @return This Connection.
960 *
961 * @hide
962 */
963 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +0000964 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700965 return this;
966 }
967
968 /**
969 * Remove a previously assigned listener that was being notified of state changes.
970 *
971 * @param l A Listener.
972 * @return This Connection.
973 *
974 * @hide
975 */
976 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700977 if (l != null) {
978 mListeners.remove(l);
979 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700980 return this;
981 }
982
983 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700984 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -0700985 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700986 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700987 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -0700988 }
989
990 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700991 * Inform this Connection that the state of its audio output has been changed externally.
992 *
993 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -0700994 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -0700995 */
Yorke Lee4af59352015-05-13 14:14:54 -0700996 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800997 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -0700998 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -0700999 mCallAudioState = state;
1000 onAudioStateChanged(getAudioState());
1001 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001002 }
1003
1004 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001005 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001006 * @return A string representation of the value.
1007 */
1008 public static String stateToString(int state) {
1009 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001010 case STATE_INITIALIZING:
1011 return "STATE_INITIALIZING";
1012 case STATE_NEW:
1013 return "STATE_NEW";
1014 case STATE_RINGING:
1015 return "STATE_RINGING";
1016 case STATE_DIALING:
1017 return "STATE_DIALING";
1018 case STATE_ACTIVE:
1019 return "STATE_ACTIVE";
1020 case STATE_HOLDING:
1021 return "STATE_HOLDING";
1022 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001023 return "DISCONNECTED";
1024 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001025 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001026 return "UNKNOWN";
1027 }
1028 }
1029
1030 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001031 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001032 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001033 public final int getConnectionCapabilities() {
1034 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001035 }
1036
1037 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001038 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001039 *
Andrew Lee100e2932014-09-08 15:34:24 -07001040 * @param address The new address.
1041 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001042 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001043 */
Andrew Lee100e2932014-09-08 15:34:24 -07001044 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001045 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001046 Log.d(this, "setAddress %s", address);
1047 mAddress = address;
1048 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001049 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001050 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001051 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001052 }
1053
1054 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001055 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001056 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001057 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001058 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001059 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001060 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001061 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001062 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001063 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001064 mCallerDisplayName = callerDisplayName;
1065 mCallerDisplayNamePresentation = presentation;
1066 for (Listener l : mListeners) {
1067 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1068 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001069 }
1070
1071 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001072 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001073 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1074 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1075 * {@link VideoProfile#STATE_TX_ENABLED},
1076 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001077 *
1078 * @param videoState The new video state.
1079 */
1080 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001081 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001082 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001083 mVideoState = videoState;
1084 for (Listener l : mListeners) {
1085 l.onVideoStateChanged(this, mVideoState);
1086 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001087 }
1088
1089 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001090 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001091 * communicate).
1092 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001093 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001094 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001095 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001096 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001097 }
1098
1099 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001100 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001101 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001102 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001103 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001104 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001105 }
1106
1107 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001108 * Sets state to initializing (this Connection is not yet ready to be used).
1109 */
1110 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001111 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001112 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001113 }
1114
1115 /**
1116 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1117 */
1118 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001119 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001120 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001121 }
1122
1123 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001124 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001125 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001126 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001127 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001128 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001129 }
1130
1131 /**
1132 * Sets state to be on hold.
1133 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001134 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001135 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001136 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001137 }
1138
1139 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001140 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001141 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001142 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001143 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001144 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001145 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001146 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001147 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001148 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001149 }
1150
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001151 public final VideoProvider getVideoProvider() {
1152 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001153 }
1154
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001155 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001156 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001157 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001158 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001159 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001160 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001161 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001162 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001163 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001164 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001165 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001166 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001167 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001168 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001169 }
1170
1171 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001172 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1173 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1174 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1175 * to send an {@link #onPostDialContinue(boolean)} signal.
1176 *
1177 * @param remaining The DTMF character sequence remaining to be emitted once the
1178 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1179 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001180 */
1181 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001182 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001183 for (Listener l : mListeners) {
1184 l.onPostDialWait(this, remaining);
1185 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001186 }
1187
1188 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001189 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1190 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001191 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001192 *
1193 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001194 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001195 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001196 checkImmutable();
1197 for (Listener l : mListeners) {
1198 l.onPostDialChar(this, nextChar);
1199 }
1200 }
1201
1202 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001203 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001204 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001205 *
1206 * @param ringback Whether the ringback tone is to be played.
1207 */
Andrew Lee100e2932014-09-08 15:34:24 -07001208 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001209 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001210 if (mRingbackRequested != ringback) {
1211 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001212 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001213 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001214 }
1215 }
Ihab Awadf8358972014-05-28 16:46:42 -07001216 }
1217
1218 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001219 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001220 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001221 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001222 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001223 public final void setConnectionCapabilities(int connectionCapabilities) {
1224 checkImmutable();
1225 if (mConnectionCapabilities != connectionCapabilities) {
1226 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001227 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001228 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001229 }
1230 }
Santos Cordonb6939982014-06-04 20:20:58 -07001231 }
1232
1233 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001234 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001235 */
Evan Charlton36a71342014-07-19 16:31:02 -07001236 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001237 for (Listener l : mListeners) {
1238 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001239 }
Santos Cordonb6939982014-06-04 20:20:58 -07001240 }
1241
1242 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001243 * Requests that the framework use VOIP audio mode for this connection.
1244 *
1245 * @param isVoip True if the audio mode is VOIP.
1246 */
1247 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001248 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001249 mAudioModeIsVoip = isVoip;
1250 for (Listener l : mListeners) {
1251 l.onAudioModeIsVoipChanged(this, isVoip);
1252 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001253 }
1254
1255 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001256 * Sets the label and icon status to display in the in-call UI.
1257 *
1258 * @param statusHints The status label and icon to set.
1259 */
1260 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001261 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001262 mStatusHints = statusHints;
1263 for (Listener l : mListeners) {
1264 l.onStatusHintsChanged(this, statusHints);
1265 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001266 }
1267
1268 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001269 * Sets the connections with which this connection can be conferenced.
1270 *
1271 * @param conferenceableConnections The set of connections this connection can conference with.
1272 */
1273 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001274 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001275 clearConferenceableList();
1276 for (Connection c : conferenceableConnections) {
1277 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1278 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001279 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001280 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001281 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001282 }
1283 }
1284 fireOnConferenceableConnectionsChanged();
1285 }
1286
1287 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001288 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1289 * or conferences with which this connection can be conferenced.
1290 *
1291 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001292 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001293 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001294 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001295 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001296 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1297 // small amount of items here.
1298 if (!mConferenceables.contains(c)) {
1299 if (c instanceof Connection) {
1300 Connection connection = (Connection) c;
1301 connection.addConnectionListener(mConnectionDeathListener);
1302 } else if (c instanceof Conference) {
1303 Conference conference = (Conference) c;
1304 conference.addListener(mConferenceDeathListener);
1305 }
1306 mConferenceables.add(c);
1307 }
1308 }
1309 fireOnConferenceableConnectionsChanged();
1310 }
1311
1312 /**
1313 * Returns the connections or conferences with which this connection can be conferenced.
1314 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001315 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001316 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001317 }
1318
Evan Charlton8635c572014-09-24 14:04:51 -07001319 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -07001320 * @hide
1321 */
1322 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001323 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001324 if (mConnectionService != null) {
1325 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1326 "which is already associated with another ConnectionService.");
1327 } else {
1328 mConnectionService = connectionService;
1329 }
1330 }
1331
1332 /**
1333 * @hide
1334 */
1335 public final void unsetConnectionService(ConnectionService connectionService) {
1336 if (mConnectionService != connectionService) {
1337 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1338 "that does not belong to the ConnectionService.");
1339 } else {
1340 mConnectionService = null;
1341 }
1342 }
1343
1344 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001345 * @hide
1346 */
1347 public final ConnectionService getConnectionService() {
1348 return mConnectionService;
1349 }
1350
1351 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001352 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001353 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001354 *
1355 * @param conference The conference.
1356 * @return {@code true} if the conference was successfully set.
1357 * @hide
1358 */
1359 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001360 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001361 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001362 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001363 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001364 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1365 fireConferenceChanged();
1366 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001367 return true;
1368 }
1369 return false;
1370 }
1371
1372 /**
1373 * Resets the conference that this connection is a part of.
1374 * @hide
1375 */
1376 public final void resetConference() {
1377 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001378 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001379 mConference = null;
1380 fireConferenceChanged();
1381 }
1382 }
1383
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001384 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001385 * Set some extras that can be associated with this {@code Connection}. No assumptions should
1386 * be made as to how an In-Call UI or service will handle these extras.
1387 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1388 *
1389 * @param extras The extras associated with this {@code Connection}.
1390 */
1391 public final void setExtras(@Nullable Bundle extras) {
1392 checkImmutable();
1393 mExtras = extras;
1394 for (Listener l : mListeners) {
1395 l.onExtrasChanged(this, extras);
1396 }
1397 }
1398
1399 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001400 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001401 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001402 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001403 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
1404 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07001405 */
Yorke Lee4af59352015-05-13 14:14:54 -07001406 @SystemApi
1407 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07001408 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001409
1410 /**
Yorke Lee4af59352015-05-13 14:14:54 -07001411 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
1412 *
1413 * @param state The new connection audio state.
1414 */
1415 public void onCallAudioStateChanged(CallAudioState state) {}
1416
1417 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001418 * Notifies this Connection of an internal state change. This method is called after the
1419 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001420 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001421 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001422 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001423 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001424
1425 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001426 * Notifies this Connection of a request to play a DTMF tone.
1427 *
1428 * @param c A DTMF character.
1429 */
Santos Cordonf2951102014-07-20 19:06:29 -07001430 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001431
1432 /**
1433 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1434 */
Santos Cordonf2951102014-07-20 19:06:29 -07001435 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001436
1437 /**
1438 * Notifies this Connection of a request to disconnect.
1439 */
Santos Cordonf2951102014-07-20 19:06:29 -07001440 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001441
1442 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001443 * Notifies this Connection of a request to disconnect a participant of the conference managed
1444 * by the connection.
1445 *
1446 * @param endpoint the {@link Uri} of the participant to disconnect.
1447 * @hide
1448 */
1449 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1450
1451 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001452 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001453 */
Santos Cordonf2951102014-07-20 19:06:29 -07001454 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001455
1456 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001457 * Notifies this Connection of a request to abort.
1458 */
Santos Cordonf2951102014-07-20 19:06:29 -07001459 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001460
1461 /**
1462 * Notifies this Connection of a request to hold.
1463 */
Santos Cordonf2951102014-07-20 19:06:29 -07001464 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001465
1466 /**
1467 * Notifies this Connection of a request to exit a hold state.
1468 */
Santos Cordonf2951102014-07-20 19:06:29 -07001469 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001470
1471 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001472 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001473 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001474 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001475 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001476 */
Santos Cordonf2951102014-07-20 19:06:29 -07001477 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001478
1479 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001480 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001481 * a request to accept.
1482 */
1483 public void onAnswer() {
1484 onAnswer(VideoProfile.VideoState.AUDIO_ONLY);
1485 }
1486
1487 /**
1488 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001489 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001490 */
Santos Cordonf2951102014-07-20 19:06:29 -07001491 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001492
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001493 /**
1494 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1495 */
Santos Cordonf2951102014-07-20 19:06:29 -07001496 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001497
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001498 static String toLogSafePhoneNumber(String number) {
1499 // For unknown number, log empty string.
1500 if (number == null) {
1501 return "";
1502 }
1503
1504 if (PII_DEBUG) {
1505 // When PII_DEBUG is true we emit PII.
1506 return number;
1507 }
1508
1509 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1510 // sanitized phone numbers.
1511 StringBuilder builder = new StringBuilder();
1512 for (int i = 0; i < number.length(); i++) {
1513 char c = number.charAt(i);
1514 if (c == '-' || c == '@' || c == '.') {
1515 builder.append(c);
1516 } else {
1517 builder.append('x');
1518 }
1519 }
1520 return builder.toString();
1521 }
1522
Ihab Awad542e0ea2014-05-16 10:22:16 -07001523 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001524 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001525 if (mState == STATE_DISCONNECTED && mState != state) {
1526 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001527 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001528 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001529 if (mState != state) {
1530 Log.d(this, "setState: %s", stateToString(state));
1531 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001532 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001533 for (Listener l : mListeners) {
1534 l.onStateChanged(this, state);
1535 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001536 }
1537 }
1538
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001539 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001540 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001541 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1542 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001543 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001544 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001545
1546 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001547 if (mImmutable) {
1548 throw new UnsupportedOperationException("Connection is immutable");
1549 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001550 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001551 }
1552
Evan Charltonbf11f982014-07-20 22:06:28 -07001553 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001554 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001555 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1556 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001557 * <p>
1558 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1559 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001560 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001561 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001562 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001563 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001564 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1565 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001566 }
1567
Evan Charltonbf11f982014-07-20 22:06:28 -07001568 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001569 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1570 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1571 * this should never be un-@hide-den.
1572 *
1573 * @hide
1574 */
1575 public void checkImmutable() {}
1576
1577 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001578 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1579 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1580 * that state. This connection should not be used for anything, and no other
1581 * {@code Connection}s should be attempted.
1582 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001583 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001584 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001585 * @return A {@code Connection} which indicates that the underlying connection should
1586 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001587 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001588 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001589 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001590 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001591
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001592 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001593 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001594 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001595 }
1596 }
1597
Santos Cordon823fd3c2014-08-07 18:35:18 -07001598 private final void fireConferenceChanged() {
1599 for (Listener l : mListeners) {
1600 l.onConferenceChanged(this, mConference);
1601 }
1602 }
1603
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001604 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001605 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001606 if (c instanceof Connection) {
1607 Connection connection = (Connection) c;
1608 connection.removeConnectionListener(mConnectionDeathListener);
1609 } else if (c instanceof Conference) {
1610 Conference conference = (Conference) c;
1611 conference.removeListener(mConferenceDeathListener);
1612 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001613 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001614 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001615 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001616
1617 /**
Anthony Lee17455a32015-04-24 15:25:29 -07001618 * Notifies listeners that the merge request failed.
1619 *
1620 * @hide
1621 */
1622 protected final void notifyConferenceMergeFailed() {
1623 for (Listener l : mListeners) {
1624 l.onConferenceMergeFailed(this);
1625 }
1626 }
1627
1628 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001629 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001630 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001631 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001632 * @hide
1633 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001634 protected final void updateConferenceParticipants(
1635 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001636 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001637 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001638 }
1639 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001640
1641 /**
1642 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07001643 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001644 */
1645 protected void notifyConferenceStarted() {
1646 for (Listener l : mListeners) {
1647 l.onConferenceStarted();
1648 }
1649 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001650}