blob: d7412a7012569b06aeed87331aa0ad41aa7fd4c1 [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
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700572 // Flag controlling whether PII is emitted into the logs
573 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
574
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800575 /**
576 * Whether the given capabilities support the specified capability.
577 *
578 * @param capabilities A capability bit field.
579 * @param capability The capability to check capabilities for.
580 * @return Whether the specified capability is supported.
581 * @hide
582 */
583 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800584 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800585 }
586
587 /**
588 * Whether the capabilities of this {@code Connection} supports the specified capability.
589 *
590 * @param capability The capability to check capabilities for.
591 * @return Whether the specified capability is supported.
592 * @hide
593 */
594 public boolean can(int capability) {
595 return can(mConnectionCapabilities, capability);
596 }
597
598 /**
599 * Removes the specified capability from the set of capabilities of this {@code Connection}.
600 *
601 * @param capability The capability to remove from the set.
602 * @hide
603 */
604 public void removeCapability(int capability) {
605 mConnectionCapabilities &= ~capability;
606 }
607
608 /**
609 * Adds the specified capability to the set of capabilities of this {@code Connection}.
610 *
611 * @param capability The capability to add to the set.
612 * @hide
613 */
614 public void addCapability(int capability) {
615 mConnectionCapabilities |= capability;
616 }
617
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700618 /**
619 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
620 *
621 * @param capabilities A capability bit field.
622 * @return A human readable string representation.
623 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800624 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700625 return capabilitiesToStringInternal(capabilities, true /* isLong */);
626 }
627
628 /**
629 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
630 * string.
631 *
632 * @param capabilities A capability bit field.
633 * @return A human readable string representation.
634 * @hide
635 */
636 public static String capabilitiesToStringShort(int capabilities) {
637 return capabilitiesToStringInternal(capabilities, false /* isLong */);
638 }
639
640 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800641 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700642 builder.append("[");
643 if (isLong) {
644 builder.append("Capabilities:");
645 }
646
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800647 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700648 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800649 }
650 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700651 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800652 }
653 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700654 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800655 }
656 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700657 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800658 }
659 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700660 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800661 }
662 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700663 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800664 }
665 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700666 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800667 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700668 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700669 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700670 }
671 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700672 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700673 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700674 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700675 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800676 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700677 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700678 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700679 }
680 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700681 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700682 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700683 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700684 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800685 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800686 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700687 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800688 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500689 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700690 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500691 }
Rekha Kumar07366812015-03-24 16:42:31 -0700692 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700693 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700694 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700695 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700696 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700697 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700698 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700699 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700700 }
Bryce Lee81901682015-08-28 16:38:02 -0700701 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700702 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700703 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700704 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700705 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700706 }
Bryce Lee81901682015-08-28 16:38:02 -0700707
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800708 builder.append("]");
709 return builder.toString();
710 }
711
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700712 /**
713 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
714 *
715 * @param properties A property bit field.
716 * @return A human readable string representation.
717 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700718 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700719 return propertiesToStringInternal(properties, true /* isLong */);
720 }
721
722 /**
723 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
724 *
725 * @param properties A property bit field.
726 * @return A human readable string representation.
727 * @hide
728 */
729 public static String propertiesToStringShort(int properties) {
730 return propertiesToStringInternal(properties, false /* isLong */);
731 }
732
733 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700734 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700735 builder.append("[");
736 if (isLong) {
737 builder.append("Properties:");
738 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700739
Tyler Gunnf5035432017-01-09 09:43:12 -0800740 if (can(properties, PROPERTY_SELF_MANAGED)) {
741 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
742 }
743
Hall Liu25c7c4d2016-08-30 13:41:02 -0700744 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
745 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700746 }
747
748 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700749 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700750 }
751
752 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700753 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700754 }
755
756 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700757 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700758 }
759
760 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700761 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700762 }
763
Brad Ebinger15847072016-05-18 11:08:36 -0700764 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700765 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700766 }
767
Tyler Gunn720c6642016-03-22 09:02:47 -0700768 builder.append("]");
769 return builder.toString();
770 }
771
Sailesh Nepal091768c2014-06-30 15:15:23 -0700772 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700773 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700774 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700775 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700776 public void onCallerDisplayNameChanged(
777 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700778 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700779 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700780 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800781 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700782 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700783 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800784 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700785 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800786 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700787 public void onVideoProviderChanged(
788 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700789 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
790 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800791 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700792 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700793 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700794 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800795 public void onConferenceParticipantsChanged(Connection c,
796 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800797 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700798 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700799 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700800 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700801 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700802 /** @hide */
803 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Tyler Gunnf5035432017-01-09 09:43:12 -0800804 public void onAudioRouteChanged(Connection c, int audioRoute) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800805 public void onRttInitiationSuccess(Connection c) {}
806 public void onRttInitiationFailure(Connection c, int reason) {}
807 public void onRttSessionRemotelyTerminated(Connection c) {}
808 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530809 /** @hide */
810 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700811 }
812
Tyler Gunnb702ef82015-05-29 11:51:53 -0700813 /**
Hall Liu95d55872017-01-25 17:12:49 -0800814 * Provides methods to read and write RTT data to/from the in-call app.
815 * @hide
816 */
Hall Liuffa4a812017-03-02 16:11:00 -0800817 @TestApi
Hall Liu95d55872017-01-25 17:12:49 -0800818 public static final class RttTextStream {
819 private static final int READ_BUFFER_SIZE = 1000;
820 private final InputStreamReader mPipeFromInCall;
821 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800822 private final ParcelFileDescriptor mFdFromInCall;
823 private final ParcelFileDescriptor mFdToInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800824 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
825
826 /**
827 * @hide
828 */
829 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800830 mFdFromInCall = fromInCall;
831 mFdToInCall = toInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800832 mPipeFromInCall = new InputStreamReader(
833 new ParcelFileDescriptor.AutoCloseInputStream(fromInCall));
834 mPipeToInCall = new OutputStreamWriter(
835 new ParcelFileDescriptor.AutoCloseOutputStream(toInCall));
836 }
837
838 /**
839 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
840 * RTT transmits text in real-time, this method should be called as often as text snippets
841 * are received from the remote user, even if it is only one character.
842 *
843 * This method is not thread-safe -- calling it from multiple threads simultaneously may
844 * lead to interleaved text.
845 * @param input The message to send to the in-call app.
846 */
847 public void write(String input) throws IOException {
848 mPipeToInCall.write(input);
849 mPipeToInCall.flush();
850 }
851
852
853 /**
854 * Reads a string from the in-call app, blocking if there is no data available. Returns
855 * {@code null} if the RTT conversation has been terminated and there is no further data
856 * to read.
857 *
858 * This method is not thread-safe -- calling it from multiple threads simultaneously may
859 * lead to interleaved text.
860 * @return A string containing text entered by the user, or {@code null} if the
861 * conversation has been terminated or if there was an error while reading.
862 */
Hall Liuffa4a812017-03-02 16:11:00 -0800863 public String read() throws IOException {
864 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
865 if (numRead < 0) {
866 return null;
867 }
868 return new String(mReadBuffer, 0, numRead);
869 }
870
871 /**
872 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
873 * be read.
874 * @return A string containing text entered by the user, or {@code null} if the user has
875 * not entered any new text yet.
876 */
877 public String readImmediately() throws IOException {
878 if (mPipeFromInCall.ready()) {
879 return read();
880 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800881 return null;
882 }
883 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800884
885 /** @hide */
886 public ParcelFileDescriptor getFdFromInCall() {
887 return mFdFromInCall;
888 }
889
890 /** @hide */
891 public ParcelFileDescriptor getFdToInCall() {
892 return mFdToInCall;
893 }
894 }
895
896 /**
897 * Provides constants to represent the results of responses to session modify requests sent via
898 * {@link Call#sendRttRequest()}
899 */
900 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -0700901 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800902 /**
903 * Session modify request was successful.
904 */
905 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
906
907 /**
908 * Session modify request failed.
909 */
910 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
911
912 /**
913 * Session modify request ignored due to invalid parameters.
914 */
915 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
916
917 /**
918 * Session modify request timed out.
919 */
920 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
921
922 /**
923 * Session modify request rejected by remote user.
924 */
925 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -0800926 }
927
928 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700929 * Provides a means of controlling the video session associated with a {@link Connection}.
930 * <p>
931 * Implementations create a custom subclass of {@link VideoProvider} and the
932 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
933 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
934 * should set the {@link VideoProvider}.
935 * <p>
936 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
937 * {@link InCallService} implementations to issue requests related to the video session;
938 * it provides a means for the {@link ConnectionService} to report events and information
939 * related to the video session to Telecom and the {@link InCallService} implementations.
940 * <p>
941 * {@link InCallService} implementations interact with the {@link VideoProvider} via
942 * {@link android.telecom.InCallService.VideoCall}.
943 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700944 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700945 /**
946 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700947 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700948 */
949 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700950
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700951 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700952 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
953 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700954 */
955 public static final int SESSION_EVENT_RX_RESUME = 2;
956
957 /**
958 * Video transmission has begun. This occurs after a negotiated start of video transmission
959 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700960 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700961 */
962 public static final int SESSION_EVENT_TX_START = 3;
963
964 /**
965 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
966 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700967 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700968 */
969 public static final int SESSION_EVENT_TX_STOP = 4;
970
971 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800972 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -0700973 * this as a cue to inform the user the camera is not available.
974 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700975 */
976 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
977
978 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700979 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800980 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -0700981 * the camera has become available again.
982 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700983 */
984 public static final int SESSION_EVENT_CAMERA_READY = 6;
985
986 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800987 * Session event raised by Telecom when
988 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
989 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
990 * @see #handleCallSessionEvent(int)
991 */
992 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
993
994 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700995 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700996 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700997 */
998 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
999
1000 /**
1001 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001002 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001003 */
1004 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1005
1006 /**
1007 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001008 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001009 */
1010 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1011
Rekha Kumar07366812015-03-24 16:42:31 -07001012 /**
1013 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001014 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001015 */
1016 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1017
1018 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001019 * Session modify request rejected by remote user.
1020 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001021 */
1022 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1023
Tyler Gunn75958422015-04-15 14:23:42 -07001024 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001025 private static final int MSG_SET_CAMERA = 2;
1026 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1027 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1028 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1029 private static final int MSG_SET_ZOOM = 6;
1030 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1031 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1032 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001033 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001034 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001035 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001036
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001037 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1038 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1039 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1040 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1041 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1042 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001043 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1044 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001045 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1046
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001047 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001048 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001049
1050 /**
1051 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001052 *
1053 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1054 * load factor before resizing, 1 means we only expect a single thread to
1055 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001056 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001057 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1058 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001059
1060 /**
1061 * Default handler used to consolidate binder method calls onto a single thread.
1062 */
1063 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001064 public VideoProviderHandler() {
1065 super();
1066 }
1067
1068 public VideoProviderHandler(Looper looper) {
1069 super(looper);
1070 }
1071
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001072 @Override
1073 public void handleMessage(Message msg) {
1074 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001075 case MSG_ADD_VIDEO_CALLBACK: {
1076 IBinder binder = (IBinder) msg.obj;
1077 IVideoCallback callback = IVideoCallback.Stub
1078 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001079 if (callback == null) {
1080 Log.w(this, "addVideoProvider - skipped; callback is null.");
1081 break;
1082 }
1083
Tyler Gunn75958422015-04-15 14:23:42 -07001084 if (mVideoCallbacks.containsKey(binder)) {
1085 Log.i(this, "addVideoProvider - skipped; already present.");
1086 break;
1087 }
1088 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001089 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001090 }
1091 case MSG_REMOVE_VIDEO_CALLBACK: {
1092 IBinder binder = (IBinder) msg.obj;
1093 IVideoCallback callback = IVideoCallback.Stub
1094 .asInterface((IBinder) msg.obj);
1095 if (!mVideoCallbacks.containsKey(binder)) {
1096 Log.i(this, "removeVideoProvider - skipped; not present.");
1097 break;
1098 }
1099 mVideoCallbacks.remove(binder);
1100 break;
1101 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001102 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001103 {
1104 SomeArgs args = (SomeArgs) msg.obj;
1105 try {
1106 onSetCamera((String) args.arg1);
1107 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001108 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001109 } finally {
1110 args.recycle();
1111 }
1112 }
1113 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001114 case MSG_SET_PREVIEW_SURFACE:
1115 onSetPreviewSurface((Surface) msg.obj);
1116 break;
1117 case MSG_SET_DISPLAY_SURFACE:
1118 onSetDisplaySurface((Surface) msg.obj);
1119 break;
1120 case MSG_SET_DEVICE_ORIENTATION:
1121 onSetDeviceOrientation(msg.arg1);
1122 break;
1123 case MSG_SET_ZOOM:
1124 onSetZoom((Float) msg.obj);
1125 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001126 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1127 SomeArgs args = (SomeArgs) msg.obj;
1128 try {
1129 onSendSessionModifyRequest((VideoProfile) args.arg1,
1130 (VideoProfile) args.arg2);
1131 } finally {
1132 args.recycle();
1133 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001134 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001135 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001136 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1137 onSendSessionModifyResponse((VideoProfile) msg.obj);
1138 break;
1139 case MSG_REQUEST_CAMERA_CAPABILITIES:
1140 onRequestCameraCapabilities();
1141 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001142 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1143 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001144 break;
1145 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001146 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001147 break;
1148 default:
1149 break;
1150 }
1151 }
1152 }
1153
1154 /**
1155 * IVideoProvider stub implementation.
1156 */
1157 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001158 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001159 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001160 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1161 }
1162
1163 public void removeVideoCallback(IBinder videoCallbackBinder) {
1164 mMessageHandler.obtainMessage(
1165 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001166 }
1167
Tyler Gunn159f35c2017-03-02 09:28:37 -08001168 public void setCamera(String cameraId, String callingPackageName,
1169 int targetSdkVersion) {
1170
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001171 SomeArgs args = SomeArgs.obtain();
1172 args.arg1 = cameraId;
1173 // Propagate the calling package; originally determined in
1174 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1175 // process.
1176 args.arg2 = callingPackageName;
1177 // Pass along the uid and pid of the calling app; this gets lost when we put the
1178 // message onto the handler. These are required for Telecom to perform a permission
1179 // check to see if the calling app is able to use the camera.
1180 args.argi1 = Binder.getCallingUid();
1181 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001182 // Pass along the target SDK version of the calling InCallService. This is used to
1183 // maintain backwards compatibility of the API for older callers.
1184 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001185 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001186 }
1187
1188 public void setPreviewSurface(Surface surface) {
1189 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1190 }
1191
1192 public void setDisplaySurface(Surface surface) {
1193 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1194 }
1195
1196 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001197 mMessageHandler.obtainMessage(
1198 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001199 }
1200
1201 public void setZoom(float value) {
1202 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1203 }
1204
Tyler Gunn45382162015-05-06 08:52:27 -07001205 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1206 SomeArgs args = SomeArgs.obtain();
1207 args.arg1 = fromProfile;
1208 args.arg2 = toProfile;
1209 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001210 }
1211
1212 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1213 mMessageHandler.obtainMessage(
1214 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1215 }
1216
1217 public void requestCameraCapabilities() {
1218 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1219 }
1220
1221 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001222 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001223 }
1224
Yorke Lee32f24732015-05-12 16:18:03 -07001225 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001226 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1227 }
1228 }
1229
1230 public VideoProvider() {
1231 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001232 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001233 }
1234
1235 /**
1236 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1237 *
1238 * @param looper The looper.
1239 * @hide
1240 */
1241 public VideoProvider(Looper looper) {
1242 mBinder = new VideoProvider.VideoProviderBinder();
1243 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001244 }
1245
1246 /**
1247 * Returns binder object which can be used across IPC methods.
1248 * @hide
1249 */
1250 public final IVideoProvider getInterface() {
1251 return mBinder;
1252 }
1253
1254 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001255 * Sets the camera to be used for the outgoing video.
1256 * <p>
1257 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1258 * camera via
1259 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1260 * <p>
1261 * Sent from the {@link InCallService} via
1262 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001263 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001264 * @param cameraId The id of the camera (use ids as reported by
1265 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001266 */
1267 public abstract void onSetCamera(String cameraId);
1268
1269 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001270 * Sets the camera to be used for the outgoing video.
1271 * <p>
1272 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1273 * camera via
1274 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1275 * <p>
1276 * This prototype is used internally to ensure that the calling package name, UID and PID
1277 * are sent to Telecom so that can perform a camera permission check on the caller.
1278 * <p>
1279 * Sent from the {@link InCallService} via
1280 * {@link InCallService.VideoCall#setCamera(String)}.
1281 *
1282 * @param cameraId The id of the camera (use ids as reported by
1283 * {@link CameraManager#getCameraIdList()}).
1284 * @param callingPackageName The AppOpps package name of the caller.
1285 * @param callingUid The UID of the caller.
1286 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001287 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001288 * @hide
1289 */
1290 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001291 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001292
1293 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001294 * Sets the surface to be used for displaying a preview of what the user's camera is
1295 * currently capturing. When video transmission is enabled, this is the video signal which
1296 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001297 * <p>
1298 * Sent from the {@link InCallService} via
1299 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001300 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001301 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001302 */
1303 public abstract void onSetPreviewSurface(Surface surface);
1304
1305 /**
1306 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001307 * <p>
1308 * Sent from the {@link InCallService} via
1309 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001310 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001311 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001312 */
1313 public abstract void onSetDisplaySurface(Surface surface);
1314
1315 /**
1316 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1317 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001318 * <p>
1319 * Sent from the {@link InCallService} via
1320 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001321 *
1322 * @param rotation The device orientation, in degrees.
1323 */
1324 public abstract void onSetDeviceOrientation(int rotation);
1325
1326 /**
1327 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001328 * <p>
1329 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001330 *
1331 * @param value The camera zoom ratio.
1332 */
1333 public abstract void onSetZoom(float value);
1334
1335 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001336 * Issues a request to modify the properties of the current video session.
1337 * <p>
1338 * Example scenarios include: requesting an audio-only call to be upgraded to a
1339 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1340 * when the {@link InCallService} is no longer the foreground application.
1341 * <p>
1342 * If the {@link VideoProvider} determines a request to be invalid, it should call
1343 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1344 * invalid request back to the {@link InCallService}.
1345 * <p>
1346 * Where a request requires confirmation from the user of the peer device, the
1347 * {@link VideoProvider} must communicate the request to the peer device and handle the
1348 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1349 * is used to inform the {@link InCallService} of the result of the request.
1350 * <p>
1351 * Sent from the {@link InCallService} via
1352 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001353 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001354 * @param fromProfile The video profile prior to the request.
1355 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001356 */
Tyler Gunn45382162015-05-06 08:52:27 -07001357 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1358 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001359
Tyler Gunnb702ef82015-05-29 11:51:53 -07001360 /**
1361 * Provides a response to a request to change the current video session properties.
1362 * <p>
1363 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1364 * video call, could decline the request and keep the call as audio-only.
1365 * In such a scenario, the {@code responseProfile} would have a video state of
1366 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1367 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1368 * <p>
1369 * Sent from the {@link InCallService} via
1370 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1371 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1372 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001373 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001374 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001375 */
1376 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1377
1378 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001379 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1380 * <p>
1381 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1382 * camera via
1383 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1384 * <p>
1385 * Sent from the {@link InCallService} via
1386 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001387 */
1388 public abstract void onRequestCameraCapabilities();
1389
1390 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001391 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1392 * video component of the current {@link Connection}.
1393 * <p>
1394 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1395 * via {@link VideoProvider#setCallDataUsage(long)}.
1396 * <p>
1397 * Sent from the {@link InCallService} via
1398 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001399 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001400 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001401
1402 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001403 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1404 * the peer device when the video signal is paused.
1405 * <p>
1406 * Sent from the {@link InCallService} via
1407 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001408 *
1409 * @param uri URI of image to display.
1410 */
Yorke Lee32f24732015-05-12 16:18:03 -07001411 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001412
1413 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001414 * Used to inform listening {@link InCallService} implementations when the
1415 * {@link VideoProvider} receives a session modification request.
1416 * <p>
1417 * Received by the {@link InCallService} via
1418 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001419 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001420 * @param videoProfile The requested video profile.
1421 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001422 */
1423 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001424 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001425 for (IVideoCallback callback : mVideoCallbacks.values()) {
1426 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001427 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001428 } catch (RemoteException ignored) {
1429 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001430 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001431 }
1432 }
1433 }
1434
1435 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001436 * Used to inform listening {@link InCallService} implementations when the
1437 * {@link VideoProvider} receives a response to a session modification request.
1438 * <p>
1439 * Received by the {@link InCallService} via
1440 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1441 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001442 *
1443 * @param status Status of the session modify request. Valid values are
1444 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1445 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001446 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1447 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1448 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1449 * @param requestedProfile The original request which was sent to the peer device.
1450 * @param responseProfile The actual profile changes agreed to by the peer device.
1451 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001452 */
1453 public void receiveSessionModifyResponse(int status,
1454 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001455 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001456 for (IVideoCallback callback : mVideoCallbacks.values()) {
1457 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001458 callback.receiveSessionModifyResponse(status, requestedProfile,
1459 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001460 } catch (RemoteException ignored) {
1461 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001462 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001463 }
1464 }
1465 }
1466
1467 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001468 * Used to inform listening {@link InCallService} implementations when the
1469 * {@link VideoProvider} reports a call session event.
1470 * <p>
1471 * Received by the {@link InCallService} via
1472 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001473 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001474 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1475 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1476 * {@link VideoProvider#SESSION_EVENT_TX_START},
1477 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1478 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001479 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1480 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001481 */
1482 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001483 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001484 for (IVideoCallback callback : mVideoCallbacks.values()) {
1485 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001486 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001487 } catch (RemoteException ignored) {
1488 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001489 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001490 }
1491 }
1492 }
1493
1494 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001495 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1496 * peer's video have changed.
1497 * <p>
1498 * This could occur if, for example, the peer rotates their device, changing the aspect
1499 * ratio of the video, or if the user switches between the back and front cameras.
1500 * <p>
1501 * Received by the {@link InCallService} via
1502 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001503 *
1504 * @param width The updated peer video width.
1505 * @param height The updated peer video height.
1506 */
1507 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001508 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001509 for (IVideoCallback callback : mVideoCallbacks.values()) {
1510 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001511 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001512 } catch (RemoteException ignored) {
1513 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001514 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001515 }
1516 }
1517 }
1518
1519 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001520 * Used to inform listening {@link InCallService} implementations when the data usage of the
1521 * video associated with the current {@link Connection} has changed.
1522 * <p>
1523 * This could be in response to a preview request via
1524 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001525 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1526 * 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 -07001527 * <p>
1528 * Received by the {@link InCallService} via
1529 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001530 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001531 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1532 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001533 */
Yorke Lee32f24732015-05-12 16:18:03 -07001534 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001535 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001536 for (IVideoCallback callback : mVideoCallbacks.values()) {
1537 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001538 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001539 } catch (RemoteException ignored) {
1540 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001541 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001542 }
1543 }
1544 }
1545
1546 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001547 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001548 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001549 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001550 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1551 * @hide
1552 */
1553 public void changeCallDataUsage(long dataUsage) {
1554 setCallDataUsage(dataUsage);
1555 }
1556
1557 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001558 * Used to inform listening {@link InCallService} implementations when the capabilities of
1559 * the current camera have changed.
1560 * <p>
1561 * The {@link VideoProvider} should call this in response to
1562 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1563 * changed via {@link VideoProvider#onSetCamera(String)}.
1564 * <p>
1565 * Received by the {@link InCallService} via
1566 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1567 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001568 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001569 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001570 */
Yorke Lee400470f2015-05-12 13:31:25 -07001571 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001572 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001573 for (IVideoCallback callback : mVideoCallbacks.values()) {
1574 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001575 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001576 } catch (RemoteException ignored) {
1577 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001578 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001579 }
1580 }
1581 }
Rekha Kumar07366812015-03-24 16:42:31 -07001582
1583 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001584 * Used to inform listening {@link InCallService} implementations when the video quality
1585 * of the call has changed.
1586 * <p>
1587 * Received by the {@link InCallService} via
1588 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001589 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001590 * @param videoQuality The updated video quality. Valid values:
1591 * {@link VideoProfile#QUALITY_HIGH},
1592 * {@link VideoProfile#QUALITY_MEDIUM},
1593 * {@link VideoProfile#QUALITY_LOW},
1594 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001595 */
1596 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001597 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001598 for (IVideoCallback callback : mVideoCallbacks.values()) {
1599 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001600 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001601 } catch (RemoteException ignored) {
1602 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001603 }
Rekha Kumar07366812015-03-24 16:42:31 -07001604 }
1605 }
1606 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001607
1608 /**
1609 * Returns a string representation of a call session event.
1610 *
1611 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1612 * @return String representation of the call session event.
1613 * @hide
1614 */
1615 public static String sessionEventToString(int event) {
1616 switch (event) {
1617 case SESSION_EVENT_CAMERA_FAILURE:
1618 return SESSION_EVENT_CAMERA_FAILURE_STR;
1619 case SESSION_EVENT_CAMERA_READY:
1620 return SESSION_EVENT_CAMERA_READY_STR;
1621 case SESSION_EVENT_RX_PAUSE:
1622 return SESSION_EVENT_RX_PAUSE_STR;
1623 case SESSION_EVENT_RX_RESUME:
1624 return SESSION_EVENT_RX_RESUME_STR;
1625 case SESSION_EVENT_TX_START:
1626 return SESSION_EVENT_TX_START_STR;
1627 case SESSION_EVENT_TX_STOP:
1628 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001629 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1630 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001631 default:
1632 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1633 }
1634 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001635 }
1636
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001637 private final Listener mConnectionDeathListener = new Listener() {
1638 @Override
1639 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001640 if (mConferenceables.remove(c)) {
1641 fireOnConferenceableConnectionsChanged();
1642 }
1643 }
1644 };
1645
1646 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1647 @Override
1648 public void onDestroyed(Conference c) {
1649 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001650 fireOnConferenceableConnectionsChanged();
1651 }
1652 }
1653 };
1654
Jay Shrauner229e3822014-08-15 09:23:07 -07001655 /**
1656 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1657 * load factor before resizing, 1 means we only expect a single thread to
1658 * access the map so make only a single shard
1659 */
1660 private final Set<Listener> mListeners = Collections.newSetFromMap(
1661 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001662 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1663 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001664 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001665
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001666 // The internal telecom call ID associated with this connection.
1667 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001668 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001669 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001670 private Uri mAddress;
1671 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001672 private String mCallerDisplayName;
1673 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001674 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001675 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001676 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001677 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001678 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001679 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001680 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001681 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001682 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001683 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001684 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001685 private Conference mConference;
1686 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001687 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001688 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001689
1690 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001691 * Tracks the key set for the extras bundle provided on the last invocation of
1692 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1693 * keys which were set previously but are no longer present in the replacement Bundle.
1694 */
1695 private Set<String> mPreviousExtraKeys;
1696
1697 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001698 * Create a new Connection.
1699 */
Santos Cordonf2951102014-07-20 19:06:29 -07001700 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001701
1702 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001703 * Returns the Telecom internal call ID associated with this connection. Should only be used
1704 * for debugging and tracing purposes.
1705 *
1706 * @return The Telecom call ID.
1707 * @hide
1708 */
1709 public final String getTelecomCallId() {
1710 return mTelecomCallId;
1711 }
1712
1713 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001714 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001715 */
Andrew Lee100e2932014-09-08 15:34:24 -07001716 public final Uri getAddress() {
1717 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001718 }
1719
1720 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001721 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001722 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001723 */
Andrew Lee100e2932014-09-08 15:34:24 -07001724 public final int getAddressPresentation() {
1725 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001726 }
1727
1728 /**
1729 * @return The caller display name (CNAP).
1730 */
1731 public final String getCallerDisplayName() {
1732 return mCallerDisplayName;
1733 }
1734
1735 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001736 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001737 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001738 */
1739 public final int getCallerDisplayNamePresentation() {
1740 return mCallerDisplayNamePresentation;
1741 }
1742
1743 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001744 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001745 */
1746 public final int getState() {
1747 return mState;
1748 }
1749
1750 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001751 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001752 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1753 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1754 * {@link VideoProfile#STATE_TX_ENABLED},
1755 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001756 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001757 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001758 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001759 */
1760 public final int getVideoState() {
1761 return mVideoState;
1762 }
1763
1764 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001765 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001766 * being routed by the system. This is {@code null} if this Connection
1767 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001768 * @deprecated Use {@link #getCallAudioState()} instead.
1769 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001770 */
Yorke Lee4af59352015-05-13 14:14:54 -07001771 @SystemApi
1772 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001773 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001774 if (mCallAudioState == null) {
1775 return null;
1776 }
Yorke Lee4af59352015-05-13 14:14:54 -07001777 return new AudioState(mCallAudioState);
1778 }
1779
1780 /**
1781 * @return The audio state of the connection, describing how its audio is currently
1782 * being routed by the system. This is {@code null} if this Connection
1783 * does not directly know about its audio state.
1784 */
1785 public final CallAudioState getCallAudioState() {
1786 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001787 }
1788
1789 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001790 * @return The conference that this connection is a part of. Null if it is not part of any
1791 * conference.
1792 */
1793 public final Conference getConference() {
1794 return mConference;
1795 }
1796
1797 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001798 * Returns whether this connection is requesting that the system play a ringback tone
1799 * on its behalf.
1800 */
Andrew Lee100e2932014-09-08 15:34:24 -07001801 public final boolean isRingbackRequested() {
1802 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001803 }
1804
1805 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001806 * @return True if the connection's audio mode is VOIP.
1807 */
1808 public final boolean getAudioModeIsVoip() {
1809 return mAudioModeIsVoip;
1810 }
1811
1812 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001813 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1814 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1815 * start time of the conference.
1816 *
1817 * @return The time at which the {@code Connnection} was connected.
1818 *
1819 * @hide
1820 */
1821 public final long getConnectTimeMillis() {
1822 return mConnectTimeMillis;
1823 }
1824
1825 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001826 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1827 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1828 * start time of the conference.
1829 *
1830 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
1831 * changes do not impact the call duration.
1832 *
1833 * @return The time at which the {@link Connection} was connected.
1834 *
1835 * @hide
1836 */
1837 public final long getConnectElapsedTimeMillis() {
1838 return mConnectElapsedTimeMillis;
1839 }
1840
1841 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001842 * @return The status hints for this connection.
1843 */
1844 public final StatusHints getStatusHints() {
1845 return mStatusHints;
1846 }
1847
1848 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001849 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001850 * <p>
1851 * Extras should be updated using {@link #putExtras(Bundle)}.
1852 * <p>
1853 * Telecom or an {@link InCallService} can also update the extras via
1854 * {@link android.telecom.Call#putExtras(Bundle)}, and
1855 * {@link Call#removeExtras(List)}.
1856 * <p>
1857 * The connection is notified of changes to the extras made by Telecom or an
1858 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001859 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001860 * @return The extras associated with this connection.
1861 */
1862 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001863 Bundle extras = null;
1864 synchronized (mExtrasLock) {
1865 if (mExtras != null) {
1866 extras = new Bundle(mExtras);
1867 }
1868 }
1869 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001870 }
1871
1872 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001873 * Assign a listener to be notified of state changes.
1874 *
1875 * @param l A listener.
1876 * @return This Connection.
1877 *
1878 * @hide
1879 */
1880 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001881 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001882 return this;
1883 }
1884
1885 /**
1886 * Remove a previously assigned listener that was being notified of state changes.
1887 *
1888 * @param l A Listener.
1889 * @return This Connection.
1890 *
1891 * @hide
1892 */
1893 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001894 if (l != null) {
1895 mListeners.remove(l);
1896 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001897 return this;
1898 }
1899
1900 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001901 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001902 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001903 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001904 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001905 }
1906
1907 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001908 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1909 * ONLY for debugging purposes.
1910 *
1911 * @param callId The telecom call ID.
1912 * @hide
1913 */
1914 public void setTelecomCallId(String callId) {
1915 mTelecomCallId = callId;
1916 }
1917
1918 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001919 * Inform this Connection that the state of its audio output has been changed externally.
1920 *
1921 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001922 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001923 */
Yorke Lee4af59352015-05-13 14:14:54 -07001924 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001925 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001926 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001927 mCallAudioState = state;
1928 onAudioStateChanged(getAudioState());
1929 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001930 }
1931
1932 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001933 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001934 * @return A string representation of the value.
1935 */
1936 public static String stateToString(int state) {
1937 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001938 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001939 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001940 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001941 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001942 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001943 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001944 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001945 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001946 case STATE_PULLING_CALL:
1947 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001948 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001949 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001950 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001951 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001952 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001953 return "DISCONNECTED";
1954 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001955 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001956 return "UNKNOWN";
1957 }
1958 }
1959
1960 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001961 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001962 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001963 public final int getConnectionCapabilities() {
1964 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001965 }
1966
1967 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001968 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1969 */
1970 public final int getConnectionProperties() {
1971 return mConnectionProperties;
1972 }
1973
1974 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001975 * Returns the connection's supported audio routes.
1976 *
1977 * @hide
1978 */
1979 public final int getSupportedAudioRoutes() {
1980 return mSupportedAudioRoutes;
1981 }
1982
1983 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001984 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001985 *
Andrew Lee100e2932014-09-08 15:34:24 -07001986 * @param address The new address.
1987 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001988 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001989 */
Andrew Lee100e2932014-09-08 15:34:24 -07001990 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001991 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001992 Log.d(this, "setAddress %s", address);
1993 mAddress = address;
1994 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001995 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001996 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001997 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001998 }
1999
2000 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002001 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002002 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002003 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002004 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002005 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002006 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002007 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002008 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002009 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002010 mCallerDisplayName = callerDisplayName;
2011 mCallerDisplayNamePresentation = presentation;
2012 for (Listener l : mListeners) {
2013 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2014 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002015 }
2016
2017 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002018 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002019 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2020 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2021 * {@link VideoProfile#STATE_TX_ENABLED},
2022 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002023 *
2024 * @param videoState The new video state.
2025 */
2026 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002027 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002028 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002029 mVideoState = videoState;
2030 for (Listener l : mListeners) {
2031 l.onVideoStateChanged(this, mVideoState);
2032 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002033 }
2034
2035 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002036 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002037 * communicate).
2038 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002039 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002040 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002041 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002042 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002043 }
2044
2045 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002046 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002047 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002048 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002049 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002050 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002051 }
2052
2053 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002054 * Sets state to initializing (this Connection is not yet ready to be used).
2055 */
2056 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002057 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002058 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002059 }
2060
2061 /**
2062 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2063 */
2064 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002065 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002066 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002067 }
2068
2069 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002070 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002071 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002072 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002073 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002074 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002075 }
2076
2077 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002078 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2079 * device). Only applicable for {@link Connection}s with
2080 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2081 */
2082 public final void setPulling() {
2083 checkImmutable();
2084 setState(STATE_PULLING_CALL);
2085 }
2086
2087 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002088 * Sets state to be on hold.
2089 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002090 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002091 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002092 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002093 }
2094
2095 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002096 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002097 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002098 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002099 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002100 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002101 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002102 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002103 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002104 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002105 }
2106
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002107 public final VideoProvider getVideoProvider() {
2108 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002109 }
2110
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002111 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002112 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002113 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002114 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002115 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002116 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002117 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002118 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002119 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002120 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002121 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002122 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002123 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002124 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002125 }
2126
2127 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002128 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2129 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2130 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2131 * to send an {@link #onPostDialContinue(boolean)} signal.
2132 *
2133 * @param remaining The DTMF character sequence remaining to be emitted once the
2134 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2135 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002136 */
2137 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002138 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002139 for (Listener l : mListeners) {
2140 l.onPostDialWait(this, remaining);
2141 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002142 }
2143
2144 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002145 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2146 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002147 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002148 *
2149 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002150 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002151 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002152 checkImmutable();
2153 for (Listener l : mListeners) {
2154 l.onPostDialChar(this, nextChar);
2155 }
2156 }
2157
2158 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002159 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002160 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002161 *
2162 * @param ringback Whether the ringback tone is to be played.
2163 */
Andrew Lee100e2932014-09-08 15:34:24 -07002164 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002165 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002166 if (mRingbackRequested != ringback) {
2167 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002168 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002169 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002170 }
2171 }
Ihab Awadf8358972014-05-28 16:46:42 -07002172 }
2173
2174 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002175 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002176 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002177 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002178 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002179 public final void setConnectionCapabilities(int connectionCapabilities) {
2180 checkImmutable();
2181 if (mConnectionCapabilities != connectionCapabilities) {
2182 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002183 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002184 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002185 }
2186 }
Santos Cordonb6939982014-06-04 20:20:58 -07002187 }
2188
2189 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002190 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2191 *
2192 * @param connectionProperties The new connection properties.
2193 */
2194 public final void setConnectionProperties(int connectionProperties) {
2195 checkImmutable();
2196 if (mConnectionProperties != connectionProperties) {
2197 mConnectionProperties = connectionProperties;
2198 for (Listener l : mListeners) {
2199 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2200 }
2201 }
2202 }
2203
2204 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002205 * Sets the supported audio routes.
2206 *
2207 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2208 * See {@link CallAudioState}
2209 * @hide
2210 */
2211 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2212 if ((supportedAudioRoutes
2213 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2214 throw new IllegalArgumentException(
2215 "supported audio routes must include either speaker or earpiece");
2216 }
2217
2218 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2219 mSupportedAudioRoutes = supportedAudioRoutes;
2220 for (Listener l : mListeners) {
2221 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2222 }
2223 }
2224 }
2225
2226 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002227 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002228 */
Evan Charlton36a71342014-07-19 16:31:02 -07002229 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002230 for (Listener l : mListeners) {
2231 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002232 }
Santos Cordonb6939982014-06-04 20:20:58 -07002233 }
2234
2235 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002236 * Requests that the framework use VOIP audio mode for this connection.
2237 *
2238 * @param isVoip True if the audio mode is VOIP.
2239 */
2240 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002241 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002242 mAudioModeIsVoip = isVoip;
2243 for (Listener l : mListeners) {
2244 l.onAudioModeIsVoipChanged(this, isVoip);
2245 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002246 }
2247
2248 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002249 * Sets the time at which a call became active on this Connection. This is set only
2250 * when a conference call becomes active on this connection.
2251 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002252 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2253 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002254 *
2255 * @hide
2256 */
2257 public final void setConnectTimeMillis(long connectTimeMillis) {
2258 mConnectTimeMillis = connectTimeMillis;
2259 }
2260
2261 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002262 * Sets the time at which a call became active on this Connection. This is set only
2263 * when a conference call becomes active on this connection.
2264 *
2265 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2266 * {@link SystemClock#elapsedRealtime()}.
2267 *
2268 * @hide
2269 */
2270 public final void setConnectElapsedTimeMillis(long connectElapsedTimeMillis) {
2271 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2272 }
2273
2274 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002275 * Sets the label and icon status to display in the in-call UI.
2276 *
2277 * @param statusHints The status label and icon to set.
2278 */
2279 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002280 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002281 mStatusHints = statusHints;
2282 for (Listener l : mListeners) {
2283 l.onStatusHintsChanged(this, statusHints);
2284 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002285 }
2286
2287 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002288 * Sets the connections with which this connection can be conferenced.
2289 *
2290 * @param conferenceableConnections The set of connections this connection can conference with.
2291 */
2292 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002293 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002294 clearConferenceableList();
2295 for (Connection c : conferenceableConnections) {
2296 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2297 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002298 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002299 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002300 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002301 }
2302 }
2303 fireOnConferenceableConnectionsChanged();
2304 }
2305
2306 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002307 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2308 * or conferences with which this connection can be conferenced.
2309 *
2310 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002311 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002312 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002313 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002314 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002315 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2316 // small amount of items here.
2317 if (!mConferenceables.contains(c)) {
2318 if (c instanceof Connection) {
2319 Connection connection = (Connection) c;
2320 connection.addConnectionListener(mConnectionDeathListener);
2321 } else if (c instanceof Conference) {
2322 Conference conference = (Conference) c;
2323 conference.addListener(mConferenceDeathListener);
2324 }
2325 mConferenceables.add(c);
2326 }
2327 }
2328 fireOnConferenceableConnectionsChanged();
2329 }
2330
2331 /**
2332 * Returns the connections or conferences with which this connection can be conferenced.
2333 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002334 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002335 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002336 }
2337
Yorke Lee53463962015-08-04 16:07:19 -07002338 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002339 * @hide
2340 */
2341 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002342 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002343 if (mConnectionService != null) {
2344 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2345 "which is already associated with another ConnectionService.");
2346 } else {
2347 mConnectionService = connectionService;
2348 }
2349 }
2350
2351 /**
2352 * @hide
2353 */
2354 public final void unsetConnectionService(ConnectionService connectionService) {
2355 if (mConnectionService != connectionService) {
2356 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2357 "that does not belong to the ConnectionService.");
2358 } else {
2359 mConnectionService = null;
2360 }
2361 }
2362
2363 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002364 * @hide
2365 */
2366 public final ConnectionService getConnectionService() {
2367 return mConnectionService;
2368 }
2369
2370 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002371 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002372 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002373 *
2374 * @param conference The conference.
2375 * @return {@code true} if the conference was successfully set.
2376 * @hide
2377 */
2378 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002379 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002380 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002381 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002382 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002383 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2384 fireConferenceChanged();
2385 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002386 return true;
2387 }
2388 return false;
2389 }
2390
2391 /**
2392 * Resets the conference that this connection is a part of.
2393 * @hide
2394 */
2395 public final void resetConference() {
2396 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002397 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002398 mConference = null;
2399 fireConferenceChanged();
2400 }
2401 }
2402
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002403 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002404 * Set some extras that can be associated with this {@code Connection}.
2405 * <p>
2406 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2407 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2408 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002409 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2410 * {@link #removeExtras(String...)} methods to modify the extras.
2411 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002412 * 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 -07002413 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2414 *
2415 * @param extras The extras associated with this {@code Connection}.
2416 */
2417 public final void setExtras(@Nullable Bundle extras) {
2418 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002419
2420 // Add/replace any new or changed extras values.
2421 putExtras(extras);
2422
2423 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2424 // the current one and remove any keys that went away.
2425 if (mPreviousExtraKeys != null) {
2426 List<String> toRemove = new ArrayList<String>();
2427 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002428 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002429 toRemove.add(oldKey);
2430 }
2431 }
2432 if (!toRemove.isEmpty()) {
2433 removeExtras(toRemove);
2434 }
2435 }
2436
2437 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2438 // called we can see if the caller has removed any extras values.
2439 if (mPreviousExtraKeys == null) {
2440 mPreviousExtraKeys = new ArraySet<String>();
2441 }
2442 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002443 if (extras != null) {
2444 mPreviousExtraKeys.addAll(extras.keySet());
2445 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002446 }
2447
2448 /**
2449 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2450 * added.
2451 * <p>
2452 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2453 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2454 *
2455 * @param extras The extras to add.
2456 */
2457 public final void putExtras(@NonNull Bundle extras) {
2458 checkImmutable();
2459 if (extras == null) {
2460 return;
2461 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002462 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2463 // the listeners.
2464 Bundle listenerExtras;
2465 synchronized (mExtrasLock) {
2466 if (mExtras == null) {
2467 mExtras = new Bundle();
2468 }
2469 mExtras.putAll(extras);
2470 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002471 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002472 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002473 // Create a new clone of the extras for each listener so that they don't clobber
2474 // each other
2475 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002476 }
2477 }
2478
2479 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002480 * Adds a boolean extra to this {@code Connection}.
2481 *
2482 * @param key The extra key.
2483 * @param value The value.
2484 * @hide
2485 */
2486 public final void putExtra(String key, boolean value) {
2487 Bundle newExtras = new Bundle();
2488 newExtras.putBoolean(key, value);
2489 putExtras(newExtras);
2490 }
2491
2492 /**
2493 * Adds an integer extra to this {@code Connection}.
2494 *
2495 * @param key The extra key.
2496 * @param value The value.
2497 * @hide
2498 */
2499 public final void putExtra(String key, int value) {
2500 Bundle newExtras = new Bundle();
2501 newExtras.putInt(key, value);
2502 putExtras(newExtras);
2503 }
2504
2505 /**
2506 * Adds a string extra to this {@code Connection}.
2507 *
2508 * @param key The extra key.
2509 * @param value The value.
2510 * @hide
2511 */
2512 public final void putExtra(String key, String value) {
2513 Bundle newExtras = new Bundle();
2514 newExtras.putString(key, value);
2515 putExtras(newExtras);
2516 }
2517
2518 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002519 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002520 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002521 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002522 */
2523 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002524 synchronized (mExtrasLock) {
2525 if (mExtras != null) {
2526 for (String key : keys) {
2527 mExtras.remove(key);
2528 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002529 }
2530 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002531 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002532 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002533 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002534 }
2535 }
2536
2537 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002538 * Removes extras from this {@code Connection}.
2539 *
2540 * @param keys The keys of the extras to remove.
2541 */
2542 public final void removeExtras(String ... keys) {
2543 removeExtras(Arrays.asList(keys));
2544 }
2545
2546 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002547 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2548 * be change to the {@link #getCallAudioState()}.
2549 * <p>
2550 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2551 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2552 * <p>
2553 * See also {@link InCallService#setAudioRoute(int)}.
2554 *
2555 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2556 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2557 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2558 */
2559 public final void setAudioRoute(int route) {
2560 for (Listener l : mListeners) {
2561 l.onAudioRouteChanged(this, route);
2562 }
2563 }
2564
2565 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002566 * Informs listeners that a previously requested RTT session via
2567 * {@link ConnectionRequest#isRequestingRtt()} or
2568 * {@link #onStartRtt(ParcelFileDescriptor, ParcelFileDescriptor)} has succeeded.
2569 * @hide
2570 */
Hall Liuffa4a812017-03-02 16:11:00 -08002571 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002572 public final void sendRttInitiationSuccess() {
Hall Liuffa4a812017-03-02 16:11:00 -08002573 setRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08002574 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2575 }
2576
2577 /**
2578 * Informs listeners that a previously requested RTT session via
2579 * {@link ConnectionRequest#isRequestingRtt()} or
2580 * {@link #onStartRtt(ParcelFileDescriptor, ParcelFileDescriptor)}
2581 * has failed.
2582 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2583 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
2584 * @hide
2585 */
Hall Liuffa4a812017-03-02 16:11:00 -08002586 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002587 public final void sendRttInitiationFailure(int reason) {
Hall Liuffa4a812017-03-02 16:11:00 -08002588 unsetRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08002589 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2590 }
2591
2592 /**
2593 * Informs listeners that a currently active RTT session has been terminated by the remote
2594 * side of the coll.
2595 * @hide
2596 */
Hall Liuffa4a812017-03-02 16:11:00 -08002597 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002598 public final void sendRttSessionRemotelyTerminated() {
2599 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2600 }
2601
2602 /**
2603 * Informs listeners that the remote side of the call has requested an upgrade to include an
2604 * RTT session in the call.
2605 * @hide
2606 */
Hall Liuffa4a812017-03-02 16:11:00 -08002607 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002608 public final void sendRemoteRttRequest() {
2609 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2610 }
2611
2612 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002613 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002614 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002615 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002616 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2617 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002618 */
Yorke Lee4af59352015-05-13 14:14:54 -07002619 @SystemApi
2620 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002621 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002622
2623 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002624 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2625 *
2626 * @param state The new connection audio state.
2627 */
2628 public void onCallAudioStateChanged(CallAudioState state) {}
2629
2630 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002631 * Notifies this Connection of an internal state change. This method is called after the
2632 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002633 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002634 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002635 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002636 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002637
2638 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002639 * Notifies this Connection of a request to play a DTMF tone.
2640 *
2641 * @param c A DTMF character.
2642 */
Santos Cordonf2951102014-07-20 19:06:29 -07002643 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002644
2645 /**
2646 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2647 */
Santos Cordonf2951102014-07-20 19:06:29 -07002648 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002649
2650 /**
2651 * Notifies this Connection of a request to disconnect.
2652 */
Santos Cordonf2951102014-07-20 19:06:29 -07002653 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002654
2655 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002656 * Notifies this Connection of a request to disconnect a participant of the conference managed
2657 * by the connection.
2658 *
2659 * @param endpoint the {@link Uri} of the participant to disconnect.
2660 * @hide
2661 */
2662 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2663
2664 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002665 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002666 */
Santos Cordonf2951102014-07-20 19:06:29 -07002667 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002668
2669 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002670 * Notifies this Connection of a request to abort.
2671 */
Santos Cordonf2951102014-07-20 19:06:29 -07002672 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002673
2674 /**
2675 * Notifies this Connection of a request to hold.
2676 */
Santos Cordonf2951102014-07-20 19:06:29 -07002677 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002678
2679 /**
2680 * Notifies this Connection of a request to exit a hold state.
2681 */
Santos Cordonf2951102014-07-20 19:06:29 -07002682 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002683
2684 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002685 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002686 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002687 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002688 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002689 */
Santos Cordonf2951102014-07-20 19:06:29 -07002690 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002691
2692 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002693 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002694 * a request to accept.
2695 */
2696 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002697 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002698 }
2699
2700 /**
2701 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002702 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002703 */
Santos Cordonf2951102014-07-20 19:06:29 -07002704 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002705
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002706 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002707 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2708 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002709 */
2710 public void onReject(String replyMessage) {}
2711
2712 /**
Bryce Leecac50772015-11-17 15:13:29 -08002713 * Notifies the Connection of a request to silence the ringer.
2714 *
2715 * @hide
2716 */
2717 public void onSilence() {}
2718
2719 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002720 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2721 */
Santos Cordonf2951102014-07-20 19:06:29 -07002722 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002723
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002724 /**
2725 * Notifies this Connection of a request to pull an external call to the local device.
2726 * <p>
2727 * The {@link InCallService} issues a request to pull an external call to the local device via
2728 * {@link Call#pullExternalCall()}.
2729 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002730 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2731 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002732 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002733 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002734 */
2735 public void onPullExternalCall() {}
2736
2737 /**
2738 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2739 * <p>
2740 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2741 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002742 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2743 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2744 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2745 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2746 * not aware of.
2747 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002748 * See also {@link Call#sendCallEvent(String, Bundle)}.
2749 *
2750 * @param event The call event.
2751 * @param extras Extras associated with the call event.
2752 */
2753 public void onCallEvent(String event, Bundle extras) {}
2754
Tyler Gunndee56a82016-03-23 16:06:34 -07002755 /**
2756 * Notifies this {@link Connection} of a change to the extras made outside the
2757 * {@link ConnectionService}.
2758 * <p>
2759 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2760 * the {@link android.telecom.Call#putExtras(Bundle)} and
2761 * {@link Call#removeExtras(List)}.
2762 *
2763 * @param extras The new extras bundle.
2764 */
2765 public void onExtrasChanged(Bundle extras) {}
2766
Tyler Gunnf5035432017-01-09 09:43:12 -08002767 /**
2768 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2769 * displaying its incoming call user interface for the {@link Connection}.
2770 * <p>
2771 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2772 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2773 * should show its own incoming call user interface.
2774 * <p>
2775 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
2776 * regular {@link ConnectionService}, the Telecom framework will display its own incoming call
2777 * user interface to allow the user to choose whether to answer the new incoming call and
2778 * disconnect other ongoing calls, or to reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002779 * <p>
2780 * You should trigger the display of the incoming call user interface for your application by
2781 * showing a {@link Notification} with a full-screen {@link Intent} specified.
2782 * For example:
2783 * <pre><code>
2784 * // Create an intent which triggers your fullscreen incoming call user interface.
2785 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
2786 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
2787 * intent.setClass(context, YourIncomingCallActivity.class);
2788 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
2789 *
2790 * // Build the notification as an ongoing high priority item; this ensures it will show as
2791 * // a heads up notification which slides down over top of the current content.
2792 * final Notification.Builder builder = new Notification.Builder(context);
2793 * builder.setOngoing(true);
2794 * builder.setPriority(Notification.PRIORITY_HIGH);
2795 *
2796 * // Set notification content intent to take user to fullscreen UI if user taps on the
2797 * // notification body.
2798 * builder.setContentIntent(pendingIntent);
2799 * // Set full screen intent to trigger display of the fullscreen UI when the notification
2800 * // manager deems it appropriate.
2801 * builder.setFullScreenIntent(pendingIntent, true);
2802 *
2803 * // Setup notification content.
2804 * builder.setSmallIcon( yourIconResourceId );
2805 * builder.setContentTitle("Your notification title");
2806 * builder.setContentText("Your notification content.");
2807 *
2808 * // Use builder.addAction(..) to add buttons to answer or reject the call.
2809 *
2810 * NotificationManager notificationManager = mContext.getSystemService(
2811 * NotificationManager.class);
2812 * notificationManager.notify(YOUR_TAG, YOUR_ID, builder.build());
2813 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08002814 */
2815 public void onShowIncomingCallUi() {}
2816
Hall Liub64ac4c2017-02-06 10:49:48 -08002817 /**
2818 * Notifies this {@link Connection} that the user has requested an RTT session.
2819 * The connection service should call {@link #sendRttInitiationSuccess} or
2820 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
2821 * request, respectively.
2822 * @param rttTextStream The object that should be used to send text to or receive text from
2823 * the in-call app.
2824 * @hide
2825 */
Hall Liuffa4a812017-03-02 16:11:00 -08002826 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002827 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
2828
2829 /**
2830 * Notifies this {@link Connection} that it should terminate any existing RTT communication
2831 * channel. No response to Telecom is needed for this method.
2832 * @hide
2833 */
Hall Liuffa4a812017-03-02 16:11:00 -08002834 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002835 public void onStopRtt() {}
2836
2837 /**
2838 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
2839 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
2840 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
2841 * indicated by {@code rttTextStream} being {@code null}
2842 * @hide
2843 * @param rttTextStream The object that should be used to send text to or receive text from
2844 * the in-call app.
2845 */
Hall Liuffa4a812017-03-02 16:11:00 -08002846 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002847 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
2848
Hall Liuffa4a812017-03-02 16:11:00 -08002849 /**
2850 * Internal method to set {@link #PROPERTY_IS_RTT}.
2851 * @hide
2852 */
2853 void setRttProperty() {
2854 setConnectionProperties(getConnectionProperties() | PROPERTY_IS_RTT);
2855 }
2856
2857 /**
2858 * Internal method to un-set {@link #PROPERTY_IS_RTT}.
2859 * @hide
2860 */
2861 void unsetRttProperty() {
2862 setConnectionProperties(getConnectionProperties() & (~PROPERTY_IS_RTT));
2863 }
2864
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002865 static String toLogSafePhoneNumber(String number) {
2866 // For unknown number, log empty string.
2867 if (number == null) {
2868 return "";
2869 }
2870
2871 if (PII_DEBUG) {
2872 // When PII_DEBUG is true we emit PII.
2873 return number;
2874 }
2875
2876 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2877 // sanitized phone numbers.
2878 StringBuilder builder = new StringBuilder();
2879 for (int i = 0; i < number.length(); i++) {
2880 char c = number.charAt(i);
2881 if (c == '-' || c == '@' || c == '.') {
2882 builder.append(c);
2883 } else {
2884 builder.append('x');
2885 }
2886 }
2887 return builder.toString();
2888 }
2889
Ihab Awad542e0ea2014-05-16 10:22:16 -07002890 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002891 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002892 if (mState == STATE_DISCONNECTED && mState != state) {
2893 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002894 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002895 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002896 if (mState != state) {
2897 Log.d(this, "setState: %s", stateToString(state));
2898 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002899 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002900 for (Listener l : mListeners) {
2901 l.onStateChanged(this, state);
2902 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002903 }
2904 }
2905
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002906 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002907 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002908 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2909 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002910 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002911 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002912
2913 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002914 if (mImmutable) {
2915 throw new UnsupportedOperationException("Connection is immutable");
2916 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002917 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002918 }
2919
Evan Charltonbf11f982014-07-20 22:06:28 -07002920 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002921 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002922 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2923 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002924 * <p>
2925 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2926 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002927 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002928 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002929 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002930 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002931 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2932 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002933 }
2934
Evan Charltonbf11f982014-07-20 22:06:28 -07002935 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002936 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2937 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2938 * this should never be un-@hide-den.
2939 *
2940 * @hide
2941 */
2942 public void checkImmutable() {}
2943
2944 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002945 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2946 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2947 * that state. This connection should not be used for anything, and no other
2948 * {@code Connection}s should be attempted.
2949 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002950 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002951 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002952 * @return A {@code Connection} which indicates that the underlying connection should
2953 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002954 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002955 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002956 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002957 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002958
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002959 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002960 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002961 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002962 }
2963 }
2964
Santos Cordon823fd3c2014-08-07 18:35:18 -07002965 private final void fireConferenceChanged() {
2966 for (Listener l : mListeners) {
2967 l.onConferenceChanged(this, mConference);
2968 }
2969 }
2970
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002971 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002972 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002973 if (c instanceof Connection) {
2974 Connection connection = (Connection) c;
2975 connection.removeConnectionListener(mConnectionDeathListener);
2976 } else if (c instanceof Conference) {
2977 Conference conference = (Conference) c;
2978 conference.removeListener(mConferenceDeathListener);
2979 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002980 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002981 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002982 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002983
2984 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002985 * Handles a change to extras received from Telecom.
2986 *
2987 * @param extras The new extras.
2988 * @hide
2989 */
2990 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002991 Bundle b = null;
2992 synchronized (mExtrasLock) {
2993 mExtras = extras;
2994 if (mExtras != null) {
2995 b = new Bundle(mExtras);
2996 }
2997 }
2998 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07002999 }
3000
3001 /**
Anthony Lee17455a32015-04-24 15:25:29 -07003002 * Notifies listeners that the merge request failed.
3003 *
3004 * @hide
3005 */
3006 protected final void notifyConferenceMergeFailed() {
3007 for (Listener l : mListeners) {
3008 l.onConferenceMergeFailed(this);
3009 }
3010 }
3011
3012 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08003013 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003014 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08003015 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003016 * @hide
3017 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08003018 protected final void updateConferenceParticipants(
3019 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003020 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08003021 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003022 }
3023 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003024
3025 /**
3026 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07003027 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003028 */
3029 protected void notifyConferenceStarted() {
3030 for (Listener l : mListeners) {
3031 l.onConferenceStarted();
3032 }
3033 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003034
3035 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07003036 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
3037 * be a part of a conference call.
3038 * @param isConferenceSupported {@code true} if the connection supports being part of a
3039 * conference call, {@code false} otherwise.
3040 * @hide
3041 */
3042 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
3043 for (Listener l : mListeners) {
3044 l.onConferenceSupportedChanged(this, isConferenceSupported);
3045 }
3046 }
3047
3048 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303049 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3050 * changed due to an emergency call being redialed.
3051 * @param pHandle The new PhoneAccountHandle for this connection.
3052 * @hide
3053 */
3054 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3055 for (Listener l : mListeners) {
3056 l.onPhoneAccountChanged(this, pHandle);
3057 }
3058 }
3059
3060 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003061 * Sends an event associated with this {@code Connection} with associated event extras to the
3062 * {@link InCallService}.
3063 * <p>
3064 * Connection events are used to communicate point in time information from a
3065 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3066 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3067 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3068 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3069 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3070 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3071 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3072 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3073 * <p>
3074 * Events are exposed to {@link InCallService} implementations via
3075 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3076 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003077 * 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 -07003078 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3079 * some events altogether.
3080 * <p>
3081 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3082 * conflicts between {@link ConnectionService} implementations. Further, custom
3083 * {@link ConnectionService} implementations shall not re-purpose events in the
3084 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3085 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3086 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3087 * {@code com.example.extra.MY_EXTRA}).
3088 * <p>
3089 * When defining events and the associated extras, it is important to keep their behavior
3090 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3091 * events/extras should me maintained to ensure backwards compatibility with older
3092 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003093 *
3094 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003095 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003096 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003097 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003098 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003099 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003100 }
3101 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003102}