blob: 72c66d20548a3465d2d1972e99d3f15bd74150a5 [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 Gunnd57d76c2019-09-24 14:53:23 -070019import android.annotation.IntDef;
Tyler Gunndee56a82016-03-23 16:06:34 -070020import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070021import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070022import android.annotation.SystemApi;
Tyler Gunn5567d742019-10-31 13:04:37 -070023import android.annotation.TestApi;
Tyler Gunn159f35c2017-03-02 09:28:37 -080024import android.app.Notification;
Hall Liua98f58b52017-11-07 17:59:28 -080025import android.bluetooth.BluetoothDevice;
Artur Satayev53ada2a2019-12-10 17:47:56 +000026import android.compat.annotation.UnsupportedAppUsage;
Tyler Gunn159f35c2017-03-02 09:28:37 -080027import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070028import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070029import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080030import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070031import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070032import android.os.Handler;
33import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070034import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070035import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080036import android.os.ParcelFileDescriptor;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070037import android.os.RemoteException;
Tyler Gunn3fa819c2017-08-04 09:27:26 -070038import android.os.SystemClock;
allenwtsu2aca9892019-11-25 14:38:21 +080039import android.telephony.ims.ImsStreamMediaProfile;
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
Youming Yed6de26e2019-01-30 11:20:35 -080043import com.android.internal.os.SomeArgs;
44import com.android.internal.telecom.IVideoCallback;
45import com.android.internal.telecom.IVideoProvider;
46
Hall Liua549fed2018-02-09 16:40:03 -080047import java.io.FileInputStream;
48import java.io.FileOutputStream;
Hall Liu95d55872017-01-25 17:12:49 -080049import java.io.IOException;
50import java.io.InputStreamReader;
51import java.io.OutputStreamWriter;
Tyler Gunnd57d76c2019-09-24 14:53:23 -070052import java.lang.annotation.Retention;
53import java.lang.annotation.RetentionPolicy;
Hall Liu730a2592018-06-25 19:48:33 -070054import java.nio.channels.Channels;
Santos Cordonb6939982014-06-04 20:20:58 -070055import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070056import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070057import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070058import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070059import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070060import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070061
62/**
Santos Cordon895d4b82015-06-25 16:41:48 -070063 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
64 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070065 * <p>
66 * Implementations create a custom subclass of {@code Connection} and return it to the framework
67 * as the return value of
68 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
69 * or
70 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
71 * Implementations are then responsible for updating the state of the {@code Connection}, and
72 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
73 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070074 * <p>
75 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
76 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
77 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
78 * {@code Connection} instance.
79 * <p>
80 * Basic call support requires overriding the following methods: {@link #onAnswer()},
81 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
82 * <p>
83 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
84 * {@link #onUnhold()} methods should be overridden to provide hold support for the
85 * {@code Connection}.
86 * <p>
87 * Where a {@code Connection} supports a variation of video calling (e.g. the
88 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
89 * to support answering a call as a video call.
90 * <p>
91 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
92 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
93 * support for pulling the external call.
94 * <p>
95 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
96 * overridden.
97 * <p>
98 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
99 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
100 * for example, call events from a {@link InCallService} are handled,
101 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
102 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
103 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
104 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700105 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -0700106public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700107
Santos Cordon895d4b82015-06-25 16:41:48 -0700108 /**
109 * The connection is initializing. This is generally the first state for a {@code Connection}
110 * returned by a {@link ConnectionService}.
111 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700112 public static final int STATE_INITIALIZING = 0;
113
Santos Cordon895d4b82015-06-25 16:41:48 -0700114 /**
115 * The connection is new and not connected.
116 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700117 public static final int STATE_NEW = 1;
118
Santos Cordon895d4b82015-06-25 16:41:48 -0700119 /**
120 * An incoming connection is in the ringing state. During this state, the user's ringer or
121 * vibration feature will be activated.
122 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700123 public static final int STATE_RINGING = 2;
124
Santos Cordon895d4b82015-06-25 16:41:48 -0700125 /**
126 * An outgoing connection is in the dialing state. In this state the other party has not yet
127 * answered the call and the user traditionally hears a ringback tone.
128 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700129 public static final int STATE_DIALING = 3;
130
Santos Cordon895d4b82015-06-25 16:41:48 -0700131 /**
132 * A connection is active. Both parties are connected to the call and can actively communicate.
133 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700134 public static final int STATE_ACTIVE = 4;
135
Santos Cordon895d4b82015-06-25 16:41:48 -0700136 /**
137 * A connection is on hold.
138 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700139 public static final int STATE_HOLDING = 5;
140
Santos Cordon895d4b82015-06-25 16:41:48 -0700141 /**
142 * A connection has been disconnected. This is the final state once the user has been
143 * disconnected from a call either locally, remotely or by an error in the service.
144 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700145 public static final int STATE_DISCONNECTED = 6;
146
Santos Cordon895d4b82015-06-25 16:41:48 -0700147 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700148 * The state of an external connection which is in the process of being pulled from a remote
149 * device to the local device.
150 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700151 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700152 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
153 */
154 public static final int STATE_PULLING_CALL = 7;
155
156 /**
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700157 * Indicates that the network could not perform verification.
158 */
159 public static final int VERIFICATION_STATUS_NOT_VERIFIED = 0;
160
161 /**
162 * Indicates that verification by the network passed. This indicates there is a high likelihood
163 * that the call originated from a valid source.
164 */
165 public static final int VERIFICATION_STATUS_PASSED = 1;
166
167 /**
168 * Indicates that verification by the network failed. This indicates there is a high likelihood
169 * that the call did not originate from a valid source.
170 */
171 public static final int VERIFICATION_STATUS_FAILED = 2;
172
173 /**@hide*/
174 @Retention(RetentionPolicy.SOURCE)
175 @IntDef(prefix = "VERIFICATION_STATUS_", value = {
176 VERIFICATION_STATUS_NOT_VERIFIED,
177 VERIFICATION_STATUS_PASSED,
178 VERIFICATION_STATUS_FAILED
179 })
180 public @interface VerificationStatus {}
181
182 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700183 * Connection can currently be put on hold or unheld. This is distinct from
184 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
185 * it does not at the moment support the function. This can be true while the call is in the
186 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
187 * display a disabled 'hold' button.
188 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800189 public static final int CAPABILITY_HOLD = 0x00000001;
190
191 /** Connection supports the hold feature. */
192 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
193
194 /**
195 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
196 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
197 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
198 * capability allows a merge button to be shown while the conference is in the foreground
199 * of the in-call UI.
200 * <p>
201 * This is only intended for use by a {@link Conference}.
202 */
203 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
204
205 /**
206 * Connections within a conference can be swapped between foreground and background.
207 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
208 * <p>
209 * This is only intended for use by a {@link Conference}.
210 */
211 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
212
213 /**
214 * @hide
215 */
216 public static final int CAPABILITY_UNUSED = 0x00000010;
217
218 /** Connection supports responding via text option. */
219 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
220
221 /** Connection can be muted. */
222 public static final int CAPABILITY_MUTE = 0x00000040;
223
224 /**
225 * Connection supports conference management. This capability only applies to
226 * {@link Conference}s which can have {@link Connection}s as children.
227 */
228 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
229
230 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700231 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800232 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700233 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800234
235 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700236 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800237 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700238 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800239
240 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700241 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800242 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700243 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700244 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800245
246 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700247 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800248 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700249 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
250
251 /**
252 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700253 */
254 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
255
256 /**
257 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700258 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700259 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700260 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800261
262 /**
263 * Connection is able to be separated from its parent {@code Conference}, if any.
264 */
265 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
266
267 /**
268 * Connection is able to be individually disconnected when in a {@code Conference}.
269 */
270 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
271
272 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700273 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800274 * @hide
275 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700276 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800277
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700278 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700279 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700280 * @hide
281 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700282 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700283
284 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700285 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700286 * @hide
287 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700288 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700289
Tyler Gunn068085b2015-02-06 13:56:52 -0800290 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700291 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800292 * @hide
293 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700294 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800295
Tyler Gunn96d6c402015-03-18 12:39:23 -0700296 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500297 * Speed up audio setup for MT call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700298 * <p>
299 * Used for IMS calls to indicate that mobile-terminated (incoming) call audio setup should take
300 * place as soon as the device answers the call, but prior to it being connected. This is an
301 * optimization some IMS stacks depend on to ensure prompt setup of call audio.
Dong Zhou89f41eb2015-03-15 11:59:49 -0500302 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700303 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700304 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700305 @TestApi
Tyler Gunn96d6c402015-03-18 12:39:23 -0700306 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800307
Rekha Kumar07366812015-03-24 16:42:31 -0700308 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700309 * Call can be upgraded to a video call.
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800310 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
311 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call whether or not
312 * video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700313 */
314 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
315
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700316 /**
317 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700318 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700319 */
320 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
321
Tyler Gunnd4091732015-06-29 09:15:37 -0700322 /**
323 * For a conference, indicates the conference will not have child connections.
324 * <p>
325 * An example of a conference with child connections is a GSM conference call, where the radio
326 * retains connections to the individual participants of the conference. Another example is an
327 * IMS conference call where conference event package functionality is supported; in this case
328 * the conference server ensures the radio is aware of the participants in the conference, which
329 * are represented by child connections.
330 * <p>
331 * An example of a conference with no child connections is an IMS conference call with no
332 * conference event package support. Such a conference is represented by the radio as a single
333 * connection to the IMS conference server.
334 * <p>
335 * Indicating whether a conference has children or not is important to help user interfaces
336 * visually represent a conference. A conference with no children, for example, will have the
337 * conference connection shown in the list of calls on a Bluetooth device, where if the
338 * conference has children, only the children will be shown in the list of calls on a Bluetooth
339 * device.
340 * @hide
341 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700342 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700343 @TestApi
Tyler Gunnd4091732015-06-29 09:15:37 -0700344 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
345
Bryce Lee81901682015-08-28 16:38:02 -0700346 /**
347 * Indicates that the connection itself wants to handle any sort of reply response, rather than
348 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700349 */
350 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
351
Tyler Gunnf97a0092016-01-19 15:59:34 -0800352 /**
353 * When set, prevents a video call from being downgraded to an audio-only call.
354 * <p>
355 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
356 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
357 * downgraded from a video call back to a VideoState of
358 * {@link VideoProfile#STATE_AUDIO_ONLY}.
359 * <p>
360 * Intuitively, a call which can be downgraded to audio should also have local and remote
361 * video
362 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
363 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
364 */
365 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
366
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700367 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700368 * When set for an external connection, indicates that this {@code Connection} can be pulled
369 * from a remote device to the current device.
370 * <p>
371 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
372 * is set.
373 */
374 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
375
Pooja Jaind34698d2017-12-28 14:15:31 +0530376 /** Call supports the deflect feature. */
377 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x02000000;
378
Tyler Gunn720c6642016-03-22 09:02:47 -0700379 //**********************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530380 // Next CAPABILITY value: 0x04000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700381 //**********************************************************************************************
382
383 /**
384 * Indicates that the current device callback number should be shown.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700385 * <p>
386 * Supports Telephony calls where CDMA emergency callback mode is active.
Tyler Gunn720c6642016-03-22 09:02:47 -0700387 * @hide
388 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700389 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700390 @TestApi
Hall Liu25c7c4d2016-08-30 13:41:02 -0700391 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700392
393 /**
394 * Whether the call is a generic conference, where we do not know the precise state of
395 * participants in the conference (eg. on CDMA).
Tyler Gunnc63f9082019-10-15 13:19:26 -0700396 * <p>
397 * Supports legacy telephony CDMA calls.
Tyler Gunn720c6642016-03-22 09:02:47 -0700398 * @hide
399 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700400 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700401 @TestApi
Tyler Gunn720c6642016-03-22 09:02:47 -0700402 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
403
404 /**
405 * Connection is using high definition audio.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700406 * <p>
407 * Indicates that the {@link Connection} is using a "high definition" audio codec. This usually
408 * implies something like AMR wideband, but the interpretation of when a call is considered high
409 * definition is left to the {@link ConnectionService} to decide.
410 * <p>
411 * Translates to {@link android.telecom.Call.Details#PROPERTY_HIGH_DEF_AUDIO}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700412 */
413 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
414
415 /**
416 * Connection is using WIFI.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700417 * <p>
418 * Used to indicate that a call is taking place over WIFI versus a carrier network.
419 * <p>
420 * Translates to {@link android.telecom.Call.Details#PROPERTY_WIFI}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700421 */
422 public static final int PROPERTY_WIFI = 1<<3;
423
424 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700425 * When set, indicates that the {@code Connection} does not actually exist locally for the
426 * {@link ConnectionService}.
427 * <p>
428 * Consider, for example, a scenario where a user has two devices with the same phone number.
429 * When a user places a call on one devices, the telephony stack can represent that call on the
430 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700431 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700432 * <p>
433 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
434 * external connections. Only those {@link InCallService}s which have the
435 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
436 * manifest will see external connections.
437 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700438 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700439
Brad Ebinger15847072016-05-18 11:08:36 -0700440 /**
441 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
442 */
443 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700444
Hall Liu9f332c72016-07-14 15:37:37 -0700445 /**
446 * Indicates that the connection represents a downgraded IMS conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700447 * <p>
448 * This property is set when an IMS conference undergoes SRVCC and is re-added to Telecom as a
449 * new entity to indicate that the new connection was a conference.
Hall Liu9f332c72016-07-14 15:37:37 -0700450 * @hide
451 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700452 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700453 @TestApi
Hall Liu9f332c72016-07-14 15:37:37 -0700454 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
455
Tyler Gunnf5035432017-01-09 09:43:12 -0800456 /**
457 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
458 * {@link ConnectionService}.
459 * <p>
460 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
461 */
462 public static final int PROPERTY_SELF_MANAGED = 1<<7;
463
Hall Liu95d55872017-01-25 17:12:49 -0800464 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800465 * Set by the framework to indicate that a connection has an active RTT session associated with
466 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800467 */
468 public static final int PROPERTY_IS_RTT = 1 << 8;
469
Eric Erfanian62706c52017-12-06 16:27:53 -0800470 /**
471 * Set by the framework to indicate that a connection is using assisted dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700472 * <p>
473 * This is used for outgoing calls.
474 *
475 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanian62706c52017-12-06 16:27:53 -0800476 */
477 public static final int PROPERTY_ASSISTED_DIALING_USED = 1 << 9;
478
Tyler Gunn5bd90852018-09-21 09:37:07 -0700479 /**
480 * Set by the framework to indicate that the network has identified a Connection as an emergency
481 * call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700482 * <p>
483 * This is used for incoming (mobile-terminated) calls to indicate the call is from emergency
484 * services.
Tyler Gunn5bd90852018-09-21 09:37:07 -0700485 */
486 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 1 << 10;
487
Tyler Gunnac60f952019-05-31 07:23:16 -0700488 /**
489 * Set by the framework to indicate that a Conference or Connection is hosted by a device other
490 * than the current one. Used in scenarios where the conference originator is the remote device
491 * and the current device is a participant of that conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700492 * <p>
493 * This property is specific to IMS conference calls originating in Telephony.
Tyler Gunnac60f952019-05-31 07:23:16 -0700494 * @hide
495 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700496 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700497 @TestApi
Tyler Gunnac60f952019-05-31 07:23:16 -0700498 public static final int PROPERTY_REMOTELY_HOSTED = 1 << 11;
499
Ravi Paluri80aa2142019-12-02 11:57:37 +0530500 /**
501 * Set by the framework to indicate that it is an adhoc conference call.
502 * <p>
503 * This is used for Outgoing and incoming conference calls.
504 *
505 */
506 public static final int PROPERTY_IS_ADHOC_CONFERENCE = 1 << 12;
507
508
Tyler Gunn96d6c402015-03-18 12:39:23 -0700509 //**********************************************************************************************
Ravi Paluri80aa2142019-12-02 11:57:37 +0530510 // Next PROPERTY value: 1<<13
Tyler Gunn96d6c402015-03-18 12:39:23 -0700511 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800512
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700513 /**
Tyler Gunn1c687622019-12-20 11:08:13 -0800514 * Indicates that the audio codec is currently not specified or is unknown.
allenwtsu2aca9892019-11-25 14:38:21 +0800515 */
allenwtsu2aca9892019-11-25 14:38:21 +0800516 public static final int AUDIO_CODEC_NONE = ImsStreamMediaProfile.AUDIO_QUALITY_NONE; // 0
Tyler Gunn1c687622019-12-20 11:08:13 -0800517 /**
518 * Adaptive Multi-rate audio codec.
519 */
allenwtsu2aca9892019-11-25 14:38:21 +0800520 public static final int AUDIO_CODEC_AMR = ImsStreamMediaProfile.AUDIO_QUALITY_AMR; // 1
Tyler Gunn1c687622019-12-20 11:08:13 -0800521 /**
522 * Adaptive Multi-rate wideband audio codec.
523 */
allenwtsu2aca9892019-11-25 14:38:21 +0800524 public static final int AUDIO_CODEC_AMR_WB = ImsStreamMediaProfile.AUDIO_QUALITY_AMR_WB; // 2
Tyler Gunn1c687622019-12-20 11:08:13 -0800525 /**
526 * Qualcomm code-excited linear prediction 13 kilobit audio codec.
527 */
allenwtsu2aca9892019-11-25 14:38:21 +0800528 public static final int AUDIO_CODEC_QCELP13K = ImsStreamMediaProfile.AUDIO_QUALITY_QCELP13K; //3
Tyler Gunn1c687622019-12-20 11:08:13 -0800529 /**
530 * Enhanced Variable Rate Codec. See 3GPP2 C.S0014-A.
531 */
allenwtsu2aca9892019-11-25 14:38:21 +0800532 public static final int AUDIO_CODEC_EVRC = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC; // 4
Tyler Gunn1c687622019-12-20 11:08:13 -0800533 /**
534 * Enhanced Variable Rate Codec B. Commonly used on CDMA networks.
535 */
allenwtsu2aca9892019-11-25 14:38:21 +0800536 public static final int AUDIO_CODEC_EVRC_B = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_B; // 5
Tyler Gunn1c687622019-12-20 11:08:13 -0800537 /**
538 * Enhanced Variable Rate Wideband Codec. See RFC5188.
539 */
allenwtsu2aca9892019-11-25 14:38:21 +0800540 public static final int AUDIO_CODEC_EVRC_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_WB; // 6
Tyler Gunn1c687622019-12-20 11:08:13 -0800541 /**
542 * Enhanced Variable Rate Narrowband-Wideband Codec.
543 */
allenwtsu2aca9892019-11-25 14:38:21 +0800544 public static final int AUDIO_CODEC_EVRC_NW = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_NW; // 7
Tyler Gunn1c687622019-12-20 11:08:13 -0800545 /**
546 * GSM Enhanced Full-Rate audio codec, also known as GSM-EFR, GSM 06.60, or simply EFR.
547 */
allenwtsu2aca9892019-11-25 14:38:21 +0800548 public static final int AUDIO_CODEC_GSM_EFR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_EFR; // 8
Tyler Gunn1c687622019-12-20 11:08:13 -0800549 /**
550 * GSM Full-Rate audio codec, also known as GSM-FR, GSM 06.10, GSM, or simply FR.
551 */
allenwtsu2aca9892019-11-25 14:38:21 +0800552 public static final int AUDIO_CODEC_GSM_FR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_FR; // 9
Tyler Gunn1c687622019-12-20 11:08:13 -0800553 /**
554 * GSM Half Rate audio codec.
555 */
allenwtsu2aca9892019-11-25 14:38:21 +0800556 public static final int AUDIO_CODEC_GSM_HR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_HR; // 10
Tyler Gunn1c687622019-12-20 11:08:13 -0800557 /**
558 * ITU-T G711U audio codec.
559 */
allenwtsu2aca9892019-11-25 14:38:21 +0800560 public static final int AUDIO_CODEC_G711U = ImsStreamMediaProfile.AUDIO_QUALITY_G711U; // 11
Tyler Gunn1c687622019-12-20 11:08:13 -0800561 /**
562 * ITU-T G723 audio codec.
563 */
allenwtsu2aca9892019-11-25 14:38:21 +0800564 public static final int AUDIO_CODEC_G723 = ImsStreamMediaProfile.AUDIO_QUALITY_G723; // 12
Tyler Gunn1c687622019-12-20 11:08:13 -0800565 /**
566 * ITU-T G711A audio codec.
567 */
allenwtsu2aca9892019-11-25 14:38:21 +0800568 public static final int AUDIO_CODEC_G711A = ImsStreamMediaProfile.AUDIO_QUALITY_G711A; // 13
Tyler Gunn1c687622019-12-20 11:08:13 -0800569 /**
570 * ITU-T G722 audio codec.
571 */
allenwtsu2aca9892019-11-25 14:38:21 +0800572 public static final int AUDIO_CODEC_G722 = ImsStreamMediaProfile.AUDIO_QUALITY_G722; // 14
Tyler Gunn1c687622019-12-20 11:08:13 -0800573 /**
574 * ITU-T G711AB audio codec.
575 */
allenwtsu2aca9892019-11-25 14:38:21 +0800576 public static final int AUDIO_CODEC_G711AB = ImsStreamMediaProfile.AUDIO_QUALITY_G711AB; // 15
Tyler Gunn1c687622019-12-20 11:08:13 -0800577 /**
578 * ITU-T G729 audio codec.
579 */
allenwtsu2aca9892019-11-25 14:38:21 +0800580 public static final int AUDIO_CODEC_G729 = ImsStreamMediaProfile.AUDIO_QUALITY_G729; // 16
Tyler Gunn1c687622019-12-20 11:08:13 -0800581 /**
582 * Enhanced Voice Services Narrowband audio codec. See 3GPP TS 26.441.
583 */
allenwtsu2aca9892019-11-25 14:38:21 +0800584 public static final int AUDIO_CODEC_EVS_NB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_NB; // 17
Tyler Gunn1c687622019-12-20 11:08:13 -0800585 /**
586 * Enhanced Voice Services Wideband audio codec. See 3GPP TS 26.441.
587 */
allenwtsu2aca9892019-11-25 14:38:21 +0800588 public static final int AUDIO_CODEC_EVS_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_WB; // 18
Tyler Gunn1c687622019-12-20 11:08:13 -0800589 /**
590 * Enhanced Voice Services Super-Wideband audio codec. See 3GPP TS 26.441.
591 */
allenwtsu2aca9892019-11-25 14:38:21 +0800592 public static final int AUDIO_CODEC_EVS_SWB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_SWB; // 19
Tyler Gunn1c687622019-12-20 11:08:13 -0800593 /**
594 * Enhanced Voice Services Fullband audio codec. See 3GPP TS 26.441.
595 */
allenwtsu2aca9892019-11-25 14:38:21 +0800596 public static final int AUDIO_CODEC_EVS_FB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_FB; // 20
597
Tyler Gunn1c687622019-12-20 11:08:13 -0800598 /**@hide*/
599 @Retention(RetentionPolicy.SOURCE)
600 @IntDef(prefix = "AUDIO_CODEC_", value = {
601 AUDIO_CODEC_NONE,
602 AUDIO_CODEC_AMR,
603 AUDIO_CODEC_AMR_WB,
604 AUDIO_CODEC_QCELP13K,
605 AUDIO_CODEC_EVRC,
606 AUDIO_CODEC_EVRC_B,
607 AUDIO_CODEC_EVRC_WB,
608 AUDIO_CODEC_EVRC_NW,
609 AUDIO_CODEC_GSM_EFR,
610 AUDIO_CODEC_GSM_FR,
611 AUDIO_CODEC_GSM_HR,
612 AUDIO_CODEC_G711U,
613 AUDIO_CODEC_G723,
614 AUDIO_CODEC_G711A,
615 AUDIO_CODEC_G722,
616 AUDIO_CODEC_G711AB,
617 AUDIO_CODEC_G729,
618 AUDIO_CODEC_EVS_NB,
619 AUDIO_CODEC_EVS_SWB,
620 AUDIO_CODEC_EVS_FB
621 })
622 public @interface AudioCodec {}
623
allenwtsu2aca9892019-11-25 14:38:21 +0800624 /**
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700625 * Connection extra key used to store the last forwarded number associated with the current
626 * connection. Used to communicate to the user interface that the connection was forwarded via
627 * the specified number.
628 */
629 public static final String EXTRA_LAST_FORWARDED_NUMBER =
630 "android.telecom.extra.LAST_FORWARDED_NUMBER";
631
632 /**
633 * Connection extra key used to store a child number associated with the current connection.
634 * Used to communicate to the user interface that the connection was received via
635 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
636 * address.
637 */
638 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
639
640 /**
641 * Connection extra key used to store the subject for an incoming call. The user interface can
642 * query this extra and display its contents for incoming calls. Will only be used if the
643 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
644 */
645 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
646
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800647 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700648 * Boolean connection extra key set on a {@link Connection} in
649 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
650 * current active foreground call to be dropped.
651 */
652 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
653 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
654
655 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700656 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
657 * state to indicate the name of the third-party app which is responsible for the current
658 * foreground call.
659 * <p>
660 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
661 * is able to inform the user that answering the new incoming call will cause a call owned by
662 * another app to be dropped when the incoming call is answered.
663 */
664 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
665 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
666
667 /**
Hall Liu10208662016-06-15 17:55:00 -0700668 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700669 * additional call is disallowed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700670 * <p>
671 * Used for mobile-network calls to identify scenarios where carrier requirements preclude
672 * adding another call at the current time.
Hall Liu10208662016-06-15 17:55:00 -0700673 * @hide
674 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700675 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700676 @TestApi
Hall Liuee6e86b2016-07-06 16:32:43 -0700677 public static final String EXTRA_DISABLE_ADD_CALL =
678 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700679
680 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700681 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
682 * original Connection ID associated with the connection. Used in
683 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
684 * connection/conference added via
685 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
686 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
687 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
688 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
689 * be a way to ensure that we don't add the connection again as a duplicate.
690 * <p>
691 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
692 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
693 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
694 * in a new {@link Connection} which it adds to Telecom via
695 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
696 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
697 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
698 * ID it originally referred to the connection as. Thus Telecom needs to know that the
699 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700700 * <p>
701 * This is an internal Telecom framework concept and is not exposed outside of the Telecom
702 * framework.
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700703 * @hide
704 */
705 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
706 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
707
708 /**
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700709 * Boolean connection extra key set on the extras passed to
710 * {@link Connection#sendConnectionEvent} which indicates that audio is present
711 * on the RTT call when the extra value is true.
712 */
713 public static final String EXTRA_IS_RTT_AUDIO_PRESENT =
714 "android.telecom.extra.IS_RTT_AUDIO_PRESENT";
715
716 /**
Tyler Gunn1c687622019-12-20 11:08:13 -0800717 * The audio codec in use for the current {@link Connection}, if known. Examples of valid
718 * values include {@link #AUDIO_CODEC_AMR_WB} and {@link #AUDIO_CODEC_EVS_WB}.
allenwtsu2aca9892019-11-25 14:38:21 +0800719 */
Tyler Gunn1c687622019-12-20 11:08:13 -0800720 public static final @AudioCodec String EXTRA_AUDIO_CODEC =
allenwtsu2aca9892019-11-25 14:38:21 +0800721 "android.telecom.extra.AUDIO_CODEC";
722
723 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800724 * Connection event used to inform Telecom that it should play the on hold tone. This is used
725 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700726 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800727 */
728 public static final String EVENT_ON_HOLD_TONE_START =
729 "android.telecom.event.ON_HOLD_TONE_START";
730
731 /**
732 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
733 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700734 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800735 */
736 public static final String EVENT_ON_HOLD_TONE_END =
737 "android.telecom.event.ON_HOLD_TONE_END";
738
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700739 /**
740 * Connection event used to inform {@link InCallService}s when pulling of an external call has
741 * failed. The user interface should inform the user of the error.
742 * <p>
743 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
744 * API is called on a {@link Call} with the properties
745 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
746 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
747 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700748 * <p>
749 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
750 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700751 */
752 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
753
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700754 /**
755 * Connection event used to inform {@link InCallService}s when the merging of two calls has
756 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700757 * <p>
758 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
759 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700760 */
761 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
762
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700763 /**
Hall Liu06ae75b2019-03-11 19:11:35 -0700764 * Connection event used to inform Telecom when a hold operation on a call has failed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700765 * <p>
Hall Liu06ae75b2019-03-11 19:11:35 -0700766 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
767 * expected to be null when this connection event is used.
Hall Liu06ae75b2019-03-11 19:11:35 -0700768 */
769 public static final String EVENT_CALL_HOLD_FAILED = "android.telecom.event.CALL_HOLD_FAILED";
770
771 /**
Masaho Nishikawacb8fa742019-11-07 14:41:21 +0900772 * Connection event used to inform Telecom when a switch operation on a call has failed.
773 * <p>
774 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
775 * expected to be null when this connection event is used.
776 */
777 public static final String EVENT_CALL_SWITCH_FAILED =
778 "android.telecom.event.CALL_SWITCH_FAILED";
779
780 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700781 * Connection event used to inform {@link InCallService}s when the process of merging a
782 * Connection into a conference has begun.
783 * <p>
784 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
785 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700786 */
787 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
788
789 /**
790 * Connection event used to inform {@link InCallService}s when the process of merging a
791 * Connection into a conference has completed.
792 * <p>
793 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
794 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700795 */
796 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
797
798 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700799 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
800 * the remote party.
801 * <p>
802 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
803 * call is being held locally on the device. When a capable {@link ConnectionService} receives
804 * signalling to indicate that the remote party has put the call on hold, it can send this
805 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700806 */
807 public static final String EVENT_CALL_REMOTELY_HELD =
808 "android.telecom.event.CALL_REMOTELY_HELD";
809
810 /**
811 * Connection event used to inform {@link InCallService}s when a call which was remotely held
812 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
813 * <p>
814 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
815 * call is being held locally on the device. When a capable {@link ConnectionService} receives
816 * signalling to indicate that the remote party has taken the call off hold, it can send this
817 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700818 */
819 public static final String EVENT_CALL_REMOTELY_UNHELD =
820 "android.telecom.event.CALL_REMOTELY_UNHELD";
821
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700822 /**
823 * Connection event used to inform an {@link InCallService} which initiated a call handover via
824 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
825 * successfully completed.
826 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700827 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
828 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700829 */
830 public static final String EVENT_HANDOVER_COMPLETE =
831 "android.telecom.event.HANDOVER_COMPLETE";
832
833 /**
834 * Connection event used to inform an {@link InCallService} which initiated a call handover via
835 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
836 * to complete.
837 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700838 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
839 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700840 */
841 public static final String EVENT_HANDOVER_FAILED =
842 "android.telecom.event.HANDOVER_FAILED";
843
shilub7ec9a02018-11-09 15:52:04 -0800844 /**
Shi Lu528eb5b2019-02-08 05:09:11 +0000845 * String Connection extra key used to store SIP invite fields for an incoming call for IMS call
shilub7ec9a02018-11-09 15:52:04 -0800846 */
847 public static final String EXTRA_SIP_INVITE = "android.telecom.extra.SIP_INVITE";
848
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700849 /**
850 * Connection event used to inform an {@link InCallService} that the RTT audio indication
851 * has changed.
852 */
853 public static final String EVENT_RTT_AUDIO_INDICATION_CHANGED =
854 "android.telecom.event.RTT_AUDIO_INDICATION_CHANGED";
855
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700856 // Flag controlling whether PII is emitted into the logs
857 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
858
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800859 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700860 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
861 *
862 * @param capabilities A capability bit field.
863 * @return A human readable string representation.
864 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800865 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700866 return capabilitiesToStringInternal(capabilities, true /* isLong */);
867 }
868
869 /**
870 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
871 * string.
872 *
873 * @param capabilities A capability bit field.
874 * @return A human readable string representation.
875 * @hide
876 */
877 public static String capabilitiesToStringShort(int capabilities) {
878 return capabilitiesToStringInternal(capabilities, false /* isLong */);
879 }
880
881 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800882 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700883 builder.append("[");
884 if (isLong) {
885 builder.append("Capabilities:");
886 }
887
Tyler Gunnc63f9082019-10-15 13:19:26 -0700888 if ((capabilities & CAPABILITY_HOLD) == CAPABILITY_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700889 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800890 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700891 if ((capabilities & CAPABILITY_SUPPORT_HOLD) == CAPABILITY_SUPPORT_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700892 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800893 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700894 if ((capabilities & CAPABILITY_MERGE_CONFERENCE) == CAPABILITY_MERGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700895 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800896 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700897 if ((capabilities & CAPABILITY_SWAP_CONFERENCE) == CAPABILITY_SWAP_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700898 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800899 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700900 if ((capabilities & CAPABILITY_RESPOND_VIA_TEXT) == CAPABILITY_RESPOND_VIA_TEXT) {
Santos Cordon1a749302016-07-26 16:08:53 -0700901 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800902 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700903 if ((capabilities & CAPABILITY_MUTE) == CAPABILITY_MUTE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700904 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800905 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700906 if ((capabilities & CAPABILITY_MANAGE_CONFERENCE) == CAPABILITY_MANAGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700907 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800908 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700909 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_RX) == CAPABILITY_SUPPORTS_VT_LOCAL_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700910 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700911 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700912 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_TX) == CAPABILITY_SUPPORTS_VT_LOCAL_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700913 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700914 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700915 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)
916 == CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700917 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800918 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700919 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_RX) == CAPABILITY_SUPPORTS_VT_REMOTE_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700920 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700921 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700922 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_TX) == CAPABILITY_SUPPORTS_VT_REMOTE_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700923 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700924 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700925 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)
926 == CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700927 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800928 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700929 if ((capabilities & CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)
930 == CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700931 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800932 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700933 if ((capabilities & CAPABILITY_SPEED_UP_MT_AUDIO) == CAPABILITY_SPEED_UP_MT_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700934 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500935 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700936 if ((capabilities & CAPABILITY_CAN_UPGRADE_TO_VIDEO) == CAPABILITY_CAN_UPGRADE_TO_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700937 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700938 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700939 if ((capabilities & CAPABILITY_CAN_PAUSE_VIDEO) == CAPABILITY_CAN_PAUSE_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700940 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700941 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700942 if ((capabilities & CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)
943 == CAPABILITY_CONFERENCE_HAS_NO_CHILDREN) {
Santos Cordon1a749302016-07-26 16:08:53 -0700944 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700945 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700946 if ((capabilities & CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)
947 == CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION) {
Santos Cordon1a749302016-07-26 16:08:53 -0700948 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700949 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700950 if ((capabilities & CAPABILITY_CAN_PULL_CALL) == CAPABILITY_CAN_PULL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700951 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700952 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700953 if ((capabilities & CAPABILITY_SUPPORT_DEFLECT) == CAPABILITY_SUPPORT_DEFLECT) {
Pooja Jaind34698d2017-12-28 14:15:31 +0530954 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
955 }
Bryce Lee81901682015-08-28 16:38:02 -0700956
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800957 builder.append("]");
958 return builder.toString();
959 }
960
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700961 /**
962 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
963 *
964 * @param properties A property bit field.
965 * @return A human readable string representation.
966 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700967 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700968 return propertiesToStringInternal(properties, true /* isLong */);
969 }
970
971 /**
972 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
973 *
974 * @param properties A property bit field.
975 * @return A human readable string representation.
976 * @hide
977 */
978 public static String propertiesToStringShort(int properties) {
979 return propertiesToStringInternal(properties, false /* isLong */);
980 }
981
982 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700983 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700984 builder.append("[");
985 if (isLong) {
986 builder.append("Properties:");
987 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700988
Tyler Gunnc63f9082019-10-15 13:19:26 -0700989 if ((properties & PROPERTY_SELF_MANAGED) == PROPERTY_SELF_MANAGED) {
Tyler Gunnf5035432017-01-09 09:43:12 -0800990 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
991 }
992
Tyler Gunnc63f9082019-10-15 13:19:26 -0700993 if ((properties & PROPERTY_EMERGENCY_CALLBACK_MODE) == PROPERTY_EMERGENCY_CALLBACK_MODE) {
Hall Liu25c7c4d2016-08-30 13:41:02 -0700994 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700995 }
996
Tyler Gunnc63f9082019-10-15 13:19:26 -0700997 if ((properties & PROPERTY_HIGH_DEF_AUDIO) == PROPERTY_HIGH_DEF_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700998 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700999 }
1000
Tyler Gunnc63f9082019-10-15 13:19:26 -07001001 if ((properties & PROPERTY_WIFI) == PROPERTY_WIFI) {
Santos Cordon1a749302016-07-26 16:08:53 -07001002 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -07001003 }
1004
Tyler Gunnc63f9082019-10-15 13:19:26 -07001005 if ((properties & PROPERTY_GENERIC_CONFERENCE) == PROPERTY_GENERIC_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001006 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -07001007 }
1008
Tyler Gunnc63f9082019-10-15 13:19:26 -07001009 if ((properties & PROPERTY_IS_EXTERNAL_CALL) == PROPERTY_IS_EXTERNAL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001010 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -07001011 }
1012
Tyler Gunnc63f9082019-10-15 13:19:26 -07001013 if ((properties & PROPERTY_HAS_CDMA_VOICE_PRIVACY) == PROPERTY_HAS_CDMA_VOICE_PRIVACY) {
Santos Cordon1a749302016-07-26 16:08:53 -07001014 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -07001015 }
1016
Tyler Gunnc63f9082019-10-15 13:19:26 -07001017 if ((properties & PROPERTY_IS_RTT) == PROPERTY_IS_RTT) {
Hall Liud4d2a8a2018-01-29 17:22:02 -08001018 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
1019 }
1020
Tyler Gunnc63f9082019-10-15 13:19:26 -07001021 if ((properties & PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)
1022 == PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL) {
Tyler Gunn5bd90852018-09-21 09:37:07 -07001023 builder.append(isLong ? " PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL" : " ecall");
1024 }
1025
Tyler Gunnc63f9082019-10-15 13:19:26 -07001026 if ((properties & PROPERTY_REMOTELY_HOSTED) == PROPERTY_REMOTELY_HOSTED) {
Tyler Gunnac60f952019-05-31 07:23:16 -07001027 builder.append(isLong ? " PROPERTY_REMOTELY_HOSTED" : " remote_hst");
1028 }
1029
Ravi Paluri80aa2142019-12-02 11:57:37 +05301030 if ((properties & PROPERTY_IS_ADHOC_CONFERENCE) == PROPERTY_IS_ADHOC_CONFERENCE) {
1031 builder.append(isLong ? " PROPERTY_IS_ADHOC_CONFERENCE" : " adhoc_conf");
1032 }
1033
Tyler Gunn720c6642016-03-22 09:02:47 -07001034 builder.append("]");
1035 return builder.toString();
1036 }
1037
Sailesh Nepal091768c2014-06-30 15:15:23 -07001038 /** @hide */
Tyler Gunn633e4c32019-10-24 15:40:48 -07001039 abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001040 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -07001041 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -07001042 public void onCallerDisplayNameChanged(
1043 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -07001044 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001045 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -07001046 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001047 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -07001048 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -07001049 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001050 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -07001051 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001052 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001053 public void onVideoProviderChanged(
1054 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001055 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
1056 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001057 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001058 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -07001059 public void onConferenceChanged(Connection c, Conference conference) {}
Anthony Lee17455a32015-04-24 15:25:29 -07001060 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -07001061 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -07001062 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001063 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Hall Liua98f58b52017-11-07 17:59:28 -08001064 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001065 public void onRttInitiationSuccess(Connection c) {}
1066 public void onRttInitiationFailure(Connection c, int reason) {}
1067 public void onRttSessionRemotelyTerminated(Connection c) {}
1068 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301069 /** @hide */
1070 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +08001071 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001072 }
1073
Tyler Gunnb702ef82015-05-29 11:51:53 -07001074 /**
Hall Liu95d55872017-01-25 17:12:49 -08001075 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -08001076 */
1077 public static final class RttTextStream {
1078 private static final int READ_BUFFER_SIZE = 1000;
1079 private final InputStreamReader mPipeFromInCall;
1080 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -08001081 private final ParcelFileDescriptor mFdFromInCall;
1082 private final ParcelFileDescriptor mFdToInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -07001083
1084 private final FileInputStream mFromInCallFileInputStream;
Hall Liu95d55872017-01-25 17:12:49 -08001085 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1086
1087 /**
1088 * @hide
1089 */
1090 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -08001091 mFdFromInCall = fromInCall;
1092 mFdToInCall = toInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -07001093 mFromInCallFileInputStream = new FileInputStream(fromInCall.getFileDescriptor());
Hall Liu730a2592018-06-25 19:48:33 -07001094
1095 // Wrap the FileInputStream in a Channel so that it's interruptible.
Hall Liu95d55872017-01-25 17:12:49 -08001096 mPipeFromInCall = new InputStreamReader(
Hall Liu17eb1bd2018-07-03 15:17:41 -07001097 Channels.newInputStream(Channels.newChannel(mFromInCallFileInputStream)));
Hall Liu95d55872017-01-25 17:12:49 -08001098 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -08001099 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -08001100 }
1101
1102 /**
1103 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
1104 * RTT transmits text in real-time, this method should be called as often as text snippets
1105 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -08001106 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001107 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1108 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001109 *
Hall Liu95d55872017-01-25 17:12:49 -08001110 * @param input The message to send to the in-call app.
1111 */
1112 public void write(String input) throws IOException {
1113 mPipeToInCall.write(input);
1114 mPipeToInCall.flush();
1115 }
1116
1117
1118 /**
1119 * Reads a string from the in-call app, blocking if there is no data available. Returns
1120 * {@code null} if the RTT conversation has been terminated and there is no further data
1121 * to read.
Hall Liua549fed2018-02-09 16:40:03 -08001122 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001123 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1124 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001125 *
Hall Liu95d55872017-01-25 17:12:49 -08001126 * @return A string containing text entered by the user, or {@code null} if the
1127 * conversation has been terminated or if there was an error while reading.
1128 */
Hall Liuffa4a812017-03-02 16:11:00 -08001129 public String read() throws IOException {
1130 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1131 if (numRead < 0) {
1132 return null;
1133 }
1134 return new String(mReadBuffer, 0, numRead);
1135 }
1136
1137 /**
1138 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1139 * be read.
Hall Liua549fed2018-02-09 16:40:03 -08001140 *
Hall Liuffa4a812017-03-02 16:11:00 -08001141 * @return A string containing text entered by the user, or {@code null} if the user has
1142 * not entered any new text yet.
1143 */
1144 public String readImmediately() throws IOException {
Hall Liu17eb1bd2018-07-03 15:17:41 -07001145 if (mFromInCallFileInputStream.available() > 0) {
Hall Liuffa4a812017-03-02 16:11:00 -08001146 return read();
1147 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001148 return null;
1149 }
1150 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001151
1152 /** @hide */
1153 public ParcelFileDescriptor getFdFromInCall() {
1154 return mFdFromInCall;
1155 }
1156
1157 /** @hide */
1158 public ParcelFileDescriptor getFdToInCall() {
1159 return mFdToInCall;
1160 }
1161 }
1162
1163 /**
1164 * Provides constants to represent the results of responses to session modify requests sent via
1165 * {@link Call#sendRttRequest()}
1166 */
1167 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -07001168 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001169 /**
1170 * Session modify request was successful.
1171 */
1172 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1173
1174 /**
1175 * Session modify request failed.
1176 */
1177 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1178
1179 /**
1180 * Session modify request ignored due to invalid parameters.
1181 */
1182 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1183
1184 /**
1185 * Session modify request timed out.
1186 */
1187 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1188
1189 /**
1190 * Session modify request rejected by remote user.
1191 */
1192 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -08001193 }
1194
1195 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001196 * Provides a means of controlling the video session associated with a {@link Connection}.
1197 * <p>
1198 * Implementations create a custom subclass of {@link VideoProvider} and the
1199 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
1200 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
1201 * should set the {@link VideoProvider}.
1202 * <p>
1203 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
1204 * {@link InCallService} implementations to issue requests related to the video session;
1205 * it provides a means for the {@link ConnectionService} to report events and information
1206 * related to the video session to Telecom and the {@link InCallService} implementations.
1207 * <p>
1208 * {@link InCallService} implementations interact with the {@link VideoProvider} via
1209 * {@link android.telecom.InCallService.VideoCall}.
1210 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001211 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001212 /**
1213 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -07001214 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001215 */
1216 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001217
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001218 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001219 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
1220 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001221 */
1222 public static final int SESSION_EVENT_RX_RESUME = 2;
1223
1224 /**
1225 * Video transmission has begun. This occurs after a negotiated start of video transmission
1226 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001227 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001228 */
1229 public static final int SESSION_EVENT_TX_START = 3;
1230
1231 /**
1232 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1233 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001234 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001235 */
1236 public static final int SESSION_EVENT_TX_STOP = 4;
1237
1238 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001239 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001240 * this as a cue to inform the user the camera is not available.
1241 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001242 */
1243 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1244
1245 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001246 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001247 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001248 * the camera has become available again.
1249 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001250 */
1251 public static final int SESSION_EVENT_CAMERA_READY = 6;
1252
1253 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001254 * Session event raised by Telecom when
1255 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1256 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1257 * @see #handleCallSessionEvent(int)
1258 */
1259 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1260
1261 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001262 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001263 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001264 */
1265 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1266
1267 /**
1268 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001269 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001270 */
1271 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1272
1273 /**
1274 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001275 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001276 */
1277 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1278
Rekha Kumar07366812015-03-24 16:42:31 -07001279 /**
1280 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001281 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001282 */
1283 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1284
1285 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001286 * Session modify request rejected by remote user.
1287 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001288 */
1289 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1290
Tyler Gunn75958422015-04-15 14:23:42 -07001291 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001292 private static final int MSG_SET_CAMERA = 2;
1293 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1294 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1295 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1296 private static final int MSG_SET_ZOOM = 6;
1297 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1298 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1299 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001300 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001301 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001302 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001303
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001304 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1305 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1306 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1307 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1308 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1309 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001310 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1311 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001312 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1313
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001314 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001315 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001316
1317 /**
1318 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001319 *
1320 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1321 * load factor before resizing, 1 means we only expect a single thread to
1322 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001323 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001324 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1325 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001326
1327 /**
1328 * Default handler used to consolidate binder method calls onto a single thread.
1329 */
1330 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001331 public VideoProviderHandler() {
1332 super();
1333 }
1334
1335 public VideoProviderHandler(Looper looper) {
1336 super(looper);
1337 }
1338
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001339 @Override
1340 public void handleMessage(Message msg) {
1341 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001342 case MSG_ADD_VIDEO_CALLBACK: {
1343 IBinder binder = (IBinder) msg.obj;
1344 IVideoCallback callback = IVideoCallback.Stub
1345 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001346 if (callback == null) {
1347 Log.w(this, "addVideoProvider - skipped; callback is null.");
1348 break;
1349 }
1350
Tyler Gunn75958422015-04-15 14:23:42 -07001351 if (mVideoCallbacks.containsKey(binder)) {
1352 Log.i(this, "addVideoProvider - skipped; already present.");
1353 break;
1354 }
1355 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001356 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001357 }
1358 case MSG_REMOVE_VIDEO_CALLBACK: {
1359 IBinder binder = (IBinder) msg.obj;
1360 IVideoCallback callback = IVideoCallback.Stub
1361 .asInterface((IBinder) msg.obj);
1362 if (!mVideoCallbacks.containsKey(binder)) {
1363 Log.i(this, "removeVideoProvider - skipped; not present.");
1364 break;
1365 }
1366 mVideoCallbacks.remove(binder);
1367 break;
1368 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001369 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001370 {
1371 SomeArgs args = (SomeArgs) msg.obj;
1372 try {
1373 onSetCamera((String) args.arg1);
1374 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001375 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001376 } finally {
1377 args.recycle();
1378 }
1379 }
1380 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001381 case MSG_SET_PREVIEW_SURFACE:
1382 onSetPreviewSurface((Surface) msg.obj);
1383 break;
1384 case MSG_SET_DISPLAY_SURFACE:
1385 onSetDisplaySurface((Surface) msg.obj);
1386 break;
1387 case MSG_SET_DEVICE_ORIENTATION:
1388 onSetDeviceOrientation(msg.arg1);
1389 break;
1390 case MSG_SET_ZOOM:
1391 onSetZoom((Float) msg.obj);
1392 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001393 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1394 SomeArgs args = (SomeArgs) msg.obj;
1395 try {
1396 onSendSessionModifyRequest((VideoProfile) args.arg1,
1397 (VideoProfile) args.arg2);
1398 } finally {
1399 args.recycle();
1400 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001401 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001402 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001403 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1404 onSendSessionModifyResponse((VideoProfile) msg.obj);
1405 break;
1406 case MSG_REQUEST_CAMERA_CAPABILITIES:
1407 onRequestCameraCapabilities();
1408 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001409 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1410 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001411 break;
1412 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001413 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001414 break;
1415 default:
1416 break;
1417 }
1418 }
1419 }
1420
1421 /**
1422 * IVideoProvider stub implementation.
1423 */
1424 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001425 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001426 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001427 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1428 }
1429
1430 public void removeVideoCallback(IBinder videoCallbackBinder) {
1431 mMessageHandler.obtainMessage(
1432 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001433 }
1434
Tyler Gunn159f35c2017-03-02 09:28:37 -08001435 public void setCamera(String cameraId, String callingPackageName,
1436 int targetSdkVersion) {
1437
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001438 SomeArgs args = SomeArgs.obtain();
1439 args.arg1 = cameraId;
1440 // Propagate the calling package; originally determined in
1441 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1442 // process.
1443 args.arg2 = callingPackageName;
1444 // Pass along the uid and pid of the calling app; this gets lost when we put the
1445 // message onto the handler. These are required for Telecom to perform a permission
1446 // check to see if the calling app is able to use the camera.
1447 args.argi1 = Binder.getCallingUid();
1448 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001449 // Pass along the target SDK version of the calling InCallService. This is used to
1450 // maintain backwards compatibility of the API for older callers.
1451 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001452 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001453 }
1454
1455 public void setPreviewSurface(Surface surface) {
1456 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1457 }
1458
1459 public void setDisplaySurface(Surface surface) {
1460 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1461 }
1462
1463 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001464 mMessageHandler.obtainMessage(
1465 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001466 }
1467
1468 public void setZoom(float value) {
1469 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1470 }
1471
Tyler Gunn45382162015-05-06 08:52:27 -07001472 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1473 SomeArgs args = SomeArgs.obtain();
1474 args.arg1 = fromProfile;
1475 args.arg2 = toProfile;
1476 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001477 }
1478
1479 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1480 mMessageHandler.obtainMessage(
1481 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1482 }
1483
1484 public void requestCameraCapabilities() {
1485 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1486 }
1487
1488 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001489 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001490 }
1491
Yorke Lee32f24732015-05-12 16:18:03 -07001492 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001493 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1494 }
1495 }
1496
1497 public VideoProvider() {
1498 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001499 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001500 }
1501
1502 /**
1503 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1504 *
1505 * @param looper The looper.
1506 * @hide
1507 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001508 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001509 public VideoProvider(Looper looper) {
1510 mBinder = new VideoProvider.VideoProviderBinder();
1511 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001512 }
1513
1514 /**
1515 * Returns binder object which can be used across IPC methods.
1516 * @hide
1517 */
1518 public final IVideoProvider getInterface() {
1519 return mBinder;
1520 }
1521
1522 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001523 * Sets the camera to be used for the outgoing video.
1524 * <p>
1525 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1526 * camera via
1527 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1528 * <p>
1529 * Sent from the {@link InCallService} via
1530 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001531 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001532 * @param cameraId The id of the camera (use ids as reported by
1533 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001534 */
1535 public abstract void onSetCamera(String cameraId);
1536
1537 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001538 * Sets the camera to be used for the outgoing video.
1539 * <p>
1540 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1541 * camera via
1542 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1543 * <p>
1544 * This prototype is used internally to ensure that the calling package name, UID and PID
1545 * are sent to Telecom so that can perform a camera permission check on the caller.
1546 * <p>
1547 * Sent from the {@link InCallService} via
1548 * {@link InCallService.VideoCall#setCamera(String)}.
1549 *
1550 * @param cameraId The id of the camera (use ids as reported by
1551 * {@link CameraManager#getCameraIdList()}).
1552 * @param callingPackageName The AppOpps package name of the caller.
1553 * @param callingUid The UID of the caller.
1554 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001555 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001556 * @hide
1557 */
1558 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001559 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001560
1561 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001562 * Sets the surface to be used for displaying a preview of what the user's camera is
1563 * currently capturing. When video transmission is enabled, this is the video signal which
1564 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001565 * <p>
1566 * Sent from the {@link InCallService} via
1567 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001568 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001569 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001570 */
1571 public abstract void onSetPreviewSurface(Surface surface);
1572
1573 /**
1574 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001575 * <p>
1576 * Sent from the {@link InCallService} via
1577 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001578 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001579 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001580 */
1581 public abstract void onSetDisplaySurface(Surface surface);
1582
1583 /**
1584 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1585 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001586 * <p>
1587 * Sent from the {@link InCallService} via
1588 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001589 *
1590 * @param rotation The device orientation, in degrees.
1591 */
1592 public abstract void onSetDeviceOrientation(int rotation);
1593
1594 /**
1595 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001596 * <p>
1597 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001598 *
1599 * @param value The camera zoom ratio.
1600 */
1601 public abstract void onSetZoom(float value);
1602
1603 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001604 * Issues a request to modify the properties of the current video session.
1605 * <p>
1606 * Example scenarios include: requesting an audio-only call to be upgraded to a
1607 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1608 * when the {@link InCallService} is no longer the foreground application.
1609 * <p>
1610 * If the {@link VideoProvider} determines a request to be invalid, it should call
1611 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1612 * invalid request back to the {@link InCallService}.
1613 * <p>
1614 * Where a request requires confirmation from the user of the peer device, the
1615 * {@link VideoProvider} must communicate the request to the peer device and handle the
1616 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1617 * is used to inform the {@link InCallService} of the result of the request.
1618 * <p>
1619 * Sent from the {@link InCallService} via
1620 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001621 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001622 * @param fromProfile The video profile prior to the request.
1623 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001624 */
Tyler Gunn45382162015-05-06 08:52:27 -07001625 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1626 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001627
Tyler Gunnb702ef82015-05-29 11:51:53 -07001628 /**
1629 * Provides a response to a request to change the current video session properties.
1630 * <p>
1631 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1632 * video call, could decline the request and keep the call as audio-only.
1633 * In such a scenario, the {@code responseProfile} would have a video state of
1634 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1635 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1636 * <p>
1637 * Sent from the {@link InCallService} via
1638 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1639 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1640 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001641 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001642 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001643 */
1644 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1645
1646 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001647 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1648 * <p>
1649 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1650 * camera via
1651 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1652 * <p>
1653 * Sent from the {@link InCallService} via
1654 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001655 */
1656 public abstract void onRequestCameraCapabilities();
1657
1658 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001659 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1660 * video component of the current {@link Connection}.
1661 * <p>
1662 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1663 * via {@link VideoProvider#setCallDataUsage(long)}.
1664 * <p>
1665 * Sent from the {@link InCallService} via
1666 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001667 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001668 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001669
1670 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001671 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1672 * the peer device when the video signal is paused.
1673 * <p>
1674 * Sent from the {@link InCallService} via
1675 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001676 *
1677 * @param uri URI of image to display.
1678 */
Yorke Lee32f24732015-05-12 16:18:03 -07001679 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001680
1681 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001682 * Used to inform listening {@link InCallService} implementations when the
1683 * {@link VideoProvider} receives a session modification request.
1684 * <p>
1685 * Received by the {@link InCallService} via
1686 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001687 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001688 * @param videoProfile The requested video profile.
1689 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001690 */
1691 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001692 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001693 for (IVideoCallback callback : mVideoCallbacks.values()) {
1694 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001695 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001696 } catch (RemoteException ignored) {
1697 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001698 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001699 }
1700 }
1701 }
1702
1703 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001704 * Used to inform listening {@link InCallService} implementations when the
1705 * {@link VideoProvider} receives a response to a session modification request.
1706 * <p>
1707 * Received by the {@link InCallService} via
1708 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1709 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001710 *
1711 * @param status Status of the session modify request. Valid values are
1712 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1713 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001714 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1715 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1716 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1717 * @param requestedProfile The original request which was sent to the peer device.
1718 * @param responseProfile The actual profile changes agreed to by the peer device.
1719 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001720 */
1721 public void receiveSessionModifyResponse(int status,
1722 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001723 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001724 for (IVideoCallback callback : mVideoCallbacks.values()) {
1725 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001726 callback.receiveSessionModifyResponse(status, requestedProfile,
1727 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001728 } catch (RemoteException ignored) {
1729 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001730 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001731 }
1732 }
1733 }
1734
1735 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001736 * Used to inform listening {@link InCallService} implementations when the
1737 * {@link VideoProvider} reports a call session event.
1738 * <p>
1739 * Received by the {@link InCallService} via
1740 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001741 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001742 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1743 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1744 * {@link VideoProvider#SESSION_EVENT_TX_START},
1745 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1746 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001747 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1748 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001749 */
1750 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001751 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001752 for (IVideoCallback callback : mVideoCallbacks.values()) {
1753 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001754 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001755 } catch (RemoteException ignored) {
1756 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001757 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001758 }
1759 }
1760 }
1761
1762 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001763 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1764 * peer's video have changed.
1765 * <p>
1766 * This could occur if, for example, the peer rotates their device, changing the aspect
1767 * ratio of the video, or if the user switches between the back and front cameras.
1768 * <p>
1769 * Received by the {@link InCallService} via
1770 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001771 *
1772 * @param width The updated peer video width.
1773 * @param height The updated peer video height.
1774 */
1775 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001776 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001777 for (IVideoCallback callback : mVideoCallbacks.values()) {
1778 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001779 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001780 } catch (RemoteException ignored) {
1781 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001782 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001783 }
1784 }
1785 }
1786
1787 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001788 * Used to inform listening {@link InCallService} implementations when the data usage of the
1789 * video associated with the current {@link Connection} has changed.
1790 * <p>
1791 * This could be in response to a preview request via
1792 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001793 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1794 * 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 -07001795 * <p>
1796 * Received by the {@link InCallService} via
1797 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001798 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001799 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1800 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001801 */
Yorke Lee32f24732015-05-12 16:18:03 -07001802 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001803 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001804 for (IVideoCallback callback : mVideoCallbacks.values()) {
1805 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001806 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001807 } catch (RemoteException ignored) {
1808 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001809 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001810 }
1811 }
1812 }
1813
1814 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001815 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001816 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001817 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001818 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1819 * @hide
1820 */
1821 public void changeCallDataUsage(long dataUsage) {
1822 setCallDataUsage(dataUsage);
1823 }
1824
1825 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001826 * Used to inform listening {@link InCallService} implementations when the capabilities of
1827 * the current camera have changed.
1828 * <p>
1829 * The {@link VideoProvider} should call this in response to
1830 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1831 * changed via {@link VideoProvider#onSetCamera(String)}.
1832 * <p>
1833 * Received by the {@link InCallService} via
1834 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1835 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001836 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001837 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001838 */
Yorke Lee400470f2015-05-12 13:31:25 -07001839 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001840 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001841 for (IVideoCallback callback : mVideoCallbacks.values()) {
1842 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001843 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001844 } catch (RemoteException ignored) {
1845 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001846 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001847 }
1848 }
1849 }
Rekha Kumar07366812015-03-24 16:42:31 -07001850
1851 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001852 * Used to inform listening {@link InCallService} implementations when the video quality
1853 * of the call has changed.
1854 * <p>
1855 * Received by the {@link InCallService} via
1856 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001857 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001858 * @param videoQuality The updated video quality. Valid values:
1859 * {@link VideoProfile#QUALITY_HIGH},
1860 * {@link VideoProfile#QUALITY_MEDIUM},
1861 * {@link VideoProfile#QUALITY_LOW},
1862 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001863 */
1864 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001865 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001866 for (IVideoCallback callback : mVideoCallbacks.values()) {
1867 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001868 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001869 } catch (RemoteException ignored) {
1870 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001871 }
Rekha Kumar07366812015-03-24 16:42:31 -07001872 }
1873 }
1874 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001875
1876 /**
1877 * Returns a string representation of a call session event.
1878 *
1879 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1880 * @return String representation of the call session event.
1881 * @hide
1882 */
1883 public static String sessionEventToString(int event) {
1884 switch (event) {
1885 case SESSION_EVENT_CAMERA_FAILURE:
1886 return SESSION_EVENT_CAMERA_FAILURE_STR;
1887 case SESSION_EVENT_CAMERA_READY:
1888 return SESSION_EVENT_CAMERA_READY_STR;
1889 case SESSION_EVENT_RX_PAUSE:
1890 return SESSION_EVENT_RX_PAUSE_STR;
1891 case SESSION_EVENT_RX_RESUME:
1892 return SESSION_EVENT_RX_RESUME_STR;
1893 case SESSION_EVENT_TX_START:
1894 return SESSION_EVENT_TX_START_STR;
1895 case SESSION_EVENT_TX_STOP:
1896 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001897 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1898 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001899 default:
1900 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1901 }
1902 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001903 }
1904
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001905 private final Listener mConnectionDeathListener = new Listener() {
1906 @Override
1907 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001908 if (mConferenceables.remove(c)) {
1909 fireOnConferenceableConnectionsChanged();
1910 }
1911 }
1912 };
1913
1914 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1915 @Override
1916 public void onDestroyed(Conference c) {
1917 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001918 fireOnConferenceableConnectionsChanged();
1919 }
1920 }
1921 };
1922
Jay Shrauner229e3822014-08-15 09:23:07 -07001923 /**
1924 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1925 * load factor before resizing, 1 means we only expect a single thread to
1926 * access the map so make only a single shard
1927 */
1928 private final Set<Listener> mListeners = Collections.newSetFromMap(
1929 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001930 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1931 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001932 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001933
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001934 // The internal telecom call ID associated with this connection.
1935 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07001936 // The PhoneAccountHandle associated with this connection.
1937 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001938 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001939 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001940 private Uri mAddress;
1941 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001942 private String mCallerDisplayName;
1943 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001944 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001945 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001946 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001947 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001948 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001949 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001950 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001951 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001952 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001953 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001954 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001955 private Conference mConference;
1956 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001957 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001958 private final Object mExtrasLock = new Object();
Tyler Gunn6986a632019-06-25 13:45:32 -07001959 /**
1960 * The direction of the connection; used where an existing connection is created and we need to
1961 * communicate to Telecom whether its incoming or outgoing.
1962 */
1963 private @Call.Details.CallDirection int mCallDirection = Call.Details.DIRECTION_UNKNOWN;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001964
1965 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001966 * Tracks the key set for the extras bundle provided on the last invocation of
1967 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1968 * keys which were set previously but are no longer present in the replacement Bundle.
1969 */
1970 private Set<String> mPreviousExtraKeys;
1971
1972 /**
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001973 * The verification status for an incoming call's phone number.
1974 */
1975 private @VerificationStatus int mCallerNumberVerificationStatus;
1976
1977
1978 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001979 * Create a new Connection.
1980 */
Santos Cordonf2951102014-07-20 19:06:29 -07001981 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001982
1983 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001984 * Returns the Telecom internal call ID associated with this connection. Should only be used
1985 * for debugging and tracing purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07001986 * <p>
1987 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
1988 * provided to facilitate debugging of the Telephony stack only.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001989 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07001990 * @return The Telecom call ID, or {@code null} if it was not set.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001991 * @hide
1992 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07001993 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07001994 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07001995 public final @Nullable String getTelecomCallId() {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001996 return mTelecomCallId;
1997 }
1998
1999 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002000 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002001 */
Andrew Lee100e2932014-09-08 15:34:24 -07002002 public final Uri getAddress() {
2003 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002004 }
2005
2006 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002007 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002008 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07002009 */
Andrew Lee100e2932014-09-08 15:34:24 -07002010 public final int getAddressPresentation() {
2011 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07002012 }
2013
2014 /**
2015 * @return The caller display name (CNAP).
2016 */
2017 public final String getCallerDisplayName() {
2018 return mCallerDisplayName;
2019 }
2020
2021 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07002022 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002023 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07002024 */
2025 public final int getCallerDisplayNamePresentation() {
2026 return mCallerDisplayNamePresentation;
2027 }
2028
2029 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002030 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002031 */
2032 public final int getState() {
2033 return mState;
2034 }
2035
2036 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002037 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002038 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2039 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2040 * {@link VideoProfile#STATE_TX_ENABLED},
2041 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002042 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002043 * @return The video state of the connection.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002044 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002045 public final @VideoProfile.VideoState int getVideoState() {
Tyler Gunnaa07df82014-07-17 07:50:22 -07002046 return mVideoState;
2047 }
2048
2049 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002050 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07002051 * being routed by the system. This is {@code null} if this Connection
2052 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002053 * @deprecated Use {@link #getCallAudioState()} instead.
2054 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002055 */
Yorke Lee4af59352015-05-13 14:14:54 -07002056 @SystemApi
2057 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002058 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07002059 if (mCallAudioState == null) {
2060 return null;
2061 }
Yorke Lee4af59352015-05-13 14:14:54 -07002062 return new AudioState(mCallAudioState);
2063 }
2064
2065 /**
2066 * @return The audio state of the connection, describing how its audio is currently
2067 * being routed by the system. This is {@code null} if this Connection
2068 * does not directly know about its audio state.
2069 */
2070 public final CallAudioState getCallAudioState() {
2071 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002072 }
2073
2074 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002075 * @return The conference that this connection is a part of. Null if it is not part of any
2076 * conference.
2077 */
2078 public final Conference getConference() {
2079 return mConference;
2080 }
2081
2082 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002083 * Returns whether this connection is requesting that the system play a ringback tone
2084 * on its behalf.
2085 */
Andrew Lee100e2932014-09-08 15:34:24 -07002086 public final boolean isRingbackRequested() {
2087 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002088 }
2089
2090 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002091 * @return True if the connection's audio mode is VOIP.
2092 */
2093 public final boolean getAudioModeIsVoip() {
2094 return mAudioModeIsVoip;
2095 }
2096
2097 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002098 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
2099 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
2100 * start time of the conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002101 * <p>
2102 * Note: This is an implementation detail specific to IMS conference calls over a mobile
2103 * network.
Roshan Piuse927ec02015-07-15 15:47:21 -07002104 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07002105 * @return The time at which the {@code Connnection} was connected. Will be a value as retrieved
2106 * from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002107 *
2108 * @hide
2109 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002110 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002111 @TestApi
Roshan Piuse927ec02015-07-15 15:47:21 -07002112 public final long getConnectTimeMillis() {
2113 return mConnectTimeMillis;
2114 }
2115
2116 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002117 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
2118 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
2119 * start time of the conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002120 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002121 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
2122 * changes do not impact the call duration.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002123 * <p>
2124 * Used internally in Telephony when migrating conference participant data for IMS conferences.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002125 *
2126 * @return The time at which the {@link Connection} was connected.
2127 *
2128 * @hide
2129 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002130 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002131 @TestApi
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002132 public final long getConnectElapsedTimeMillis() {
2133 return mConnectElapsedTimeMillis;
2134 }
2135
2136 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002137 * @return The status hints for this connection.
2138 */
2139 public final StatusHints getStatusHints() {
2140 return mStatusHints;
2141 }
2142
2143 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002144 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00002145 * <p>
2146 * Extras should be updated using {@link #putExtras(Bundle)}.
2147 * <p>
2148 * Telecom or an {@link InCallService} can also update the extras via
2149 * {@link android.telecom.Call#putExtras(Bundle)}, and
2150 * {@link Call#removeExtras(List)}.
2151 * <p>
2152 * The connection is notified of changes to the extras made by Telecom or an
2153 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002154 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07002155 * @return The extras associated with this connection.
2156 */
2157 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002158 Bundle extras = null;
2159 synchronized (mExtrasLock) {
2160 if (mExtras != null) {
2161 extras = new Bundle(mExtras);
2162 }
2163 }
2164 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002165 }
2166
2167 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002168 * Assign a listener to be notified of state changes.
2169 *
2170 * @param l A listener.
2171 * @return This Connection.
2172 *
2173 * @hide
2174 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002175 final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00002176 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002177 return this;
2178 }
2179
2180 /**
2181 * Remove a previously assigned listener that was being notified of state changes.
2182 *
2183 * @param l A Listener.
2184 * @return This Connection.
2185 *
2186 * @hide
2187 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002188 final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07002189 if (l != null) {
2190 mListeners.remove(l);
2191 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002192 return this;
2193 }
2194
2195 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002196 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07002197 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002198 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002199 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07002200 }
2201
2202 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002203 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
2204 * ONLY for debugging purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002205 * <p>
2206 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2207 * provided to facilitate debugging of the Telephony stack only. Changing the ID via this
2208 * method does NOT change any functionality in Telephony or Telecom and impacts only logging.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002209 *
2210 * @param callId The telecom call ID.
2211 * @hide
2212 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002213 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002214 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07002215 public void setTelecomCallId(@NonNull String callId) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002216 mTelecomCallId = callId;
2217 }
2218
2219 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002220 * Inform this Connection that the state of its audio output has been changed externally.
2221 *
2222 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002223 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002224 */
Yorke Lee4af59352015-05-13 14:14:54 -07002225 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002226 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07002227 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07002228 mCallAudioState = state;
2229 onAudioStateChanged(getAudioState());
2230 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002231 }
2232
2233 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002234 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002235 * @return A string representation of the value.
2236 */
2237 public static String stateToString(int state) {
2238 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002239 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002240 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002241 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07002242 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002243 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002244 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002245 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002246 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07002247 case STATE_PULLING_CALL:
2248 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002249 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002250 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002251 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002252 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002253 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002254 return "DISCONNECTED";
2255 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002256 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002257 return "UNKNOWN";
2258 }
2259 }
2260
2261 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002262 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002263 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002264 public final int getConnectionCapabilities() {
2265 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002266 }
2267
2268 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002269 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2270 */
2271 public final int getConnectionProperties() {
2272 return mConnectionProperties;
2273 }
2274
2275 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002276 * Returns the connection's supported audio routes.
2277 *
2278 * @hide
2279 */
2280 public final int getSupportedAudioRoutes() {
2281 return mSupportedAudioRoutes;
2282 }
2283
2284 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002285 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002286 *
Andrew Lee100e2932014-09-08 15:34:24 -07002287 * @param address The new address.
2288 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002289 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002290 */
Andrew Lee100e2932014-09-08 15:34:24 -07002291 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002292 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002293 Log.d(this, "setAddress %s", address);
2294 mAddress = address;
2295 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002296 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002297 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002298 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002299 }
2300
2301 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002302 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002303 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002304 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002305 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002306 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002307 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002308 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002309 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002310 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002311 mCallerDisplayName = callerDisplayName;
2312 mCallerDisplayNamePresentation = presentation;
2313 for (Listener l : mListeners) {
2314 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2315 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002316 }
2317
2318 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002319 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002320 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2321 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2322 * {@link VideoProfile#STATE_TX_ENABLED},
2323 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002324 *
2325 * @param videoState The new video state.
2326 */
2327 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002328 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002329 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002330 mVideoState = videoState;
2331 for (Listener l : mListeners) {
2332 l.onVideoStateChanged(this, mVideoState);
2333 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002334 }
2335
2336 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002337 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002338 * communicate).
2339 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002340 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002341 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002342 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002343 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002344 }
2345
2346 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002347 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002348 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002349 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002350 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002351 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002352 }
2353
2354 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002355 * Sets state to initializing (this Connection is not yet ready to be used).
2356 */
2357 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002358 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002359 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002360 }
2361
2362 /**
2363 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2364 */
2365 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002366 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002367 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002368 }
2369
2370 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002371 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002372 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002373 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002374 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002375 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002376 }
2377
2378 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002379 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2380 * device). Only applicable for {@link Connection}s with
2381 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2382 */
2383 public final void setPulling() {
2384 checkImmutable();
2385 setState(STATE_PULLING_CALL);
2386 }
2387
2388 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002389 * Sets state to be on hold.
2390 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002391 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002392 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002393 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002394 }
2395
2396 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002397 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002398 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002399 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002400 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002401 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002402 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002403 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002404 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002405 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002406 }
2407
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002408 public final VideoProvider getVideoProvider() {
2409 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002410 }
2411
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002412 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002413 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002414 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002415 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002416 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002417 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002418 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002419 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002420 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002421 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002422 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002423 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002424 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002425 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002426 }
2427
2428 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002429 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2430 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2431 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2432 * to send an {@link #onPostDialContinue(boolean)} signal.
2433 *
2434 * @param remaining The DTMF character sequence remaining to be emitted once the
2435 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2436 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002437 */
2438 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002439 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002440 for (Listener l : mListeners) {
2441 l.onPostDialWait(this, remaining);
2442 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002443 }
2444
2445 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002446 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2447 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002448 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002449 *
2450 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002451 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002452 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002453 checkImmutable();
2454 for (Listener l : mListeners) {
2455 l.onPostDialChar(this, nextChar);
2456 }
2457 }
2458
2459 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002460 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002461 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002462 *
2463 * @param ringback Whether the ringback tone is to be played.
2464 */
Andrew Lee100e2932014-09-08 15:34:24 -07002465 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002466 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002467 if (mRingbackRequested != ringback) {
2468 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002469 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002470 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002471 }
2472 }
Ihab Awadf8358972014-05-28 16:46:42 -07002473 }
2474
2475 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002476 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002477 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002478 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002479 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002480 public final void setConnectionCapabilities(int connectionCapabilities) {
2481 checkImmutable();
2482 if (mConnectionCapabilities != connectionCapabilities) {
2483 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002484 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002485 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002486 }
2487 }
Santos Cordonb6939982014-06-04 20:20:58 -07002488 }
2489
2490 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002491 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2492 *
2493 * @param connectionProperties The new connection properties.
2494 */
2495 public final void setConnectionProperties(int connectionProperties) {
2496 checkImmutable();
2497 if (mConnectionProperties != connectionProperties) {
2498 mConnectionProperties = connectionProperties;
2499 for (Listener l : mListeners) {
2500 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2501 }
2502 }
2503 }
2504
2505 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002506 * Sets the supported audio routes.
2507 *
2508 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2509 * See {@link CallAudioState}
2510 * @hide
2511 */
2512 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2513 if ((supportedAudioRoutes
2514 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2515 throw new IllegalArgumentException(
2516 "supported audio routes must include either speaker or earpiece");
2517 }
2518
2519 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2520 mSupportedAudioRoutes = supportedAudioRoutes;
2521 for (Listener l : mListeners) {
2522 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2523 }
2524 }
2525 }
2526
2527 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002528 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002529 */
Evan Charlton36a71342014-07-19 16:31:02 -07002530 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002531 for (Listener l : mListeners) {
2532 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002533 }
Santos Cordonb6939982014-06-04 20:20:58 -07002534 }
2535
2536 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002537 * Requests that the framework use VOIP audio mode for this connection.
2538 *
2539 * @param isVoip True if the audio mode is VOIP.
2540 */
2541 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002542 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002543 mAudioModeIsVoip = isVoip;
2544 for (Listener l : mListeners) {
2545 l.onAudioModeIsVoipChanged(this, isVoip);
2546 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002547 }
2548
2549 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002550 * Sets the time at which a call became active on this Connection. This is set only
2551 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002552 * <p>
2553 * Used by telephony to maintain calls associated with an IMS Conference.
Roshan Piuse927ec02015-07-15 15:47:21 -07002554 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002555 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2556 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002557 *
2558 * @hide
2559 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002560 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002561 @TestApi
Roshan Piuse927ec02015-07-15 15:47:21 -07002562 public final void setConnectTimeMillis(long connectTimeMillis) {
2563 mConnectTimeMillis = connectTimeMillis;
2564 }
2565
2566 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002567 * Sets the time at which a call became active on this Connection. This is set only
2568 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002569 * <p>
2570 * Used by telephony to maintain calls associated with an IMS Conference.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002571 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2572 * {@link SystemClock#elapsedRealtime()}.
2573 *
2574 * @hide
2575 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002576 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002577 @TestApi
Tyler Gunn17541392018-02-01 08:58:38 -08002578 public final void setConnectionStartElapsedRealTime(long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002579 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2580 }
2581
2582 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002583 * Sets the label and icon status to display in the in-call UI.
2584 *
2585 * @param statusHints The status label and icon to set.
2586 */
2587 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002588 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002589 mStatusHints = statusHints;
2590 for (Listener l : mListeners) {
2591 l.onStatusHintsChanged(this, statusHints);
2592 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002593 }
2594
2595 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002596 * Sets the connections with which this connection can be conferenced.
2597 *
2598 * @param conferenceableConnections The set of connections this connection can conference with.
2599 */
2600 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002601 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002602 clearConferenceableList();
2603 for (Connection c : conferenceableConnections) {
2604 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2605 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002606 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002607 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002608 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002609 }
2610 }
2611 fireOnConferenceableConnectionsChanged();
2612 }
2613
2614 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002615 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2616 * or conferences with which this connection can be conferenced.
2617 *
2618 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002619 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002620 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002621 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002622 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002623 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2624 // small amount of items here.
2625 if (!mConferenceables.contains(c)) {
2626 if (c instanceof Connection) {
2627 Connection connection = (Connection) c;
2628 connection.addConnectionListener(mConnectionDeathListener);
2629 } else if (c instanceof Conference) {
2630 Conference conference = (Conference) c;
2631 conference.addListener(mConferenceDeathListener);
2632 }
2633 mConferenceables.add(c);
2634 }
2635 }
2636 fireOnConferenceableConnectionsChanged();
2637 }
2638
2639 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07002640 * Resets the CDMA connection time.
2641 * <p>
2642 * This is an implementation detail specific to legacy CDMA calls on mobile networks.
Mengjun Leng25707742017-07-04 11:10:37 +08002643 * @hide
Mengjun Leng25707742017-07-04 11:10:37 +08002644 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002645 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002646 @TestApi
Mengjun Leng25707742017-07-04 11:10:37 +08002647 public final void resetConnectionTime() {
2648 for (Listener l : mListeners) {
2649 l.onConnectionTimeReset(this);
2650 }
2651 }
2652
2653 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002654 * Returns the connections or conferences with which this connection can be conferenced.
2655 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002656 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002657 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002658 }
2659
Yorke Lee53463962015-08-04 16:07:19 -07002660 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002661 * @hide
2662 */
2663 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002664 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002665 if (mConnectionService != null) {
2666 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2667 "which is already associated with another ConnectionService.");
2668 } else {
2669 mConnectionService = connectionService;
2670 }
2671 }
2672
2673 /**
2674 * @hide
2675 */
2676 public final void unsetConnectionService(ConnectionService connectionService) {
2677 if (mConnectionService != connectionService) {
2678 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2679 "that does not belong to the ConnectionService.");
2680 } else {
2681 mConnectionService = null;
2682 }
2683 }
2684
2685 /**
2686 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002687 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002688 *
2689 * @param conference The conference.
2690 * @return {@code true} if the conference was successfully set.
2691 * @hide
2692 */
2693 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002694 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002695 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002696 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002697 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002698 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2699 fireConferenceChanged();
2700 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002701 return true;
2702 }
2703 return false;
2704 }
2705
2706 /**
2707 * Resets the conference that this connection is a part of.
2708 * @hide
2709 */
2710 public final void resetConference() {
2711 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002712 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002713 mConference = null;
2714 fireConferenceChanged();
2715 }
2716 }
2717
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002718 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002719 * Set some extras that can be associated with this {@code Connection}.
2720 * <p>
2721 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2722 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2723 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002724 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2725 * {@link #removeExtras(String...)} methods to modify the extras.
2726 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002727 * 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 -07002728 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2729 *
2730 * @param extras The extras associated with this {@code Connection}.
2731 */
2732 public final void setExtras(@Nullable Bundle extras) {
2733 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002734
2735 // Add/replace any new or changed extras values.
2736 putExtras(extras);
2737
2738 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2739 // the current one and remove any keys that went away.
2740 if (mPreviousExtraKeys != null) {
2741 List<String> toRemove = new ArrayList<String>();
2742 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002743 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002744 toRemove.add(oldKey);
2745 }
2746 }
2747 if (!toRemove.isEmpty()) {
2748 removeExtras(toRemove);
2749 }
2750 }
2751
2752 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2753 // called we can see if the caller has removed any extras values.
2754 if (mPreviousExtraKeys == null) {
2755 mPreviousExtraKeys = new ArraySet<String>();
2756 }
2757 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002758 if (extras != null) {
2759 mPreviousExtraKeys.addAll(extras.keySet());
2760 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002761 }
2762
2763 /**
2764 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2765 * added.
2766 * <p>
2767 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2768 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2769 *
2770 * @param extras The extras to add.
2771 */
2772 public final void putExtras(@NonNull Bundle extras) {
2773 checkImmutable();
2774 if (extras == null) {
2775 return;
2776 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002777 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2778 // the listeners.
2779 Bundle listenerExtras;
2780 synchronized (mExtrasLock) {
2781 if (mExtras == null) {
2782 mExtras = new Bundle();
2783 }
2784 mExtras.putAll(extras);
2785 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002786 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002787 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002788 // Create a new clone of the extras for each listener so that they don't clobber
2789 // each other
2790 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002791 }
2792 }
2793
2794 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002795 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002796 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002797 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002798 */
2799 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002800 synchronized (mExtrasLock) {
2801 if (mExtras != null) {
2802 for (String key : keys) {
2803 mExtras.remove(key);
2804 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002805 }
2806 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002807 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002808 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002809 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002810 }
2811 }
2812
2813 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002814 * Removes extras from this {@code Connection}.
2815 *
2816 * @param keys The keys of the extras to remove.
2817 */
2818 public final void removeExtras(String ... keys) {
2819 removeExtras(Arrays.asList(keys));
2820 }
2821
2822 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002823 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2824 * be change to the {@link #getCallAudioState()}.
2825 * <p>
2826 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2827 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2828 * <p>
2829 * See also {@link InCallService#setAudioRoute(int)}.
2830 *
2831 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2832 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2833 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2834 */
2835 public final void setAudioRoute(int route) {
2836 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002837 l.onAudioRouteChanged(this, route, null);
2838 }
2839 }
2840
2841 /**
Hall Liua98f58b52017-11-07 17:59:28 -08002842 * Request audio routing to a specific bluetooth device. Calling this method may result in
2843 * the device routing audio to a different bluetooth device than the one specified if the
2844 * bluetooth stack is unable to route audio to the requested device.
2845 * A list of available devices can be obtained via
2846 * {@link CallAudioState#getSupportedBluetoothDevices()}
2847 *
2848 * <p>
2849 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2850 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2851 * <p>
Hall Liu2b6a6a32018-04-02 13:52:57 -07002852 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2853 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -08002854 */
Hall Liu2b6a6a32018-04-02 13:52:57 -07002855 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08002856 for (Listener l : mListeners) {
Hall Liu2b6a6a32018-04-02 13:52:57 -07002857 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
2858 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08002859 }
2860 }
2861
2862 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002863 * Informs listeners that a previously requested RTT session via
2864 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08002865 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002866 */
2867 public final void sendRttInitiationSuccess() {
2868 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2869 }
2870
2871 /**
2872 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002873 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002874 * has failed.
2875 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2876 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002877 */
2878 public final void sendRttInitiationFailure(int reason) {
2879 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2880 }
2881
2882 /**
2883 * Informs listeners that a currently active RTT session has been terminated by the remote
2884 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002885 */
2886 public final void sendRttSessionRemotelyTerminated() {
2887 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2888 }
2889
2890 /**
2891 * Informs listeners that the remote side of the call has requested an upgrade to include an
2892 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002893 */
2894 public final void sendRemoteRttRequest() {
2895 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2896 }
2897
2898 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002899 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002900 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002901 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002902 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2903 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002904 */
Yorke Lee4af59352015-05-13 14:14:54 -07002905 @SystemApi
2906 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002907 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002908
2909 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002910 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2911 *
2912 * @param state The new connection audio state.
2913 */
2914 public void onCallAudioStateChanged(CallAudioState state) {}
2915
2916 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002917 * Notifies this Connection of an internal state change. This method is called after the
2918 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002919 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002920 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002921 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002922 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002923
2924 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002925 * Notifies this Connection of a request to play a DTMF tone.
2926 *
2927 * @param c A DTMF character.
2928 */
Santos Cordonf2951102014-07-20 19:06:29 -07002929 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002930
2931 /**
2932 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2933 */
Santos Cordonf2951102014-07-20 19:06:29 -07002934 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002935
2936 /**
2937 * Notifies this Connection of a request to disconnect.
2938 */
Santos Cordonf2951102014-07-20 19:06:29 -07002939 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002940
2941 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002942 * Notifies this Connection of a request to disconnect a participant of the conference managed
2943 * by the connection.
2944 *
2945 * @param endpoint the {@link Uri} of the participant to disconnect.
2946 * @hide
2947 */
2948 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2949
2950 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002951 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002952 */
Santos Cordonf2951102014-07-20 19:06:29 -07002953 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002954
2955 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002956 * Notifies this Connection of a request to abort.
2957 */
Santos Cordonf2951102014-07-20 19:06:29 -07002958 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002959
2960 /**
2961 * Notifies this Connection of a request to hold.
2962 */
Santos Cordonf2951102014-07-20 19:06:29 -07002963 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002964
2965 /**
2966 * Notifies this Connection of a request to exit a hold state.
2967 */
Santos Cordonf2951102014-07-20 19:06:29 -07002968 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002969
2970 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002971 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002972 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002973 * <p>
2974 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2975 * the default dialer's {@link InCallService}.
2976 * <p>
2977 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2978 * Telecom framework may request that the call is answered in the following circumstances:
2979 * <ul>
2980 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2981 * <li>A car mode {@link InCallService} is in use which has declared
2982 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2983 * {@link InCallService} will be able to see calls from self-managed
2984 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2985 * behalf.</li>
2986 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002987 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002988 */
Santos Cordonf2951102014-07-20 19:06:29 -07002989 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002990
2991 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002992 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002993 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002994 * <p>
2995 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2996 * the default dialer's {@link InCallService}.
2997 * <p>
2998 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2999 * Telecom framework may request that the call is answered in the following circumstances:
3000 * <ul>
3001 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
3002 * <li>A car mode {@link InCallService} is in use which has declared
3003 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3004 * {@link InCallService} will be able to see calls from self-managed
3005 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3006 * behalf.</li>
3007 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07003008 */
3009 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07003010 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07003011 }
3012
3013 /**
3014 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05303015 * a request to deflect.
3016 */
3017 public void onDeflect(Uri address) {}
3018
3019 /**
3020 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00003021 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003022 * <p>
3023 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
3024 * the default dialer's {@link InCallService}.
3025 * <p>
3026 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3027 * Telecom framework may request that the call is rejected in the following circumstances:
3028 * <ul>
3029 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
3030 * <li>A car mode {@link InCallService} is in use which has declared
3031 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3032 * {@link InCallService} will be able to see calls from self-managed
3033 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3034 * behalf.</li>
3035 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07003036 */
Santos Cordonf2951102014-07-20 19:06:29 -07003037 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003038
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003039 /**
Tyler Gunnfacfdee2020-01-23 13:10:37 -08003040 * Notifies this Connection, which is in {@link #STATE_RINGING}, of a request to reject.
3041 * <p>
3042 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
3043 * the default dialer's {@link InCallService} using {@link Call#reject(int)}.
3044 * @param rejectReason the reason the user provided for rejecting the call.
3045 */
3046 public void onReject(@android.telecom.Call.RejectReason int rejectReason) {
3047 // to be implemented by ConnectionService.
3048 }
3049
3050 /**
Hall Liu712acbe2016-03-14 16:38:56 -07003051 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
3052 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07003053 */
3054 public void onReject(String replyMessage) {}
3055
3056 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07003057 * Notifies this Connection of a request to silence the ringer.
3058 * <p>
3059 * The ringer may be silenced by any of the following methods:
3060 * <ul>
3061 * <li>{@link TelecomManager#silenceRinger()}</li>
3062 * <li>The user presses the volume-down button while a call is ringing.</li>
3063 * </ul>
3064 * <p>
3065 * Self-managed {@link ConnectionService} implementations should override this method in their
3066 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
3067 * your app set the ringtone as part of the incoming call {@link Notification} (see
3068 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
3069 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
3070 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
3071 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08003072 */
3073 public void onSilence() {}
3074
3075 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003076 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
3077 */
Santos Cordonf2951102014-07-20 19:06:29 -07003078 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003079
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003080 /**
3081 * Notifies this Connection of a request to pull an external call to the local device.
3082 * <p>
3083 * The {@link InCallService} issues a request to pull an external call to the local device via
3084 * {@link Call#pullExternalCall()}.
3085 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07003086 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
3087 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003088 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07003089 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003090 */
3091 public void onPullExternalCall() {}
3092
3093 /**
3094 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
3095 * <p>
3096 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
3097 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003098 * Where possible, the Connection should make an attempt to handle {@link Call} events which
3099 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
3100 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
3101 * possible that a {@link InCallService} has defined its own Call events which a Connection is
3102 * not aware of.
3103 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003104 * See also {@link Call#sendCallEvent(String, Bundle)}.
3105 *
3106 * @param event The call event.
3107 * @param extras Extras associated with the call event.
3108 */
3109 public void onCallEvent(String event, Bundle extras) {}
3110
Tyler Gunndee56a82016-03-23 16:06:34 -07003111 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08003112 * Notifies this {@link Connection} that a handover has completed.
3113 * <p>
3114 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
3115 * Bundle)} on the initiating side of the handover, and
3116 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
3117 */
3118 public void onHandoverComplete() {}
3119
3120 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003121 * Notifies this {@link Connection} of a change to the extras made outside the
3122 * {@link ConnectionService}.
3123 * <p>
3124 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
3125 * the {@link android.telecom.Call#putExtras(Bundle)} and
3126 * {@link Call#removeExtras(List)}.
3127 *
3128 * @param extras The new extras bundle.
3129 */
3130 public void onExtrasChanged(Bundle extras) {}
3131
Tyler Gunnf5035432017-01-09 09:43:12 -08003132 /**
3133 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
3134 * displaying its incoming call user interface for the {@link Connection}.
3135 * <p>
3136 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
3137 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
3138 * should show its own incoming call user interface.
3139 * <p>
3140 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003141 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
3142 * Telecom framework will display its own incoming call user interface to allow the user to
3143 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
3144 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003145 * <p>
3146 * You should trigger the display of the incoming call user interface for your application by
3147 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07003148 *
3149 * In your application code, you should create a {@link android.app.NotificationChannel} for
3150 * incoming call notifications from your app:
3151 * <pre><code>
3152 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
3153 * NotificationManager.IMPORTANCE_MAX);
3154 * // other channel setup stuff goes here.
3155 *
3156 * // We'll use the default system ringtone for our incoming call notification channel. You can
3157 * // use your own audio resource here.
3158 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
3159 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
3160 * // Setting the AudioAttributes is important as it identifies the purpose of your
3161 * // notification sound.
3162 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
3163 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
3164 * .build());
3165 *
3166 * NotificationManager mgr = getSystemService(NotificationManager.class);
3167 * mgr.createNotificationChannel(channel);
3168 * </code></pre>
3169 * When it comes time to post a notification for your incoming call, ensure it uses your
3170 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003171 * <pre><code>
3172 * // Create an intent which triggers your fullscreen incoming call user interface.
3173 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
3174 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
3175 * intent.setClass(context, YourIncomingCallActivity.class);
3176 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
3177 *
3178 * // Build the notification as an ongoing high priority item; this ensures it will show as
3179 * // a heads up notification which slides down over top of the current content.
3180 * final Notification.Builder builder = new Notification.Builder(context);
3181 * builder.setOngoing(true);
3182 * builder.setPriority(Notification.PRIORITY_HIGH);
3183 *
3184 * // Set notification content intent to take user to fullscreen UI if user taps on the
3185 * // notification body.
3186 * builder.setContentIntent(pendingIntent);
3187 * // Set full screen intent to trigger display of the fullscreen UI when the notification
3188 * // manager deems it appropriate.
3189 * builder.setFullScreenIntent(pendingIntent, true);
3190 *
3191 * // Setup notification content.
3192 * builder.setSmallIcon( yourIconResourceId );
3193 * builder.setContentTitle("Your notification title");
3194 * builder.setContentText("Your notification content.");
3195 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003196 * // Set notification as insistent to cause your ringtone to loop.
3197 * Notification notification = builder.build();
3198 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08003199 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003200 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003201 * NotificationManager notificationManager = mContext.getSystemService(
3202 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07003203 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003204 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08003205 */
3206 public void onShowIncomingCallUi() {}
3207
Hall Liub64ac4c2017-02-06 10:49:48 -08003208 /**
3209 * Notifies this {@link Connection} that the user has requested an RTT session.
3210 * The connection service should call {@link #sendRttInitiationSuccess} or
3211 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
3212 * request, respectively.
3213 * @param rttTextStream The object that should be used to send text to or receive text from
3214 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08003215 */
3216 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
3217
3218 /**
3219 * Notifies this {@link Connection} that it should terminate any existing RTT communication
3220 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08003221 */
3222 public void onStopRtt() {}
3223
3224 /**
3225 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3226 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3227 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3228 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003229 * @param rttTextStream The object that should be used to send text to or receive text from
3230 * the in-call app.
3231 */
3232 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3233
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003234 static String toLogSafePhoneNumber(String number) {
3235 // For unknown number, log empty string.
3236 if (number == null) {
3237 return "";
3238 }
3239
3240 if (PII_DEBUG) {
3241 // When PII_DEBUG is true we emit PII.
3242 return number;
3243 }
3244
3245 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3246 // sanitized phone numbers.
3247 StringBuilder builder = new StringBuilder();
3248 for (int i = 0; i < number.length(); i++) {
3249 char c = number.charAt(i);
3250 if (c == '-' || c == '@' || c == '.') {
3251 builder.append(c);
3252 } else {
3253 builder.append('x');
3254 }
3255 }
3256 return builder.toString();
3257 }
3258
Ihab Awad542e0ea2014-05-16 10:22:16 -07003259 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003260 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003261 if (mState == STATE_DISCONNECTED && mState != state) {
3262 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003263 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003264 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003265 if (mState != state) {
3266 Log.d(this, "setState: %s", stateToString(state));
3267 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003268 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003269 for (Listener l : mListeners) {
3270 l.onStateChanged(this, state);
3271 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003272 }
3273 }
3274
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003275 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003276 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003277 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3278 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08003279 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003280 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003281
3282 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003283 if (mImmutable) {
3284 throw new UnsupportedOperationException("Connection is immutable");
3285 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003286 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003287 }
3288
Evan Charltonbf11f982014-07-20 22:06:28 -07003289 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003290 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003291 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3292 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003293 * <p>
3294 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3295 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003296 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003297 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003298 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003299 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003300 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3301 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003302 }
3303
Evan Charltonbf11f982014-07-20 22:06:28 -07003304 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003305 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3306 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3307 * this should never be un-@hide-den.
3308 *
3309 * @hide
3310 */
3311 public void checkImmutable() {}
3312
3313 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003314 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3315 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3316 * that state. This connection should not be used for anything, and no other
3317 * {@code Connection}s should be attempted.
3318 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003319 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003320 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003321 * @return A {@code Connection} which indicates that the underlying connection should
3322 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003323 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003324 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003325 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003326 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003327
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003328 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003329 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003330 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003331 }
3332 }
3333
Santos Cordon823fd3c2014-08-07 18:35:18 -07003334 private final void fireConferenceChanged() {
3335 for (Listener l : mListeners) {
3336 l.onConferenceChanged(this, mConference);
3337 }
3338 }
3339
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003340 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003341 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003342 if (c instanceof Connection) {
3343 Connection connection = (Connection) c;
3344 connection.removeConnectionListener(mConnectionDeathListener);
3345 } else if (c instanceof Conference) {
3346 Conference conference = (Conference) c;
3347 conference.removeListener(mConferenceDeathListener);
3348 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003349 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003350 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003351 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003352
3353 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003354 * Handles a change to extras received from Telecom.
3355 *
3356 * @param extras The new extras.
3357 * @hide
3358 */
3359 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003360 Bundle b = null;
3361 synchronized (mExtrasLock) {
3362 mExtras = extras;
3363 if (mExtras != null) {
3364 b = new Bundle(mExtras);
3365 }
3366 }
3367 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003368 }
3369
3370 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07003371 * Called by a {@link ConnectionService} to notify Telecom that a {@link Conference#onMerge()}
3372 * request failed.
Anthony Lee17455a32015-04-24 15:25:29 -07003373 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003374 public final void notifyConferenceMergeFailed() {
Anthony Lee17455a32015-04-24 15:25:29 -07003375 for (Listener l : mListeners) {
3376 l.onConferenceMergeFailed(this);
3377 }
3378 }
3379
3380 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303381 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3382 * changed due to an emergency call being redialed.
3383 * @param pHandle The new PhoneAccountHandle for this connection.
3384 * @hide
3385 */
3386 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3387 for (Listener l : mListeners) {
3388 l.onPhoneAccountChanged(this, pHandle);
3389 }
3390 }
3391
3392 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003393 * Sets the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003394 * <p>
3395 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3396 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003397 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003398 * @param phoneAccountHandle the phone account handle to set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003399 * @hide
3400 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003401 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07003402 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07003403 public void setPhoneAccountHandle(@NonNull PhoneAccountHandle phoneAccountHandle) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003404 if (mPhoneAccountHandle != phoneAccountHandle) {
3405 mPhoneAccountHandle = phoneAccountHandle;
3406 notifyPhoneAccountChanged(phoneAccountHandle);
3407 }
3408 }
3409
3410 /**
3411 * Returns the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003412 * <p>
3413 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3414 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003415 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003416 * @return the phone account handle specified via
3417 * {@link #setPhoneAccountHandle(PhoneAccountHandle)}, or {@code null} if none was set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003418 * @hide
3419 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003420 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07003421 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07003422 public @Nullable PhoneAccountHandle getPhoneAccountHandle() {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003423 return mPhoneAccountHandle;
3424 }
3425
3426 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003427 * Sends an event associated with this {@code Connection} with associated event extras to the
3428 * {@link InCallService}.
3429 * <p>
3430 * Connection events are used to communicate point in time information from a
3431 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3432 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3433 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3434 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3435 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3436 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3437 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3438 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3439 * <p>
3440 * Events are exposed to {@link InCallService} implementations via
3441 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3442 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003443 * 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 -07003444 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3445 * some events altogether.
3446 * <p>
3447 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3448 * conflicts between {@link ConnectionService} implementations. Further, custom
3449 * {@link ConnectionService} implementations shall not re-purpose events in the
3450 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3451 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3452 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3453 * {@code com.example.extra.MY_EXTRA}).
3454 * <p>
3455 * When defining events and the associated extras, it is important to keep their behavior
3456 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3457 * events/extras should me maintained to ensure backwards compatibility with older
3458 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003459 *
3460 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003461 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003462 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003463 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003464 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003465 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003466 }
3467 }
Tyler Gunn6986a632019-06-25 13:45:32 -07003468
3469 /**
3470 * @return The direction of the call.
3471 * @hide
3472 */
3473 public final @Call.Details.CallDirection int getCallDirection() {
3474 return mCallDirection;
3475 }
3476
3477 /**
3478 * Sets the direction of this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003479 * <p>
3480 * Used when calling {@link ConnectionService#addExistingConnection} to specify the existing
3481 * call direction.
3482 *
Tyler Gunn6986a632019-06-25 13:45:32 -07003483 * @param callDirection The direction of this connection.
3484 * @hide
3485 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003486 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07003487 @TestApi
Tyler Gunn6986a632019-06-25 13:45:32 -07003488 public void setCallDirection(@Call.Details.CallDirection int callDirection) {
3489 mCallDirection = callDirection;
3490 }
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003491
3492 /**
3493 * Gets the verification status for the phone number of an incoming call as identified in
3494 * ATIS-1000082.
3495 * @return the verification status.
3496 */
3497 public @VerificationStatus int getCallerNumberVerificationStatus() {
3498 return mCallerNumberVerificationStatus;
3499 }
3500
3501 /**
3502 * Sets the verification status for the phone number of an incoming call as identified in
3503 * ATIS-1000082.
3504 * <p>
3505 * This property can only be set at the time of creation of a {@link Connection} being returned
3506 * by
3507 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}.
3508 */
3509 public void setCallerNumberVerificationStatus(
3510 @VerificationStatus int callerNumberVerificationStatus) {
3511 mCallerNumberVerificationStatus = callerNumberVerificationStatus;
3512 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003513}