blob: 239cdcf038fd6d9d08f9170873a5150de89a03e9 [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
Hall Liub64ac4c2017-02-06 10:49:48 -080023import android.annotation.IntDef;
Tyler Gunndee56a82016-03-23 16:06:34 -070024import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070025import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070026import android.annotation.SystemApi;
Hall Liuffa4a812017-03-02 16:11:00 -080027import android.annotation.TestApi;
Tyler Gunn159f35c2017-03-02 09:28:37 -080028import android.app.Notification;
29import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070030import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070031import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080032import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070033import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070034import android.os.Handler;
35import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070036import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070037import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080038import android.os.ParcelFileDescriptor;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070039import android.os.RemoteException;
Tyler Gunndee56a82016-03-23 16:06:34 -070040import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070041import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070042
Hall Liu95d55872017-01-25 17:12:49 -080043import java.io.IOException;
44import java.io.InputStreamReader;
45import java.io.OutputStreamWriter;
Hall Liub64ac4c2017-02-06 10:49:48 -080046import java.lang.annotation.Retention;
47import java.lang.annotation.RetentionPolicy;
Santos Cordonb6939982014-06-04 20:20:58 -070048import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070049import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070050import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070051import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070052import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070053import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070054
55/**
Santos Cordon895d4b82015-06-25 16:41:48 -070056 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
57 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070058 * <p>
59 * Implementations create a custom subclass of {@code Connection} and return it to the framework
60 * as the return value of
61 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
62 * or
63 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
64 * Implementations are then responsible for updating the state of the {@code Connection}, and
65 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
66 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070067 * <p>
68 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
69 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
70 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
71 * {@code Connection} instance.
72 * <p>
73 * Basic call support requires overriding the following methods: {@link #onAnswer()},
74 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
75 * <p>
76 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
77 * {@link #onUnhold()} methods should be overridden to provide hold support for the
78 * {@code Connection}.
79 * <p>
80 * Where a {@code Connection} supports a variation of video calling (e.g. the
81 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
82 * to support answering a call as a video call.
83 * <p>
84 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
85 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
86 * support for pulling the external call.
87 * <p>
88 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
89 * overridden.
90 * <p>
91 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
92 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
93 * for example, call events from a {@link InCallService} are handled,
94 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
95 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
96 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
97 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -070098 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070099public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700100
Santos Cordon895d4b82015-06-25 16:41:48 -0700101 /**
102 * The connection is initializing. This is generally the first state for a {@code Connection}
103 * returned by a {@link ConnectionService}.
104 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700105 public static final int STATE_INITIALIZING = 0;
106
Santos Cordon895d4b82015-06-25 16:41:48 -0700107 /**
108 * The connection is new and not connected.
109 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700110 public static final int STATE_NEW = 1;
111
Santos Cordon895d4b82015-06-25 16:41:48 -0700112 /**
113 * An incoming connection is in the ringing state. During this state, the user's ringer or
114 * vibration feature will be activated.
115 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700116 public static final int STATE_RINGING = 2;
117
Santos Cordon895d4b82015-06-25 16:41:48 -0700118 /**
119 * An outgoing connection is in the dialing state. In this state the other party has not yet
120 * answered the call and the user traditionally hears a ringback tone.
121 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700122 public static final int STATE_DIALING = 3;
123
Santos Cordon895d4b82015-06-25 16:41:48 -0700124 /**
125 * A connection is active. Both parties are connected to the call and can actively communicate.
126 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700127 public static final int STATE_ACTIVE = 4;
128
Santos Cordon895d4b82015-06-25 16:41:48 -0700129 /**
130 * A connection is on hold.
131 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700132 public static final int STATE_HOLDING = 5;
133
Santos Cordon895d4b82015-06-25 16:41:48 -0700134 /**
135 * A connection has been disconnected. This is the final state once the user has been
136 * disconnected from a call either locally, remotely or by an error in the service.
137 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700138 public static final int STATE_DISCONNECTED = 6;
139
Santos Cordon895d4b82015-06-25 16:41:48 -0700140 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700141 * The state of an external connection which is in the process of being pulled from a remote
142 * device to the local device.
143 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700144 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700145 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
146 */
147 public static final int STATE_PULLING_CALL = 7;
148
149 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700150 * Connection can currently be put on hold or unheld. This is distinct from
151 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
152 * it does not at the moment support the function. This can be true while the call is in the
153 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
154 * display a disabled 'hold' button.
155 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800156 public static final int CAPABILITY_HOLD = 0x00000001;
157
158 /** Connection supports the hold feature. */
159 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
160
161 /**
162 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
163 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
164 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
165 * capability allows a merge button to be shown while the conference is in the foreground
166 * of the in-call UI.
167 * <p>
168 * This is only intended for use by a {@link Conference}.
169 */
170 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
171
172 /**
173 * Connections within a conference can be swapped between foreground and background.
174 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
175 * <p>
176 * This is only intended for use by a {@link Conference}.
177 */
178 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
179
180 /**
181 * @hide
182 */
183 public static final int CAPABILITY_UNUSED = 0x00000010;
184
185 /** Connection supports responding via text option. */
186 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
187
188 /** Connection can be muted. */
189 public static final int CAPABILITY_MUTE = 0x00000040;
190
191 /**
192 * Connection supports conference management. This capability only applies to
193 * {@link Conference}s which can have {@link Connection}s as children.
194 */
195 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
196
197 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700198 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800199 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700200 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800201
202 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700203 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800204 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700205 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800206
207 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700208 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800209 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700210 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700211 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800212
213 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700214 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800215 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700216 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
217
218 /**
219 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700220 */
221 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
222
223 /**
224 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700225 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700226 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700227 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800228
229 /**
230 * Connection is able to be separated from its parent {@code Conference}, if any.
231 */
232 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
233
234 /**
235 * Connection is able to be individually disconnected when in a {@code Conference}.
236 */
237 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
238
239 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700240 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800241 * @hide
242 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700243 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800244
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700245 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700246 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700247 * @hide
248 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700249 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700250
251 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700252 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700253 * @hide
254 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700255 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700256
Tyler Gunn068085b2015-02-06 13:56:52 -0800257 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700258 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800259 * @hide
260 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700261 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800262
Tyler Gunn96d6c402015-03-18 12:39:23 -0700263 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500264 * Speed up audio setup for MT call.
265 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700266 */
267 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800268
Rekha Kumar07366812015-03-24 16:42:31 -0700269 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700270 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700271 */
272 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
273
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700274 /**
275 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700276 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700277 */
278 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
279
Tyler Gunnd4091732015-06-29 09:15:37 -0700280 /**
281 * For a conference, indicates the conference will not have child connections.
282 * <p>
283 * An example of a conference with child connections is a GSM conference call, where the radio
284 * retains connections to the individual participants of the conference. Another example is an
285 * IMS conference call where conference event package functionality is supported; in this case
286 * the conference server ensures the radio is aware of the participants in the conference, which
287 * are represented by child connections.
288 * <p>
289 * An example of a conference with no child connections is an IMS conference call with no
290 * conference event package support. Such a conference is represented by the radio as a single
291 * connection to the IMS conference server.
292 * <p>
293 * Indicating whether a conference has children or not is important to help user interfaces
294 * visually represent a conference. A conference with no children, for example, will have the
295 * conference connection shown in the list of calls on a Bluetooth device, where if the
296 * conference has children, only the children will be shown in the list of calls on a Bluetooth
297 * device.
298 * @hide
299 */
300 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
301
Bryce Lee81901682015-08-28 16:38:02 -0700302 /**
303 * Indicates that the connection itself wants to handle any sort of reply response, rather than
304 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700305 */
306 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
307
Tyler Gunnf97a0092016-01-19 15:59:34 -0800308 /**
309 * When set, prevents a video call from being downgraded to an audio-only call.
310 * <p>
311 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
312 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
313 * downgraded from a video call back to a VideoState of
314 * {@link VideoProfile#STATE_AUDIO_ONLY}.
315 * <p>
316 * Intuitively, a call which can be downgraded to audio should also have local and remote
317 * video
318 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
319 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
320 */
321 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
322
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700323 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700324 * When set for an external connection, indicates that this {@code Connection} can be pulled
325 * from a remote device to the current device.
326 * <p>
327 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
328 * is set.
329 */
330 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
331
332 //**********************************************************************************************
333 // Next CAPABILITY value: 0x02000000
334 //**********************************************************************************************
335
336 /**
337 * Indicates that the current device callback number should be shown.
338 *
339 * @hide
340 */
Hall Liu25c7c4d2016-08-30 13:41:02 -0700341 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700342
343 /**
344 * Whether the call is a generic conference, where we do not know the precise state of
345 * participants in the conference (eg. on CDMA).
346 *
347 * @hide
348 */
349 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
350
351 /**
352 * Connection is using high definition audio.
353 * @hide
354 */
355 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
356
357 /**
358 * Connection is using WIFI.
359 * @hide
360 */
361 public static final int PROPERTY_WIFI = 1<<3;
362
363 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700364 * When set, indicates that the {@code Connection} does not actually exist locally for the
365 * {@link ConnectionService}.
366 * <p>
367 * Consider, for example, a scenario where a user has two devices with the same phone number.
368 * When a user places a call on one devices, the telephony stack can represent that call on the
369 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700370 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700371 * <p>
372 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
373 * external connections. Only those {@link InCallService}s which have the
374 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
375 * manifest will see external connections.
376 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700377 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700378
Brad Ebinger15847072016-05-18 11:08:36 -0700379 /**
380 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
381 */
382 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700383
Hall Liu9f332c72016-07-14 15:37:37 -0700384 /**
385 * Indicates that the connection represents a downgraded IMS conference.
386 * @hide
387 */
388 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
389
Tyler Gunnf5035432017-01-09 09:43:12 -0800390 /**
391 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
392 * {@link ConnectionService}.
393 * <p>
394 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
395 */
396 public static final int PROPERTY_SELF_MANAGED = 1<<7;
397
Hall Liu95d55872017-01-25 17:12:49 -0800398 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800399 * Set by the framework to indicate that a connection has an active RTT session associated with
400 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800401 * @hide
402 */
Hall Liuffa4a812017-03-02 16:11:00 -0800403 @TestApi
Hall Liu95d55872017-01-25 17:12:49 -0800404 public static final int PROPERTY_IS_RTT = 1 << 8;
405
Tyler Gunn96d6c402015-03-18 12:39:23 -0700406 //**********************************************************************************************
Hall Liu95d55872017-01-25 17:12:49 -0800407 // Next PROPERTY value: 1<<9
Tyler Gunn96d6c402015-03-18 12:39:23 -0700408 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800409
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700410 /**
411 * Connection extra key used to store the last forwarded number associated with the current
412 * connection. Used to communicate to the user interface that the connection was forwarded via
413 * the specified number.
414 */
415 public static final String EXTRA_LAST_FORWARDED_NUMBER =
416 "android.telecom.extra.LAST_FORWARDED_NUMBER";
417
418 /**
419 * Connection extra key used to store a child number associated with the current connection.
420 * Used to communicate to the user interface that the connection was received via
421 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
422 * address.
423 */
424 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
425
426 /**
427 * Connection extra key used to store the subject for an incoming call. The user interface can
428 * query this extra and display its contents for incoming calls. Will only be used if the
429 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
430 */
431 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
432
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800433 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700434 * Boolean connection extra key set on a {@link Connection} in
435 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
436 * current active foreground call to be dropped.
437 */
438 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
439 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
440
441 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700442 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
443 * state to indicate the name of the third-party app which is responsible for the current
444 * foreground call.
445 * <p>
446 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
447 * is able to inform the user that answering the new incoming call will cause a call owned by
448 * another app to be dropped when the incoming call is answered.
449 */
450 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
451 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
452
453 /**
Hall Liu10208662016-06-15 17:55:00 -0700454 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700455 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700456 * @hide
457 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700458 public static final String EXTRA_DISABLE_ADD_CALL =
459 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700460
461 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700462 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
463 * original Connection ID associated with the connection. Used in
464 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
465 * connection/conference added via
466 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
467 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
468 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
469 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
470 * be a way to ensure that we don't add the connection again as a duplicate.
471 * <p>
472 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
473 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
474 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
475 * in a new {@link Connection} which it adds to Telecom via
476 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
477 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
478 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
479 * ID it originally referred to the connection as. Thus Telecom needs to know that the
480 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
481 * @hide
482 */
483 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
484 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
485
486 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800487 * Connection event used to inform Telecom that it should play the on hold tone. This is used
488 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700489 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800490 * @hide
491 */
492 public static final String EVENT_ON_HOLD_TONE_START =
493 "android.telecom.event.ON_HOLD_TONE_START";
494
495 /**
496 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
497 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700498 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800499 * @hide
500 */
501 public static final String EVENT_ON_HOLD_TONE_END =
502 "android.telecom.event.ON_HOLD_TONE_END";
503
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700504 /**
505 * Connection event used to inform {@link InCallService}s when pulling of an external call has
506 * failed. The user interface should inform the user of the error.
507 * <p>
508 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
509 * API is called on a {@link Call} with the properties
510 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
511 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
512 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700513 * <p>
514 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
515 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700516 */
517 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
518
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700519 /**
520 * Connection event used to inform {@link InCallService}s when the merging of two calls has
521 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700522 * <p>
523 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
524 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700525 */
526 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
527
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700528 /**
529 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
530 * the remote party.
531 * <p>
532 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
533 * call is being held locally on the device. When a capable {@link ConnectionService} receives
534 * signalling to indicate that the remote party has put the call on hold, it can send this
535 * connection event.
536 * @hide
537 */
538 public static final String EVENT_CALL_REMOTELY_HELD =
539 "android.telecom.event.CALL_REMOTELY_HELD";
540
541 /**
542 * Connection event used to inform {@link InCallService}s when a call which was remotely held
543 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
544 * <p>
545 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
546 * call is being held locally on the device. When a capable {@link ConnectionService} receives
547 * signalling to indicate that the remote party has taken the call off hold, it can send this
548 * connection event.
549 * @hide
550 */
551 public static final String EVENT_CALL_REMOTELY_UNHELD =
552 "android.telecom.event.CALL_REMOTELY_UNHELD";
553
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700554 // Flag controlling whether PII is emitted into the logs
555 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
556
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800557 /**
558 * Whether the given capabilities support the specified capability.
559 *
560 * @param capabilities A capability bit field.
561 * @param capability The capability to check capabilities for.
562 * @return Whether the specified capability is supported.
563 * @hide
564 */
565 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800566 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800567 }
568
569 /**
570 * Whether the capabilities of this {@code Connection} supports the specified capability.
571 *
572 * @param capability The capability to check capabilities for.
573 * @return Whether the specified capability is supported.
574 * @hide
575 */
576 public boolean can(int capability) {
577 return can(mConnectionCapabilities, capability);
578 }
579
580 /**
581 * Removes the specified capability from the set of capabilities of this {@code Connection}.
582 *
583 * @param capability The capability to remove from the set.
584 * @hide
585 */
586 public void removeCapability(int capability) {
587 mConnectionCapabilities &= ~capability;
588 }
589
590 /**
591 * Adds the specified capability to the set of capabilities of this {@code Connection}.
592 *
593 * @param capability The capability to add to the set.
594 * @hide
595 */
596 public void addCapability(int capability) {
597 mConnectionCapabilities |= capability;
598 }
599
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700600 /**
601 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
602 *
603 * @param capabilities A capability bit field.
604 * @return A human readable string representation.
605 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800606 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700607 return capabilitiesToStringInternal(capabilities, true /* isLong */);
608 }
609
610 /**
611 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
612 * string.
613 *
614 * @param capabilities A capability bit field.
615 * @return A human readable string representation.
616 * @hide
617 */
618 public static String capabilitiesToStringShort(int capabilities) {
619 return capabilitiesToStringInternal(capabilities, false /* isLong */);
620 }
621
622 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800623 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700624 builder.append("[");
625 if (isLong) {
626 builder.append("Capabilities:");
627 }
628
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800629 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700630 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800631 }
632 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700633 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800634 }
635 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700636 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800637 }
638 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700639 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800640 }
641 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700642 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800643 }
644 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700645 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800646 }
647 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700648 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800649 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700650 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700651 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700652 }
653 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700654 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700655 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700656 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700657 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800658 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700659 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700660 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700661 }
662 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700663 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700664 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700665 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700666 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800667 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800668 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700669 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800670 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500671 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700672 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500673 }
Rekha Kumar07366812015-03-24 16:42:31 -0700674 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700675 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700676 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700677 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700678 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700679 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700680 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700681 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700682 }
Bryce Lee81901682015-08-28 16:38:02 -0700683 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700684 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700685 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700686 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700687 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700688 }
Bryce Lee81901682015-08-28 16:38:02 -0700689
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800690 builder.append("]");
691 return builder.toString();
692 }
693
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700694 /**
695 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
696 *
697 * @param properties A property bit field.
698 * @return A human readable string representation.
699 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700700 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700701 return propertiesToStringInternal(properties, true /* isLong */);
702 }
703
704 /**
705 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
706 *
707 * @param properties A property bit field.
708 * @return A human readable string representation.
709 * @hide
710 */
711 public static String propertiesToStringShort(int properties) {
712 return propertiesToStringInternal(properties, false /* isLong */);
713 }
714
715 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700716 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700717 builder.append("[");
718 if (isLong) {
719 builder.append("Properties:");
720 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700721
Tyler Gunnf5035432017-01-09 09:43:12 -0800722 if (can(properties, PROPERTY_SELF_MANAGED)) {
723 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
724 }
725
Hall Liu25c7c4d2016-08-30 13:41:02 -0700726 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
727 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700728 }
729
730 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700731 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700732 }
733
734 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700735 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700736 }
737
738 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700739 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700740 }
741
742 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700743 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700744 }
745
Brad Ebinger15847072016-05-18 11:08:36 -0700746 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700747 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700748 }
749
Tyler Gunn720c6642016-03-22 09:02:47 -0700750 builder.append("]");
751 return builder.toString();
752 }
753
Sailesh Nepal091768c2014-06-30 15:15:23 -0700754 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700755 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700756 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700757 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700758 public void onCallerDisplayNameChanged(
759 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700760 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700761 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700762 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800763 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700764 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700765 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800766 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700767 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800768 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700769 public void onVideoProviderChanged(
770 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700771 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
772 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800773 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700774 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700775 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700776 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800777 public void onConferenceParticipantsChanged(Connection c,
778 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800779 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700780 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700781 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700782 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700783 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700784 /** @hide */
785 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Tyler Gunnf5035432017-01-09 09:43:12 -0800786 public void onAudioRouteChanged(Connection c, int audioRoute) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800787 public void onRttInitiationSuccess(Connection c) {}
788 public void onRttInitiationFailure(Connection c, int reason) {}
789 public void onRttSessionRemotelyTerminated(Connection c) {}
790 public void onRemoteRttRequest(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700791 }
792
Tyler Gunnb702ef82015-05-29 11:51:53 -0700793 /**
Hall Liu95d55872017-01-25 17:12:49 -0800794 * Provides methods to read and write RTT data to/from the in-call app.
795 * @hide
796 */
Hall Liuffa4a812017-03-02 16:11:00 -0800797 @TestApi
Hall Liu95d55872017-01-25 17:12:49 -0800798 public static final class RttTextStream {
799 private static final int READ_BUFFER_SIZE = 1000;
800 private final InputStreamReader mPipeFromInCall;
801 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800802 private final ParcelFileDescriptor mFdFromInCall;
803 private final ParcelFileDescriptor mFdToInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800804 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
805
806 /**
807 * @hide
808 */
809 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800810 mFdFromInCall = fromInCall;
811 mFdToInCall = toInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800812 mPipeFromInCall = new InputStreamReader(
813 new ParcelFileDescriptor.AutoCloseInputStream(fromInCall));
814 mPipeToInCall = new OutputStreamWriter(
815 new ParcelFileDescriptor.AutoCloseOutputStream(toInCall));
816 }
817
818 /**
819 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
820 * RTT transmits text in real-time, this method should be called as often as text snippets
821 * are received from the remote user, even if it is only one character.
822 *
823 * This method is not thread-safe -- calling it from multiple threads simultaneously may
824 * lead to interleaved text.
825 * @param input The message to send to the in-call app.
826 */
827 public void write(String input) throws IOException {
828 mPipeToInCall.write(input);
829 mPipeToInCall.flush();
830 }
831
832
833 /**
834 * Reads a string from the in-call app, blocking if there is no data available. Returns
835 * {@code null} if the RTT conversation has been terminated and there is no further data
836 * to read.
837 *
838 * This method is not thread-safe -- calling it from multiple threads simultaneously may
839 * lead to interleaved text.
840 * @return A string containing text entered by the user, or {@code null} if the
841 * conversation has been terminated or if there was an error while reading.
842 */
Hall Liuffa4a812017-03-02 16:11:00 -0800843 public String read() throws IOException {
844 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
845 if (numRead < 0) {
846 return null;
847 }
848 return new String(mReadBuffer, 0, numRead);
849 }
850
851 /**
852 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
853 * be read.
854 * @return A string containing text entered by the user, or {@code null} if the user has
855 * not entered any new text yet.
856 */
857 public String readImmediately() throws IOException {
858 if (mPipeFromInCall.ready()) {
859 return read();
860 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800861 return null;
862 }
863 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800864
865 /** @hide */
866 public ParcelFileDescriptor getFdFromInCall() {
867 return mFdFromInCall;
868 }
869
870 /** @hide */
871 public ParcelFileDescriptor getFdToInCall() {
872 return mFdToInCall;
873 }
874 }
875
876 /**
877 * Provides constants to represent the results of responses to session modify requests sent via
878 * {@link Call#sendRttRequest()}
879 */
880 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -0700881 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800882 /**
883 * Session modify request was successful.
884 */
885 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
886
887 /**
888 * Session modify request failed.
889 */
890 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
891
892 /**
893 * Session modify request ignored due to invalid parameters.
894 */
895 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
896
897 /**
898 * Session modify request timed out.
899 */
900 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
901
902 /**
903 * Session modify request rejected by remote user.
904 */
905 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -0800906 }
907
908 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700909 * Provides a means of controlling the video session associated with a {@link Connection}.
910 * <p>
911 * Implementations create a custom subclass of {@link VideoProvider} and the
912 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
913 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
914 * should set the {@link VideoProvider}.
915 * <p>
916 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
917 * {@link InCallService} implementations to issue requests related to the video session;
918 * it provides a means for the {@link ConnectionService} to report events and information
919 * related to the video session to Telecom and the {@link InCallService} implementations.
920 * <p>
921 * {@link InCallService} implementations interact with the {@link VideoProvider} via
922 * {@link android.telecom.InCallService.VideoCall}.
923 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700924 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700925 /**
926 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700927 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700928 */
929 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700930
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700931 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700932 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
933 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700934 */
935 public static final int SESSION_EVENT_RX_RESUME = 2;
936
937 /**
938 * Video transmission has begun. This occurs after a negotiated start of video transmission
939 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700940 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700941 */
942 public static final int SESSION_EVENT_TX_START = 3;
943
944 /**
945 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
946 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700947 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700948 */
949 public static final int SESSION_EVENT_TX_STOP = 4;
950
951 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800952 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -0700953 * this as a cue to inform the user the camera is not available.
954 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700955 */
956 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
957
958 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700959 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800960 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -0700961 * the camera has become available again.
962 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700963 */
964 public static final int SESSION_EVENT_CAMERA_READY = 6;
965
966 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800967 * Session event raised by Telecom when
968 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
969 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
970 * @see #handleCallSessionEvent(int)
971 */
972 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
973
974 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700975 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700976 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700977 */
978 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
979
980 /**
981 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700982 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700983 */
984 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
985
986 /**
987 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700988 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700989 */
990 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
991
Rekha Kumar07366812015-03-24 16:42:31 -0700992 /**
993 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700994 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700995 */
996 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
997
998 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700999 * Session modify request rejected by remote user.
1000 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001001 */
1002 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1003
Tyler Gunn75958422015-04-15 14:23:42 -07001004 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001005 private static final int MSG_SET_CAMERA = 2;
1006 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1007 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1008 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1009 private static final int MSG_SET_ZOOM = 6;
1010 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1011 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1012 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001013 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001014 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001015 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001016
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001017 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1018 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1019 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1020 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1021 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1022 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001023 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1024 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001025 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1026
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001027 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001028 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001029
1030 /**
1031 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001032 *
1033 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1034 * load factor before resizing, 1 means we only expect a single thread to
1035 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001036 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001037 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1038 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001039
1040 /**
1041 * Default handler used to consolidate binder method calls onto a single thread.
1042 */
1043 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001044 public VideoProviderHandler() {
1045 super();
1046 }
1047
1048 public VideoProviderHandler(Looper looper) {
1049 super(looper);
1050 }
1051
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001052 @Override
1053 public void handleMessage(Message msg) {
1054 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001055 case MSG_ADD_VIDEO_CALLBACK: {
1056 IBinder binder = (IBinder) msg.obj;
1057 IVideoCallback callback = IVideoCallback.Stub
1058 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001059 if (callback == null) {
1060 Log.w(this, "addVideoProvider - skipped; callback is null.");
1061 break;
1062 }
1063
Tyler Gunn75958422015-04-15 14:23:42 -07001064 if (mVideoCallbacks.containsKey(binder)) {
1065 Log.i(this, "addVideoProvider - skipped; already present.");
1066 break;
1067 }
1068 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001069 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001070 }
1071 case MSG_REMOVE_VIDEO_CALLBACK: {
1072 IBinder binder = (IBinder) msg.obj;
1073 IVideoCallback callback = IVideoCallback.Stub
1074 .asInterface((IBinder) msg.obj);
1075 if (!mVideoCallbacks.containsKey(binder)) {
1076 Log.i(this, "removeVideoProvider - skipped; not present.");
1077 break;
1078 }
1079 mVideoCallbacks.remove(binder);
1080 break;
1081 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001082 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001083 {
1084 SomeArgs args = (SomeArgs) msg.obj;
1085 try {
1086 onSetCamera((String) args.arg1);
1087 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001088 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001089 } finally {
1090 args.recycle();
1091 }
1092 }
1093 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001094 case MSG_SET_PREVIEW_SURFACE:
1095 onSetPreviewSurface((Surface) msg.obj);
1096 break;
1097 case MSG_SET_DISPLAY_SURFACE:
1098 onSetDisplaySurface((Surface) msg.obj);
1099 break;
1100 case MSG_SET_DEVICE_ORIENTATION:
1101 onSetDeviceOrientation(msg.arg1);
1102 break;
1103 case MSG_SET_ZOOM:
1104 onSetZoom((Float) msg.obj);
1105 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001106 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1107 SomeArgs args = (SomeArgs) msg.obj;
1108 try {
1109 onSendSessionModifyRequest((VideoProfile) args.arg1,
1110 (VideoProfile) args.arg2);
1111 } finally {
1112 args.recycle();
1113 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001114 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001115 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001116 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1117 onSendSessionModifyResponse((VideoProfile) msg.obj);
1118 break;
1119 case MSG_REQUEST_CAMERA_CAPABILITIES:
1120 onRequestCameraCapabilities();
1121 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001122 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1123 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001124 break;
1125 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001126 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001127 break;
1128 default:
1129 break;
1130 }
1131 }
1132 }
1133
1134 /**
1135 * IVideoProvider stub implementation.
1136 */
1137 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001138 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001139 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001140 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1141 }
1142
1143 public void removeVideoCallback(IBinder videoCallbackBinder) {
1144 mMessageHandler.obtainMessage(
1145 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001146 }
1147
Tyler Gunn159f35c2017-03-02 09:28:37 -08001148 public void setCamera(String cameraId, String callingPackageName,
1149 int targetSdkVersion) {
1150
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001151 SomeArgs args = SomeArgs.obtain();
1152 args.arg1 = cameraId;
1153 // Propagate the calling package; originally determined in
1154 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1155 // process.
1156 args.arg2 = callingPackageName;
1157 // Pass along the uid and pid of the calling app; this gets lost when we put the
1158 // message onto the handler. These are required for Telecom to perform a permission
1159 // check to see if the calling app is able to use the camera.
1160 args.argi1 = Binder.getCallingUid();
1161 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001162 // Pass along the target SDK version of the calling InCallService. This is used to
1163 // maintain backwards compatibility of the API for older callers.
1164 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001165 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001166 }
1167
1168 public void setPreviewSurface(Surface surface) {
1169 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1170 }
1171
1172 public void setDisplaySurface(Surface surface) {
1173 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1174 }
1175
1176 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001177 mMessageHandler.obtainMessage(
1178 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001179 }
1180
1181 public void setZoom(float value) {
1182 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1183 }
1184
Tyler Gunn45382162015-05-06 08:52:27 -07001185 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1186 SomeArgs args = SomeArgs.obtain();
1187 args.arg1 = fromProfile;
1188 args.arg2 = toProfile;
1189 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001190 }
1191
1192 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1193 mMessageHandler.obtainMessage(
1194 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1195 }
1196
1197 public void requestCameraCapabilities() {
1198 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1199 }
1200
1201 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001202 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001203 }
1204
Yorke Lee32f24732015-05-12 16:18:03 -07001205 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001206 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1207 }
1208 }
1209
1210 public VideoProvider() {
1211 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001212 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001213 }
1214
1215 /**
1216 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1217 *
1218 * @param looper The looper.
1219 * @hide
1220 */
1221 public VideoProvider(Looper looper) {
1222 mBinder = new VideoProvider.VideoProviderBinder();
1223 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001224 }
1225
1226 /**
1227 * Returns binder object which can be used across IPC methods.
1228 * @hide
1229 */
1230 public final IVideoProvider getInterface() {
1231 return mBinder;
1232 }
1233
1234 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001235 * Sets the camera to be used for the outgoing video.
1236 * <p>
1237 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1238 * camera via
1239 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1240 * <p>
1241 * Sent from the {@link InCallService} via
1242 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001243 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001244 * @param cameraId The id of the camera (use ids as reported by
1245 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001246 */
1247 public abstract void onSetCamera(String cameraId);
1248
1249 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001250 * Sets the camera to be used for the outgoing video.
1251 * <p>
1252 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1253 * camera via
1254 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1255 * <p>
1256 * This prototype is used internally to ensure that the calling package name, UID and PID
1257 * are sent to Telecom so that can perform a camera permission check on the caller.
1258 * <p>
1259 * Sent from the {@link InCallService} via
1260 * {@link InCallService.VideoCall#setCamera(String)}.
1261 *
1262 * @param cameraId The id of the camera (use ids as reported by
1263 * {@link CameraManager#getCameraIdList()}).
1264 * @param callingPackageName The AppOpps package name of the caller.
1265 * @param callingUid The UID of the caller.
1266 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001267 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001268 * @hide
1269 */
1270 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001271 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001272
1273 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001274 * Sets the surface to be used for displaying a preview of what the user's camera is
1275 * currently capturing. When video transmission is enabled, this is the video signal which
1276 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001277 * <p>
1278 * Sent from the {@link InCallService} via
1279 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001280 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001281 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001282 */
1283 public abstract void onSetPreviewSurface(Surface surface);
1284
1285 /**
1286 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001287 * <p>
1288 * Sent from the {@link InCallService} via
1289 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001290 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001291 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001292 */
1293 public abstract void onSetDisplaySurface(Surface surface);
1294
1295 /**
1296 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1297 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001298 * <p>
1299 * Sent from the {@link InCallService} via
1300 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001301 *
1302 * @param rotation The device orientation, in degrees.
1303 */
1304 public abstract void onSetDeviceOrientation(int rotation);
1305
1306 /**
1307 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001308 * <p>
1309 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001310 *
1311 * @param value The camera zoom ratio.
1312 */
1313 public abstract void onSetZoom(float value);
1314
1315 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001316 * Issues a request to modify the properties of the current video session.
1317 * <p>
1318 * Example scenarios include: requesting an audio-only call to be upgraded to a
1319 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1320 * when the {@link InCallService} is no longer the foreground application.
1321 * <p>
1322 * If the {@link VideoProvider} determines a request to be invalid, it should call
1323 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1324 * invalid request back to the {@link InCallService}.
1325 * <p>
1326 * Where a request requires confirmation from the user of the peer device, the
1327 * {@link VideoProvider} must communicate the request to the peer device and handle the
1328 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1329 * is used to inform the {@link InCallService} of the result of the request.
1330 * <p>
1331 * Sent from the {@link InCallService} via
1332 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001333 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001334 * @param fromProfile The video profile prior to the request.
1335 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001336 */
Tyler Gunn45382162015-05-06 08:52:27 -07001337 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1338 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001339
Tyler Gunnb702ef82015-05-29 11:51:53 -07001340 /**
1341 * Provides a response to a request to change the current video session properties.
1342 * <p>
1343 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1344 * video call, could decline the request and keep the call as audio-only.
1345 * In such a scenario, the {@code responseProfile} would have a video state of
1346 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1347 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1348 * <p>
1349 * Sent from the {@link InCallService} via
1350 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1351 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1352 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001353 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001354 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001355 */
1356 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1357
1358 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001359 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1360 * <p>
1361 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1362 * camera via
1363 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1364 * <p>
1365 * Sent from the {@link InCallService} via
1366 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001367 */
1368 public abstract void onRequestCameraCapabilities();
1369
1370 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001371 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1372 * video component of the current {@link Connection}.
1373 * <p>
1374 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1375 * via {@link VideoProvider#setCallDataUsage(long)}.
1376 * <p>
1377 * Sent from the {@link InCallService} via
1378 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001379 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001380 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001381
1382 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001383 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1384 * the peer device when the video signal is paused.
1385 * <p>
1386 * Sent from the {@link InCallService} via
1387 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001388 *
1389 * @param uri URI of image to display.
1390 */
Yorke Lee32f24732015-05-12 16:18:03 -07001391 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001392
1393 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001394 * Used to inform listening {@link InCallService} implementations when the
1395 * {@link VideoProvider} receives a session modification request.
1396 * <p>
1397 * Received by the {@link InCallService} via
1398 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001399 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001400 * @param videoProfile The requested video profile.
1401 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001402 */
1403 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001404 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001405 for (IVideoCallback callback : mVideoCallbacks.values()) {
1406 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001407 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001408 } catch (RemoteException ignored) {
1409 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001410 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001411 }
1412 }
1413 }
1414
1415 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001416 * Used to inform listening {@link InCallService} implementations when the
1417 * {@link VideoProvider} receives a response to a session modification request.
1418 * <p>
1419 * Received by the {@link InCallService} via
1420 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1421 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001422 *
1423 * @param status Status of the session modify request. Valid values are
1424 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1425 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001426 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1427 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1428 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1429 * @param requestedProfile The original request which was sent to the peer device.
1430 * @param responseProfile The actual profile changes agreed to by the peer device.
1431 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001432 */
1433 public void receiveSessionModifyResponse(int status,
1434 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001435 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001436 for (IVideoCallback callback : mVideoCallbacks.values()) {
1437 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001438 callback.receiveSessionModifyResponse(status, requestedProfile,
1439 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001440 } catch (RemoteException ignored) {
1441 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001442 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001443 }
1444 }
1445 }
1446
1447 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001448 * Used to inform listening {@link InCallService} implementations when the
1449 * {@link VideoProvider} reports a call session event.
1450 * <p>
1451 * Received by the {@link InCallService} via
1452 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001453 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001454 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1455 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1456 * {@link VideoProvider#SESSION_EVENT_TX_START},
1457 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1458 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001459 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1460 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001461 */
1462 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001463 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001464 for (IVideoCallback callback : mVideoCallbacks.values()) {
1465 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001466 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001467 } catch (RemoteException ignored) {
1468 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001469 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001470 }
1471 }
1472 }
1473
1474 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001475 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1476 * peer's video have changed.
1477 * <p>
1478 * This could occur if, for example, the peer rotates their device, changing the aspect
1479 * ratio of the video, or if the user switches between the back and front cameras.
1480 * <p>
1481 * Received by the {@link InCallService} via
1482 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001483 *
1484 * @param width The updated peer video width.
1485 * @param height The updated peer video height.
1486 */
1487 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001488 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001489 for (IVideoCallback callback : mVideoCallbacks.values()) {
1490 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001491 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001492 } catch (RemoteException ignored) {
1493 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001494 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001495 }
1496 }
1497 }
1498
1499 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001500 * Used to inform listening {@link InCallService} implementations when the data usage of the
1501 * video associated with the current {@link Connection} has changed.
1502 * <p>
1503 * This could be in response to a preview request via
1504 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001505 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1506 * 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 -07001507 * <p>
1508 * Received by the {@link InCallService} via
1509 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001510 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001511 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1512 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001513 */
Yorke Lee32f24732015-05-12 16:18:03 -07001514 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001515 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001516 for (IVideoCallback callback : mVideoCallbacks.values()) {
1517 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001518 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001519 } catch (RemoteException ignored) {
1520 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001521 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001522 }
1523 }
1524 }
1525
1526 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001527 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001528 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001529 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001530 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1531 * @hide
1532 */
1533 public void changeCallDataUsage(long dataUsage) {
1534 setCallDataUsage(dataUsage);
1535 }
1536
1537 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001538 * Used to inform listening {@link InCallService} implementations when the capabilities of
1539 * the current camera have changed.
1540 * <p>
1541 * The {@link VideoProvider} should call this in response to
1542 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1543 * changed via {@link VideoProvider#onSetCamera(String)}.
1544 * <p>
1545 * Received by the {@link InCallService} via
1546 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1547 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001548 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001549 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001550 */
Yorke Lee400470f2015-05-12 13:31:25 -07001551 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001552 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001553 for (IVideoCallback callback : mVideoCallbacks.values()) {
1554 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001555 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001556 } catch (RemoteException ignored) {
1557 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001558 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001559 }
1560 }
1561 }
Rekha Kumar07366812015-03-24 16:42:31 -07001562
1563 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001564 * Used to inform listening {@link InCallService} implementations when the video quality
1565 * of the call has changed.
1566 * <p>
1567 * Received by the {@link InCallService} via
1568 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001569 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001570 * @param videoQuality The updated video quality. Valid values:
1571 * {@link VideoProfile#QUALITY_HIGH},
1572 * {@link VideoProfile#QUALITY_MEDIUM},
1573 * {@link VideoProfile#QUALITY_LOW},
1574 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001575 */
1576 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001577 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001578 for (IVideoCallback callback : mVideoCallbacks.values()) {
1579 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001580 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001581 } catch (RemoteException ignored) {
1582 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001583 }
Rekha Kumar07366812015-03-24 16:42:31 -07001584 }
1585 }
1586 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001587
1588 /**
1589 * Returns a string representation of a call session event.
1590 *
1591 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1592 * @return String representation of the call session event.
1593 * @hide
1594 */
1595 public static String sessionEventToString(int event) {
1596 switch (event) {
1597 case SESSION_EVENT_CAMERA_FAILURE:
1598 return SESSION_EVENT_CAMERA_FAILURE_STR;
1599 case SESSION_EVENT_CAMERA_READY:
1600 return SESSION_EVENT_CAMERA_READY_STR;
1601 case SESSION_EVENT_RX_PAUSE:
1602 return SESSION_EVENT_RX_PAUSE_STR;
1603 case SESSION_EVENT_RX_RESUME:
1604 return SESSION_EVENT_RX_RESUME_STR;
1605 case SESSION_EVENT_TX_START:
1606 return SESSION_EVENT_TX_START_STR;
1607 case SESSION_EVENT_TX_STOP:
1608 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001609 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1610 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001611 default:
1612 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1613 }
1614 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001615 }
1616
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001617 private final Listener mConnectionDeathListener = new Listener() {
1618 @Override
1619 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001620 if (mConferenceables.remove(c)) {
1621 fireOnConferenceableConnectionsChanged();
1622 }
1623 }
1624 };
1625
1626 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1627 @Override
1628 public void onDestroyed(Conference c) {
1629 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001630 fireOnConferenceableConnectionsChanged();
1631 }
1632 }
1633 };
1634
Jay Shrauner229e3822014-08-15 09:23:07 -07001635 /**
1636 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1637 * load factor before resizing, 1 means we only expect a single thread to
1638 * access the map so make only a single shard
1639 */
1640 private final Set<Listener> mListeners = Collections.newSetFromMap(
1641 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001642 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1643 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001644 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001645
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001646 // The internal telecom call ID associated with this connection.
1647 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001648 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001649 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001650 private Uri mAddress;
1651 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001652 private String mCallerDisplayName;
1653 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001654 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001655 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001656 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001657 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001658 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001659 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001660 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001661 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001662 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001663 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001664 private Conference mConference;
1665 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001666 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001667 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001668
1669 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001670 * Tracks the key set for the extras bundle provided on the last invocation of
1671 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1672 * keys which were set previously but are no longer present in the replacement Bundle.
1673 */
1674 private Set<String> mPreviousExtraKeys;
1675
1676 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001677 * Create a new Connection.
1678 */
Santos Cordonf2951102014-07-20 19:06:29 -07001679 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001680
1681 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001682 * Returns the Telecom internal call ID associated with this connection. Should only be used
1683 * for debugging and tracing purposes.
1684 *
1685 * @return The Telecom call ID.
1686 * @hide
1687 */
1688 public final String getTelecomCallId() {
1689 return mTelecomCallId;
1690 }
1691
1692 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001693 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001694 */
Andrew Lee100e2932014-09-08 15:34:24 -07001695 public final Uri getAddress() {
1696 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001697 }
1698
1699 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001700 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001701 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001702 */
Andrew Lee100e2932014-09-08 15:34:24 -07001703 public final int getAddressPresentation() {
1704 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001705 }
1706
1707 /**
1708 * @return The caller display name (CNAP).
1709 */
1710 public final String getCallerDisplayName() {
1711 return mCallerDisplayName;
1712 }
1713
1714 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001715 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001716 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001717 */
1718 public final int getCallerDisplayNamePresentation() {
1719 return mCallerDisplayNamePresentation;
1720 }
1721
1722 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001723 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001724 */
1725 public final int getState() {
1726 return mState;
1727 }
1728
1729 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001730 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001731 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1732 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1733 * {@link VideoProfile#STATE_TX_ENABLED},
1734 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001735 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001736 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001737 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001738 */
1739 public final int getVideoState() {
1740 return mVideoState;
1741 }
1742
1743 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001744 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001745 * being routed by the system. This is {@code null} if this Connection
1746 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001747 * @deprecated Use {@link #getCallAudioState()} instead.
1748 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001749 */
Yorke Lee4af59352015-05-13 14:14:54 -07001750 @SystemApi
1751 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001752 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001753 if (mCallAudioState == null) {
1754 return null;
1755 }
Yorke Lee4af59352015-05-13 14:14:54 -07001756 return new AudioState(mCallAudioState);
1757 }
1758
1759 /**
1760 * @return The audio state of the connection, describing how its audio is currently
1761 * being routed by the system. This is {@code null} if this Connection
1762 * does not directly know about its audio state.
1763 */
1764 public final CallAudioState getCallAudioState() {
1765 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001766 }
1767
1768 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001769 * @return The conference that this connection is a part of. Null if it is not part of any
1770 * conference.
1771 */
1772 public final Conference getConference() {
1773 return mConference;
1774 }
1775
1776 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001777 * Returns whether this connection is requesting that the system play a ringback tone
1778 * on its behalf.
1779 */
Andrew Lee100e2932014-09-08 15:34:24 -07001780 public final boolean isRingbackRequested() {
1781 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001782 }
1783
1784 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001785 * @return True if the connection's audio mode is VOIP.
1786 */
1787 public final boolean getAudioModeIsVoip() {
1788 return mAudioModeIsVoip;
1789 }
1790
1791 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001792 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1793 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1794 * start time of the conference.
1795 *
1796 * @return The time at which the {@code Connnection} was connected.
1797 *
1798 * @hide
1799 */
1800 public final long getConnectTimeMillis() {
1801 return mConnectTimeMillis;
1802 }
1803
1804 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001805 * @return The status hints for this connection.
1806 */
1807 public final StatusHints getStatusHints() {
1808 return mStatusHints;
1809 }
1810
1811 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001812 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001813 * <p>
1814 * Extras should be updated using {@link #putExtras(Bundle)}.
1815 * <p>
1816 * Telecom or an {@link InCallService} can also update the extras via
1817 * {@link android.telecom.Call#putExtras(Bundle)}, and
1818 * {@link Call#removeExtras(List)}.
1819 * <p>
1820 * The connection is notified of changes to the extras made by Telecom or an
1821 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001822 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001823 * @return The extras associated with this connection.
1824 */
1825 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001826 Bundle extras = null;
1827 synchronized (mExtrasLock) {
1828 if (mExtras != null) {
1829 extras = new Bundle(mExtras);
1830 }
1831 }
1832 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001833 }
1834
1835 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001836 * Assign a listener to be notified of state changes.
1837 *
1838 * @param l A listener.
1839 * @return This Connection.
1840 *
1841 * @hide
1842 */
1843 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001844 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001845 return this;
1846 }
1847
1848 /**
1849 * Remove a previously assigned listener that was being notified of state changes.
1850 *
1851 * @param l A Listener.
1852 * @return This Connection.
1853 *
1854 * @hide
1855 */
1856 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001857 if (l != null) {
1858 mListeners.remove(l);
1859 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001860 return this;
1861 }
1862
1863 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001864 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001865 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001866 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001867 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001868 }
1869
1870 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001871 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1872 * ONLY for debugging purposes.
1873 *
1874 * @param callId The telecom call ID.
1875 * @hide
1876 */
1877 public void setTelecomCallId(String callId) {
1878 mTelecomCallId = callId;
1879 }
1880
1881 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001882 * Inform this Connection that the state of its audio output has been changed externally.
1883 *
1884 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001885 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001886 */
Yorke Lee4af59352015-05-13 14:14:54 -07001887 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001888 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001889 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001890 mCallAudioState = state;
1891 onAudioStateChanged(getAudioState());
1892 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001893 }
1894
1895 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001896 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001897 * @return A string representation of the value.
1898 */
1899 public static String stateToString(int state) {
1900 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001901 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001902 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001903 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001904 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001905 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001906 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001907 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001908 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001909 case STATE_PULLING_CALL:
1910 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001911 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001912 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001913 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001914 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001915 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001916 return "DISCONNECTED";
1917 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001918 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001919 return "UNKNOWN";
1920 }
1921 }
1922
1923 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001924 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001925 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001926 public final int getConnectionCapabilities() {
1927 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001928 }
1929
1930 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001931 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1932 */
1933 public final int getConnectionProperties() {
1934 return mConnectionProperties;
1935 }
1936
1937 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001938 * Returns the connection's supported audio routes.
1939 *
1940 * @hide
1941 */
1942 public final int getSupportedAudioRoutes() {
1943 return mSupportedAudioRoutes;
1944 }
1945
1946 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001947 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001948 *
Andrew Lee100e2932014-09-08 15:34:24 -07001949 * @param address The new address.
1950 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001951 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001952 */
Andrew Lee100e2932014-09-08 15:34:24 -07001953 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001954 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001955 Log.d(this, "setAddress %s", address);
1956 mAddress = address;
1957 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001958 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001959 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001960 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001961 }
1962
1963 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001964 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001965 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001966 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001967 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001968 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001969 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001970 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001971 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001972 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001973 mCallerDisplayName = callerDisplayName;
1974 mCallerDisplayNamePresentation = presentation;
1975 for (Listener l : mListeners) {
1976 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1977 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001978 }
1979
1980 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001981 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001982 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1983 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1984 * {@link VideoProfile#STATE_TX_ENABLED},
1985 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001986 *
1987 * @param videoState The new video state.
1988 */
1989 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001990 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001991 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001992 mVideoState = videoState;
1993 for (Listener l : mListeners) {
1994 l.onVideoStateChanged(this, mVideoState);
1995 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001996 }
1997
1998 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001999 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002000 * communicate).
2001 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002002 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002003 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002004 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002005 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002006 }
2007
2008 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002009 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002010 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002011 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002012 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002013 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002014 }
2015
2016 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002017 * Sets state to initializing (this Connection is not yet ready to be used).
2018 */
2019 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002020 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002021 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002022 }
2023
2024 /**
2025 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2026 */
2027 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002028 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002029 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002030 }
2031
2032 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002033 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002034 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002035 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002036 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002037 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002038 }
2039
2040 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002041 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2042 * device). Only applicable for {@link Connection}s with
2043 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2044 */
2045 public final void setPulling() {
2046 checkImmutable();
2047 setState(STATE_PULLING_CALL);
2048 }
2049
2050 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002051 * Sets state to be on hold.
2052 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002053 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002054 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002055 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002056 }
2057
2058 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002059 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002060 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002061 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002062 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002063 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002064 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002065 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002066 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002067 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002068 }
2069
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002070 public final VideoProvider getVideoProvider() {
2071 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002072 }
2073
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002074 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002075 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002076 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002077 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002078 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002079 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002080 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002081 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002082 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002083 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002084 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002085 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002086 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002087 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002088 }
2089
2090 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002091 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2092 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2093 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2094 * to send an {@link #onPostDialContinue(boolean)} signal.
2095 *
2096 * @param remaining The DTMF character sequence remaining to be emitted once the
2097 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2098 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002099 */
2100 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002101 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002102 for (Listener l : mListeners) {
2103 l.onPostDialWait(this, remaining);
2104 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002105 }
2106
2107 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002108 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2109 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002110 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002111 *
2112 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002113 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002114 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002115 checkImmutable();
2116 for (Listener l : mListeners) {
2117 l.onPostDialChar(this, nextChar);
2118 }
2119 }
2120
2121 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002122 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002123 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002124 *
2125 * @param ringback Whether the ringback tone is to be played.
2126 */
Andrew Lee100e2932014-09-08 15:34:24 -07002127 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002128 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002129 if (mRingbackRequested != ringback) {
2130 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002131 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002132 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002133 }
2134 }
Ihab Awadf8358972014-05-28 16:46:42 -07002135 }
2136
2137 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002138 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002139 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002140 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002141 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002142 public final void setConnectionCapabilities(int connectionCapabilities) {
2143 checkImmutable();
2144 if (mConnectionCapabilities != connectionCapabilities) {
2145 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002146 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002147 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002148 }
2149 }
Santos Cordonb6939982014-06-04 20:20:58 -07002150 }
2151
2152 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002153 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2154 *
2155 * @param connectionProperties The new connection properties.
2156 */
2157 public final void setConnectionProperties(int connectionProperties) {
2158 checkImmutable();
2159 if (mConnectionProperties != connectionProperties) {
2160 mConnectionProperties = connectionProperties;
2161 for (Listener l : mListeners) {
2162 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2163 }
2164 }
2165 }
2166
2167 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002168 * Sets the supported audio routes.
2169 *
2170 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2171 * See {@link CallAudioState}
2172 * @hide
2173 */
2174 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2175 if ((supportedAudioRoutes
2176 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2177 throw new IllegalArgumentException(
2178 "supported audio routes must include either speaker or earpiece");
2179 }
2180
2181 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2182 mSupportedAudioRoutes = supportedAudioRoutes;
2183 for (Listener l : mListeners) {
2184 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2185 }
2186 }
2187 }
2188
2189 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002190 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002191 */
Evan Charlton36a71342014-07-19 16:31:02 -07002192 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002193 for (Listener l : mListeners) {
2194 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002195 }
Santos Cordonb6939982014-06-04 20:20:58 -07002196 }
2197
2198 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002199 * Requests that the framework use VOIP audio mode for this connection.
2200 *
2201 * @param isVoip True if the audio mode is VOIP.
2202 */
2203 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002204 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002205 mAudioModeIsVoip = isVoip;
2206 for (Listener l : mListeners) {
2207 l.onAudioModeIsVoipChanged(this, isVoip);
2208 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002209 }
2210
2211 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002212 * Sets the time at which a call became active on this Connection. This is set only
2213 * when a conference call becomes active on this connection.
2214 *
2215 * @param connectionTimeMillis The connection time, in milliseconds.
2216 *
2217 * @hide
2218 */
2219 public final void setConnectTimeMillis(long connectTimeMillis) {
2220 mConnectTimeMillis = connectTimeMillis;
2221 }
2222
2223 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002224 * Sets the label and icon status to display in the in-call UI.
2225 *
2226 * @param statusHints The status label and icon to set.
2227 */
2228 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002229 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002230 mStatusHints = statusHints;
2231 for (Listener l : mListeners) {
2232 l.onStatusHintsChanged(this, statusHints);
2233 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002234 }
2235
2236 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002237 * Sets the connections with which this connection can be conferenced.
2238 *
2239 * @param conferenceableConnections The set of connections this connection can conference with.
2240 */
2241 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002242 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002243 clearConferenceableList();
2244 for (Connection c : conferenceableConnections) {
2245 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2246 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002247 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002248 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002249 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002250 }
2251 }
2252 fireOnConferenceableConnectionsChanged();
2253 }
2254
2255 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002256 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2257 * or conferences with which this connection can be conferenced.
2258 *
2259 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002260 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002261 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002262 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002263 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002264 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2265 // small amount of items here.
2266 if (!mConferenceables.contains(c)) {
2267 if (c instanceof Connection) {
2268 Connection connection = (Connection) c;
2269 connection.addConnectionListener(mConnectionDeathListener);
2270 } else if (c instanceof Conference) {
2271 Conference conference = (Conference) c;
2272 conference.addListener(mConferenceDeathListener);
2273 }
2274 mConferenceables.add(c);
2275 }
2276 }
2277 fireOnConferenceableConnectionsChanged();
2278 }
2279
2280 /**
2281 * Returns the connections or conferences with which this connection can be conferenced.
2282 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002283 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002284 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002285 }
2286
Yorke Lee53463962015-08-04 16:07:19 -07002287 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002288 * @hide
2289 */
2290 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002291 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002292 if (mConnectionService != null) {
2293 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2294 "which is already associated with another ConnectionService.");
2295 } else {
2296 mConnectionService = connectionService;
2297 }
2298 }
2299
2300 /**
2301 * @hide
2302 */
2303 public final void unsetConnectionService(ConnectionService connectionService) {
2304 if (mConnectionService != connectionService) {
2305 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2306 "that does not belong to the ConnectionService.");
2307 } else {
2308 mConnectionService = null;
2309 }
2310 }
2311
2312 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002313 * @hide
2314 */
2315 public final ConnectionService getConnectionService() {
2316 return mConnectionService;
2317 }
2318
2319 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002320 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002321 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002322 *
2323 * @param conference The conference.
2324 * @return {@code true} if the conference was successfully set.
2325 * @hide
2326 */
2327 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002328 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002329 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002330 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002331 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002332 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2333 fireConferenceChanged();
2334 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002335 return true;
2336 }
2337 return false;
2338 }
2339
2340 /**
2341 * Resets the conference that this connection is a part of.
2342 * @hide
2343 */
2344 public final void resetConference() {
2345 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002346 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002347 mConference = null;
2348 fireConferenceChanged();
2349 }
2350 }
2351
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002352 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002353 * Set some extras that can be associated with this {@code Connection}.
2354 * <p>
2355 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2356 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2357 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002358 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2359 * {@link #removeExtras(String...)} methods to modify the extras.
2360 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002361 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
Santos Cordon6b7f9552015-05-27 17:21:45 -07002362 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2363 *
2364 * @param extras The extras associated with this {@code Connection}.
2365 */
2366 public final void setExtras(@Nullable Bundle extras) {
2367 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002368
2369 // Add/replace any new or changed extras values.
2370 putExtras(extras);
2371
2372 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2373 // the current one and remove any keys that went away.
2374 if (mPreviousExtraKeys != null) {
2375 List<String> toRemove = new ArrayList<String>();
2376 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002377 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002378 toRemove.add(oldKey);
2379 }
2380 }
2381 if (!toRemove.isEmpty()) {
2382 removeExtras(toRemove);
2383 }
2384 }
2385
2386 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2387 // called we can see if the caller has removed any extras values.
2388 if (mPreviousExtraKeys == null) {
2389 mPreviousExtraKeys = new ArraySet<String>();
2390 }
2391 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002392 if (extras != null) {
2393 mPreviousExtraKeys.addAll(extras.keySet());
2394 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002395 }
2396
2397 /**
2398 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2399 * added.
2400 * <p>
2401 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2402 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2403 *
2404 * @param extras The extras to add.
2405 */
2406 public final void putExtras(@NonNull Bundle extras) {
2407 checkImmutable();
2408 if (extras == null) {
2409 return;
2410 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002411 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2412 // the listeners.
2413 Bundle listenerExtras;
2414 synchronized (mExtrasLock) {
2415 if (mExtras == null) {
2416 mExtras = new Bundle();
2417 }
2418 mExtras.putAll(extras);
2419 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002420 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002421 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002422 // Create a new clone of the extras for each listener so that they don't clobber
2423 // each other
2424 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002425 }
2426 }
2427
2428 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002429 * Adds a boolean extra to this {@code Connection}.
2430 *
2431 * @param key The extra key.
2432 * @param value The value.
2433 * @hide
2434 */
2435 public final void putExtra(String key, boolean value) {
2436 Bundle newExtras = new Bundle();
2437 newExtras.putBoolean(key, value);
2438 putExtras(newExtras);
2439 }
2440
2441 /**
2442 * Adds an integer extra to this {@code Connection}.
2443 *
2444 * @param key The extra key.
2445 * @param value The value.
2446 * @hide
2447 */
2448 public final void putExtra(String key, int value) {
2449 Bundle newExtras = new Bundle();
2450 newExtras.putInt(key, value);
2451 putExtras(newExtras);
2452 }
2453
2454 /**
2455 * Adds a string extra to this {@code Connection}.
2456 *
2457 * @param key The extra key.
2458 * @param value The value.
2459 * @hide
2460 */
2461 public final void putExtra(String key, String value) {
2462 Bundle newExtras = new Bundle();
2463 newExtras.putString(key, value);
2464 putExtras(newExtras);
2465 }
2466
2467 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002468 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002469 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002470 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002471 */
2472 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002473 synchronized (mExtrasLock) {
2474 if (mExtras != null) {
2475 for (String key : keys) {
2476 mExtras.remove(key);
2477 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002478 }
2479 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002480 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002481 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002482 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002483 }
2484 }
2485
2486 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002487 * Removes extras from this {@code Connection}.
2488 *
2489 * @param keys The keys of the extras to remove.
2490 */
2491 public final void removeExtras(String ... keys) {
2492 removeExtras(Arrays.asList(keys));
2493 }
2494
2495 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002496 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2497 * be change to the {@link #getCallAudioState()}.
2498 * <p>
2499 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2500 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2501 * <p>
2502 * See also {@link InCallService#setAudioRoute(int)}.
2503 *
2504 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2505 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2506 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2507 */
2508 public final void setAudioRoute(int route) {
2509 for (Listener l : mListeners) {
2510 l.onAudioRouteChanged(this, route);
2511 }
2512 }
2513
2514 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002515 * Informs listeners that a previously requested RTT session via
2516 * {@link ConnectionRequest#isRequestingRtt()} or
2517 * {@link #onStartRtt(ParcelFileDescriptor, ParcelFileDescriptor)} has succeeded.
2518 * @hide
2519 */
Hall Liuffa4a812017-03-02 16:11:00 -08002520 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002521 public final void sendRttInitiationSuccess() {
Hall Liuffa4a812017-03-02 16:11:00 -08002522 setRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08002523 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2524 }
2525
2526 /**
2527 * Informs listeners that a previously requested RTT session via
2528 * {@link ConnectionRequest#isRequestingRtt()} or
2529 * {@link #onStartRtt(ParcelFileDescriptor, ParcelFileDescriptor)}
2530 * has failed.
2531 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2532 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
2533 * @hide
2534 */
Hall Liuffa4a812017-03-02 16:11:00 -08002535 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002536 public final void sendRttInitiationFailure(int reason) {
Hall Liuffa4a812017-03-02 16:11:00 -08002537 unsetRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08002538 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2539 }
2540
2541 /**
2542 * Informs listeners that a currently active RTT session has been terminated by the remote
2543 * side of the coll.
2544 * @hide
2545 */
Hall Liuffa4a812017-03-02 16:11:00 -08002546 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002547 public final void sendRttSessionRemotelyTerminated() {
2548 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2549 }
2550
2551 /**
2552 * Informs listeners that the remote side of the call has requested an upgrade to include an
2553 * RTT session in the call.
2554 * @hide
2555 */
Hall Liuffa4a812017-03-02 16:11:00 -08002556 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002557 public final void sendRemoteRttRequest() {
2558 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2559 }
2560
2561 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002562 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002563 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002564 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002565 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2566 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002567 */
Yorke Lee4af59352015-05-13 14:14:54 -07002568 @SystemApi
2569 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002570 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002571
2572 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002573 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2574 *
2575 * @param state The new connection audio state.
2576 */
2577 public void onCallAudioStateChanged(CallAudioState state) {}
2578
2579 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002580 * Notifies this Connection of an internal state change. This method is called after the
2581 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002582 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002583 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002584 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002585 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002586
2587 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002588 * Notifies this Connection of a request to play a DTMF tone.
2589 *
2590 * @param c A DTMF character.
2591 */
Santos Cordonf2951102014-07-20 19:06:29 -07002592 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002593
2594 /**
2595 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2596 */
Santos Cordonf2951102014-07-20 19:06:29 -07002597 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002598
2599 /**
2600 * Notifies this Connection of a request to disconnect.
2601 */
Santos Cordonf2951102014-07-20 19:06:29 -07002602 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002603
2604 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002605 * Notifies this Connection of a request to disconnect a participant of the conference managed
2606 * by the connection.
2607 *
2608 * @param endpoint the {@link Uri} of the participant to disconnect.
2609 * @hide
2610 */
2611 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2612
2613 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002614 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002615 */
Santos Cordonf2951102014-07-20 19:06:29 -07002616 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002617
2618 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002619 * Notifies this Connection of a request to abort.
2620 */
Santos Cordonf2951102014-07-20 19:06:29 -07002621 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002622
2623 /**
2624 * Notifies this Connection of a request to hold.
2625 */
Santos Cordonf2951102014-07-20 19:06:29 -07002626 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002627
2628 /**
2629 * Notifies this Connection of a request to exit a hold state.
2630 */
Santos Cordonf2951102014-07-20 19:06:29 -07002631 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002632
2633 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002634 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002635 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002636 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002637 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002638 */
Santos Cordonf2951102014-07-20 19:06:29 -07002639 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002640
2641 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002642 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002643 * a request to accept.
2644 */
2645 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002646 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002647 }
2648
2649 /**
2650 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002651 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002652 */
Santos Cordonf2951102014-07-20 19:06:29 -07002653 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002654
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002655 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002656 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2657 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002658 */
2659 public void onReject(String replyMessage) {}
2660
2661 /**
Bryce Leecac50772015-11-17 15:13:29 -08002662 * Notifies the Connection of a request to silence the ringer.
2663 *
2664 * @hide
2665 */
2666 public void onSilence() {}
2667
2668 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002669 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2670 */
Santos Cordonf2951102014-07-20 19:06:29 -07002671 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002672
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002673 /**
2674 * Notifies this Connection of a request to pull an external call to the local device.
2675 * <p>
2676 * The {@link InCallService} issues a request to pull an external call to the local device via
2677 * {@link Call#pullExternalCall()}.
2678 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002679 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2680 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002681 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002682 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002683 */
2684 public void onPullExternalCall() {}
2685
2686 /**
2687 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2688 * <p>
2689 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2690 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002691 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2692 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2693 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2694 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2695 * not aware of.
2696 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002697 * See also {@link Call#sendCallEvent(String, Bundle)}.
2698 *
2699 * @param event The call event.
2700 * @param extras Extras associated with the call event.
2701 */
2702 public void onCallEvent(String event, Bundle extras) {}
2703
Tyler Gunndee56a82016-03-23 16:06:34 -07002704 /**
2705 * Notifies this {@link Connection} of a change to the extras made outside the
2706 * {@link ConnectionService}.
2707 * <p>
2708 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2709 * the {@link android.telecom.Call#putExtras(Bundle)} and
2710 * {@link Call#removeExtras(List)}.
2711 *
2712 * @param extras The new extras bundle.
2713 */
2714 public void onExtrasChanged(Bundle extras) {}
2715
Tyler Gunnf5035432017-01-09 09:43:12 -08002716 /**
2717 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2718 * displaying its incoming call user interface for the {@link Connection}.
2719 * <p>
2720 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2721 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2722 * should show its own incoming call user interface.
2723 * <p>
2724 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
2725 * regular {@link ConnectionService}, the Telecom framework will display its own incoming call
2726 * user interface to allow the user to choose whether to answer the new incoming call and
2727 * disconnect other ongoing calls, or to reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002728 * <p>
2729 * You should trigger the display of the incoming call user interface for your application by
2730 * showing a {@link Notification} with a full-screen {@link Intent} specified.
2731 * For example:
2732 * <pre><code>
2733 * // Create an intent which triggers your fullscreen incoming call user interface.
2734 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
2735 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
2736 * intent.setClass(context, YourIncomingCallActivity.class);
2737 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
2738 *
2739 * // Build the notification as an ongoing high priority item; this ensures it will show as
2740 * // a heads up notification which slides down over top of the current content.
2741 * final Notification.Builder builder = new Notification.Builder(context);
2742 * builder.setOngoing(true);
2743 * builder.setPriority(Notification.PRIORITY_HIGH);
2744 *
2745 * // Set notification content intent to take user to fullscreen UI if user taps on the
2746 * // notification body.
2747 * builder.setContentIntent(pendingIntent);
2748 * // Set full screen intent to trigger display of the fullscreen UI when the notification
2749 * // manager deems it appropriate.
2750 * builder.setFullScreenIntent(pendingIntent, true);
2751 *
2752 * // Setup notification content.
2753 * builder.setSmallIcon( yourIconResourceId );
2754 * builder.setContentTitle("Your notification title");
2755 * builder.setContentText("Your notification content.");
2756 *
2757 * // Use builder.addAction(..) to add buttons to answer or reject the call.
2758 *
2759 * NotificationManager notificationManager = mContext.getSystemService(
2760 * NotificationManager.class);
2761 * notificationManager.notify(YOUR_TAG, YOUR_ID, builder.build());
2762 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08002763 */
2764 public void onShowIncomingCallUi() {}
2765
Hall Liub64ac4c2017-02-06 10:49:48 -08002766 /**
2767 * Notifies this {@link Connection} that the user has requested an RTT session.
2768 * The connection service should call {@link #sendRttInitiationSuccess} or
2769 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
2770 * request, respectively.
2771 * @param rttTextStream The object that should be used to send text to or receive text from
2772 * the in-call app.
2773 * @hide
2774 */
Hall Liuffa4a812017-03-02 16:11:00 -08002775 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002776 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
2777
2778 /**
2779 * Notifies this {@link Connection} that it should terminate any existing RTT communication
2780 * channel. No response to Telecom is needed for this method.
2781 * @hide
2782 */
Hall Liuffa4a812017-03-02 16:11:00 -08002783 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002784 public void onStopRtt() {}
2785
2786 /**
2787 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
2788 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
2789 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
2790 * indicated by {@code rttTextStream} being {@code null}
2791 * @hide
2792 * @param rttTextStream The object that should be used to send text to or receive text from
2793 * the in-call app.
2794 */
Hall Liuffa4a812017-03-02 16:11:00 -08002795 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002796 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
2797
Hall Liuffa4a812017-03-02 16:11:00 -08002798 /**
2799 * Internal method to set {@link #PROPERTY_IS_RTT}.
2800 * @hide
2801 */
2802 void setRttProperty() {
2803 setConnectionProperties(getConnectionProperties() | PROPERTY_IS_RTT);
2804 }
2805
2806 /**
2807 * Internal method to un-set {@link #PROPERTY_IS_RTT}.
2808 * @hide
2809 */
2810 void unsetRttProperty() {
2811 setConnectionProperties(getConnectionProperties() & (~PROPERTY_IS_RTT));
2812 }
2813
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002814 static String toLogSafePhoneNumber(String number) {
2815 // For unknown number, log empty string.
2816 if (number == null) {
2817 return "";
2818 }
2819
2820 if (PII_DEBUG) {
2821 // When PII_DEBUG is true we emit PII.
2822 return number;
2823 }
2824
2825 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2826 // sanitized phone numbers.
2827 StringBuilder builder = new StringBuilder();
2828 for (int i = 0; i < number.length(); i++) {
2829 char c = number.charAt(i);
2830 if (c == '-' || c == '@' || c == '.') {
2831 builder.append(c);
2832 } else {
2833 builder.append('x');
2834 }
2835 }
2836 return builder.toString();
2837 }
2838
Ihab Awad542e0ea2014-05-16 10:22:16 -07002839 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002840 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002841 if (mState == STATE_DISCONNECTED && mState != state) {
2842 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002843 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002844 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002845 if (mState != state) {
2846 Log.d(this, "setState: %s", stateToString(state));
2847 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002848 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002849 for (Listener l : mListeners) {
2850 l.onStateChanged(this, state);
2851 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002852 }
2853 }
2854
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002855 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002856 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002857 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2858 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002859 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002860 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002861
2862 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002863 if (mImmutable) {
2864 throw new UnsupportedOperationException("Connection is immutable");
2865 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002866 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002867 }
2868
Evan Charltonbf11f982014-07-20 22:06:28 -07002869 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002870 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002871 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2872 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002873 * <p>
2874 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2875 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002876 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002877 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002878 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002879 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002880 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2881 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002882 }
2883
Evan Charltonbf11f982014-07-20 22:06:28 -07002884 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002885 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2886 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2887 * this should never be un-@hide-den.
2888 *
2889 * @hide
2890 */
2891 public void checkImmutable() {}
2892
2893 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002894 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2895 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2896 * that state. This connection should not be used for anything, and no other
2897 * {@code Connection}s should be attempted.
2898 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002899 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002900 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002901 * @return A {@code Connection} which indicates that the underlying connection should
2902 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002903 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002904 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002905 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002906 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002907
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002908 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002909 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002910 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002911 }
2912 }
2913
Santos Cordon823fd3c2014-08-07 18:35:18 -07002914 private final void fireConferenceChanged() {
2915 for (Listener l : mListeners) {
2916 l.onConferenceChanged(this, mConference);
2917 }
2918 }
2919
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002920 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002921 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002922 if (c instanceof Connection) {
2923 Connection connection = (Connection) c;
2924 connection.removeConnectionListener(mConnectionDeathListener);
2925 } else if (c instanceof Conference) {
2926 Conference conference = (Conference) c;
2927 conference.removeListener(mConferenceDeathListener);
2928 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002929 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002930 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002931 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002932
2933 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002934 * Handles a change to extras received from Telecom.
2935 *
2936 * @param extras The new extras.
2937 * @hide
2938 */
2939 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002940 Bundle b = null;
2941 synchronized (mExtrasLock) {
2942 mExtras = extras;
2943 if (mExtras != null) {
2944 b = new Bundle(mExtras);
2945 }
2946 }
2947 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07002948 }
2949
2950 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002951 * Notifies listeners that the merge request failed.
2952 *
2953 * @hide
2954 */
2955 protected final void notifyConferenceMergeFailed() {
2956 for (Listener l : mListeners) {
2957 l.onConferenceMergeFailed(this);
2958 }
2959 }
2960
2961 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002962 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002963 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002964 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002965 * @hide
2966 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002967 protected final void updateConferenceParticipants(
2968 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002969 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002970 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002971 }
2972 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002973
2974 /**
2975 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002976 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002977 */
2978 protected void notifyConferenceStarted() {
2979 for (Listener l : mListeners) {
2980 l.onConferenceStarted();
2981 }
2982 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002983
2984 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07002985 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
2986 * be a part of a conference call.
2987 * @param isConferenceSupported {@code true} if the connection supports being part of a
2988 * conference call, {@code false} otherwise.
2989 * @hide
2990 */
2991 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
2992 for (Listener l : mListeners) {
2993 l.onConferenceSupportedChanged(this, isConferenceSupported);
2994 }
2995 }
2996
2997 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002998 * Sends an event associated with this {@code Connection} with associated event extras to the
2999 * {@link InCallService}.
3000 * <p>
3001 * Connection events are used to communicate point in time information from a
3002 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3003 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3004 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3005 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3006 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3007 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3008 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3009 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3010 * <p>
3011 * Events are exposed to {@link InCallService} implementations via
3012 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3013 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003014 * No assumptions should be made as to how an In-Call UI or service will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003015 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3016 * some events altogether.
3017 * <p>
3018 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3019 * conflicts between {@link ConnectionService} implementations. Further, custom
3020 * {@link ConnectionService} implementations shall not re-purpose events in the
3021 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3022 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3023 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3024 * {@code com.example.extra.MY_EXTRA}).
3025 * <p>
3026 * When defining events and the associated extras, it is important to keep their behavior
3027 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3028 * events/extras should me maintained to ensure backwards compatibility with older
3029 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003030 *
3031 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003032 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003033 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003034 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003035 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003036 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003037 }
3038 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003039}