blob: d66395263afd32e409171fa20f996d1e6d3771b8 [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
Tyler Gunn96d6c402015-03-18 12:39:23 -0700251 //**********************************************************************************************
Tyler Gunnd4091732015-06-29 09:15:37 -0700252 // Next CAPABILITY value: 0x00400000
Tyler Gunn96d6c402015-03-18 12:39:23 -0700253 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800254
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700255 /**
256 * Connection extra key used to store the last forwarded number associated with the current
257 * connection. Used to communicate to the user interface that the connection was forwarded via
258 * the specified number.
259 */
260 public static final String EXTRA_LAST_FORWARDED_NUMBER =
261 "android.telecom.extra.LAST_FORWARDED_NUMBER";
262
263 /**
264 * Connection extra key used to store a child number associated with the current connection.
265 * Used to communicate to the user interface that the connection was received via
266 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
267 * address.
268 */
269 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
270
271 /**
272 * Connection extra key used to store the subject for an incoming call. The user interface can
273 * query this extra and display its contents for incoming calls. Will only be used if the
274 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
275 */
276 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
277
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700278 // Flag controlling whether PII is emitted into the logs
279 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
280
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800281 /**
282 * Whether the given capabilities support the specified capability.
283 *
284 * @param capabilities A capability bit field.
285 * @param capability The capability to check capabilities for.
286 * @return Whether the specified capability is supported.
287 * @hide
288 */
289 public static boolean can(int capabilities, int capability) {
290 return (capabilities & capability) != 0;
291 }
292
293 /**
294 * Whether the capabilities of this {@code Connection} supports the specified capability.
295 *
296 * @param capability The capability to check capabilities for.
297 * @return Whether the specified capability is supported.
298 * @hide
299 */
300 public boolean can(int capability) {
301 return can(mConnectionCapabilities, capability);
302 }
303
304 /**
305 * Removes the specified capability from the set of capabilities of this {@code Connection}.
306 *
307 * @param capability The capability to remove from the set.
308 * @hide
309 */
310 public void removeCapability(int capability) {
311 mConnectionCapabilities &= ~capability;
312 }
313
314 /**
315 * Adds the specified capability to the set of capabilities of this {@code Connection}.
316 *
317 * @param capability The capability to add to the set.
318 * @hide
319 */
320 public void addCapability(int capability) {
321 mConnectionCapabilities |= capability;
322 }
323
324
325 public static String capabilitiesToString(int capabilities) {
326 StringBuilder builder = new StringBuilder();
327 builder.append("[Capabilities:");
328 if (can(capabilities, CAPABILITY_HOLD)) {
329 builder.append(" CAPABILITY_HOLD");
330 }
331 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
332 builder.append(" CAPABILITY_SUPPORT_HOLD");
333 }
334 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
335 builder.append(" CAPABILITY_MERGE_CONFERENCE");
336 }
337 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
338 builder.append(" CAPABILITY_SWAP_CONFERENCE");
339 }
340 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
341 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
342 }
343 if (can(capabilities, CAPABILITY_MUTE)) {
344 builder.append(" CAPABILITY_MUTE");
345 }
346 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
347 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
348 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700349 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
350 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
351 }
352 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
353 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
354 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700355 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
356 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800357 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700358 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
359 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
360 }
361 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
362 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
363 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700364 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
365 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800366 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800367 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
368 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800369 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800370 if (can(capabilities, CAPABILITY_WIFI)) {
371 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800372 }
373 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
374 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
375 }
Tyler Gunn068085b2015-02-06 13:56:52 -0800376 if (can(capabilities, CAPABILITY_SHOW_CALLBACK_NUMBER)) {
377 builder.append(" CAPABILITY_SHOW_CALLBACK_NUMBER");
378 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500379 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700380 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500381 }
Rekha Kumar07366812015-03-24 16:42:31 -0700382 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
383 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
384 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700385 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
386 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
387 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700388 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
389 builder.append(" CAPABILITY_SINGLE_PARTY_CONFERENCE");
390 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800391 builder.append("]");
392 return builder.toString();
393 }
394
Sailesh Nepal091768c2014-06-30 15:15:23 -0700395 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700396 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700397 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700398 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700399 public void onCallerDisplayNameChanged(
400 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700401 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700402 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700403 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800404 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700405 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700406 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800407 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700408 public void onVideoProviderChanged(
409 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700410 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
411 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800412 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700413 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700414 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700415 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800416 public void onConferenceParticipantsChanged(Connection c,
417 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800418 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700419 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700420 public void onExtrasChanged(Connection c, Bundle extras) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700421 }
422
Tyler Gunnb702ef82015-05-29 11:51:53 -0700423 /**
424 * Provides a means of controlling the video session associated with a {@link Connection}.
425 * <p>
426 * Implementations create a custom subclass of {@link VideoProvider} and the
427 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
428 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
429 * should set the {@link VideoProvider}.
430 * <p>
431 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
432 * {@link InCallService} implementations to issue requests related to the video session;
433 * it provides a means for the {@link ConnectionService} to report events and information
434 * related to the video session to Telecom and the {@link InCallService} implementations.
435 * <p>
436 * {@link InCallService} implementations interact with the {@link VideoProvider} via
437 * {@link android.telecom.InCallService.VideoCall}.
438 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700439 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700440
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700441 /**
442 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700443 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700444 */
445 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700446
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700447 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700448 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
449 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700450 */
451 public static final int SESSION_EVENT_RX_RESUME = 2;
452
453 /**
454 * Video transmission has begun. This occurs after a negotiated start of video transmission
455 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700456 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700457 */
458 public static final int SESSION_EVENT_TX_START = 3;
459
460 /**
461 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
462 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700463 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700464 */
465 public static final int SESSION_EVENT_TX_STOP = 4;
466
467 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700468 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
469 * this as a cue to inform the user the camera is not available.
470 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700471 */
472 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
473
474 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700475 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
476 * for operation. The {@link InCallService} can use this as a cue to inform the user that
477 * the camera has become available again.
478 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700479 */
480 public static final int SESSION_EVENT_CAMERA_READY = 6;
481
482 /**
483 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700484 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700485 */
486 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
487
488 /**
489 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700490 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700491 */
492 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
493
494 /**
495 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700496 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700497 */
498 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
499
Rekha Kumar07366812015-03-24 16:42:31 -0700500 /**
501 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700502 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700503 */
504 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
505
506 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700507 * Session modify request rejected by remote user.
508 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700509 */
510 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
511
Tyler Gunn75958422015-04-15 14:23:42 -0700512 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700513 private static final int MSG_SET_CAMERA = 2;
514 private static final int MSG_SET_PREVIEW_SURFACE = 3;
515 private static final int MSG_SET_DISPLAY_SURFACE = 4;
516 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
517 private static final int MSG_SET_ZOOM = 6;
518 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
519 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
520 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800521 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700522 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700523 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700524
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700525 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700526 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700527
528 /**
529 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700530 *
531 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
532 * load factor before resizing, 1 means we only expect a single thread to
533 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700534 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700535 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
536 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700537
538 /**
539 * Default handler used to consolidate binder method calls onto a single thread.
540 */
541 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700542 public VideoProviderHandler() {
543 super();
544 }
545
546 public VideoProviderHandler(Looper looper) {
547 super(looper);
548 }
549
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700550 @Override
551 public void handleMessage(Message msg) {
552 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700553 case MSG_ADD_VIDEO_CALLBACK: {
554 IBinder binder = (IBinder) msg.obj;
555 IVideoCallback callback = IVideoCallback.Stub
556 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700557 if (callback == null) {
558 Log.w(this, "addVideoProvider - skipped; callback is null.");
559 break;
560 }
561
Tyler Gunn75958422015-04-15 14:23:42 -0700562 if (mVideoCallbacks.containsKey(binder)) {
563 Log.i(this, "addVideoProvider - skipped; already present.");
564 break;
565 }
566 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700567 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700568 }
569 case MSG_REMOVE_VIDEO_CALLBACK: {
570 IBinder binder = (IBinder) msg.obj;
571 IVideoCallback callback = IVideoCallback.Stub
572 .asInterface((IBinder) msg.obj);
573 if (!mVideoCallbacks.containsKey(binder)) {
574 Log.i(this, "removeVideoProvider - skipped; not present.");
575 break;
576 }
577 mVideoCallbacks.remove(binder);
578 break;
579 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700580 case MSG_SET_CAMERA:
581 onSetCamera((String) msg.obj);
582 break;
583 case MSG_SET_PREVIEW_SURFACE:
584 onSetPreviewSurface((Surface) msg.obj);
585 break;
586 case MSG_SET_DISPLAY_SURFACE:
587 onSetDisplaySurface((Surface) msg.obj);
588 break;
589 case MSG_SET_DEVICE_ORIENTATION:
590 onSetDeviceOrientation(msg.arg1);
591 break;
592 case MSG_SET_ZOOM:
593 onSetZoom((Float) msg.obj);
594 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700595 case MSG_SEND_SESSION_MODIFY_REQUEST: {
596 SomeArgs args = (SomeArgs) msg.obj;
597 try {
598 onSendSessionModifyRequest((VideoProfile) args.arg1,
599 (VideoProfile) args.arg2);
600 } finally {
601 args.recycle();
602 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700603 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700604 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700605 case MSG_SEND_SESSION_MODIFY_RESPONSE:
606 onSendSessionModifyResponse((VideoProfile) msg.obj);
607 break;
608 case MSG_REQUEST_CAMERA_CAPABILITIES:
609 onRequestCameraCapabilities();
610 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800611 case MSG_REQUEST_CONNECTION_DATA_USAGE:
612 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700613 break;
614 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700615 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700616 break;
617 default:
618 break;
619 }
620 }
621 }
622
623 /**
624 * IVideoProvider stub implementation.
625 */
626 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700627 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700628 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700629 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
630 }
631
632 public void removeVideoCallback(IBinder videoCallbackBinder) {
633 mMessageHandler.obtainMessage(
634 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700635 }
636
637 public void setCamera(String cameraId) {
638 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
639 }
640
641 public void setPreviewSurface(Surface surface) {
642 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
643 }
644
645 public void setDisplaySurface(Surface surface) {
646 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
647 }
648
649 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700650 mMessageHandler.obtainMessage(
651 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700652 }
653
654 public void setZoom(float value) {
655 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
656 }
657
Tyler Gunn45382162015-05-06 08:52:27 -0700658 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
659 SomeArgs args = SomeArgs.obtain();
660 args.arg1 = fromProfile;
661 args.arg2 = toProfile;
662 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700663 }
664
665 public void sendSessionModifyResponse(VideoProfile responseProfile) {
666 mMessageHandler.obtainMessage(
667 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
668 }
669
670 public void requestCameraCapabilities() {
671 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
672 }
673
674 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800675 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700676 }
677
Yorke Lee32f24732015-05-12 16:18:03 -0700678 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700679 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
680 }
681 }
682
683 public VideoProvider() {
684 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700685 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700686 }
687
688 /**
689 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
690 *
691 * @param looper The looper.
692 * @hide
693 */
694 public VideoProvider(Looper looper) {
695 mBinder = new VideoProvider.VideoProviderBinder();
696 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700697 }
698
699 /**
700 * Returns binder object which can be used across IPC methods.
701 * @hide
702 */
703 public final IVideoProvider getInterface() {
704 return mBinder;
705 }
706
707 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700708 * Sets the camera to be used for the outgoing video.
709 * <p>
710 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
711 * camera via
712 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
713 * <p>
714 * Sent from the {@link InCallService} via
715 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700716 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700717 * @param cameraId The id of the camera (use ids as reported by
718 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700719 */
720 public abstract void onSetCamera(String cameraId);
721
722 /**
723 * Sets the surface to be used for displaying a preview of what the user's camera is
724 * currently capturing. When video transmission is enabled, this is the video signal which
725 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700726 * <p>
727 * Sent from the {@link InCallService} via
728 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700729 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700730 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700731 */
732 public abstract void onSetPreviewSurface(Surface surface);
733
734 /**
735 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700736 * <p>
737 * Sent from the {@link InCallService} via
738 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700739 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700740 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700741 */
742 public abstract void onSetDisplaySurface(Surface surface);
743
744 /**
745 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
746 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700747 * <p>
748 * Sent from the {@link InCallService} via
749 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700750 *
751 * @param rotation The device orientation, in degrees.
752 */
753 public abstract void onSetDeviceOrientation(int rotation);
754
755 /**
756 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700757 * <p>
758 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700759 *
760 * @param value The camera zoom ratio.
761 */
762 public abstract void onSetZoom(float value);
763
764 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700765 * Issues a request to modify the properties of the current video session.
766 * <p>
767 * Example scenarios include: requesting an audio-only call to be upgraded to a
768 * bi-directional video call, turning on or off the user's camera, sending a pause signal
769 * when the {@link InCallService} is no longer the foreground application.
770 * <p>
771 * If the {@link VideoProvider} determines a request to be invalid, it should call
772 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
773 * invalid request back to the {@link InCallService}.
774 * <p>
775 * Where a request requires confirmation from the user of the peer device, the
776 * {@link VideoProvider} must communicate the request to the peer device and handle the
777 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
778 * is used to inform the {@link InCallService} of the result of the request.
779 * <p>
780 * Sent from the {@link InCallService} via
781 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700782 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700783 * @param fromProfile The video profile prior to the request.
784 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700785 */
Tyler Gunn45382162015-05-06 08:52:27 -0700786 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
787 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700788
Tyler Gunnb702ef82015-05-29 11:51:53 -0700789 /**
790 * Provides a response to a request to change the current video session properties.
791 * <p>
792 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
793 * video call, could decline the request and keep the call as audio-only.
794 * In such a scenario, the {@code responseProfile} would have a video state of
795 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
796 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
797 * <p>
798 * Sent from the {@link InCallService} via
799 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
800 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
801 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700802 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700803 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700804 */
805 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
806
807 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700808 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
809 * <p>
810 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
811 * camera via
812 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
813 * <p>
814 * Sent from the {@link InCallService} via
815 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700816 */
817 public abstract void onRequestCameraCapabilities();
818
819 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700820 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
821 * video component of the current {@link Connection}.
822 * <p>
823 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
824 * via {@link VideoProvider#setCallDataUsage(long)}.
825 * <p>
826 * Sent from the {@link InCallService} via
827 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700828 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800829 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700830
831 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700832 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
833 * the peer device when the video signal is paused.
834 * <p>
835 * Sent from the {@link InCallService} via
836 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700837 *
838 * @param uri URI of image to display.
839 */
Yorke Lee32f24732015-05-12 16:18:03 -0700840 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700841
842 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700843 * Used to inform listening {@link InCallService} implementations when the
844 * {@link VideoProvider} receives a session modification request.
845 * <p>
846 * Received by the {@link InCallService} via
847 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700848 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700849 * @param videoProfile The requested video profile.
850 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700851 */
852 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700853 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700854 for (IVideoCallback callback : mVideoCallbacks.values()) {
855 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700856 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700857 } catch (RemoteException ignored) {
858 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700859 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700860 }
861 }
862 }
863
864 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700865 * Used to inform listening {@link InCallService} implementations when the
866 * {@link VideoProvider} receives a response to a session modification request.
867 * <p>
868 * Received by the {@link InCallService} via
869 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
870 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700871 *
872 * @param status Status of the session modify request. Valid values are
873 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
874 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -0700875 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
876 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
877 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
878 * @param requestedProfile The original request which was sent to the peer device.
879 * @param responseProfile The actual profile changes agreed to by the peer device.
880 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700881 */
882 public void receiveSessionModifyResponse(int status,
883 VideoProfile requestedProfile, VideoProfile responseProfile) {
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.receiveSessionModifyResponse(status, requestedProfile,
888 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700889 } catch (RemoteException ignored) {
890 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700891 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700892 }
893 }
894 }
895
896 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700897 * Used to inform listening {@link InCallService} implementations when the
898 * {@link VideoProvider} reports a call session event.
899 * <p>
900 * Received by the {@link InCallService} via
901 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700902 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700903 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
904 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
905 * {@link VideoProvider#SESSION_EVENT_TX_START},
906 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
907 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
908 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700909 */
910 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -0700911 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700912 for (IVideoCallback callback : mVideoCallbacks.values()) {
913 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700914 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700915 } catch (RemoteException ignored) {
916 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700917 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700918 }
919 }
920 }
921
922 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700923 * Used to inform listening {@link InCallService} implementations when the dimensions of the
924 * peer's video have changed.
925 * <p>
926 * This could occur if, for example, the peer rotates their device, changing the aspect
927 * ratio of the video, or if the user switches between the back and front cameras.
928 * <p>
929 * Received by the {@link InCallService} via
930 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700931 *
932 * @param width The updated peer video width.
933 * @param height The updated peer video height.
934 */
935 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -0700936 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700937 for (IVideoCallback callback : mVideoCallbacks.values()) {
938 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700939 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700940 } catch (RemoteException ignored) {
941 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700942 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700943 }
944 }
945 }
946
947 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700948 * Used to inform listening {@link InCallService} implementations when the data usage of the
949 * video associated with the current {@link Connection} has changed.
950 * <p>
951 * This could be in response to a preview request via
952 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -0700953 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
954 * 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 -0700955 * <p>
956 * Received by the {@link InCallService} via
957 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700958 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700959 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
960 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700961 */
Yorke Lee32f24732015-05-12 16:18:03 -0700962 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -0700963 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700964 for (IVideoCallback callback : mVideoCallbacks.values()) {
965 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700966 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700967 } catch (RemoteException ignored) {
968 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700969 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700970 }
971 }
972 }
973
974 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700975 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700976 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700977 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -0700978 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
979 * @hide
980 */
981 public void changeCallDataUsage(long dataUsage) {
982 setCallDataUsage(dataUsage);
983 }
984
985 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700986 * Used to inform listening {@link InCallService} implementations when the capabilities of
987 * the current camera have changed.
988 * <p>
989 * The {@link VideoProvider} should call this in response to
990 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
991 * changed via {@link VideoProvider#onSetCamera(String)}.
992 * <p>
993 * Received by the {@link InCallService} via
994 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
995 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -0700996 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700997 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700998 */
Yorke Lee400470f2015-05-12 13:31:25 -0700999 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001000 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001001 for (IVideoCallback callback : mVideoCallbacks.values()) {
1002 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001003 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001004 } catch (RemoteException ignored) {
1005 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001006 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001007 }
1008 }
1009 }
Rekha Kumar07366812015-03-24 16:42:31 -07001010
1011 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001012 * Used to inform listening {@link InCallService} implementations when the video quality
1013 * of the call has changed.
1014 * <p>
1015 * Received by the {@link InCallService} via
1016 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001017 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001018 * @param videoQuality The updated video quality. Valid values:
1019 * {@link VideoProfile#QUALITY_HIGH},
1020 * {@link VideoProfile#QUALITY_MEDIUM},
1021 * {@link VideoProfile#QUALITY_LOW},
1022 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001023 */
1024 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001025 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001026 for (IVideoCallback callback : mVideoCallbacks.values()) {
1027 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001028 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001029 } catch (RemoteException ignored) {
1030 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001031 }
Rekha Kumar07366812015-03-24 16:42:31 -07001032 }
1033 }
1034 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001035 }
1036
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001037 private final Listener mConnectionDeathListener = new Listener() {
1038 @Override
1039 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001040 if (mConferenceables.remove(c)) {
1041 fireOnConferenceableConnectionsChanged();
1042 }
1043 }
1044 };
1045
1046 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1047 @Override
1048 public void onDestroyed(Conference c) {
1049 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001050 fireOnConferenceableConnectionsChanged();
1051 }
1052 }
1053 };
1054
Jay Shrauner229e3822014-08-15 09:23:07 -07001055 /**
1056 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1057 * load factor before resizing, 1 means we only expect a single thread to
1058 * access the map so make only a single shard
1059 */
1060 private final Set<Listener> mListeners = Collections.newSetFromMap(
1061 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001062 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1063 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001064 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001065
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001066 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001067 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001068 private Uri mAddress;
1069 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001070 private String mCallerDisplayName;
1071 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001072 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001073 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001074 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001075 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001076 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001077 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001078 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001079 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001080 private Conference mConference;
1081 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001082 private Bundle mExtras;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001083
1084 /**
1085 * Create a new Connection.
1086 */
Santos Cordonf2951102014-07-20 19:06:29 -07001087 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001088
1089 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001090 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001091 */
Andrew Lee100e2932014-09-08 15:34:24 -07001092 public final Uri getAddress() {
1093 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001094 }
1095
1096 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001097 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001098 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001099 */
Andrew Lee100e2932014-09-08 15:34:24 -07001100 public final int getAddressPresentation() {
1101 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001102 }
1103
1104 /**
1105 * @return The caller display name (CNAP).
1106 */
1107 public final String getCallerDisplayName() {
1108 return mCallerDisplayName;
1109 }
1110
1111 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001112 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001113 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001114 */
1115 public final int getCallerDisplayNamePresentation() {
1116 return mCallerDisplayNamePresentation;
1117 }
1118
1119 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001120 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001121 */
1122 public final int getState() {
1123 return mState;
1124 }
1125
1126 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001127 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001128 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1129 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1130 * {@link VideoProfile#STATE_TX_ENABLED},
1131 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001132 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001133 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001134 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001135 */
1136 public final int getVideoState() {
1137 return mVideoState;
1138 }
1139
1140 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001141 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001142 * being routed by the system. This is {@code null} if this Connection
1143 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001144 * @deprecated Use {@link #getCallAudioState()} instead.
1145 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001146 */
Yorke Lee4af59352015-05-13 14:14:54 -07001147 @SystemApi
1148 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001149 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001150 if (mCallAudioState == null) {
1151 return null;
1152 }
Yorke Lee4af59352015-05-13 14:14:54 -07001153 return new AudioState(mCallAudioState);
1154 }
1155
1156 /**
1157 * @return The audio state of the connection, describing how its audio is currently
1158 * being routed by the system. This is {@code null} if this Connection
1159 * does not directly know about its audio state.
1160 */
1161 public final CallAudioState getCallAudioState() {
1162 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001163 }
1164
1165 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001166 * @return The conference that this connection is a part of. Null if it is not part of any
1167 * conference.
1168 */
1169 public final Conference getConference() {
1170 return mConference;
1171 }
1172
1173 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001174 * Returns whether this connection is requesting that the system play a ringback tone
1175 * on its behalf.
1176 */
Andrew Lee100e2932014-09-08 15:34:24 -07001177 public final boolean isRingbackRequested() {
1178 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001179 }
1180
1181 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001182 * @return True if the connection's audio mode is VOIP.
1183 */
1184 public final boolean getAudioModeIsVoip() {
1185 return mAudioModeIsVoip;
1186 }
1187
1188 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001189 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1190 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1191 * start time of the conference.
1192 *
1193 * @return The time at which the {@code Connnection} was connected.
1194 *
1195 * @hide
1196 */
1197 public final long getConnectTimeMillis() {
1198 return mConnectTimeMillis;
1199 }
1200
1201 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001202 * @return The status hints for this connection.
1203 */
1204 public final StatusHints getStatusHints() {
1205 return mStatusHints;
1206 }
1207
1208 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001209 * @return The extras associated with this connection.
1210 */
1211 public final Bundle getExtras() {
1212 return mExtras;
1213 }
1214
1215 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001216 * Assign a listener to be notified of state changes.
1217 *
1218 * @param l A listener.
1219 * @return This Connection.
1220 *
1221 * @hide
1222 */
1223 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001224 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001225 return this;
1226 }
1227
1228 /**
1229 * Remove a previously assigned listener that was being notified of state changes.
1230 *
1231 * @param l A Listener.
1232 * @return This Connection.
1233 *
1234 * @hide
1235 */
1236 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001237 if (l != null) {
1238 mListeners.remove(l);
1239 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001240 return this;
1241 }
1242
1243 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001244 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001245 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001246 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001247 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001248 }
1249
1250 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001251 * Inform this Connection that the state of its audio output has been changed externally.
1252 *
1253 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001254 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001255 */
Yorke Lee4af59352015-05-13 14:14:54 -07001256 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001257 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001258 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001259 mCallAudioState = state;
1260 onAudioStateChanged(getAudioState());
1261 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001262 }
1263
1264 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001265 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001266 * @return A string representation of the value.
1267 */
1268 public static String stateToString(int state) {
1269 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001270 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001271 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001272 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001273 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001274 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001275 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001276 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001277 return "DIALING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001278 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001279 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001280 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001281 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001282 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001283 return "DISCONNECTED";
1284 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001285 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001286 return "UNKNOWN";
1287 }
1288 }
1289
1290 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001291 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001292 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001293 public final int getConnectionCapabilities() {
1294 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001295 }
1296
1297 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001298 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001299 *
Andrew Lee100e2932014-09-08 15:34:24 -07001300 * @param address The new address.
1301 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001302 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001303 */
Andrew Lee100e2932014-09-08 15:34:24 -07001304 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001305 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001306 Log.d(this, "setAddress %s", address);
1307 mAddress = address;
1308 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001309 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001310 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001311 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001312 }
1313
1314 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001315 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001316 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001317 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001318 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001319 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001320 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001321 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001322 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001323 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001324 mCallerDisplayName = callerDisplayName;
1325 mCallerDisplayNamePresentation = presentation;
1326 for (Listener l : mListeners) {
1327 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1328 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001329 }
1330
1331 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001332 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001333 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1334 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1335 * {@link VideoProfile#STATE_TX_ENABLED},
1336 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001337 *
1338 * @param videoState The new video state.
1339 */
1340 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001341 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001342 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001343 mVideoState = videoState;
1344 for (Listener l : mListeners) {
1345 l.onVideoStateChanged(this, mVideoState);
1346 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001347 }
1348
1349 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001350 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001351 * communicate).
1352 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001353 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001354 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001355 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001356 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001357 }
1358
1359 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001360 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001361 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001362 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001363 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001364 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001365 }
1366
1367 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001368 * Sets state to initializing (this Connection is not yet ready to be used).
1369 */
1370 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001371 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001372 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001373 }
1374
1375 /**
1376 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1377 */
1378 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001379 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001380 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001381 }
1382
1383 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001384 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001385 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001386 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001387 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001388 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001389 }
1390
1391 /**
1392 * Sets state to be on hold.
1393 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001394 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001395 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001396 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001397 }
1398
1399 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001400 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001401 * @param videoProvider The video provider.
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001402 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001403 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001404 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001405 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001406 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001407 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001408 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001409 }
1410
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001411 public final VideoProvider getVideoProvider() {
1412 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001413 }
1414
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001415 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001416 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001417 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001418 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001419 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001420 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001421 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001422 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001423 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001424 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001425 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001426 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001427 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001428 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001429 }
1430
1431 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001432 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1433 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1434 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1435 * to send an {@link #onPostDialContinue(boolean)} signal.
1436 *
1437 * @param remaining The DTMF character sequence remaining to be emitted once the
1438 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1439 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001440 */
1441 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001442 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001443 for (Listener l : mListeners) {
1444 l.onPostDialWait(this, remaining);
1445 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001446 }
1447
1448 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001449 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1450 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001451 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001452 *
1453 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001454 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001455 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001456 checkImmutable();
1457 for (Listener l : mListeners) {
1458 l.onPostDialChar(this, nextChar);
1459 }
1460 }
1461
1462 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001463 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001464 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001465 *
1466 * @param ringback Whether the ringback tone is to be played.
1467 */
Andrew Lee100e2932014-09-08 15:34:24 -07001468 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001469 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001470 if (mRingbackRequested != ringback) {
1471 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001472 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001473 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001474 }
1475 }
Ihab Awadf8358972014-05-28 16:46:42 -07001476 }
1477
1478 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001479 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001480 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001481 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001482 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001483 public final void setConnectionCapabilities(int connectionCapabilities) {
1484 checkImmutable();
1485 if (mConnectionCapabilities != connectionCapabilities) {
1486 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001487 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001488 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001489 }
1490 }
Santos Cordonb6939982014-06-04 20:20:58 -07001491 }
1492
1493 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001494 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001495 */
Evan Charlton36a71342014-07-19 16:31:02 -07001496 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001497 for (Listener l : mListeners) {
1498 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001499 }
Santos Cordonb6939982014-06-04 20:20:58 -07001500 }
1501
1502 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001503 * Requests that the framework use VOIP audio mode for this connection.
1504 *
1505 * @param isVoip True if the audio mode is VOIP.
1506 */
1507 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001508 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001509 mAudioModeIsVoip = isVoip;
1510 for (Listener l : mListeners) {
1511 l.onAudioModeIsVoipChanged(this, isVoip);
1512 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001513 }
1514
1515 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001516 * Sets the time at which a call became active on this Connection. This is set only
1517 * when a conference call becomes active on this connection.
1518 *
1519 * @param connectionTimeMillis The connection time, in milliseconds.
1520 *
1521 * @hide
1522 */
1523 public final void setConnectTimeMillis(long connectTimeMillis) {
1524 mConnectTimeMillis = connectTimeMillis;
1525 }
1526
1527 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001528 * Sets the label and icon status to display in the in-call UI.
1529 *
1530 * @param statusHints The status label and icon to set.
1531 */
1532 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001533 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001534 mStatusHints = statusHints;
1535 for (Listener l : mListeners) {
1536 l.onStatusHintsChanged(this, statusHints);
1537 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001538 }
1539
1540 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001541 * Sets the connections with which this connection can be conferenced.
1542 *
1543 * @param conferenceableConnections The set of connections this connection can conference with.
1544 */
1545 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001546 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001547 clearConferenceableList();
1548 for (Connection c : conferenceableConnections) {
1549 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1550 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001551 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001552 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001553 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001554 }
1555 }
1556 fireOnConferenceableConnectionsChanged();
1557 }
1558
1559 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001560 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1561 * or conferences with which this connection can be conferenced.
1562 *
1563 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001564 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001565 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001566 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001567 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001568 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1569 // small amount of items here.
1570 if (!mConferenceables.contains(c)) {
1571 if (c instanceof Connection) {
1572 Connection connection = (Connection) c;
1573 connection.addConnectionListener(mConnectionDeathListener);
1574 } else if (c instanceof Conference) {
1575 Conference conference = (Conference) c;
1576 conference.addListener(mConferenceDeathListener);
1577 }
1578 mConferenceables.add(c);
1579 }
1580 }
1581 fireOnConferenceableConnectionsChanged();
1582 }
1583
1584 /**
1585 * Returns the connections or conferences with which this connection can be conferenced.
1586 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001587 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001588 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001589 }
1590
Evan Charlton8635c572014-09-24 14:04:51 -07001591 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -07001592 * @hide
1593 */
1594 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001595 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001596 if (mConnectionService != null) {
1597 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1598 "which is already associated with another ConnectionService.");
1599 } else {
1600 mConnectionService = connectionService;
1601 }
1602 }
1603
1604 /**
1605 * @hide
1606 */
1607 public final void unsetConnectionService(ConnectionService connectionService) {
1608 if (mConnectionService != connectionService) {
1609 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1610 "that does not belong to the ConnectionService.");
1611 } else {
1612 mConnectionService = null;
1613 }
1614 }
1615
1616 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001617 * @hide
1618 */
1619 public final ConnectionService getConnectionService() {
1620 return mConnectionService;
1621 }
1622
1623 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001624 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001625 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001626 *
1627 * @param conference The conference.
1628 * @return {@code true} if the conference was successfully set.
1629 * @hide
1630 */
1631 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001632 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001633 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001634 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001635 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001636 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1637 fireConferenceChanged();
1638 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001639 return true;
1640 }
1641 return false;
1642 }
1643
1644 /**
1645 * Resets the conference that this connection is a part of.
1646 * @hide
1647 */
1648 public final void resetConference() {
1649 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001650 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001651 mConference = null;
1652 fireConferenceChanged();
1653 }
1654 }
1655
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001656 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001657 * Set some extras that can be associated with this {@code Connection}. No assumptions should
1658 * be made as to how an In-Call UI or service will handle these extras.
1659 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1660 *
1661 * @param extras The extras associated with this {@code Connection}.
1662 */
1663 public final void setExtras(@Nullable Bundle extras) {
1664 checkImmutable();
1665 mExtras = extras;
1666 for (Listener l : mListeners) {
1667 l.onExtrasChanged(this, extras);
1668 }
1669 }
1670
1671 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001672 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001673 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001674 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001675 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
1676 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07001677 */
Yorke Lee4af59352015-05-13 14:14:54 -07001678 @SystemApi
1679 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07001680 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001681
1682 /**
Yorke Lee4af59352015-05-13 14:14:54 -07001683 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
1684 *
1685 * @param state The new connection audio state.
1686 */
1687 public void onCallAudioStateChanged(CallAudioState state) {}
1688
1689 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001690 * Notifies this Connection of an internal state change. This method is called after the
1691 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001692 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001693 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001694 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001695 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001696
1697 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001698 * Notifies this Connection of a request to play a DTMF tone.
1699 *
1700 * @param c A DTMF character.
1701 */
Santos Cordonf2951102014-07-20 19:06:29 -07001702 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001703
1704 /**
1705 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1706 */
Santos Cordonf2951102014-07-20 19:06:29 -07001707 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001708
1709 /**
1710 * Notifies this Connection of a request to disconnect.
1711 */
Santos Cordonf2951102014-07-20 19:06:29 -07001712 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001713
1714 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001715 * Notifies this Connection of a request to disconnect a participant of the conference managed
1716 * by the connection.
1717 *
1718 * @param endpoint the {@link Uri} of the participant to disconnect.
1719 * @hide
1720 */
1721 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1722
1723 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001724 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001725 */
Santos Cordonf2951102014-07-20 19:06:29 -07001726 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001727
1728 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001729 * Notifies this Connection of a request to abort.
1730 */
Santos Cordonf2951102014-07-20 19:06:29 -07001731 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001732
1733 /**
1734 * Notifies this Connection of a request to hold.
1735 */
Santos Cordonf2951102014-07-20 19:06:29 -07001736 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001737
1738 /**
1739 * Notifies this Connection of a request to exit a hold state.
1740 */
Santos Cordonf2951102014-07-20 19:06:29 -07001741 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001742
1743 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001744 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001745 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001746 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001747 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001748 */
Santos Cordonf2951102014-07-20 19:06:29 -07001749 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001750
1751 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001752 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001753 * a request to accept.
1754 */
1755 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07001756 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07001757 }
1758
1759 /**
1760 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001761 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001762 */
Santos Cordonf2951102014-07-20 19:06:29 -07001763 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001764
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001765 /**
1766 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1767 */
Santos Cordonf2951102014-07-20 19:06:29 -07001768 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001769
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001770 static String toLogSafePhoneNumber(String number) {
1771 // For unknown number, log empty string.
1772 if (number == null) {
1773 return "";
1774 }
1775
1776 if (PII_DEBUG) {
1777 // When PII_DEBUG is true we emit PII.
1778 return number;
1779 }
1780
1781 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1782 // sanitized phone numbers.
1783 StringBuilder builder = new StringBuilder();
1784 for (int i = 0; i < number.length(); i++) {
1785 char c = number.charAt(i);
1786 if (c == '-' || c == '@' || c == '.') {
1787 builder.append(c);
1788 } else {
1789 builder.append('x');
1790 }
1791 }
1792 return builder.toString();
1793 }
1794
Ihab Awad542e0ea2014-05-16 10:22:16 -07001795 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001796 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001797 if (mState == STATE_DISCONNECTED && mState != state) {
1798 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001799 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001800 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001801 if (mState != state) {
1802 Log.d(this, "setState: %s", stateToString(state));
1803 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001804 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001805 for (Listener l : mListeners) {
1806 l.onStateChanged(this, state);
1807 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001808 }
1809 }
1810
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001811 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001812 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001813 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1814 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001815 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001816 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001817
1818 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001819 if (mImmutable) {
1820 throw new UnsupportedOperationException("Connection is immutable");
1821 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001822 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001823 }
1824
Evan Charltonbf11f982014-07-20 22:06:28 -07001825 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001826 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001827 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1828 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001829 * <p>
1830 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1831 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001832 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001833 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001834 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001835 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001836 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1837 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001838 }
1839
Evan Charltonbf11f982014-07-20 22:06:28 -07001840 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001841 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1842 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1843 * this should never be un-@hide-den.
1844 *
1845 * @hide
1846 */
1847 public void checkImmutable() {}
1848
1849 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001850 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1851 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1852 * that state. This connection should not be used for anything, and no other
1853 * {@code Connection}s should be attempted.
1854 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001855 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001856 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001857 * @return A {@code Connection} which indicates that the underlying connection should
1858 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001859 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001860 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001861 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001862 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001863
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001864 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001865 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001866 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001867 }
1868 }
1869
Santos Cordon823fd3c2014-08-07 18:35:18 -07001870 private final void fireConferenceChanged() {
1871 for (Listener l : mListeners) {
1872 l.onConferenceChanged(this, mConference);
1873 }
1874 }
1875
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001876 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001877 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001878 if (c instanceof Connection) {
1879 Connection connection = (Connection) c;
1880 connection.removeConnectionListener(mConnectionDeathListener);
1881 } else if (c instanceof Conference) {
1882 Conference conference = (Conference) c;
1883 conference.removeListener(mConferenceDeathListener);
1884 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001885 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001886 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001887 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001888
1889 /**
Anthony Lee17455a32015-04-24 15:25:29 -07001890 * Notifies listeners that the merge request failed.
1891 *
1892 * @hide
1893 */
1894 protected final void notifyConferenceMergeFailed() {
1895 for (Listener l : mListeners) {
1896 l.onConferenceMergeFailed(this);
1897 }
1898 }
1899
1900 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001901 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001902 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001903 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001904 * @hide
1905 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001906 protected final void updateConferenceParticipants(
1907 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001908 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001909 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001910 }
1911 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001912
1913 /**
1914 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07001915 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001916 */
1917 protected void notifyConferenceStarted() {
1918 for (Listener l : mListeners) {
1919 l.onConferenceStarted();
1920 }
1921 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001922}