blob: 835eac54abc6e80bb84539694f605b356a6ddb51 [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 /**
Hall Liu10208662016-06-15 17:55:00 -0700442 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700443 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700444 * @hide
445 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700446 public static final String EXTRA_DISABLE_ADD_CALL =
447 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700448
449 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700450 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
451 * original Connection ID associated with the connection. Used in
452 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
453 * connection/conference added via
454 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
455 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
456 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
457 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
458 * be a way to ensure that we don't add the connection again as a duplicate.
459 * <p>
460 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
461 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
462 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
463 * in a new {@link Connection} which it adds to Telecom via
464 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
465 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
466 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
467 * ID it originally referred to the connection as. Thus Telecom needs to know that the
468 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
469 * @hide
470 */
471 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
472 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
473
474 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800475 * Connection event used to inform Telecom that it should play the on hold tone. This is used
476 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700477 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800478 * @hide
479 */
480 public static final String EVENT_ON_HOLD_TONE_START =
481 "android.telecom.event.ON_HOLD_TONE_START";
482
483 /**
484 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
485 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700486 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800487 * @hide
488 */
489 public static final String EVENT_ON_HOLD_TONE_END =
490 "android.telecom.event.ON_HOLD_TONE_END";
491
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700492 /**
493 * Connection event used to inform {@link InCallService}s when pulling of an external call has
494 * failed. The user interface should inform the user of the error.
495 * <p>
496 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
497 * API is called on a {@link Call} with the properties
498 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
499 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
500 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700501 * <p>
502 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
503 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700504 */
505 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
506
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700507 /**
508 * Connection event used to inform {@link InCallService}s when the merging of two calls has
509 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700510 * <p>
511 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
512 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700513 */
514 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
515
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700516 /**
517 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
518 * the remote party.
519 * <p>
520 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
521 * call is being held locally on the device. When a capable {@link ConnectionService} receives
522 * signalling to indicate that the remote party has put the call on hold, it can send this
523 * connection event.
524 * @hide
525 */
526 public static final String EVENT_CALL_REMOTELY_HELD =
527 "android.telecom.event.CALL_REMOTELY_HELD";
528
529 /**
530 * Connection event used to inform {@link InCallService}s when a call which was remotely held
531 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
532 * <p>
533 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
534 * call is being held locally on the device. When a capable {@link ConnectionService} receives
535 * signalling to indicate that the remote party has taken the call off hold, it can send this
536 * connection event.
537 * @hide
538 */
539 public static final String EVENT_CALL_REMOTELY_UNHELD =
540 "android.telecom.event.CALL_REMOTELY_UNHELD";
541
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700542 // Flag controlling whether PII is emitted into the logs
543 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
544
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800545 /**
546 * Whether the given capabilities support the specified capability.
547 *
548 * @param capabilities A capability bit field.
549 * @param capability The capability to check capabilities for.
550 * @return Whether the specified capability is supported.
551 * @hide
552 */
553 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800554 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800555 }
556
557 /**
558 * Whether the capabilities of this {@code Connection} supports the specified capability.
559 *
560 * @param capability The capability to check capabilities for.
561 * @return Whether the specified capability is supported.
562 * @hide
563 */
564 public boolean can(int capability) {
565 return can(mConnectionCapabilities, capability);
566 }
567
568 /**
569 * Removes the specified capability from the set of capabilities of this {@code Connection}.
570 *
571 * @param capability The capability to remove from the set.
572 * @hide
573 */
574 public void removeCapability(int capability) {
575 mConnectionCapabilities &= ~capability;
576 }
577
578 /**
579 * Adds the specified capability to the set of capabilities of this {@code Connection}.
580 *
581 * @param capability The capability to add to the set.
582 * @hide
583 */
584 public void addCapability(int capability) {
585 mConnectionCapabilities |= capability;
586 }
587
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700588 /**
589 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
590 *
591 * @param capabilities A capability bit field.
592 * @return A human readable string representation.
593 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800594 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700595 return capabilitiesToStringInternal(capabilities, true /* isLong */);
596 }
597
598 /**
599 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
600 * string.
601 *
602 * @param capabilities A capability bit field.
603 * @return A human readable string representation.
604 * @hide
605 */
606 public static String capabilitiesToStringShort(int capabilities) {
607 return capabilitiesToStringInternal(capabilities, false /* isLong */);
608 }
609
610 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800611 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700612 builder.append("[");
613 if (isLong) {
614 builder.append("Capabilities:");
615 }
616
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800617 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700618 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800619 }
620 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700621 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800622 }
623 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700624 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800625 }
626 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700627 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800628 }
629 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700630 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800631 }
632 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700633 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800634 }
635 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700636 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800637 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700638 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700639 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700640 }
641 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700642 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700643 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700644 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700645 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800646 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700647 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700648 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700649 }
650 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700651 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700652 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700653 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700654 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800655 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800656 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700657 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800658 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500659 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700660 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500661 }
Rekha Kumar07366812015-03-24 16:42:31 -0700662 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700663 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700664 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700665 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700666 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700667 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700668 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700669 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700670 }
Bryce Lee81901682015-08-28 16:38:02 -0700671 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700672 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700673 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700674 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700675 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700676 }
Bryce Lee81901682015-08-28 16:38:02 -0700677
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800678 builder.append("]");
679 return builder.toString();
680 }
681
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700682 /**
683 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
684 *
685 * @param properties A property bit field.
686 * @return A human readable string representation.
687 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700688 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700689 return propertiesToStringInternal(properties, true /* isLong */);
690 }
691
692 /**
693 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
694 *
695 * @param properties A property bit field.
696 * @return A human readable string representation.
697 * @hide
698 */
699 public static String propertiesToStringShort(int properties) {
700 return propertiesToStringInternal(properties, false /* isLong */);
701 }
702
703 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700704 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700705 builder.append("[");
706 if (isLong) {
707 builder.append("Properties:");
708 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700709
Tyler Gunnf5035432017-01-09 09:43:12 -0800710 if (can(properties, PROPERTY_SELF_MANAGED)) {
711 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
712 }
713
Hall Liu25c7c4d2016-08-30 13:41:02 -0700714 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
715 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700716 }
717
718 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700719 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700720 }
721
722 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700723 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700724 }
725
726 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700727 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700728 }
729
730 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700731 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700732 }
733
Brad Ebinger15847072016-05-18 11:08:36 -0700734 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700735 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700736 }
737
Tyler Gunn720c6642016-03-22 09:02:47 -0700738 builder.append("]");
739 return builder.toString();
740 }
741
Sailesh Nepal091768c2014-06-30 15:15:23 -0700742 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700743 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700744 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700745 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700746 public void onCallerDisplayNameChanged(
747 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700748 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700749 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700750 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800751 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700752 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700753 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800754 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700755 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800756 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700757 public void onVideoProviderChanged(
758 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700759 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
760 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800761 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700762 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700763 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700764 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800765 public void onConferenceParticipantsChanged(Connection c,
766 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800767 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700768 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700769 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700770 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700771 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700772 /** @hide */
773 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Tyler Gunnf5035432017-01-09 09:43:12 -0800774 public void onAudioRouteChanged(Connection c, int audioRoute) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800775 public void onRttInitiationSuccess(Connection c) {}
776 public void onRttInitiationFailure(Connection c, int reason) {}
777 public void onRttSessionRemotelyTerminated(Connection c) {}
778 public void onRemoteRttRequest(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700779 }
780
Tyler Gunnb702ef82015-05-29 11:51:53 -0700781 /**
Hall Liu95d55872017-01-25 17:12:49 -0800782 * Provides methods to read and write RTT data to/from the in-call app.
783 * @hide
784 */
Hall Liuffa4a812017-03-02 16:11:00 -0800785 @TestApi
Hall Liu95d55872017-01-25 17:12:49 -0800786 public static final class RttTextStream {
787 private static final int READ_BUFFER_SIZE = 1000;
788 private final InputStreamReader mPipeFromInCall;
789 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800790 private final ParcelFileDescriptor mFdFromInCall;
791 private final ParcelFileDescriptor mFdToInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800792 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
793
794 /**
795 * @hide
796 */
797 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800798 mFdFromInCall = fromInCall;
799 mFdToInCall = toInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800800 mPipeFromInCall = new InputStreamReader(
801 new ParcelFileDescriptor.AutoCloseInputStream(fromInCall));
802 mPipeToInCall = new OutputStreamWriter(
803 new ParcelFileDescriptor.AutoCloseOutputStream(toInCall));
804 }
805
806 /**
807 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
808 * RTT transmits text in real-time, this method should be called as often as text snippets
809 * are received from the remote user, even if it is only one character.
810 *
811 * This method is not thread-safe -- calling it from multiple threads simultaneously may
812 * lead to interleaved text.
813 * @param input The message to send to the in-call app.
814 */
815 public void write(String input) throws IOException {
816 mPipeToInCall.write(input);
817 mPipeToInCall.flush();
818 }
819
820
821 /**
822 * Reads a string from the in-call app, blocking if there is no data available. Returns
823 * {@code null} if the RTT conversation has been terminated and there is no further data
824 * to read.
825 *
826 * This method is not thread-safe -- calling it from multiple threads simultaneously may
827 * lead to interleaved text.
828 * @return A string containing text entered by the user, or {@code null} if the
829 * conversation has been terminated or if there was an error while reading.
830 */
Hall Liuffa4a812017-03-02 16:11:00 -0800831 public String read() throws IOException {
832 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
833 if (numRead < 0) {
834 return null;
835 }
836 return new String(mReadBuffer, 0, numRead);
837 }
838
839 /**
840 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
841 * be read.
842 * @return A string containing text entered by the user, or {@code null} if the user has
843 * not entered any new text yet.
844 */
845 public String readImmediately() throws IOException {
846 if (mPipeFromInCall.ready()) {
847 return read();
848 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800849 return null;
850 }
851 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800852
853 /** @hide */
854 public ParcelFileDescriptor getFdFromInCall() {
855 return mFdFromInCall;
856 }
857
858 /** @hide */
859 public ParcelFileDescriptor getFdToInCall() {
860 return mFdToInCall;
861 }
862 }
863
864 /**
865 * Provides constants to represent the results of responses to session modify requests sent via
866 * {@link Call#sendRttRequest()}
867 */
868 public static final class RttModifyStatus {
869 /**
870 * Session modify request was successful.
871 */
872 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
873
874 /**
875 * Session modify request failed.
876 */
877 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
878
879 /**
880 * Session modify request ignored due to invalid parameters.
881 */
882 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
883
884 /**
885 * Session modify request timed out.
886 */
887 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
888
889 /**
890 * Session modify request rejected by remote user.
891 */
892 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -0800893 }
894
895 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700896 * Provides a means of controlling the video session associated with a {@link Connection}.
897 * <p>
898 * Implementations create a custom subclass of {@link VideoProvider} and the
899 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
900 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
901 * should set the {@link VideoProvider}.
902 * <p>
903 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
904 * {@link InCallService} implementations to issue requests related to the video session;
905 * it provides a means for the {@link ConnectionService} to report events and information
906 * related to the video session to Telecom and the {@link InCallService} implementations.
907 * <p>
908 * {@link InCallService} implementations interact with the {@link VideoProvider} via
909 * {@link android.telecom.InCallService.VideoCall}.
910 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700911 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700912 /**
913 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700914 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700915 */
916 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700917
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700918 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700919 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
920 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700921 */
922 public static final int SESSION_EVENT_RX_RESUME = 2;
923
924 /**
925 * Video transmission has begun. This occurs after a negotiated start of video transmission
926 * when the underlying protocol has actually begun transmitting video to the remote party.
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_TX_START = 3;
930
931 /**
932 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
933 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700934 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700935 */
936 public static final int SESSION_EVENT_TX_STOP = 4;
937
938 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800939 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -0700940 * this as a cue to inform the user the camera is not available.
941 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700942 */
943 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
944
945 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700946 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800947 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -0700948 * the camera has become available again.
949 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700950 */
951 public static final int SESSION_EVENT_CAMERA_READY = 6;
952
953 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800954 * Session event raised by Telecom when
955 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
956 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
957 * @see #handleCallSessionEvent(int)
958 */
959 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
960
961 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700962 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700963 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700964 */
965 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
966
967 /**
968 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700969 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700970 */
971 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
972
973 /**
974 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700975 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700976 */
977 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
978
Rekha Kumar07366812015-03-24 16:42:31 -0700979 /**
980 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700981 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700982 */
983 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
984
985 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700986 * Session modify request rejected by remote user.
987 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700988 */
989 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
990
Tyler Gunn75958422015-04-15 14:23:42 -0700991 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700992 private static final int MSG_SET_CAMERA = 2;
993 private static final int MSG_SET_PREVIEW_SURFACE = 3;
994 private static final int MSG_SET_DISPLAY_SURFACE = 4;
995 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
996 private static final int MSG_SET_ZOOM = 6;
997 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
998 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
999 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001000 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001001 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001002 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001003
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001004 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1005 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1006 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1007 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1008 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1009 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001010 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1011 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001012 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1013
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001014 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001015 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001016
1017 /**
1018 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001019 *
1020 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1021 * load factor before resizing, 1 means we only expect a single thread to
1022 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001023 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001024 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1025 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001026
1027 /**
1028 * Default handler used to consolidate binder method calls onto a single thread.
1029 */
1030 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001031 public VideoProviderHandler() {
1032 super();
1033 }
1034
1035 public VideoProviderHandler(Looper looper) {
1036 super(looper);
1037 }
1038
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001039 @Override
1040 public void handleMessage(Message msg) {
1041 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001042 case MSG_ADD_VIDEO_CALLBACK: {
1043 IBinder binder = (IBinder) msg.obj;
1044 IVideoCallback callback = IVideoCallback.Stub
1045 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001046 if (callback == null) {
1047 Log.w(this, "addVideoProvider - skipped; callback is null.");
1048 break;
1049 }
1050
Tyler Gunn75958422015-04-15 14:23:42 -07001051 if (mVideoCallbacks.containsKey(binder)) {
1052 Log.i(this, "addVideoProvider - skipped; already present.");
1053 break;
1054 }
1055 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001056 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001057 }
1058 case MSG_REMOVE_VIDEO_CALLBACK: {
1059 IBinder binder = (IBinder) msg.obj;
1060 IVideoCallback callback = IVideoCallback.Stub
1061 .asInterface((IBinder) msg.obj);
1062 if (!mVideoCallbacks.containsKey(binder)) {
1063 Log.i(this, "removeVideoProvider - skipped; not present.");
1064 break;
1065 }
1066 mVideoCallbacks.remove(binder);
1067 break;
1068 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001069 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001070 {
1071 SomeArgs args = (SomeArgs) msg.obj;
1072 try {
1073 onSetCamera((String) args.arg1);
1074 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001075 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001076 } finally {
1077 args.recycle();
1078 }
1079 }
1080 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001081 case MSG_SET_PREVIEW_SURFACE:
1082 onSetPreviewSurface((Surface) msg.obj);
1083 break;
1084 case MSG_SET_DISPLAY_SURFACE:
1085 onSetDisplaySurface((Surface) msg.obj);
1086 break;
1087 case MSG_SET_DEVICE_ORIENTATION:
1088 onSetDeviceOrientation(msg.arg1);
1089 break;
1090 case MSG_SET_ZOOM:
1091 onSetZoom((Float) msg.obj);
1092 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001093 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1094 SomeArgs args = (SomeArgs) msg.obj;
1095 try {
1096 onSendSessionModifyRequest((VideoProfile) args.arg1,
1097 (VideoProfile) args.arg2);
1098 } finally {
1099 args.recycle();
1100 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001101 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001102 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001103 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1104 onSendSessionModifyResponse((VideoProfile) msg.obj);
1105 break;
1106 case MSG_REQUEST_CAMERA_CAPABILITIES:
1107 onRequestCameraCapabilities();
1108 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001109 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1110 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001111 break;
1112 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001113 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001114 break;
1115 default:
1116 break;
1117 }
1118 }
1119 }
1120
1121 /**
1122 * IVideoProvider stub implementation.
1123 */
1124 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001125 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001126 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001127 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1128 }
1129
1130 public void removeVideoCallback(IBinder videoCallbackBinder) {
1131 mMessageHandler.obtainMessage(
1132 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001133 }
1134
Tyler Gunn159f35c2017-03-02 09:28:37 -08001135 public void setCamera(String cameraId, String callingPackageName,
1136 int targetSdkVersion) {
1137
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001138 SomeArgs args = SomeArgs.obtain();
1139 args.arg1 = cameraId;
1140 // Propagate the calling package; originally determined in
1141 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1142 // process.
1143 args.arg2 = callingPackageName;
1144 // Pass along the uid and pid of the calling app; this gets lost when we put the
1145 // message onto the handler. These are required for Telecom to perform a permission
1146 // check to see if the calling app is able to use the camera.
1147 args.argi1 = Binder.getCallingUid();
1148 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001149 // Pass along the target SDK version of the calling InCallService. This is used to
1150 // maintain backwards compatibility of the API for older callers.
1151 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001152 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001153 }
1154
1155 public void setPreviewSurface(Surface surface) {
1156 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1157 }
1158
1159 public void setDisplaySurface(Surface surface) {
1160 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1161 }
1162
1163 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001164 mMessageHandler.obtainMessage(
1165 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001166 }
1167
1168 public void setZoom(float value) {
1169 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1170 }
1171
Tyler Gunn45382162015-05-06 08:52:27 -07001172 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1173 SomeArgs args = SomeArgs.obtain();
1174 args.arg1 = fromProfile;
1175 args.arg2 = toProfile;
1176 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001177 }
1178
1179 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1180 mMessageHandler.obtainMessage(
1181 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1182 }
1183
1184 public void requestCameraCapabilities() {
1185 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1186 }
1187
1188 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001189 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001190 }
1191
Yorke Lee32f24732015-05-12 16:18:03 -07001192 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001193 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1194 }
1195 }
1196
1197 public VideoProvider() {
1198 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001199 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001200 }
1201
1202 /**
1203 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1204 *
1205 * @param looper The looper.
1206 * @hide
1207 */
1208 public VideoProvider(Looper looper) {
1209 mBinder = new VideoProvider.VideoProviderBinder();
1210 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001211 }
1212
1213 /**
1214 * Returns binder object which can be used across IPC methods.
1215 * @hide
1216 */
1217 public final IVideoProvider getInterface() {
1218 return mBinder;
1219 }
1220
1221 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001222 * Sets the camera to be used for the outgoing video.
1223 * <p>
1224 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1225 * camera via
1226 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1227 * <p>
1228 * Sent from the {@link InCallService} via
1229 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001230 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001231 * @param cameraId The id of the camera (use ids as reported by
1232 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001233 */
1234 public abstract void onSetCamera(String cameraId);
1235
1236 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001237 * Sets the camera to be used for the outgoing video.
1238 * <p>
1239 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1240 * camera via
1241 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1242 * <p>
1243 * This prototype is used internally to ensure that the calling package name, UID and PID
1244 * are sent to Telecom so that can perform a camera permission check on the caller.
1245 * <p>
1246 * Sent from the {@link InCallService} via
1247 * {@link InCallService.VideoCall#setCamera(String)}.
1248 *
1249 * @param cameraId The id of the camera (use ids as reported by
1250 * {@link CameraManager#getCameraIdList()}).
1251 * @param callingPackageName The AppOpps package name of the caller.
1252 * @param callingUid The UID of the caller.
1253 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001254 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001255 * @hide
1256 */
1257 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001258 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001259
1260 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001261 * Sets the surface to be used for displaying a preview of what the user's camera is
1262 * currently capturing. When video transmission is enabled, this is the video signal which
1263 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001264 * <p>
1265 * Sent from the {@link InCallService} via
1266 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001267 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001268 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001269 */
1270 public abstract void onSetPreviewSurface(Surface surface);
1271
1272 /**
1273 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001274 * <p>
1275 * Sent from the {@link InCallService} via
1276 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001277 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001278 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001279 */
1280 public abstract void onSetDisplaySurface(Surface surface);
1281
1282 /**
1283 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1284 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001285 * <p>
1286 * Sent from the {@link InCallService} via
1287 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001288 *
1289 * @param rotation The device orientation, in degrees.
1290 */
1291 public abstract void onSetDeviceOrientation(int rotation);
1292
1293 /**
1294 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001295 * <p>
1296 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001297 *
1298 * @param value The camera zoom ratio.
1299 */
1300 public abstract void onSetZoom(float value);
1301
1302 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001303 * Issues a request to modify the properties of the current video session.
1304 * <p>
1305 * Example scenarios include: requesting an audio-only call to be upgraded to a
1306 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1307 * when the {@link InCallService} is no longer the foreground application.
1308 * <p>
1309 * If the {@link VideoProvider} determines a request to be invalid, it should call
1310 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1311 * invalid request back to the {@link InCallService}.
1312 * <p>
1313 * Where a request requires confirmation from the user of the peer device, the
1314 * {@link VideoProvider} must communicate the request to the peer device and handle the
1315 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1316 * is used to inform the {@link InCallService} of the result of the request.
1317 * <p>
1318 * Sent from the {@link InCallService} via
1319 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001320 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001321 * @param fromProfile The video profile prior to the request.
1322 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001323 */
Tyler Gunn45382162015-05-06 08:52:27 -07001324 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1325 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001326
Tyler Gunnb702ef82015-05-29 11:51:53 -07001327 /**
1328 * Provides a response to a request to change the current video session properties.
1329 * <p>
1330 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1331 * video call, could decline the request and keep the call as audio-only.
1332 * In such a scenario, the {@code responseProfile} would have a video state of
1333 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1334 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1335 * <p>
1336 * Sent from the {@link InCallService} via
1337 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1338 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1339 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001340 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001341 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001342 */
1343 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1344
1345 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001346 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1347 * <p>
1348 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1349 * camera via
1350 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1351 * <p>
1352 * Sent from the {@link InCallService} via
1353 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001354 */
1355 public abstract void onRequestCameraCapabilities();
1356
1357 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001358 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1359 * video component of the current {@link Connection}.
1360 * <p>
1361 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1362 * via {@link VideoProvider#setCallDataUsage(long)}.
1363 * <p>
1364 * Sent from the {@link InCallService} via
1365 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001366 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001367 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001368
1369 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001370 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1371 * the peer device when the video signal is paused.
1372 * <p>
1373 * Sent from the {@link InCallService} via
1374 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001375 *
1376 * @param uri URI of image to display.
1377 */
Yorke Lee32f24732015-05-12 16:18:03 -07001378 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001379
1380 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001381 * Used to inform listening {@link InCallService} implementations when the
1382 * {@link VideoProvider} receives a session modification request.
1383 * <p>
1384 * Received by the {@link InCallService} via
1385 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001386 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001387 * @param videoProfile The requested video profile.
1388 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001389 */
1390 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001391 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001392 for (IVideoCallback callback : mVideoCallbacks.values()) {
1393 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001394 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001395 } catch (RemoteException ignored) {
1396 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001397 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001398 }
1399 }
1400 }
1401
1402 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001403 * Used to inform listening {@link InCallService} implementations when the
1404 * {@link VideoProvider} receives a response to a session modification request.
1405 * <p>
1406 * Received by the {@link InCallService} via
1407 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1408 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001409 *
1410 * @param status Status of the session modify request. Valid values are
1411 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1412 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001413 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1414 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1415 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1416 * @param requestedProfile The original request which was sent to the peer device.
1417 * @param responseProfile The actual profile changes agreed to by the peer device.
1418 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001419 */
1420 public void receiveSessionModifyResponse(int status,
1421 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001422 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001423 for (IVideoCallback callback : mVideoCallbacks.values()) {
1424 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001425 callback.receiveSessionModifyResponse(status, requestedProfile,
1426 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001427 } catch (RemoteException ignored) {
1428 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001429 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001430 }
1431 }
1432 }
1433
1434 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001435 * Used to inform listening {@link InCallService} implementations when the
1436 * {@link VideoProvider} reports a call session event.
1437 * <p>
1438 * Received by the {@link InCallService} via
1439 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001440 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001441 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1442 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1443 * {@link VideoProvider#SESSION_EVENT_TX_START},
1444 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1445 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001446 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1447 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001448 */
1449 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001450 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001451 for (IVideoCallback callback : mVideoCallbacks.values()) {
1452 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001453 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001454 } catch (RemoteException ignored) {
1455 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001456 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001457 }
1458 }
1459 }
1460
1461 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001462 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1463 * peer's video have changed.
1464 * <p>
1465 * This could occur if, for example, the peer rotates their device, changing the aspect
1466 * ratio of the video, or if the user switches between the back and front cameras.
1467 * <p>
1468 * Received by the {@link InCallService} via
1469 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001470 *
1471 * @param width The updated peer video width.
1472 * @param height The updated peer video height.
1473 */
1474 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001475 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001476 for (IVideoCallback callback : mVideoCallbacks.values()) {
1477 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001478 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001479 } catch (RemoteException ignored) {
1480 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001481 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001482 }
1483 }
1484 }
1485
1486 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001487 * Used to inform listening {@link InCallService} implementations when the data usage of the
1488 * video associated with the current {@link Connection} has changed.
1489 * <p>
1490 * This could be in response to a preview request via
1491 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001492 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1493 * 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 -07001494 * <p>
1495 * Received by the {@link InCallService} via
1496 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001497 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001498 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1499 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001500 */
Yorke Lee32f24732015-05-12 16:18:03 -07001501 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001502 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001503 for (IVideoCallback callback : mVideoCallbacks.values()) {
1504 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001505 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001506 } catch (RemoteException ignored) {
1507 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001508 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001509 }
1510 }
1511 }
1512
1513 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001514 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001515 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001516 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001517 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1518 * @hide
1519 */
1520 public void changeCallDataUsage(long dataUsage) {
1521 setCallDataUsage(dataUsage);
1522 }
1523
1524 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001525 * Used to inform listening {@link InCallService} implementations when the capabilities of
1526 * the current camera have changed.
1527 * <p>
1528 * The {@link VideoProvider} should call this in response to
1529 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1530 * changed via {@link VideoProvider#onSetCamera(String)}.
1531 * <p>
1532 * Received by the {@link InCallService} via
1533 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1534 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001535 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001536 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001537 */
Yorke Lee400470f2015-05-12 13:31:25 -07001538 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001539 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001540 for (IVideoCallback callback : mVideoCallbacks.values()) {
1541 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001542 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001543 } catch (RemoteException ignored) {
1544 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001545 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001546 }
1547 }
1548 }
Rekha Kumar07366812015-03-24 16:42:31 -07001549
1550 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001551 * Used to inform listening {@link InCallService} implementations when the video quality
1552 * of the call has changed.
1553 * <p>
1554 * Received by the {@link InCallService} via
1555 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001556 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001557 * @param videoQuality The updated video quality. Valid values:
1558 * {@link VideoProfile#QUALITY_HIGH},
1559 * {@link VideoProfile#QUALITY_MEDIUM},
1560 * {@link VideoProfile#QUALITY_LOW},
1561 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001562 */
1563 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001564 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001565 for (IVideoCallback callback : mVideoCallbacks.values()) {
1566 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001567 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001568 } catch (RemoteException ignored) {
1569 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001570 }
Rekha Kumar07366812015-03-24 16:42:31 -07001571 }
1572 }
1573 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001574
1575 /**
1576 * Returns a string representation of a call session event.
1577 *
1578 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1579 * @return String representation of the call session event.
1580 * @hide
1581 */
1582 public static String sessionEventToString(int event) {
1583 switch (event) {
1584 case SESSION_EVENT_CAMERA_FAILURE:
1585 return SESSION_EVENT_CAMERA_FAILURE_STR;
1586 case SESSION_EVENT_CAMERA_READY:
1587 return SESSION_EVENT_CAMERA_READY_STR;
1588 case SESSION_EVENT_RX_PAUSE:
1589 return SESSION_EVENT_RX_PAUSE_STR;
1590 case SESSION_EVENT_RX_RESUME:
1591 return SESSION_EVENT_RX_RESUME_STR;
1592 case SESSION_EVENT_TX_START:
1593 return SESSION_EVENT_TX_START_STR;
1594 case SESSION_EVENT_TX_STOP:
1595 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001596 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1597 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001598 default:
1599 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1600 }
1601 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001602 }
1603
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001604 private final Listener mConnectionDeathListener = new Listener() {
1605 @Override
1606 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001607 if (mConferenceables.remove(c)) {
1608 fireOnConferenceableConnectionsChanged();
1609 }
1610 }
1611 };
1612
1613 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1614 @Override
1615 public void onDestroyed(Conference c) {
1616 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001617 fireOnConferenceableConnectionsChanged();
1618 }
1619 }
1620 };
1621
Jay Shrauner229e3822014-08-15 09:23:07 -07001622 /**
1623 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1624 * load factor before resizing, 1 means we only expect a single thread to
1625 * access the map so make only a single shard
1626 */
1627 private final Set<Listener> mListeners = Collections.newSetFromMap(
1628 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001629 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1630 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001631 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001632
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001633 // The internal telecom call ID associated with this connection.
1634 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001635 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001636 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001637 private Uri mAddress;
1638 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001639 private String mCallerDisplayName;
1640 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001641 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001642 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001643 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001644 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001645 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001646 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001647 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001648 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001649 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001650 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001651 private Conference mConference;
1652 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001653 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001654 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001655
1656 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001657 * Tracks the key set for the extras bundle provided on the last invocation of
1658 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1659 * keys which were set previously but are no longer present in the replacement Bundle.
1660 */
1661 private Set<String> mPreviousExtraKeys;
1662
1663 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001664 * Create a new Connection.
1665 */
Santos Cordonf2951102014-07-20 19:06:29 -07001666 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001667
1668 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001669 * Returns the Telecom internal call ID associated with this connection. Should only be used
1670 * for debugging and tracing purposes.
1671 *
1672 * @return The Telecom call ID.
1673 * @hide
1674 */
1675 public final String getTelecomCallId() {
1676 return mTelecomCallId;
1677 }
1678
1679 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001680 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001681 */
Andrew Lee100e2932014-09-08 15:34:24 -07001682 public final Uri getAddress() {
1683 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001684 }
1685
1686 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001687 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001688 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001689 */
Andrew Lee100e2932014-09-08 15:34:24 -07001690 public final int getAddressPresentation() {
1691 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001692 }
1693
1694 /**
1695 * @return The caller display name (CNAP).
1696 */
1697 public final String getCallerDisplayName() {
1698 return mCallerDisplayName;
1699 }
1700
1701 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001702 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001703 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001704 */
1705 public final int getCallerDisplayNamePresentation() {
1706 return mCallerDisplayNamePresentation;
1707 }
1708
1709 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001710 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001711 */
1712 public final int getState() {
1713 return mState;
1714 }
1715
1716 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001717 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001718 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1719 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1720 * {@link VideoProfile#STATE_TX_ENABLED},
1721 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001722 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001723 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001724 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001725 */
1726 public final int getVideoState() {
1727 return mVideoState;
1728 }
1729
1730 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001731 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001732 * being routed by the system. This is {@code null} if this Connection
1733 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001734 * @deprecated Use {@link #getCallAudioState()} instead.
1735 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001736 */
Yorke Lee4af59352015-05-13 14:14:54 -07001737 @SystemApi
1738 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001739 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001740 if (mCallAudioState == null) {
1741 return null;
1742 }
Yorke Lee4af59352015-05-13 14:14:54 -07001743 return new AudioState(mCallAudioState);
1744 }
1745
1746 /**
1747 * @return The audio state of the connection, describing how its audio is currently
1748 * being routed by the system. This is {@code null} if this Connection
1749 * does not directly know about its audio state.
1750 */
1751 public final CallAudioState getCallAudioState() {
1752 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001753 }
1754
1755 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001756 * @return The conference that this connection is a part of. Null if it is not part of any
1757 * conference.
1758 */
1759 public final Conference getConference() {
1760 return mConference;
1761 }
1762
1763 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001764 * Returns whether this connection is requesting that the system play a ringback tone
1765 * on its behalf.
1766 */
Andrew Lee100e2932014-09-08 15:34:24 -07001767 public final boolean isRingbackRequested() {
1768 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001769 }
1770
1771 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001772 * @return True if the connection's audio mode is VOIP.
1773 */
1774 public final boolean getAudioModeIsVoip() {
1775 return mAudioModeIsVoip;
1776 }
1777
1778 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001779 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1780 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1781 * start time of the conference.
1782 *
1783 * @return The time at which the {@code Connnection} was connected.
1784 *
1785 * @hide
1786 */
1787 public final long getConnectTimeMillis() {
1788 return mConnectTimeMillis;
1789 }
1790
1791 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001792 * @return The status hints for this connection.
1793 */
1794 public final StatusHints getStatusHints() {
1795 return mStatusHints;
1796 }
1797
1798 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001799 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001800 * <p>
1801 * Extras should be updated using {@link #putExtras(Bundle)}.
1802 * <p>
1803 * Telecom or an {@link InCallService} can also update the extras via
1804 * {@link android.telecom.Call#putExtras(Bundle)}, and
1805 * {@link Call#removeExtras(List)}.
1806 * <p>
1807 * The connection is notified of changes to the extras made by Telecom or an
1808 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001809 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001810 * @return The extras associated with this connection.
1811 */
1812 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001813 Bundle extras = null;
1814 synchronized (mExtrasLock) {
1815 if (mExtras != null) {
1816 extras = new Bundle(mExtras);
1817 }
1818 }
1819 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001820 }
1821
1822 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001823 * Assign a listener to be notified of state changes.
1824 *
1825 * @param l A listener.
1826 * @return This Connection.
1827 *
1828 * @hide
1829 */
1830 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001831 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001832 return this;
1833 }
1834
1835 /**
1836 * Remove a previously assigned listener that was being notified of state changes.
1837 *
1838 * @param l A Listener.
1839 * @return This Connection.
1840 *
1841 * @hide
1842 */
1843 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001844 if (l != null) {
1845 mListeners.remove(l);
1846 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001847 return this;
1848 }
1849
1850 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001851 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001852 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001853 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001854 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001855 }
1856
1857 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001858 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1859 * ONLY for debugging purposes.
1860 *
1861 * @param callId The telecom call ID.
1862 * @hide
1863 */
1864 public void setTelecomCallId(String callId) {
1865 mTelecomCallId = callId;
1866 }
1867
1868 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001869 * Inform this Connection that the state of its audio output has been changed externally.
1870 *
1871 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001872 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001873 */
Yorke Lee4af59352015-05-13 14:14:54 -07001874 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001875 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001876 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001877 mCallAudioState = state;
1878 onAudioStateChanged(getAudioState());
1879 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001880 }
1881
1882 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001883 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001884 * @return A string representation of the value.
1885 */
1886 public static String stateToString(int state) {
1887 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001888 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001889 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001890 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001891 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001892 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001893 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001894 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001895 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001896 case STATE_PULLING_CALL:
1897 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001898 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001899 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001900 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001901 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001902 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001903 return "DISCONNECTED";
1904 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001905 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001906 return "UNKNOWN";
1907 }
1908 }
1909
1910 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001911 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001912 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001913 public final int getConnectionCapabilities() {
1914 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001915 }
1916
1917 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001918 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1919 */
1920 public final int getConnectionProperties() {
1921 return mConnectionProperties;
1922 }
1923
1924 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001925 * Returns the connection's supported audio routes.
1926 *
1927 * @hide
1928 */
1929 public final int getSupportedAudioRoutes() {
1930 return mSupportedAudioRoutes;
1931 }
1932
1933 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001934 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001935 *
Andrew Lee100e2932014-09-08 15:34:24 -07001936 * @param address The new address.
1937 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001938 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001939 */
Andrew Lee100e2932014-09-08 15:34:24 -07001940 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001941 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001942 Log.d(this, "setAddress %s", address);
1943 mAddress = address;
1944 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001945 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001946 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001947 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001948 }
1949
1950 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001951 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001952 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001953 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001954 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001955 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001956 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001957 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001958 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001959 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001960 mCallerDisplayName = callerDisplayName;
1961 mCallerDisplayNamePresentation = presentation;
1962 for (Listener l : mListeners) {
1963 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1964 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001965 }
1966
1967 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001968 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001969 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1970 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1971 * {@link VideoProfile#STATE_TX_ENABLED},
1972 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001973 *
1974 * @param videoState The new video state.
1975 */
1976 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001977 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001978 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001979 mVideoState = videoState;
1980 for (Listener l : mListeners) {
1981 l.onVideoStateChanged(this, mVideoState);
1982 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001983 }
1984
1985 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001986 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001987 * communicate).
1988 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001989 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001990 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001991 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001992 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001993 }
1994
1995 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001996 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001997 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001998 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001999 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002000 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002001 }
2002
2003 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002004 * Sets state to initializing (this Connection is not yet ready to be used).
2005 */
2006 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002007 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002008 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002009 }
2010
2011 /**
2012 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2013 */
2014 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002015 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002016 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002017 }
2018
2019 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002020 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002021 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002022 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002023 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002024 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002025 }
2026
2027 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002028 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2029 * device). Only applicable for {@link Connection}s with
2030 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2031 */
2032 public final void setPulling() {
2033 checkImmutable();
2034 setState(STATE_PULLING_CALL);
2035 }
2036
2037 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002038 * Sets state to be on hold.
2039 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002040 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002041 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002042 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002043 }
2044
2045 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002046 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002047 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002048 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002049 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002050 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002051 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002052 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002053 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002054 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002055 }
2056
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002057 public final VideoProvider getVideoProvider() {
2058 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002059 }
2060
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002061 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002062 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002063 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002064 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002065 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002066 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002067 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002068 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002069 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002070 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002071 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002072 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002073 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002074 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002075 }
2076
2077 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002078 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2079 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2080 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2081 * to send an {@link #onPostDialContinue(boolean)} signal.
2082 *
2083 * @param remaining The DTMF character sequence remaining to be emitted once the
2084 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2085 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002086 */
2087 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002088 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002089 for (Listener l : mListeners) {
2090 l.onPostDialWait(this, remaining);
2091 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002092 }
2093
2094 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002095 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2096 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002097 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002098 *
2099 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002100 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002101 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002102 checkImmutable();
2103 for (Listener l : mListeners) {
2104 l.onPostDialChar(this, nextChar);
2105 }
2106 }
2107
2108 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002109 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002110 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002111 *
2112 * @param ringback Whether the ringback tone is to be played.
2113 */
Andrew Lee100e2932014-09-08 15:34:24 -07002114 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002115 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002116 if (mRingbackRequested != ringback) {
2117 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002118 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002119 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002120 }
2121 }
Ihab Awadf8358972014-05-28 16:46:42 -07002122 }
2123
2124 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002125 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002126 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002127 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002128 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002129 public final void setConnectionCapabilities(int connectionCapabilities) {
2130 checkImmutable();
2131 if (mConnectionCapabilities != connectionCapabilities) {
2132 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002133 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002134 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002135 }
2136 }
Santos Cordonb6939982014-06-04 20:20:58 -07002137 }
2138
2139 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002140 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2141 *
2142 * @param connectionProperties The new connection properties.
2143 */
2144 public final void setConnectionProperties(int connectionProperties) {
2145 checkImmutable();
2146 if (mConnectionProperties != connectionProperties) {
2147 mConnectionProperties = connectionProperties;
2148 for (Listener l : mListeners) {
2149 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2150 }
2151 }
2152 }
2153
2154 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002155 * Sets the supported audio routes.
2156 *
2157 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2158 * See {@link CallAudioState}
2159 * @hide
2160 */
2161 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2162 if ((supportedAudioRoutes
2163 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2164 throw new IllegalArgumentException(
2165 "supported audio routes must include either speaker or earpiece");
2166 }
2167
2168 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2169 mSupportedAudioRoutes = supportedAudioRoutes;
2170 for (Listener l : mListeners) {
2171 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2172 }
2173 }
2174 }
2175
2176 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002177 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002178 */
Evan Charlton36a71342014-07-19 16:31:02 -07002179 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002180 for (Listener l : mListeners) {
2181 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002182 }
Santos Cordonb6939982014-06-04 20:20:58 -07002183 }
2184
2185 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002186 * Requests that the framework use VOIP audio mode for this connection.
2187 *
2188 * @param isVoip True if the audio mode is VOIP.
2189 */
2190 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002191 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002192 mAudioModeIsVoip = isVoip;
2193 for (Listener l : mListeners) {
2194 l.onAudioModeIsVoipChanged(this, isVoip);
2195 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002196 }
2197
2198 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002199 * Sets the time at which a call became active on this Connection. This is set only
2200 * when a conference call becomes active on this connection.
2201 *
2202 * @param connectionTimeMillis The connection time, in milliseconds.
2203 *
2204 * @hide
2205 */
2206 public final void setConnectTimeMillis(long connectTimeMillis) {
2207 mConnectTimeMillis = connectTimeMillis;
2208 }
2209
2210 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002211 * Sets the label and icon status to display in the in-call UI.
2212 *
2213 * @param statusHints The status label and icon to set.
2214 */
2215 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002216 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002217 mStatusHints = statusHints;
2218 for (Listener l : mListeners) {
2219 l.onStatusHintsChanged(this, statusHints);
2220 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002221 }
2222
2223 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002224 * Sets the connections with which this connection can be conferenced.
2225 *
2226 * @param conferenceableConnections The set of connections this connection can conference with.
2227 */
2228 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002229 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002230 clearConferenceableList();
2231 for (Connection c : conferenceableConnections) {
2232 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2233 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002234 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002235 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002236 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002237 }
2238 }
2239 fireOnConferenceableConnectionsChanged();
2240 }
2241
2242 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002243 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2244 * or conferences with which this connection can be conferenced.
2245 *
2246 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002247 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002248 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002249 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002250 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002251 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2252 // small amount of items here.
2253 if (!mConferenceables.contains(c)) {
2254 if (c instanceof Connection) {
2255 Connection connection = (Connection) c;
2256 connection.addConnectionListener(mConnectionDeathListener);
2257 } else if (c instanceof Conference) {
2258 Conference conference = (Conference) c;
2259 conference.addListener(mConferenceDeathListener);
2260 }
2261 mConferenceables.add(c);
2262 }
2263 }
2264 fireOnConferenceableConnectionsChanged();
2265 }
2266
2267 /**
2268 * Returns the connections or conferences with which this connection can be conferenced.
2269 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002270 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002271 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002272 }
2273
Yorke Lee53463962015-08-04 16:07:19 -07002274 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002275 * @hide
2276 */
2277 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002278 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002279 if (mConnectionService != null) {
2280 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2281 "which is already associated with another ConnectionService.");
2282 } else {
2283 mConnectionService = connectionService;
2284 }
2285 }
2286
2287 /**
2288 * @hide
2289 */
2290 public final void unsetConnectionService(ConnectionService connectionService) {
2291 if (mConnectionService != connectionService) {
2292 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2293 "that does not belong to the ConnectionService.");
2294 } else {
2295 mConnectionService = null;
2296 }
2297 }
2298
2299 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002300 * @hide
2301 */
2302 public final ConnectionService getConnectionService() {
2303 return mConnectionService;
2304 }
2305
2306 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002307 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002308 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002309 *
2310 * @param conference The conference.
2311 * @return {@code true} if the conference was successfully set.
2312 * @hide
2313 */
2314 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002315 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002316 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002317 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002318 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002319 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2320 fireConferenceChanged();
2321 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002322 return true;
2323 }
2324 return false;
2325 }
2326
2327 /**
2328 * Resets the conference that this connection is a part of.
2329 * @hide
2330 */
2331 public final void resetConference() {
2332 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002333 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002334 mConference = null;
2335 fireConferenceChanged();
2336 }
2337 }
2338
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002339 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002340 * Set some extras that can be associated with this {@code Connection}.
2341 * <p>
2342 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2343 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2344 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002345 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2346 * {@link #removeExtras(String...)} methods to modify the extras.
2347 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002348 * 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 -07002349 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2350 *
2351 * @param extras The extras associated with this {@code Connection}.
2352 */
2353 public final void setExtras(@Nullable Bundle extras) {
2354 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002355
2356 // Add/replace any new or changed extras values.
2357 putExtras(extras);
2358
2359 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2360 // the current one and remove any keys that went away.
2361 if (mPreviousExtraKeys != null) {
2362 List<String> toRemove = new ArrayList<String>();
2363 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002364 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002365 toRemove.add(oldKey);
2366 }
2367 }
2368 if (!toRemove.isEmpty()) {
2369 removeExtras(toRemove);
2370 }
2371 }
2372
2373 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2374 // called we can see if the caller has removed any extras values.
2375 if (mPreviousExtraKeys == null) {
2376 mPreviousExtraKeys = new ArraySet<String>();
2377 }
2378 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002379 if (extras != null) {
2380 mPreviousExtraKeys.addAll(extras.keySet());
2381 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002382 }
2383
2384 /**
2385 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2386 * added.
2387 * <p>
2388 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2389 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2390 *
2391 * @param extras The extras to add.
2392 */
2393 public final void putExtras(@NonNull Bundle extras) {
2394 checkImmutable();
2395 if (extras == null) {
2396 return;
2397 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002398 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2399 // the listeners.
2400 Bundle listenerExtras;
2401 synchronized (mExtrasLock) {
2402 if (mExtras == null) {
2403 mExtras = new Bundle();
2404 }
2405 mExtras.putAll(extras);
2406 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002407 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002408 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002409 // Create a new clone of the extras for each listener so that they don't clobber
2410 // each other
2411 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002412 }
2413 }
2414
2415 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002416 * Adds a boolean extra to this {@code Connection}.
2417 *
2418 * @param key The extra key.
2419 * @param value The value.
2420 * @hide
2421 */
2422 public final void putExtra(String key, boolean value) {
2423 Bundle newExtras = new Bundle();
2424 newExtras.putBoolean(key, value);
2425 putExtras(newExtras);
2426 }
2427
2428 /**
2429 * Adds an integer 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, int value) {
2436 Bundle newExtras = new Bundle();
2437 newExtras.putInt(key, value);
2438 putExtras(newExtras);
2439 }
2440
2441 /**
2442 * Adds a string 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, String value) {
2449 Bundle newExtras = new Bundle();
2450 newExtras.putString(key, value);
2451 putExtras(newExtras);
2452 }
2453
2454 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002455 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002456 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002457 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002458 */
2459 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002460 synchronized (mExtrasLock) {
2461 if (mExtras != null) {
2462 for (String key : keys) {
2463 mExtras.remove(key);
2464 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002465 }
2466 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002467 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002468 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002469 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002470 }
2471 }
2472
2473 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002474 * Removes extras from this {@code Connection}.
2475 *
2476 * @param keys The keys of the extras to remove.
2477 */
2478 public final void removeExtras(String ... keys) {
2479 removeExtras(Arrays.asList(keys));
2480 }
2481
2482 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002483 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2484 * be change to the {@link #getCallAudioState()}.
2485 * <p>
2486 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2487 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2488 * <p>
2489 * See also {@link InCallService#setAudioRoute(int)}.
2490 *
2491 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2492 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2493 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2494 */
2495 public final void setAudioRoute(int route) {
2496 for (Listener l : mListeners) {
2497 l.onAudioRouteChanged(this, route);
2498 }
2499 }
2500
2501 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002502 * Informs listeners that a previously requested RTT session via
2503 * {@link ConnectionRequest#isRequestingRtt()} or
2504 * {@link #onStartRtt(ParcelFileDescriptor, ParcelFileDescriptor)} has succeeded.
2505 * @hide
2506 */
Hall Liuffa4a812017-03-02 16:11:00 -08002507 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002508 public final void sendRttInitiationSuccess() {
Hall Liuffa4a812017-03-02 16:11:00 -08002509 setRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08002510 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2511 }
2512
2513 /**
2514 * Informs listeners that a previously requested RTT session via
2515 * {@link ConnectionRequest#isRequestingRtt()} or
2516 * {@link #onStartRtt(ParcelFileDescriptor, ParcelFileDescriptor)}
2517 * has failed.
2518 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2519 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
2520 * @hide
2521 */
Hall Liuffa4a812017-03-02 16:11:00 -08002522 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002523 public final void sendRttInitiationFailure(int reason) {
Hall Liuffa4a812017-03-02 16:11:00 -08002524 unsetRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08002525 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2526 }
2527
2528 /**
2529 * Informs listeners that a currently active RTT session has been terminated by the remote
2530 * side of the coll.
2531 * @hide
2532 */
Hall Liuffa4a812017-03-02 16:11:00 -08002533 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002534 public final void sendRttSessionRemotelyTerminated() {
2535 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2536 }
2537
2538 /**
2539 * Informs listeners that the remote side of the call has requested an upgrade to include an
2540 * RTT session in the call.
2541 * @hide
2542 */
Hall Liuffa4a812017-03-02 16:11:00 -08002543 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002544 public final void sendRemoteRttRequest() {
2545 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2546 }
2547
2548 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002549 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002550 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002551 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002552 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2553 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002554 */
Yorke Lee4af59352015-05-13 14:14:54 -07002555 @SystemApi
2556 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002557 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002558
2559 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002560 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2561 *
2562 * @param state The new connection audio state.
2563 */
2564 public void onCallAudioStateChanged(CallAudioState state) {}
2565
2566 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002567 * Notifies this Connection of an internal state change. This method is called after the
2568 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002569 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002570 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002571 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002572 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002573
2574 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002575 * Notifies this Connection of a request to play a DTMF tone.
2576 *
2577 * @param c A DTMF character.
2578 */
Santos Cordonf2951102014-07-20 19:06:29 -07002579 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002580
2581 /**
2582 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2583 */
Santos Cordonf2951102014-07-20 19:06:29 -07002584 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002585
2586 /**
2587 * Notifies this Connection of a request to disconnect.
2588 */
Santos Cordonf2951102014-07-20 19:06:29 -07002589 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002590
2591 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002592 * Notifies this Connection of a request to disconnect a participant of the conference managed
2593 * by the connection.
2594 *
2595 * @param endpoint the {@link Uri} of the participant to disconnect.
2596 * @hide
2597 */
2598 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2599
2600 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002601 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002602 */
Santos Cordonf2951102014-07-20 19:06:29 -07002603 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002604
2605 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002606 * Notifies this Connection of a request to abort.
2607 */
Santos Cordonf2951102014-07-20 19:06:29 -07002608 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002609
2610 /**
2611 * Notifies this Connection of a request to hold.
2612 */
Santos Cordonf2951102014-07-20 19:06:29 -07002613 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002614
2615 /**
2616 * Notifies this Connection of a request to exit a hold state.
2617 */
Santos Cordonf2951102014-07-20 19:06:29 -07002618 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002619
2620 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002621 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002622 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002623 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002624 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002625 */
Santos Cordonf2951102014-07-20 19:06:29 -07002626 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002627
2628 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002629 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002630 * a request to accept.
2631 */
2632 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002633 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002634 }
2635
2636 /**
2637 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002638 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002639 */
Santos Cordonf2951102014-07-20 19:06:29 -07002640 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002641
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002642 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002643 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2644 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002645 */
2646 public void onReject(String replyMessage) {}
2647
2648 /**
Bryce Leecac50772015-11-17 15:13:29 -08002649 * Notifies the Connection of a request to silence the ringer.
2650 *
2651 * @hide
2652 */
2653 public void onSilence() {}
2654
2655 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002656 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2657 */
Santos Cordonf2951102014-07-20 19:06:29 -07002658 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002659
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002660 /**
2661 * Notifies this Connection of a request to pull an external call to the local device.
2662 * <p>
2663 * The {@link InCallService} issues a request to pull an external call to the local device via
2664 * {@link Call#pullExternalCall()}.
2665 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002666 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2667 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002668 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002669 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002670 */
2671 public void onPullExternalCall() {}
2672
2673 /**
2674 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2675 * <p>
2676 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2677 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002678 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2679 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2680 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2681 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2682 * not aware of.
2683 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002684 * See also {@link Call#sendCallEvent(String, Bundle)}.
2685 *
2686 * @param event The call event.
2687 * @param extras Extras associated with the call event.
2688 */
2689 public void onCallEvent(String event, Bundle extras) {}
2690
Tyler Gunndee56a82016-03-23 16:06:34 -07002691 /**
2692 * Notifies this {@link Connection} of a change to the extras made outside the
2693 * {@link ConnectionService}.
2694 * <p>
2695 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2696 * the {@link android.telecom.Call#putExtras(Bundle)} and
2697 * {@link Call#removeExtras(List)}.
2698 *
2699 * @param extras The new extras bundle.
2700 */
2701 public void onExtrasChanged(Bundle extras) {}
2702
Tyler Gunnf5035432017-01-09 09:43:12 -08002703 /**
2704 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2705 * displaying its incoming call user interface for the {@link Connection}.
2706 * <p>
2707 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2708 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2709 * should show its own incoming call user interface.
2710 * <p>
2711 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
2712 * regular {@link ConnectionService}, the Telecom framework will display its own incoming call
2713 * user interface to allow the user to choose whether to answer the new incoming call and
2714 * disconnect other ongoing calls, or to reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002715 * <p>
2716 * You should trigger the display of the incoming call user interface for your application by
2717 * showing a {@link Notification} with a full-screen {@link Intent} specified.
2718 * For example:
2719 * <pre><code>
2720 * // Create an intent which triggers your fullscreen incoming call user interface.
2721 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
2722 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
2723 * intent.setClass(context, YourIncomingCallActivity.class);
2724 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
2725 *
2726 * // Build the notification as an ongoing high priority item; this ensures it will show as
2727 * // a heads up notification which slides down over top of the current content.
2728 * final Notification.Builder builder = new Notification.Builder(context);
2729 * builder.setOngoing(true);
2730 * builder.setPriority(Notification.PRIORITY_HIGH);
2731 *
2732 * // Set notification content intent to take user to fullscreen UI if user taps on the
2733 * // notification body.
2734 * builder.setContentIntent(pendingIntent);
2735 * // Set full screen intent to trigger display of the fullscreen UI when the notification
2736 * // manager deems it appropriate.
2737 * builder.setFullScreenIntent(pendingIntent, true);
2738 *
2739 * // Setup notification content.
2740 * builder.setSmallIcon( yourIconResourceId );
2741 * builder.setContentTitle("Your notification title");
2742 * builder.setContentText("Your notification content.");
2743 *
2744 * // Use builder.addAction(..) to add buttons to answer or reject the call.
2745 *
2746 * NotificationManager notificationManager = mContext.getSystemService(
2747 * NotificationManager.class);
2748 * notificationManager.notify(YOUR_TAG, YOUR_ID, builder.build());
2749 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08002750 */
2751 public void onShowIncomingCallUi() {}
2752
Hall Liub64ac4c2017-02-06 10:49:48 -08002753 /**
2754 * Notifies this {@link Connection} that the user has requested an RTT session.
2755 * The connection service should call {@link #sendRttInitiationSuccess} or
2756 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
2757 * request, respectively.
2758 * @param rttTextStream The object that should be used to send text to or receive text from
2759 * the in-call app.
2760 * @hide
2761 */
Hall Liuffa4a812017-03-02 16:11:00 -08002762 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002763 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
2764
2765 /**
2766 * Notifies this {@link Connection} that it should terminate any existing RTT communication
2767 * channel. No response to Telecom is needed for this method.
2768 * @hide
2769 */
Hall Liuffa4a812017-03-02 16:11:00 -08002770 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002771 public void onStopRtt() {}
2772
2773 /**
2774 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
2775 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
2776 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
2777 * indicated by {@code rttTextStream} being {@code null}
2778 * @hide
2779 * @param rttTextStream The object that should be used to send text to or receive text from
2780 * the in-call app.
2781 */
Hall Liuffa4a812017-03-02 16:11:00 -08002782 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002783 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
2784
Hall Liuffa4a812017-03-02 16:11:00 -08002785 /**
2786 * Internal method to set {@link #PROPERTY_IS_RTT}.
2787 * @hide
2788 */
2789 void setRttProperty() {
2790 setConnectionProperties(getConnectionProperties() | PROPERTY_IS_RTT);
2791 }
2792
2793 /**
2794 * Internal method to un-set {@link #PROPERTY_IS_RTT}.
2795 * @hide
2796 */
2797 void unsetRttProperty() {
2798 setConnectionProperties(getConnectionProperties() & (~PROPERTY_IS_RTT));
2799 }
2800
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002801 static String toLogSafePhoneNumber(String number) {
2802 // For unknown number, log empty string.
2803 if (number == null) {
2804 return "";
2805 }
2806
2807 if (PII_DEBUG) {
2808 // When PII_DEBUG is true we emit PII.
2809 return number;
2810 }
2811
2812 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2813 // sanitized phone numbers.
2814 StringBuilder builder = new StringBuilder();
2815 for (int i = 0; i < number.length(); i++) {
2816 char c = number.charAt(i);
2817 if (c == '-' || c == '@' || c == '.') {
2818 builder.append(c);
2819 } else {
2820 builder.append('x');
2821 }
2822 }
2823 return builder.toString();
2824 }
2825
Ihab Awad542e0ea2014-05-16 10:22:16 -07002826 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002827 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002828 if (mState == STATE_DISCONNECTED && mState != state) {
2829 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002830 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002831 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002832 if (mState != state) {
2833 Log.d(this, "setState: %s", stateToString(state));
2834 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002835 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002836 for (Listener l : mListeners) {
2837 l.onStateChanged(this, state);
2838 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002839 }
2840 }
2841
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002842 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002843 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002844 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2845 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002846 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002847 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002848
2849 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002850 if (mImmutable) {
2851 throw new UnsupportedOperationException("Connection is immutable");
2852 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002853 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002854 }
2855
Evan Charltonbf11f982014-07-20 22:06:28 -07002856 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002857 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002858 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2859 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002860 * <p>
2861 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2862 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002863 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002864 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002865 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002866 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002867 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2868 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002869 }
2870
Evan Charltonbf11f982014-07-20 22:06:28 -07002871 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002872 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2873 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2874 * this should never be un-@hide-den.
2875 *
2876 * @hide
2877 */
2878 public void checkImmutable() {}
2879
2880 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002881 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2882 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2883 * that state. This connection should not be used for anything, and no other
2884 * {@code Connection}s should be attempted.
2885 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002886 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002887 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002888 * @return A {@code Connection} which indicates that the underlying connection should
2889 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002890 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002891 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002892 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002893 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002894
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002895 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002896 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002897 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002898 }
2899 }
2900
Santos Cordon823fd3c2014-08-07 18:35:18 -07002901 private final void fireConferenceChanged() {
2902 for (Listener l : mListeners) {
2903 l.onConferenceChanged(this, mConference);
2904 }
2905 }
2906
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002907 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002908 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002909 if (c instanceof Connection) {
2910 Connection connection = (Connection) c;
2911 connection.removeConnectionListener(mConnectionDeathListener);
2912 } else if (c instanceof Conference) {
2913 Conference conference = (Conference) c;
2914 conference.removeListener(mConferenceDeathListener);
2915 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002916 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002917 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002918 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002919
2920 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002921 * Handles a change to extras received from Telecom.
2922 *
2923 * @param extras The new extras.
2924 * @hide
2925 */
2926 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002927 Bundle b = null;
2928 synchronized (mExtrasLock) {
2929 mExtras = extras;
2930 if (mExtras != null) {
2931 b = new Bundle(mExtras);
2932 }
2933 }
2934 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07002935 }
2936
2937 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002938 * Notifies listeners that the merge request failed.
2939 *
2940 * @hide
2941 */
2942 protected final void notifyConferenceMergeFailed() {
2943 for (Listener l : mListeners) {
2944 l.onConferenceMergeFailed(this);
2945 }
2946 }
2947
2948 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002949 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002950 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002951 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002952 * @hide
2953 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002954 protected final void updateConferenceParticipants(
2955 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002956 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002957 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002958 }
2959 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002960
2961 /**
2962 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002963 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002964 */
2965 protected void notifyConferenceStarted() {
2966 for (Listener l : mListeners) {
2967 l.onConferenceStarted();
2968 }
2969 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002970
2971 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07002972 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
2973 * be a part of a conference call.
2974 * @param isConferenceSupported {@code true} if the connection supports being part of a
2975 * conference call, {@code false} otherwise.
2976 * @hide
2977 */
2978 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
2979 for (Listener l : mListeners) {
2980 l.onConferenceSupportedChanged(this, isConferenceSupported);
2981 }
2982 }
2983
2984 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002985 * Sends an event associated with this {@code Connection} with associated event extras to the
2986 * {@link InCallService}.
2987 * <p>
2988 * Connection events are used to communicate point in time information from a
2989 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
2990 * custom connection event includes notifying the UI when a WIFI call has been handed over to
2991 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
2992 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
2993 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
2994 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
2995 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
2996 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
2997 * <p>
2998 * Events are exposed to {@link InCallService} implementations via
2999 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3000 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003001 * 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 -07003002 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3003 * some events altogether.
3004 * <p>
3005 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3006 * conflicts between {@link ConnectionService} implementations. Further, custom
3007 * {@link ConnectionService} implementations shall not re-purpose events in the
3008 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3009 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3010 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3011 * {@code com.example.extra.MY_EXTRA}).
3012 * <p>
3013 * When defining events and the associated extras, it is important to keep their behavior
3014 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3015 * events/extras should me maintained to ensure backwards compatibility with older
3016 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003017 *
3018 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003019 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003020 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003021 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003022 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003023 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003024 }
3025 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003026}