blob: 835ecaa8c90dd067083e53695ce5d81952222c70 [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
Tyler Gunn5567d742019-10-31 13:04:37 -070021import android.annotation.NonNull;
Tyler Gunnc9503d62020-01-27 10:30:51 -080022import android.annotation.RequiresPermission;
Evan Charlton0e094d92014-11-08 15:49:16 -080023import android.annotation.SystemApi;
Brad Ebinger3636d742019-05-21 15:28:19 -070024import android.content.Intent;
Santos Cordoncad84a22015-05-13 11:17:25 -070025import android.graphics.drawable.Icon;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070026import android.net.Uri;
Tyler Gunn25ed2d72015-10-05 14:14:38 -070027import android.os.Bundle;
Ihab Awad807fe0a2014-07-09 12:30:52 -070028import android.os.Parcel;
29import android.os.Parcelable;
Hall Liu221f8042020-09-23 15:36:58 -070030import android.telephony.TelephonyManager;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070031import android.text.TextUtils;
Ihab Awad807fe0a2014-07-09 12:30:52 -070032
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070033import java.util.ArrayList;
34import java.util.Collections;
35import java.util.List;
Tyler Gunn3b347812018-08-24 14:17:05 -070036import java.util.Objects;
Ihab Awad807fe0a2014-07-09 12:30:52 -070037
38/**
Santos Cordon32c65a52014-10-27 14:57:49 -070039 * Represents a distinct method to place or receive a phone call. Apps which can place calls and
40 * 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 -080041 * this class and register it with the system using {@link TelecomManager}.
Santos Cordon32c65a52014-10-27 14:57:49 -070042 * <p>
43 * {@link TelecomManager} uses registered {@link PhoneAccount}s to present the user with
44 * alternative options when placing a phone call. When building a {@link PhoneAccount}, the app
Brian Attwellad147f42014-12-19 11:37:16 -080045 * should supply a valid {@link PhoneAccountHandle} that references the connection service
Santos Cordon32c65a52014-10-27 14:57:49 -070046 * implementation Telecom will use to interact with the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -070047 */
Yorke Lee400470f2015-05-12 13:31:25 -070048public final class PhoneAccount implements Parcelable {
Ihab Awad94cf4bf2014-07-17 11:21:19 -070049
50 /**
Hall Liu4bb53ec2020-09-29 15:15:24 -070051 * Integer extra which determines the order in which {@link PhoneAccount}s are sorted
Hall Liu2ef04112020-09-14 18:34:10 -070052 *
53 * This is an extras key set via {@link Builder#setExtras} which determines the order in which
54 * {@link PhoneAccount}s from the same {@link ConnectionService} are sorted. The accounts
Hall Liu4bb53ec2020-09-29 15:15:24 -070055 * are sorted in ascending order by this key, and this ordering is used to
Hall Liu2ef04112020-09-14 18:34:10 -070056 * determine priority when a call can be placed via multiple accounts.
Hall Liu221f8042020-09-23 15:36:58 -070057 *
58 * When multiple {@link PhoneAccount}s are supplied with the same sort order key, no ordering is
59 * guaranteed between those {@link PhoneAccount}s. Additionally, no ordering is guaranteed
60 * between {@link PhoneAccount}s that do not supply this extra, and all such accounts
61 * will be sorted after the accounts that do supply this extra.
62 *
63 * An example of a sort order key is slot index (see {@link TelephonyManager#getSlotIndex()}),
64 * which is the one used by the cell Telephony stack.
Srikanth Chintala62428402017-03-27 19:27:52 +053065 * @hide
66 */
Hall Liu2ef04112020-09-14 18:34:10 -070067 @SystemApi
Srikanth Chintala62428402017-03-27 19:27:52 +053068 public static final String EXTRA_SORT_ORDER =
69 "android.telecom.extra.SORT_ORDER";
70
71 /**
72 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
Tyler Gunnd426b202015-10-13 13:33:53 -070073 * maximum permitted length of a call subject specified via the
74 * {@link TelecomManager#EXTRA_CALL_SUBJECT} extra on an
75 * {@link android.content.Intent#ACTION_CALL} intent. Ultimately a {@link ConnectionService} is
76 * responsible for enforcing the maximum call subject length when sending the message, however
77 * this extra is provided so that the user interface can proactively limit the length of the
78 * call subject as the user types it.
79 */
80 public static final String EXTRA_CALL_SUBJECT_MAX_LENGTH =
81 "android.telecom.extra.CALL_SUBJECT_MAX_LENGTH";
82
83 /**
84 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
85 * character encoding to be used when determining the length of messages.
86 * The user interface can use this when determining the number of characters the user may type
87 * in a call subject. If empty-string, the call subject message size limit will be enforced on
88 * a 1:1 basis. That is, each character will count towards the messages size limit as a single
89 * character. If a character encoding is specified, the message size limit will be based on the
90 * number of bytes in the message per the specified encoding. See
91 * {@link #EXTRA_CALL_SUBJECT_MAX_LENGTH} for more information on the call subject maximum
92 * length.
93 */
94 public static final String EXTRA_CALL_SUBJECT_CHARACTER_ENCODING =
95 "android.telecom.extra.CALL_SUBJECT_CHARACTER_ENCODING";
96
Hall Liue576fc42020-01-22 17:17:13 -080097 /**
98 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
99 * indicates that all calls from this {@link PhoneAccount} should be treated as VoIP calls
Hall Liu2ef04112020-09-14 18:34:10 -0700100 * rather than cellular calls by the Telecom audio handling logic.
Srikanth Chintalaf77d4a12017-04-03 18:08:14 +0530101 */
102 public static final String EXTRA_ALWAYS_USE_VOIP_AUDIO_MODE =
103 "android.telecom.extra.ALWAYS_USE_VOIP_AUDIO_MODE";
104
Tyler Gunnd426b202015-10-13 13:33:53 -0700105 /**
Tyler Gunn8bf76572017-04-06 15:30:08 -0700106 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
107 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
Sanket Padawea8eddd42017-11-03 11:07:35 -0700108 * connection (see {@code android.telecom.Call#handoverTo()}) to this {@link PhoneAccount} from
109 * a {@link PhoneAccount} specifying {@link #EXTRA_SUPPORTS_HANDOVER_FROM}.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700110 * <p>
111 * A handover request is initiated by the user from the default dialer app to indicate a desire
112 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700113 */
114 public static final String EXTRA_SUPPORTS_HANDOVER_TO =
115 "android.telecom.extra.SUPPORTS_HANDOVER_TO";
116
117 /**
118 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Ta-wei Yen9d20d982017-06-02 11:07:07 -0700119 * indicates whether this {@link PhoneAccount} supports using a fallback if video calling is
120 * not available. This extra is for device level support, {@link
121 * android.telephony.CarrierConfigManager#KEY_ALLOW_VIDEO_CALLING_FALLBACK_BOOL} should also
122 * be checked to ensure it is not disabled by individual carrier.
123 *
124 * @hide
125 */
126 public static final String EXTRA_SUPPORTS_VIDEO_CALLING_FALLBACK =
127 "android.telecom.extra.SUPPORTS_VIDEO_CALLING_FALLBACK";
128
129 /**
130 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Tyler Gunn8bf76572017-04-06 15:30:08 -0700131 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
132 * connection from this {@link PhoneAccount} to another {@link PhoneAccount}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700133 * (see {@code android.telecom.Call#handoverTo()}) which specifies
Tyler Gunn8bf76572017-04-06 15:30:08 -0700134 * {@link #EXTRA_SUPPORTS_HANDOVER_TO}.
135 * <p>
136 * A handover request is initiated by the user from the default dialer app to indicate a desire
137 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700138 */
139 public static final String EXTRA_SUPPORTS_HANDOVER_FROM =
140 "android.telecom.extra.SUPPORTS_HANDOVER_FROM";
141
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700142
143 /**
144 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
145 * indicates whether a Self-Managed {@link PhoneAccount} should log its calls to the call log.
Brad Ebingerbb1a55f2017-06-26 13:26:14 -0700146 * Self-Managed {@link PhoneAccount}s are responsible for their own notifications, so the system
147 * will not create a notification when a missed call is logged.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700148 * <p>
149 * By default, Self-Managed {@link PhoneAccount}s do not log their calls to the call log.
150 * Setting this extra to {@code true} provides a means for them to log their calls.
Tyler Gunn2155c4c2018-04-05 09:43:41 -0700151 * <p>
152 * Note: Only calls where the {@link Call.Details#getHandle()} {@link Uri#getScheme()} is
153 * {@link #SCHEME_SIP} or {@link #SCHEME_TEL} will be logged at the current time.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700154 */
155 public static final String EXTRA_LOG_SELF_MANAGED_CALLS =
156 "android.telecom.extra.LOG_SELF_MANAGED_CALLS";
157
Tyler Gunn8bf76572017-04-06 15:30:08 -0700158 /**
Tyler Gunnacdb6862018-01-29 14:30:52 -0800159 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
160 * indicates whether calls for a {@link PhoneAccount} should generate a "call recording tone"
161 * when the user is recording audio on the device.
162 * <p>
163 * The call recording tone is played over the telephony audio stream so that the remote party
164 * has an audible indication that it is possible their call is being recorded using a call
165 * recording app on the device.
166 * <p>
167 * This extra only has an effect for calls placed via Telephony (e.g.
168 * {@link #CAPABILITY_SIM_SUBSCRIPTION}).
169 * <p>
170 * The call recording tone is a 1400 hz tone which repeats every 15 seconds while recording is
171 * in progress.
172 * @hide
173 */
Hall Liu2ef04112020-09-14 18:34:10 -0700174 @SystemApi
Tyler Gunnacdb6862018-01-29 14:30:52 -0800175 public static final String EXTRA_PLAY_CALL_RECORDING_TONE =
176 "android.telecom.extra.PLAY_CALL_RECORDING_TONE";
177
178 /**
Sean Kelley4d3c1782018-05-22 14:35:27 -0700179 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()} which
180 * indicates whether calls for a {@link PhoneAccount} should skip call filtering.
181 * <p>
182 * If not specified, this will default to false; all calls will undergo call filtering unless
183 * specifically exempted (e.g. {@link Connection#PROPERTY_EMERGENCY_CALLBACK_MODE}.) However,
184 * this may be used to skip call filtering when it has already been performed on another device.
185 * @hide
186 */
187 public static final String EXTRA_SKIP_CALL_FILTERING =
188 "android.telecom.extra.SKIP_CALL_FILTERING";
189
190 /**
Ihab Awadf8b69882014-07-25 15:14:01 -0700191 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
192 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
193 * will be allowed to manage phone calls including using its own proprietary phone-call
194 * implementation (like VoIP calling) to make calls instead of the telephony stack.
195 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700196 * When a user opts to place a call using the SIM-based telephony stack, the
197 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
198 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700199 * <p>
200 * See {@link #getCapabilities}
201 */
Ihab Awadf8b69882014-07-25 15:14:01 -0700202 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700203
204 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700205 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -0700206 * traditional SIM-based telephony calls. This account will be treated as a distinct method
207 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -0700208 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -0700209 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700210 * <p>
211 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700212 * <p>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700213 */
214 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
215
Ihab Awad7522bbd62014-07-18 15:53:17 -0700216 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700217 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -0700218 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -0700219 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700220 * Only the Android framework can register a {@code PhoneAccount} having this capability.
221 * <p>
222 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -0700223 */
224 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
225
Ihab Awadf8b69882014-07-25 15:14:01 -0700226 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800227 * Flag indicating that this {@code PhoneAccount} is currently able to place video calls.
228 * <p>
229 * See also {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING} which indicates whether the
230 * {@code PhoneAccount} supports placing video calls.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700231 * <p>
232 * See {@link #getCapabilities}
Ihab Awadf8b69882014-07-25 15:14:01 -0700233 */
234 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
235
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700236 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700237 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
238 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
239 * <p>
240 * See {@link #getCapabilities}
241 */
242 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
243
244 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800245 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
246 * should only be used by system apps (and will be ignored for all other apps trying to use it).
247 * <p>
248 * See {@link #getCapabilities}
249 * @hide
250 */
Brian Attwellad147f42014-12-19 11:37:16 -0800251 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800252 public static final int CAPABILITY_MULTI_USER = 0x20;
253
254 /**
Tyler Gunn65a3d342015-07-27 16:06:16 -0700255 * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a
256 * caller is able to specify a short subject line for an outgoing call. A capable receiving
257 * device displays the call subject on the incoming call screen.
258 * <p>
259 * See {@link #getCapabilities}
260 */
261 public static final int CAPABILITY_CALL_SUBJECT = 0x40;
262
263 /**
Bryce Leeb96d89c2015-10-14 16:48:40 -0700264 * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls.
265 * <p>
266 * See {@link #getCapabilities}
267 * @hide
268 */
Hall Liu2ef04112020-09-14 18:34:10 -0700269 @SystemApi
Bryce Leeb96d89c2015-10-14 16:48:40 -0700270 public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80;
271
272 /**
Tyler Gunn9a365752015-12-09 15:00:18 -0800273 * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a
274 * number relies on presence. Should only be set if the {@code PhoneAccount} also has
275 * {@link #CAPABILITY_VIDEO_CALLING}.
276 * <p>
277 * When set, the {@link ConnectionService} is responsible for toggling the
278 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the
279 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether
280 * a contact's phone number supports video calling.
281 * <p>
282 * See {@link #getCapabilities}
283 */
284 public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100;
285
286 /**
Tyler Gunncee9ea62016-03-24 11:45:43 -0700287 * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed.
288 * <p>
289 * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will
290 * convert all outgoing video calls to emergency numbers to audio-only.
291 * @hide
292 */
Hall Liu2ef04112020-09-14 18:34:10 -0700293 @SystemApi
Tyler Gunncee9ea62016-03-24 11:45:43 -0700294 public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200;
295
296 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800297 * Flag indicating that this {@link PhoneAccount} supports video calling.
298 * This is not an indication that the {@link PhoneAccount} is currently able to make a video
299 * call, but rather that it has the ability to make video calls (but not necessarily at this
300 * time).
301 * <p>
302 * Whether a {@link PhoneAccount} can make a video call is ultimately controlled by
303 * {@link #CAPABILITY_VIDEO_CALLING}, which indicates whether the {@link PhoneAccount} is
304 * currently capable of making a video call. Consider a case where, for example, a
305 * {@link PhoneAccount} supports making video calls (e.g.
306 * {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING}), but a current lack of network connectivity
307 * prevents video calls from being made (e.g. {@link #CAPABILITY_VIDEO_CALLING}).
308 * <p>
309 * See {@link #getCapabilities}
310 */
311 public static final int CAPABILITY_SUPPORTS_VIDEO_CALLING = 0x400;
312
313 /**
Tyler Gunnf5035432017-01-09 09:43:12 -0800314 * Flag indicating that this {@link PhoneAccount} is responsible for managing its own
315 * {@link Connection}s. This type of {@link PhoneAccount} is ideal for use with standalone
316 * calling apps which do not wish to use the default phone app for {@link Connection} UX,
317 * but which want to leverage the call and audio routing capabilities of the Telecom framework.
318 * <p>
319 * When set, {@link Connection}s created by the self-managed {@link ConnectionService} will not
320 * be surfaced to implementations of the {@link InCallService} API. Thus it is the
321 * responsibility of a self-managed {@link ConnectionService} to provide a user interface for
322 * its {@link Connection}s.
323 * <p>
324 * Self-managed {@link Connection}s will, however, be displayed on connected Bluetooth devices.
325 */
326 public static final int CAPABILITY_SELF_MANAGED = 0x800;
327
328 /**
Hall Liu95d55872017-01-25 17:12:49 -0800329 * Flag indicating that this {@link PhoneAccount} is capable of making a call with an
330 * RTT (Real-time text) session.
331 * When set, Telecom will attempt to open an RTT session on outgoing calls that specify
332 * that they should be placed with an RTT session , and the in-call app will be displayed
333 * with text entry fields for RTT. Likewise, the in-call app can request that an RTT
334 * session be opened during a call if this bit is set.
335 */
336 public static final int CAPABILITY_RTT = 0x1000;
337
Brad Ebinger3636d742019-05-21 15:28:19 -0700338 /**
339 * Flag indicating that this {@link PhoneAccount} is the preferred SIM subscription for
Hall Liu2ef04112020-09-14 18:34:10 -0700340 * emergency calls. A {@link PhoneAccount} that sets this capability must also
Brad Ebinger3636d742019-05-21 15:28:19 -0700341 * set the {@link #CAPABILITY_SIM_SUBSCRIPTION} and {@link #CAPABILITY_PLACE_EMERGENCY_CALLS}
Hall Liu2ef04112020-09-14 18:34:10 -0700342 * capabilities. There must only be one emergency preferred {@link PhoneAccount} on the device.
Brad Ebinger3636d742019-05-21 15:28:19 -0700343 * <p>
344 * When set, Telecom will prefer this {@link PhoneAccount} over others for emergency calling,
345 * even if the emergency call was placed with a specific {@link PhoneAccount} set using the
346 * extra{@link TelecomManager#EXTRA_PHONE_ACCOUNT_HANDLE} in
347 * {@link Intent#ACTION_CALL_EMERGENCY} or {@link TelecomManager#placeCall(Uri, Bundle)}.
348 *
349 * @hide
350 */
Hall Liu2ef04112020-09-14 18:34:10 -0700351 @SystemApi
Brad Ebinger3636d742019-05-21 15:28:19 -0700352 public static final int CAPABILITY_EMERGENCY_PREFERRED = 0x2000;
353
Ravi Paluri80aa2142019-12-02 11:57:37 +0530354 /**
355 * An adhoc conference call is established by providing a list of addresses to
356 * {@code TelecomManager#startConference(List<Uri>, int videoState)} where the
357 * {@link ConnectionService} is responsible for connecting all indicated participants
358 * to a conference simultaneously.
359 * This is in contrast to conferences formed by merging calls together (e.g. using
360 * {@link android.telecom.Call#mergeConference()}).
361 */
362 public static final int CAPABILITY_ADHOC_CONFERENCE_CALLING = 0x4000;
363
Shuo Qiand24aea32020-11-24 15:08:49 -0800364 /**
365 * Flag indicating whether this {@link PhoneAccount} is capable of supporting the call composer
366 * functionality for enriched calls.
367 */
368 public static final int CAPABILITY_CALL_COMPOSER = 0x8000;
369
370 /* NEXT CAPABILITY: 0x10000 */
Hall Liu95d55872017-01-25 17:12:49 -0800371
372 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700373 * URI scheme for telephone number URIs.
374 */
375 public static final String SCHEME_TEL = "tel";
376
377 /**
378 * URI scheme for voicemail URIs.
379 */
380 public static final String SCHEME_VOICEMAIL = "voicemail";
381
382 /**
383 * URI scheme for SIP URIs.
384 */
385 public static final String SCHEME_SIP = "sip";
386
Nancy Chen3ace54b2014-10-22 17:45:26 -0700387 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800388 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700389 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700390 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800391 public static final int NO_ICON_TINT = 0;
392
393 /**
394 * Indicating no hightlight color is set.
395 */
396 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700397
Ihab Awad476cc832014-11-03 09:47:51 -0800398 /**
399 * Indicating no resource ID is set.
400 */
401 public static final int NO_RESOURCE_ID = -1;
402
Evan Charlton8c8a0622014-07-20 12:31:00 -0700403 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700404 private final Uri mAddress;
405 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700406 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800407 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700408 private final CharSequence mLabel;
409 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700410 private final List<String> mSupportedUriSchemes;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800411 private final int mSupportedAudioRoutes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700412 private final Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700413 private final Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700414 private boolean mIsEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700415 private String mGroupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700416
Tyler Gunn3b347812018-08-24 14:17:05 -0700417 @Override
418 public boolean equals(Object o) {
419 if (this == o) return true;
420 if (o == null || getClass() != o.getClass()) return false;
421 PhoneAccount that = (PhoneAccount) o;
422 return mCapabilities == that.mCapabilities &&
423 mHighlightColor == that.mHighlightColor &&
424 mSupportedAudioRoutes == that.mSupportedAudioRoutes &&
425 mIsEnabled == that.mIsEnabled &&
426 Objects.equals(mAccountHandle, that.mAccountHandle) &&
427 Objects.equals(mAddress, that.mAddress) &&
428 Objects.equals(mSubscriptionAddress, that.mSubscriptionAddress) &&
429 Objects.equals(mLabel, that.mLabel) &&
430 Objects.equals(mShortDescription, that.mShortDescription) &&
431 Objects.equals(mSupportedUriSchemes, that.mSupportedUriSchemes) &&
432 areBundlesEqual(mExtras, that.mExtras) &&
433 Objects.equals(mGroupId, that.mGroupId);
434 }
435
436 @Override
437 public int hashCode() {
438 return Objects.hash(mAccountHandle, mAddress, mSubscriptionAddress, mCapabilities,
439 mHighlightColor, mLabel, mShortDescription, mSupportedUriSchemes,
440 mSupportedAudioRoutes,
441 mExtras, mIsEnabled, mGroupId);
442 }
443
Santos Cordon32c65a52014-10-27 14:57:49 -0700444 /**
445 * Helper class for creating a {@link PhoneAccount}.
446 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700447 public static class Builder {
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800448
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700449 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700450 private Uri mAddress;
451 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700452 private int mCapabilities;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800453 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800454 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700455 private CharSequence mLabel;
456 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700457 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700458 private Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700459 private Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700460 private boolean mIsEnabled = false;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700461 private String mGroupId = "";
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700462
Santos Cordon32c65a52014-10-27 14:57:49 -0700463 /**
464 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
465 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700466 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
467 this.mAccountHandle = accountHandle;
468 this.mLabel = label;
469 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700470
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700471 /**
472 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
473 * {@link PhoneAccount}.
474 *
475 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
476 */
477 public Builder(PhoneAccount phoneAccount) {
478 mAccountHandle = phoneAccount.getAccountHandle();
479 mAddress = phoneAccount.getAddress();
480 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
481 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800482 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700483 mLabel = phoneAccount.getLabel();
484 mShortDescription = phoneAccount.getShortDescription();
485 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700486 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc02015-05-08 13:52:09 -0700487 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunnd426b202015-10-13 13:33:53 -0700488 mExtras = phoneAccount.getExtras();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700489 mGroupId = phoneAccount.getGroupId();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800490 mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700491 }
492
Santos Cordon32c65a52014-10-27 14:57:49 -0700493 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700494 * Sets the label. See {@link PhoneAccount#getLabel()}.
495 *
496 * @param label The label of the phone account.
497 * @return The builder.
498 * @hide
499 */
500 public Builder setLabel(CharSequence label) {
501 this.mLabel = label;
502 return this;
503 }
504
505 /**
Santos Cordon32c65a52014-10-27 14:57:49 -0700506 * Sets the address. See {@link PhoneAccount#getAddress}.
507 *
508 * @param value The address of the phone account.
509 * @return The builder.
510 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700511 public Builder setAddress(Uri value) {
512 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700513 return this;
514 }
515
Santos Cordon32c65a52014-10-27 14:57:49 -0700516 /**
517 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
518 *
519 * @param value The subscription address.
520 * @return The builder.
521 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700522 public Builder setSubscriptionAddress(Uri value) {
523 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700524 return this;
525 }
526
Santos Cordon32c65a52014-10-27 14:57:49 -0700527 /**
528 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
529 *
530 * @param value The capabilities to set.
531 * @return The builder.
532 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700533 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700534 this.mCapabilities = value;
535 return this;
536 }
537
Santos Cordon32c65a52014-10-27 14:57:49 -0700538 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700539 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700540 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700541 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700542 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700543 public Builder setIcon(Icon icon) {
544 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700545 return this;
546 }
547
548 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800549 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700550 *
Ihab Awad476cc832014-11-03 09:47:51 -0800551 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700552 * @return The builder.
553 */
Ihab Awad476cc832014-11-03 09:47:51 -0800554 public Builder setHighlightColor(int value) {
555 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700556 return this;
557 }
558
Santos Cordon32c65a52014-10-27 14:57:49 -0700559 /**
560 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
561 *
562 * @param value The short description.
563 * @return The builder.
564 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700565 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700566 this.mShortDescription = value;
567 return this;
568 }
569
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700570 /**
571 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
572 *
573 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700574 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700575 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700576 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700577 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
578 this.mSupportedUriSchemes.add(uriScheme);
579 }
580 return this;
581 }
582
583 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700584 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700585 *
586 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700587 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700588 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700589 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
590 mSupportedUriSchemes.clear();
591
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700592 if (uriSchemes != null && !uriSchemes.isEmpty()) {
593 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700594 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700595 }
596 }
597 return this;
598 }
599
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700600 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700601 * Specifies the extras associated with the {@link PhoneAccount}.
602 * <p>
603 * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer},
604 * and {@link Boolean}. Extras which are not of these types are ignored.
605 *
606 * @param extras
607 * @return
608 */
609 public Builder setExtras(Bundle extras) {
610 mExtras = extras;
611 return this;
612 }
613
614 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700615 * Sets the enabled state of the phone account.
616 *
617 * @param isEnabled The enabled state.
618 * @return The builder.
619 * @hide
620 */
621 public Builder setIsEnabled(boolean isEnabled) {
622 mIsEnabled = isEnabled;
623 return this;
624 }
625
626 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700627 * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is
628 * registered to Telecom, it will replace another {@link PhoneAccount} that is already
629 * registered in Telecom and take on the current user defaults and enabled status. There can
630 * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a
631 * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only
632 * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced.
Tyler Gunn5567d742019-10-31 13:04:37 -0700633 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -0800634 * Note: This is an API specific to the Telephony stack; the group Id will be ignored for
635 * callers not holding the correct permission.
Tyler Gunn5567d742019-10-31 13:04:37 -0700636 *
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700637 * @param groupId The group Id of the {@link PhoneAccount} that will replace any other
638 * registered {@link PhoneAccount} in Telecom with the same Group Id.
639 * @return The builder
640 * @hide
641 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700642 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -0800643 @RequiresPermission(MODIFY_PHONE_STATE)
Tyler Gunn5567d742019-10-31 13:04:37 -0700644 public @NonNull Builder setGroupId(@NonNull String groupId) {
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700645 if (groupId != null) {
646 mGroupId = groupId;
647 } else {
648 mGroupId = "";
649 }
650 return this;
651 }
652
653 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800654 * Sets the audio routes supported by this {@link PhoneAccount}.
655 *
656 * @param routes bit mask of available routes.
657 * @return The builder.
658 * @hide
659 */
660 public Builder setSupportedAudioRoutes(int routes) {
661 mSupportedAudioRoutes = routes;
662 return this;
663 }
664
665 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700666 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
667 *
668 * @return The {@link PhoneAccount}.
669 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700670 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700671 // If no supported URI schemes were defined, assume "tel" is supported.
672 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700673 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700674 }
675
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700676 return new PhoneAccount(
677 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700678 mAddress,
679 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700680 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700681 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800682 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700683 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700684 mShortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700685 mSupportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700686 mExtras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800687 mSupportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700688 mIsEnabled,
689 mGroupId);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700690 }
691 }
692
693 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700694 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700695 Uri address,
696 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700697 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700698 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800699 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700700 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700701 CharSequence shortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700702 List<String> supportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700703 Bundle extras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800704 int supportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700705 boolean isEnabled,
706 String groupId) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700707 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700708 mAddress = address;
709 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700710 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700711 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800712 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700713 mLabel = label;
714 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700715 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700716 mExtras = extras;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800717 mSupportedAudioRoutes = supportedAudioRoutes;
Santos Cordon91371dc02015-05-08 13:52:09 -0700718 mIsEnabled = isEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700719 mGroupId = groupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700720 }
721
Andrew Lee3085a6c2014-09-04 10:59:13 -0700722 public static Builder builder(
723 PhoneAccountHandle accountHandle,
724 CharSequence label) {
725 return new Builder(accountHandle, label);
726 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700727
Ihab Awad807fe0a2014-07-09 12:30:52 -0700728 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700729 * Returns a builder initialized with the current {@link PhoneAccount} instance.
730 *
731 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700732 */
733 public Builder toBuilder() { return new Builder(this); }
734
735 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700736 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700737 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700738 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700739 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700740 public PhoneAccountHandle getAccountHandle() {
741 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700742 }
743
744 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700745 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700746 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700747 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700748 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700749 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700750 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700751 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700752 public Uri getAddress() {
753 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700754 }
755
756 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700757 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700758 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700759 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000760 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
761 * has been used to alter the callback number.
762 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700763 *
764 * @return The subscription number, suitable for display to the user.
765 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700766 public Uri getSubscriptionAddress() {
767 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700768 }
769
770 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700771 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700772 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700773 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700774 */
775 public int getCapabilities() {
776 return mCapabilities;
777 }
778
779 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700780 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
781 * bit mask.
782 *
783 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700784 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700785 */
786 public boolean hasCapabilities(int capability) {
787 return (mCapabilities & capability) == capability;
788 }
789
790 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800791 * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask.
792 *
793 * @param route The routes to check.
794 * @return {@code true} if the phone account has the routes.
795 * @hide
796 */
797 public boolean hasAudioRoutes(int routes) {
798 return (mSupportedAudioRoutes & routes) == routes;
799 }
800
801 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700802 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700803 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700804 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700805 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700806 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700807 return mLabel;
808 }
809
810 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700811 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700812 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700813 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700814 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700815 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700816 return mShortDescription;
817 }
818
819 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700820 * The URI schemes supported by this {@code PhoneAccount}.
821 *
822 * @return The URI schemes.
823 */
824 public List<String> getSupportedUriSchemes() {
825 return mSupportedUriSchemes;
826 }
827
828 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700829 * The extras associated with this {@code PhoneAccount}.
830 * <p>
831 * A {@link ConnectionService} may provide implementation specific information about the
832 * {@link PhoneAccount} via the extras.
833 *
834 * @return The extras.
835 */
836 public Bundle getExtras() {
837 return mExtras;
838 }
839
840 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800841 * The audio routes supported by this {@code PhoneAccount}.
842 *
843 * @hide
844 */
845 public int getSupportedAudioRoutes() {
846 return mSupportedAudioRoutes;
847 }
848
849 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700850 * The icon to represent this {@code PhoneAccount}.
851 *
852 * @return The icon.
853 */
854 public Icon getIcon() {
855 return mIcon;
856 }
857
858 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700859 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
860 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc02015-05-08 13:52:09 -0700861 *
Santos Cordon895d4b82015-06-25 16:41:48 -0700862 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc02015-05-08 13:52:09 -0700863 */
864 public boolean isEnabled() {
865 return mIsEnabled;
866 }
867
868 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700869 * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an
870 * empty {@link String} if the {@link PhoneAccount} is not in a group. If this
871 * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered
872 * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced,
873 * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}.
874 * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced.
875 *
876 * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group.
877 * @hide
878 */
879 public String getGroupId() {
880 return mGroupId;
881 }
882
883 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700884 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700885 * scheme.
886 *
887 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700888 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700889 * specified URI scheme.
890 */
891 public boolean supportsUriScheme(String uriScheme) {
892 if (mSupportedUriSchemes == null || uriScheme == null) {
893 return false;
894 }
895
896 for (String scheme : mSupportedUriSchemes) {
897 if (scheme != null && scheme.equals(uriScheme)) {
898 return true;
899 }
900 }
901 return false;
902 }
903
904 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800905 * A highlight color to use in displaying information about this {@code PhoneAccount}.
906 *
907 * @return A hexadecimal color value.
908 */
909 public int getHighlightColor() {
910 return mHighlightColor;
911 }
912
Santos Cordon91371dc02015-05-08 13:52:09 -0700913 /**
914 * Sets the enabled state of the phone account.
915 * @hide
916 */
917 public void setIsEnabled(boolean isEnabled) {
918 mIsEnabled = isEnabled;
919 }
920
Tyler Gunnf5035432017-01-09 09:43:12 -0800921 /**
922 * @return {@code true} if the {@link PhoneAccount} is self-managed, {@code false} otherwise.
923 * @hide
924 */
925 public boolean isSelfManaged() {
926 return (mCapabilities & CAPABILITY_SELF_MANAGED) == CAPABILITY_SELF_MANAGED;
927 }
928
Ihab Awad807fe0a2014-07-09 12:30:52 -0700929 //
930 // Parcelable implementation
931 //
932
933 @Override
934 public int describeContents() {
935 return 0;
936 }
937
938 @Override
939 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800940 if (mAccountHandle == null) {
941 out.writeInt(0);
942 } else {
943 out.writeInt(1);
944 mAccountHandle.writeToParcel(out, flags);
945 }
946 if (mAddress == null) {
947 out.writeInt(0);
948 } else {
949 out.writeInt(1);
950 mAddress.writeToParcel(out, flags);
951 }
952 if (mSubscriptionAddress == null) {
953 out.writeInt(0);
954 } else {
955 out.writeInt(1);
956 mSubscriptionAddress.writeToParcel(out, flags);
957 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700958 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800959 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700960 out.writeCharSequence(mLabel);
961 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800962 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc02015-05-08 13:52:09 -0700963
Santos Cordoncad84a22015-05-13 11:17:25 -0700964 if (mIcon == null) {
965 out.writeInt(0);
966 } else {
967 out.writeInt(1);
968 mIcon.writeToParcel(out, flags);
969 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700970 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Tyler Gunnef829ec2015-10-08 09:46:23 -0700971 out.writeBundle(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700972 out.writeString(mGroupId);
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800973 out.writeInt(mSupportedAudioRoutes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700974 }
975
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700976 public static final @android.annotation.NonNull Creator<PhoneAccount> CREATOR
Evan Charlton8c8a0622014-07-20 12:31:00 -0700977 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700978 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700979 public PhoneAccount createFromParcel(Parcel in) {
980 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700981 }
982
983 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700984 public PhoneAccount[] newArray(int size) {
985 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700986 }
987 };
988
Evan Charlton8c8a0622014-07-20 12:31:00 -0700989 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800990 if (in.readInt() > 0) {
991 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
992 } else {
993 mAccountHandle = null;
994 }
995 if (in.readInt() > 0) {
996 mAddress = Uri.CREATOR.createFromParcel(in);
997 } else {
998 mAddress = null;
999 }
1000 if (in.readInt() > 0) {
1001 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
1002 } else {
1003 mSubscriptionAddress = null;
1004 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -07001005 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -08001006 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -07001007 mLabel = in.readCharSequence();
1008 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -08001009 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -07001010 if (in.readInt() > 0) {
1011 mIcon = Icon.CREATOR.createFromParcel(in);
1012 } else {
1013 mIcon = null;
1014 }
Santos Cordon91371dc02015-05-08 13:52:09 -07001015 mIsEnabled = in.readByte() == 1;
Tyler Gunnef829ec2015-10-08 09:46:23 -07001016 mExtras = in.readBundle();
Brad Ebinger7298f3b2016-06-10 17:19:42 -07001017 mGroupId = in.readString();
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001018 mSupportedAudioRoutes = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -07001019 }
Tyler Gunn76c01a52014-09-30 14:47:51 -07001020
1021 @Override
1022 public String toString() {
Santos Cordon91371dc02015-05-08 13:52:09 -07001023 StringBuilder sb = new StringBuilder().append("[[")
1024 .append(mIsEnabled ? 'X' : ' ')
1025 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -07001026 .append(mAccountHandle)
1027 .append(" Capabilities: ")
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001028 .append(capabilitiesToString())
1029 .append(" Audio Routes: ")
1030 .append(audioRoutesToString())
Tyler Gunn76c01a52014-09-30 14:47:51 -07001031 .append(" Schemes: ");
1032 for (String scheme : mSupportedUriSchemes) {
1033 sb.append(scheme)
1034 .append(" ");
1035 }
Tyler Gunnef829ec2015-10-08 09:46:23 -07001036 sb.append(" Extras: ");
Tyler Gunn25ed2d72015-10-05 14:14:38 -07001037 sb.append(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -07001038 sb.append(" GroupId: ");
1039 sb.append(Log.pii(mGroupId));
Tyler Gunn76c01a52014-09-30 14:47:51 -07001040 sb.append("]");
1041 return sb.toString();
1042 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001043
1044 /**
1045 * Generates a string representation of a capabilities bitmask.
1046 *
Tyler Gunn3e122f72016-01-11 19:25:00 -08001047 * @return String representation of the capabilities bitmask.
Tyler Gunn1847b4e2018-11-09 08:43:02 -08001048 * @hide
Tyler Gunn3e122f72016-01-11 19:25:00 -08001049 */
Tyler Gunn1847b4e2018-11-09 08:43:02 -08001050 public String capabilitiesToString() {
Tyler Gunn3e122f72016-01-11 19:25:00 -08001051 StringBuilder sb = new StringBuilder();
Tyler Gunnf5035432017-01-09 09:43:12 -08001052 if (hasCapabilities(CAPABILITY_SELF_MANAGED)) {
1053 sb.append("SelfManaged ");
1054 }
Tyler Gunn58cbd7a2016-11-11 11:31:28 -08001055 if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) {
1056 sb.append("SuppVideo ");
1057 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001058 if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) {
1059 sb.append("Video ");
1060 }
1061 if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
1062 sb.append("Presence ");
1063 }
1064 if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) {
1065 sb.append("CallProvider ");
1066 }
1067 if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) {
1068 sb.append("CallSubject ");
1069 }
1070 if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) {
1071 sb.append("ConnectionMgr ");
1072 }
1073 if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) {
1074 sb.append("EmergOnly ");
1075 }
1076 if (hasCapabilities(CAPABILITY_MULTI_USER)) {
1077 sb.append("MultiUser ");
1078 }
1079 if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) {
1080 sb.append("PlaceEmerg ");
1081 }
Brad Ebinger3636d742019-05-21 15:28:19 -07001082 if (hasCapabilities(CAPABILITY_EMERGENCY_PREFERRED)) {
1083 sb.append("EmerPrefer ");
1084 }
Tyler Gunncee9ea62016-03-24 11:45:43 -07001085 if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
1086 sb.append("EmergVideo ");
1087 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001088 if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) {
1089 sb.append("SimSub ");
1090 }
Hall Liu47ed6202017-11-20 16:25:39 -08001091 if (hasCapabilities(CAPABILITY_RTT)) {
1092 sb.append("Rtt");
1093 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05301094 if (hasCapabilities(CAPABILITY_ADHOC_CONFERENCE_CALLING)) {
1095 sb.append("AdhocConf");
1096 }
Shuo Qiand24aea32020-11-24 15:08:49 -08001097 if (hasCapabilities(CAPABILITY_CALL_COMPOSER)) {
1098 sb.append("CallComposer ");
1099 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001100 return sb.toString();
1101 }
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001102
1103 private String audioRoutesToString() {
1104 StringBuilder sb = new StringBuilder();
1105
1106 if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) {
1107 sb.append("B");
1108 }
1109 if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) {
1110 sb.append("E");
1111 }
1112 if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) {
1113 sb.append("S");
1114 }
1115 if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) {
1116 sb.append("W");
1117 }
1118
1119 return sb.toString();
1120 }
Tyler Gunn3b347812018-08-24 14:17:05 -07001121
1122 /**
1123 * Determines if two {@link Bundle}s are equal.
1124 * @param extras First {@link Bundle} to check.
1125 * @param newExtras {@link Bundle} to compare against.
1126 * @return {@code true} if the {@link Bundle}s are equal, {@code false} otherwise.
1127 */
1128 private static boolean areBundlesEqual(Bundle extras, Bundle newExtras) {
1129 if (extras == null || newExtras == null) {
1130 return extras == newExtras;
1131 }
1132
1133 if (extras.size() != newExtras.size()) {
1134 return false;
1135 }
1136
1137 for(String key : extras.keySet()) {
1138 if (key != null) {
1139 final Object value = extras.get(key);
1140 final Object newValue = newExtras.get(key);
1141 if (!Objects.equals(value, newValue)) {
1142 return false;
1143 }
1144 }
1145 }
1146 return true;
1147 }
Ihab Awad807fe0a2014-07-09 12:30:52 -07001148}