blob: d59adbe9f9c9aa73af1a9b9ad63e82c5618ab0b2 [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
Tyler Gunn7904a972016-03-17 18:34:27 -0700285 /**
286 * Connection event used to inform Telecom that it should play the on hold tone. This is used
287 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
288 * {@link #sendConnectionEvent(String)}.
289 * @hide
290 */
291 public static final String EVENT_ON_HOLD_TONE_START =
292 "android.telecom.event.ON_HOLD_TONE_START";
293
294 /**
295 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
296 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
297 * {@link #sendConnectionEvent(String)}.
298 * @hide
299 */
300 public static final String EVENT_ON_HOLD_TONE_END =
301 "android.telecom.event.ON_HOLD_TONE_END";
302
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700303 // Flag controlling whether PII is emitted into the logs
304 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
305
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800306 /**
307 * Whether the given capabilities support the specified capability.
308 *
309 * @param capabilities A capability bit field.
310 * @param capability The capability to check capabilities for.
311 * @return Whether the specified capability is supported.
312 * @hide
313 */
314 public static boolean can(int capabilities, int capability) {
315 return (capabilities & capability) != 0;
316 }
317
318 /**
319 * Whether the capabilities of this {@code Connection} supports the specified capability.
320 *
321 * @param capability The capability to check capabilities for.
322 * @return Whether the specified capability is supported.
323 * @hide
324 */
325 public boolean can(int capability) {
326 return can(mConnectionCapabilities, capability);
327 }
328
329 /**
330 * Removes the specified capability from the set of capabilities of this {@code Connection}.
331 *
332 * @param capability The capability to remove from the set.
333 * @hide
334 */
335 public void removeCapability(int capability) {
336 mConnectionCapabilities &= ~capability;
337 }
338
339 /**
340 * Adds the specified capability to the set of capabilities of this {@code Connection}.
341 *
342 * @param capability The capability to add to the set.
343 * @hide
344 */
345 public void addCapability(int capability) {
346 mConnectionCapabilities |= capability;
347 }
348
349
350 public static String capabilitiesToString(int capabilities) {
351 StringBuilder builder = new StringBuilder();
352 builder.append("[Capabilities:");
353 if (can(capabilities, CAPABILITY_HOLD)) {
354 builder.append(" CAPABILITY_HOLD");
355 }
356 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
357 builder.append(" CAPABILITY_SUPPORT_HOLD");
358 }
359 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
360 builder.append(" CAPABILITY_MERGE_CONFERENCE");
361 }
362 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
363 builder.append(" CAPABILITY_SWAP_CONFERENCE");
364 }
365 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
366 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
367 }
368 if (can(capabilities, CAPABILITY_MUTE)) {
369 builder.append(" CAPABILITY_MUTE");
370 }
371 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
372 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
373 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700374 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
375 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
376 }
377 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
378 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
379 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700380 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
381 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800382 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700383 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
384 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
385 }
386 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
387 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
388 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700389 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
390 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800391 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800392 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
393 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800394 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800395 if (can(capabilities, CAPABILITY_WIFI)) {
396 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800397 }
398 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
399 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
400 }
Tyler Gunn068085b2015-02-06 13:56:52 -0800401 if (can(capabilities, CAPABILITY_SHOW_CALLBACK_NUMBER)) {
402 builder.append(" CAPABILITY_SHOW_CALLBACK_NUMBER");
403 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500404 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700405 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500406 }
Rekha Kumar07366812015-03-24 16:42:31 -0700407 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
408 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
409 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700410 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
411 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
412 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700413 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
414 builder.append(" CAPABILITY_SINGLE_PARTY_CONFERENCE");
415 }
Bryce Lee81901682015-08-28 16:38:02 -0700416 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
417 builder.append(" CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION");
418 }
419
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800420 builder.append("]");
421 return builder.toString();
422 }
423
Sailesh Nepal091768c2014-06-30 15:15:23 -0700424 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700425 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700426 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700427 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700428 public void onCallerDisplayNameChanged(
429 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700430 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700431 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700432 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800433 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700434 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700435 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800436 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700437 public void onVideoProviderChanged(
438 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700439 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
440 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800441 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700442 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700443 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700444 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800445 public void onConferenceParticipantsChanged(Connection c,
446 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800447 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700448 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700449 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunn7904a972016-03-17 18:34:27 -0700450 /** @hide */
451 public void onConnectionEvent(Connection c, String event) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700452 }
453
Tyler Gunnb702ef82015-05-29 11:51:53 -0700454 /**
455 * Provides a means of controlling the video session associated with a {@link Connection}.
456 * <p>
457 * Implementations create a custom subclass of {@link VideoProvider} and the
458 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
459 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
460 * should set the {@link VideoProvider}.
461 * <p>
462 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
463 * {@link InCallService} implementations to issue requests related to the video session;
464 * it provides a means for the {@link ConnectionService} to report events and information
465 * related to the video session to Telecom and the {@link InCallService} implementations.
466 * <p>
467 * {@link InCallService} implementations interact with the {@link VideoProvider} via
468 * {@link android.telecom.InCallService.VideoCall}.
469 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700470 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700471
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700472 /**
473 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700474 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700475 */
476 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700477
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700478 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700479 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
480 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700481 */
482 public static final int SESSION_EVENT_RX_RESUME = 2;
483
484 /**
485 * Video transmission has begun. This occurs after a negotiated start of video transmission
486 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700487 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700488 */
489 public static final int SESSION_EVENT_TX_START = 3;
490
491 /**
492 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
493 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700494 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700495 */
496 public static final int SESSION_EVENT_TX_STOP = 4;
497
498 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700499 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
500 * this as a cue to inform the user the camera is not available.
501 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700502 */
503 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
504
505 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700506 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
507 * for operation. The {@link InCallService} can use this as a cue to inform the user that
508 * the camera has become available again.
509 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700510 */
511 public static final int SESSION_EVENT_CAMERA_READY = 6;
512
513 /**
514 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700515 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700516 */
517 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
518
519 /**
520 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700521 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700522 */
523 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
524
525 /**
526 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700527 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700528 */
529 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
530
Rekha Kumar07366812015-03-24 16:42:31 -0700531 /**
532 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700533 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700534 */
535 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
536
537 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700538 * Session modify request rejected by remote user.
539 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700540 */
541 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
542
Tyler Gunn75958422015-04-15 14:23:42 -0700543 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700544 private static final int MSG_SET_CAMERA = 2;
545 private static final int MSG_SET_PREVIEW_SURFACE = 3;
546 private static final int MSG_SET_DISPLAY_SURFACE = 4;
547 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
548 private static final int MSG_SET_ZOOM = 6;
549 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
550 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
551 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800552 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700553 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700554 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700555
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700556 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700557 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700558
559 /**
560 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700561 *
562 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
563 * load factor before resizing, 1 means we only expect a single thread to
564 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700565 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700566 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
567 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700568
569 /**
570 * Default handler used to consolidate binder method calls onto a single thread.
571 */
572 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700573 public VideoProviderHandler() {
574 super();
575 }
576
577 public VideoProviderHandler(Looper looper) {
578 super(looper);
579 }
580
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700581 @Override
582 public void handleMessage(Message msg) {
583 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700584 case MSG_ADD_VIDEO_CALLBACK: {
585 IBinder binder = (IBinder) msg.obj;
586 IVideoCallback callback = IVideoCallback.Stub
587 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700588 if (callback == null) {
589 Log.w(this, "addVideoProvider - skipped; callback is null.");
590 break;
591 }
592
Tyler Gunn75958422015-04-15 14:23:42 -0700593 if (mVideoCallbacks.containsKey(binder)) {
594 Log.i(this, "addVideoProvider - skipped; already present.");
595 break;
596 }
597 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700598 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700599 }
600 case MSG_REMOVE_VIDEO_CALLBACK: {
601 IBinder binder = (IBinder) msg.obj;
602 IVideoCallback callback = IVideoCallback.Stub
603 .asInterface((IBinder) msg.obj);
604 if (!mVideoCallbacks.containsKey(binder)) {
605 Log.i(this, "removeVideoProvider - skipped; not present.");
606 break;
607 }
608 mVideoCallbacks.remove(binder);
609 break;
610 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700611 case MSG_SET_CAMERA:
612 onSetCamera((String) msg.obj);
613 break;
614 case MSG_SET_PREVIEW_SURFACE:
615 onSetPreviewSurface((Surface) msg.obj);
616 break;
617 case MSG_SET_DISPLAY_SURFACE:
618 onSetDisplaySurface((Surface) msg.obj);
619 break;
620 case MSG_SET_DEVICE_ORIENTATION:
621 onSetDeviceOrientation(msg.arg1);
622 break;
623 case MSG_SET_ZOOM:
624 onSetZoom((Float) msg.obj);
625 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700626 case MSG_SEND_SESSION_MODIFY_REQUEST: {
627 SomeArgs args = (SomeArgs) msg.obj;
628 try {
629 onSendSessionModifyRequest((VideoProfile) args.arg1,
630 (VideoProfile) args.arg2);
631 } finally {
632 args.recycle();
633 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700634 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700635 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700636 case MSG_SEND_SESSION_MODIFY_RESPONSE:
637 onSendSessionModifyResponse((VideoProfile) msg.obj);
638 break;
639 case MSG_REQUEST_CAMERA_CAPABILITIES:
640 onRequestCameraCapabilities();
641 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800642 case MSG_REQUEST_CONNECTION_DATA_USAGE:
643 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700644 break;
645 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700646 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700647 break;
648 default:
649 break;
650 }
651 }
652 }
653
654 /**
655 * IVideoProvider stub implementation.
656 */
657 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700658 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700659 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700660 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
661 }
662
663 public void removeVideoCallback(IBinder videoCallbackBinder) {
664 mMessageHandler.obtainMessage(
665 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700666 }
667
668 public void setCamera(String cameraId) {
669 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
670 }
671
672 public void setPreviewSurface(Surface surface) {
673 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
674 }
675
676 public void setDisplaySurface(Surface surface) {
677 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
678 }
679
680 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700681 mMessageHandler.obtainMessage(
682 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700683 }
684
685 public void setZoom(float value) {
686 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
687 }
688
Tyler Gunn45382162015-05-06 08:52:27 -0700689 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
690 SomeArgs args = SomeArgs.obtain();
691 args.arg1 = fromProfile;
692 args.arg2 = toProfile;
693 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700694 }
695
696 public void sendSessionModifyResponse(VideoProfile responseProfile) {
697 mMessageHandler.obtainMessage(
698 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
699 }
700
701 public void requestCameraCapabilities() {
702 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
703 }
704
705 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800706 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700707 }
708
Yorke Lee32f24732015-05-12 16:18:03 -0700709 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700710 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
711 }
712 }
713
714 public VideoProvider() {
715 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700716 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700717 }
718
719 /**
720 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
721 *
722 * @param looper The looper.
723 * @hide
724 */
725 public VideoProvider(Looper looper) {
726 mBinder = new VideoProvider.VideoProviderBinder();
727 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700728 }
729
730 /**
731 * Returns binder object which can be used across IPC methods.
732 * @hide
733 */
734 public final IVideoProvider getInterface() {
735 return mBinder;
736 }
737
738 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700739 * Sets the camera to be used for the outgoing video.
740 * <p>
741 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
742 * camera via
743 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
744 * <p>
745 * Sent from the {@link InCallService} via
746 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700747 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700748 * @param cameraId The id of the camera (use ids as reported by
749 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700750 */
751 public abstract void onSetCamera(String cameraId);
752
753 /**
754 * Sets the surface to be used for displaying a preview of what the user's camera is
755 * currently capturing. When video transmission is enabled, this is the video signal which
756 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700757 * <p>
758 * Sent from the {@link InCallService} via
759 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700760 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700761 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700762 */
763 public abstract void onSetPreviewSurface(Surface surface);
764
765 /**
766 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700767 * <p>
768 * Sent from the {@link InCallService} via
769 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700770 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700771 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700772 */
773 public abstract void onSetDisplaySurface(Surface surface);
774
775 /**
776 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
777 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700778 * <p>
779 * Sent from the {@link InCallService} via
780 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700781 *
782 * @param rotation The device orientation, in degrees.
783 */
784 public abstract void onSetDeviceOrientation(int rotation);
785
786 /**
787 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700788 * <p>
789 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700790 *
791 * @param value The camera zoom ratio.
792 */
793 public abstract void onSetZoom(float value);
794
795 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700796 * Issues a request to modify the properties of the current video session.
797 * <p>
798 * Example scenarios include: requesting an audio-only call to be upgraded to a
799 * bi-directional video call, turning on or off the user's camera, sending a pause signal
800 * when the {@link InCallService} is no longer the foreground application.
801 * <p>
802 * If the {@link VideoProvider} determines a request to be invalid, it should call
803 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
804 * invalid request back to the {@link InCallService}.
805 * <p>
806 * Where a request requires confirmation from the user of the peer device, the
807 * {@link VideoProvider} must communicate the request to the peer device and handle the
808 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
809 * is used to inform the {@link InCallService} of the result of the request.
810 * <p>
811 * Sent from the {@link InCallService} via
812 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700813 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700814 * @param fromProfile The video profile prior to the request.
815 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700816 */
Tyler Gunn45382162015-05-06 08:52:27 -0700817 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
818 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700819
Tyler Gunnb702ef82015-05-29 11:51:53 -0700820 /**
821 * Provides a response to a request to change the current video session properties.
822 * <p>
823 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
824 * video call, could decline the request and keep the call as audio-only.
825 * In such a scenario, the {@code responseProfile} would have a video state of
826 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
827 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
828 * <p>
829 * Sent from the {@link InCallService} via
830 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
831 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
832 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700833 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700834 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700835 */
836 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
837
838 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700839 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
840 * <p>
841 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
842 * camera via
843 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
844 * <p>
845 * Sent from the {@link InCallService} via
846 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700847 */
848 public abstract void onRequestCameraCapabilities();
849
850 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700851 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
852 * video component of the current {@link Connection}.
853 * <p>
854 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
855 * via {@link VideoProvider#setCallDataUsage(long)}.
856 * <p>
857 * Sent from the {@link InCallService} via
858 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700859 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800860 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700861
862 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700863 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
864 * the peer device when the video signal is paused.
865 * <p>
866 * Sent from the {@link InCallService} via
867 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700868 *
869 * @param uri URI of image to display.
870 */
Yorke Lee32f24732015-05-12 16:18:03 -0700871 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700872
873 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700874 * Used to inform listening {@link InCallService} implementations when the
875 * {@link VideoProvider} receives a session modification request.
876 * <p>
877 * Received by the {@link InCallService} via
878 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700879 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700880 * @param videoProfile The requested video profile.
881 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700882 */
883 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700884 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700885 for (IVideoCallback callback : mVideoCallbacks.values()) {
886 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700887 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700888 } catch (RemoteException ignored) {
889 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700890 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700891 }
892 }
893 }
894
895 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700896 * Used to inform listening {@link InCallService} implementations when the
897 * {@link VideoProvider} receives a response to a session modification request.
898 * <p>
899 * Received by the {@link InCallService} via
900 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
901 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700902 *
903 * @param status Status of the session modify request. Valid values are
904 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
905 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -0700906 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
907 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
908 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
909 * @param requestedProfile The original request which was sent to the peer device.
910 * @param responseProfile The actual profile changes agreed to by the peer device.
911 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700912 */
913 public void receiveSessionModifyResponse(int status,
914 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700915 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700916 for (IVideoCallback callback : mVideoCallbacks.values()) {
917 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700918 callback.receiveSessionModifyResponse(status, requestedProfile,
919 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700920 } catch (RemoteException ignored) {
921 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700922 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700923 }
924 }
925 }
926
927 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700928 * Used to inform listening {@link InCallService} implementations when the
929 * {@link VideoProvider} reports a call session event.
930 * <p>
931 * Received by the {@link InCallService} via
932 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700933 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700934 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
935 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
936 * {@link VideoProvider#SESSION_EVENT_TX_START},
937 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
938 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
939 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700940 */
941 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -0700942 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700943 for (IVideoCallback callback : mVideoCallbacks.values()) {
944 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700945 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700946 } catch (RemoteException ignored) {
947 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700948 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700949 }
950 }
951 }
952
953 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700954 * Used to inform listening {@link InCallService} implementations when the dimensions of the
955 * peer's video have changed.
956 * <p>
957 * This could occur if, for example, the peer rotates their device, changing the aspect
958 * ratio of the video, or if the user switches between the back and front cameras.
959 * <p>
960 * Received by the {@link InCallService} via
961 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700962 *
963 * @param width The updated peer video width.
964 * @param height The updated peer video height.
965 */
966 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -0700967 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700968 for (IVideoCallback callback : mVideoCallbacks.values()) {
969 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700970 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700971 } catch (RemoteException ignored) {
972 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700973 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700974 }
975 }
976 }
977
978 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700979 * Used to inform listening {@link InCallService} implementations when the data usage of the
980 * video associated with the current {@link Connection} has changed.
981 * <p>
982 * This could be in response to a preview request via
983 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -0700984 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
985 * 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 -0700986 * <p>
987 * Received by the {@link InCallService} via
988 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700989 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700990 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
991 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700992 */
Yorke Lee32f24732015-05-12 16:18:03 -0700993 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -0700994 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700995 for (IVideoCallback callback : mVideoCallbacks.values()) {
996 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700997 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700998 } catch (RemoteException ignored) {
999 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001000 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001001 }
1002 }
1003 }
1004
1005 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001006 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001007 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001008 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001009 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1010 * @hide
1011 */
1012 public void changeCallDataUsage(long dataUsage) {
1013 setCallDataUsage(dataUsage);
1014 }
1015
1016 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001017 * Used to inform listening {@link InCallService} implementations when the capabilities of
1018 * the current camera have changed.
1019 * <p>
1020 * The {@link VideoProvider} should call this in response to
1021 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1022 * changed via {@link VideoProvider#onSetCamera(String)}.
1023 * <p>
1024 * Received by the {@link InCallService} via
1025 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1026 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001027 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001028 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001029 */
Yorke Lee400470f2015-05-12 13:31:25 -07001030 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001031 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001032 for (IVideoCallback callback : mVideoCallbacks.values()) {
1033 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001034 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001035 } catch (RemoteException ignored) {
1036 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001037 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001038 }
1039 }
1040 }
Rekha Kumar07366812015-03-24 16:42:31 -07001041
1042 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001043 * Used to inform listening {@link InCallService} implementations when the video quality
1044 * of the call has changed.
1045 * <p>
1046 * Received by the {@link InCallService} via
1047 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001048 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001049 * @param videoQuality The updated video quality. Valid values:
1050 * {@link VideoProfile#QUALITY_HIGH},
1051 * {@link VideoProfile#QUALITY_MEDIUM},
1052 * {@link VideoProfile#QUALITY_LOW},
1053 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001054 */
1055 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001056 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001057 for (IVideoCallback callback : mVideoCallbacks.values()) {
1058 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001059 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001060 } catch (RemoteException ignored) {
1061 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001062 }
Rekha Kumar07366812015-03-24 16:42:31 -07001063 }
1064 }
1065 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001066 }
1067
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001068 private final Listener mConnectionDeathListener = new Listener() {
1069 @Override
1070 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001071 if (mConferenceables.remove(c)) {
1072 fireOnConferenceableConnectionsChanged();
1073 }
1074 }
1075 };
1076
1077 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1078 @Override
1079 public void onDestroyed(Conference c) {
1080 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001081 fireOnConferenceableConnectionsChanged();
1082 }
1083 }
1084 };
1085
Jay Shrauner229e3822014-08-15 09:23:07 -07001086 /**
1087 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1088 * load factor before resizing, 1 means we only expect a single thread to
1089 * access the map so make only a single shard
1090 */
1091 private final Set<Listener> mListeners = Collections.newSetFromMap(
1092 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001093 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1094 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001095 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001096
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001097 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001098 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001099 private Uri mAddress;
1100 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001101 private String mCallerDisplayName;
1102 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001103 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001104 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001105 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001106 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001107 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001108 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001109 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001110 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001111 private Conference mConference;
1112 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001113 private Bundle mExtras;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001114
1115 /**
1116 * Create a new Connection.
1117 */
Santos Cordonf2951102014-07-20 19:06:29 -07001118 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001119
1120 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001121 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001122 */
Andrew Lee100e2932014-09-08 15:34:24 -07001123 public final Uri getAddress() {
1124 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001125 }
1126
1127 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001128 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001129 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001130 */
Andrew Lee100e2932014-09-08 15:34:24 -07001131 public final int getAddressPresentation() {
1132 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001133 }
1134
1135 /**
1136 * @return The caller display name (CNAP).
1137 */
1138 public final String getCallerDisplayName() {
1139 return mCallerDisplayName;
1140 }
1141
1142 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001143 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001144 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001145 */
1146 public final int getCallerDisplayNamePresentation() {
1147 return mCallerDisplayNamePresentation;
1148 }
1149
1150 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001151 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001152 */
1153 public final int getState() {
1154 return mState;
1155 }
1156
1157 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001158 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001159 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1160 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1161 * {@link VideoProfile#STATE_TX_ENABLED},
1162 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001163 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001164 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001165 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001166 */
1167 public final int getVideoState() {
1168 return mVideoState;
1169 }
1170
1171 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001172 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001173 * being routed by the system. This is {@code null} if this Connection
1174 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001175 * @deprecated Use {@link #getCallAudioState()} instead.
1176 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001177 */
Yorke Lee4af59352015-05-13 14:14:54 -07001178 @SystemApi
1179 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001180 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001181 if (mCallAudioState == null) {
1182 return null;
1183 }
Yorke Lee4af59352015-05-13 14:14:54 -07001184 return new AudioState(mCallAudioState);
1185 }
1186
1187 /**
1188 * @return The audio state of the connection, describing how its audio is currently
1189 * being routed by the system. This is {@code null} if this Connection
1190 * does not directly know about its audio state.
1191 */
1192 public final CallAudioState getCallAudioState() {
1193 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001194 }
1195
1196 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001197 * @return The conference that this connection is a part of. Null if it is not part of any
1198 * conference.
1199 */
1200 public final Conference getConference() {
1201 return mConference;
1202 }
1203
1204 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001205 * Returns whether this connection is requesting that the system play a ringback tone
1206 * on its behalf.
1207 */
Andrew Lee100e2932014-09-08 15:34:24 -07001208 public final boolean isRingbackRequested() {
1209 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001210 }
1211
1212 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001213 * @return True if the connection's audio mode is VOIP.
1214 */
1215 public final boolean getAudioModeIsVoip() {
1216 return mAudioModeIsVoip;
1217 }
1218
1219 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001220 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1221 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1222 * start time of the conference.
1223 *
1224 * @return The time at which the {@code Connnection} was connected.
1225 *
1226 * @hide
1227 */
1228 public final long getConnectTimeMillis() {
1229 return mConnectTimeMillis;
1230 }
1231
1232 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001233 * @return The status hints for this connection.
1234 */
1235 public final StatusHints getStatusHints() {
1236 return mStatusHints;
1237 }
1238
1239 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001240 * @return The extras associated with this connection.
1241 */
1242 public final Bundle getExtras() {
1243 return mExtras;
1244 }
1245
1246 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001247 * Assign a listener to be notified of state changes.
1248 *
1249 * @param l A listener.
1250 * @return This Connection.
1251 *
1252 * @hide
1253 */
1254 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001255 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001256 return this;
1257 }
1258
1259 /**
1260 * Remove a previously assigned listener that was being notified of state changes.
1261 *
1262 * @param l A Listener.
1263 * @return This Connection.
1264 *
1265 * @hide
1266 */
1267 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001268 if (l != null) {
1269 mListeners.remove(l);
1270 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001271 return this;
1272 }
1273
1274 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001275 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001276 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001277 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001278 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001279 }
1280
1281 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001282 * Inform this Connection that the state of its audio output has been changed externally.
1283 *
1284 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001285 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001286 */
Yorke Lee4af59352015-05-13 14:14:54 -07001287 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001288 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001289 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001290 mCallAudioState = state;
1291 onAudioStateChanged(getAudioState());
1292 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001293 }
1294
1295 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001296 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001297 * @return A string representation of the value.
1298 */
1299 public static String stateToString(int state) {
1300 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001301 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001302 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001303 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001304 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001305 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001306 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001307 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001308 return "DIALING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001309 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001310 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001311 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001312 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001313 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001314 return "DISCONNECTED";
1315 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001316 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001317 return "UNKNOWN";
1318 }
1319 }
1320
1321 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001322 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001323 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001324 public final int getConnectionCapabilities() {
1325 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001326 }
1327
1328 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001329 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001330 *
Andrew Lee100e2932014-09-08 15:34:24 -07001331 * @param address The new address.
1332 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001333 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001334 */
Andrew Lee100e2932014-09-08 15:34:24 -07001335 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001336 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001337 Log.d(this, "setAddress %s", address);
1338 mAddress = address;
1339 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001340 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001341 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001342 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001343 }
1344
1345 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001346 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001347 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001348 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001349 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001350 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001351 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001352 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001353 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001354 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001355 mCallerDisplayName = callerDisplayName;
1356 mCallerDisplayNamePresentation = presentation;
1357 for (Listener l : mListeners) {
1358 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1359 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001360 }
1361
1362 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001363 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001364 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1365 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1366 * {@link VideoProfile#STATE_TX_ENABLED},
1367 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001368 *
1369 * @param videoState The new video state.
1370 */
1371 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001372 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001373 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001374 mVideoState = videoState;
1375 for (Listener l : mListeners) {
1376 l.onVideoStateChanged(this, mVideoState);
1377 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001378 }
1379
1380 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001381 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001382 * communicate).
1383 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001384 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001385 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001386 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001387 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001388 }
1389
1390 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001391 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001392 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001393 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001394 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001395 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001396 }
1397
1398 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001399 * Sets state to initializing (this Connection is not yet ready to be used).
1400 */
1401 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001402 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001403 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001404 }
1405
1406 /**
1407 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1408 */
1409 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001410 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001411 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001412 }
1413
1414 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001415 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001416 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001417 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001418 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001419 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001420 }
1421
1422 /**
1423 * Sets state to be on hold.
1424 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001425 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001426 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001427 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001428 }
1429
1430 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001431 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001432 * @param videoProvider The video provider.
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001433 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001434 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001435 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001436 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001437 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001438 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001439 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001440 }
1441
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001442 public final VideoProvider getVideoProvider() {
1443 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001444 }
1445
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001446 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001447 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001448 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001449 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001450 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001451 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001452 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001453 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001454 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001455 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001456 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001457 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001458 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001459 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001460 }
1461
1462 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001463 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1464 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1465 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1466 * to send an {@link #onPostDialContinue(boolean)} signal.
1467 *
1468 * @param remaining The DTMF character sequence remaining to be emitted once the
1469 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1470 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001471 */
1472 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001473 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001474 for (Listener l : mListeners) {
1475 l.onPostDialWait(this, remaining);
1476 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001477 }
1478
1479 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001480 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1481 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001482 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001483 *
1484 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001485 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001486 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001487 checkImmutable();
1488 for (Listener l : mListeners) {
1489 l.onPostDialChar(this, nextChar);
1490 }
1491 }
1492
1493 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001494 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001495 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001496 *
1497 * @param ringback Whether the ringback tone is to be played.
1498 */
Andrew Lee100e2932014-09-08 15:34:24 -07001499 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001500 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001501 if (mRingbackRequested != ringback) {
1502 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001503 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001504 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001505 }
1506 }
Ihab Awadf8358972014-05-28 16:46:42 -07001507 }
1508
1509 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001510 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001511 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001512 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001513 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001514 public final void setConnectionCapabilities(int connectionCapabilities) {
1515 checkImmutable();
1516 if (mConnectionCapabilities != connectionCapabilities) {
1517 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001518 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001519 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001520 }
1521 }
Santos Cordonb6939982014-06-04 20:20:58 -07001522 }
1523
1524 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001525 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001526 */
Evan Charlton36a71342014-07-19 16:31:02 -07001527 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001528 for (Listener l : mListeners) {
1529 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001530 }
Santos Cordonb6939982014-06-04 20:20:58 -07001531 }
1532
1533 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001534 * Requests that the framework use VOIP audio mode for this connection.
1535 *
1536 * @param isVoip True if the audio mode is VOIP.
1537 */
1538 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001539 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001540 mAudioModeIsVoip = isVoip;
1541 for (Listener l : mListeners) {
1542 l.onAudioModeIsVoipChanged(this, isVoip);
1543 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001544 }
1545
1546 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001547 * Sets the time at which a call became active on this Connection. This is set only
1548 * when a conference call becomes active on this connection.
1549 *
1550 * @param connectionTimeMillis The connection time, in milliseconds.
1551 *
1552 * @hide
1553 */
1554 public final void setConnectTimeMillis(long connectTimeMillis) {
1555 mConnectTimeMillis = connectTimeMillis;
1556 }
1557
1558 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001559 * Sets the label and icon status to display in the in-call UI.
1560 *
1561 * @param statusHints The status label and icon to set.
1562 */
1563 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001564 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001565 mStatusHints = statusHints;
1566 for (Listener l : mListeners) {
1567 l.onStatusHintsChanged(this, statusHints);
1568 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001569 }
1570
1571 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001572 * Sets the connections with which this connection can be conferenced.
1573 *
1574 * @param conferenceableConnections The set of connections this connection can conference with.
1575 */
1576 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001577 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001578 clearConferenceableList();
1579 for (Connection c : conferenceableConnections) {
1580 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1581 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001582 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001583 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001584 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001585 }
1586 }
1587 fireOnConferenceableConnectionsChanged();
1588 }
1589
1590 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001591 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1592 * or conferences with which this connection can be conferenced.
1593 *
1594 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001595 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001596 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001597 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001598 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001599 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1600 // small amount of items here.
1601 if (!mConferenceables.contains(c)) {
1602 if (c instanceof Connection) {
1603 Connection connection = (Connection) c;
1604 connection.addConnectionListener(mConnectionDeathListener);
1605 } else if (c instanceof Conference) {
1606 Conference conference = (Conference) c;
1607 conference.addListener(mConferenceDeathListener);
1608 }
1609 mConferenceables.add(c);
1610 }
1611 }
1612 fireOnConferenceableConnectionsChanged();
1613 }
1614
1615 /**
1616 * Returns the connections or conferences with which this connection can be conferenced.
1617 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001618 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001619 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001620 }
1621
Yorke Lee53463962015-08-04 16:07:19 -07001622 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001623 * @hide
1624 */
1625 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001626 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001627 if (mConnectionService != null) {
1628 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1629 "which is already associated with another ConnectionService.");
1630 } else {
1631 mConnectionService = connectionService;
1632 }
1633 }
1634
1635 /**
1636 * @hide
1637 */
1638 public final void unsetConnectionService(ConnectionService connectionService) {
1639 if (mConnectionService != connectionService) {
1640 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1641 "that does not belong to the ConnectionService.");
1642 } else {
1643 mConnectionService = null;
1644 }
1645 }
1646
1647 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001648 * @hide
1649 */
1650 public final ConnectionService getConnectionService() {
1651 return mConnectionService;
1652 }
1653
1654 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001655 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001656 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001657 *
1658 * @param conference The conference.
1659 * @return {@code true} if the conference was successfully set.
1660 * @hide
1661 */
1662 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001663 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001664 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001665 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001666 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001667 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1668 fireConferenceChanged();
1669 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001670 return true;
1671 }
1672 return false;
1673 }
1674
1675 /**
1676 * Resets the conference that this connection is a part of.
1677 * @hide
1678 */
1679 public final void resetConference() {
1680 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001681 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001682 mConference = null;
1683 fireConferenceChanged();
1684 }
1685 }
1686
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001687 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001688 * Set some extras that can be associated with this {@code Connection}. No assumptions should
1689 * be made as to how an In-Call UI or service will handle these extras.
1690 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1691 *
1692 * @param extras The extras associated with this {@code Connection}.
1693 */
1694 public final void setExtras(@Nullable Bundle extras) {
1695 checkImmutable();
1696 mExtras = extras;
1697 for (Listener l : mListeners) {
1698 l.onExtrasChanged(this, extras);
1699 }
1700 }
1701
1702 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001703 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001704 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001705 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001706 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
1707 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07001708 */
Yorke Lee4af59352015-05-13 14:14:54 -07001709 @SystemApi
1710 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07001711 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001712
1713 /**
Yorke Lee4af59352015-05-13 14:14:54 -07001714 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
1715 *
1716 * @param state The new connection audio state.
1717 */
1718 public void onCallAudioStateChanged(CallAudioState state) {}
1719
1720 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001721 * Notifies this Connection of an internal state change. This method is called after the
1722 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001723 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001724 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001725 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001726 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001727
1728 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001729 * Notifies this Connection of a request to play a DTMF tone.
1730 *
1731 * @param c A DTMF character.
1732 */
Santos Cordonf2951102014-07-20 19:06:29 -07001733 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001734
1735 /**
1736 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1737 */
Santos Cordonf2951102014-07-20 19:06:29 -07001738 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001739
1740 /**
1741 * Notifies this Connection of a request to disconnect.
1742 */
Santos Cordonf2951102014-07-20 19:06:29 -07001743 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001744
1745 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001746 * Notifies this Connection of a request to disconnect a participant of the conference managed
1747 * by the connection.
1748 *
1749 * @param endpoint the {@link Uri} of the participant to disconnect.
1750 * @hide
1751 */
1752 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1753
1754 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001755 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001756 */
Santos Cordonf2951102014-07-20 19:06:29 -07001757 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001758
1759 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001760 * Notifies this Connection of a request to abort.
1761 */
Santos Cordonf2951102014-07-20 19:06:29 -07001762 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001763
1764 /**
1765 * Notifies this Connection of a request to hold.
1766 */
Santos Cordonf2951102014-07-20 19:06:29 -07001767 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001768
1769 /**
1770 * Notifies this Connection of a request to exit a hold state.
1771 */
Santos Cordonf2951102014-07-20 19:06:29 -07001772 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001773
1774 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001775 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001776 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001777 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001778 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001779 */
Santos Cordonf2951102014-07-20 19:06:29 -07001780 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001781
1782 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001783 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001784 * a request to accept.
1785 */
1786 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07001787 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07001788 }
1789
1790 /**
1791 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001792 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001793 */
Santos Cordonf2951102014-07-20 19:06:29 -07001794 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001795
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001796 /**
Bryce Lee81901682015-08-28 16:38:02 -07001797 * Notifies ths Connection of a request reject with a message.
1798 *
1799 * @hide
1800 */
1801 public void onReject(String replyMessage) {}
1802
1803 /**
Bryce Leecac50772015-11-17 15:13:29 -08001804 * Notifies the Connection of a request to silence the ringer.
1805 *
1806 * @hide
1807 */
1808 public void onSilence() {}
1809
1810 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001811 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1812 */
Santos Cordonf2951102014-07-20 19:06:29 -07001813 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001814
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001815 static String toLogSafePhoneNumber(String number) {
1816 // For unknown number, log empty string.
1817 if (number == null) {
1818 return "";
1819 }
1820
1821 if (PII_DEBUG) {
1822 // When PII_DEBUG is true we emit PII.
1823 return number;
1824 }
1825
1826 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1827 // sanitized phone numbers.
1828 StringBuilder builder = new StringBuilder();
1829 for (int i = 0; i < number.length(); i++) {
1830 char c = number.charAt(i);
1831 if (c == '-' || c == '@' || c == '.') {
1832 builder.append(c);
1833 } else {
1834 builder.append('x');
1835 }
1836 }
1837 return builder.toString();
1838 }
1839
Ihab Awad542e0ea2014-05-16 10:22:16 -07001840 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001841 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001842 if (mState == STATE_DISCONNECTED && mState != state) {
1843 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001844 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001845 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001846 if (mState != state) {
1847 Log.d(this, "setState: %s", stateToString(state));
1848 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001849 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001850 for (Listener l : mListeners) {
1851 l.onStateChanged(this, state);
1852 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001853 }
1854 }
1855
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001856 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001857 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001858 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1859 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001860 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001861 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001862
1863 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001864 if (mImmutable) {
1865 throw new UnsupportedOperationException("Connection is immutable");
1866 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001867 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001868 }
1869
Evan Charltonbf11f982014-07-20 22:06:28 -07001870 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001871 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001872 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1873 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001874 * <p>
1875 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1876 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001877 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001878 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001879 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001880 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001881 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1882 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001883 }
1884
Evan Charltonbf11f982014-07-20 22:06:28 -07001885 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001886 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1887 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1888 * this should never be un-@hide-den.
1889 *
1890 * @hide
1891 */
1892 public void checkImmutable() {}
1893
1894 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001895 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1896 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1897 * that state. This connection should not be used for anything, and no other
1898 * {@code Connection}s should be attempted.
1899 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001900 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001901 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001902 * @return A {@code Connection} which indicates that the underlying connection should
1903 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001904 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001905 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001906 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001907 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001908
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001909 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001910 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001911 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001912 }
1913 }
1914
Santos Cordon823fd3c2014-08-07 18:35:18 -07001915 private final void fireConferenceChanged() {
1916 for (Listener l : mListeners) {
1917 l.onConferenceChanged(this, mConference);
1918 }
1919 }
1920
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001921 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001922 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001923 if (c instanceof Connection) {
1924 Connection connection = (Connection) c;
1925 connection.removeConnectionListener(mConnectionDeathListener);
1926 } else if (c instanceof Conference) {
1927 Conference conference = (Conference) c;
1928 conference.removeListener(mConferenceDeathListener);
1929 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001930 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001931 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001932 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001933
1934 /**
Anthony Lee17455a32015-04-24 15:25:29 -07001935 * Notifies listeners that the merge request failed.
1936 *
1937 * @hide
1938 */
1939 protected final void notifyConferenceMergeFailed() {
1940 for (Listener l : mListeners) {
1941 l.onConferenceMergeFailed(this);
1942 }
1943 }
1944
1945 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001946 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001947 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001948 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001949 * @hide
1950 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001951 protected final void updateConferenceParticipants(
1952 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001953 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001954 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001955 }
1956 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001957
1958 /**
1959 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07001960 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001961 */
1962 protected void notifyConferenceStarted() {
1963 for (Listener l : mListeners) {
1964 l.onConferenceStarted();
1965 }
1966 }
Tyler Gunn7904a972016-03-17 18:34:27 -07001967
1968 /**
1969 * Sends a connection event to Telecom.
1970 *
1971 * @param event The connection event.
1972 * @hide
1973 */
1974 protected void sendConnectionEvent(String event) {
1975 for (Listener l : mListeners) {
1976 l.onConnectionEvent(this, event);
1977 }
1978 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001979}