blob: 4a3561b5d509eda0300ff18e95078ea71c2adccd [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;
Tyler Gunn5567d742019-10-31 13:04:37 -070024import android.annotation.TestApi;
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;
Hall Liu221f8042020-09-23 15:36:58 -070031import android.telephony.TelephonyManager;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070032import android.text.TextUtils;
Ihab Awad807fe0a2014-07-09 12:30:52 -070033
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070034import java.util.ArrayList;
35import java.util.Collections;
36import java.util.List;
Tyler Gunn3b347812018-08-24 14:17:05 -070037import java.util.Objects;
Ihab Awad807fe0a2014-07-09 12:30:52 -070038
39/**
Santos Cordon32c65a52014-10-27 14:57:49 -070040 * Represents a distinct method to place or receive a phone call. Apps which can place calls and
41 * 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 -080042 * this class and register it with the system using {@link TelecomManager}.
Santos Cordon32c65a52014-10-27 14:57:49 -070043 * <p>
44 * {@link TelecomManager} uses registered {@link PhoneAccount}s to present the user with
45 * alternative options when placing a phone call. When building a {@link PhoneAccount}, the app
Brian Attwellad147f42014-12-19 11:37:16 -080046 * should supply a valid {@link PhoneAccountHandle} that references the connection service
Santos Cordon32c65a52014-10-27 14:57:49 -070047 * implementation Telecom will use to interact with the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -070048 */
Yorke Lee400470f2015-05-12 13:31:25 -070049public final class PhoneAccount implements Parcelable {
Ihab Awad94cf4bf2014-07-17 11:21:19 -070050
51 /**
Hall Liu2ef04112020-09-14 18:34:10 -070052 * String extra which determines the order in which {@link PhoneAccount}s are sorted
53 *
54 * This is an extras key set via {@link Builder#setExtras} which determines the order in which
55 * {@link PhoneAccount}s from the same {@link ConnectionService} are sorted. The accounts
Hall Liu221f8042020-09-23 15:36:58 -070056 * are sorted by this key via standard lexicographical order, (as implemented in
57 * {@link String#compareTo}), and this ordering is used to
Hall Liu2ef04112020-09-14 18:34:10 -070058 * determine priority when a call can be placed via multiple accounts.
Hall Liu221f8042020-09-23 15:36:58 -070059 *
60 * When multiple {@link PhoneAccount}s are supplied with the same sort order key, no ordering is
61 * guaranteed between those {@link PhoneAccount}s. Additionally, no ordering is guaranteed
62 * between {@link PhoneAccount}s that do not supply this extra, and all such accounts
63 * will be sorted after the accounts that do supply this extra.
64 *
65 * An example of a sort order key is slot index (see {@link TelephonyManager#getSlotIndex()}),
66 * which is the one used by the cell Telephony stack.
Srikanth Chintala62428402017-03-27 19:27:52 +053067 * @hide
68 */
Hall Liu2ef04112020-09-14 18:34:10 -070069 @SystemApi
Srikanth Chintala62428402017-03-27 19:27:52 +053070 public static final String EXTRA_SORT_ORDER =
71 "android.telecom.extra.SORT_ORDER";
72
73 /**
74 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
Tyler Gunnd426b202015-10-13 13:33:53 -070075 * maximum permitted length of a call subject specified via the
76 * {@link TelecomManager#EXTRA_CALL_SUBJECT} extra on an
77 * {@link android.content.Intent#ACTION_CALL} intent. Ultimately a {@link ConnectionService} is
78 * responsible for enforcing the maximum call subject length when sending the message, however
79 * this extra is provided so that the user interface can proactively limit the length of the
80 * call subject as the user types it.
81 */
82 public static final String EXTRA_CALL_SUBJECT_MAX_LENGTH =
83 "android.telecom.extra.CALL_SUBJECT_MAX_LENGTH";
84
85 /**
86 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
87 * character encoding to be used when determining the length of messages.
88 * The user interface can use this when determining the number of characters the user may type
89 * in a call subject. If empty-string, the call subject message size limit will be enforced on
90 * a 1:1 basis. That is, each character will count towards the messages size limit as a single
91 * character. If a character encoding is specified, the message size limit will be based on the
92 * number of bytes in the message per the specified encoding. See
93 * {@link #EXTRA_CALL_SUBJECT_MAX_LENGTH} for more information on the call subject maximum
94 * length.
95 */
96 public static final String EXTRA_CALL_SUBJECT_CHARACTER_ENCODING =
97 "android.telecom.extra.CALL_SUBJECT_CHARACTER_ENCODING";
98
Hall Liue576fc42020-01-22 17:17:13 -080099 /**
100 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
101 * indicates that all calls from this {@link PhoneAccount} should be treated as VoIP calls
Hall Liu2ef04112020-09-14 18:34:10 -0700102 * rather than cellular calls by the Telecom audio handling logic.
Srikanth Chintalaf77d4a12017-04-03 18:08:14 +0530103 */
104 public static final String EXTRA_ALWAYS_USE_VOIP_AUDIO_MODE =
105 "android.telecom.extra.ALWAYS_USE_VOIP_AUDIO_MODE";
106
Tyler Gunnd426b202015-10-13 13:33:53 -0700107 /**
Tyler Gunn8bf76572017-04-06 15:30:08 -0700108 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
109 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
Sanket Padawea8eddd42017-11-03 11:07:35 -0700110 * connection (see {@code android.telecom.Call#handoverTo()}) to this {@link PhoneAccount} from
111 * a {@link PhoneAccount} specifying {@link #EXTRA_SUPPORTS_HANDOVER_FROM}.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700112 * <p>
113 * A handover request is initiated by the user from the default dialer app to indicate a desire
114 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700115 */
116 public static final String EXTRA_SUPPORTS_HANDOVER_TO =
117 "android.telecom.extra.SUPPORTS_HANDOVER_TO";
118
119 /**
120 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Ta-wei Yen9d20d982017-06-02 11:07:07 -0700121 * indicates whether this {@link PhoneAccount} supports using a fallback if video calling is
122 * not available. This extra is for device level support, {@link
123 * android.telephony.CarrierConfigManager#KEY_ALLOW_VIDEO_CALLING_FALLBACK_BOOL} should also
124 * be checked to ensure it is not disabled by individual carrier.
125 *
126 * @hide
127 */
128 public static final String EXTRA_SUPPORTS_VIDEO_CALLING_FALLBACK =
129 "android.telecom.extra.SUPPORTS_VIDEO_CALLING_FALLBACK";
130
131 /**
132 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Tyler Gunn8bf76572017-04-06 15:30:08 -0700133 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
134 * connection from this {@link PhoneAccount} to another {@link PhoneAccount}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700135 * (see {@code android.telecom.Call#handoverTo()}) which specifies
Tyler Gunn8bf76572017-04-06 15:30:08 -0700136 * {@link #EXTRA_SUPPORTS_HANDOVER_TO}.
137 * <p>
138 * A handover request is initiated by the user from the default dialer app to indicate a desire
139 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700140 */
141 public static final String EXTRA_SUPPORTS_HANDOVER_FROM =
142 "android.telecom.extra.SUPPORTS_HANDOVER_FROM";
143
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700144
145 /**
146 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
147 * indicates whether a Self-Managed {@link PhoneAccount} should log its calls to the call log.
Brad Ebingerbb1a55f2017-06-26 13:26:14 -0700148 * Self-Managed {@link PhoneAccount}s are responsible for their own notifications, so the system
149 * will not create a notification when a missed call is logged.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700150 * <p>
151 * By default, Self-Managed {@link PhoneAccount}s do not log their calls to the call log.
152 * Setting this extra to {@code true} provides a means for them to log their calls.
Tyler Gunn2155c4c2018-04-05 09:43:41 -0700153 * <p>
154 * Note: Only calls where the {@link Call.Details#getHandle()} {@link Uri#getScheme()} is
155 * {@link #SCHEME_SIP} or {@link #SCHEME_TEL} will be logged at the current time.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700156 */
157 public static final String EXTRA_LOG_SELF_MANAGED_CALLS =
158 "android.telecom.extra.LOG_SELF_MANAGED_CALLS";
159
Tyler Gunn8bf76572017-04-06 15:30:08 -0700160 /**
Tyler Gunnacdb6862018-01-29 14:30:52 -0800161 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
162 * indicates whether calls for a {@link PhoneAccount} should generate a "call recording tone"
163 * when the user is recording audio on the device.
164 * <p>
165 * The call recording tone is played over the telephony audio stream so that the remote party
166 * has an audible indication that it is possible their call is being recorded using a call
167 * recording app on the device.
168 * <p>
169 * This extra only has an effect for calls placed via Telephony (e.g.
170 * {@link #CAPABILITY_SIM_SUBSCRIPTION}).
171 * <p>
172 * The call recording tone is a 1400 hz tone which repeats every 15 seconds while recording is
173 * in progress.
174 * @hide
175 */
Hall Liu2ef04112020-09-14 18:34:10 -0700176 @SystemApi
Tyler Gunnacdb6862018-01-29 14:30:52 -0800177 public static final String EXTRA_PLAY_CALL_RECORDING_TONE =
178 "android.telecom.extra.PLAY_CALL_RECORDING_TONE";
179
180 /**
Sean Kelley4d3c1782018-05-22 14:35:27 -0700181 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()} which
182 * indicates whether calls for a {@link PhoneAccount} should skip call filtering.
183 * <p>
184 * If not specified, this will default to false; all calls will undergo call filtering unless
185 * specifically exempted (e.g. {@link Connection#PROPERTY_EMERGENCY_CALLBACK_MODE}.) However,
186 * this may be used to skip call filtering when it has already been performed on another device.
187 * @hide
188 */
189 public static final String EXTRA_SKIP_CALL_FILTERING =
190 "android.telecom.extra.SKIP_CALL_FILTERING";
191
192 /**
Ihab Awadf8b69882014-07-25 15:14:01 -0700193 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
194 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
195 * will be allowed to manage phone calls including using its own proprietary phone-call
196 * implementation (like VoIP calling) to make calls instead of the telephony stack.
197 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700198 * When a user opts to place a call using the SIM-based telephony stack, the
199 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
200 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700201 * <p>
202 * See {@link #getCapabilities}
203 */
Ihab Awadf8b69882014-07-25 15:14:01 -0700204 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700205
206 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700207 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -0700208 * traditional SIM-based telephony calls. This account will be treated as a distinct method
209 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -0700210 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -0700211 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700212 * <p>
213 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700214 * <p>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700215 */
216 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
217
Ihab Awad7522bbd62014-07-18 15:53:17 -0700218 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700219 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -0700220 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -0700221 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700222 * Only the Android framework can register a {@code PhoneAccount} having this capability.
223 * <p>
224 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -0700225 */
226 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
227
Ihab Awadf8b69882014-07-25 15:14:01 -0700228 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800229 * Flag indicating that this {@code PhoneAccount} is currently able to place video calls.
230 * <p>
231 * See also {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING} which indicates whether the
232 * {@code PhoneAccount} supports placing video calls.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700233 * <p>
234 * See {@link #getCapabilities}
Ihab Awadf8b69882014-07-25 15:14:01 -0700235 */
236 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
237
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700238 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700239 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
240 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
241 * <p>
242 * See {@link #getCapabilities}
243 */
244 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
245
246 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800247 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
248 * should only be used by system apps (and will be ignored for all other apps trying to use it).
249 * <p>
250 * See {@link #getCapabilities}
251 * @hide
252 */
Brian Attwellad147f42014-12-19 11:37:16 -0800253 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800254 public static final int CAPABILITY_MULTI_USER = 0x20;
255
256 /**
Tyler Gunn65a3d342015-07-27 16:06:16 -0700257 * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a
258 * caller is able to specify a short subject line for an outgoing call. A capable receiving
259 * device displays the call subject on the incoming call screen.
260 * <p>
261 * See {@link #getCapabilities}
262 */
263 public static final int CAPABILITY_CALL_SUBJECT = 0x40;
264
265 /**
Bryce Leeb96d89c2015-10-14 16:48:40 -0700266 * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls.
267 * <p>
268 * See {@link #getCapabilities}
269 * @hide
270 */
Hall Liu2ef04112020-09-14 18:34:10 -0700271 @SystemApi
Bryce Leeb96d89c2015-10-14 16:48:40 -0700272 public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80;
273
274 /**
Tyler Gunn9a365752015-12-09 15:00:18 -0800275 * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a
276 * number relies on presence. Should only be set if the {@code PhoneAccount} also has
277 * {@link #CAPABILITY_VIDEO_CALLING}.
278 * <p>
279 * When set, the {@link ConnectionService} is responsible for toggling the
280 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the
281 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether
282 * a contact's phone number supports video calling.
283 * <p>
284 * See {@link #getCapabilities}
285 */
286 public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100;
287
288 /**
Tyler Gunncee9ea62016-03-24 11:45:43 -0700289 * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed.
290 * <p>
291 * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will
292 * convert all outgoing video calls to emergency numbers to audio-only.
293 * @hide
294 */
Hall Liu2ef04112020-09-14 18:34:10 -0700295 @SystemApi
Tyler Gunncee9ea62016-03-24 11:45:43 -0700296 public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200;
297
298 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800299 * Flag indicating that this {@link PhoneAccount} supports video calling.
300 * This is not an indication that the {@link PhoneAccount} is currently able to make a video
301 * call, but rather that it has the ability to make video calls (but not necessarily at this
302 * time).
303 * <p>
304 * Whether a {@link PhoneAccount} can make a video call is ultimately controlled by
305 * {@link #CAPABILITY_VIDEO_CALLING}, which indicates whether the {@link PhoneAccount} is
306 * currently capable of making a video call. Consider a case where, for example, a
307 * {@link PhoneAccount} supports making video calls (e.g.
308 * {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING}), but a current lack of network connectivity
309 * prevents video calls from being made (e.g. {@link #CAPABILITY_VIDEO_CALLING}).
310 * <p>
311 * See {@link #getCapabilities}
312 */
313 public static final int CAPABILITY_SUPPORTS_VIDEO_CALLING = 0x400;
314
315 /**
Tyler Gunnf5035432017-01-09 09:43:12 -0800316 * Flag indicating that this {@link PhoneAccount} is responsible for managing its own
317 * {@link Connection}s. This type of {@link PhoneAccount} is ideal for use with standalone
318 * calling apps which do not wish to use the default phone app for {@link Connection} UX,
319 * but which want to leverage the call and audio routing capabilities of the Telecom framework.
320 * <p>
321 * When set, {@link Connection}s created by the self-managed {@link ConnectionService} will not
322 * be surfaced to implementations of the {@link InCallService} API. Thus it is the
323 * responsibility of a self-managed {@link ConnectionService} to provide a user interface for
324 * its {@link Connection}s.
325 * <p>
326 * Self-managed {@link Connection}s will, however, be displayed on connected Bluetooth devices.
327 */
328 public static final int CAPABILITY_SELF_MANAGED = 0x800;
329
330 /**
Hall Liu95d55872017-01-25 17:12:49 -0800331 * Flag indicating that this {@link PhoneAccount} is capable of making a call with an
332 * RTT (Real-time text) session.
333 * When set, Telecom will attempt to open an RTT session on outgoing calls that specify
334 * that they should be placed with an RTT session , and the in-call app will be displayed
335 * with text entry fields for RTT. Likewise, the in-call app can request that an RTT
336 * session be opened during a call if this bit is set.
337 */
338 public static final int CAPABILITY_RTT = 0x1000;
339
Brad Ebinger3636d742019-05-21 15:28:19 -0700340 /**
341 * Flag indicating that this {@link PhoneAccount} is the preferred SIM subscription for
Hall Liu2ef04112020-09-14 18:34:10 -0700342 * emergency calls. A {@link PhoneAccount} that sets this capability must also
Brad Ebinger3636d742019-05-21 15:28:19 -0700343 * set the {@link #CAPABILITY_SIM_SUBSCRIPTION} and {@link #CAPABILITY_PLACE_EMERGENCY_CALLS}
Hall Liu2ef04112020-09-14 18:34:10 -0700344 * capabilities. There must only be one emergency preferred {@link PhoneAccount} on the device.
Brad Ebinger3636d742019-05-21 15:28:19 -0700345 * <p>
346 * When set, Telecom will prefer this {@link PhoneAccount} over others for emergency calling,
347 * even if the emergency call was placed with a specific {@link PhoneAccount} set using the
348 * extra{@link TelecomManager#EXTRA_PHONE_ACCOUNT_HANDLE} in
349 * {@link Intent#ACTION_CALL_EMERGENCY} or {@link TelecomManager#placeCall(Uri, Bundle)}.
350 *
351 * @hide
352 */
Hall Liu2ef04112020-09-14 18:34:10 -0700353 @SystemApi
Brad Ebinger3636d742019-05-21 15:28:19 -0700354 public static final int CAPABILITY_EMERGENCY_PREFERRED = 0x2000;
355
Ravi Paluri80aa2142019-12-02 11:57:37 +0530356 /**
357 * An adhoc conference call is established by providing a list of addresses to
358 * {@code TelecomManager#startConference(List<Uri>, int videoState)} where the
359 * {@link ConnectionService} is responsible for connecting all indicated participants
360 * to a conference simultaneously.
361 * This is in contrast to conferences formed by merging calls together (e.g. using
362 * {@link android.telecom.Call#mergeConference()}).
363 */
364 public static final int CAPABILITY_ADHOC_CONFERENCE_CALLING = 0x4000;
365
366 /* NEXT CAPABILITY: 0x8000 */
Hall Liu95d55872017-01-25 17:12:49 -0800367
368 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700369 * URI scheme for telephone number URIs.
370 */
371 public static final String SCHEME_TEL = "tel";
372
373 /**
374 * URI scheme for voicemail URIs.
375 */
376 public static final String SCHEME_VOICEMAIL = "voicemail";
377
378 /**
379 * URI scheme for SIP URIs.
380 */
381 public static final String SCHEME_SIP = "sip";
382
Nancy Chen3ace54b2014-10-22 17:45:26 -0700383 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800384 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700385 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700386 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800387 public static final int NO_ICON_TINT = 0;
388
389 /**
390 * Indicating no hightlight color is set.
391 */
392 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700393
Ihab Awad476cc832014-11-03 09:47:51 -0800394 /**
395 * Indicating no resource ID is set.
396 */
397 public static final int NO_RESOURCE_ID = -1;
398
Evan Charlton8c8a0622014-07-20 12:31:00 -0700399 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700400 private final Uri mAddress;
401 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700402 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800403 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700404 private final CharSequence mLabel;
405 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700406 private final List<String> mSupportedUriSchemes;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800407 private final int mSupportedAudioRoutes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700408 private final Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700409 private final Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700410 private boolean mIsEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700411 private String mGroupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700412
Tyler Gunn3b347812018-08-24 14:17:05 -0700413 @Override
414 public boolean equals(Object o) {
415 if (this == o) return true;
416 if (o == null || getClass() != o.getClass()) return false;
417 PhoneAccount that = (PhoneAccount) o;
418 return mCapabilities == that.mCapabilities &&
419 mHighlightColor == that.mHighlightColor &&
420 mSupportedAudioRoutes == that.mSupportedAudioRoutes &&
421 mIsEnabled == that.mIsEnabled &&
422 Objects.equals(mAccountHandle, that.mAccountHandle) &&
423 Objects.equals(mAddress, that.mAddress) &&
424 Objects.equals(mSubscriptionAddress, that.mSubscriptionAddress) &&
425 Objects.equals(mLabel, that.mLabel) &&
426 Objects.equals(mShortDescription, that.mShortDescription) &&
427 Objects.equals(mSupportedUriSchemes, that.mSupportedUriSchemes) &&
428 areBundlesEqual(mExtras, that.mExtras) &&
429 Objects.equals(mGroupId, that.mGroupId);
430 }
431
432 @Override
433 public int hashCode() {
434 return Objects.hash(mAccountHandle, mAddress, mSubscriptionAddress, mCapabilities,
435 mHighlightColor, mLabel, mShortDescription, mSupportedUriSchemes,
436 mSupportedAudioRoutes,
437 mExtras, mIsEnabled, mGroupId);
438 }
439
Santos Cordon32c65a52014-10-27 14:57:49 -0700440 /**
441 * Helper class for creating a {@link PhoneAccount}.
442 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700443 public static class Builder {
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800444
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700445 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700446 private Uri mAddress;
447 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700448 private int mCapabilities;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800449 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800450 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700451 private CharSequence mLabel;
452 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700453 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700454 private Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700455 private Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700456 private boolean mIsEnabled = false;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700457 private String mGroupId = "";
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700458
Santos Cordon32c65a52014-10-27 14:57:49 -0700459 /**
460 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
461 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700462 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
463 this.mAccountHandle = accountHandle;
464 this.mLabel = label;
465 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700466
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700467 /**
468 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
469 * {@link PhoneAccount}.
470 *
471 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
472 */
473 public Builder(PhoneAccount phoneAccount) {
474 mAccountHandle = phoneAccount.getAccountHandle();
475 mAddress = phoneAccount.getAddress();
476 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
477 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800478 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700479 mLabel = phoneAccount.getLabel();
480 mShortDescription = phoneAccount.getShortDescription();
481 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700482 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc02015-05-08 13:52:09 -0700483 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunnd426b202015-10-13 13:33:53 -0700484 mExtras = phoneAccount.getExtras();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700485 mGroupId = phoneAccount.getGroupId();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800486 mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700487 }
488
Santos Cordon32c65a52014-10-27 14:57:49 -0700489 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700490 * Sets the label. See {@link PhoneAccount#getLabel()}.
491 *
492 * @param label The label of the phone account.
493 * @return The builder.
494 * @hide
495 */
496 public Builder setLabel(CharSequence label) {
497 this.mLabel = label;
498 return this;
499 }
500
501 /**
Santos Cordon32c65a52014-10-27 14:57:49 -0700502 * Sets the address. See {@link PhoneAccount#getAddress}.
503 *
504 * @param value The address of the phone account.
505 * @return The builder.
506 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700507 public Builder setAddress(Uri value) {
508 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700509 return this;
510 }
511
Santos Cordon32c65a52014-10-27 14:57:49 -0700512 /**
513 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
514 *
515 * @param value The subscription address.
516 * @return The builder.
517 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700518 public Builder setSubscriptionAddress(Uri value) {
519 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700520 return this;
521 }
522
Santos Cordon32c65a52014-10-27 14:57:49 -0700523 /**
524 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
525 *
526 * @param value The capabilities to set.
527 * @return The builder.
528 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700529 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700530 this.mCapabilities = value;
531 return this;
532 }
533
Santos Cordon32c65a52014-10-27 14:57:49 -0700534 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700535 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700536 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700537 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700538 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700539 public Builder setIcon(Icon icon) {
540 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700541 return this;
542 }
543
544 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800545 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700546 *
Ihab Awad476cc832014-11-03 09:47:51 -0800547 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700548 * @return The builder.
549 */
Ihab Awad476cc832014-11-03 09:47:51 -0800550 public Builder setHighlightColor(int value) {
551 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700552 return this;
553 }
554
Santos Cordon32c65a52014-10-27 14:57:49 -0700555 /**
556 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
557 *
558 * @param value The short description.
559 * @return The builder.
560 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700561 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700562 this.mShortDescription = value;
563 return this;
564 }
565
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700566 /**
567 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
568 *
569 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700570 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700571 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700572 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700573 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
574 this.mSupportedUriSchemes.add(uriScheme);
575 }
576 return this;
577 }
578
579 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700580 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700581 *
582 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700583 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700584 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700585 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
586 mSupportedUriSchemes.clear();
587
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700588 if (uriSchemes != null && !uriSchemes.isEmpty()) {
589 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700590 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700591 }
592 }
593 return this;
594 }
595
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700596 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700597 * Specifies the extras associated with the {@link PhoneAccount}.
598 * <p>
599 * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer},
600 * and {@link Boolean}. Extras which are not of these types are ignored.
601 *
602 * @param extras
603 * @return
604 */
605 public Builder setExtras(Bundle extras) {
606 mExtras = extras;
607 return this;
608 }
609
610 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700611 * Sets the enabled state of the phone account.
612 *
613 * @param isEnabled The enabled state.
614 * @return The builder.
615 * @hide
616 */
617 public Builder setIsEnabled(boolean isEnabled) {
618 mIsEnabled = isEnabled;
619 return this;
620 }
621
622 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700623 * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is
624 * registered to Telecom, it will replace another {@link PhoneAccount} that is already
625 * registered in Telecom and take on the current user defaults and enabled status. There can
626 * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a
627 * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only
628 * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced.
Tyler Gunn5567d742019-10-31 13:04:37 -0700629 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -0800630 * Note: This is an API specific to the Telephony stack; the group Id will be ignored for
631 * callers not holding the correct permission.
Tyler Gunn5567d742019-10-31 13:04:37 -0700632 *
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700633 * @param groupId The group Id of the {@link PhoneAccount} that will replace any other
634 * registered {@link PhoneAccount} in Telecom with the same Group Id.
635 * @return The builder
636 * @hide
637 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700638 @SystemApi
639 @TestApi
Tyler Gunnc9503d62020-01-27 10:30:51 -0800640 @RequiresPermission(MODIFY_PHONE_STATE)
Tyler Gunn5567d742019-10-31 13:04:37 -0700641 public @NonNull Builder setGroupId(@NonNull String groupId) {
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700642 if (groupId != null) {
643 mGroupId = groupId;
644 } else {
645 mGroupId = "";
646 }
647 return this;
648 }
649
650 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800651 * Sets the audio routes supported by this {@link PhoneAccount}.
652 *
653 * @param routes bit mask of available routes.
654 * @return The builder.
655 * @hide
656 */
657 public Builder setSupportedAudioRoutes(int routes) {
658 mSupportedAudioRoutes = routes;
659 return this;
660 }
661
662 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700663 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
664 *
665 * @return The {@link PhoneAccount}.
666 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700667 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700668 // If no supported URI schemes were defined, assume "tel" is supported.
669 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700670 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700671 }
672
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700673 return new PhoneAccount(
674 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700675 mAddress,
676 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700677 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700678 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800679 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700680 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700681 mShortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700682 mSupportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700683 mExtras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800684 mSupportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700685 mIsEnabled,
686 mGroupId);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700687 }
688 }
689
690 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700691 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700692 Uri address,
693 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700694 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700695 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800696 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700697 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700698 CharSequence shortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700699 List<String> supportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700700 Bundle extras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800701 int supportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700702 boolean isEnabled,
703 String groupId) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700704 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700705 mAddress = address;
706 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700707 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700708 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800709 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700710 mLabel = label;
711 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700712 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700713 mExtras = extras;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800714 mSupportedAudioRoutes = supportedAudioRoutes;
Santos Cordon91371dc02015-05-08 13:52:09 -0700715 mIsEnabled = isEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700716 mGroupId = groupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700717 }
718
Andrew Lee3085a6c2014-09-04 10:59:13 -0700719 public static Builder builder(
720 PhoneAccountHandle accountHandle,
721 CharSequence label) {
722 return new Builder(accountHandle, label);
723 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700724
Ihab Awad807fe0a2014-07-09 12:30:52 -0700725 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700726 * Returns a builder initialized with the current {@link PhoneAccount} instance.
727 *
728 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700729 */
730 public Builder toBuilder() { return new Builder(this); }
731
732 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700733 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700734 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700735 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700736 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700737 public PhoneAccountHandle getAccountHandle() {
738 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700739 }
740
741 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700742 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700743 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700744 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700745 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700746 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700747 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700748 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700749 public Uri getAddress() {
750 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700751 }
752
753 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700754 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700755 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700756 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000757 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
758 * has been used to alter the callback number.
759 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700760 *
761 * @return The subscription number, suitable for display to the user.
762 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700763 public Uri getSubscriptionAddress() {
764 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700765 }
766
767 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700768 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700769 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700770 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700771 */
772 public int getCapabilities() {
773 return mCapabilities;
774 }
775
776 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700777 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
778 * bit mask.
779 *
780 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700781 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700782 */
783 public boolean hasCapabilities(int capability) {
784 return (mCapabilities & capability) == capability;
785 }
786
787 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800788 * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask.
789 *
790 * @param route The routes to check.
791 * @return {@code true} if the phone account has the routes.
792 * @hide
793 */
794 public boolean hasAudioRoutes(int routes) {
795 return (mSupportedAudioRoutes & routes) == routes;
796 }
797
798 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700799 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700800 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700801 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700802 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700803 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700804 return mLabel;
805 }
806
807 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700808 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700809 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700810 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700811 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700812 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700813 return mShortDescription;
814 }
815
816 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700817 * The URI schemes supported by this {@code PhoneAccount}.
818 *
819 * @return The URI schemes.
820 */
821 public List<String> getSupportedUriSchemes() {
822 return mSupportedUriSchemes;
823 }
824
825 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700826 * The extras associated with this {@code PhoneAccount}.
827 * <p>
828 * A {@link ConnectionService} may provide implementation specific information about the
829 * {@link PhoneAccount} via the extras.
830 *
831 * @return The extras.
832 */
833 public Bundle getExtras() {
834 return mExtras;
835 }
836
837 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800838 * The audio routes supported by this {@code PhoneAccount}.
839 *
840 * @hide
841 */
842 public int getSupportedAudioRoutes() {
843 return mSupportedAudioRoutes;
844 }
845
846 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700847 * The icon to represent this {@code PhoneAccount}.
848 *
849 * @return The icon.
850 */
851 public Icon getIcon() {
852 return mIcon;
853 }
854
855 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700856 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
857 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc02015-05-08 13:52:09 -0700858 *
Santos Cordon895d4b82015-06-25 16:41:48 -0700859 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc02015-05-08 13:52:09 -0700860 */
861 public boolean isEnabled() {
862 return mIsEnabled;
863 }
864
865 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700866 * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an
867 * empty {@link String} if the {@link PhoneAccount} is not in a group. If this
868 * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered
869 * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced,
870 * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}.
871 * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced.
872 *
873 * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group.
874 * @hide
875 */
876 public String getGroupId() {
877 return mGroupId;
878 }
879
880 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700881 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700882 * scheme.
883 *
884 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700885 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700886 * specified URI scheme.
887 */
888 public boolean supportsUriScheme(String uriScheme) {
889 if (mSupportedUriSchemes == null || uriScheme == null) {
890 return false;
891 }
892
893 for (String scheme : mSupportedUriSchemes) {
894 if (scheme != null && scheme.equals(uriScheme)) {
895 return true;
896 }
897 }
898 return false;
899 }
900
901 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800902 * A highlight color to use in displaying information about this {@code PhoneAccount}.
903 *
904 * @return A hexadecimal color value.
905 */
906 public int getHighlightColor() {
907 return mHighlightColor;
908 }
909
Santos Cordon91371dc02015-05-08 13:52:09 -0700910 /**
911 * Sets the enabled state of the phone account.
912 * @hide
913 */
914 public void setIsEnabled(boolean isEnabled) {
915 mIsEnabled = isEnabled;
916 }
917
Tyler Gunnf5035432017-01-09 09:43:12 -0800918 /**
919 * @return {@code true} if the {@link PhoneAccount} is self-managed, {@code false} otherwise.
920 * @hide
921 */
922 public boolean isSelfManaged() {
923 return (mCapabilities & CAPABILITY_SELF_MANAGED) == CAPABILITY_SELF_MANAGED;
924 }
925
Ihab Awad807fe0a2014-07-09 12:30:52 -0700926 //
927 // Parcelable implementation
928 //
929
930 @Override
931 public int describeContents() {
932 return 0;
933 }
934
935 @Override
936 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800937 if (mAccountHandle == null) {
938 out.writeInt(0);
939 } else {
940 out.writeInt(1);
941 mAccountHandle.writeToParcel(out, flags);
942 }
943 if (mAddress == null) {
944 out.writeInt(0);
945 } else {
946 out.writeInt(1);
947 mAddress.writeToParcel(out, flags);
948 }
949 if (mSubscriptionAddress == null) {
950 out.writeInt(0);
951 } else {
952 out.writeInt(1);
953 mSubscriptionAddress.writeToParcel(out, flags);
954 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700955 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800956 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700957 out.writeCharSequence(mLabel);
958 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800959 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc02015-05-08 13:52:09 -0700960
Santos Cordoncad84a22015-05-13 11:17:25 -0700961 if (mIcon == null) {
962 out.writeInt(0);
963 } else {
964 out.writeInt(1);
965 mIcon.writeToParcel(out, flags);
966 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700967 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Tyler Gunnef829ec2015-10-08 09:46:23 -0700968 out.writeBundle(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700969 out.writeString(mGroupId);
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800970 out.writeInt(mSupportedAudioRoutes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700971 }
972
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700973 public static final @android.annotation.NonNull Creator<PhoneAccount> CREATOR
Evan Charlton8c8a0622014-07-20 12:31:00 -0700974 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700975 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700976 public PhoneAccount createFromParcel(Parcel in) {
977 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700978 }
979
980 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700981 public PhoneAccount[] newArray(int size) {
982 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700983 }
984 };
985
Evan Charlton8c8a0622014-07-20 12:31:00 -0700986 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800987 if (in.readInt() > 0) {
988 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
989 } else {
990 mAccountHandle = null;
991 }
992 if (in.readInt() > 0) {
993 mAddress = Uri.CREATOR.createFromParcel(in);
994 } else {
995 mAddress = null;
996 }
997 if (in.readInt() > 0) {
998 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
999 } else {
1000 mSubscriptionAddress = null;
1001 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -07001002 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -08001003 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -07001004 mLabel = in.readCharSequence();
1005 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -08001006 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -07001007 if (in.readInt() > 0) {
1008 mIcon = Icon.CREATOR.createFromParcel(in);
1009 } else {
1010 mIcon = null;
1011 }
Santos Cordon91371dc02015-05-08 13:52:09 -07001012 mIsEnabled = in.readByte() == 1;
Tyler Gunnef829ec2015-10-08 09:46:23 -07001013 mExtras = in.readBundle();
Brad Ebinger7298f3b2016-06-10 17:19:42 -07001014 mGroupId = in.readString();
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001015 mSupportedAudioRoutes = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -07001016 }
Tyler Gunn76c01a52014-09-30 14:47:51 -07001017
1018 @Override
1019 public String toString() {
Santos Cordon91371dc02015-05-08 13:52:09 -07001020 StringBuilder sb = new StringBuilder().append("[[")
1021 .append(mIsEnabled ? 'X' : ' ')
1022 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -07001023 .append(mAccountHandle)
1024 .append(" Capabilities: ")
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001025 .append(capabilitiesToString())
1026 .append(" Audio Routes: ")
1027 .append(audioRoutesToString())
Tyler Gunn76c01a52014-09-30 14:47:51 -07001028 .append(" Schemes: ");
1029 for (String scheme : mSupportedUriSchemes) {
1030 sb.append(scheme)
1031 .append(" ");
1032 }
Tyler Gunnef829ec2015-10-08 09:46:23 -07001033 sb.append(" Extras: ");
Tyler Gunn25ed2d72015-10-05 14:14:38 -07001034 sb.append(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -07001035 sb.append(" GroupId: ");
1036 sb.append(Log.pii(mGroupId));
Tyler Gunn76c01a52014-09-30 14:47:51 -07001037 sb.append("]");
1038 return sb.toString();
1039 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001040
1041 /**
1042 * Generates a string representation of a capabilities bitmask.
1043 *
Tyler Gunn3e122f72016-01-11 19:25:00 -08001044 * @return String representation of the capabilities bitmask.
Tyler Gunn1847b4e2018-11-09 08:43:02 -08001045 * @hide
Tyler Gunn3e122f72016-01-11 19:25:00 -08001046 */
Tyler Gunn1847b4e2018-11-09 08:43:02 -08001047 public String capabilitiesToString() {
Tyler Gunn3e122f72016-01-11 19:25:00 -08001048 StringBuilder sb = new StringBuilder();
Tyler Gunnf5035432017-01-09 09:43:12 -08001049 if (hasCapabilities(CAPABILITY_SELF_MANAGED)) {
1050 sb.append("SelfManaged ");
1051 }
Tyler Gunn58cbd7a2016-11-11 11:31:28 -08001052 if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) {
1053 sb.append("SuppVideo ");
1054 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001055 if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) {
1056 sb.append("Video ");
1057 }
1058 if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
1059 sb.append("Presence ");
1060 }
1061 if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) {
1062 sb.append("CallProvider ");
1063 }
1064 if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) {
1065 sb.append("CallSubject ");
1066 }
1067 if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) {
1068 sb.append("ConnectionMgr ");
1069 }
1070 if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) {
1071 sb.append("EmergOnly ");
1072 }
1073 if (hasCapabilities(CAPABILITY_MULTI_USER)) {
1074 sb.append("MultiUser ");
1075 }
1076 if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) {
1077 sb.append("PlaceEmerg ");
1078 }
Brad Ebinger3636d742019-05-21 15:28:19 -07001079 if (hasCapabilities(CAPABILITY_EMERGENCY_PREFERRED)) {
1080 sb.append("EmerPrefer ");
1081 }
Tyler Gunncee9ea62016-03-24 11:45:43 -07001082 if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
1083 sb.append("EmergVideo ");
1084 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001085 if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) {
1086 sb.append("SimSub ");
1087 }
Hall Liu47ed6202017-11-20 16:25:39 -08001088 if (hasCapabilities(CAPABILITY_RTT)) {
1089 sb.append("Rtt");
1090 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05301091 if (hasCapabilities(CAPABILITY_ADHOC_CONFERENCE_CALLING)) {
1092 sb.append("AdhocConf");
1093 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001094 return sb.toString();
1095 }
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001096
1097 private String audioRoutesToString() {
1098 StringBuilder sb = new StringBuilder();
1099
1100 if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) {
1101 sb.append("B");
1102 }
1103 if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) {
1104 sb.append("E");
1105 }
1106 if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) {
1107 sb.append("S");
1108 }
1109 if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) {
1110 sb.append("W");
1111 }
1112
1113 return sb.toString();
1114 }
Tyler Gunn3b347812018-08-24 14:17:05 -07001115
1116 /**
1117 * Determines if two {@link Bundle}s are equal.
1118 * @param extras First {@link Bundle} to check.
1119 * @param newExtras {@link Bundle} to compare against.
1120 * @return {@code true} if the {@link Bundle}s are equal, {@code false} otherwise.
1121 */
1122 private static boolean areBundlesEqual(Bundle extras, Bundle newExtras) {
1123 if (extras == null || newExtras == null) {
1124 return extras == newExtras;
1125 }
1126
1127 if (extras.size() != newExtras.size()) {
1128 return false;
1129 }
1130
1131 for(String key : extras.keySet()) {
1132 if (key != null) {
1133 final Object value = extras.get(key);
1134 final Object newValue = newExtras.get(key);
1135 if (!Objects.equals(value, newValue)) {
1136 return false;
1137 }
1138 }
1139 }
1140 return true;
1141 }
Ihab Awad807fe0a2014-07-09 12:30:52 -07001142}