blob: 8ba934ccdb8bbf43841cfc268d358f80bd7a6901 [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;
Hall Liuffa4a812017-03-02 16:11:00 -080026import android.annotation.TestApi;
Tyler Gunn159f35c2017-03-02 09:28:37 -080027import android.app.Notification;
28import 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 * @hide
400 */
Hall Liuffa4a812017-03-02 16:11:00 -0800401 @TestApi
Hall Liu95d55872017-01-25 17:12:49 -0800402 public static final int PROPERTY_IS_RTT = 1 << 8;
403
Tyler Gunn96d6c402015-03-18 12:39:23 -0700404 //**********************************************************************************************
Hall Liu95d55872017-01-25 17:12:49 -0800405 // Next PROPERTY value: 1<<9
Tyler Gunn96d6c402015-03-18 12:39:23 -0700406 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800407
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700408 /**
409 * Connection extra key used to store the last forwarded number associated with the current
410 * connection. Used to communicate to the user interface that the connection was forwarded via
411 * the specified number.
412 */
413 public static final String EXTRA_LAST_FORWARDED_NUMBER =
414 "android.telecom.extra.LAST_FORWARDED_NUMBER";
415
416 /**
417 * Connection extra key used to store a child number associated with the current connection.
418 * Used to communicate to the user interface that the connection was received via
419 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
420 * address.
421 */
422 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
423
424 /**
425 * Connection extra key used to store the subject for an incoming call. The user interface can
426 * query this extra and display its contents for incoming calls. Will only be used if the
427 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
428 */
429 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
430
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800431 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700432 * Boolean connection extra key set on a {@link Connection} in
433 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
434 * current active foreground call to be dropped.
435 */
436 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
437 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
438
439 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700440 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
441 * state to indicate the name of the third-party app which is responsible for the current
442 * foreground call.
443 * <p>
444 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
445 * is able to inform the user that answering the new incoming call will cause a call owned by
446 * another app to be dropped when the incoming call is answered.
447 */
448 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
449 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
450
451 /**
Hall Liu10208662016-06-15 17:55:00 -0700452 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700453 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700454 * @hide
455 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700456 public static final String EXTRA_DISABLE_ADD_CALL =
457 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700458
459 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700460 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
461 * original Connection ID associated with the connection. Used in
462 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
463 * connection/conference added via
464 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
465 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
466 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
467 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
468 * be a way to ensure that we don't add the connection again as a duplicate.
469 * <p>
470 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
471 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
472 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
473 * in a new {@link Connection} which it adds to Telecom via
474 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
475 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
476 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
477 * ID it originally referred to the connection as. Thus Telecom needs to know that the
478 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
479 * @hide
480 */
481 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
482 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
483
484 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800485 * Connection event used to inform Telecom that it should play the on hold tone. This is used
486 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700487 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800488 * @hide
489 */
490 public static final String EVENT_ON_HOLD_TONE_START =
491 "android.telecom.event.ON_HOLD_TONE_START";
492
493 /**
494 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
495 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700496 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800497 * @hide
498 */
499 public static final String EVENT_ON_HOLD_TONE_END =
500 "android.telecom.event.ON_HOLD_TONE_END";
501
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700502 /**
503 * Connection event used to inform {@link InCallService}s when pulling of an external call has
504 * failed. The user interface should inform the user of the error.
505 * <p>
506 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
507 * API is called on a {@link Call} with the properties
508 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
509 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
510 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700511 * <p>
512 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
513 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700514 */
515 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
516
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700517 /**
518 * Connection event used to inform {@link InCallService}s when the merging of two calls has
519 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700520 * <p>
521 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
522 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700523 */
524 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
525
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700526 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700527 * Connection event used to inform {@link InCallService}s when the process of merging a
528 * Connection into a conference has begun.
529 * <p>
530 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
531 * expected to be null when this connection event is used.
532 * @hide
533 */
534 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
535
536 /**
537 * Connection event used to inform {@link InCallService}s when the process of merging a
538 * Connection into a conference has completed.
539 * <p>
540 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
541 * expected to be null when this connection event is used.
542 * @hide
543 */
544 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
545
546 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700547 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
548 * the remote party.
549 * <p>
550 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
551 * call is being held locally on the device. When a capable {@link ConnectionService} receives
552 * signalling to indicate that the remote party has put the call on hold, it can send this
553 * connection event.
554 * @hide
555 */
556 public static final String EVENT_CALL_REMOTELY_HELD =
557 "android.telecom.event.CALL_REMOTELY_HELD";
558
559 /**
560 * Connection event used to inform {@link InCallService}s when a call which was remotely held
561 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
562 * <p>
563 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
564 * call is being held locally on the device. When a capable {@link ConnectionService} receives
565 * signalling to indicate that the remote party has taken the call off hold, it can send this
566 * connection event.
567 * @hide
568 */
569 public static final String EVENT_CALL_REMOTELY_UNHELD =
570 "android.telecom.event.CALL_REMOTELY_UNHELD";
571
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700572 /**
573 * Connection event used to inform an {@link InCallService} which initiated a call handover via
574 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
575 * successfully completed.
576 * @hide
577 */
578 public static final String EVENT_HANDOVER_COMPLETE =
579 "android.telecom.event.HANDOVER_COMPLETE";
580
581 /**
582 * Connection event used to inform an {@link InCallService} which initiated a call handover via
583 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
584 * to complete.
585 * @hide
586 */
587 public static final String EVENT_HANDOVER_FAILED =
588 "android.telecom.event.HANDOVER_FAILED";
589
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700590 // Flag controlling whether PII is emitted into the logs
591 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
592
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800593 /**
594 * Whether the given capabilities support the specified capability.
595 *
596 * @param capabilities A capability bit field.
597 * @param capability The capability to check capabilities for.
598 * @return Whether the specified capability is supported.
599 * @hide
600 */
601 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800602 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800603 }
604
605 /**
606 * Whether the capabilities of this {@code Connection} supports the specified capability.
607 *
608 * @param capability The capability to check capabilities for.
609 * @return Whether the specified capability is supported.
610 * @hide
611 */
612 public boolean can(int capability) {
613 return can(mConnectionCapabilities, capability);
614 }
615
616 /**
617 * Removes the specified capability from the set of capabilities of this {@code Connection}.
618 *
619 * @param capability The capability to remove from the set.
620 * @hide
621 */
622 public void removeCapability(int capability) {
623 mConnectionCapabilities &= ~capability;
624 }
625
626 /**
627 * Adds the specified capability to the set of capabilities of this {@code Connection}.
628 *
629 * @param capability The capability to add to the set.
630 * @hide
631 */
632 public void addCapability(int capability) {
633 mConnectionCapabilities |= capability;
634 }
635
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700636 /**
637 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
638 *
639 * @param capabilities A capability bit field.
640 * @return A human readable string representation.
641 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800642 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700643 return capabilitiesToStringInternal(capabilities, true /* isLong */);
644 }
645
646 /**
647 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
648 * string.
649 *
650 * @param capabilities A capability bit field.
651 * @return A human readable string representation.
652 * @hide
653 */
654 public static String capabilitiesToStringShort(int capabilities) {
655 return capabilitiesToStringInternal(capabilities, false /* isLong */);
656 }
657
658 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800659 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700660 builder.append("[");
661 if (isLong) {
662 builder.append("Capabilities:");
663 }
664
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800665 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700666 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800667 }
668 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700669 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800670 }
671 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700672 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800673 }
674 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700675 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800676 }
677 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700678 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800679 }
680 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700681 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800682 }
683 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700684 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800685 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700686 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700687 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700688 }
689 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700690 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700691 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700692 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700693 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800694 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700695 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700696 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700697 }
698 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700699 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700700 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700701 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700702 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800703 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800704 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700705 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800706 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500707 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700708 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500709 }
Rekha Kumar07366812015-03-24 16:42:31 -0700710 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700711 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700712 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700713 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700714 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700715 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700716 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700717 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700718 }
Bryce Lee81901682015-08-28 16:38:02 -0700719 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700720 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700721 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700722 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700723 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700724 }
Bryce Lee81901682015-08-28 16:38:02 -0700725
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800726 builder.append("]");
727 return builder.toString();
728 }
729
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700730 /**
731 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
732 *
733 * @param properties A property bit field.
734 * @return A human readable string representation.
735 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700736 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700737 return propertiesToStringInternal(properties, true /* isLong */);
738 }
739
740 /**
741 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
742 *
743 * @param properties A property bit field.
744 * @return A human readable string representation.
745 * @hide
746 */
747 public static String propertiesToStringShort(int properties) {
748 return propertiesToStringInternal(properties, false /* isLong */);
749 }
750
751 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700752 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700753 builder.append("[");
754 if (isLong) {
755 builder.append("Properties:");
756 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700757
Tyler Gunnf5035432017-01-09 09:43:12 -0800758 if (can(properties, PROPERTY_SELF_MANAGED)) {
759 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
760 }
761
Hall Liu25c7c4d2016-08-30 13:41:02 -0700762 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
763 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700764 }
765
766 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700767 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700768 }
769
770 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700771 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700772 }
773
774 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700775 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700776 }
777
778 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700779 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700780 }
781
Brad Ebinger15847072016-05-18 11:08:36 -0700782 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700783 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700784 }
785
Tyler Gunn720c6642016-03-22 09:02:47 -0700786 builder.append("]");
787 return builder.toString();
788 }
789
Sailesh Nepal091768c2014-06-30 15:15:23 -0700790 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700791 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700792 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700793 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700794 public void onCallerDisplayNameChanged(
795 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700796 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700797 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700798 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800799 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700800 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700801 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800802 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700803 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800804 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700805 public void onVideoProviderChanged(
806 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700807 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
808 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800809 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700810 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700811 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700812 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800813 public void onConferenceParticipantsChanged(Connection c,
814 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800815 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700816 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700817 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700818 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700819 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700820 /** @hide */
821 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Tyler Gunnf5035432017-01-09 09:43:12 -0800822 public void onAudioRouteChanged(Connection c, int audioRoute) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800823 public void onRttInitiationSuccess(Connection c) {}
824 public void onRttInitiationFailure(Connection c, int reason) {}
825 public void onRttSessionRemotelyTerminated(Connection c) {}
826 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530827 /** @hide */
828 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700829 }
830
Tyler Gunnb702ef82015-05-29 11:51:53 -0700831 /**
Hall Liu95d55872017-01-25 17:12:49 -0800832 * Provides methods to read and write RTT data to/from the in-call app.
833 * @hide
834 */
Hall Liuffa4a812017-03-02 16:11:00 -0800835 @TestApi
Hall Liu95d55872017-01-25 17:12:49 -0800836 public static final class RttTextStream {
837 private static final int READ_BUFFER_SIZE = 1000;
838 private final InputStreamReader mPipeFromInCall;
839 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800840 private final ParcelFileDescriptor mFdFromInCall;
841 private final ParcelFileDescriptor mFdToInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800842 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
843
844 /**
845 * @hide
846 */
847 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800848 mFdFromInCall = fromInCall;
849 mFdToInCall = toInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800850 mPipeFromInCall = new InputStreamReader(
851 new ParcelFileDescriptor.AutoCloseInputStream(fromInCall));
852 mPipeToInCall = new OutputStreamWriter(
853 new ParcelFileDescriptor.AutoCloseOutputStream(toInCall));
854 }
855
856 /**
857 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
858 * RTT transmits text in real-time, this method should be called as often as text snippets
859 * are received from the remote user, even if it is only one character.
860 *
861 * This method is not thread-safe -- calling it from multiple threads simultaneously may
862 * lead to interleaved text.
863 * @param input The message to send to the in-call app.
864 */
865 public void write(String input) throws IOException {
866 mPipeToInCall.write(input);
867 mPipeToInCall.flush();
868 }
869
870
871 /**
872 * Reads a string from the in-call app, blocking if there is no data available. Returns
873 * {@code null} if the RTT conversation has been terminated and there is no further data
874 * to read.
875 *
876 * This method is not thread-safe -- calling it from multiple threads simultaneously may
877 * lead to interleaved text.
878 * @return A string containing text entered by the user, or {@code null} if the
879 * conversation has been terminated or if there was an error while reading.
880 */
Hall Liuffa4a812017-03-02 16:11:00 -0800881 public String read() throws IOException {
882 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
883 if (numRead < 0) {
884 return null;
885 }
886 return new String(mReadBuffer, 0, numRead);
887 }
888
889 /**
890 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
891 * be read.
892 * @return A string containing text entered by the user, or {@code null} if the user has
893 * not entered any new text yet.
894 */
895 public String readImmediately() throws IOException {
896 if (mPipeFromInCall.ready()) {
897 return read();
898 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800899 return null;
900 }
901 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800902
903 /** @hide */
904 public ParcelFileDescriptor getFdFromInCall() {
905 return mFdFromInCall;
906 }
907
908 /** @hide */
909 public ParcelFileDescriptor getFdToInCall() {
910 return mFdToInCall;
911 }
912 }
913
914 /**
915 * Provides constants to represent the results of responses to session modify requests sent via
916 * {@link Call#sendRttRequest()}
917 */
918 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -0700919 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800920 /**
921 * Session modify request was successful.
922 */
923 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
924
925 /**
926 * Session modify request failed.
927 */
928 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
929
930 /**
931 * Session modify request ignored due to invalid parameters.
932 */
933 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
934
935 /**
936 * Session modify request timed out.
937 */
938 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
939
940 /**
941 * Session modify request rejected by remote user.
942 */
943 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -0800944 }
945
946 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700947 * Provides a means of controlling the video session associated with a {@link Connection}.
948 * <p>
949 * Implementations create a custom subclass of {@link VideoProvider} and the
950 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
951 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
952 * should set the {@link VideoProvider}.
953 * <p>
954 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
955 * {@link InCallService} implementations to issue requests related to the video session;
956 * it provides a means for the {@link ConnectionService} to report events and information
957 * related to the video session to Telecom and the {@link InCallService} implementations.
958 * <p>
959 * {@link InCallService} implementations interact with the {@link VideoProvider} via
960 * {@link android.telecom.InCallService.VideoCall}.
961 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700962 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700963 /**
964 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700965 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700966 */
967 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700968
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700969 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700970 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
971 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700972 */
973 public static final int SESSION_EVENT_RX_RESUME = 2;
974
975 /**
976 * Video transmission has begun. This occurs after a negotiated start of video transmission
977 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700978 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700979 */
980 public static final int SESSION_EVENT_TX_START = 3;
981
982 /**
983 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
984 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700985 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700986 */
987 public static final int SESSION_EVENT_TX_STOP = 4;
988
989 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800990 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -0700991 * this as a cue to inform the user the camera is not available.
992 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700993 */
994 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
995
996 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700997 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800998 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -0700999 * the camera has become available again.
1000 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001001 */
1002 public static final int SESSION_EVENT_CAMERA_READY = 6;
1003
1004 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001005 * Session event raised by Telecom when
1006 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1007 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1008 * @see #handleCallSessionEvent(int)
1009 */
1010 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1011
1012 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001013 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001014 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001015 */
1016 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1017
1018 /**
1019 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001020 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001021 */
1022 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1023
1024 /**
1025 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001026 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001027 */
1028 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1029
Rekha Kumar07366812015-03-24 16:42:31 -07001030 /**
1031 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001032 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001033 */
1034 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1035
1036 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001037 * Session modify request rejected by remote user.
1038 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001039 */
1040 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1041
Tyler Gunn75958422015-04-15 14:23:42 -07001042 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001043 private static final int MSG_SET_CAMERA = 2;
1044 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1045 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1046 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1047 private static final int MSG_SET_ZOOM = 6;
1048 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1049 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1050 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001051 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001052 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001053 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001054
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001055 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1056 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1057 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1058 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1059 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1060 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001061 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1062 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001063 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1064
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001065 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001066 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001067
1068 /**
1069 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001070 *
1071 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1072 * load factor before resizing, 1 means we only expect a single thread to
1073 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001074 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001075 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1076 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001077
1078 /**
1079 * Default handler used to consolidate binder method calls onto a single thread.
1080 */
1081 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001082 public VideoProviderHandler() {
1083 super();
1084 }
1085
1086 public VideoProviderHandler(Looper looper) {
1087 super(looper);
1088 }
1089
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001090 @Override
1091 public void handleMessage(Message msg) {
1092 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001093 case MSG_ADD_VIDEO_CALLBACK: {
1094 IBinder binder = (IBinder) msg.obj;
1095 IVideoCallback callback = IVideoCallback.Stub
1096 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001097 if (callback == null) {
1098 Log.w(this, "addVideoProvider - skipped; callback is null.");
1099 break;
1100 }
1101
Tyler Gunn75958422015-04-15 14:23:42 -07001102 if (mVideoCallbacks.containsKey(binder)) {
1103 Log.i(this, "addVideoProvider - skipped; already present.");
1104 break;
1105 }
1106 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001107 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001108 }
1109 case MSG_REMOVE_VIDEO_CALLBACK: {
1110 IBinder binder = (IBinder) msg.obj;
1111 IVideoCallback callback = IVideoCallback.Stub
1112 .asInterface((IBinder) msg.obj);
1113 if (!mVideoCallbacks.containsKey(binder)) {
1114 Log.i(this, "removeVideoProvider - skipped; not present.");
1115 break;
1116 }
1117 mVideoCallbacks.remove(binder);
1118 break;
1119 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001120 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001121 {
1122 SomeArgs args = (SomeArgs) msg.obj;
1123 try {
1124 onSetCamera((String) args.arg1);
1125 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001126 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001127 } finally {
1128 args.recycle();
1129 }
1130 }
1131 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001132 case MSG_SET_PREVIEW_SURFACE:
1133 onSetPreviewSurface((Surface) msg.obj);
1134 break;
1135 case MSG_SET_DISPLAY_SURFACE:
1136 onSetDisplaySurface((Surface) msg.obj);
1137 break;
1138 case MSG_SET_DEVICE_ORIENTATION:
1139 onSetDeviceOrientation(msg.arg1);
1140 break;
1141 case MSG_SET_ZOOM:
1142 onSetZoom((Float) msg.obj);
1143 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001144 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1145 SomeArgs args = (SomeArgs) msg.obj;
1146 try {
1147 onSendSessionModifyRequest((VideoProfile) args.arg1,
1148 (VideoProfile) args.arg2);
1149 } finally {
1150 args.recycle();
1151 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001152 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001153 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001154 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1155 onSendSessionModifyResponse((VideoProfile) msg.obj);
1156 break;
1157 case MSG_REQUEST_CAMERA_CAPABILITIES:
1158 onRequestCameraCapabilities();
1159 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001160 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1161 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001162 break;
1163 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001164 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001165 break;
1166 default:
1167 break;
1168 }
1169 }
1170 }
1171
1172 /**
1173 * IVideoProvider stub implementation.
1174 */
1175 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001176 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001177 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001178 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1179 }
1180
1181 public void removeVideoCallback(IBinder videoCallbackBinder) {
1182 mMessageHandler.obtainMessage(
1183 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001184 }
1185
Tyler Gunn159f35c2017-03-02 09:28:37 -08001186 public void setCamera(String cameraId, String callingPackageName,
1187 int targetSdkVersion) {
1188
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001189 SomeArgs args = SomeArgs.obtain();
1190 args.arg1 = cameraId;
1191 // Propagate the calling package; originally determined in
1192 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1193 // process.
1194 args.arg2 = callingPackageName;
1195 // Pass along the uid and pid of the calling app; this gets lost when we put the
1196 // message onto the handler. These are required for Telecom to perform a permission
1197 // check to see if the calling app is able to use the camera.
1198 args.argi1 = Binder.getCallingUid();
1199 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001200 // Pass along the target SDK version of the calling InCallService. This is used to
1201 // maintain backwards compatibility of the API for older callers.
1202 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001203 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001204 }
1205
1206 public void setPreviewSurface(Surface surface) {
1207 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1208 }
1209
1210 public void setDisplaySurface(Surface surface) {
1211 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1212 }
1213
1214 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001215 mMessageHandler.obtainMessage(
1216 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001217 }
1218
1219 public void setZoom(float value) {
1220 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1221 }
1222
Tyler Gunn45382162015-05-06 08:52:27 -07001223 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1224 SomeArgs args = SomeArgs.obtain();
1225 args.arg1 = fromProfile;
1226 args.arg2 = toProfile;
1227 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001228 }
1229
1230 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1231 mMessageHandler.obtainMessage(
1232 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1233 }
1234
1235 public void requestCameraCapabilities() {
1236 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1237 }
1238
1239 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001240 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001241 }
1242
Yorke Lee32f24732015-05-12 16:18:03 -07001243 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001244 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1245 }
1246 }
1247
1248 public VideoProvider() {
1249 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001250 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001251 }
1252
1253 /**
1254 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1255 *
1256 * @param looper The looper.
1257 * @hide
1258 */
1259 public VideoProvider(Looper looper) {
1260 mBinder = new VideoProvider.VideoProviderBinder();
1261 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001262 }
1263
1264 /**
1265 * Returns binder object which can be used across IPC methods.
1266 * @hide
1267 */
1268 public final IVideoProvider getInterface() {
1269 return mBinder;
1270 }
1271
1272 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001273 * Sets the camera to be used for the outgoing video.
1274 * <p>
1275 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1276 * camera via
1277 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1278 * <p>
1279 * Sent from the {@link InCallService} via
1280 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001281 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001282 * @param cameraId The id of the camera (use ids as reported by
1283 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001284 */
1285 public abstract void onSetCamera(String cameraId);
1286
1287 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001288 * Sets the camera to be used for the outgoing video.
1289 * <p>
1290 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1291 * camera via
1292 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1293 * <p>
1294 * This prototype is used internally to ensure that the calling package name, UID and PID
1295 * are sent to Telecom so that can perform a camera permission check on the caller.
1296 * <p>
1297 * Sent from the {@link InCallService} via
1298 * {@link InCallService.VideoCall#setCamera(String)}.
1299 *
1300 * @param cameraId The id of the camera (use ids as reported by
1301 * {@link CameraManager#getCameraIdList()}).
1302 * @param callingPackageName The AppOpps package name of the caller.
1303 * @param callingUid The UID of the caller.
1304 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001305 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001306 * @hide
1307 */
1308 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001309 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001310
1311 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001312 * Sets the surface to be used for displaying a preview of what the user's camera is
1313 * currently capturing. When video transmission is enabled, this is the video signal which
1314 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001315 * <p>
1316 * Sent from the {@link InCallService} via
1317 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001318 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001319 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001320 */
1321 public abstract void onSetPreviewSurface(Surface surface);
1322
1323 /**
1324 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001325 * <p>
1326 * Sent from the {@link InCallService} via
1327 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001328 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001329 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001330 */
1331 public abstract void onSetDisplaySurface(Surface surface);
1332
1333 /**
1334 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1335 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001336 * <p>
1337 * Sent from the {@link InCallService} via
1338 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001339 *
1340 * @param rotation The device orientation, in degrees.
1341 */
1342 public abstract void onSetDeviceOrientation(int rotation);
1343
1344 /**
1345 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001346 * <p>
1347 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001348 *
1349 * @param value The camera zoom ratio.
1350 */
1351 public abstract void onSetZoom(float value);
1352
1353 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001354 * Issues a request to modify the properties of the current video session.
1355 * <p>
1356 * Example scenarios include: requesting an audio-only call to be upgraded to a
1357 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1358 * when the {@link InCallService} is no longer the foreground application.
1359 * <p>
1360 * If the {@link VideoProvider} determines a request to be invalid, it should call
1361 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1362 * invalid request back to the {@link InCallService}.
1363 * <p>
1364 * Where a request requires confirmation from the user of the peer device, the
1365 * {@link VideoProvider} must communicate the request to the peer device and handle the
1366 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1367 * is used to inform the {@link InCallService} of the result of the request.
1368 * <p>
1369 * Sent from the {@link InCallService} via
1370 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001371 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001372 * @param fromProfile The video profile prior to the request.
1373 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001374 */
Tyler Gunn45382162015-05-06 08:52:27 -07001375 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1376 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001377
Tyler Gunnb702ef82015-05-29 11:51:53 -07001378 /**
1379 * Provides a response to a request to change the current video session properties.
1380 * <p>
1381 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1382 * video call, could decline the request and keep the call as audio-only.
1383 * In such a scenario, the {@code responseProfile} would have a video state of
1384 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1385 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1386 * <p>
1387 * Sent from the {@link InCallService} via
1388 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1389 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1390 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001391 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001392 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001393 */
1394 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1395
1396 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001397 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1398 * <p>
1399 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1400 * camera via
1401 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1402 * <p>
1403 * Sent from the {@link InCallService} via
1404 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001405 */
1406 public abstract void onRequestCameraCapabilities();
1407
1408 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001409 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1410 * video component of the current {@link Connection}.
1411 * <p>
1412 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1413 * via {@link VideoProvider#setCallDataUsage(long)}.
1414 * <p>
1415 * Sent from the {@link InCallService} via
1416 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001417 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001418 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001419
1420 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001421 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1422 * the peer device when the video signal is paused.
1423 * <p>
1424 * Sent from the {@link InCallService} via
1425 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001426 *
1427 * @param uri URI of image to display.
1428 */
Yorke Lee32f24732015-05-12 16:18:03 -07001429 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001430
1431 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001432 * Used to inform listening {@link InCallService} implementations when the
1433 * {@link VideoProvider} receives a session modification request.
1434 * <p>
1435 * Received by the {@link InCallService} via
1436 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001437 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001438 * @param videoProfile The requested video profile.
1439 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001440 */
1441 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001442 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001443 for (IVideoCallback callback : mVideoCallbacks.values()) {
1444 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001445 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001446 } catch (RemoteException ignored) {
1447 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001448 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001449 }
1450 }
1451 }
1452
1453 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001454 * Used to inform listening {@link InCallService} implementations when the
1455 * {@link VideoProvider} receives a response to a session modification request.
1456 * <p>
1457 * Received by the {@link InCallService} via
1458 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1459 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001460 *
1461 * @param status Status of the session modify request. Valid values are
1462 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1463 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001464 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1465 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1466 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1467 * @param requestedProfile The original request which was sent to the peer device.
1468 * @param responseProfile The actual profile changes agreed to by the peer device.
1469 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001470 */
1471 public void receiveSessionModifyResponse(int status,
1472 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001473 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001474 for (IVideoCallback callback : mVideoCallbacks.values()) {
1475 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001476 callback.receiveSessionModifyResponse(status, requestedProfile,
1477 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001478 } catch (RemoteException ignored) {
1479 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001480 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001481 }
1482 }
1483 }
1484
1485 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001486 * Used to inform listening {@link InCallService} implementations when the
1487 * {@link VideoProvider} reports a call session event.
1488 * <p>
1489 * Received by the {@link InCallService} via
1490 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001491 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001492 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1493 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1494 * {@link VideoProvider#SESSION_EVENT_TX_START},
1495 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1496 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001497 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1498 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001499 */
1500 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001501 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001502 for (IVideoCallback callback : mVideoCallbacks.values()) {
1503 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001504 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001505 } catch (RemoteException ignored) {
1506 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001507 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001508 }
1509 }
1510 }
1511
1512 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001513 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1514 * peer's video have changed.
1515 * <p>
1516 * This could occur if, for example, the peer rotates their device, changing the aspect
1517 * ratio of the video, or if the user switches between the back and front cameras.
1518 * <p>
1519 * Received by the {@link InCallService} via
1520 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001521 *
1522 * @param width The updated peer video width.
1523 * @param height The updated peer video height.
1524 */
1525 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001526 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001527 for (IVideoCallback callback : mVideoCallbacks.values()) {
1528 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001529 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001530 } catch (RemoteException ignored) {
1531 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001532 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001533 }
1534 }
1535 }
1536
1537 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001538 * Used to inform listening {@link InCallService} implementations when the data usage of the
1539 * video associated with the current {@link Connection} has changed.
1540 * <p>
1541 * This could be in response to a preview request via
1542 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001543 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1544 * 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 -07001545 * <p>
1546 * Received by the {@link InCallService} via
1547 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001548 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001549 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1550 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001551 */
Yorke Lee32f24732015-05-12 16:18:03 -07001552 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001553 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001554 for (IVideoCallback callback : mVideoCallbacks.values()) {
1555 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001556 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001557 } catch (RemoteException ignored) {
1558 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001559 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001560 }
1561 }
1562 }
1563
1564 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001565 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001566 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001567 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001568 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1569 * @hide
1570 */
1571 public void changeCallDataUsage(long dataUsage) {
1572 setCallDataUsage(dataUsage);
1573 }
1574
1575 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001576 * Used to inform listening {@link InCallService} implementations when the capabilities of
1577 * the current camera have changed.
1578 * <p>
1579 * The {@link VideoProvider} should call this in response to
1580 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1581 * changed via {@link VideoProvider#onSetCamera(String)}.
1582 * <p>
1583 * Received by the {@link InCallService} via
1584 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1585 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001586 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001587 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001588 */
Yorke Lee400470f2015-05-12 13:31:25 -07001589 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001590 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001591 for (IVideoCallback callback : mVideoCallbacks.values()) {
1592 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001593 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001594 } catch (RemoteException ignored) {
1595 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001596 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001597 }
1598 }
1599 }
Rekha Kumar07366812015-03-24 16:42:31 -07001600
1601 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001602 * Used to inform listening {@link InCallService} implementations when the video quality
1603 * of the call has changed.
1604 * <p>
1605 * Received by the {@link InCallService} via
1606 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001607 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001608 * @param videoQuality The updated video quality. Valid values:
1609 * {@link VideoProfile#QUALITY_HIGH},
1610 * {@link VideoProfile#QUALITY_MEDIUM},
1611 * {@link VideoProfile#QUALITY_LOW},
1612 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001613 */
1614 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001615 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001616 for (IVideoCallback callback : mVideoCallbacks.values()) {
1617 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001618 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001619 } catch (RemoteException ignored) {
1620 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001621 }
Rekha Kumar07366812015-03-24 16:42:31 -07001622 }
1623 }
1624 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001625
1626 /**
1627 * Returns a string representation of a call session event.
1628 *
1629 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1630 * @return String representation of the call session event.
1631 * @hide
1632 */
1633 public static String sessionEventToString(int event) {
1634 switch (event) {
1635 case SESSION_EVENT_CAMERA_FAILURE:
1636 return SESSION_EVENT_CAMERA_FAILURE_STR;
1637 case SESSION_EVENT_CAMERA_READY:
1638 return SESSION_EVENT_CAMERA_READY_STR;
1639 case SESSION_EVENT_RX_PAUSE:
1640 return SESSION_EVENT_RX_PAUSE_STR;
1641 case SESSION_EVENT_RX_RESUME:
1642 return SESSION_EVENT_RX_RESUME_STR;
1643 case SESSION_EVENT_TX_START:
1644 return SESSION_EVENT_TX_START_STR;
1645 case SESSION_EVENT_TX_STOP:
1646 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001647 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1648 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001649 default:
1650 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1651 }
1652 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001653 }
1654
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001655 private final Listener mConnectionDeathListener = new Listener() {
1656 @Override
1657 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001658 if (mConferenceables.remove(c)) {
1659 fireOnConferenceableConnectionsChanged();
1660 }
1661 }
1662 };
1663
1664 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1665 @Override
1666 public void onDestroyed(Conference c) {
1667 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001668 fireOnConferenceableConnectionsChanged();
1669 }
1670 }
1671 };
1672
Jay Shrauner229e3822014-08-15 09:23:07 -07001673 /**
1674 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1675 * load factor before resizing, 1 means we only expect a single thread to
1676 * access the map so make only a single shard
1677 */
1678 private final Set<Listener> mListeners = Collections.newSetFromMap(
1679 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001680 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1681 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001682 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001683
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001684 // The internal telecom call ID associated with this connection.
1685 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001686 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001687 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001688 private Uri mAddress;
1689 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001690 private String mCallerDisplayName;
1691 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001692 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001693 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001694 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001695 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001696 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001697 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001698 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001699 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001700 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001701 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001702 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001703 private Conference mConference;
1704 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001705 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001706 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001707
1708 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001709 * Tracks the key set for the extras bundle provided on the last invocation of
1710 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1711 * keys which were set previously but are no longer present in the replacement Bundle.
1712 */
1713 private Set<String> mPreviousExtraKeys;
1714
1715 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001716 * Create a new Connection.
1717 */
Santos Cordonf2951102014-07-20 19:06:29 -07001718 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001719
1720 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001721 * Returns the Telecom internal call ID associated with this connection. Should only be used
1722 * for debugging and tracing purposes.
1723 *
1724 * @return The Telecom call ID.
1725 * @hide
1726 */
1727 public final String getTelecomCallId() {
1728 return mTelecomCallId;
1729 }
1730
1731 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001732 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001733 */
Andrew Lee100e2932014-09-08 15:34:24 -07001734 public final Uri getAddress() {
1735 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001736 }
1737
1738 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001739 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001740 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001741 */
Andrew Lee100e2932014-09-08 15:34:24 -07001742 public final int getAddressPresentation() {
1743 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001744 }
1745
1746 /**
1747 * @return The caller display name (CNAP).
1748 */
1749 public final String getCallerDisplayName() {
1750 return mCallerDisplayName;
1751 }
1752
1753 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001754 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001755 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001756 */
1757 public final int getCallerDisplayNamePresentation() {
1758 return mCallerDisplayNamePresentation;
1759 }
1760
1761 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001762 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001763 */
1764 public final int getState() {
1765 return mState;
1766 }
1767
1768 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001769 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001770 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1771 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1772 * {@link VideoProfile#STATE_TX_ENABLED},
1773 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001774 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001775 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001776 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001777 */
1778 public final int getVideoState() {
1779 return mVideoState;
1780 }
1781
1782 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001783 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001784 * being routed by the system. This is {@code null} if this Connection
1785 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001786 * @deprecated Use {@link #getCallAudioState()} instead.
1787 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001788 */
Yorke Lee4af59352015-05-13 14:14:54 -07001789 @SystemApi
1790 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001791 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001792 if (mCallAudioState == null) {
1793 return null;
1794 }
Yorke Lee4af59352015-05-13 14:14:54 -07001795 return new AudioState(mCallAudioState);
1796 }
1797
1798 /**
1799 * @return The audio state of the connection, describing how its audio is currently
1800 * being routed by the system. This is {@code null} if this Connection
1801 * does not directly know about its audio state.
1802 */
1803 public final CallAudioState getCallAudioState() {
1804 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001805 }
1806
1807 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001808 * @return The conference that this connection is a part of. Null if it is not part of any
1809 * conference.
1810 */
1811 public final Conference getConference() {
1812 return mConference;
1813 }
1814
1815 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001816 * Returns whether this connection is requesting that the system play a ringback tone
1817 * on its behalf.
1818 */
Andrew Lee100e2932014-09-08 15:34:24 -07001819 public final boolean isRingbackRequested() {
1820 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001821 }
1822
1823 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001824 * @return True if the connection's audio mode is VOIP.
1825 */
1826 public final boolean getAudioModeIsVoip() {
1827 return mAudioModeIsVoip;
1828 }
1829
1830 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001831 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1832 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1833 * start time of the conference.
1834 *
1835 * @return The time at which the {@code Connnection} was connected.
1836 *
1837 * @hide
1838 */
1839 public final long getConnectTimeMillis() {
1840 return mConnectTimeMillis;
1841 }
1842
1843 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001844 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1845 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1846 * start time of the conference.
1847 *
1848 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
1849 * changes do not impact the call duration.
1850 *
1851 * @return The time at which the {@link Connection} was connected.
1852 *
1853 * @hide
1854 */
1855 public final long getConnectElapsedTimeMillis() {
1856 return mConnectElapsedTimeMillis;
1857 }
1858
1859 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001860 * @return The status hints for this connection.
1861 */
1862 public final StatusHints getStatusHints() {
1863 return mStatusHints;
1864 }
1865
1866 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001867 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001868 * <p>
1869 * Extras should be updated using {@link #putExtras(Bundle)}.
1870 * <p>
1871 * Telecom or an {@link InCallService} can also update the extras via
1872 * {@link android.telecom.Call#putExtras(Bundle)}, and
1873 * {@link Call#removeExtras(List)}.
1874 * <p>
1875 * The connection is notified of changes to the extras made by Telecom or an
1876 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001877 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001878 * @return The extras associated with this connection.
1879 */
1880 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001881 Bundle extras = null;
1882 synchronized (mExtrasLock) {
1883 if (mExtras != null) {
1884 extras = new Bundle(mExtras);
1885 }
1886 }
1887 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001888 }
1889
1890 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001891 * Assign a listener to be notified of state changes.
1892 *
1893 * @param l A listener.
1894 * @return This Connection.
1895 *
1896 * @hide
1897 */
1898 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001899 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001900 return this;
1901 }
1902
1903 /**
1904 * Remove a previously assigned listener that was being notified of state changes.
1905 *
1906 * @param l A Listener.
1907 * @return This Connection.
1908 *
1909 * @hide
1910 */
1911 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001912 if (l != null) {
1913 mListeners.remove(l);
1914 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001915 return this;
1916 }
1917
1918 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001919 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001920 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001921 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001922 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001923 }
1924
1925 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001926 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1927 * ONLY for debugging purposes.
1928 *
1929 * @param callId The telecom call ID.
1930 * @hide
1931 */
1932 public void setTelecomCallId(String callId) {
1933 mTelecomCallId = callId;
1934 }
1935
1936 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001937 * Inform this Connection that the state of its audio output has been changed externally.
1938 *
1939 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001940 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001941 */
Yorke Lee4af59352015-05-13 14:14:54 -07001942 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001943 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001944 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001945 mCallAudioState = state;
1946 onAudioStateChanged(getAudioState());
1947 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001948 }
1949
1950 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001951 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001952 * @return A string representation of the value.
1953 */
1954 public static String stateToString(int state) {
1955 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001956 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001957 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001958 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001959 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001960 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001961 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001962 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001963 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001964 case STATE_PULLING_CALL:
1965 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001966 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001967 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001968 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001969 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001970 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001971 return "DISCONNECTED";
1972 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001973 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001974 return "UNKNOWN";
1975 }
1976 }
1977
1978 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001979 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001980 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001981 public final int getConnectionCapabilities() {
1982 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001983 }
1984
1985 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001986 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1987 */
1988 public final int getConnectionProperties() {
1989 return mConnectionProperties;
1990 }
1991
1992 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001993 * Returns the connection's supported audio routes.
1994 *
1995 * @hide
1996 */
1997 public final int getSupportedAudioRoutes() {
1998 return mSupportedAudioRoutes;
1999 }
2000
2001 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002002 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002003 *
Andrew Lee100e2932014-09-08 15:34:24 -07002004 * @param address The new address.
2005 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002006 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002007 */
Andrew Lee100e2932014-09-08 15:34:24 -07002008 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002009 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002010 Log.d(this, "setAddress %s", address);
2011 mAddress = address;
2012 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002013 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002014 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002015 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002016 }
2017
2018 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002019 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002020 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002021 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002022 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002023 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002024 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002025 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002026 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002027 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002028 mCallerDisplayName = callerDisplayName;
2029 mCallerDisplayNamePresentation = presentation;
2030 for (Listener l : mListeners) {
2031 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2032 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002033 }
2034
2035 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002036 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002037 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2038 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2039 * {@link VideoProfile#STATE_TX_ENABLED},
2040 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002041 *
2042 * @param videoState The new video state.
2043 */
2044 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002045 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002046 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002047 mVideoState = videoState;
2048 for (Listener l : mListeners) {
2049 l.onVideoStateChanged(this, mVideoState);
2050 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002051 }
2052
2053 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002054 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002055 * communicate).
2056 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002057 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002058 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002059 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002060 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002061 }
2062
2063 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002064 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002065 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002066 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002067 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002068 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002069 }
2070
2071 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002072 * Sets state to initializing (this Connection is not yet ready to be used).
2073 */
2074 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002075 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002076 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002077 }
2078
2079 /**
2080 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2081 */
2082 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002083 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002084 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002085 }
2086
2087 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002088 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002089 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002090 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002091 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002092 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002093 }
2094
2095 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002096 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2097 * device). Only applicable for {@link Connection}s with
2098 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2099 */
2100 public final void setPulling() {
2101 checkImmutable();
2102 setState(STATE_PULLING_CALL);
2103 }
2104
2105 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002106 * Sets state to be on hold.
2107 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002108 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002109 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002110 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002111 }
2112
2113 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002114 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002115 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002116 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002117 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002118 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002119 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002120 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002121 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002122 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002123 }
2124
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002125 public final VideoProvider getVideoProvider() {
2126 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002127 }
2128
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002129 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002130 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002131 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002132 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002133 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002134 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002135 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002136 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002137 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002138 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002139 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002140 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002141 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002142 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002143 }
2144
2145 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002146 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2147 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2148 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2149 * to send an {@link #onPostDialContinue(boolean)} signal.
2150 *
2151 * @param remaining The DTMF character sequence remaining to be emitted once the
2152 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2153 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002154 */
2155 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002156 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002157 for (Listener l : mListeners) {
2158 l.onPostDialWait(this, remaining);
2159 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002160 }
2161
2162 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002163 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2164 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002165 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002166 *
2167 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002168 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002169 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002170 checkImmutable();
2171 for (Listener l : mListeners) {
2172 l.onPostDialChar(this, nextChar);
2173 }
2174 }
2175
2176 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002177 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002178 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002179 *
2180 * @param ringback Whether the ringback tone is to be played.
2181 */
Andrew Lee100e2932014-09-08 15:34:24 -07002182 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002183 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002184 if (mRingbackRequested != ringback) {
2185 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002186 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002187 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002188 }
2189 }
Ihab Awadf8358972014-05-28 16:46:42 -07002190 }
2191
2192 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002193 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002194 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002195 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002196 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002197 public final void setConnectionCapabilities(int connectionCapabilities) {
2198 checkImmutable();
2199 if (mConnectionCapabilities != connectionCapabilities) {
2200 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002201 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002202 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002203 }
2204 }
Santos Cordonb6939982014-06-04 20:20:58 -07002205 }
2206
2207 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002208 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2209 *
2210 * @param connectionProperties The new connection properties.
2211 */
2212 public final void setConnectionProperties(int connectionProperties) {
2213 checkImmutable();
2214 if (mConnectionProperties != connectionProperties) {
2215 mConnectionProperties = connectionProperties;
2216 for (Listener l : mListeners) {
2217 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2218 }
2219 }
2220 }
2221
2222 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002223 * Sets the supported audio routes.
2224 *
2225 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2226 * See {@link CallAudioState}
2227 * @hide
2228 */
2229 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2230 if ((supportedAudioRoutes
2231 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2232 throw new IllegalArgumentException(
2233 "supported audio routes must include either speaker or earpiece");
2234 }
2235
2236 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2237 mSupportedAudioRoutes = supportedAudioRoutes;
2238 for (Listener l : mListeners) {
2239 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2240 }
2241 }
2242 }
2243
2244 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002245 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002246 */
Evan Charlton36a71342014-07-19 16:31:02 -07002247 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002248 for (Listener l : mListeners) {
2249 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002250 }
Santos Cordonb6939982014-06-04 20:20:58 -07002251 }
2252
2253 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002254 * Requests that the framework use VOIP audio mode for this connection.
2255 *
2256 * @param isVoip True if the audio mode is VOIP.
2257 */
2258 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002259 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002260 mAudioModeIsVoip = isVoip;
2261 for (Listener l : mListeners) {
2262 l.onAudioModeIsVoipChanged(this, isVoip);
2263 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002264 }
2265
2266 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002267 * Sets the time at which a call became active on this Connection. This is set only
2268 * when a conference call becomes active on this connection.
2269 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002270 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2271 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002272 *
2273 * @hide
2274 */
2275 public final void setConnectTimeMillis(long connectTimeMillis) {
2276 mConnectTimeMillis = connectTimeMillis;
2277 }
2278
2279 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002280 * Sets the time at which a call became active on this Connection. This is set only
2281 * when a conference call becomes active on this connection.
2282 *
2283 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2284 * {@link SystemClock#elapsedRealtime()}.
2285 *
2286 * @hide
2287 */
2288 public final void setConnectElapsedTimeMillis(long connectElapsedTimeMillis) {
2289 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2290 }
2291
2292 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002293 * Sets the label and icon status to display in the in-call UI.
2294 *
2295 * @param statusHints The status label and icon to set.
2296 */
2297 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002298 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002299 mStatusHints = statusHints;
2300 for (Listener l : mListeners) {
2301 l.onStatusHintsChanged(this, statusHints);
2302 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002303 }
2304
2305 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002306 * Sets the connections with which this connection can be conferenced.
2307 *
2308 * @param conferenceableConnections The set of connections this connection can conference with.
2309 */
2310 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002311 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002312 clearConferenceableList();
2313 for (Connection c : conferenceableConnections) {
2314 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2315 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002316 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002317 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002318 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002319 }
2320 }
2321 fireOnConferenceableConnectionsChanged();
2322 }
2323
2324 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002325 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2326 * or conferences with which this connection can be conferenced.
2327 *
2328 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002329 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002330 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002331 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002332 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002333 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2334 // small amount of items here.
2335 if (!mConferenceables.contains(c)) {
2336 if (c instanceof Connection) {
2337 Connection connection = (Connection) c;
2338 connection.addConnectionListener(mConnectionDeathListener);
2339 } else if (c instanceof Conference) {
2340 Conference conference = (Conference) c;
2341 conference.addListener(mConferenceDeathListener);
2342 }
2343 mConferenceables.add(c);
2344 }
2345 }
2346 fireOnConferenceableConnectionsChanged();
2347 }
2348
2349 /**
2350 * Returns the connections or conferences with which this connection can be conferenced.
2351 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002352 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002353 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002354 }
2355
Yorke Lee53463962015-08-04 16:07:19 -07002356 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002357 * @hide
2358 */
2359 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002360 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002361 if (mConnectionService != null) {
2362 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2363 "which is already associated with another ConnectionService.");
2364 } else {
2365 mConnectionService = connectionService;
2366 }
2367 }
2368
2369 /**
2370 * @hide
2371 */
2372 public final void unsetConnectionService(ConnectionService connectionService) {
2373 if (mConnectionService != connectionService) {
2374 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2375 "that does not belong to the ConnectionService.");
2376 } else {
2377 mConnectionService = null;
2378 }
2379 }
2380
2381 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002382 * @hide
2383 */
2384 public final ConnectionService getConnectionService() {
2385 return mConnectionService;
2386 }
2387
2388 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002389 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002390 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002391 *
2392 * @param conference The conference.
2393 * @return {@code true} if the conference was successfully set.
2394 * @hide
2395 */
2396 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002397 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002398 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002399 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002400 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002401 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2402 fireConferenceChanged();
2403 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002404 return true;
2405 }
2406 return false;
2407 }
2408
2409 /**
2410 * Resets the conference that this connection is a part of.
2411 * @hide
2412 */
2413 public final void resetConference() {
2414 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002415 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002416 mConference = null;
2417 fireConferenceChanged();
2418 }
2419 }
2420
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002421 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002422 * Set some extras that can be associated with this {@code Connection}.
2423 * <p>
2424 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2425 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2426 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002427 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2428 * {@link #removeExtras(String...)} methods to modify the extras.
2429 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002430 * 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 -07002431 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2432 *
2433 * @param extras The extras associated with this {@code Connection}.
2434 */
2435 public final void setExtras(@Nullable Bundle extras) {
2436 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002437
2438 // Add/replace any new or changed extras values.
2439 putExtras(extras);
2440
2441 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2442 // the current one and remove any keys that went away.
2443 if (mPreviousExtraKeys != null) {
2444 List<String> toRemove = new ArrayList<String>();
2445 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002446 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002447 toRemove.add(oldKey);
2448 }
2449 }
2450 if (!toRemove.isEmpty()) {
2451 removeExtras(toRemove);
2452 }
2453 }
2454
2455 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2456 // called we can see if the caller has removed any extras values.
2457 if (mPreviousExtraKeys == null) {
2458 mPreviousExtraKeys = new ArraySet<String>();
2459 }
2460 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002461 if (extras != null) {
2462 mPreviousExtraKeys.addAll(extras.keySet());
2463 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002464 }
2465
2466 /**
2467 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2468 * added.
2469 * <p>
2470 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2471 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2472 *
2473 * @param extras The extras to add.
2474 */
2475 public final void putExtras(@NonNull Bundle extras) {
2476 checkImmutable();
2477 if (extras == null) {
2478 return;
2479 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002480 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2481 // the listeners.
2482 Bundle listenerExtras;
2483 synchronized (mExtrasLock) {
2484 if (mExtras == null) {
2485 mExtras = new Bundle();
2486 }
2487 mExtras.putAll(extras);
2488 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002489 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002490 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002491 // Create a new clone of the extras for each listener so that they don't clobber
2492 // each other
2493 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002494 }
2495 }
2496
2497 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002498 * Adds a boolean extra to this {@code Connection}.
2499 *
2500 * @param key The extra key.
2501 * @param value The value.
2502 * @hide
2503 */
2504 public final void putExtra(String key, boolean value) {
2505 Bundle newExtras = new Bundle();
2506 newExtras.putBoolean(key, value);
2507 putExtras(newExtras);
2508 }
2509
2510 /**
2511 * Adds an integer extra to this {@code Connection}.
2512 *
2513 * @param key The extra key.
2514 * @param value The value.
2515 * @hide
2516 */
2517 public final void putExtra(String key, int value) {
2518 Bundle newExtras = new Bundle();
2519 newExtras.putInt(key, value);
2520 putExtras(newExtras);
2521 }
2522
2523 /**
2524 * Adds a string extra to this {@code Connection}.
2525 *
2526 * @param key The extra key.
2527 * @param value The value.
2528 * @hide
2529 */
2530 public final void putExtra(String key, String value) {
2531 Bundle newExtras = new Bundle();
2532 newExtras.putString(key, value);
2533 putExtras(newExtras);
2534 }
2535
2536 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002537 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002538 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002539 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002540 */
2541 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002542 synchronized (mExtrasLock) {
2543 if (mExtras != null) {
2544 for (String key : keys) {
2545 mExtras.remove(key);
2546 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002547 }
2548 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002549 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002550 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002551 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002552 }
2553 }
2554
2555 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002556 * Removes extras from this {@code Connection}.
2557 *
2558 * @param keys The keys of the extras to remove.
2559 */
2560 public final void removeExtras(String ... keys) {
2561 removeExtras(Arrays.asList(keys));
2562 }
2563
2564 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002565 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2566 * be change to the {@link #getCallAudioState()}.
2567 * <p>
2568 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2569 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2570 * <p>
2571 * See also {@link InCallService#setAudioRoute(int)}.
2572 *
2573 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2574 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2575 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2576 */
2577 public final void setAudioRoute(int route) {
2578 for (Listener l : mListeners) {
2579 l.onAudioRouteChanged(this, route);
2580 }
2581 }
2582
2583 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002584 * Informs listeners that a previously requested RTT session via
2585 * {@link ConnectionRequest#isRequestingRtt()} or
2586 * {@link #onStartRtt(ParcelFileDescriptor, ParcelFileDescriptor)} has succeeded.
2587 * @hide
2588 */
Hall Liuffa4a812017-03-02 16:11:00 -08002589 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002590 public final void sendRttInitiationSuccess() {
Hall Liuffa4a812017-03-02 16:11:00 -08002591 setRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08002592 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2593 }
2594
2595 /**
2596 * Informs listeners that a previously requested RTT session via
2597 * {@link ConnectionRequest#isRequestingRtt()} or
2598 * {@link #onStartRtt(ParcelFileDescriptor, ParcelFileDescriptor)}
2599 * has failed.
2600 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2601 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
2602 * @hide
2603 */
Hall Liuffa4a812017-03-02 16:11:00 -08002604 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002605 public final void sendRttInitiationFailure(int reason) {
Hall Liuffa4a812017-03-02 16:11:00 -08002606 unsetRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08002607 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2608 }
2609
2610 /**
2611 * Informs listeners that a currently active RTT session has been terminated by the remote
2612 * side of the coll.
2613 * @hide
2614 */
Hall Liuffa4a812017-03-02 16:11:00 -08002615 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002616 public final void sendRttSessionRemotelyTerminated() {
2617 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2618 }
2619
2620 /**
2621 * Informs listeners that the remote side of the call has requested an upgrade to include an
2622 * RTT session in the call.
2623 * @hide
2624 */
Hall Liuffa4a812017-03-02 16:11:00 -08002625 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002626 public final void sendRemoteRttRequest() {
2627 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2628 }
2629
2630 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002631 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002632 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002633 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002634 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2635 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002636 */
Yorke Lee4af59352015-05-13 14:14:54 -07002637 @SystemApi
2638 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002639 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002640
2641 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002642 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2643 *
2644 * @param state The new connection audio state.
2645 */
2646 public void onCallAudioStateChanged(CallAudioState state) {}
2647
2648 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002649 * Notifies this Connection of an internal state change. This method is called after the
2650 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002651 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002652 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002653 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002654 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002655
2656 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002657 * Notifies this Connection of a request to play a DTMF tone.
2658 *
2659 * @param c A DTMF character.
2660 */
Santos Cordonf2951102014-07-20 19:06:29 -07002661 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002662
2663 /**
2664 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2665 */
Santos Cordonf2951102014-07-20 19:06:29 -07002666 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002667
2668 /**
2669 * Notifies this Connection of a request to disconnect.
2670 */
Santos Cordonf2951102014-07-20 19:06:29 -07002671 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002672
2673 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002674 * Notifies this Connection of a request to disconnect a participant of the conference managed
2675 * by the connection.
2676 *
2677 * @param endpoint the {@link Uri} of the participant to disconnect.
2678 * @hide
2679 */
2680 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2681
2682 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002683 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002684 */
Santos Cordonf2951102014-07-20 19:06:29 -07002685 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002686
2687 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002688 * Notifies this Connection of a request to abort.
2689 */
Santos Cordonf2951102014-07-20 19:06:29 -07002690 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002691
2692 /**
2693 * Notifies this Connection of a request to hold.
2694 */
Santos Cordonf2951102014-07-20 19:06:29 -07002695 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002696
2697 /**
2698 * Notifies this Connection of a request to exit a hold state.
2699 */
Santos Cordonf2951102014-07-20 19:06:29 -07002700 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002701
2702 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002703 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002704 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002705 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002706 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002707 */
Santos Cordonf2951102014-07-20 19:06:29 -07002708 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002709
2710 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002711 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002712 * a request to accept.
2713 */
2714 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002715 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002716 }
2717
2718 /**
2719 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002720 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002721 */
Santos Cordonf2951102014-07-20 19:06:29 -07002722 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002723
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002724 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002725 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2726 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002727 */
2728 public void onReject(String replyMessage) {}
2729
2730 /**
Bryce Leecac50772015-11-17 15:13:29 -08002731 * Notifies the Connection of a request to silence the ringer.
2732 *
2733 * @hide
2734 */
2735 public void onSilence() {}
2736
2737 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002738 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2739 */
Santos Cordonf2951102014-07-20 19:06:29 -07002740 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002741
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002742 /**
2743 * Notifies this Connection of a request to pull an external call to the local device.
2744 * <p>
2745 * The {@link InCallService} issues a request to pull an external call to the local device via
2746 * {@link Call#pullExternalCall()}.
2747 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002748 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2749 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002750 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002751 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002752 */
2753 public void onPullExternalCall() {}
2754
2755 /**
2756 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2757 * <p>
2758 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2759 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002760 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2761 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2762 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2763 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2764 * not aware of.
2765 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002766 * See also {@link Call#sendCallEvent(String, Bundle)}.
2767 *
2768 * @param event The call event.
2769 * @param extras Extras associated with the call event.
2770 */
2771 public void onCallEvent(String event, Bundle extras) {}
2772
Tyler Gunndee56a82016-03-23 16:06:34 -07002773 /**
2774 * Notifies this {@link Connection} of a change to the extras made outside the
2775 * {@link ConnectionService}.
2776 * <p>
2777 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2778 * the {@link android.telecom.Call#putExtras(Bundle)} and
2779 * {@link Call#removeExtras(List)}.
2780 *
2781 * @param extras The new extras bundle.
2782 */
2783 public void onExtrasChanged(Bundle extras) {}
2784
Tyler Gunnf5035432017-01-09 09:43:12 -08002785 /**
2786 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2787 * displaying its incoming call user interface for the {@link Connection}.
2788 * <p>
2789 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2790 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2791 * should show its own incoming call user interface.
2792 * <p>
2793 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
2794 * regular {@link ConnectionService}, the Telecom framework will display its own incoming call
2795 * user interface to allow the user to choose whether to answer the new incoming call and
2796 * disconnect other ongoing calls, or to reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002797 * <p>
2798 * You should trigger the display of the incoming call user interface for your application by
2799 * showing a {@link Notification} with a full-screen {@link Intent} specified.
2800 * For example:
2801 * <pre><code>
2802 * // Create an intent which triggers your fullscreen incoming call user interface.
2803 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
2804 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
2805 * intent.setClass(context, YourIncomingCallActivity.class);
2806 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
2807 *
2808 * // Build the notification as an ongoing high priority item; this ensures it will show as
2809 * // a heads up notification which slides down over top of the current content.
2810 * final Notification.Builder builder = new Notification.Builder(context);
2811 * builder.setOngoing(true);
2812 * builder.setPriority(Notification.PRIORITY_HIGH);
2813 *
2814 * // Set notification content intent to take user to fullscreen UI if user taps on the
2815 * // notification body.
2816 * builder.setContentIntent(pendingIntent);
2817 * // Set full screen intent to trigger display of the fullscreen UI when the notification
2818 * // manager deems it appropriate.
2819 * builder.setFullScreenIntent(pendingIntent, true);
2820 *
2821 * // Setup notification content.
2822 * builder.setSmallIcon( yourIconResourceId );
2823 * builder.setContentTitle("Your notification title");
2824 * builder.setContentText("Your notification content.");
2825 *
2826 * // Use builder.addAction(..) to add buttons to answer or reject the call.
2827 *
2828 * NotificationManager notificationManager = mContext.getSystemService(
2829 * NotificationManager.class);
2830 * notificationManager.notify(YOUR_TAG, YOUR_ID, builder.build());
2831 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08002832 */
2833 public void onShowIncomingCallUi() {}
2834
Hall Liub64ac4c2017-02-06 10:49:48 -08002835 /**
2836 * Notifies this {@link Connection} that the user has requested an RTT session.
2837 * The connection service should call {@link #sendRttInitiationSuccess} or
2838 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
2839 * request, respectively.
2840 * @param rttTextStream The object that should be used to send text to or receive text from
2841 * the in-call app.
2842 * @hide
2843 */
Hall Liuffa4a812017-03-02 16:11:00 -08002844 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002845 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
2846
2847 /**
2848 * Notifies this {@link Connection} that it should terminate any existing RTT communication
2849 * channel. No response to Telecom is needed for this method.
2850 * @hide
2851 */
Hall Liuffa4a812017-03-02 16:11:00 -08002852 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002853 public void onStopRtt() {}
2854
2855 /**
2856 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
2857 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
2858 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
2859 * indicated by {@code rttTextStream} being {@code null}
2860 * @hide
2861 * @param rttTextStream The object that should be used to send text to or receive text from
2862 * the in-call app.
2863 */
Hall Liuffa4a812017-03-02 16:11:00 -08002864 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002865 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
2866
Hall Liuffa4a812017-03-02 16:11:00 -08002867 /**
2868 * Internal method to set {@link #PROPERTY_IS_RTT}.
2869 * @hide
2870 */
2871 void setRttProperty() {
2872 setConnectionProperties(getConnectionProperties() | PROPERTY_IS_RTT);
2873 }
2874
2875 /**
2876 * Internal method to un-set {@link #PROPERTY_IS_RTT}.
2877 * @hide
2878 */
2879 void unsetRttProperty() {
2880 setConnectionProperties(getConnectionProperties() & (~PROPERTY_IS_RTT));
2881 }
2882
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002883 static String toLogSafePhoneNumber(String number) {
2884 // For unknown number, log empty string.
2885 if (number == null) {
2886 return "";
2887 }
2888
2889 if (PII_DEBUG) {
2890 // When PII_DEBUG is true we emit PII.
2891 return number;
2892 }
2893
2894 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2895 // sanitized phone numbers.
2896 StringBuilder builder = new StringBuilder();
2897 for (int i = 0; i < number.length(); i++) {
2898 char c = number.charAt(i);
2899 if (c == '-' || c == '@' || c == '.') {
2900 builder.append(c);
2901 } else {
2902 builder.append('x');
2903 }
2904 }
2905 return builder.toString();
2906 }
2907
Ihab Awad542e0ea2014-05-16 10:22:16 -07002908 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002909 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002910 if (mState == STATE_DISCONNECTED && mState != state) {
2911 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002912 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002913 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002914 if (mState != state) {
2915 Log.d(this, "setState: %s", stateToString(state));
2916 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002917 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002918 for (Listener l : mListeners) {
2919 l.onStateChanged(this, state);
2920 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002921 }
2922 }
2923
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002924 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002925 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002926 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2927 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002928 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002929 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002930
2931 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002932 if (mImmutable) {
2933 throw new UnsupportedOperationException("Connection is immutable");
2934 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002935 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002936 }
2937
Evan Charltonbf11f982014-07-20 22:06:28 -07002938 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002939 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002940 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2941 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002942 * <p>
2943 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2944 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002945 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002946 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002947 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002948 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002949 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2950 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002951 }
2952
Evan Charltonbf11f982014-07-20 22:06:28 -07002953 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002954 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2955 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2956 * this should never be un-@hide-den.
2957 *
2958 * @hide
2959 */
2960 public void checkImmutable() {}
2961
2962 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002963 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2964 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2965 * that state. This connection should not be used for anything, and no other
2966 * {@code Connection}s should be attempted.
2967 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002968 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002969 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002970 * @return A {@code Connection} which indicates that the underlying connection should
2971 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002972 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002973 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002974 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002975 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002976
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002977 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002978 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002979 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002980 }
2981 }
2982
Santos Cordon823fd3c2014-08-07 18:35:18 -07002983 private final void fireConferenceChanged() {
2984 for (Listener l : mListeners) {
2985 l.onConferenceChanged(this, mConference);
2986 }
2987 }
2988
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002989 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002990 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002991 if (c instanceof Connection) {
2992 Connection connection = (Connection) c;
2993 connection.removeConnectionListener(mConnectionDeathListener);
2994 } else if (c instanceof Conference) {
2995 Conference conference = (Conference) c;
2996 conference.removeListener(mConferenceDeathListener);
2997 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002998 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002999 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003000 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003001
3002 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003003 * Handles a change to extras received from Telecom.
3004 *
3005 * @param extras The new extras.
3006 * @hide
3007 */
3008 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003009 Bundle b = null;
3010 synchronized (mExtrasLock) {
3011 mExtras = extras;
3012 if (mExtras != null) {
3013 b = new Bundle(mExtras);
3014 }
3015 }
3016 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003017 }
3018
3019 /**
Anthony Lee17455a32015-04-24 15:25:29 -07003020 * Notifies listeners that the merge request failed.
3021 *
3022 * @hide
3023 */
3024 protected final void notifyConferenceMergeFailed() {
3025 for (Listener l : mListeners) {
3026 l.onConferenceMergeFailed(this);
3027 }
3028 }
3029
3030 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08003031 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003032 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08003033 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003034 * @hide
3035 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08003036 protected final void updateConferenceParticipants(
3037 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003038 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08003039 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003040 }
3041 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003042
3043 /**
3044 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07003045 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003046 */
3047 protected void notifyConferenceStarted() {
3048 for (Listener l : mListeners) {
3049 l.onConferenceStarted();
3050 }
3051 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003052
3053 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07003054 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
3055 * be a part of a conference call.
3056 * @param isConferenceSupported {@code true} if the connection supports being part of a
3057 * conference call, {@code false} otherwise.
3058 * @hide
3059 */
3060 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
3061 for (Listener l : mListeners) {
3062 l.onConferenceSupportedChanged(this, isConferenceSupported);
3063 }
3064 }
3065
3066 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303067 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3068 * changed due to an emergency call being redialed.
3069 * @param pHandle The new PhoneAccountHandle for this connection.
3070 * @hide
3071 */
3072 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3073 for (Listener l : mListeners) {
3074 l.onPhoneAccountChanged(this, pHandle);
3075 }
3076 }
3077
3078 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003079 * Sends an event associated with this {@code Connection} with associated event extras to the
3080 * {@link InCallService}.
3081 * <p>
3082 * Connection events are used to communicate point in time information from a
3083 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3084 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3085 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3086 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3087 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3088 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3089 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3090 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3091 * <p>
3092 * Events are exposed to {@link InCallService} implementations via
3093 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3094 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003095 * 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 -07003096 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3097 * some events altogether.
3098 * <p>
3099 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3100 * conflicts between {@link ConnectionService} implementations. Further, custom
3101 * {@link ConnectionService} implementations shall not re-purpose events in the
3102 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3103 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3104 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3105 * {@code com.example.extra.MY_EXTRA}).
3106 * <p>
3107 * When defining events and the associated extras, it is important to keep their behavior
3108 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3109 * events/extras should me maintained to ensure backwards compatibility with older
3110 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003111 *
3112 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003113 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003114 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003115 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003116 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003117 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003118 }
3119 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003120}