blob: 6bdc43ec2414af3c1eba216427abe4fc47cba0c3 [file] [log] [blame]
Ihab Awad807fe0a2014-07-09 12:30:52 -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 Awad807fe0a2014-07-09 12:30:52 -070018
Tyler Gunnc9503d62020-01-27 10:30:51 -080019import static android.Manifest.permission.MODIFY_PHONE_STATE;
20
Brad Ebingerb0c1d912024-01-12 14:51:35 -080021import android.annotation.FlaggedApi;
Tyler Gunn5567d742019-10-31 13:04:37 -070022import android.annotation.NonNull;
Tyler Gunnc9503d62020-01-27 10:30:51 -080023import android.annotation.RequiresPermission;
Evan Charlton0e094d92014-11-08 15:49:16 -080024import android.annotation.SystemApi;
Brad Ebinger3636d742019-05-21 15:28:19 -070025import android.content.Intent;
Santos Cordoncad84a22015-05-13 11:17:25 -070026import android.graphics.drawable.Icon;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070027import android.net.Uri;
Tyler Gunn25ed2d72015-10-05 14:14:38 -070028import android.os.Bundle;
Ihab Awad807fe0a2014-07-09 12:30:52 -070029import android.os.Parcel;
30import android.os.Parcelable;
Brad Ebinger722cacf2021-05-14 01:53:56 +000031import android.telephony.CarrierConfigManager;
Hall Liu221f8042020-09-23 15:36:58 -070032import android.telephony.TelephonyManager;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070033import android.text.TextUtils;
Brad Ebingerb0c1d912024-01-12 14:51:35 -080034import android.util.ArraySet;
35
36import com.android.internal.telephony.flags.Flags;
Ihab Awad807fe0a2014-07-09 12:30:52 -070037
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070038import java.util.ArrayList;
39import java.util.Collections;
40import java.util.List;
Tyler Gunn3b347812018-08-24 14:17:05 -070041import java.util.Objects;
Brad Ebingerb0c1d912024-01-12 14:51:35 -080042import java.util.Set;
Ihab Awad807fe0a2014-07-09 12:30:52 -070043
44/**
Santos Cordon32c65a52014-10-27 14:57:49 -070045 * Represents a distinct method to place or receive a phone call. Apps which can place calls and
46 * want those calls to be integrated into the dialer and in-call UI should build an instance of
Brian Attwellad147f42014-12-19 11:37:16 -080047 * this class and register it with the system using {@link TelecomManager}.
Santos Cordon32c65a52014-10-27 14:57:49 -070048 * <p>
49 * {@link TelecomManager} uses registered {@link PhoneAccount}s to present the user with
50 * alternative options when placing a phone call. When building a {@link PhoneAccount}, the app
Brian Attwellad147f42014-12-19 11:37:16 -080051 * should supply a valid {@link PhoneAccountHandle} that references the connection service
Santos Cordon32c65a52014-10-27 14:57:49 -070052 * implementation Telecom will use to interact with the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -070053 */
Yorke Lee400470f2015-05-12 13:31:25 -070054public final class PhoneAccount implements Parcelable {
Ihab Awad94cf4bf2014-07-17 11:21:19 -070055
56 /**
Hall Liu4bb53ec2020-09-29 15:15:24 -070057 * Integer extra which determines the order in which {@link PhoneAccount}s are sorted
Hall Liu2ef04112020-09-14 18:34:10 -070058 *
59 * This is an extras key set via {@link Builder#setExtras} which determines the order in which
60 * {@link PhoneAccount}s from the same {@link ConnectionService} are sorted. The accounts
Hall Liu4bb53ec2020-09-29 15:15:24 -070061 * are sorted in ascending order by this key, and this ordering is used to
Hall Liu2ef04112020-09-14 18:34:10 -070062 * determine priority when a call can be placed via multiple accounts.
Hall Liu221f8042020-09-23 15:36:58 -070063 *
64 * When multiple {@link PhoneAccount}s are supplied with the same sort order key, no ordering is
65 * guaranteed between those {@link PhoneAccount}s. Additionally, no ordering is guaranteed
66 * between {@link PhoneAccount}s that do not supply this extra, and all such accounts
67 * will be sorted after the accounts that do supply this extra.
68 *
69 * An example of a sort order key is slot index (see {@link TelephonyManager#getSlotIndex()}),
70 * which is the one used by the cell Telephony stack.
Srikanth Chintala62428402017-03-27 19:27:52 +053071 * @hide
72 */
Hall Liu2ef04112020-09-14 18:34:10 -070073 @SystemApi
Srikanth Chintala62428402017-03-27 19:27:52 +053074 public static final String EXTRA_SORT_ORDER =
75 "android.telecom.extra.SORT_ORDER";
76
77 /**
78 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
Tyler Gunnd426b202015-10-13 13:33:53 -070079 * maximum permitted length of a call subject specified via the
80 * {@link TelecomManager#EXTRA_CALL_SUBJECT} extra on an
81 * {@link android.content.Intent#ACTION_CALL} intent. Ultimately a {@link ConnectionService} is
82 * responsible for enforcing the maximum call subject length when sending the message, however
83 * this extra is provided so that the user interface can proactively limit the length of the
84 * call subject as the user types it.
85 */
86 public static final String EXTRA_CALL_SUBJECT_MAX_LENGTH =
87 "android.telecom.extra.CALL_SUBJECT_MAX_LENGTH";
88
89 /**
90 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
91 * character encoding to be used when determining the length of messages.
92 * The user interface can use this when determining the number of characters the user may type
93 * in a call subject. If empty-string, the call subject message size limit will be enforced on
94 * a 1:1 basis. That is, each character will count towards the messages size limit as a single
95 * character. If a character encoding is specified, the message size limit will be based on the
96 * number of bytes in the message per the specified encoding. See
97 * {@link #EXTRA_CALL_SUBJECT_MAX_LENGTH} for more information on the call subject maximum
98 * length.
99 */
100 public static final String EXTRA_CALL_SUBJECT_CHARACTER_ENCODING =
101 "android.telecom.extra.CALL_SUBJECT_CHARACTER_ENCODING";
102
Hall Liue576fc42020-01-22 17:17:13 -0800103 /**
104 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
105 * indicates that all calls from this {@link PhoneAccount} should be treated as VoIP calls
Hall Liu2ef04112020-09-14 18:34:10 -0700106 * rather than cellular calls by the Telecom audio handling logic.
Srikanth Chintalaf77d4a12017-04-03 18:08:14 +0530107 */
108 public static final String EXTRA_ALWAYS_USE_VOIP_AUDIO_MODE =
109 "android.telecom.extra.ALWAYS_USE_VOIP_AUDIO_MODE";
110
Tyler Gunnd426b202015-10-13 13:33:53 -0700111 /**
Tyler Gunn8bf76572017-04-06 15:30:08 -0700112 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
113 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
Sanket Padawea8eddd42017-11-03 11:07:35 -0700114 * connection (see {@code android.telecom.Call#handoverTo()}) to this {@link PhoneAccount} from
115 * a {@link PhoneAccount} specifying {@link #EXTRA_SUPPORTS_HANDOVER_FROM}.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700116 * <p>
117 * A handover request is initiated by the user from the default dialer app to indicate a desire
118 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700119 */
120 public static final String EXTRA_SUPPORTS_HANDOVER_TO =
121 "android.telecom.extra.SUPPORTS_HANDOVER_TO";
122
123 /**
124 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Ta-wei Yen9d20d982017-06-02 11:07:07 -0700125 * indicates whether this {@link PhoneAccount} supports using a fallback if video calling is
126 * not available. This extra is for device level support, {@link
127 * android.telephony.CarrierConfigManager#KEY_ALLOW_VIDEO_CALLING_FALLBACK_BOOL} should also
128 * be checked to ensure it is not disabled by individual carrier.
129 *
130 * @hide
131 */
132 public static final String EXTRA_SUPPORTS_VIDEO_CALLING_FALLBACK =
133 "android.telecom.extra.SUPPORTS_VIDEO_CALLING_FALLBACK";
134
135 /**
136 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Tyler Gunn8bf76572017-04-06 15:30:08 -0700137 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
138 * connection from this {@link PhoneAccount} to another {@link PhoneAccount}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700139 * (see {@code android.telecom.Call#handoverTo()}) which specifies
Tyler Gunn8bf76572017-04-06 15:30:08 -0700140 * {@link #EXTRA_SUPPORTS_HANDOVER_TO}.
141 * <p>
142 * A handover request is initiated by the user from the default dialer app to indicate a desire
143 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700144 */
145 public static final String EXTRA_SUPPORTS_HANDOVER_FROM =
146 "android.telecom.extra.SUPPORTS_HANDOVER_FROM";
147
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700148
149 /**
150 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
151 * indicates whether a Self-Managed {@link PhoneAccount} should log its calls to the call log.
Brad Ebingerbb1a55f2017-06-26 13:26:14 -0700152 * Self-Managed {@link PhoneAccount}s are responsible for their own notifications, so the system
153 * will not create a notification when a missed call is logged.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700154 * <p>
155 * By default, Self-Managed {@link PhoneAccount}s do not log their calls to the call log.
156 * Setting this extra to {@code true} provides a means for them to log their calls.
Tyler Gunn2155c4c2018-04-05 09:43:41 -0700157 * <p>
158 * Note: Only calls where the {@link Call.Details#getHandle()} {@link Uri#getScheme()} is
159 * {@link #SCHEME_SIP} or {@link #SCHEME_TEL} will be logged at the current time.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700160 */
161 public static final String EXTRA_LOG_SELF_MANAGED_CALLS =
162 "android.telecom.extra.LOG_SELF_MANAGED_CALLS";
163
Tyler Gunn8bf76572017-04-06 15:30:08 -0700164 /**
Tyler Gunnacdb6862018-01-29 14:30:52 -0800165 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
166 * indicates whether calls for a {@link PhoneAccount} should generate a "call recording tone"
167 * when the user is recording audio on the device.
168 * <p>
169 * The call recording tone is played over the telephony audio stream so that the remote party
170 * has an audible indication that it is possible their call is being recorded using a call
171 * recording app on the device.
172 * <p>
173 * This extra only has an effect for calls placed via Telephony (e.g.
174 * {@link #CAPABILITY_SIM_SUBSCRIPTION}).
175 * <p>
176 * The call recording tone is a 1400 hz tone which repeats every 15 seconds while recording is
177 * in progress.
178 * @hide
179 */
Hall Liu2ef04112020-09-14 18:34:10 -0700180 @SystemApi
Tyler Gunnacdb6862018-01-29 14:30:52 -0800181 public static final String EXTRA_PLAY_CALL_RECORDING_TONE =
182 "android.telecom.extra.PLAY_CALL_RECORDING_TONE";
183
184 /**
Sean Kelley4d3c1782018-05-22 14:35:27 -0700185 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()} which
186 * indicates whether calls for a {@link PhoneAccount} should skip call filtering.
187 * <p>
188 * If not specified, this will default to false; all calls will undergo call filtering unless
189 * specifically exempted (e.g. {@link Connection#PROPERTY_EMERGENCY_CALLBACK_MODE}.) However,
190 * this may be used to skip call filtering when it has already been performed on another device.
191 * @hide
192 */
193 public static final String EXTRA_SKIP_CALL_FILTERING =
194 "android.telecom.extra.SKIP_CALL_FILTERING";
195
196 /**
Grace Jiae99fde92021-01-19 14:58:01 -0800197 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
198 * indicates whether a Self-managed {@link PhoneAccount} want to expose its calls to all
199 * {@link InCallService} which declares the metadata
200 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS}.
201 */
202 public static final String EXTRA_ADD_SELF_MANAGED_CALLS_TO_INCALLSERVICE =
203 "android.telecom.extra.ADD_SELF_MANAGED_CALLS_TO_INCALLSERVICE";
204
205 /**
Ihab Awadf8b69882014-07-25 15:14:01 -0700206 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
207 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
208 * will be allowed to manage phone calls including using its own proprietary phone-call
209 * implementation (like VoIP calling) to make calls instead of the telephony stack.
210 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700211 * When a user opts to place a call using the SIM-based telephony stack, the
212 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
213 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700214 * <p>
215 * See {@link #getCapabilities}
216 */
Ihab Awadf8b69882014-07-25 15:14:01 -0700217 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700218
219 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700220 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -0700221 * traditional SIM-based telephony calls. This account will be treated as a distinct method
222 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -0700223 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -0700224 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700225 * <p>
226 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700227 * <p>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700228 */
229 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
230
Ihab Awad7522bbd62014-07-18 15:53:17 -0700231 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700232 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -0700233 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -0700234 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700235 * Only the Android framework can register a {@code PhoneAccount} having this capability.
236 * <p>
237 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -0700238 */
239 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
240
Ihab Awadf8b69882014-07-25 15:14:01 -0700241 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800242 * Flag indicating that this {@code PhoneAccount} is currently able to place video calls.
243 * <p>
244 * See also {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING} which indicates whether the
245 * {@code PhoneAccount} supports placing video calls.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700246 * <p>
247 * See {@link #getCapabilities}
Ihab Awadf8b69882014-07-25 15:14:01 -0700248 */
249 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
250
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700251 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700252 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
253 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
254 * <p>
255 * See {@link #getCapabilities}
256 */
257 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
258
259 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800260 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
261 * should only be used by system apps (and will be ignored for all other apps trying to use it).
262 * <p>
263 * See {@link #getCapabilities}
264 * @hide
265 */
Brian Attwellad147f42014-12-19 11:37:16 -0800266 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800267 public static final int CAPABILITY_MULTI_USER = 0x20;
268
269 /**
Tyler Gunn65a3d342015-07-27 16:06:16 -0700270 * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a
271 * caller is able to specify a short subject line for an outgoing call. A capable receiving
272 * device displays the call subject on the incoming call screen.
273 * <p>
274 * See {@link #getCapabilities}
275 */
276 public static final int CAPABILITY_CALL_SUBJECT = 0x40;
277
278 /**
Bryce Leeb96d89c2015-10-14 16:48:40 -0700279 * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls.
280 * <p>
281 * See {@link #getCapabilities}
282 * @hide
283 */
Hall Liu2ef04112020-09-14 18:34:10 -0700284 @SystemApi
Bryce Leeb96d89c2015-10-14 16:48:40 -0700285 public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80;
286
287 /**
Tyler Gunn9a365752015-12-09 15:00:18 -0800288 * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a
289 * number relies on presence. Should only be set if the {@code PhoneAccount} also has
290 * {@link #CAPABILITY_VIDEO_CALLING}.
291 * <p>
Brad Ebinger722cacf2021-05-14 01:53:56 +0000292 * Note: As of Android 12, using the
Tyler Gunn9a365752015-12-09 15:00:18 -0800293 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the
294 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether
Brad Ebinger722cacf2021-05-14 01:53:56 +0000295 * a contact's phone number supports video calling has been deprecated and should only be used
296 * on devices where {@link CarrierConfigManager#KEY_USE_RCS_PRESENCE_BOOL} is set. On newer
297 * devices, applications must use {@link android.telephony.ims.RcsUceAdapter} instead to
298 * determine whether or not a contact's phone number supports carrier video calling.
Tyler Gunn9a365752015-12-09 15:00:18 -0800299 * <p>
300 * See {@link #getCapabilities}
301 */
302 public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100;
303
304 /**
Tyler Gunncee9ea62016-03-24 11:45:43 -0700305 * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed.
306 * <p>
307 * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will
308 * convert all outgoing video calls to emergency numbers to audio-only.
309 * @hide
310 */
Hall Liu2ef04112020-09-14 18:34:10 -0700311 @SystemApi
Tyler Gunncee9ea62016-03-24 11:45:43 -0700312 public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200;
313
314 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800315 * Flag indicating that this {@link PhoneAccount} supports video calling.
316 * This is not an indication that the {@link PhoneAccount} is currently able to make a video
317 * call, but rather that it has the ability to make video calls (but not necessarily at this
318 * time).
319 * <p>
320 * Whether a {@link PhoneAccount} can make a video call is ultimately controlled by
321 * {@link #CAPABILITY_VIDEO_CALLING}, which indicates whether the {@link PhoneAccount} is
322 * currently capable of making a video call. Consider a case where, for example, a
323 * {@link PhoneAccount} supports making video calls (e.g.
324 * {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING}), but a current lack of network connectivity
325 * prevents video calls from being made (e.g. {@link #CAPABILITY_VIDEO_CALLING}).
326 * <p>
327 * See {@link #getCapabilities}
328 */
329 public static final int CAPABILITY_SUPPORTS_VIDEO_CALLING = 0x400;
330
331 /**
Tyler Gunnf5035432017-01-09 09:43:12 -0800332 * Flag indicating that this {@link PhoneAccount} is responsible for managing its own
333 * {@link Connection}s. This type of {@link PhoneAccount} is ideal for use with standalone
334 * calling apps which do not wish to use the default phone app for {@link Connection} UX,
335 * but which want to leverage the call and audio routing capabilities of the Telecom framework.
336 * <p>
337 * When set, {@link Connection}s created by the self-managed {@link ConnectionService} will not
338 * be surfaced to implementations of the {@link InCallService} API. Thus it is the
339 * responsibility of a self-managed {@link ConnectionService} to provide a user interface for
340 * its {@link Connection}s.
341 * <p>
342 * Self-managed {@link Connection}s will, however, be displayed on connected Bluetooth devices.
343 */
344 public static final int CAPABILITY_SELF_MANAGED = 0x800;
345
346 /**
Hall Liu95d55872017-01-25 17:12:49 -0800347 * Flag indicating that this {@link PhoneAccount} is capable of making a call with an
348 * RTT (Real-time text) session.
349 * When set, Telecom will attempt to open an RTT session on outgoing calls that specify
350 * that they should be placed with an RTT session , and the in-call app will be displayed
351 * with text entry fields for RTT. Likewise, the in-call app can request that an RTT
352 * session be opened during a call if this bit is set.
353 */
354 public static final int CAPABILITY_RTT = 0x1000;
355
Brad Ebinger3636d742019-05-21 15:28:19 -0700356 /**
357 * Flag indicating that this {@link PhoneAccount} is the preferred SIM subscription for
Hall Liu2ef04112020-09-14 18:34:10 -0700358 * emergency calls. A {@link PhoneAccount} that sets this capability must also
Brad Ebinger3636d742019-05-21 15:28:19 -0700359 * set the {@link #CAPABILITY_SIM_SUBSCRIPTION} and {@link #CAPABILITY_PLACE_EMERGENCY_CALLS}
Hall Liu2ef04112020-09-14 18:34:10 -0700360 * capabilities. There must only be one emergency preferred {@link PhoneAccount} on the device.
Brad Ebinger3636d742019-05-21 15:28:19 -0700361 * <p>
362 * When set, Telecom will prefer this {@link PhoneAccount} over others for emergency calling,
363 * even if the emergency call was placed with a specific {@link PhoneAccount} set using the
364 * extra{@link TelecomManager#EXTRA_PHONE_ACCOUNT_HANDLE} in
365 * {@link Intent#ACTION_CALL_EMERGENCY} or {@link TelecomManager#placeCall(Uri, Bundle)}.
366 *
367 * @hide
368 */
Hall Liu2ef04112020-09-14 18:34:10 -0700369 @SystemApi
Brad Ebinger3636d742019-05-21 15:28:19 -0700370 public static final int CAPABILITY_EMERGENCY_PREFERRED = 0x2000;
371
Ravi Paluri80aa2142019-12-02 11:57:37 +0530372 /**
373 * An adhoc conference call is established by providing a list of addresses to
374 * {@code TelecomManager#startConference(List<Uri>, int videoState)} where the
375 * {@link ConnectionService} is responsible for connecting all indicated participants
376 * to a conference simultaneously.
377 * This is in contrast to conferences formed by merging calls together (e.g. using
378 * {@link android.telecom.Call#mergeConference()}).
379 */
380 public static final int CAPABILITY_ADHOC_CONFERENCE_CALLING = 0x4000;
381
Shuo Qiand24aea32020-11-24 15:08:49 -0800382 /**
383 * Flag indicating whether this {@link PhoneAccount} is capable of supporting the call composer
384 * functionality for enriched calls.
385 */
386 public static final int CAPABILITY_CALL_COMPOSER = 0x8000;
387
Hunter Knepshield25265682022-01-19 02:25:06 -0800388 /**
389 * Flag indicating that this {@link PhoneAccount} provides SIM-based voice calls, potentially as
390 * an over-the-top solution such as wi-fi calling.
391 *
392 * <p>Similar to {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING}, this capability indicates this
393 * {@link PhoneAccount} has the ability to make voice calls (but not necessarily at this time).
394 * Whether this {@link PhoneAccount} can make a voice call is ultimately controlled by {@link
395 * #CAPABILITY_VOICE_CALLING_AVAILABLE}, which indicates whether this {@link PhoneAccount} is
396 * currently capable of making a voice call. Consider a case where, for example, a {@link
397 * PhoneAccount} supports making voice calls (e.g. {@link
398 * #CAPABILITY_SUPPORTS_VOICE_CALLING_INDICATIONS}), but a current lack of network connectivity
399 * prevents voice calls from being made (e.g. {@link #CAPABILITY_VOICE_CALLING_AVAILABLE}).
400 *
401 * <p>In order to declare this capability, this {@link PhoneAccount} must also declare {@link
402 * #CAPABILITY_SIM_SUBSCRIPTION} or {@link #CAPABILITY_CONNECTION_MANAGER} and satisfy the
403 * associated requirements.
404 *
405 * @see #CAPABILITY_VOICE_CALLING_AVAILABLE
406 * @see #getCapabilities
407 */
408 public static final int CAPABILITY_SUPPORTS_VOICE_CALLING_INDICATIONS = 0x10000;
409
410 /**
411 * Flag indicating that this {@link PhoneAccount} is <em>currently</em> able to place SIM-based
412 * voice calls, similar to {@link #CAPABILITY_VIDEO_CALLING}.
413 *
414 * <p>See also {@link #CAPABILITY_SUPPORTS_VOICE_CALLING_INDICATIONS}, which indicates whether
415 * the {@code PhoneAccount} supports placing SIM-based voice calls or not.
416 *
417 * <p>In order to declare this capability, this {@link PhoneAccount} must also declare {@link
418 * #CAPABILITY_SIM_SUBSCRIPTION} or {@link #CAPABILITY_CONNECTION_MANAGER} and satisfy the
419 * associated requirements.
420 *
421 * @see #CAPABILITY_SUPPORTS_VOICE_CALLING_INDICATIONS
422 * @see #getCapabilities
423 */
424 public static final int CAPABILITY_VOICE_CALLING_AVAILABLE = 0x20000;
425
Thomas Stuart9bfb2432022-09-27 15:02:07 -0700426
427 /**
428 * Flag indicating that this {@link PhoneAccount} supports the use TelecomManager APIs that
429 * utilize {@link android.os.OutcomeReceiver}s or {@link java.util.function.Consumer}s.
430 * Be aware, if this capability is set, {@link #CAPABILITY_SELF_MANAGED} will be amended by
431 * Telecom when this {@link PhoneAccount} is registered via
432 * {@link TelecomManager#registerPhoneAccount(PhoneAccount)}.
433 *
434 * <p>
435 * {@link android.os.OutcomeReceiver}s and {@link java.util.function.Consumer}s represent
436 * transactional operations because the operation can succeed or fail. An app wishing to use
437 * transactional operations should define behavior for a successful and failed TelecomManager
438 * API call.
439 *
440 * @see #CAPABILITY_SELF_MANAGED
441 * @see #getCapabilities
442 */
443 public static final int CAPABILITY_SUPPORTS_TRANSACTIONAL_OPERATIONS = 0x40000;
444
Grace Jiaef5a4cc2022-12-13 11:08:55 -0800445 /**
446 * Flag indicating that this voip app {@link PhoneAccount} supports the call streaming session
447 * to stream call audio to another remote device via streaming app.
448 *
449 * @see #getCapabilities
450 */
451 public static final int CAPABILITY_SUPPORTS_CALL_STREAMING = 0x80000;
452
453 /* NEXT CAPABILITY: [0x100000, 0x200000, 0x400000] */
Hall Liu95d55872017-01-25 17:12:49 -0800454
455 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700456 * URI scheme for telephone number URIs.
457 */
458 public static final String SCHEME_TEL = "tel";
459
460 /**
461 * URI scheme for voicemail URIs.
462 */
463 public static final String SCHEME_VOICEMAIL = "voicemail";
464
465 /**
466 * URI scheme for SIP URIs.
467 */
468 public static final String SCHEME_SIP = "sip";
469
Nancy Chen3ace54b2014-10-22 17:45:26 -0700470 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800471 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700472 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700473 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800474 public static final int NO_ICON_TINT = 0;
475
476 /**
477 * Indicating no hightlight color is set.
478 */
479 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700480
Ihab Awad476cc832014-11-03 09:47:51 -0800481 /**
482 * Indicating no resource ID is set.
483 */
484 public static final int NO_RESOURCE_ID = -1;
485
Evan Charlton8c8a0622014-07-20 12:31:00 -0700486 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700487 private final Uri mAddress;
488 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700489 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800490 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700491 private final CharSequence mLabel;
492 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700493 private final List<String> mSupportedUriSchemes;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800494 private final int mSupportedAudioRoutes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700495 private final Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700496 private final Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700497 private boolean mIsEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700498 private String mGroupId;
Brad Ebingerb0c1d912024-01-12 14:51:35 -0800499 private final Set<PhoneAccountHandle> mSimultaneousCallingRestriction;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700500
Tyler Gunn3b347812018-08-24 14:17:05 -0700501 @Override
502 public boolean equals(Object o) {
503 if (this == o) return true;
504 if (o == null || getClass() != o.getClass()) return false;
505 PhoneAccount that = (PhoneAccount) o;
506 return mCapabilities == that.mCapabilities &&
507 mHighlightColor == that.mHighlightColor &&
508 mSupportedAudioRoutes == that.mSupportedAudioRoutes &&
509 mIsEnabled == that.mIsEnabled &&
510 Objects.equals(mAccountHandle, that.mAccountHandle) &&
511 Objects.equals(mAddress, that.mAddress) &&
512 Objects.equals(mSubscriptionAddress, that.mSubscriptionAddress) &&
513 Objects.equals(mLabel, that.mLabel) &&
514 Objects.equals(mShortDescription, that.mShortDescription) &&
515 Objects.equals(mSupportedUriSchemes, that.mSupportedUriSchemes) &&
516 areBundlesEqual(mExtras, that.mExtras) &&
Brad Ebingerb0c1d912024-01-12 14:51:35 -0800517 Objects.equals(mGroupId, that.mGroupId)
518 && Objects.equals(mSimultaneousCallingRestriction,
519 that.mSimultaneousCallingRestriction);
Tyler Gunn3b347812018-08-24 14:17:05 -0700520 }
521
522 @Override
523 public int hashCode() {
524 return Objects.hash(mAccountHandle, mAddress, mSubscriptionAddress, mCapabilities,
525 mHighlightColor, mLabel, mShortDescription, mSupportedUriSchemes,
526 mSupportedAudioRoutes,
Brad Ebingerb0c1d912024-01-12 14:51:35 -0800527 mExtras, mIsEnabled, mGroupId, mSimultaneousCallingRestriction);
Tyler Gunn3b347812018-08-24 14:17:05 -0700528 }
529
Santos Cordon32c65a52014-10-27 14:57:49 -0700530 /**
531 * Helper class for creating a {@link PhoneAccount}.
532 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700533 public static class Builder {
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800534
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700535 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700536 private Uri mAddress;
537 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700538 private int mCapabilities;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800539 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800540 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700541 private CharSequence mLabel;
542 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700543 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700544 private Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700545 private Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700546 private boolean mIsEnabled = false;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700547 private String mGroupId = "";
Brad Ebingerb0c1d912024-01-12 14:51:35 -0800548 private Set<PhoneAccountHandle> mSimultaneousCallingRestriction = null;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700549
Santos Cordon32c65a52014-10-27 14:57:49 -0700550 /**
551 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
Thomas Stuarte2b0dc52022-12-28 11:10:50 -0800552 * <p>
553 * Note: each CharSequence or String field is limited to 256 characters. This check is
554 * enforced when registering the PhoneAccount via
555 * {@link TelecomManager#registerPhoneAccount(PhoneAccount)} and will cause an
556 * {@link IllegalArgumentException} to be thrown if the character field limit is over 256.
Santos Cordon32c65a52014-10-27 14:57:49 -0700557 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700558 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
559 this.mAccountHandle = accountHandle;
560 this.mLabel = label;
561 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700562
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700563 /**
564 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
565 * {@link PhoneAccount}.
566 *
567 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
568 */
569 public Builder(PhoneAccount phoneAccount) {
570 mAccountHandle = phoneAccount.getAccountHandle();
571 mAddress = phoneAccount.getAddress();
572 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
573 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800574 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700575 mLabel = phoneAccount.getLabel();
576 mShortDescription = phoneAccount.getShortDescription();
577 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700578 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc02015-05-08 13:52:09 -0700579 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunnd426b202015-10-13 13:33:53 -0700580 mExtras = phoneAccount.getExtras();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700581 mGroupId = phoneAccount.getGroupId();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800582 mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes();
Brad Ebingerad37ddc2024-01-22 12:34:02 -0800583 if (phoneAccount.hasSimultaneousCallingRestriction()) {
584 mSimultaneousCallingRestriction = phoneAccount.getSimultaneousCallingRestriction();
585 }
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700586 }
587
Santos Cordon32c65a52014-10-27 14:57:49 -0700588 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700589 * Sets the label. See {@link PhoneAccount#getLabel()}.
Thomas Stuarte2b0dc52022-12-28 11:10:50 -0800590 * <p>
591 * Note: Each CharSequence or String field is limited to 256 characters. This check is
592 * enforced when registering the PhoneAccount via
593 * {@link TelecomManager#registerPhoneAccount(PhoneAccount)} and will cause an
594 * {@link IllegalArgumentException} to be thrown if the character field limit is over 256.
Tyler Gunn37653562017-03-13 18:15:15 -0700595 *
596 * @param label The label of the phone account.
597 * @return The builder.
598 * @hide
599 */
600 public Builder setLabel(CharSequence label) {
601 this.mLabel = label;
602 return this;
603 }
604
605 /**
Santos Cordon32c65a52014-10-27 14:57:49 -0700606 * Sets the address. See {@link PhoneAccount#getAddress}.
Thomas Stuartba6c21c2022-11-21 17:38:21 -0800607 * <p>
608 * Note: The entire URI value is limited to 256 characters. This check is
609 * enforced when registering the PhoneAccount via
610 * {@link TelecomManager#registerPhoneAccount(PhoneAccount)} and will cause an
611 * {@link IllegalArgumentException} to be thrown if URI is over 256.
Santos Cordon32c65a52014-10-27 14:57:49 -0700612 *
613 * @param value The address of the phone account.
614 * @return The builder.
615 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700616 public Builder setAddress(Uri value) {
617 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700618 return this;
619 }
620
Santos Cordon32c65a52014-10-27 14:57:49 -0700621 /**
622 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
623 *
624 * @param value The subscription address.
625 * @return The builder.
626 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700627 public Builder setSubscriptionAddress(Uri value) {
628 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700629 return this;
630 }
631
Santos Cordon32c65a52014-10-27 14:57:49 -0700632 /**
633 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
634 *
635 * @param value The capabilities to set.
636 * @return The builder.
637 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700638 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700639 this.mCapabilities = value;
640 return this;
641 }
642
Santos Cordon32c65a52014-10-27 14:57:49 -0700643 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700644 * Sets the icon. See {@link PhoneAccount#getIcon}.
Thomas Stuartba6c21c2022-11-21 17:38:21 -0800645 * <p>
646 * Note: An {@link IllegalArgumentException} if the Icon cannot be written to memory.
647 * This check is enforced when registering the PhoneAccount via
648 * {@link TelecomManager#registerPhoneAccount(PhoneAccount)}
Santos Cordon32c65a52014-10-27 14:57:49 -0700649 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700650 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700651 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700652 public Builder setIcon(Icon icon) {
653 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700654 return this;
655 }
656
657 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800658 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700659 *
Ihab Awad476cc832014-11-03 09:47:51 -0800660 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700661 * @return The builder.
662 */
Ihab Awad476cc832014-11-03 09:47:51 -0800663 public Builder setHighlightColor(int value) {
664 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700665 return this;
666 }
667
Santos Cordon32c65a52014-10-27 14:57:49 -0700668 /**
669 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
Thomas Stuarte2b0dc52022-12-28 11:10:50 -0800670 * <p>
671 * Note: Each CharSequence or String field is limited to 256 characters. This check is
672 * enforced when registering the PhoneAccount via
673 * {@link TelecomManager#registerPhoneAccount(PhoneAccount)} and will cause an
674 * {@link IllegalArgumentException} to be thrown if the character field limit is over 256.
Santos Cordon32c65a52014-10-27 14:57:49 -0700675 *
676 * @param value The short description.
677 * @return The builder.
678 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700679 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700680 this.mShortDescription = value;
681 return this;
682 }
683
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700684 /**
685 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
686 *
Thomas Stuartba6c21c2022-11-21 17:38:21 -0800687 * <p>
688 * Each URI scheme is limited to 256 characters. Adding a scheme over 256 characters will
689 * cause an {@link IllegalArgumentException} to be thrown when the account is registered.
690 *
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700691 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700692 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700693 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700694 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700695 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
696 this.mSupportedUriSchemes.add(uriScheme);
697 }
698 return this;
699 }
700
701 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700702 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700703 *
Thomas Stuartba6c21c2022-11-21 17:38:21 -0800704 * <p>
705 * A max of 10 URI schemes can be added per account. Additionally, each URI scheme is
706 * limited to 256 characters. Adding more than 10 URI schemes or 256 characters on any
707 * scheme will cause an {@link IllegalArgumentException} to be thrown when the account
708 * is registered.
709 *
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700710 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700711 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700712 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700713 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
714 mSupportedUriSchemes.clear();
715
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700716 if (uriSchemes != null && !uriSchemes.isEmpty()) {
717 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700718 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700719 }
720 }
721 return this;
722 }
723
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700724 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700725 * Specifies the extras associated with the {@link PhoneAccount}.
726 * <p>
727 * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer},
728 * and {@link Boolean}. Extras which are not of these types are ignored.
Thomas Stuarte2b0dc52022-12-28 11:10:50 -0800729 * <p>
730 * Note: Each Bundle (Key, Value) String field is limited to 256 characters. Additionally,
731 * the bundle is limited to 100 (Key, Value) pairs total. This check is
732 * enforced when registering the PhoneAccount via
733 * {@link TelecomManager#registerPhoneAccount(PhoneAccount)} and will cause an
734 * {@link IllegalArgumentException} to be thrown if the character field limit is over 256
735 * or more than 100 (Key, Value) pairs are in the Bundle.
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700736 *
737 * @param extras
738 * @return
739 */
740 public Builder setExtras(Bundle extras) {
741 mExtras = extras;
742 return this;
743 }
744
745 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700746 * Sets the enabled state of the phone account.
747 *
748 * @param isEnabled The enabled state.
749 * @return The builder.
750 * @hide
751 */
752 public Builder setIsEnabled(boolean isEnabled) {
753 mIsEnabled = isEnabled;
754 return this;
755 }
756
757 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700758 * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is
759 * registered to Telecom, it will replace another {@link PhoneAccount} that is already
760 * registered in Telecom and take on the current user defaults and enabled status. There can
761 * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a
762 * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only
763 * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced.
Tyler Gunn5567d742019-10-31 13:04:37 -0700764 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -0800765 * Note: This is an API specific to the Telephony stack; the group Id will be ignored for
766 * callers not holding the correct permission.
Thomas Stuarte2b0dc52022-12-28 11:10:50 -0800767 * <p>
768 * Additionally, each CharSequence or String field is limited to 256 characters.
769 * This check is enforced when registering the PhoneAccount via
770 * {@link TelecomManager#registerPhoneAccount(PhoneAccount)} and will cause an
771 * {@link IllegalArgumentException} to be thrown if the character field limit is over 256.
Tyler Gunn5567d742019-10-31 13:04:37 -0700772 *
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700773 * @param groupId The group Id of the {@link PhoneAccount} that will replace any other
774 * registered {@link PhoneAccount} in Telecom with the same Group Id.
775 * @return The builder
776 * @hide
777 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700778 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -0800779 @RequiresPermission(MODIFY_PHONE_STATE)
Tyler Gunn5567d742019-10-31 13:04:37 -0700780 public @NonNull Builder setGroupId(@NonNull String groupId) {
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700781 if (groupId != null) {
782 mGroupId = groupId;
783 } else {
784 mGroupId = "";
785 }
786 return this;
787 }
788
789 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800790 * Sets the audio routes supported by this {@link PhoneAccount}.
791 *
792 * @param routes bit mask of available routes.
793 * @return The builder.
794 * @hide
795 */
796 public Builder setSupportedAudioRoutes(int routes) {
797 mSupportedAudioRoutes = routes;
798 return this;
799 }
800
801 /**
Brad Ebingerb0c1d912024-01-12 14:51:35 -0800802 * Restricts the ability of this {@link PhoneAccount} to ONLY support simultaneous calling
803 * with the other {@link PhoneAccountHandle}s in this Set.
804 * <p>
805 * If two or more {@link PhoneAccount}s support calling simultaneously, it means that
806 * Telecom allows the user to place additional outgoing calls and receive additional
807 * incoming calls using other {@link PhoneAccount}s while this PhoneAccount also has one or
808 * more active calls.
809 * <p>
810 * If this setter method is never called or cleared using
811 * {@link #clearSimultaneousCallingRestriction()}, there is no restriction and all
812 * {@link PhoneAccount}s registered to Telecom by this package support simultaneous calling.
Brad Ebinger1cfeff52024-02-06 15:36:22 -0800813 * If this setter is called and set as an empty Set, then this {@link PhoneAccount} does
814 * not support simultaneous calling with any other {@link PhoneAccount}s registered by the
815 * same application.
Brad Ebingerb0c1d912024-01-12 14:51:35 -0800816 * <p>
817 * Note: Simultaneous calling restrictions can only be placed on {@link PhoneAccount}s that
818 * were registered by the same application. Simultaneous calling across applications is
819 * always possible as long as the {@link Connection} supports hold. If a
820 * {@link PhoneAccountHandle} is included here and the package name doesn't match this
821 * application's package name, {@link TelecomManager#registerPhoneAccount(PhoneAccount)}
822 * will throw a {@link SecurityException}.
823 *
824 * @param handles The other {@link PhoneAccountHandle}s that support calling simultaneously
Brad Ebinger516e7ab2024-01-19 15:31:57 -0800825 * with this one. Use {@link #clearSimultaneousCallingRestriction()} to remove the
826 * restriction and allow simultaneous calling to be supported across all
827 * {@link PhoneAccount}s registered by this package.
Brad Ebingerb0c1d912024-01-12 14:51:35 -0800828 * @return The Builder used to set up the new PhoneAccount.
829 */
830 @FlaggedApi(Flags.FLAG_SIMULTANEOUS_CALLING_INDICATIONS)
831 public @NonNull Builder setSimultaneousCallingRestriction(
832 @NonNull Set<PhoneAccountHandle> handles) {
833 if (handles == null) {
834 throw new IllegalArgumentException("the Set of PhoneAccountHandles must not be "
835 + "null");
836 }
837 mSimultaneousCallingRestriction = handles;
838 return this;
839 }
840
841 /**
842 * Clears a previously set simultaneous calling restriction set when
843 * {@link PhoneAccount.Builder#Builder(PhoneAccount)} is used to create a new PhoneAccount
844 * from an existing one.
845 *
846 * @return The Builder used to set up the new PhoneAccount.
847 * @see #setSimultaneousCallingRestriction(Set)
848 */
849 @FlaggedApi(Flags.FLAG_SIMULTANEOUS_CALLING_INDICATIONS)
850 public @NonNull Builder clearSimultaneousCallingRestriction() {
851 mSimultaneousCallingRestriction = null;
852 return this;
853 }
854
855 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700856 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
857 *
858 * @return The {@link PhoneAccount}.
859 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700860 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700861 // If no supported URI schemes were defined, assume "tel" is supported.
862 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700863 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700864 }
865
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700866 return new PhoneAccount(
867 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700868 mAddress,
869 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700870 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700871 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800872 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700873 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700874 mShortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700875 mSupportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700876 mExtras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800877 mSupportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700878 mIsEnabled,
Brad Ebingerb0c1d912024-01-12 14:51:35 -0800879 mGroupId,
880 mSimultaneousCallingRestriction);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700881 }
882 }
883
884 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700885 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700886 Uri address,
887 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700888 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700889 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800890 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700891 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700892 CharSequence shortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700893 List<String> supportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700894 Bundle extras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800895 int supportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700896 boolean isEnabled,
Brad Ebingerb0c1d912024-01-12 14:51:35 -0800897 String groupId,
898 Set<PhoneAccountHandle> simultaneousCallingRestriction) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700899 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700900 mAddress = address;
901 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700902 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700903 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800904 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700905 mLabel = label;
906 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700907 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700908 mExtras = extras;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800909 mSupportedAudioRoutes = supportedAudioRoutes;
Santos Cordon91371dc02015-05-08 13:52:09 -0700910 mIsEnabled = isEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700911 mGroupId = groupId;
Brad Ebingerb0c1d912024-01-12 14:51:35 -0800912 mSimultaneousCallingRestriction = simultaneousCallingRestriction;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700913 }
914
Andrew Lee3085a6c2014-09-04 10:59:13 -0700915 public static Builder builder(
916 PhoneAccountHandle accountHandle,
917 CharSequence label) {
918 return new Builder(accountHandle, label);
919 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700920
Ihab Awad807fe0a2014-07-09 12:30:52 -0700921 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700922 * Returns a builder initialized with the current {@link PhoneAccount} instance.
923 *
924 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700925 */
926 public Builder toBuilder() { return new Builder(this); }
927
928 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700929 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700930 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700931 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700932 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700933 public PhoneAccountHandle getAccountHandle() {
934 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700935 }
936
937 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700938 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700939 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700940 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700941 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700942 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700943 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700944 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700945 public Uri getAddress() {
946 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700947 }
948
949 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700950 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700951 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700952 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000953 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
954 * has been used to alter the callback number.
955 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700956 *
957 * @return The subscription number, suitable for display to the user.
958 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700959 public Uri getSubscriptionAddress() {
960 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700961 }
962
963 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700964 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700965 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700966 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700967 */
968 public int getCapabilities() {
969 return mCapabilities;
970 }
971
972 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700973 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
974 * bit mask.
975 *
976 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700977 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700978 */
979 public boolean hasCapabilities(int capability) {
980 return (mCapabilities & capability) == capability;
981 }
982
983 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800984 * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask.
985 *
986 * @param route The routes to check.
987 * @return {@code true} if the phone account has the routes.
988 * @hide
989 */
990 public boolean hasAudioRoutes(int routes) {
991 return (mSupportedAudioRoutes & routes) == routes;
992 }
993
994 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700995 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700996 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700997 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700998 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700999 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -07001000 return mLabel;
1001 }
1002
1003 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001004 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -07001005 *
Evan Charlton8c8a0622014-07-20 12:31:00 -07001006 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -07001007 */
Santos Cordon146a3e32014-07-21 00:00:44 -07001008 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -07001009 return mShortDescription;
1010 }
1011
1012 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -07001013 * The URI schemes supported by this {@code PhoneAccount}.
1014 *
1015 * @return The URI schemes.
1016 */
1017 public List<String> getSupportedUriSchemes() {
1018 return mSupportedUriSchemes;
1019 }
1020
1021 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -07001022 * The extras associated with this {@code PhoneAccount}.
1023 * <p>
1024 * A {@link ConnectionService} may provide implementation specific information about the
1025 * {@link PhoneAccount} via the extras.
1026 *
1027 * @return The extras.
1028 */
1029 public Bundle getExtras() {
1030 return mExtras;
1031 }
1032
1033 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001034 * The audio routes supported by this {@code PhoneAccount}.
1035 *
1036 * @hide
1037 */
1038 public int getSupportedAudioRoutes() {
1039 return mSupportedAudioRoutes;
1040 }
1041
1042 /**
Santos Cordoncad84a22015-05-13 11:17:25 -07001043 * The icon to represent this {@code PhoneAccount}.
1044 *
1045 * @return The icon.
1046 */
1047 public Icon getIcon() {
1048 return mIcon;
1049 }
1050
1051 /**
Santos Cordon895d4b82015-06-25 16:41:48 -07001052 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
1053 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc02015-05-08 13:52:09 -07001054 *
Santos Cordon895d4b82015-06-25 16:41:48 -07001055 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc02015-05-08 13:52:09 -07001056 */
1057 public boolean isEnabled() {
1058 return mIsEnabled;
1059 }
1060
1061 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -07001062 * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an
1063 * empty {@link String} if the {@link PhoneAccount} is not in a group. If this
1064 * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered
1065 * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced,
1066 * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}.
1067 * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced.
1068 *
1069 * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group.
1070 * @hide
1071 */
1072 public String getGroupId() {
1073 return mGroupId;
1074 }
1075
1076 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -07001077 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -07001078 * scheme.
1079 *
1080 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -07001081 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -07001082 * specified URI scheme.
1083 */
1084 public boolean supportsUriScheme(String uriScheme) {
1085 if (mSupportedUriSchemes == null || uriScheme == null) {
1086 return false;
1087 }
1088
1089 for (String scheme : mSupportedUriSchemes) {
1090 if (scheme != null && scheme.equals(uriScheme)) {
1091 return true;
1092 }
1093 }
1094 return false;
1095 }
1096
1097 /**
Ihab Awad476cc832014-11-03 09:47:51 -08001098 * A highlight color to use in displaying information about this {@code PhoneAccount}.
1099 *
1100 * @return A hexadecimal color value.
1101 */
1102 public int getHighlightColor() {
1103 return mHighlightColor;
1104 }
1105
Santos Cordon91371dc02015-05-08 13:52:09 -07001106 /**
1107 * Sets the enabled state of the phone account.
1108 * @hide
1109 */
1110 public void setIsEnabled(boolean isEnabled) {
1111 mIsEnabled = isEnabled;
1112 }
1113
Tyler Gunnf5035432017-01-09 09:43:12 -08001114 /**
1115 * @return {@code true} if the {@link PhoneAccount} is self-managed, {@code false} otherwise.
1116 * @hide
1117 */
1118 public boolean isSelfManaged() {
1119 return (mCapabilities & CAPABILITY_SELF_MANAGED) == CAPABILITY_SELF_MANAGED;
1120 }
1121
Brad Ebingerb0c1d912024-01-12 14:51:35 -08001122 /**
1123 * If a restriction is set (see {@link #hasSimultaneousCallingRestriction()}), this method
1124 * returns the Set of {@link PhoneAccountHandle}s that are allowed to support calls
1125 * simultaneously with this {@link PhoneAccount}.
1126 * <p>
1127 * If this {@link PhoneAccount} is busy with one or more ongoing calls, a restriction is set on
1128 * this PhoneAccount (see {@link #hasSimultaneousCallingRestriction()} to check), and a new
1129 * incoming or outgoing call is received or placed on a PhoneAccount that is not in this Set,
1130 * Telecom will reject or cancel the pending call in favor of keeping the ongoing call alive.
1131 * <p>
1132 * Note: Simultaneous calling restrictions can only be placed on {@link PhoneAccount}s that
1133 * were registered by the same application. Simultaneous calling across applications is
1134 * always possible as long as the {@link Connection} supports hold.
1135 *
1136 * @return the Set of {@link PhoneAccountHandle}s that this {@link PhoneAccount} supports
1137 * simultaneous calls with.
1138 * @throws IllegalStateException If there is no restriction set on this {@link PhoneAccount}
1139 * and this method is called. Whether or not there is a restriction can be checked using
1140 * {@link #hasSimultaneousCallingRestriction()}.
1141 */
1142 @FlaggedApi(Flags.FLAG_SIMULTANEOUS_CALLING_INDICATIONS)
1143 public @NonNull Set<PhoneAccountHandle> getSimultaneousCallingRestriction() {
1144 if (mSimultaneousCallingRestriction == null) {
1145 throw new IllegalStateException("This method can not be called if there is no "
1146 + "simultaneous calling restriction. See #hasSimultaneousCallingRestriction");
1147 }
1148 return mSimultaneousCallingRestriction;
1149 }
1150
1151 /**
1152 * Whether or not this {@link PhoneAccount} contains a simultaneous calling restriction on it.
1153 *
1154 * @return {@code true} if this PhoneAccount contains a simultaneous calling restriction,
1155 * {@code false} if it does not. Use {@link #getSimultaneousCallingRestriction()} to query which
1156 * other {@link PhoneAccount}s support simultaneous calling with this one.
1157 * @see #getSimultaneousCallingRestriction() for more information on how the sinultaneous
1158 * calling restriction works.
1159 */
1160 @FlaggedApi(Flags.FLAG_SIMULTANEOUS_CALLING_INDICATIONS)
1161 public boolean hasSimultaneousCallingRestriction() {
1162 return mSimultaneousCallingRestriction != null;
1163 }
1164
Ihab Awad807fe0a2014-07-09 12:30:52 -07001165 //
1166 // Parcelable implementation
1167 //
1168
1169 @Override
1170 public int describeContents() {
1171 return 0;
1172 }
1173
1174 @Override
1175 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -08001176 if (mAccountHandle == null) {
1177 out.writeInt(0);
1178 } else {
1179 out.writeInt(1);
1180 mAccountHandle.writeToParcel(out, flags);
1181 }
1182 if (mAddress == null) {
1183 out.writeInt(0);
1184 } else {
1185 out.writeInt(1);
1186 mAddress.writeToParcel(out, flags);
1187 }
1188 if (mSubscriptionAddress == null) {
1189 out.writeInt(0);
1190 } else {
1191 out.writeInt(1);
1192 mSubscriptionAddress.writeToParcel(out, flags);
1193 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -07001194 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -08001195 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -07001196 out.writeCharSequence(mLabel);
1197 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -08001198 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc02015-05-08 13:52:09 -07001199
Santos Cordoncad84a22015-05-13 11:17:25 -07001200 if (mIcon == null) {
1201 out.writeInt(0);
1202 } else {
1203 out.writeInt(1);
1204 mIcon.writeToParcel(out, flags);
1205 }
Santos Cordon91371dc02015-05-08 13:52:09 -07001206 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Tyler Gunnef829ec2015-10-08 09:46:23 -07001207 out.writeBundle(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -07001208 out.writeString(mGroupId);
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001209 out.writeInt(mSupportedAudioRoutes);
Brad Ebingerb0c1d912024-01-12 14:51:35 -08001210 if (mSimultaneousCallingRestriction == null) {
1211 out.writeBoolean(false);
1212 } else {
1213 out.writeBoolean(true);
1214 out.writeTypedList(mSimultaneousCallingRestriction.stream().toList());
1215 }
Ihab Awad807fe0a2014-07-09 12:30:52 -07001216 }
1217
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07001218 public static final @android.annotation.NonNull Creator<PhoneAccount> CREATOR
Evan Charlton8c8a0622014-07-20 12:31:00 -07001219 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -07001220 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -07001221 public PhoneAccount createFromParcel(Parcel in) {
1222 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -07001223 }
1224
1225 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -07001226 public PhoneAccount[] newArray(int size) {
1227 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -07001228 }
1229 };
1230
Evan Charlton8c8a0622014-07-20 12:31:00 -07001231 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -08001232 if (in.readInt() > 0) {
1233 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
1234 } else {
1235 mAccountHandle = null;
1236 }
1237 if (in.readInt() > 0) {
1238 mAddress = Uri.CREATOR.createFromParcel(in);
1239 } else {
1240 mAddress = null;
1241 }
1242 if (in.readInt() > 0) {
1243 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
1244 } else {
1245 mSubscriptionAddress = null;
1246 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -07001247 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -08001248 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -07001249 mLabel = in.readCharSequence();
1250 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -08001251 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -07001252 if (in.readInt() > 0) {
1253 mIcon = Icon.CREATOR.createFromParcel(in);
1254 } else {
1255 mIcon = null;
1256 }
Santos Cordon91371dc02015-05-08 13:52:09 -07001257 mIsEnabled = in.readByte() == 1;
Tyler Gunnef829ec2015-10-08 09:46:23 -07001258 mExtras = in.readBundle();
Brad Ebinger7298f3b2016-06-10 17:19:42 -07001259 mGroupId = in.readString();
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001260 mSupportedAudioRoutes = in.readInt();
Brad Ebingerb0c1d912024-01-12 14:51:35 -08001261 if (in.readBoolean()) {
1262 List<PhoneAccountHandle> list = new ArrayList<>();
1263 in.readTypedList(list, PhoneAccountHandle.CREATOR);
1264 mSimultaneousCallingRestriction = new ArraySet<>(list);
1265 } else {
1266 mSimultaneousCallingRestriction = null;
1267 }
Ihab Awad807fe0a2014-07-09 12:30:52 -07001268 }
Tyler Gunn76c01a52014-09-30 14:47:51 -07001269
1270 @Override
1271 public String toString() {
Santos Cordon91371dc02015-05-08 13:52:09 -07001272 StringBuilder sb = new StringBuilder().append("[[")
1273 .append(mIsEnabled ? 'X' : ' ')
1274 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -07001275 .append(mAccountHandle)
1276 .append(" Capabilities: ")
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001277 .append(capabilitiesToString())
1278 .append(" Audio Routes: ")
1279 .append(audioRoutesToString())
Tyler Gunn76c01a52014-09-30 14:47:51 -07001280 .append(" Schemes: ");
1281 for (String scheme : mSupportedUriSchemes) {
1282 sb.append(scheme)
1283 .append(" ");
1284 }
Tyler Gunnef829ec2015-10-08 09:46:23 -07001285 sb.append(" Extras: ");
Tyler Gunn25ed2d72015-10-05 14:14:38 -07001286 sb.append(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -07001287 sb.append(" GroupId: ");
1288 sb.append(Log.pii(mGroupId));
Brad Ebinger5365cc32024-01-26 09:53:55 -08001289 sb.append(" SC Restrictions: ");
1290 if (hasSimultaneousCallingRestriction()) {
1291 sb.append("[ ");
1292 for (PhoneAccountHandle handle : mSimultaneousCallingRestriction) {
1293 sb.append(handle);
1294 sb.append(" ");
1295 }
1296 sb.append("]");
1297 } else {
1298 sb.append("[NONE]");
1299 }
Tyler Gunn76c01a52014-09-30 14:47:51 -07001300 sb.append("]");
1301 return sb.toString();
1302 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001303
1304 /**
1305 * Generates a string representation of a capabilities bitmask.
1306 *
Tyler Gunn3e122f72016-01-11 19:25:00 -08001307 * @return String representation of the capabilities bitmask.
Tyler Gunn1847b4e2018-11-09 08:43:02 -08001308 * @hide
Tyler Gunn3e122f72016-01-11 19:25:00 -08001309 */
Tyler Gunn1847b4e2018-11-09 08:43:02 -08001310 public String capabilitiesToString() {
Tyler Gunn3e122f72016-01-11 19:25:00 -08001311 StringBuilder sb = new StringBuilder();
Tyler Gunnf5035432017-01-09 09:43:12 -08001312 if (hasCapabilities(CAPABILITY_SELF_MANAGED)) {
1313 sb.append("SelfManaged ");
1314 }
Tyler Gunn58cbd7a2016-11-11 11:31:28 -08001315 if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) {
1316 sb.append("SuppVideo ");
1317 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001318 if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) {
1319 sb.append("Video ");
1320 }
1321 if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
1322 sb.append("Presence ");
1323 }
1324 if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) {
1325 sb.append("CallProvider ");
1326 }
1327 if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) {
1328 sb.append("CallSubject ");
1329 }
1330 if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) {
1331 sb.append("ConnectionMgr ");
1332 }
1333 if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) {
1334 sb.append("EmergOnly ");
1335 }
1336 if (hasCapabilities(CAPABILITY_MULTI_USER)) {
1337 sb.append("MultiUser ");
1338 }
1339 if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) {
1340 sb.append("PlaceEmerg ");
1341 }
Brad Ebinger3636d742019-05-21 15:28:19 -07001342 if (hasCapabilities(CAPABILITY_EMERGENCY_PREFERRED)) {
1343 sb.append("EmerPrefer ");
1344 }
Tyler Gunncee9ea62016-03-24 11:45:43 -07001345 if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
1346 sb.append("EmergVideo ");
1347 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001348 if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) {
1349 sb.append("SimSub ");
1350 }
Hall Liu47ed6202017-11-20 16:25:39 -08001351 if (hasCapabilities(CAPABILITY_RTT)) {
Hunter Knepshield25265682022-01-19 02:25:06 -08001352 sb.append("Rtt ");
Hall Liu47ed6202017-11-20 16:25:39 -08001353 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05301354 if (hasCapabilities(CAPABILITY_ADHOC_CONFERENCE_CALLING)) {
Hunter Knepshield25265682022-01-19 02:25:06 -08001355 sb.append("AdhocConf ");
Ravi Paluri80aa2142019-12-02 11:57:37 +05301356 }
Shuo Qiand24aea32020-11-24 15:08:49 -08001357 if (hasCapabilities(CAPABILITY_CALL_COMPOSER)) {
1358 sb.append("CallComposer ");
1359 }
Hunter Knepshield25265682022-01-19 02:25:06 -08001360 if (hasCapabilities(CAPABILITY_SUPPORTS_VOICE_CALLING_INDICATIONS)) {
1361 sb.append("SuppVoice ");
1362 }
1363 if (hasCapabilities(CAPABILITY_VOICE_CALLING_AVAILABLE)) {
1364 sb.append("Voice ");
1365 }
Thomas Stuart649bedd2023-02-23 15:48:31 -08001366 if (hasCapabilities(CAPABILITY_SUPPORTS_TRANSACTIONAL_OPERATIONS)) {
1367 sb.append("TransactOps ");
1368 }
1369 if (hasCapabilities(CAPABILITY_SUPPORTS_CALL_STREAMING)) {
1370 sb.append("Stream ");
1371 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001372 return sb.toString();
1373 }
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001374
1375 private String audioRoutesToString() {
1376 StringBuilder sb = new StringBuilder();
1377
1378 if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) {
1379 sb.append("B");
1380 }
1381 if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) {
1382 sb.append("E");
1383 }
1384 if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) {
1385 sb.append("S");
1386 }
1387 if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) {
1388 sb.append("W");
1389 }
1390
1391 return sb.toString();
1392 }
Tyler Gunn3b347812018-08-24 14:17:05 -07001393
1394 /**
1395 * Determines if two {@link Bundle}s are equal.
1396 * @param extras First {@link Bundle} to check.
1397 * @param newExtras {@link Bundle} to compare against.
1398 * @return {@code true} if the {@link Bundle}s are equal, {@code false} otherwise.
1399 */
1400 private static boolean areBundlesEqual(Bundle extras, Bundle newExtras) {
1401 if (extras == null || newExtras == null) {
1402 return extras == newExtras;
1403 }
1404
1405 if (extras.size() != newExtras.size()) {
1406 return false;
1407 }
1408
1409 for(String key : extras.keySet()) {
1410 if (key != null) {
1411 final Object value = extras.get(key);
1412 final Object newValue = newExtras.get(key);
1413 if (!Objects.equals(value, newValue)) {
1414 return false;
1415 }
1416 }
1417 }
1418 return true;
1419 }
Ihab Awad807fe0a2014-07-09 12:30:52 -07001420}