blob: a9c1bf5809d48156a85d4f40deb69c37022430db [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Tyler Gunn45382162015-05-06 08:52:27 -070019import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070020import com.android.internal.telecom.IVideoCallback;
21import com.android.internal.telecom.IVideoProvider;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070022
Santos Cordon6b7f9552015-05-27 17:21:45 -070023import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070024import android.annotation.SystemApi;
Tyler Gunnb702ef82015-05-29 11:51:53 -070025import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070026import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070027import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070028import android.os.Handler;
29import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070030import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070031import android.os.Message;
32import android.os.RemoteException;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070033import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070034
Santos Cordonb6939982014-06-04 20:20:58 -070035import java.util.ArrayList;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070036import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070037import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070038import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070039import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070040
41/**
Santos Cordon895d4b82015-06-25 16:41:48 -070042 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
43 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070044 * <p>
45 * Implementations create a custom subclass of {@code Connection} and return it to the framework
46 * as the return value of
47 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
48 * or
49 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
50 * Implementations are then responsible for updating the state of the {@code Connection}, and
51 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
52 * longer used and associated resources may be recovered.
Ihab Awad542e0ea2014-05-16 10:22:16 -070053 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070054public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070055
Santos Cordon895d4b82015-06-25 16:41:48 -070056 /**
57 * The connection is initializing. This is generally the first state for a {@code Connection}
58 * returned by a {@link ConnectionService}.
59 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070060 public static final int STATE_INITIALIZING = 0;
61
Santos Cordon895d4b82015-06-25 16:41:48 -070062 /**
63 * The connection is new and not connected.
64 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070065 public static final int STATE_NEW = 1;
66
Santos Cordon895d4b82015-06-25 16:41:48 -070067 /**
68 * An incoming connection is in the ringing state. During this state, the user's ringer or
69 * vibration feature will be activated.
70 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070071 public static final int STATE_RINGING = 2;
72
Santos Cordon895d4b82015-06-25 16:41:48 -070073 /**
74 * An outgoing connection is in the dialing state. In this state the other party has not yet
75 * answered the call and the user traditionally hears a ringback tone.
76 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070077 public static final int STATE_DIALING = 3;
78
Santos Cordon895d4b82015-06-25 16:41:48 -070079 /**
80 * A connection is active. Both parties are connected to the call and can actively communicate.
81 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070082 public static final int STATE_ACTIVE = 4;
83
Santos Cordon895d4b82015-06-25 16:41:48 -070084 /**
85 * A connection is on hold.
86 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070087 public static final int STATE_HOLDING = 5;
88
Santos Cordon895d4b82015-06-25 16:41:48 -070089 /**
90 * A connection has been disconnected. This is the final state once the user has been
91 * disconnected from a call either locally, remotely or by an error in the service.
92 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070093 public static final int STATE_DISCONNECTED = 6;
94
Santos Cordon895d4b82015-06-25 16:41:48 -070095 /**
96 * Connection can currently be put on hold or unheld. This is distinct from
97 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
98 * it does not at the moment support the function. This can be true while the call is in the
99 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
100 * display a disabled 'hold' button.
101 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800102 public static final int CAPABILITY_HOLD = 0x00000001;
103
104 /** Connection supports the hold feature. */
105 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
106
107 /**
108 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
109 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
110 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
111 * capability allows a merge button to be shown while the conference is in the foreground
112 * of the in-call UI.
113 * <p>
114 * This is only intended for use by a {@link Conference}.
115 */
116 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
117
118 /**
119 * Connections within a conference can be swapped between foreground and background.
120 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
121 * <p>
122 * This is only intended for use by a {@link Conference}.
123 */
124 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
125
126 /**
127 * @hide
128 */
129 public static final int CAPABILITY_UNUSED = 0x00000010;
130
131 /** Connection supports responding via text option. */
132 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
133
134 /** Connection can be muted. */
135 public static final int CAPABILITY_MUTE = 0x00000040;
136
137 /**
138 * Connection supports conference management. This capability only applies to
139 * {@link Conference}s which can have {@link Connection}s as children.
140 */
141 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
142
143 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700144 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800145 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700146 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800147
148 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700149 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800150 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700151 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800152
153 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700154 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800155 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700156 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700157 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800158
159 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700160 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800161 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700162 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
163
164 /**
165 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700166 */
167 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
168
169 /**
170 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700171 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700172 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700173 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800174
175 /**
176 * Connection is able to be separated from its parent {@code Conference}, if any.
177 */
178 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
179
180 /**
181 * Connection is able to be individually disconnected when in a {@code Conference}.
182 */
183 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
184
185 /**
186 * Whether the call is a generic conference, where we do not know the precise state of
187 * participants in the conference (eg. on CDMA).
188 *
189 * @hide
190 */
191 public static final int CAPABILITY_GENERIC_CONFERENCE = 0x00004000;
192
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700193 /**
194 * Connection is using high definition audio.
195 * @hide
196 */
197 public static final int CAPABILITY_HIGH_DEF_AUDIO = 0x00008000;
198
199 /**
200 * Connection is using WIFI.
201 * @hide
202 */
Tyler Gunnd11a3152015-03-18 13:09:14 -0700203 public static final int CAPABILITY_WIFI = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700204
Tyler Gunn068085b2015-02-06 13:56:52 -0800205 /**
206 * Indicates that the current device callback number should be shown.
207 *
208 * @hide
209 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700210 public static final int CAPABILITY_SHOW_CALLBACK_NUMBER = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800211
Tyler Gunn96d6c402015-03-18 12:39:23 -0700212 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500213 * Speed up audio setup for MT call.
214 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700215 */
216 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800217
Rekha Kumar07366812015-03-24 16:42:31 -0700218 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700219 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700220 */
221 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
222
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700223 /**
224 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700225 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700226 */
227 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
228
Tyler Gunnd4091732015-06-29 09:15:37 -0700229 /**
230 * For a conference, indicates the conference will not have child connections.
231 * <p>
232 * An example of a conference with child connections is a GSM conference call, where the radio
233 * retains connections to the individual participants of the conference. Another example is an
234 * IMS conference call where conference event package functionality is supported; in this case
235 * the conference server ensures the radio is aware of the participants in the conference, which
236 * are represented by child connections.
237 * <p>
238 * An example of a conference with no child connections is an IMS conference call with no
239 * conference event package support. Such a conference is represented by the radio as a single
240 * connection to the IMS conference server.
241 * <p>
242 * Indicating whether a conference has children or not is important to help user interfaces
243 * visually represent a conference. A conference with no children, for example, will have the
244 * conference connection shown in the list of calls on a Bluetooth device, where if the
245 * conference has children, only the children will be shown in the list of calls on a Bluetooth
246 * device.
247 * @hide
248 */
249 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
250
Bryce Lee81901682015-08-28 16:38:02 -0700251 /**
252 * Indicates that the connection itself wants to handle any sort of reply response, rather than
253 * relying on SMS.
254 * @hide
255 */
256 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
257
Tyler Gunn96d6c402015-03-18 12:39:23 -0700258 //**********************************************************************************************
Bryce Lee81901682015-08-28 16:38:02 -0700259 // Next CAPABILITY value: 0x00800000
Tyler Gunn96d6c402015-03-18 12:39:23 -0700260 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800261
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700262 /**
263 * Connection extra key used to store the last forwarded number associated with the current
264 * connection. Used to communicate to the user interface that the connection was forwarded via
265 * the specified number.
266 */
267 public static final String EXTRA_LAST_FORWARDED_NUMBER =
268 "android.telecom.extra.LAST_FORWARDED_NUMBER";
269
270 /**
271 * Connection extra key used to store a child number associated with the current connection.
272 * Used to communicate to the user interface that the connection was received via
273 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
274 * address.
275 */
276 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
277
278 /**
279 * Connection extra key used to store the subject for an incoming call. The user interface can
280 * query this extra and display its contents for incoming calls. Will only be used if the
281 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
282 */
283 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
284
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700285 // Flag controlling whether PII is emitted into the logs
286 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
287
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800288 /**
289 * Whether the given capabilities support the specified capability.
290 *
291 * @param capabilities A capability bit field.
292 * @param capability The capability to check capabilities for.
293 * @return Whether the specified capability is supported.
294 * @hide
295 */
296 public static boolean can(int capabilities, int capability) {
297 return (capabilities & capability) != 0;
298 }
299
300 /**
301 * Whether the capabilities of this {@code Connection} supports the specified capability.
302 *
303 * @param capability The capability to check capabilities for.
304 * @return Whether the specified capability is supported.
305 * @hide
306 */
307 public boolean can(int capability) {
308 return can(mConnectionCapabilities, capability);
309 }
310
311 /**
312 * Removes the specified capability from the set of capabilities of this {@code Connection}.
313 *
314 * @param capability The capability to remove from the set.
315 * @hide
316 */
317 public void removeCapability(int capability) {
318 mConnectionCapabilities &= ~capability;
319 }
320
321 /**
322 * Adds the specified capability to the set of capabilities of this {@code Connection}.
323 *
324 * @param capability The capability to add to the set.
325 * @hide
326 */
327 public void addCapability(int capability) {
328 mConnectionCapabilities |= capability;
329 }
330
331
332 public static String capabilitiesToString(int capabilities) {
333 StringBuilder builder = new StringBuilder();
334 builder.append("[Capabilities:");
335 if (can(capabilities, CAPABILITY_HOLD)) {
336 builder.append(" CAPABILITY_HOLD");
337 }
338 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
339 builder.append(" CAPABILITY_SUPPORT_HOLD");
340 }
341 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
342 builder.append(" CAPABILITY_MERGE_CONFERENCE");
343 }
344 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
345 builder.append(" CAPABILITY_SWAP_CONFERENCE");
346 }
347 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
348 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
349 }
350 if (can(capabilities, CAPABILITY_MUTE)) {
351 builder.append(" CAPABILITY_MUTE");
352 }
353 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
354 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
355 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700356 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
357 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
358 }
359 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
360 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
361 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700362 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
363 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800364 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700365 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
366 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
367 }
368 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
369 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
370 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700371 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
372 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800373 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800374 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
375 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800376 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800377 if (can(capabilities, CAPABILITY_WIFI)) {
378 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800379 }
380 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
381 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
382 }
Tyler Gunn068085b2015-02-06 13:56:52 -0800383 if (can(capabilities, CAPABILITY_SHOW_CALLBACK_NUMBER)) {
384 builder.append(" CAPABILITY_SHOW_CALLBACK_NUMBER");
385 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500386 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700387 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500388 }
Rekha Kumar07366812015-03-24 16:42:31 -0700389 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
390 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
391 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700392 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
393 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
394 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700395 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
396 builder.append(" CAPABILITY_SINGLE_PARTY_CONFERENCE");
397 }
Bryce Lee81901682015-08-28 16:38:02 -0700398 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
399 builder.append(" CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION");
400 }
401
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800402 builder.append("]");
403 return builder.toString();
404 }
405
Sailesh Nepal091768c2014-06-30 15:15:23 -0700406 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700407 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700408 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700409 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700410 public void onCallerDisplayNameChanged(
411 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700412 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700413 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700414 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800415 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700416 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700417 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800418 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Bryce Leedd976b12015-11-17 12:31:53 -0800419 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700420 public void onVideoProviderChanged(
421 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700422 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
423 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800424 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700425 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700426 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700427 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800428 public void onConferenceParticipantsChanged(Connection c,
429 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800430 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700431 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700432 public void onExtrasChanged(Connection c, Bundle extras) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700433 }
434
Tyler Gunnb702ef82015-05-29 11:51:53 -0700435 /**
436 * Provides a means of controlling the video session associated with a {@link Connection}.
437 * <p>
438 * Implementations create a custom subclass of {@link VideoProvider} and the
439 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
440 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
441 * should set the {@link VideoProvider}.
442 * <p>
443 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
444 * {@link InCallService} implementations to issue requests related to the video session;
445 * it provides a means for the {@link ConnectionService} to report events and information
446 * related to the video session to Telecom and the {@link InCallService} implementations.
447 * <p>
448 * {@link InCallService} implementations interact with the {@link VideoProvider} via
449 * {@link android.telecom.InCallService.VideoCall}.
450 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700451 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700452
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700453 /**
454 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700455 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700456 */
457 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700458
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700459 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700460 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
461 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700462 */
463 public static final int SESSION_EVENT_RX_RESUME = 2;
464
465 /**
466 * Video transmission has begun. This occurs after a negotiated start of video transmission
467 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700468 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700469 */
470 public static final int SESSION_EVENT_TX_START = 3;
471
472 /**
473 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
474 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700475 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700476 */
477 public static final int SESSION_EVENT_TX_STOP = 4;
478
479 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700480 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
481 * this as a cue to inform the user the camera is not available.
482 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700483 */
484 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
485
486 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700487 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
488 * for operation. The {@link InCallService} can use this as a cue to inform the user that
489 * the camera has become available again.
490 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700491 */
492 public static final int SESSION_EVENT_CAMERA_READY = 6;
493
494 /**
495 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700496 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700497 */
498 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
499
500 /**
501 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700502 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700503 */
504 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
505
506 /**
507 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700508 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700509 */
510 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
511
Rekha Kumar07366812015-03-24 16:42:31 -0700512 /**
513 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700514 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700515 */
516 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
517
518 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700519 * Session modify request rejected by remote user.
520 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700521 */
522 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
523
Tyler Gunn75958422015-04-15 14:23:42 -0700524 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700525 private static final int MSG_SET_CAMERA = 2;
526 private static final int MSG_SET_PREVIEW_SURFACE = 3;
527 private static final int MSG_SET_DISPLAY_SURFACE = 4;
528 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
529 private static final int MSG_SET_ZOOM = 6;
530 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
531 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
532 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800533 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700534 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700535 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700536
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700537 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700538 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700539
540 /**
541 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700542 *
543 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
544 * load factor before resizing, 1 means we only expect a single thread to
545 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700546 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700547 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
548 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700549
550 /**
551 * Default handler used to consolidate binder method calls onto a single thread.
552 */
553 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700554 public VideoProviderHandler() {
555 super();
556 }
557
558 public VideoProviderHandler(Looper looper) {
559 super(looper);
560 }
561
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700562 @Override
563 public void handleMessage(Message msg) {
564 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700565 case MSG_ADD_VIDEO_CALLBACK: {
566 IBinder binder = (IBinder) msg.obj;
567 IVideoCallback callback = IVideoCallback.Stub
568 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700569 if (callback == null) {
570 Log.w(this, "addVideoProvider - skipped; callback is null.");
571 break;
572 }
573
Tyler Gunn75958422015-04-15 14:23:42 -0700574 if (mVideoCallbacks.containsKey(binder)) {
575 Log.i(this, "addVideoProvider - skipped; already present.");
576 break;
577 }
578 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700579 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700580 }
581 case MSG_REMOVE_VIDEO_CALLBACK: {
582 IBinder binder = (IBinder) msg.obj;
583 IVideoCallback callback = IVideoCallback.Stub
584 .asInterface((IBinder) msg.obj);
585 if (!mVideoCallbacks.containsKey(binder)) {
586 Log.i(this, "removeVideoProvider - skipped; not present.");
587 break;
588 }
589 mVideoCallbacks.remove(binder);
590 break;
591 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700592 case MSG_SET_CAMERA:
593 onSetCamera((String) msg.obj);
594 break;
595 case MSG_SET_PREVIEW_SURFACE:
596 onSetPreviewSurface((Surface) msg.obj);
597 break;
598 case MSG_SET_DISPLAY_SURFACE:
599 onSetDisplaySurface((Surface) msg.obj);
600 break;
601 case MSG_SET_DEVICE_ORIENTATION:
602 onSetDeviceOrientation(msg.arg1);
603 break;
604 case MSG_SET_ZOOM:
605 onSetZoom((Float) msg.obj);
606 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700607 case MSG_SEND_SESSION_MODIFY_REQUEST: {
608 SomeArgs args = (SomeArgs) msg.obj;
609 try {
610 onSendSessionModifyRequest((VideoProfile) args.arg1,
611 (VideoProfile) args.arg2);
612 } finally {
613 args.recycle();
614 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700615 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700616 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700617 case MSG_SEND_SESSION_MODIFY_RESPONSE:
618 onSendSessionModifyResponse((VideoProfile) msg.obj);
619 break;
620 case MSG_REQUEST_CAMERA_CAPABILITIES:
621 onRequestCameraCapabilities();
622 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800623 case MSG_REQUEST_CONNECTION_DATA_USAGE:
624 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700625 break;
626 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700627 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700628 break;
629 default:
630 break;
631 }
632 }
633 }
634
635 /**
636 * IVideoProvider stub implementation.
637 */
638 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700639 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700640 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700641 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
642 }
643
644 public void removeVideoCallback(IBinder videoCallbackBinder) {
645 mMessageHandler.obtainMessage(
646 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700647 }
648
649 public void setCamera(String cameraId) {
650 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
651 }
652
653 public void setPreviewSurface(Surface surface) {
654 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
655 }
656
657 public void setDisplaySurface(Surface surface) {
658 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
659 }
660
661 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700662 mMessageHandler.obtainMessage(
663 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700664 }
665
666 public void setZoom(float value) {
667 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
668 }
669
Tyler Gunn45382162015-05-06 08:52:27 -0700670 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
671 SomeArgs args = SomeArgs.obtain();
672 args.arg1 = fromProfile;
673 args.arg2 = toProfile;
674 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700675 }
676
677 public void sendSessionModifyResponse(VideoProfile responseProfile) {
678 mMessageHandler.obtainMessage(
679 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
680 }
681
682 public void requestCameraCapabilities() {
683 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
684 }
685
686 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800687 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700688 }
689
Yorke Lee32f24732015-05-12 16:18:03 -0700690 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700691 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
692 }
693 }
694
695 public VideoProvider() {
696 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700697 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700698 }
699
700 /**
701 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
702 *
703 * @param looper The looper.
704 * @hide
705 */
706 public VideoProvider(Looper looper) {
707 mBinder = new VideoProvider.VideoProviderBinder();
708 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700709 }
710
711 /**
712 * Returns binder object which can be used across IPC methods.
713 * @hide
714 */
715 public final IVideoProvider getInterface() {
716 return mBinder;
717 }
718
719 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700720 * Sets the camera to be used for the outgoing video.
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#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700728 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700729 * @param cameraId The id of the camera (use ids as reported by
730 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700731 */
732 public abstract void onSetCamera(String cameraId);
733
734 /**
735 * Sets the surface to be used for displaying a preview of what the user's camera is
736 * currently capturing. When video transmission is enabled, this is the video signal which
737 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700738 * <p>
739 * Sent from the {@link InCallService} via
740 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700741 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700742 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700743 */
744 public abstract void onSetPreviewSurface(Surface surface);
745
746 /**
747 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700748 * <p>
749 * Sent from the {@link InCallService} via
750 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700751 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700752 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700753 */
754 public abstract void onSetDisplaySurface(Surface surface);
755
756 /**
757 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
758 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700759 * <p>
760 * Sent from the {@link InCallService} via
761 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700762 *
763 * @param rotation The device orientation, in degrees.
764 */
765 public abstract void onSetDeviceOrientation(int rotation);
766
767 /**
768 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700769 * <p>
770 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700771 *
772 * @param value The camera zoom ratio.
773 */
774 public abstract void onSetZoom(float value);
775
776 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700777 * Issues a request to modify the properties of the current video session.
778 * <p>
779 * Example scenarios include: requesting an audio-only call to be upgraded to a
780 * bi-directional video call, turning on or off the user's camera, sending a pause signal
781 * when the {@link InCallService} is no longer the foreground application.
782 * <p>
783 * If the {@link VideoProvider} determines a request to be invalid, it should call
784 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
785 * invalid request back to the {@link InCallService}.
786 * <p>
787 * Where a request requires confirmation from the user of the peer device, the
788 * {@link VideoProvider} must communicate the request to the peer device and handle the
789 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
790 * is used to inform the {@link InCallService} of the result of the request.
791 * <p>
792 * Sent from the {@link InCallService} via
793 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700794 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700795 * @param fromProfile The video profile prior to the request.
796 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700797 */
Tyler Gunn45382162015-05-06 08:52:27 -0700798 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
799 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700800
Tyler Gunnb702ef82015-05-29 11:51:53 -0700801 /**
802 * Provides a response to a request to change the current video session properties.
803 * <p>
804 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
805 * video call, could decline the request and keep the call as audio-only.
806 * In such a scenario, the {@code responseProfile} would have a video state of
807 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
808 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
809 * <p>
810 * Sent from the {@link InCallService} via
811 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
812 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
813 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700814 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700815 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700816 */
817 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
818
819 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700820 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
821 * <p>
822 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
823 * camera via
824 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
825 * <p>
826 * Sent from the {@link InCallService} via
827 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700828 */
829 public abstract void onRequestCameraCapabilities();
830
831 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700832 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
833 * video component of the current {@link Connection}.
834 * <p>
835 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
836 * via {@link VideoProvider#setCallDataUsage(long)}.
837 * <p>
838 * Sent from the {@link InCallService} via
839 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700840 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800841 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700842
843 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700844 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
845 * the peer device when the video signal is paused.
846 * <p>
847 * Sent from the {@link InCallService} via
848 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700849 *
850 * @param uri URI of image to display.
851 */
Yorke Lee32f24732015-05-12 16:18:03 -0700852 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700853
854 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700855 * Used to inform listening {@link InCallService} implementations when the
856 * {@link VideoProvider} receives a session modification request.
857 * <p>
858 * Received by the {@link InCallService} via
859 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700860 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700861 * @param videoProfile The requested video profile.
862 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700863 */
864 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700865 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700866 for (IVideoCallback callback : mVideoCallbacks.values()) {
867 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700868 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700869 } catch (RemoteException ignored) {
870 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700871 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700872 }
873 }
874 }
875
876 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700877 * Used to inform listening {@link InCallService} implementations when the
878 * {@link VideoProvider} receives a response to a session modification request.
879 * <p>
880 * Received by the {@link InCallService} via
881 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
882 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700883 *
884 * @param status Status of the session modify request. Valid values are
885 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
886 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -0700887 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
888 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
889 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
890 * @param requestedProfile The original request which was sent to the peer device.
891 * @param responseProfile The actual profile changes agreed to by the peer device.
892 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700893 */
894 public void receiveSessionModifyResponse(int status,
895 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700896 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700897 for (IVideoCallback callback : mVideoCallbacks.values()) {
898 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700899 callback.receiveSessionModifyResponse(status, requestedProfile,
900 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700901 } catch (RemoteException ignored) {
902 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700903 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700904 }
905 }
906 }
907
908 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700909 * Used to inform listening {@link InCallService} implementations when the
910 * {@link VideoProvider} reports a call session event.
911 * <p>
912 * Received by the {@link InCallService} via
913 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700914 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700915 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
916 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
917 * {@link VideoProvider#SESSION_EVENT_TX_START},
918 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
919 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
920 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700921 */
922 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -0700923 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700924 for (IVideoCallback callback : mVideoCallbacks.values()) {
925 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700926 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700927 } catch (RemoteException ignored) {
928 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700929 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700930 }
931 }
932 }
933
934 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700935 * Used to inform listening {@link InCallService} implementations when the dimensions of the
936 * peer's video have changed.
937 * <p>
938 * This could occur if, for example, the peer rotates their device, changing the aspect
939 * ratio of the video, or if the user switches between the back and front cameras.
940 * <p>
941 * Received by the {@link InCallService} via
942 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700943 *
944 * @param width The updated peer video width.
945 * @param height The updated peer video height.
946 */
947 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -0700948 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700949 for (IVideoCallback callback : mVideoCallbacks.values()) {
950 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700951 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700952 } catch (RemoteException ignored) {
953 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700954 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700955 }
956 }
957 }
958
959 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700960 * Used to inform listening {@link InCallService} implementations when the data usage of the
961 * video associated with the current {@link Connection} has changed.
962 * <p>
963 * This could be in response to a preview request via
964 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -0700965 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
966 * 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 -0700967 * <p>
968 * Received by the {@link InCallService} via
969 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700970 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700971 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
972 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700973 */
Yorke Lee32f24732015-05-12 16:18:03 -0700974 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -0700975 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700976 for (IVideoCallback callback : mVideoCallbacks.values()) {
977 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700978 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700979 } catch (RemoteException ignored) {
980 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700981 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700982 }
983 }
984 }
985
986 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700987 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700988 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700989 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -0700990 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
991 * @hide
992 */
993 public void changeCallDataUsage(long dataUsage) {
994 setCallDataUsage(dataUsage);
995 }
996
997 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700998 * Used to inform listening {@link InCallService} implementations when the capabilities of
999 * the current camera have changed.
1000 * <p>
1001 * The {@link VideoProvider} should call this in response to
1002 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1003 * changed via {@link VideoProvider#onSetCamera(String)}.
1004 * <p>
1005 * Received by the {@link InCallService} via
1006 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1007 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001008 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001009 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001010 */
Yorke Lee400470f2015-05-12 13:31:25 -07001011 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001012 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001013 for (IVideoCallback callback : mVideoCallbacks.values()) {
1014 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001015 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001016 } catch (RemoteException ignored) {
1017 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001018 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001019 }
1020 }
1021 }
Rekha Kumar07366812015-03-24 16:42:31 -07001022
1023 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001024 * Used to inform listening {@link InCallService} implementations when the video quality
1025 * of the call has changed.
1026 * <p>
1027 * Received by the {@link InCallService} via
1028 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001029 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001030 * @param videoQuality The updated video quality. Valid values:
1031 * {@link VideoProfile#QUALITY_HIGH},
1032 * {@link VideoProfile#QUALITY_MEDIUM},
1033 * {@link VideoProfile#QUALITY_LOW},
1034 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001035 */
1036 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001037 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001038 for (IVideoCallback callback : mVideoCallbacks.values()) {
1039 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001040 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001041 } catch (RemoteException ignored) {
1042 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001043 }
Rekha Kumar07366812015-03-24 16:42:31 -07001044 }
1045 }
1046 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001047 }
1048
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001049 private final Listener mConnectionDeathListener = new Listener() {
1050 @Override
1051 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001052 if (mConferenceables.remove(c)) {
1053 fireOnConferenceableConnectionsChanged();
1054 }
1055 }
1056 };
1057
1058 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1059 @Override
1060 public void onDestroyed(Conference c) {
1061 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001062 fireOnConferenceableConnectionsChanged();
1063 }
1064 }
1065 };
1066
Jay Shrauner229e3822014-08-15 09:23:07 -07001067 /**
1068 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1069 * load factor before resizing, 1 means we only expect a single thread to
1070 * access the map so make only a single shard
1071 */
1072 private final Set<Listener> mListeners = Collections.newSetFromMap(
1073 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001074 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1075 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001076 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001077
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001078 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001079 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001080 private Uri mAddress;
1081 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001082 private String mCallerDisplayName;
1083 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001084 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001085 private int mConnectionCapabilities;
Bryce Leedd976b12015-11-17 12:31:53 -08001086 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001087 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001088 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001089 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001090 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001091 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001092 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001093 private Conference mConference;
1094 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001095 private Bundle mExtras;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001096
1097 /**
1098 * Create a new Connection.
1099 */
Santos Cordonf2951102014-07-20 19:06:29 -07001100 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001101
1102 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001103 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001104 */
Andrew Lee100e2932014-09-08 15:34:24 -07001105 public final Uri getAddress() {
1106 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001107 }
1108
1109 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001110 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001111 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001112 */
Andrew Lee100e2932014-09-08 15:34:24 -07001113 public final int getAddressPresentation() {
1114 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001115 }
1116
1117 /**
1118 * @return The caller display name (CNAP).
1119 */
1120 public final String getCallerDisplayName() {
1121 return mCallerDisplayName;
1122 }
1123
1124 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001125 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001126 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001127 */
1128 public final int getCallerDisplayNamePresentation() {
1129 return mCallerDisplayNamePresentation;
1130 }
1131
1132 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001133 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001134 */
1135 public final int getState() {
1136 return mState;
1137 }
1138
1139 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001140 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001141 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1142 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1143 * {@link VideoProfile#STATE_TX_ENABLED},
1144 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001145 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001146 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001147 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001148 */
1149 public final int getVideoState() {
1150 return mVideoState;
1151 }
1152
1153 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001154 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001155 * being routed by the system. This is {@code null} if this Connection
1156 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001157 * @deprecated Use {@link #getCallAudioState()} instead.
1158 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001159 */
Yorke Lee4af59352015-05-13 14:14:54 -07001160 @SystemApi
1161 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001162 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001163 if (mCallAudioState == null) {
1164 return null;
1165 }
Yorke Lee4af59352015-05-13 14:14:54 -07001166 return new AudioState(mCallAudioState);
1167 }
1168
1169 /**
1170 * @return The audio state of the connection, describing how its audio is currently
1171 * being routed by the system. This is {@code null} if this Connection
1172 * does not directly know about its audio state.
1173 */
1174 public final CallAudioState getCallAudioState() {
1175 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001176 }
1177
1178 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001179 * @return The conference that this connection is a part of. Null if it is not part of any
1180 * conference.
1181 */
1182 public final Conference getConference() {
1183 return mConference;
1184 }
1185
1186 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001187 * Returns whether this connection is requesting that the system play a ringback tone
1188 * on its behalf.
1189 */
Andrew Lee100e2932014-09-08 15:34:24 -07001190 public final boolean isRingbackRequested() {
1191 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001192 }
1193
1194 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001195 * @return True if the connection's audio mode is VOIP.
1196 */
1197 public final boolean getAudioModeIsVoip() {
1198 return mAudioModeIsVoip;
1199 }
1200
1201 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001202 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1203 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1204 * start time of the conference.
1205 *
1206 * @return The time at which the {@code Connnection} was connected.
1207 *
1208 * @hide
1209 */
1210 public final long getConnectTimeMillis() {
1211 return mConnectTimeMillis;
1212 }
1213
1214 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001215 * @return The status hints for this connection.
1216 */
1217 public final StatusHints getStatusHints() {
1218 return mStatusHints;
1219 }
1220
1221 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001222 * @return The extras associated with this connection.
1223 */
1224 public final Bundle getExtras() {
1225 return mExtras;
1226 }
1227
1228 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001229 * Assign a listener to be notified of state changes.
1230 *
1231 * @param l A listener.
1232 * @return This Connection.
1233 *
1234 * @hide
1235 */
1236 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001237 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001238 return this;
1239 }
1240
1241 /**
1242 * Remove a previously assigned listener that was being notified of state changes.
1243 *
1244 * @param l A Listener.
1245 * @return This Connection.
1246 *
1247 * @hide
1248 */
1249 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001250 if (l != null) {
1251 mListeners.remove(l);
1252 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001253 return this;
1254 }
1255
1256 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001257 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001258 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001259 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001260 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001261 }
1262
1263 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001264 * Inform this Connection that the state of its audio output has been changed externally.
1265 *
1266 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001267 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001268 */
Yorke Lee4af59352015-05-13 14:14:54 -07001269 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001270 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001271 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001272 mCallAudioState = state;
1273 onAudioStateChanged(getAudioState());
1274 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001275 }
1276
1277 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001278 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001279 * @return A string representation of the value.
1280 */
1281 public static String stateToString(int state) {
1282 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001283 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001284 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001285 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001286 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001287 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001288 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001289 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001290 return "DIALING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001291 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001292 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001293 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001294 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001295 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001296 return "DISCONNECTED";
1297 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001298 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001299 return "UNKNOWN";
1300 }
1301 }
1302
1303 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001304 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001305 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001306 public final int getConnectionCapabilities() {
1307 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001308 }
1309
1310 /**
Bryce Leedd976b12015-11-17 12:31:53 -08001311 * Returns the connection's supported audio routes.
1312 *
1313 * @hide
1314 */
1315 public final int getSupportedAudioRoutes() {
1316 return mSupportedAudioRoutes;
1317 }
1318
1319 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001320 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001321 *
Andrew Lee100e2932014-09-08 15:34:24 -07001322 * @param address The new address.
1323 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001324 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001325 */
Andrew Lee100e2932014-09-08 15:34:24 -07001326 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001327 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001328 Log.d(this, "setAddress %s", address);
1329 mAddress = address;
1330 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001331 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001332 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001333 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001334 }
1335
1336 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001337 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001338 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001339 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001340 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001341 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001342 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001343 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001344 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001345 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001346 mCallerDisplayName = callerDisplayName;
1347 mCallerDisplayNamePresentation = presentation;
1348 for (Listener l : mListeners) {
1349 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1350 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001351 }
1352
1353 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001354 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001355 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1356 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1357 * {@link VideoProfile#STATE_TX_ENABLED},
1358 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001359 *
1360 * @param videoState The new video state.
1361 */
1362 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001363 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001364 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001365 mVideoState = videoState;
1366 for (Listener l : mListeners) {
1367 l.onVideoStateChanged(this, mVideoState);
1368 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001369 }
1370
1371 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001372 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001373 * communicate).
1374 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001375 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001376 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001377 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001378 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001379 }
1380
1381 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001382 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001383 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001384 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001385 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001386 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001387 }
1388
1389 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001390 * Sets state to initializing (this Connection is not yet ready to be used).
1391 */
1392 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001393 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001394 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001395 }
1396
1397 /**
1398 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1399 */
1400 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001401 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001402 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001403 }
1404
1405 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001406 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001407 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001408 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001409 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001410 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001411 }
1412
1413 /**
1414 * Sets state to be on hold.
1415 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001416 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001417 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001418 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001419 }
1420
1421 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001422 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001423 * @param videoProvider The video provider.
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001424 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001425 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001426 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001427 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001428 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001429 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001430 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001431 }
1432
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001433 public final VideoProvider getVideoProvider() {
1434 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001435 }
1436
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001437 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001438 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001439 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001440 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001441 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001442 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001443 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001444 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001445 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001446 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001447 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001448 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001449 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001450 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001451 }
1452
1453 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001454 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1455 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1456 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1457 * to send an {@link #onPostDialContinue(boolean)} signal.
1458 *
1459 * @param remaining The DTMF character sequence remaining to be emitted once the
1460 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1461 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001462 */
1463 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001464 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001465 for (Listener l : mListeners) {
1466 l.onPostDialWait(this, remaining);
1467 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001468 }
1469
1470 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001471 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1472 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001473 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001474 *
1475 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001476 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001477 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001478 checkImmutable();
1479 for (Listener l : mListeners) {
1480 l.onPostDialChar(this, nextChar);
1481 }
1482 }
1483
1484 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001485 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001486 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001487 *
1488 * @param ringback Whether the ringback tone is to be played.
1489 */
Andrew Lee100e2932014-09-08 15:34:24 -07001490 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001491 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001492 if (mRingbackRequested != ringback) {
1493 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001494 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001495 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001496 }
1497 }
Ihab Awadf8358972014-05-28 16:46:42 -07001498 }
1499
1500 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001501 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001502 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001503 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001504 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001505 public final void setConnectionCapabilities(int connectionCapabilities) {
1506 checkImmutable();
1507 if (mConnectionCapabilities != connectionCapabilities) {
1508 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001509 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001510 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001511 }
1512 }
Santos Cordonb6939982014-06-04 20:20:58 -07001513 }
1514
1515 /**
Bryce Leedd976b12015-11-17 12:31:53 -08001516 * Sets the supported audio routes.
1517 *
1518 * @param supportedAudioRoutes the supported audio routes as a bitmask.
1519 * See {@link CallAudioState}
1520 * @hide
1521 */
1522 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
1523 if (mSupportedAudioRoutes != supportedAudioRoutes) {
1524 mSupportedAudioRoutes = supportedAudioRoutes;
1525 for (Listener l : mListeners) {
1526 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
1527 }
1528 }
1529 }
1530
1531 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001532 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001533 */
Evan Charlton36a71342014-07-19 16:31:02 -07001534 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001535 for (Listener l : mListeners) {
1536 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001537 }
Santos Cordonb6939982014-06-04 20:20:58 -07001538 }
1539
1540 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001541 * Requests that the framework use VOIP audio mode for this connection.
1542 *
1543 * @param isVoip True if the audio mode is VOIP.
1544 */
1545 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001546 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001547 mAudioModeIsVoip = isVoip;
1548 for (Listener l : mListeners) {
1549 l.onAudioModeIsVoipChanged(this, isVoip);
1550 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001551 }
1552
1553 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001554 * Sets the time at which a call became active on this Connection. This is set only
1555 * when a conference call becomes active on this connection.
1556 *
1557 * @param connectionTimeMillis The connection time, in milliseconds.
1558 *
1559 * @hide
1560 */
1561 public final void setConnectTimeMillis(long connectTimeMillis) {
1562 mConnectTimeMillis = connectTimeMillis;
1563 }
1564
1565 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001566 * Sets the label and icon status to display in the in-call UI.
1567 *
1568 * @param statusHints The status label and icon to set.
1569 */
1570 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001571 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001572 mStatusHints = statusHints;
1573 for (Listener l : mListeners) {
1574 l.onStatusHintsChanged(this, statusHints);
1575 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001576 }
1577
1578 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001579 * Sets the connections with which this connection can be conferenced.
1580 *
1581 * @param conferenceableConnections The set of connections this connection can conference with.
1582 */
1583 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001584 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001585 clearConferenceableList();
1586 for (Connection c : conferenceableConnections) {
1587 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1588 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001589 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001590 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001591 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001592 }
1593 }
1594 fireOnConferenceableConnectionsChanged();
1595 }
1596
1597 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001598 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1599 * or conferences with which this connection can be conferenced.
1600 *
1601 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001602 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001603 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001604 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001605 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001606 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1607 // small amount of items here.
1608 if (!mConferenceables.contains(c)) {
1609 if (c instanceof Connection) {
1610 Connection connection = (Connection) c;
1611 connection.addConnectionListener(mConnectionDeathListener);
1612 } else if (c instanceof Conference) {
1613 Conference conference = (Conference) c;
1614 conference.addListener(mConferenceDeathListener);
1615 }
1616 mConferenceables.add(c);
1617 }
1618 }
1619 fireOnConferenceableConnectionsChanged();
1620 }
1621
1622 /**
1623 * Returns the connections or conferences with which this connection can be conferenced.
1624 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001625 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001626 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001627 }
1628
Yorke Lee53463962015-08-04 16:07:19 -07001629 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001630 * @hide
1631 */
1632 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001633 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001634 if (mConnectionService != null) {
1635 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1636 "which is already associated with another ConnectionService.");
1637 } else {
1638 mConnectionService = connectionService;
1639 }
1640 }
1641
1642 /**
1643 * @hide
1644 */
1645 public final void unsetConnectionService(ConnectionService connectionService) {
1646 if (mConnectionService != connectionService) {
1647 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1648 "that does not belong to the ConnectionService.");
1649 } else {
1650 mConnectionService = null;
1651 }
1652 }
1653
1654 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001655 * @hide
1656 */
1657 public final ConnectionService getConnectionService() {
1658 return mConnectionService;
1659 }
1660
1661 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001662 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001663 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001664 *
1665 * @param conference The conference.
1666 * @return {@code true} if the conference was successfully set.
1667 * @hide
1668 */
1669 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001670 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001671 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001672 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001673 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001674 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1675 fireConferenceChanged();
1676 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001677 return true;
1678 }
1679 return false;
1680 }
1681
1682 /**
1683 * Resets the conference that this connection is a part of.
1684 * @hide
1685 */
1686 public final void resetConference() {
1687 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001688 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001689 mConference = null;
1690 fireConferenceChanged();
1691 }
1692 }
1693
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001694 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001695 * Set some extras that can be associated with this {@code Connection}. No assumptions should
1696 * be made as to how an In-Call UI or service will handle these extras.
1697 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1698 *
1699 * @param extras The extras associated with this {@code Connection}.
1700 */
1701 public final void setExtras(@Nullable Bundle extras) {
1702 checkImmutable();
1703 mExtras = extras;
1704 for (Listener l : mListeners) {
1705 l.onExtrasChanged(this, extras);
1706 }
1707 }
1708
1709 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001710 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001711 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001712 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001713 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
1714 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07001715 */
Yorke Lee4af59352015-05-13 14:14:54 -07001716 @SystemApi
1717 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07001718 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001719
1720 /**
Yorke Lee4af59352015-05-13 14:14:54 -07001721 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
1722 *
1723 * @param state The new connection audio state.
1724 */
1725 public void onCallAudioStateChanged(CallAudioState state) {}
1726
1727 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001728 * Notifies this Connection of an internal state change. This method is called after the
1729 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001730 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001731 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001732 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001733 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001734
1735 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001736 * Notifies this Connection of a request to play a DTMF tone.
1737 *
1738 * @param c A DTMF character.
1739 */
Santos Cordonf2951102014-07-20 19:06:29 -07001740 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001741
1742 /**
1743 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1744 */
Santos Cordonf2951102014-07-20 19:06:29 -07001745 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001746
1747 /**
1748 * Notifies this Connection of a request to disconnect.
1749 */
Santos Cordonf2951102014-07-20 19:06:29 -07001750 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001751
1752 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001753 * Notifies this Connection of a request to disconnect a participant of the conference managed
1754 * by the connection.
1755 *
1756 * @param endpoint the {@link Uri} of the participant to disconnect.
1757 * @hide
1758 */
1759 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1760
1761 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001762 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001763 */
Santos Cordonf2951102014-07-20 19:06:29 -07001764 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001765
1766 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001767 * Notifies this Connection of a request to abort.
1768 */
Santos Cordonf2951102014-07-20 19:06:29 -07001769 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001770
1771 /**
1772 * Notifies this Connection of a request to hold.
1773 */
Santos Cordonf2951102014-07-20 19:06:29 -07001774 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001775
1776 /**
1777 * Notifies this Connection of a request to exit a hold state.
1778 */
Santos Cordonf2951102014-07-20 19:06:29 -07001779 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001780
1781 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001782 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001783 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001784 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001785 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001786 */
Santos Cordonf2951102014-07-20 19:06:29 -07001787 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001788
1789 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001790 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001791 * a request to accept.
1792 */
1793 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07001794 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07001795 }
1796
1797 /**
1798 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001799 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001800 */
Santos Cordonf2951102014-07-20 19:06:29 -07001801 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001802
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001803 /**
Bryce Lee81901682015-08-28 16:38:02 -07001804 * Notifies ths Connection of a request reject with a message.
1805 *
1806 * @hide
1807 */
1808 public void onReject(String replyMessage) {}
1809
1810 /**
Bryce Leecac50772015-11-17 15:13:29 -08001811 * Notifies the Connection of a request to silence the ringer.
1812 *
1813 * @hide
1814 */
1815 public void onSilence() {}
1816
1817 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001818 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1819 */
Santos Cordonf2951102014-07-20 19:06:29 -07001820 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001821
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001822 static String toLogSafePhoneNumber(String number) {
1823 // For unknown number, log empty string.
1824 if (number == null) {
1825 return "";
1826 }
1827
1828 if (PII_DEBUG) {
1829 // When PII_DEBUG is true we emit PII.
1830 return number;
1831 }
1832
1833 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1834 // sanitized phone numbers.
1835 StringBuilder builder = new StringBuilder();
1836 for (int i = 0; i < number.length(); i++) {
1837 char c = number.charAt(i);
1838 if (c == '-' || c == '@' || c == '.') {
1839 builder.append(c);
1840 } else {
1841 builder.append('x');
1842 }
1843 }
1844 return builder.toString();
1845 }
1846
Ihab Awad542e0ea2014-05-16 10:22:16 -07001847 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001848 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001849 if (mState == STATE_DISCONNECTED && mState != state) {
1850 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001851 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001852 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001853 if (mState != state) {
1854 Log.d(this, "setState: %s", stateToString(state));
1855 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001856 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001857 for (Listener l : mListeners) {
1858 l.onStateChanged(this, state);
1859 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001860 }
1861 }
1862
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001863 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001864 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001865 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1866 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001867 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001868 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001869
1870 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001871 if (mImmutable) {
1872 throw new UnsupportedOperationException("Connection is immutable");
1873 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001874 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001875 }
1876
Evan Charltonbf11f982014-07-20 22:06:28 -07001877 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001878 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001879 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1880 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001881 * <p>
1882 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1883 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001884 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001885 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001886 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001887 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001888 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1889 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001890 }
1891
Evan Charltonbf11f982014-07-20 22:06:28 -07001892 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001893 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1894 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1895 * this should never be un-@hide-den.
1896 *
1897 * @hide
1898 */
1899 public void checkImmutable() {}
1900
1901 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001902 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1903 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1904 * that state. This connection should not be used for anything, and no other
1905 * {@code Connection}s should be attempted.
1906 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001907 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001908 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001909 * @return A {@code Connection} which indicates that the underlying connection should
1910 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001911 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001912 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001913 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001914 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001915
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001916 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001917 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001918 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001919 }
1920 }
1921
Santos Cordon823fd3c2014-08-07 18:35:18 -07001922 private final void fireConferenceChanged() {
1923 for (Listener l : mListeners) {
1924 l.onConferenceChanged(this, mConference);
1925 }
1926 }
1927
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001928 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001929 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001930 if (c instanceof Connection) {
1931 Connection connection = (Connection) c;
1932 connection.removeConnectionListener(mConnectionDeathListener);
1933 } else if (c instanceof Conference) {
1934 Conference conference = (Conference) c;
1935 conference.removeListener(mConferenceDeathListener);
1936 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001937 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001938 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001939 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001940
1941 /**
Anthony Lee17455a32015-04-24 15:25:29 -07001942 * Notifies listeners that the merge request failed.
1943 *
1944 * @hide
1945 */
1946 protected final void notifyConferenceMergeFailed() {
1947 for (Listener l : mListeners) {
1948 l.onConferenceMergeFailed(this);
1949 }
1950 }
1951
1952 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001953 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001954 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001955 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001956 * @hide
1957 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001958 protected final void updateConferenceParticipants(
1959 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001960 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001961 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001962 }
1963 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001964
1965 /**
1966 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07001967 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001968 */
1969 protected void notifyConferenceStarted() {
1970 for (Listener l : mListeners) {
1971 l.onConferenceStarted();
1972 }
1973 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001974}