blob: 3c32614815cb851e3c0eff65c94da4b341094a4f [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
Tyler Gunndee56a82016-03-23 16:06:34 -070023import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070024import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070025import android.annotation.SystemApi;
Tyler Gunn159f35c2017-03-02 09:28:37 -080026import android.app.Notification;
Hall Liua98f58b52017-11-07 17:59:28 -080027import android.bluetooth.BluetoothDevice;
Tyler Gunn159f35c2017-03-02 09:28:37 -080028import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070029import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070030import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080031import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070032import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070033import android.os.Handler;
34import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070035import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070036import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080037import android.os.ParcelFileDescriptor;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070038import android.os.RemoteException;
Tyler Gunn3fa819c2017-08-04 09:27:26 -070039import android.os.SystemClock;
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;
Santos Cordonb6939982014-06-04 20:20:58 -070046import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070047import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070048import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070049import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070050import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070051import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070052
53/**
Santos Cordon895d4b82015-06-25 16:41:48 -070054 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
55 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070056 * <p>
57 * Implementations create a custom subclass of {@code Connection} and return it to the framework
58 * as the return value of
59 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
60 * or
61 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
62 * Implementations are then responsible for updating the state of the {@code Connection}, and
63 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
64 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070065 * <p>
66 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
67 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
68 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
69 * {@code Connection} instance.
70 * <p>
71 * Basic call support requires overriding the following methods: {@link #onAnswer()},
72 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
73 * <p>
74 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
75 * {@link #onUnhold()} methods should be overridden to provide hold support for the
76 * {@code Connection}.
77 * <p>
78 * Where a {@code Connection} supports a variation of video calling (e.g. the
79 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
80 * to support answering a call as a video call.
81 * <p>
82 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
83 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
84 * support for pulling the external call.
85 * <p>
86 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
87 * overridden.
88 * <p>
89 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
90 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
91 * for example, call events from a {@link InCallService} are handled,
92 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
93 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
94 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
95 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -070096 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070097public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070098
Santos Cordon895d4b82015-06-25 16:41:48 -070099 /**
100 * The connection is initializing. This is generally the first state for a {@code Connection}
101 * returned by a {@link ConnectionService}.
102 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700103 public static final int STATE_INITIALIZING = 0;
104
Santos Cordon895d4b82015-06-25 16:41:48 -0700105 /**
106 * The connection is new and not connected.
107 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700108 public static final int STATE_NEW = 1;
109
Santos Cordon895d4b82015-06-25 16:41:48 -0700110 /**
111 * An incoming connection is in the ringing state. During this state, the user's ringer or
112 * vibration feature will be activated.
113 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700114 public static final int STATE_RINGING = 2;
115
Santos Cordon895d4b82015-06-25 16:41:48 -0700116 /**
117 * An outgoing connection is in the dialing state. In this state the other party has not yet
118 * answered the call and the user traditionally hears a ringback tone.
119 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700120 public static final int STATE_DIALING = 3;
121
Santos Cordon895d4b82015-06-25 16:41:48 -0700122 /**
123 * A connection is active. Both parties are connected to the call and can actively communicate.
124 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700125 public static final int STATE_ACTIVE = 4;
126
Santos Cordon895d4b82015-06-25 16:41:48 -0700127 /**
128 * A connection is on hold.
129 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700130 public static final int STATE_HOLDING = 5;
131
Santos Cordon895d4b82015-06-25 16:41:48 -0700132 /**
133 * A connection has been disconnected. This is the final state once the user has been
134 * disconnected from a call either locally, remotely or by an error in the service.
135 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700136 public static final int STATE_DISCONNECTED = 6;
137
Santos Cordon895d4b82015-06-25 16:41:48 -0700138 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700139 * The state of an external connection which is in the process of being pulled from a remote
140 * device to the local device.
141 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700142 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700143 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
144 */
145 public static final int STATE_PULLING_CALL = 7;
146
147 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700148 * Connection can currently be put on hold or unheld. This is distinct from
149 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
150 * it does not at the moment support the function. This can be true while the call is in the
151 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
152 * display a disabled 'hold' button.
153 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800154 public static final int CAPABILITY_HOLD = 0x00000001;
155
156 /** Connection supports the hold feature. */
157 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
158
159 /**
160 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
161 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
162 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
163 * capability allows a merge button to be shown while the conference is in the foreground
164 * of the in-call UI.
165 * <p>
166 * This is only intended for use by a {@link Conference}.
167 */
168 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
169
170 /**
171 * Connections within a conference can be swapped between foreground and background.
172 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
173 * <p>
174 * This is only intended for use by a {@link Conference}.
175 */
176 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
177
178 /**
179 * @hide
180 */
181 public static final int CAPABILITY_UNUSED = 0x00000010;
182
183 /** Connection supports responding via text option. */
184 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
185
186 /** Connection can be muted. */
187 public static final int CAPABILITY_MUTE = 0x00000040;
188
189 /**
190 * Connection supports conference management. This capability only applies to
191 * {@link Conference}s which can have {@link Connection}s as children.
192 */
193 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
194
195 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700196 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800197 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700198 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800199
200 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700201 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800202 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700203 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800204
205 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700206 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800207 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700208 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700209 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800210
211 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700212 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800213 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700214 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
215
216 /**
217 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700218 */
219 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
220
221 /**
222 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700223 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700224 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700225 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800226
227 /**
228 * Connection is able to be separated from its parent {@code Conference}, if any.
229 */
230 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
231
232 /**
233 * Connection is able to be individually disconnected when in a {@code Conference}.
234 */
235 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
236
237 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700238 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800239 * @hide
240 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700241 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800242
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700243 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700244 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700245 * @hide
246 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700247 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700248
249 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700250 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700251 * @hide
252 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700253 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700254
Tyler Gunn068085b2015-02-06 13:56:52 -0800255 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700256 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800257 * @hide
258 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700259 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800260
Tyler Gunn96d6c402015-03-18 12:39:23 -0700261 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500262 * Speed up audio setup for MT call.
263 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700264 */
265 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800266
Rekha Kumar07366812015-03-24 16:42:31 -0700267 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700268 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700269 */
270 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
271
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700272 /**
273 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700274 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700275 */
276 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
277
Tyler Gunnd4091732015-06-29 09:15:37 -0700278 /**
279 * For a conference, indicates the conference will not have child connections.
280 * <p>
281 * An example of a conference with child connections is a GSM conference call, where the radio
282 * retains connections to the individual participants of the conference. Another example is an
283 * IMS conference call where conference event package functionality is supported; in this case
284 * the conference server ensures the radio is aware of the participants in the conference, which
285 * are represented by child connections.
286 * <p>
287 * An example of a conference with no child connections is an IMS conference call with no
288 * conference event package support. Such a conference is represented by the radio as a single
289 * connection to the IMS conference server.
290 * <p>
291 * Indicating whether a conference has children or not is important to help user interfaces
292 * visually represent a conference. A conference with no children, for example, will have the
293 * conference connection shown in the list of calls on a Bluetooth device, where if the
294 * conference has children, only the children will be shown in the list of calls on a Bluetooth
295 * device.
296 * @hide
297 */
298 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
299
Bryce Lee81901682015-08-28 16:38:02 -0700300 /**
301 * Indicates that the connection itself wants to handle any sort of reply response, rather than
302 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700303 */
304 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
305
Tyler Gunnf97a0092016-01-19 15:59:34 -0800306 /**
307 * When set, prevents a video call from being downgraded to an audio-only call.
308 * <p>
309 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
310 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
311 * downgraded from a video call back to a VideoState of
312 * {@link VideoProfile#STATE_AUDIO_ONLY}.
313 * <p>
314 * Intuitively, a call which can be downgraded to audio should also have local and remote
315 * video
316 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
317 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
318 */
319 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
320
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700321 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700322 * When set for an external connection, indicates that this {@code Connection} can be pulled
323 * from a remote device to the current device.
324 * <p>
325 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
326 * is set.
327 */
328 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
329
330 //**********************************************************************************************
331 // Next CAPABILITY value: 0x02000000
332 //**********************************************************************************************
333
334 /**
335 * Indicates that the current device callback number should be shown.
336 *
337 * @hide
338 */
Hall Liu25c7c4d2016-08-30 13:41:02 -0700339 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700340
341 /**
342 * Whether the call is a generic conference, where we do not know the precise state of
343 * participants in the conference (eg. on CDMA).
344 *
345 * @hide
346 */
347 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
348
349 /**
350 * Connection is using high definition audio.
351 * @hide
352 */
353 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
354
355 /**
356 * Connection is using WIFI.
357 * @hide
358 */
359 public static final int PROPERTY_WIFI = 1<<3;
360
361 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700362 * When set, indicates that the {@code Connection} does not actually exist locally for the
363 * {@link ConnectionService}.
364 * <p>
365 * Consider, for example, a scenario where a user has two devices with the same phone number.
366 * When a user places a call on one devices, the telephony stack can represent that call on the
367 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700368 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700369 * <p>
370 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
371 * external connections. Only those {@link InCallService}s which have the
372 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
373 * manifest will see external connections.
374 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700375 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700376
Brad Ebinger15847072016-05-18 11:08:36 -0700377 /**
378 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
379 */
380 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700381
Hall Liu9f332c72016-07-14 15:37:37 -0700382 /**
383 * Indicates that the connection represents a downgraded IMS conference.
384 * @hide
385 */
386 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
387
Tyler Gunnf5035432017-01-09 09:43:12 -0800388 /**
389 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
390 * {@link ConnectionService}.
391 * <p>
392 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
393 */
394 public static final int PROPERTY_SELF_MANAGED = 1<<7;
395
Hall Liu95d55872017-01-25 17:12:49 -0800396 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800397 * Set by the framework to indicate that a connection has an active RTT session associated with
398 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800399 */
400 public static final int PROPERTY_IS_RTT = 1 << 8;
401
Tyler Gunn96d6c402015-03-18 12:39:23 -0700402 //**********************************************************************************************
Hall Liu95d55872017-01-25 17:12:49 -0800403 // Next PROPERTY value: 1<<9
Tyler Gunn96d6c402015-03-18 12:39:23 -0700404 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800405
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700406 /**
407 * Connection extra key used to store the last forwarded number associated with the current
408 * connection. Used to communicate to the user interface that the connection was forwarded via
409 * the specified number.
410 */
411 public static final String EXTRA_LAST_FORWARDED_NUMBER =
412 "android.telecom.extra.LAST_FORWARDED_NUMBER";
413
414 /**
415 * Connection extra key used to store a child number associated with the current connection.
416 * Used to communicate to the user interface that the connection was received via
417 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
418 * address.
419 */
420 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
421
422 /**
423 * Connection extra key used to store the subject for an incoming call. The user interface can
424 * query this extra and display its contents for incoming calls. Will only be used if the
425 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
426 */
427 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
428
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800429 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700430 * Boolean connection extra key set on a {@link Connection} in
431 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
432 * current active foreground call to be dropped.
433 */
434 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
435 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
436
437 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700438 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
439 * state to indicate the name of the third-party app which is responsible for the current
440 * foreground call.
441 * <p>
442 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
443 * is able to inform the user that answering the new incoming call will cause a call owned by
444 * another app to be dropped when the incoming call is answered.
445 */
446 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
447 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
448
449 /**
Hall Liu10208662016-06-15 17:55:00 -0700450 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700451 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700452 * @hide
453 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700454 public static final String EXTRA_DISABLE_ADD_CALL =
455 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700456
457 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700458 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
459 * original Connection ID associated with the connection. Used in
460 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
461 * connection/conference added via
462 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
463 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
464 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
465 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
466 * be a way to ensure that we don't add the connection again as a duplicate.
467 * <p>
468 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
469 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
470 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
471 * in a new {@link Connection} which it adds to Telecom via
472 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
473 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
474 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
475 * ID it originally referred to the connection as. Thus Telecom needs to know that the
476 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
477 * @hide
478 */
479 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
480 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
481
482 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800483 * Connection event used to inform Telecom that it should play the on hold tone. This is used
484 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700485 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800486 * @hide
487 */
488 public static final String EVENT_ON_HOLD_TONE_START =
489 "android.telecom.event.ON_HOLD_TONE_START";
490
491 /**
492 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
493 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700494 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800495 * @hide
496 */
497 public static final String EVENT_ON_HOLD_TONE_END =
498 "android.telecom.event.ON_HOLD_TONE_END";
499
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700500 /**
501 * Connection event used to inform {@link InCallService}s when pulling of an external call has
502 * failed. The user interface should inform the user of the error.
503 * <p>
504 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
505 * API is called on a {@link Call} with the properties
506 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
507 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
508 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700509 * <p>
510 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
511 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700512 */
513 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
514
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700515 /**
516 * Connection event used to inform {@link InCallService}s when the merging of two calls has
517 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700518 * <p>
519 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
520 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700521 */
522 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
523
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700524 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700525 * Connection event used to inform {@link InCallService}s when the process of merging a
526 * Connection into a conference has begun.
527 * <p>
528 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
529 * expected to be null when this connection event is used.
530 * @hide
531 */
532 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
533
534 /**
535 * Connection event used to inform {@link InCallService}s when the process of merging a
536 * Connection into a conference has completed.
537 * <p>
538 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
539 * expected to be null when this connection event is used.
540 * @hide
541 */
542 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
543
544 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700545 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
546 * the remote party.
547 * <p>
548 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
549 * call is being held locally on the device. When a capable {@link ConnectionService} receives
550 * signalling to indicate that the remote party has put the call on hold, it can send this
551 * connection event.
552 * @hide
553 */
554 public static final String EVENT_CALL_REMOTELY_HELD =
555 "android.telecom.event.CALL_REMOTELY_HELD";
556
557 /**
558 * Connection event used to inform {@link InCallService}s when a call which was remotely held
559 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
560 * <p>
561 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
562 * call is being held locally on the device. When a capable {@link ConnectionService} receives
563 * signalling to indicate that the remote party has taken the call off hold, it can send this
564 * connection event.
565 * @hide
566 */
567 public static final String EVENT_CALL_REMOTELY_UNHELD =
568 "android.telecom.event.CALL_REMOTELY_UNHELD";
569
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700570 /**
571 * Connection event used to inform an {@link InCallService} which initiated a call handover via
572 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
573 * successfully completed.
574 * @hide
575 */
576 public static final String EVENT_HANDOVER_COMPLETE =
577 "android.telecom.event.HANDOVER_COMPLETE";
578
579 /**
580 * Connection event used to inform an {@link InCallService} which initiated a call handover via
581 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
582 * to complete.
583 * @hide
584 */
585 public static final String EVENT_HANDOVER_FAILED =
586 "android.telecom.event.HANDOVER_FAILED";
587
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700588 // Flag controlling whether PII is emitted into the logs
589 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
590
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800591 /**
592 * Whether the given capabilities support the specified capability.
593 *
594 * @param capabilities A capability bit field.
595 * @param capability The capability to check capabilities for.
596 * @return Whether the specified capability is supported.
597 * @hide
598 */
599 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800600 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800601 }
602
603 /**
604 * Whether the capabilities of this {@code Connection} supports the specified capability.
605 *
606 * @param capability The capability to check capabilities for.
607 * @return Whether the specified capability is supported.
608 * @hide
609 */
610 public boolean can(int capability) {
611 return can(mConnectionCapabilities, capability);
612 }
613
614 /**
615 * Removes the specified capability from the set of capabilities of this {@code Connection}.
616 *
617 * @param capability The capability to remove from the set.
618 * @hide
619 */
620 public void removeCapability(int capability) {
621 mConnectionCapabilities &= ~capability;
622 }
623
624 /**
625 * Adds the specified capability to the set of capabilities of this {@code Connection}.
626 *
627 * @param capability The capability to add to the set.
628 * @hide
629 */
630 public void addCapability(int capability) {
631 mConnectionCapabilities |= capability;
632 }
633
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700634 /**
635 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
636 *
637 * @param capabilities A capability bit field.
638 * @return A human readable string representation.
639 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800640 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700641 return capabilitiesToStringInternal(capabilities, true /* isLong */);
642 }
643
644 /**
645 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
646 * string.
647 *
648 * @param capabilities A capability bit field.
649 * @return A human readable string representation.
650 * @hide
651 */
652 public static String capabilitiesToStringShort(int capabilities) {
653 return capabilitiesToStringInternal(capabilities, false /* isLong */);
654 }
655
656 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800657 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700658 builder.append("[");
659 if (isLong) {
660 builder.append("Capabilities:");
661 }
662
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800663 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700664 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800665 }
666 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700667 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800668 }
669 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700670 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800671 }
672 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700673 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800674 }
675 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700676 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800677 }
678 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700679 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800680 }
681 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700682 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800683 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700684 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700685 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700686 }
687 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700688 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700689 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700690 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700691 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800692 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700693 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700694 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700695 }
696 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700697 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700698 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700699 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700700 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800701 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800702 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700703 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800704 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500705 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700706 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500707 }
Rekha Kumar07366812015-03-24 16:42:31 -0700708 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700709 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700710 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700711 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700712 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700713 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700714 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700715 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700716 }
Bryce Lee81901682015-08-28 16:38:02 -0700717 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700718 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700719 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700720 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700721 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700722 }
Bryce Lee81901682015-08-28 16:38:02 -0700723
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800724 builder.append("]");
725 return builder.toString();
726 }
727
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700728 /**
729 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
730 *
731 * @param properties A property bit field.
732 * @return A human readable string representation.
733 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700734 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700735 return propertiesToStringInternal(properties, true /* isLong */);
736 }
737
738 /**
739 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
740 *
741 * @param properties A property bit field.
742 * @return A human readable string representation.
743 * @hide
744 */
745 public static String propertiesToStringShort(int properties) {
746 return propertiesToStringInternal(properties, false /* isLong */);
747 }
748
749 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700750 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700751 builder.append("[");
752 if (isLong) {
753 builder.append("Properties:");
754 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700755
Tyler Gunnf5035432017-01-09 09:43:12 -0800756 if (can(properties, PROPERTY_SELF_MANAGED)) {
757 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
758 }
759
Hall Liu25c7c4d2016-08-30 13:41:02 -0700760 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
761 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700762 }
763
764 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700765 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700766 }
767
768 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700769 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700770 }
771
772 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700773 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700774 }
775
776 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700777 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700778 }
779
Brad Ebinger15847072016-05-18 11:08:36 -0700780 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700781 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700782 }
783
Tyler Gunn720c6642016-03-22 09:02:47 -0700784 builder.append("]");
785 return builder.toString();
786 }
787
Sailesh Nepal091768c2014-06-30 15:15:23 -0700788 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700789 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700790 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700791 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700792 public void onCallerDisplayNameChanged(
793 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700794 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700795 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700796 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800797 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700798 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700799 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800800 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700801 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800802 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700803 public void onVideoProviderChanged(
804 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700805 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
806 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800807 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700808 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700809 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700810 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800811 public void onConferenceParticipantsChanged(Connection c,
812 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800813 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700814 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700815 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700816 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700817 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700818 /** @hide */
819 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Hall Liua98f58b52017-11-07 17:59:28 -0800820 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800821 public void onRttInitiationSuccess(Connection c) {}
822 public void onRttInitiationFailure(Connection c, int reason) {}
823 public void onRttSessionRemotelyTerminated(Connection c) {}
824 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530825 /** @hide */
826 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700827 }
828
Tyler Gunnb702ef82015-05-29 11:51:53 -0700829 /**
Hall Liu95d55872017-01-25 17:12:49 -0800830 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -0800831 */
832 public static final class RttTextStream {
833 private static final int READ_BUFFER_SIZE = 1000;
834 private final InputStreamReader mPipeFromInCall;
835 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800836 private final ParcelFileDescriptor mFdFromInCall;
837 private final ParcelFileDescriptor mFdToInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800838 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
839
840 /**
841 * @hide
842 */
843 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800844 mFdFromInCall = fromInCall;
845 mFdToInCall = toInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800846 mPipeFromInCall = new InputStreamReader(
847 new ParcelFileDescriptor.AutoCloseInputStream(fromInCall));
848 mPipeToInCall = new OutputStreamWriter(
849 new ParcelFileDescriptor.AutoCloseOutputStream(toInCall));
850 }
851
852 /**
853 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
854 * RTT transmits text in real-time, this method should be called as often as text snippets
855 * are received from the remote user, even if it is only one character.
856 *
857 * This method is not thread-safe -- calling it from multiple threads simultaneously may
858 * lead to interleaved text.
859 * @param input The message to send to the in-call app.
860 */
861 public void write(String input) throws IOException {
862 mPipeToInCall.write(input);
863 mPipeToInCall.flush();
864 }
865
866
867 /**
868 * Reads a string from the in-call app, blocking if there is no data available. Returns
869 * {@code null} if the RTT conversation has been terminated and there is no further data
870 * to read.
871 *
872 * This method is not thread-safe -- calling it from multiple threads simultaneously may
873 * lead to interleaved text.
874 * @return A string containing text entered by the user, or {@code null} if the
875 * conversation has been terminated or if there was an error while reading.
876 */
Hall Liuffa4a812017-03-02 16:11:00 -0800877 public String read() throws IOException {
878 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
879 if (numRead < 0) {
880 return null;
881 }
882 return new String(mReadBuffer, 0, numRead);
883 }
884
885 /**
886 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
887 * be read.
888 * @return A string containing text entered by the user, or {@code null} if the user has
889 * not entered any new text yet.
890 */
891 public String readImmediately() throws IOException {
892 if (mPipeFromInCall.ready()) {
893 return read();
894 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800895 return null;
896 }
897 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800898
899 /** @hide */
900 public ParcelFileDescriptor getFdFromInCall() {
901 return mFdFromInCall;
902 }
903
904 /** @hide */
905 public ParcelFileDescriptor getFdToInCall() {
906 return mFdToInCall;
907 }
908 }
909
910 /**
911 * Provides constants to represent the results of responses to session modify requests sent via
912 * {@link Call#sendRttRequest()}
913 */
914 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -0700915 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800916 /**
917 * Session modify request was successful.
918 */
919 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
920
921 /**
922 * Session modify request failed.
923 */
924 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
925
926 /**
927 * Session modify request ignored due to invalid parameters.
928 */
929 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
930
931 /**
932 * Session modify request timed out.
933 */
934 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
935
936 /**
937 * Session modify request rejected by remote user.
938 */
939 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -0800940 }
941
942 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700943 * Provides a means of controlling the video session associated with a {@link Connection}.
944 * <p>
945 * Implementations create a custom subclass of {@link VideoProvider} and the
946 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
947 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
948 * should set the {@link VideoProvider}.
949 * <p>
950 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
951 * {@link InCallService} implementations to issue requests related to the video session;
952 * it provides a means for the {@link ConnectionService} to report events and information
953 * related to the video session to Telecom and the {@link InCallService} implementations.
954 * <p>
955 * {@link InCallService} implementations interact with the {@link VideoProvider} via
956 * {@link android.telecom.InCallService.VideoCall}.
957 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700958 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700959 /**
960 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700961 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700962 */
963 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700964
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700965 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700966 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
967 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700968 */
969 public static final int SESSION_EVENT_RX_RESUME = 2;
970
971 /**
972 * Video transmission has begun. This occurs after a negotiated start of video transmission
973 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700974 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700975 */
976 public static final int SESSION_EVENT_TX_START = 3;
977
978 /**
979 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
980 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700981 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700982 */
983 public static final int SESSION_EVENT_TX_STOP = 4;
984
985 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800986 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -0700987 * this as a cue to inform the user the camera is not available.
988 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700989 */
990 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
991
992 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700993 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800994 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -0700995 * the camera has become available again.
996 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700997 */
998 public static final int SESSION_EVENT_CAMERA_READY = 6;
999
1000 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001001 * Session event raised by Telecom when
1002 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1003 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1004 * @see #handleCallSessionEvent(int)
1005 */
1006 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1007
1008 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001009 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001010 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001011 */
1012 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1013
1014 /**
1015 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001016 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001017 */
1018 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1019
1020 /**
1021 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001022 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001023 */
1024 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1025
Rekha Kumar07366812015-03-24 16:42:31 -07001026 /**
1027 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001028 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001029 */
1030 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1031
1032 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001033 * Session modify request rejected by remote user.
1034 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001035 */
1036 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1037
Tyler Gunn75958422015-04-15 14:23:42 -07001038 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001039 private static final int MSG_SET_CAMERA = 2;
1040 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1041 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1042 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1043 private static final int MSG_SET_ZOOM = 6;
1044 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1045 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1046 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001047 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001048 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001049 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001050
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001051 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1052 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1053 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1054 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1055 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1056 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001057 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1058 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001059 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1060
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001061 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001062 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001063
1064 /**
1065 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001066 *
1067 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1068 * load factor before resizing, 1 means we only expect a single thread to
1069 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001070 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001071 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1072 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001073
1074 /**
1075 * Default handler used to consolidate binder method calls onto a single thread.
1076 */
1077 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001078 public VideoProviderHandler() {
1079 super();
1080 }
1081
1082 public VideoProviderHandler(Looper looper) {
1083 super(looper);
1084 }
1085
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001086 @Override
1087 public void handleMessage(Message msg) {
1088 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001089 case MSG_ADD_VIDEO_CALLBACK: {
1090 IBinder binder = (IBinder) msg.obj;
1091 IVideoCallback callback = IVideoCallback.Stub
1092 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001093 if (callback == null) {
1094 Log.w(this, "addVideoProvider - skipped; callback is null.");
1095 break;
1096 }
1097
Tyler Gunn75958422015-04-15 14:23:42 -07001098 if (mVideoCallbacks.containsKey(binder)) {
1099 Log.i(this, "addVideoProvider - skipped; already present.");
1100 break;
1101 }
1102 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001103 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001104 }
1105 case MSG_REMOVE_VIDEO_CALLBACK: {
1106 IBinder binder = (IBinder) msg.obj;
1107 IVideoCallback callback = IVideoCallback.Stub
1108 .asInterface((IBinder) msg.obj);
1109 if (!mVideoCallbacks.containsKey(binder)) {
1110 Log.i(this, "removeVideoProvider - skipped; not present.");
1111 break;
1112 }
1113 mVideoCallbacks.remove(binder);
1114 break;
1115 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001116 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001117 {
1118 SomeArgs args = (SomeArgs) msg.obj;
1119 try {
1120 onSetCamera((String) args.arg1);
1121 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001122 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001123 } finally {
1124 args.recycle();
1125 }
1126 }
1127 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001128 case MSG_SET_PREVIEW_SURFACE:
1129 onSetPreviewSurface((Surface) msg.obj);
1130 break;
1131 case MSG_SET_DISPLAY_SURFACE:
1132 onSetDisplaySurface((Surface) msg.obj);
1133 break;
1134 case MSG_SET_DEVICE_ORIENTATION:
1135 onSetDeviceOrientation(msg.arg1);
1136 break;
1137 case MSG_SET_ZOOM:
1138 onSetZoom((Float) msg.obj);
1139 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001140 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1141 SomeArgs args = (SomeArgs) msg.obj;
1142 try {
1143 onSendSessionModifyRequest((VideoProfile) args.arg1,
1144 (VideoProfile) args.arg2);
1145 } finally {
1146 args.recycle();
1147 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001148 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001149 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001150 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1151 onSendSessionModifyResponse((VideoProfile) msg.obj);
1152 break;
1153 case MSG_REQUEST_CAMERA_CAPABILITIES:
1154 onRequestCameraCapabilities();
1155 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001156 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1157 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001158 break;
1159 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001160 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001161 break;
1162 default:
1163 break;
1164 }
1165 }
1166 }
1167
1168 /**
1169 * IVideoProvider stub implementation.
1170 */
1171 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001172 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001173 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001174 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1175 }
1176
1177 public void removeVideoCallback(IBinder videoCallbackBinder) {
1178 mMessageHandler.obtainMessage(
1179 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001180 }
1181
Tyler Gunn159f35c2017-03-02 09:28:37 -08001182 public void setCamera(String cameraId, String callingPackageName,
1183 int targetSdkVersion) {
1184
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001185 SomeArgs args = SomeArgs.obtain();
1186 args.arg1 = cameraId;
1187 // Propagate the calling package; originally determined in
1188 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1189 // process.
1190 args.arg2 = callingPackageName;
1191 // Pass along the uid and pid of the calling app; this gets lost when we put the
1192 // message onto the handler. These are required for Telecom to perform a permission
1193 // check to see if the calling app is able to use the camera.
1194 args.argi1 = Binder.getCallingUid();
1195 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001196 // Pass along the target SDK version of the calling InCallService. This is used to
1197 // maintain backwards compatibility of the API for older callers.
1198 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001199 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001200 }
1201
1202 public void setPreviewSurface(Surface surface) {
1203 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1204 }
1205
1206 public void setDisplaySurface(Surface surface) {
1207 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1208 }
1209
1210 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001211 mMessageHandler.obtainMessage(
1212 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001213 }
1214
1215 public void setZoom(float value) {
1216 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1217 }
1218
Tyler Gunn45382162015-05-06 08:52:27 -07001219 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1220 SomeArgs args = SomeArgs.obtain();
1221 args.arg1 = fromProfile;
1222 args.arg2 = toProfile;
1223 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001224 }
1225
1226 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1227 mMessageHandler.obtainMessage(
1228 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1229 }
1230
1231 public void requestCameraCapabilities() {
1232 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1233 }
1234
1235 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001236 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001237 }
1238
Yorke Lee32f24732015-05-12 16:18:03 -07001239 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001240 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1241 }
1242 }
1243
1244 public VideoProvider() {
1245 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001246 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001247 }
1248
1249 /**
1250 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1251 *
1252 * @param looper The looper.
1253 * @hide
1254 */
1255 public VideoProvider(Looper looper) {
1256 mBinder = new VideoProvider.VideoProviderBinder();
1257 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001258 }
1259
1260 /**
1261 * Returns binder object which can be used across IPC methods.
1262 * @hide
1263 */
1264 public final IVideoProvider getInterface() {
1265 return mBinder;
1266 }
1267
1268 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001269 * Sets the camera to be used for the outgoing video.
1270 * <p>
1271 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1272 * camera via
1273 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1274 * <p>
1275 * Sent from the {@link InCallService} via
1276 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001277 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001278 * @param cameraId The id of the camera (use ids as reported by
1279 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001280 */
1281 public abstract void onSetCamera(String cameraId);
1282
1283 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001284 * Sets the camera to be used for the outgoing video.
1285 * <p>
1286 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1287 * camera via
1288 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1289 * <p>
1290 * This prototype is used internally to ensure that the calling package name, UID and PID
1291 * are sent to Telecom so that can perform a camera permission check on the caller.
1292 * <p>
1293 * Sent from the {@link InCallService} via
1294 * {@link InCallService.VideoCall#setCamera(String)}.
1295 *
1296 * @param cameraId The id of the camera (use ids as reported by
1297 * {@link CameraManager#getCameraIdList()}).
1298 * @param callingPackageName The AppOpps package name of the caller.
1299 * @param callingUid The UID of the caller.
1300 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001301 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001302 * @hide
1303 */
1304 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001305 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001306
1307 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001308 * Sets the surface to be used for displaying a preview of what the user's camera is
1309 * currently capturing. When video transmission is enabled, this is the video signal which
1310 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001311 * <p>
1312 * Sent from the {@link InCallService} via
1313 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001314 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001315 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001316 */
1317 public abstract void onSetPreviewSurface(Surface surface);
1318
1319 /**
1320 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001321 * <p>
1322 * Sent from the {@link InCallService} via
1323 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001324 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001325 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001326 */
1327 public abstract void onSetDisplaySurface(Surface surface);
1328
1329 /**
1330 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1331 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001332 * <p>
1333 * Sent from the {@link InCallService} via
1334 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001335 *
1336 * @param rotation The device orientation, in degrees.
1337 */
1338 public abstract void onSetDeviceOrientation(int rotation);
1339
1340 /**
1341 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001342 * <p>
1343 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001344 *
1345 * @param value The camera zoom ratio.
1346 */
1347 public abstract void onSetZoom(float value);
1348
1349 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001350 * Issues a request to modify the properties of the current video session.
1351 * <p>
1352 * Example scenarios include: requesting an audio-only call to be upgraded to a
1353 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1354 * when the {@link InCallService} is no longer the foreground application.
1355 * <p>
1356 * If the {@link VideoProvider} determines a request to be invalid, it should call
1357 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1358 * invalid request back to the {@link InCallService}.
1359 * <p>
1360 * Where a request requires confirmation from the user of the peer device, the
1361 * {@link VideoProvider} must communicate the request to the peer device and handle the
1362 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1363 * is used to inform the {@link InCallService} of the result of the request.
1364 * <p>
1365 * Sent from the {@link InCallService} via
1366 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001367 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001368 * @param fromProfile The video profile prior to the request.
1369 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001370 */
Tyler Gunn45382162015-05-06 08:52:27 -07001371 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1372 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001373
Tyler Gunnb702ef82015-05-29 11:51:53 -07001374 /**
1375 * Provides a response to a request to change the current video session properties.
1376 * <p>
1377 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1378 * video call, could decline the request and keep the call as audio-only.
1379 * In such a scenario, the {@code responseProfile} would have a video state of
1380 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1381 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1382 * <p>
1383 * Sent from the {@link InCallService} via
1384 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1385 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1386 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001387 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001388 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001389 */
1390 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1391
1392 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001393 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1394 * <p>
1395 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1396 * camera via
1397 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1398 * <p>
1399 * Sent from the {@link InCallService} via
1400 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001401 */
1402 public abstract void onRequestCameraCapabilities();
1403
1404 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001405 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1406 * video component of the current {@link Connection}.
1407 * <p>
1408 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1409 * via {@link VideoProvider#setCallDataUsage(long)}.
1410 * <p>
1411 * Sent from the {@link InCallService} via
1412 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001413 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001414 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001415
1416 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001417 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1418 * the peer device when the video signal is paused.
1419 * <p>
1420 * Sent from the {@link InCallService} via
1421 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001422 *
1423 * @param uri URI of image to display.
1424 */
Yorke Lee32f24732015-05-12 16:18:03 -07001425 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001426
1427 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001428 * Used to inform listening {@link InCallService} implementations when the
1429 * {@link VideoProvider} receives a session modification request.
1430 * <p>
1431 * Received by the {@link InCallService} via
1432 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001433 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001434 * @param videoProfile The requested video profile.
1435 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001436 */
1437 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001438 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001439 for (IVideoCallback callback : mVideoCallbacks.values()) {
1440 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001441 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001442 } catch (RemoteException ignored) {
1443 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001444 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001445 }
1446 }
1447 }
1448
1449 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001450 * Used to inform listening {@link InCallService} implementations when the
1451 * {@link VideoProvider} receives a response to a session modification request.
1452 * <p>
1453 * Received by the {@link InCallService} via
1454 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1455 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001456 *
1457 * @param status Status of the session modify request. Valid values are
1458 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1459 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001460 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1461 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1462 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1463 * @param requestedProfile The original request which was sent to the peer device.
1464 * @param responseProfile The actual profile changes agreed to by the peer device.
1465 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001466 */
1467 public void receiveSessionModifyResponse(int status,
1468 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001469 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001470 for (IVideoCallback callback : mVideoCallbacks.values()) {
1471 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001472 callback.receiveSessionModifyResponse(status, requestedProfile,
1473 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001474 } catch (RemoteException ignored) {
1475 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001476 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001477 }
1478 }
1479 }
1480
1481 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001482 * Used to inform listening {@link InCallService} implementations when the
1483 * {@link VideoProvider} reports a call session event.
1484 * <p>
1485 * Received by the {@link InCallService} via
1486 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001487 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001488 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1489 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1490 * {@link VideoProvider#SESSION_EVENT_TX_START},
1491 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1492 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001493 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1494 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001495 */
1496 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001497 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001498 for (IVideoCallback callback : mVideoCallbacks.values()) {
1499 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001500 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001501 } catch (RemoteException ignored) {
1502 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001503 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001504 }
1505 }
1506 }
1507
1508 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001509 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1510 * peer's video have changed.
1511 * <p>
1512 * This could occur if, for example, the peer rotates their device, changing the aspect
1513 * ratio of the video, or if the user switches between the back and front cameras.
1514 * <p>
1515 * Received by the {@link InCallService} via
1516 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001517 *
1518 * @param width The updated peer video width.
1519 * @param height The updated peer video height.
1520 */
1521 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001522 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001523 for (IVideoCallback callback : mVideoCallbacks.values()) {
1524 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001525 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001526 } catch (RemoteException ignored) {
1527 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001528 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001529 }
1530 }
1531 }
1532
1533 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001534 * Used to inform listening {@link InCallService} implementations when the data usage of the
1535 * video associated with the current {@link Connection} has changed.
1536 * <p>
1537 * This could be in response to a preview request via
1538 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001539 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1540 * 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 -07001541 * <p>
1542 * Received by the {@link InCallService} via
1543 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001544 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001545 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1546 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001547 */
Yorke Lee32f24732015-05-12 16:18:03 -07001548 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001549 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001550 for (IVideoCallback callback : mVideoCallbacks.values()) {
1551 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001552 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001553 } catch (RemoteException ignored) {
1554 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001555 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001556 }
1557 }
1558 }
1559
1560 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001561 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001562 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001563 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001564 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1565 * @hide
1566 */
1567 public void changeCallDataUsage(long dataUsage) {
1568 setCallDataUsage(dataUsage);
1569 }
1570
1571 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001572 * Used to inform listening {@link InCallService} implementations when the capabilities of
1573 * the current camera have changed.
1574 * <p>
1575 * The {@link VideoProvider} should call this in response to
1576 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1577 * changed via {@link VideoProvider#onSetCamera(String)}.
1578 * <p>
1579 * Received by the {@link InCallService} via
1580 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1581 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001582 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001583 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001584 */
Yorke Lee400470f2015-05-12 13:31:25 -07001585 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001586 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001587 for (IVideoCallback callback : mVideoCallbacks.values()) {
1588 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001589 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001590 } catch (RemoteException ignored) {
1591 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001592 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001593 }
1594 }
1595 }
Rekha Kumar07366812015-03-24 16:42:31 -07001596
1597 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001598 * Used to inform listening {@link InCallService} implementations when the video quality
1599 * of the call has changed.
1600 * <p>
1601 * Received by the {@link InCallService} via
1602 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001603 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001604 * @param videoQuality The updated video quality. Valid values:
1605 * {@link VideoProfile#QUALITY_HIGH},
1606 * {@link VideoProfile#QUALITY_MEDIUM},
1607 * {@link VideoProfile#QUALITY_LOW},
1608 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001609 */
1610 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001611 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001612 for (IVideoCallback callback : mVideoCallbacks.values()) {
1613 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001614 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001615 } catch (RemoteException ignored) {
1616 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001617 }
Rekha Kumar07366812015-03-24 16:42:31 -07001618 }
1619 }
1620 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001621
1622 /**
1623 * Returns a string representation of a call session event.
1624 *
1625 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1626 * @return String representation of the call session event.
1627 * @hide
1628 */
1629 public static String sessionEventToString(int event) {
1630 switch (event) {
1631 case SESSION_EVENT_CAMERA_FAILURE:
1632 return SESSION_EVENT_CAMERA_FAILURE_STR;
1633 case SESSION_EVENT_CAMERA_READY:
1634 return SESSION_EVENT_CAMERA_READY_STR;
1635 case SESSION_EVENT_RX_PAUSE:
1636 return SESSION_EVENT_RX_PAUSE_STR;
1637 case SESSION_EVENT_RX_RESUME:
1638 return SESSION_EVENT_RX_RESUME_STR;
1639 case SESSION_EVENT_TX_START:
1640 return SESSION_EVENT_TX_START_STR;
1641 case SESSION_EVENT_TX_STOP:
1642 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001643 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1644 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001645 default:
1646 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1647 }
1648 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001649 }
1650
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001651 private final Listener mConnectionDeathListener = new Listener() {
1652 @Override
1653 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001654 if (mConferenceables.remove(c)) {
1655 fireOnConferenceableConnectionsChanged();
1656 }
1657 }
1658 };
1659
1660 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1661 @Override
1662 public void onDestroyed(Conference c) {
1663 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001664 fireOnConferenceableConnectionsChanged();
1665 }
1666 }
1667 };
1668
Jay Shrauner229e3822014-08-15 09:23:07 -07001669 /**
1670 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1671 * load factor before resizing, 1 means we only expect a single thread to
1672 * access the map so make only a single shard
1673 */
1674 private final Set<Listener> mListeners = Collections.newSetFromMap(
1675 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001676 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1677 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001678 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001679
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001680 // The internal telecom call ID associated with this connection.
1681 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07001682 // The PhoneAccountHandle associated with this connection.
1683 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001684 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001685 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001686 private Uri mAddress;
1687 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001688 private String mCallerDisplayName;
1689 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001690 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001691 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001692 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001693 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001694 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001695 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001696 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001697 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001698 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001699 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001700 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001701 private Conference mConference;
1702 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001703 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001704 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001705
1706 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001707 * Tracks the key set for the extras bundle provided on the last invocation of
1708 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1709 * keys which were set previously but are no longer present in the replacement Bundle.
1710 */
1711 private Set<String> mPreviousExtraKeys;
1712
1713 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001714 * Create a new Connection.
1715 */
Santos Cordonf2951102014-07-20 19:06:29 -07001716 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001717
1718 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001719 * Returns the Telecom internal call ID associated with this connection. Should only be used
1720 * for debugging and tracing purposes.
1721 *
1722 * @return The Telecom call ID.
1723 * @hide
1724 */
1725 public final String getTelecomCallId() {
1726 return mTelecomCallId;
1727 }
1728
1729 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001730 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001731 */
Andrew Lee100e2932014-09-08 15:34:24 -07001732 public final Uri getAddress() {
1733 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001734 }
1735
1736 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001737 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001738 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001739 */
Andrew Lee100e2932014-09-08 15:34:24 -07001740 public final int getAddressPresentation() {
1741 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001742 }
1743
1744 /**
1745 * @return The caller display name (CNAP).
1746 */
1747 public final String getCallerDisplayName() {
1748 return mCallerDisplayName;
1749 }
1750
1751 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001752 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001753 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001754 */
1755 public final int getCallerDisplayNamePresentation() {
1756 return mCallerDisplayNamePresentation;
1757 }
1758
1759 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001760 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001761 */
1762 public final int getState() {
1763 return mState;
1764 }
1765
1766 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001767 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001768 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1769 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1770 * {@link VideoProfile#STATE_TX_ENABLED},
1771 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001772 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001773 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001774 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001775 */
1776 public final int getVideoState() {
1777 return mVideoState;
1778 }
1779
1780 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001781 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001782 * being routed by the system. This is {@code null} if this Connection
1783 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001784 * @deprecated Use {@link #getCallAudioState()} instead.
1785 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001786 */
Yorke Lee4af59352015-05-13 14:14:54 -07001787 @SystemApi
1788 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001789 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001790 if (mCallAudioState == null) {
1791 return null;
1792 }
Yorke Lee4af59352015-05-13 14:14:54 -07001793 return new AudioState(mCallAudioState);
1794 }
1795
1796 /**
1797 * @return The audio state of the connection, describing how its audio is currently
1798 * being routed by the system. This is {@code null} if this Connection
1799 * does not directly know about its audio state.
1800 */
1801 public final CallAudioState getCallAudioState() {
1802 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001803 }
1804
1805 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001806 * @return The conference that this connection is a part of. Null if it is not part of any
1807 * conference.
1808 */
1809 public final Conference getConference() {
1810 return mConference;
1811 }
1812
1813 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001814 * Returns whether this connection is requesting that the system play a ringback tone
1815 * on its behalf.
1816 */
Andrew Lee100e2932014-09-08 15:34:24 -07001817 public final boolean isRingbackRequested() {
1818 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001819 }
1820
1821 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001822 * @return True if the connection's audio mode is VOIP.
1823 */
1824 public final boolean getAudioModeIsVoip() {
1825 return mAudioModeIsVoip;
1826 }
1827
1828 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001829 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1830 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1831 * start time of the conference.
1832 *
1833 * @return The time at which the {@code Connnection} was connected.
1834 *
1835 * @hide
1836 */
1837 public final long getConnectTimeMillis() {
1838 return mConnectTimeMillis;
1839 }
1840
1841 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001842 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1843 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1844 * start time of the conference.
1845 *
1846 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
1847 * changes do not impact the call duration.
1848 *
1849 * @return The time at which the {@link Connection} was connected.
1850 *
1851 * @hide
1852 */
1853 public final long getConnectElapsedTimeMillis() {
1854 return mConnectElapsedTimeMillis;
1855 }
1856
1857 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001858 * @return The status hints for this connection.
1859 */
1860 public final StatusHints getStatusHints() {
1861 return mStatusHints;
1862 }
1863
1864 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001865 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001866 * <p>
1867 * Extras should be updated using {@link #putExtras(Bundle)}.
1868 * <p>
1869 * Telecom or an {@link InCallService} can also update the extras via
1870 * {@link android.telecom.Call#putExtras(Bundle)}, and
1871 * {@link Call#removeExtras(List)}.
1872 * <p>
1873 * The connection is notified of changes to the extras made by Telecom or an
1874 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001875 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001876 * @return The extras associated with this connection.
1877 */
1878 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001879 Bundle extras = null;
1880 synchronized (mExtrasLock) {
1881 if (mExtras != null) {
1882 extras = new Bundle(mExtras);
1883 }
1884 }
1885 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001886 }
1887
1888 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001889 * Assign a listener to be notified of state changes.
1890 *
1891 * @param l A listener.
1892 * @return This Connection.
1893 *
1894 * @hide
1895 */
1896 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001897 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001898 return this;
1899 }
1900
1901 /**
1902 * Remove a previously assigned listener that was being notified of state changes.
1903 *
1904 * @param l A Listener.
1905 * @return This Connection.
1906 *
1907 * @hide
1908 */
1909 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001910 if (l != null) {
1911 mListeners.remove(l);
1912 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001913 return this;
1914 }
1915
1916 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001917 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001918 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001919 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001920 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001921 }
1922
1923 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001924 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1925 * ONLY for debugging purposes.
1926 *
1927 * @param callId The telecom call ID.
1928 * @hide
1929 */
1930 public void setTelecomCallId(String callId) {
1931 mTelecomCallId = callId;
1932 }
1933
1934 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001935 * Inform this Connection that the state of its audio output has been changed externally.
1936 *
1937 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001938 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001939 */
Yorke Lee4af59352015-05-13 14:14:54 -07001940 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001941 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001942 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001943 mCallAudioState = state;
1944 onAudioStateChanged(getAudioState());
1945 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001946 }
1947
1948 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001949 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001950 * @return A string representation of the value.
1951 */
1952 public static String stateToString(int state) {
1953 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001954 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001955 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001956 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001957 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001958 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001959 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001960 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001961 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001962 case STATE_PULLING_CALL:
1963 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001964 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001965 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001966 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001967 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001968 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001969 return "DISCONNECTED";
1970 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001971 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001972 return "UNKNOWN";
1973 }
1974 }
1975
1976 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001977 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001978 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001979 public final int getConnectionCapabilities() {
1980 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001981 }
1982
1983 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001984 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1985 */
1986 public final int getConnectionProperties() {
1987 return mConnectionProperties;
1988 }
1989
1990 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001991 * Returns the connection's supported audio routes.
1992 *
1993 * @hide
1994 */
1995 public final int getSupportedAudioRoutes() {
1996 return mSupportedAudioRoutes;
1997 }
1998
1999 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002000 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002001 *
Andrew Lee100e2932014-09-08 15:34:24 -07002002 * @param address The new address.
2003 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002004 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002005 */
Andrew Lee100e2932014-09-08 15:34:24 -07002006 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002007 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002008 Log.d(this, "setAddress %s", address);
2009 mAddress = address;
2010 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002011 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002012 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002013 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002014 }
2015
2016 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002017 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002018 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002019 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002020 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002021 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002022 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002023 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002024 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002025 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002026 mCallerDisplayName = callerDisplayName;
2027 mCallerDisplayNamePresentation = presentation;
2028 for (Listener l : mListeners) {
2029 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2030 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002031 }
2032
2033 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002034 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002035 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2036 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2037 * {@link VideoProfile#STATE_TX_ENABLED},
2038 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002039 *
2040 * @param videoState The new video state.
2041 */
2042 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002043 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002044 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002045 mVideoState = videoState;
2046 for (Listener l : mListeners) {
2047 l.onVideoStateChanged(this, mVideoState);
2048 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002049 }
2050
2051 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002052 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002053 * communicate).
2054 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002055 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002056 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002057 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002058 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002059 }
2060
2061 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002062 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002063 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002064 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002065 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002066 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002067 }
2068
2069 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002070 * Sets state to initializing (this Connection is not yet ready to be used).
2071 */
2072 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002073 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002074 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002075 }
2076
2077 /**
2078 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2079 */
2080 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002081 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002082 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002083 }
2084
2085 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002086 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002087 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002088 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002089 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002090 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002091 }
2092
2093 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002094 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2095 * device). Only applicable for {@link Connection}s with
2096 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2097 */
2098 public final void setPulling() {
2099 checkImmutable();
2100 setState(STATE_PULLING_CALL);
2101 }
2102
2103 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002104 * Sets state to be on hold.
2105 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002106 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002107 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002108 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002109 }
2110
2111 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002112 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002113 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002114 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002115 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002116 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002117 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002118 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002119 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002120 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002121 }
2122
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002123 public final VideoProvider getVideoProvider() {
2124 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002125 }
2126
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002127 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002128 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002129 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002130 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002131 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002132 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002133 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002134 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002135 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002136 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002137 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002138 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002139 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002140 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002141 }
2142
2143 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002144 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2145 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2146 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2147 * to send an {@link #onPostDialContinue(boolean)} signal.
2148 *
2149 * @param remaining The DTMF character sequence remaining to be emitted once the
2150 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2151 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002152 */
2153 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002154 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002155 for (Listener l : mListeners) {
2156 l.onPostDialWait(this, remaining);
2157 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002158 }
2159
2160 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002161 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2162 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002163 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002164 *
2165 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002166 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002167 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002168 checkImmutable();
2169 for (Listener l : mListeners) {
2170 l.onPostDialChar(this, nextChar);
2171 }
2172 }
2173
2174 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002175 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002176 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002177 *
2178 * @param ringback Whether the ringback tone is to be played.
2179 */
Andrew Lee100e2932014-09-08 15:34:24 -07002180 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002181 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002182 if (mRingbackRequested != ringback) {
2183 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002184 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002185 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002186 }
2187 }
Ihab Awadf8358972014-05-28 16:46:42 -07002188 }
2189
2190 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002191 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002192 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002193 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002194 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002195 public final void setConnectionCapabilities(int connectionCapabilities) {
2196 checkImmutable();
2197 if (mConnectionCapabilities != connectionCapabilities) {
2198 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002199 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002200 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002201 }
2202 }
Santos Cordonb6939982014-06-04 20:20:58 -07002203 }
2204
2205 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002206 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2207 *
2208 * @param connectionProperties The new connection properties.
2209 */
2210 public final void setConnectionProperties(int connectionProperties) {
2211 checkImmutable();
2212 if (mConnectionProperties != connectionProperties) {
2213 mConnectionProperties = connectionProperties;
2214 for (Listener l : mListeners) {
2215 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2216 }
2217 }
2218 }
2219
2220 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002221 * Sets the supported audio routes.
2222 *
2223 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2224 * See {@link CallAudioState}
2225 * @hide
2226 */
2227 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2228 if ((supportedAudioRoutes
2229 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2230 throw new IllegalArgumentException(
2231 "supported audio routes must include either speaker or earpiece");
2232 }
2233
2234 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2235 mSupportedAudioRoutes = supportedAudioRoutes;
2236 for (Listener l : mListeners) {
2237 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2238 }
2239 }
2240 }
2241
2242 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002243 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002244 */
Evan Charlton36a71342014-07-19 16:31:02 -07002245 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002246 for (Listener l : mListeners) {
2247 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002248 }
Santos Cordonb6939982014-06-04 20:20:58 -07002249 }
2250
2251 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002252 * Requests that the framework use VOIP audio mode for this connection.
2253 *
2254 * @param isVoip True if the audio mode is VOIP.
2255 */
2256 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002257 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002258 mAudioModeIsVoip = isVoip;
2259 for (Listener l : mListeners) {
2260 l.onAudioModeIsVoipChanged(this, isVoip);
2261 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002262 }
2263
2264 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002265 * Sets the time at which a call became active on this Connection. This is set only
2266 * when a conference call becomes active on this connection.
2267 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002268 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2269 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002270 *
2271 * @hide
2272 */
2273 public final void setConnectTimeMillis(long connectTimeMillis) {
2274 mConnectTimeMillis = connectTimeMillis;
2275 }
2276
2277 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002278 * Sets the time at which a call became active on this Connection. This is set only
2279 * when a conference call becomes active on this connection.
2280 *
2281 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2282 * {@link SystemClock#elapsedRealtime()}.
2283 *
2284 * @hide
2285 */
2286 public final void setConnectElapsedTimeMillis(long connectElapsedTimeMillis) {
2287 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2288 }
2289
2290 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002291 * Sets the label and icon status to display in the in-call UI.
2292 *
2293 * @param statusHints The status label and icon to set.
2294 */
2295 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002296 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002297 mStatusHints = statusHints;
2298 for (Listener l : mListeners) {
2299 l.onStatusHintsChanged(this, statusHints);
2300 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002301 }
2302
2303 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002304 * Sets the connections with which this connection can be conferenced.
2305 *
2306 * @param conferenceableConnections The set of connections this connection can conference with.
2307 */
2308 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002309 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002310 clearConferenceableList();
2311 for (Connection c : conferenceableConnections) {
2312 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2313 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002314 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002315 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002316 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002317 }
2318 }
2319 fireOnConferenceableConnectionsChanged();
2320 }
2321
2322 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002323 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2324 * or conferences with which this connection can be conferenced.
2325 *
2326 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002327 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002328 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002329 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002330 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002331 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2332 // small amount of items here.
2333 if (!mConferenceables.contains(c)) {
2334 if (c instanceof Connection) {
2335 Connection connection = (Connection) c;
2336 connection.addConnectionListener(mConnectionDeathListener);
2337 } else if (c instanceof Conference) {
2338 Conference conference = (Conference) c;
2339 conference.addListener(mConferenceDeathListener);
2340 }
2341 mConferenceables.add(c);
2342 }
2343 }
2344 fireOnConferenceableConnectionsChanged();
2345 }
2346
2347 /**
2348 * Returns the connections or conferences with which this connection can be conferenced.
2349 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002350 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002351 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002352 }
2353
Yorke Lee53463962015-08-04 16:07:19 -07002354 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002355 * @hide
2356 */
2357 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002358 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002359 if (mConnectionService != null) {
2360 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2361 "which is already associated with another ConnectionService.");
2362 } else {
2363 mConnectionService = connectionService;
2364 }
2365 }
2366
2367 /**
2368 * @hide
2369 */
2370 public final void unsetConnectionService(ConnectionService connectionService) {
2371 if (mConnectionService != connectionService) {
2372 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2373 "that does not belong to the ConnectionService.");
2374 } else {
2375 mConnectionService = null;
2376 }
2377 }
2378
2379 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002380 * @hide
2381 */
2382 public final ConnectionService getConnectionService() {
2383 return mConnectionService;
2384 }
2385
2386 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002387 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002388 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002389 *
2390 * @param conference The conference.
2391 * @return {@code true} if the conference was successfully set.
2392 * @hide
2393 */
2394 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002395 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002396 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002397 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002398 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002399 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2400 fireConferenceChanged();
2401 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002402 return true;
2403 }
2404 return false;
2405 }
2406
2407 /**
2408 * Resets the conference that this connection is a part of.
2409 * @hide
2410 */
2411 public final void resetConference() {
2412 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002413 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002414 mConference = null;
2415 fireConferenceChanged();
2416 }
2417 }
2418
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002419 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002420 * Set some extras that can be associated with this {@code Connection}.
2421 * <p>
2422 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2423 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2424 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002425 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2426 * {@link #removeExtras(String...)} methods to modify the extras.
2427 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002428 * 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 -07002429 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2430 *
2431 * @param extras The extras associated with this {@code Connection}.
2432 */
2433 public final void setExtras(@Nullable Bundle extras) {
2434 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002435
2436 // Add/replace any new or changed extras values.
2437 putExtras(extras);
2438
2439 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2440 // the current one and remove any keys that went away.
2441 if (mPreviousExtraKeys != null) {
2442 List<String> toRemove = new ArrayList<String>();
2443 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002444 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002445 toRemove.add(oldKey);
2446 }
2447 }
2448 if (!toRemove.isEmpty()) {
2449 removeExtras(toRemove);
2450 }
2451 }
2452
2453 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2454 // called we can see if the caller has removed any extras values.
2455 if (mPreviousExtraKeys == null) {
2456 mPreviousExtraKeys = new ArraySet<String>();
2457 }
2458 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002459 if (extras != null) {
2460 mPreviousExtraKeys.addAll(extras.keySet());
2461 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002462 }
2463
2464 /**
2465 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2466 * added.
2467 * <p>
2468 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2469 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2470 *
2471 * @param extras The extras to add.
2472 */
2473 public final void putExtras(@NonNull Bundle extras) {
2474 checkImmutable();
2475 if (extras == null) {
2476 return;
2477 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002478 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2479 // the listeners.
2480 Bundle listenerExtras;
2481 synchronized (mExtrasLock) {
2482 if (mExtras == null) {
2483 mExtras = new Bundle();
2484 }
2485 mExtras.putAll(extras);
2486 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002487 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002488 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002489 // Create a new clone of the extras for each listener so that they don't clobber
2490 // each other
2491 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002492 }
2493 }
2494
2495 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002496 * Adds a boolean extra to this {@code Connection}.
2497 *
2498 * @param key The extra key.
2499 * @param value The value.
2500 * @hide
2501 */
2502 public final void putExtra(String key, boolean value) {
2503 Bundle newExtras = new Bundle();
2504 newExtras.putBoolean(key, value);
2505 putExtras(newExtras);
2506 }
2507
2508 /**
2509 * Adds an integer extra to this {@code Connection}.
2510 *
2511 * @param key The extra key.
2512 * @param value The value.
2513 * @hide
2514 */
2515 public final void putExtra(String key, int value) {
2516 Bundle newExtras = new Bundle();
2517 newExtras.putInt(key, value);
2518 putExtras(newExtras);
2519 }
2520
2521 /**
2522 * Adds a string extra to this {@code Connection}.
2523 *
2524 * @param key The extra key.
2525 * @param value The value.
2526 * @hide
2527 */
2528 public final void putExtra(String key, String value) {
2529 Bundle newExtras = new Bundle();
2530 newExtras.putString(key, value);
2531 putExtras(newExtras);
2532 }
2533
2534 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002535 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002536 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002537 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002538 */
2539 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002540 synchronized (mExtrasLock) {
2541 if (mExtras != null) {
2542 for (String key : keys) {
2543 mExtras.remove(key);
2544 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002545 }
2546 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002547 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002548 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002549 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002550 }
2551 }
2552
2553 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002554 * Removes extras from this {@code Connection}.
2555 *
2556 * @param keys The keys of the extras to remove.
2557 */
2558 public final void removeExtras(String ... keys) {
2559 removeExtras(Arrays.asList(keys));
2560 }
2561
2562 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002563 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2564 * be change to the {@link #getCallAudioState()}.
2565 * <p>
2566 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2567 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2568 * <p>
2569 * See also {@link InCallService#setAudioRoute(int)}.
2570 *
2571 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2572 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2573 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2574 */
2575 public final void setAudioRoute(int route) {
2576 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002577 l.onAudioRouteChanged(this, route, null);
2578 }
2579 }
2580
2581 /**
2582 *
2583 * Request audio routing to a specific bluetooth device. Calling this method may result in
2584 * the device routing audio to a different bluetooth device than the one specified if the
2585 * bluetooth stack is unable to route audio to the requested device.
2586 * A list of available devices can be obtained via
2587 * {@link CallAudioState#getSupportedBluetoothDevices()}
2588 *
2589 * <p>
2590 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2591 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2592 * <p>
2593 * See also {@link InCallService#requestBluetoothAudio(String)}
2594 * @param bluetoothAddress The address of the bluetooth device to connect to, as returned by
2595 * {@link BluetoothDevice#getAddress()}.
2596 */
2597 public void requestBluetoothAudio(@NonNull String bluetoothAddress) {
2598 for (Listener l : mListeners) {
2599 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH, bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -08002600 }
2601 }
2602
2603 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002604 * Informs listeners that a previously requested RTT session via
2605 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08002606 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002607 */
2608 public final void sendRttInitiationSuccess() {
Hall Liuffa4a812017-03-02 16:11:00 -08002609 setRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08002610 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2611 }
2612
2613 /**
2614 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002615 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002616 * has failed.
2617 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2618 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002619 */
2620 public final void sendRttInitiationFailure(int reason) {
Hall Liuffa4a812017-03-02 16:11:00 -08002621 unsetRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08002622 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2623 }
2624
2625 /**
2626 * Informs listeners that a currently active RTT session has been terminated by the remote
2627 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002628 */
2629 public final void sendRttSessionRemotelyTerminated() {
2630 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2631 }
2632
2633 /**
2634 * Informs listeners that the remote side of the call has requested an upgrade to include an
2635 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002636 */
2637 public final void sendRemoteRttRequest() {
2638 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2639 }
2640
2641 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002642 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002643 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002644 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002645 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2646 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002647 */
Yorke Lee4af59352015-05-13 14:14:54 -07002648 @SystemApi
2649 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002650 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002651
2652 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002653 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2654 *
2655 * @param state The new connection audio state.
2656 */
2657 public void onCallAudioStateChanged(CallAudioState state) {}
2658
2659 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002660 * Notifies this Connection of an internal state change. This method is called after the
2661 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002662 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002663 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002664 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002665 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002666
2667 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002668 * Notifies this Connection of a request to play a DTMF tone.
2669 *
2670 * @param c A DTMF character.
2671 */
Santos Cordonf2951102014-07-20 19:06:29 -07002672 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002673
2674 /**
2675 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2676 */
Santos Cordonf2951102014-07-20 19:06:29 -07002677 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002678
2679 /**
2680 * Notifies this Connection of a request to disconnect.
2681 */
Santos Cordonf2951102014-07-20 19:06:29 -07002682 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002683
2684 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002685 * Notifies this Connection of a request to disconnect a participant of the conference managed
2686 * by the connection.
2687 *
2688 * @param endpoint the {@link Uri} of the participant to disconnect.
2689 * @hide
2690 */
2691 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2692
2693 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002694 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002695 */
Santos Cordonf2951102014-07-20 19:06:29 -07002696 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002697
2698 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002699 * Notifies this Connection of a request to abort.
2700 */
Santos Cordonf2951102014-07-20 19:06:29 -07002701 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002702
2703 /**
2704 * Notifies this Connection of a request to hold.
2705 */
Santos Cordonf2951102014-07-20 19:06:29 -07002706 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002707
2708 /**
2709 * Notifies this Connection of a request to exit a hold state.
2710 */
Santos Cordonf2951102014-07-20 19:06:29 -07002711 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002712
2713 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002714 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002715 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002716 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002717 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002718 */
Santos Cordonf2951102014-07-20 19:06:29 -07002719 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002720
2721 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002722 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002723 * a request to accept.
2724 */
2725 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002726 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002727 }
2728
2729 /**
2730 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002731 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002732 */
Santos Cordonf2951102014-07-20 19:06:29 -07002733 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002734
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002735 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002736 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2737 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002738 */
2739 public void onReject(String replyMessage) {}
2740
2741 /**
Bryce Leecac50772015-11-17 15:13:29 -08002742 * Notifies the Connection of a request to silence the ringer.
2743 *
2744 * @hide
2745 */
2746 public void onSilence() {}
2747
2748 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002749 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2750 */
Santos Cordonf2951102014-07-20 19:06:29 -07002751 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002752
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002753 /**
2754 * Notifies this Connection of a request to pull an external call to the local device.
2755 * <p>
2756 * The {@link InCallService} issues a request to pull an external call to the local device via
2757 * {@link Call#pullExternalCall()}.
2758 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002759 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2760 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002761 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002762 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002763 */
2764 public void onPullExternalCall() {}
2765
2766 /**
2767 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2768 * <p>
2769 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2770 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002771 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2772 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2773 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2774 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2775 * not aware of.
2776 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002777 * See also {@link Call#sendCallEvent(String, Bundle)}.
2778 *
2779 * @param event The call event.
2780 * @param extras Extras associated with the call event.
2781 */
2782 public void onCallEvent(String event, Bundle extras) {}
2783
Tyler Gunndee56a82016-03-23 16:06:34 -07002784 /**
2785 * Notifies this {@link Connection} of a change to the extras made outside the
2786 * {@link ConnectionService}.
2787 * <p>
2788 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2789 * the {@link android.telecom.Call#putExtras(Bundle)} and
2790 * {@link Call#removeExtras(List)}.
2791 *
2792 * @param extras The new extras bundle.
2793 */
2794 public void onExtrasChanged(Bundle extras) {}
2795
Tyler Gunnf5035432017-01-09 09:43:12 -08002796 /**
2797 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2798 * displaying its incoming call user interface for the {@link Connection}.
2799 * <p>
2800 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2801 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2802 * should show its own incoming call user interface.
2803 * <p>
2804 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
2805 * regular {@link ConnectionService}, the Telecom framework will display its own incoming call
2806 * user interface to allow the user to choose whether to answer the new incoming call and
2807 * disconnect other ongoing calls, or to reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002808 * <p>
2809 * You should trigger the display of the incoming call user interface for your application by
2810 * showing a {@link Notification} with a full-screen {@link Intent} specified.
2811 * For example:
2812 * <pre><code>
2813 * // Create an intent which triggers your fullscreen incoming call user interface.
2814 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
2815 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
2816 * intent.setClass(context, YourIncomingCallActivity.class);
2817 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
2818 *
2819 * // Build the notification as an ongoing high priority item; this ensures it will show as
2820 * // a heads up notification which slides down over top of the current content.
2821 * final Notification.Builder builder = new Notification.Builder(context);
2822 * builder.setOngoing(true);
2823 * builder.setPriority(Notification.PRIORITY_HIGH);
2824 *
2825 * // Set notification content intent to take user to fullscreen UI if user taps on the
2826 * // notification body.
2827 * builder.setContentIntent(pendingIntent);
2828 * // Set full screen intent to trigger display of the fullscreen UI when the notification
2829 * // manager deems it appropriate.
2830 * builder.setFullScreenIntent(pendingIntent, true);
2831 *
2832 * // Setup notification content.
2833 * builder.setSmallIcon( yourIconResourceId );
2834 * builder.setContentTitle("Your notification title");
2835 * builder.setContentText("Your notification content.");
2836 *
2837 * // Use builder.addAction(..) to add buttons to answer or reject the call.
2838 *
2839 * NotificationManager notificationManager = mContext.getSystemService(
2840 * NotificationManager.class);
2841 * notificationManager.notify(YOUR_TAG, YOUR_ID, builder.build());
2842 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08002843 */
2844 public void onShowIncomingCallUi() {}
2845
Hall Liub64ac4c2017-02-06 10:49:48 -08002846 /**
2847 * Notifies this {@link Connection} that the user has requested an RTT session.
2848 * The connection service should call {@link #sendRttInitiationSuccess} or
2849 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
2850 * request, respectively.
2851 * @param rttTextStream The object that should be used to send text to or receive text from
2852 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08002853 */
2854 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
2855
2856 /**
2857 * Notifies this {@link Connection} that it should terminate any existing RTT communication
2858 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08002859 */
2860 public void onStopRtt() {}
2861
2862 /**
2863 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
2864 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
2865 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
2866 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08002867 * @param rttTextStream The object that should be used to send text to or receive text from
2868 * the in-call app.
2869 */
2870 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
2871
Hall Liuffa4a812017-03-02 16:11:00 -08002872 /**
2873 * Internal method to set {@link #PROPERTY_IS_RTT}.
2874 * @hide
2875 */
2876 void setRttProperty() {
2877 setConnectionProperties(getConnectionProperties() | PROPERTY_IS_RTT);
2878 }
2879
2880 /**
2881 * Internal method to un-set {@link #PROPERTY_IS_RTT}.
2882 * @hide
2883 */
2884 void unsetRttProperty() {
2885 setConnectionProperties(getConnectionProperties() & (~PROPERTY_IS_RTT));
2886 }
2887
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002888 static String toLogSafePhoneNumber(String number) {
2889 // For unknown number, log empty string.
2890 if (number == null) {
2891 return "";
2892 }
2893
2894 if (PII_DEBUG) {
2895 // When PII_DEBUG is true we emit PII.
2896 return number;
2897 }
2898
2899 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2900 // sanitized phone numbers.
2901 StringBuilder builder = new StringBuilder();
2902 for (int i = 0; i < number.length(); i++) {
2903 char c = number.charAt(i);
2904 if (c == '-' || c == '@' || c == '.') {
2905 builder.append(c);
2906 } else {
2907 builder.append('x');
2908 }
2909 }
2910 return builder.toString();
2911 }
2912
Ihab Awad542e0ea2014-05-16 10:22:16 -07002913 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002914 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002915 if (mState == STATE_DISCONNECTED && mState != state) {
2916 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002917 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002918 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002919 if (mState != state) {
2920 Log.d(this, "setState: %s", stateToString(state));
2921 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002922 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002923 for (Listener l : mListeners) {
2924 l.onStateChanged(this, state);
2925 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002926 }
2927 }
2928
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002929 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002930 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002931 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2932 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002933 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002934 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002935
2936 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002937 if (mImmutable) {
2938 throw new UnsupportedOperationException("Connection is immutable");
2939 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002940 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002941 }
2942
Evan Charltonbf11f982014-07-20 22:06:28 -07002943 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002944 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002945 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2946 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002947 * <p>
2948 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2949 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002950 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002951 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002952 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002953 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002954 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2955 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002956 }
2957
Evan Charltonbf11f982014-07-20 22:06:28 -07002958 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002959 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2960 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2961 * this should never be un-@hide-den.
2962 *
2963 * @hide
2964 */
2965 public void checkImmutable() {}
2966
2967 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002968 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2969 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2970 * that state. This connection should not be used for anything, and no other
2971 * {@code Connection}s should be attempted.
2972 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002973 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002974 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002975 * @return A {@code Connection} which indicates that the underlying connection should
2976 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002977 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002978 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002979 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002980 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002981
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002982 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002983 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002984 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002985 }
2986 }
2987
Santos Cordon823fd3c2014-08-07 18:35:18 -07002988 private final void fireConferenceChanged() {
2989 for (Listener l : mListeners) {
2990 l.onConferenceChanged(this, mConference);
2991 }
2992 }
2993
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002994 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002995 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002996 if (c instanceof Connection) {
2997 Connection connection = (Connection) c;
2998 connection.removeConnectionListener(mConnectionDeathListener);
2999 } else if (c instanceof Conference) {
3000 Conference conference = (Conference) c;
3001 conference.removeListener(mConferenceDeathListener);
3002 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003003 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003004 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003005 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003006
3007 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003008 * Handles a change to extras received from Telecom.
3009 *
3010 * @param extras The new extras.
3011 * @hide
3012 */
3013 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003014 Bundle b = null;
3015 synchronized (mExtrasLock) {
3016 mExtras = extras;
3017 if (mExtras != null) {
3018 b = new Bundle(mExtras);
3019 }
3020 }
3021 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003022 }
3023
3024 /**
Anthony Lee17455a32015-04-24 15:25:29 -07003025 * Notifies listeners that the merge request failed.
3026 *
3027 * @hide
3028 */
3029 protected final void notifyConferenceMergeFailed() {
3030 for (Listener l : mListeners) {
3031 l.onConferenceMergeFailed(this);
3032 }
3033 }
3034
3035 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08003036 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003037 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08003038 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003039 * @hide
3040 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08003041 protected final void updateConferenceParticipants(
3042 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003043 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08003044 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003045 }
3046 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003047
3048 /**
3049 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07003050 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003051 */
3052 protected void notifyConferenceStarted() {
3053 for (Listener l : mListeners) {
3054 l.onConferenceStarted();
3055 }
3056 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003057
3058 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07003059 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
3060 * be a part of a conference call.
3061 * @param isConferenceSupported {@code true} if the connection supports being part of a
3062 * conference call, {@code false} otherwise.
3063 * @hide
3064 */
3065 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
3066 for (Listener l : mListeners) {
3067 l.onConferenceSupportedChanged(this, isConferenceSupported);
3068 }
3069 }
3070
3071 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303072 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3073 * changed due to an emergency call being redialed.
3074 * @param pHandle The new PhoneAccountHandle for this connection.
3075 * @hide
3076 */
3077 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3078 for (Listener l : mListeners) {
3079 l.onPhoneAccountChanged(this, pHandle);
3080 }
3081 }
3082
3083 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003084 * Sets the {@link PhoneAccountHandle} associated with this connection.
3085 *
3086 * @hide
3087 */
3088 public void setPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) {
3089 if (mPhoneAccountHandle != phoneAccountHandle) {
3090 mPhoneAccountHandle = phoneAccountHandle;
3091 notifyPhoneAccountChanged(phoneAccountHandle);
3092 }
3093 }
3094
3095 /**
3096 * Returns the {@link PhoneAccountHandle} associated with this connection.
3097 *
3098 * @hide
3099 */
3100 public PhoneAccountHandle getPhoneAccountHandle() {
3101 return mPhoneAccountHandle;
3102 }
3103
3104 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003105 * Sends an event associated with this {@code Connection} with associated event extras to the
3106 * {@link InCallService}.
3107 * <p>
3108 * Connection events are used to communicate point in time information from a
3109 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3110 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3111 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3112 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3113 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3114 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3115 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3116 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3117 * <p>
3118 * Events are exposed to {@link InCallService} implementations via
3119 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3120 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003121 * 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 -07003122 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3123 * some events altogether.
3124 * <p>
3125 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3126 * conflicts between {@link ConnectionService} implementations. Further, custom
3127 * {@link ConnectionService} implementations shall not re-purpose events in the
3128 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3129 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3130 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3131 * {@code com.example.extra.MY_EXTRA}).
3132 * <p>
3133 * When defining events and the associated extras, it is important to keep their behavior
3134 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3135 * events/extras should me maintained to ensure backwards compatibility with older
3136 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003137 *
3138 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003139 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003140 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003141 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003142 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003143 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003144 }
3145 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003146}