blob: c20e5ad8ce7c5d5941b9771bdeb587927039eede [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;
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 Liu2ef04112020-09-14 18:34:10 -070051 * String extra which determines the order in which {@link PhoneAccount}s are sorted
52 *
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
55 * are sorted by this key via standard lexicographical order, and this ordering is used to
56 * determine priority when a call can be placed via multiple accounts.
Srikanth Chintala62428402017-03-27 19:27:52 +053057 * @hide
58 */
Hall Liu2ef04112020-09-14 18:34:10 -070059 @SystemApi
Srikanth Chintala62428402017-03-27 19:27:52 +053060 public static final String EXTRA_SORT_ORDER =
61 "android.telecom.extra.SORT_ORDER";
62
63 /**
64 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
Tyler Gunnd426b202015-10-13 13:33:53 -070065 * maximum permitted length of a call subject specified via the
66 * {@link TelecomManager#EXTRA_CALL_SUBJECT} extra on an
67 * {@link android.content.Intent#ACTION_CALL} intent. Ultimately a {@link ConnectionService} is
68 * responsible for enforcing the maximum call subject length when sending the message, however
69 * this extra is provided so that the user interface can proactively limit the length of the
70 * call subject as the user types it.
71 */
72 public static final String EXTRA_CALL_SUBJECT_MAX_LENGTH =
73 "android.telecom.extra.CALL_SUBJECT_MAX_LENGTH";
74
75 /**
76 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
77 * character encoding to be used when determining the length of messages.
78 * The user interface can use this when determining the number of characters the user may type
79 * in a call subject. If empty-string, the call subject message size limit will be enforced on
80 * a 1:1 basis. That is, each character will count towards the messages size limit as a single
81 * character. If a character encoding is specified, the message size limit will be based on the
82 * number of bytes in the message per the specified encoding. See
83 * {@link #EXTRA_CALL_SUBJECT_MAX_LENGTH} for more information on the call subject maximum
84 * length.
85 */
86 public static final String EXTRA_CALL_SUBJECT_CHARACTER_ENCODING =
87 "android.telecom.extra.CALL_SUBJECT_CHARACTER_ENCODING";
88
Hall Liue576fc42020-01-22 17:17:13 -080089 /**
90 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
91 * indicates that all calls from this {@link PhoneAccount} should be treated as VoIP calls
Hall Liu2ef04112020-09-14 18:34:10 -070092 * rather than cellular calls by the Telecom audio handling logic.
Srikanth Chintalaf77d4a12017-04-03 18:08:14 +053093 */
94 public static final String EXTRA_ALWAYS_USE_VOIP_AUDIO_MODE =
95 "android.telecom.extra.ALWAYS_USE_VOIP_AUDIO_MODE";
96
Tyler Gunnd426b202015-10-13 13:33:53 -070097 /**
Tyler Gunn8bf76572017-04-06 15:30:08 -070098 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
99 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
Sanket Padawea8eddd42017-11-03 11:07:35 -0700100 * connection (see {@code android.telecom.Call#handoverTo()}) to this {@link PhoneAccount} from
101 * a {@link PhoneAccount} specifying {@link #EXTRA_SUPPORTS_HANDOVER_FROM}.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700102 * <p>
103 * A handover request is initiated by the user from the default dialer app to indicate a desire
104 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700105 */
106 public static final String EXTRA_SUPPORTS_HANDOVER_TO =
107 "android.telecom.extra.SUPPORTS_HANDOVER_TO";
108
109 /**
110 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Ta-wei Yen9d20d982017-06-02 11:07:07 -0700111 * indicates whether this {@link PhoneAccount} supports using a fallback if video calling is
112 * not available. This extra is for device level support, {@link
113 * android.telephony.CarrierConfigManager#KEY_ALLOW_VIDEO_CALLING_FALLBACK_BOOL} should also
114 * be checked to ensure it is not disabled by individual carrier.
115 *
116 * @hide
117 */
118 public static final String EXTRA_SUPPORTS_VIDEO_CALLING_FALLBACK =
119 "android.telecom.extra.SUPPORTS_VIDEO_CALLING_FALLBACK";
120
121 /**
122 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Tyler Gunn8bf76572017-04-06 15:30:08 -0700123 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
124 * connection from this {@link PhoneAccount} to another {@link PhoneAccount}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700125 * (see {@code android.telecom.Call#handoverTo()}) which specifies
Tyler Gunn8bf76572017-04-06 15:30:08 -0700126 * {@link #EXTRA_SUPPORTS_HANDOVER_TO}.
127 * <p>
128 * A handover request is initiated by the user from the default dialer app to indicate a desire
129 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700130 */
131 public static final String EXTRA_SUPPORTS_HANDOVER_FROM =
132 "android.telecom.extra.SUPPORTS_HANDOVER_FROM";
133
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700134
135 /**
136 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
137 * indicates whether a Self-Managed {@link PhoneAccount} should log its calls to the call log.
Brad Ebingerbb1a55f2017-06-26 13:26:14 -0700138 * Self-Managed {@link PhoneAccount}s are responsible for their own notifications, so the system
139 * will not create a notification when a missed call is logged.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700140 * <p>
141 * By default, Self-Managed {@link PhoneAccount}s do not log their calls to the call log.
142 * Setting this extra to {@code true} provides a means for them to log their calls.
Tyler Gunn2155c4c2018-04-05 09:43:41 -0700143 * <p>
144 * Note: Only calls where the {@link Call.Details#getHandle()} {@link Uri#getScheme()} is
145 * {@link #SCHEME_SIP} or {@link #SCHEME_TEL} will be logged at the current time.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700146 */
147 public static final String EXTRA_LOG_SELF_MANAGED_CALLS =
148 "android.telecom.extra.LOG_SELF_MANAGED_CALLS";
149
Tyler Gunn8bf76572017-04-06 15:30:08 -0700150 /**
Tyler Gunnacdb6862018-01-29 14:30:52 -0800151 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
152 * indicates whether calls for a {@link PhoneAccount} should generate a "call recording tone"
153 * when the user is recording audio on the device.
154 * <p>
155 * The call recording tone is played over the telephony audio stream so that the remote party
156 * has an audible indication that it is possible their call is being recorded using a call
157 * recording app on the device.
158 * <p>
159 * This extra only has an effect for calls placed via Telephony (e.g.
160 * {@link #CAPABILITY_SIM_SUBSCRIPTION}).
161 * <p>
162 * The call recording tone is a 1400 hz tone which repeats every 15 seconds while recording is
163 * in progress.
164 * @hide
165 */
Hall Liu2ef04112020-09-14 18:34:10 -0700166 @SystemApi
Tyler Gunnacdb6862018-01-29 14:30:52 -0800167 public static final String EXTRA_PLAY_CALL_RECORDING_TONE =
168 "android.telecom.extra.PLAY_CALL_RECORDING_TONE";
169
170 /**
Sean Kelley4d3c1782018-05-22 14:35:27 -0700171 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()} which
172 * indicates whether calls for a {@link PhoneAccount} should skip call filtering.
173 * <p>
174 * If not specified, this will default to false; all calls will undergo call filtering unless
175 * specifically exempted (e.g. {@link Connection#PROPERTY_EMERGENCY_CALLBACK_MODE}.) However,
176 * this may be used to skip call filtering when it has already been performed on another device.
177 * @hide
178 */
179 public static final String EXTRA_SKIP_CALL_FILTERING =
180 "android.telecom.extra.SKIP_CALL_FILTERING";
181
182 /**
Ihab Awadf8b69882014-07-25 15:14:01 -0700183 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
184 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
185 * will be allowed to manage phone calls including using its own proprietary phone-call
186 * implementation (like VoIP calling) to make calls instead of the telephony stack.
187 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700188 * When a user opts to place a call using the SIM-based telephony stack, the
189 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
190 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700191 * <p>
192 * See {@link #getCapabilities}
193 */
Ihab Awadf8b69882014-07-25 15:14:01 -0700194 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700195
196 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700197 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -0700198 * traditional SIM-based telephony calls. This account will be treated as a distinct method
199 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -0700200 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -0700201 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700202 * <p>
203 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700204 * <p>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700205 */
206 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
207
Ihab Awad7522bbd62014-07-18 15:53:17 -0700208 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700209 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -0700210 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -0700211 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700212 * Only the Android framework can register a {@code PhoneAccount} having this capability.
213 * <p>
214 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -0700215 */
216 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
217
Ihab Awadf8b69882014-07-25 15:14:01 -0700218 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800219 * Flag indicating that this {@code PhoneAccount} is currently able to place video calls.
220 * <p>
221 * See also {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING} which indicates whether the
222 * {@code PhoneAccount} supports placing video calls.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700223 * <p>
224 * See {@link #getCapabilities}
Ihab Awadf8b69882014-07-25 15:14:01 -0700225 */
226 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
227
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700228 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700229 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
230 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
231 * <p>
232 * See {@link #getCapabilities}
233 */
234 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
235
236 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800237 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
238 * should only be used by system apps (and will be ignored for all other apps trying to use it).
239 * <p>
240 * See {@link #getCapabilities}
241 * @hide
242 */
Brian Attwellad147f42014-12-19 11:37:16 -0800243 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800244 public static final int CAPABILITY_MULTI_USER = 0x20;
245
246 /**
Tyler Gunn65a3d342015-07-27 16:06:16 -0700247 * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a
248 * caller is able to specify a short subject line for an outgoing call. A capable receiving
249 * device displays the call subject on the incoming call screen.
250 * <p>
251 * See {@link #getCapabilities}
252 */
253 public static final int CAPABILITY_CALL_SUBJECT = 0x40;
254
255 /**
Bryce Leeb96d89c2015-10-14 16:48:40 -0700256 * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls.
257 * <p>
258 * See {@link #getCapabilities}
259 * @hide
260 */
Hall Liu2ef04112020-09-14 18:34:10 -0700261 @SystemApi
Bryce Leeb96d89c2015-10-14 16:48:40 -0700262 public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80;
263
264 /**
Tyler Gunn9a365752015-12-09 15:00:18 -0800265 * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a
266 * number relies on presence. Should only be set if the {@code PhoneAccount} also has
267 * {@link #CAPABILITY_VIDEO_CALLING}.
268 * <p>
269 * When set, the {@link ConnectionService} is responsible for toggling the
270 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the
271 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether
272 * a contact's phone number supports video calling.
273 * <p>
274 * See {@link #getCapabilities}
275 */
276 public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100;
277
278 /**
Tyler Gunncee9ea62016-03-24 11:45:43 -0700279 * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed.
280 * <p>
281 * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will
282 * convert all outgoing video calls to emergency numbers to audio-only.
283 * @hide
284 */
Hall Liu2ef04112020-09-14 18:34:10 -0700285 @SystemApi
Tyler Gunncee9ea62016-03-24 11:45:43 -0700286 public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200;
287
288 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800289 * Flag indicating that this {@link PhoneAccount} supports video calling.
290 * This is not an indication that the {@link PhoneAccount} is currently able to make a video
291 * call, but rather that it has the ability to make video calls (but not necessarily at this
292 * time).
293 * <p>
294 * Whether a {@link PhoneAccount} can make a video call is ultimately controlled by
295 * {@link #CAPABILITY_VIDEO_CALLING}, which indicates whether the {@link PhoneAccount} is
296 * currently capable of making a video call. Consider a case where, for example, a
297 * {@link PhoneAccount} supports making video calls (e.g.
298 * {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING}), but a current lack of network connectivity
299 * prevents video calls from being made (e.g. {@link #CAPABILITY_VIDEO_CALLING}).
300 * <p>
301 * See {@link #getCapabilities}
302 */
303 public static final int CAPABILITY_SUPPORTS_VIDEO_CALLING = 0x400;
304
305 /**
Tyler Gunnf5035432017-01-09 09:43:12 -0800306 * Flag indicating that this {@link PhoneAccount} is responsible for managing its own
307 * {@link Connection}s. This type of {@link PhoneAccount} is ideal for use with standalone
308 * calling apps which do not wish to use the default phone app for {@link Connection} UX,
309 * but which want to leverage the call and audio routing capabilities of the Telecom framework.
310 * <p>
311 * When set, {@link Connection}s created by the self-managed {@link ConnectionService} will not
312 * be surfaced to implementations of the {@link InCallService} API. Thus it is the
313 * responsibility of a self-managed {@link ConnectionService} to provide a user interface for
314 * its {@link Connection}s.
315 * <p>
316 * Self-managed {@link Connection}s will, however, be displayed on connected Bluetooth devices.
317 */
318 public static final int CAPABILITY_SELF_MANAGED = 0x800;
319
320 /**
Hall Liu95d55872017-01-25 17:12:49 -0800321 * Flag indicating that this {@link PhoneAccount} is capable of making a call with an
322 * RTT (Real-time text) session.
323 * When set, Telecom will attempt to open an RTT session on outgoing calls that specify
324 * that they should be placed with an RTT session , and the in-call app will be displayed
325 * with text entry fields for RTT. Likewise, the in-call app can request that an RTT
326 * session be opened during a call if this bit is set.
327 */
328 public static final int CAPABILITY_RTT = 0x1000;
329
Brad Ebinger3636d742019-05-21 15:28:19 -0700330 /**
331 * Flag indicating that this {@link PhoneAccount} is the preferred SIM subscription for
Hall Liu2ef04112020-09-14 18:34:10 -0700332 * emergency calls. A {@link PhoneAccount} that sets this capability must also
Brad Ebinger3636d742019-05-21 15:28:19 -0700333 * set the {@link #CAPABILITY_SIM_SUBSCRIPTION} and {@link #CAPABILITY_PLACE_EMERGENCY_CALLS}
Hall Liu2ef04112020-09-14 18:34:10 -0700334 * capabilities. There must only be one emergency preferred {@link PhoneAccount} on the device.
Brad Ebinger3636d742019-05-21 15:28:19 -0700335 * <p>
336 * When set, Telecom will prefer this {@link PhoneAccount} over others for emergency calling,
337 * even if the emergency call was placed with a specific {@link PhoneAccount} set using the
338 * extra{@link TelecomManager#EXTRA_PHONE_ACCOUNT_HANDLE} in
339 * {@link Intent#ACTION_CALL_EMERGENCY} or {@link TelecomManager#placeCall(Uri, Bundle)}.
340 *
341 * @hide
342 */
Hall Liu2ef04112020-09-14 18:34:10 -0700343 @SystemApi
Brad Ebinger3636d742019-05-21 15:28:19 -0700344 public static final int CAPABILITY_EMERGENCY_PREFERRED = 0x2000;
345
Ravi Paluri80aa2142019-12-02 11:57:37 +0530346 /**
347 * An adhoc conference call is established by providing a list of addresses to
348 * {@code TelecomManager#startConference(List<Uri>, int videoState)} where the
349 * {@link ConnectionService} is responsible for connecting all indicated participants
350 * to a conference simultaneously.
351 * This is in contrast to conferences formed by merging calls together (e.g. using
352 * {@link android.telecom.Call#mergeConference()}).
353 */
354 public static final int CAPABILITY_ADHOC_CONFERENCE_CALLING = 0x4000;
355
356 /* NEXT CAPABILITY: 0x8000 */
Hall Liu95d55872017-01-25 17:12:49 -0800357
358 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700359 * URI scheme for telephone number URIs.
360 */
361 public static final String SCHEME_TEL = "tel";
362
363 /**
364 * URI scheme for voicemail URIs.
365 */
366 public static final String SCHEME_VOICEMAIL = "voicemail";
367
368 /**
369 * URI scheme for SIP URIs.
370 */
371 public static final String SCHEME_SIP = "sip";
372
Nancy Chen3ace54b2014-10-22 17:45:26 -0700373 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800374 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700375 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700376 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800377 public static final int NO_ICON_TINT = 0;
378
379 /**
380 * Indicating no hightlight color is set.
381 */
382 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700383
Ihab Awad476cc832014-11-03 09:47:51 -0800384 /**
385 * Indicating no resource ID is set.
386 */
387 public static final int NO_RESOURCE_ID = -1;
388
Evan Charlton8c8a0622014-07-20 12:31:00 -0700389 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700390 private final Uri mAddress;
391 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700392 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800393 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700394 private final CharSequence mLabel;
395 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700396 private final List<String> mSupportedUriSchemes;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800397 private final int mSupportedAudioRoutes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700398 private final Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700399 private final Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700400 private boolean mIsEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700401 private String mGroupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700402
Tyler Gunn3b347812018-08-24 14:17:05 -0700403 @Override
404 public boolean equals(Object o) {
405 if (this == o) return true;
406 if (o == null || getClass() != o.getClass()) return false;
407 PhoneAccount that = (PhoneAccount) o;
408 return mCapabilities == that.mCapabilities &&
409 mHighlightColor == that.mHighlightColor &&
410 mSupportedAudioRoutes == that.mSupportedAudioRoutes &&
411 mIsEnabled == that.mIsEnabled &&
412 Objects.equals(mAccountHandle, that.mAccountHandle) &&
413 Objects.equals(mAddress, that.mAddress) &&
414 Objects.equals(mSubscriptionAddress, that.mSubscriptionAddress) &&
415 Objects.equals(mLabel, that.mLabel) &&
416 Objects.equals(mShortDescription, that.mShortDescription) &&
417 Objects.equals(mSupportedUriSchemes, that.mSupportedUriSchemes) &&
418 areBundlesEqual(mExtras, that.mExtras) &&
419 Objects.equals(mGroupId, that.mGroupId);
420 }
421
422 @Override
423 public int hashCode() {
424 return Objects.hash(mAccountHandle, mAddress, mSubscriptionAddress, mCapabilities,
425 mHighlightColor, mLabel, mShortDescription, mSupportedUriSchemes,
426 mSupportedAudioRoutes,
427 mExtras, mIsEnabled, mGroupId);
428 }
429
Santos Cordon32c65a52014-10-27 14:57:49 -0700430 /**
431 * Helper class for creating a {@link PhoneAccount}.
432 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700433 public static class Builder {
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800434
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700435 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700436 private Uri mAddress;
437 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700438 private int mCapabilities;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800439 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800440 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700441 private CharSequence mLabel;
442 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700443 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700444 private Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700445 private Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700446 private boolean mIsEnabled = false;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700447 private String mGroupId = "";
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700448
Santos Cordon32c65a52014-10-27 14:57:49 -0700449 /**
450 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
451 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700452 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
453 this.mAccountHandle = accountHandle;
454 this.mLabel = label;
455 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700456
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700457 /**
458 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
459 * {@link PhoneAccount}.
460 *
461 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
462 */
463 public Builder(PhoneAccount phoneAccount) {
464 mAccountHandle = phoneAccount.getAccountHandle();
465 mAddress = phoneAccount.getAddress();
466 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
467 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800468 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700469 mLabel = phoneAccount.getLabel();
470 mShortDescription = phoneAccount.getShortDescription();
471 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700472 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc02015-05-08 13:52:09 -0700473 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunnd426b202015-10-13 13:33:53 -0700474 mExtras = phoneAccount.getExtras();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700475 mGroupId = phoneAccount.getGroupId();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800476 mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700477 }
478
Santos Cordon32c65a52014-10-27 14:57:49 -0700479 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700480 * Sets the label. See {@link PhoneAccount#getLabel()}.
481 *
482 * @param label The label of the phone account.
483 * @return The builder.
484 * @hide
485 */
486 public Builder setLabel(CharSequence label) {
487 this.mLabel = label;
488 return this;
489 }
490
491 /**
Santos Cordon32c65a52014-10-27 14:57:49 -0700492 * Sets the address. See {@link PhoneAccount#getAddress}.
493 *
494 * @param value The address of the phone account.
495 * @return The builder.
496 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700497 public Builder setAddress(Uri value) {
498 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700499 return this;
500 }
501
Santos Cordon32c65a52014-10-27 14:57:49 -0700502 /**
503 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
504 *
505 * @param value The subscription address.
506 * @return The builder.
507 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700508 public Builder setSubscriptionAddress(Uri value) {
509 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700510 return this;
511 }
512
Santos Cordon32c65a52014-10-27 14:57:49 -0700513 /**
514 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
515 *
516 * @param value The capabilities to set.
517 * @return The builder.
518 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700519 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700520 this.mCapabilities = value;
521 return this;
522 }
523
Santos Cordon32c65a52014-10-27 14:57:49 -0700524 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700525 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700526 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700527 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700528 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700529 public Builder setIcon(Icon icon) {
530 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700531 return this;
532 }
533
534 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800535 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700536 *
Ihab Awad476cc832014-11-03 09:47:51 -0800537 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700538 * @return The builder.
539 */
Ihab Awad476cc832014-11-03 09:47:51 -0800540 public Builder setHighlightColor(int value) {
541 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700542 return this;
543 }
544
Santos Cordon32c65a52014-10-27 14:57:49 -0700545 /**
546 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
547 *
548 * @param value The short description.
549 * @return The builder.
550 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700551 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700552 this.mShortDescription = value;
553 return this;
554 }
555
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700556 /**
557 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
558 *
559 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700560 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700561 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700562 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700563 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
564 this.mSupportedUriSchemes.add(uriScheme);
565 }
566 return this;
567 }
568
569 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700570 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700571 *
572 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700573 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700574 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700575 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
576 mSupportedUriSchemes.clear();
577
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700578 if (uriSchemes != null && !uriSchemes.isEmpty()) {
579 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700580 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700581 }
582 }
583 return this;
584 }
585
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700586 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700587 * Specifies the extras associated with the {@link PhoneAccount}.
588 * <p>
589 * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer},
590 * and {@link Boolean}. Extras which are not of these types are ignored.
591 *
592 * @param extras
593 * @return
594 */
595 public Builder setExtras(Bundle extras) {
596 mExtras = extras;
597 return this;
598 }
599
600 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700601 * Sets the enabled state of the phone account.
602 *
603 * @param isEnabled The enabled state.
604 * @return The builder.
605 * @hide
606 */
607 public Builder setIsEnabled(boolean isEnabled) {
608 mIsEnabled = isEnabled;
609 return this;
610 }
611
612 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700613 * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is
614 * registered to Telecom, it will replace another {@link PhoneAccount} that is already
615 * registered in Telecom and take on the current user defaults and enabled status. There can
616 * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a
617 * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only
618 * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced.
Tyler Gunn5567d742019-10-31 13:04:37 -0700619 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -0800620 * Note: This is an API specific to the Telephony stack; the group Id will be ignored for
621 * callers not holding the correct permission.
Tyler Gunn5567d742019-10-31 13:04:37 -0700622 *
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700623 * @param groupId The group Id of the {@link PhoneAccount} that will replace any other
624 * registered {@link PhoneAccount} in Telecom with the same Group Id.
625 * @return The builder
626 * @hide
627 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700628 @SystemApi
629 @TestApi
Tyler Gunnc9503d62020-01-27 10:30:51 -0800630 @RequiresPermission(MODIFY_PHONE_STATE)
Tyler Gunn5567d742019-10-31 13:04:37 -0700631 public @NonNull Builder setGroupId(@NonNull String groupId) {
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700632 if (groupId != null) {
633 mGroupId = groupId;
634 } else {
635 mGroupId = "";
636 }
637 return this;
638 }
639
640 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800641 * Sets the audio routes supported by this {@link PhoneAccount}.
642 *
643 * @param routes bit mask of available routes.
644 * @return The builder.
645 * @hide
646 */
647 public Builder setSupportedAudioRoutes(int routes) {
648 mSupportedAudioRoutes = routes;
649 return this;
650 }
651
652 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700653 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
654 *
655 * @return The {@link PhoneAccount}.
656 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700657 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700658 // If no supported URI schemes were defined, assume "tel" is supported.
659 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700660 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700661 }
662
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700663 return new PhoneAccount(
664 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700665 mAddress,
666 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700667 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700668 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800669 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700670 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700671 mShortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700672 mSupportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700673 mExtras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800674 mSupportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700675 mIsEnabled,
676 mGroupId);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700677 }
678 }
679
680 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700681 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700682 Uri address,
683 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700684 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700685 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800686 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700687 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700688 CharSequence shortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700689 List<String> supportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700690 Bundle extras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800691 int supportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700692 boolean isEnabled,
693 String groupId) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700694 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700695 mAddress = address;
696 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700697 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700698 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800699 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700700 mLabel = label;
701 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700702 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700703 mExtras = extras;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800704 mSupportedAudioRoutes = supportedAudioRoutes;
Santos Cordon91371dc02015-05-08 13:52:09 -0700705 mIsEnabled = isEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700706 mGroupId = groupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700707 }
708
Andrew Lee3085a6c2014-09-04 10:59:13 -0700709 public static Builder builder(
710 PhoneAccountHandle accountHandle,
711 CharSequence label) {
712 return new Builder(accountHandle, label);
713 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700714
Ihab Awad807fe0a2014-07-09 12:30:52 -0700715 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700716 * Returns a builder initialized with the current {@link PhoneAccount} instance.
717 *
718 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700719 */
720 public Builder toBuilder() { return new Builder(this); }
721
722 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700723 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700724 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700725 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700726 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700727 public PhoneAccountHandle getAccountHandle() {
728 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700729 }
730
731 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700732 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700733 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700734 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700735 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700736 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700737 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700738 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700739 public Uri getAddress() {
740 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700741 }
742
743 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700744 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700745 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700746 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000747 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
748 * has been used to alter the callback number.
749 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700750 *
751 * @return The subscription number, suitable for display to the user.
752 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700753 public Uri getSubscriptionAddress() {
754 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700755 }
756
757 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700758 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700759 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700760 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700761 */
762 public int getCapabilities() {
763 return mCapabilities;
764 }
765
766 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700767 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
768 * bit mask.
769 *
770 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700771 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700772 */
773 public boolean hasCapabilities(int capability) {
774 return (mCapabilities & capability) == capability;
775 }
776
777 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800778 * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask.
779 *
780 * @param route The routes to check.
781 * @return {@code true} if the phone account has the routes.
782 * @hide
783 */
784 public boolean hasAudioRoutes(int routes) {
785 return (mSupportedAudioRoutes & routes) == routes;
786 }
787
788 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700789 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700790 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700791 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700792 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700793 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700794 return mLabel;
795 }
796
797 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700798 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700799 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700800 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700801 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700802 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700803 return mShortDescription;
804 }
805
806 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700807 * The URI schemes supported by this {@code PhoneAccount}.
808 *
809 * @return The URI schemes.
810 */
811 public List<String> getSupportedUriSchemes() {
812 return mSupportedUriSchemes;
813 }
814
815 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700816 * The extras associated with this {@code PhoneAccount}.
817 * <p>
818 * A {@link ConnectionService} may provide implementation specific information about the
819 * {@link PhoneAccount} via the extras.
820 *
821 * @return The extras.
822 */
823 public Bundle getExtras() {
824 return mExtras;
825 }
826
827 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800828 * The audio routes supported by this {@code PhoneAccount}.
829 *
830 * @hide
831 */
832 public int getSupportedAudioRoutes() {
833 return mSupportedAudioRoutes;
834 }
835
836 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700837 * The icon to represent this {@code PhoneAccount}.
838 *
839 * @return The icon.
840 */
841 public Icon getIcon() {
842 return mIcon;
843 }
844
845 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700846 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
847 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc02015-05-08 13:52:09 -0700848 *
Santos Cordon895d4b82015-06-25 16:41:48 -0700849 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc02015-05-08 13:52:09 -0700850 */
851 public boolean isEnabled() {
852 return mIsEnabled;
853 }
854
855 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700856 * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an
857 * empty {@link String} if the {@link PhoneAccount} is not in a group. If this
858 * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered
859 * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced,
860 * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}.
861 * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced.
862 *
863 * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group.
864 * @hide
865 */
866 public String getGroupId() {
867 return mGroupId;
868 }
869
870 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700871 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700872 * scheme.
873 *
874 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700875 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700876 * specified URI scheme.
877 */
878 public boolean supportsUriScheme(String uriScheme) {
879 if (mSupportedUriSchemes == null || uriScheme == null) {
880 return false;
881 }
882
883 for (String scheme : mSupportedUriSchemes) {
884 if (scheme != null && scheme.equals(uriScheme)) {
885 return true;
886 }
887 }
888 return false;
889 }
890
891 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800892 * A highlight color to use in displaying information about this {@code PhoneAccount}.
893 *
894 * @return A hexadecimal color value.
895 */
896 public int getHighlightColor() {
897 return mHighlightColor;
898 }
899
Santos Cordon91371dc02015-05-08 13:52:09 -0700900 /**
901 * Sets the enabled state of the phone account.
902 * @hide
903 */
904 public void setIsEnabled(boolean isEnabled) {
905 mIsEnabled = isEnabled;
906 }
907
Tyler Gunnf5035432017-01-09 09:43:12 -0800908 /**
909 * @return {@code true} if the {@link PhoneAccount} is self-managed, {@code false} otherwise.
910 * @hide
911 */
912 public boolean isSelfManaged() {
913 return (mCapabilities & CAPABILITY_SELF_MANAGED) == CAPABILITY_SELF_MANAGED;
914 }
915
Ihab Awad807fe0a2014-07-09 12:30:52 -0700916 //
917 // Parcelable implementation
918 //
919
920 @Override
921 public int describeContents() {
922 return 0;
923 }
924
925 @Override
926 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800927 if (mAccountHandle == null) {
928 out.writeInt(0);
929 } else {
930 out.writeInt(1);
931 mAccountHandle.writeToParcel(out, flags);
932 }
933 if (mAddress == null) {
934 out.writeInt(0);
935 } else {
936 out.writeInt(1);
937 mAddress.writeToParcel(out, flags);
938 }
939 if (mSubscriptionAddress == null) {
940 out.writeInt(0);
941 } else {
942 out.writeInt(1);
943 mSubscriptionAddress.writeToParcel(out, flags);
944 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700945 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800946 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700947 out.writeCharSequence(mLabel);
948 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800949 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc02015-05-08 13:52:09 -0700950
Santos Cordoncad84a22015-05-13 11:17:25 -0700951 if (mIcon == null) {
952 out.writeInt(0);
953 } else {
954 out.writeInt(1);
955 mIcon.writeToParcel(out, flags);
956 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700957 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Tyler Gunnef829ec2015-10-08 09:46:23 -0700958 out.writeBundle(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700959 out.writeString(mGroupId);
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800960 out.writeInt(mSupportedAudioRoutes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700961 }
962
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700963 public static final @android.annotation.NonNull Creator<PhoneAccount> CREATOR
Evan Charlton8c8a0622014-07-20 12:31:00 -0700964 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700965 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700966 public PhoneAccount createFromParcel(Parcel in) {
967 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700968 }
969
970 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700971 public PhoneAccount[] newArray(int size) {
972 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700973 }
974 };
975
Evan Charlton8c8a0622014-07-20 12:31:00 -0700976 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800977 if (in.readInt() > 0) {
978 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
979 } else {
980 mAccountHandle = null;
981 }
982 if (in.readInt() > 0) {
983 mAddress = Uri.CREATOR.createFromParcel(in);
984 } else {
985 mAddress = null;
986 }
987 if (in.readInt() > 0) {
988 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
989 } else {
990 mSubscriptionAddress = null;
991 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700992 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -0800993 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700994 mLabel = in.readCharSequence();
995 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800996 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -0700997 if (in.readInt() > 0) {
998 mIcon = Icon.CREATOR.createFromParcel(in);
999 } else {
1000 mIcon = null;
1001 }
Santos Cordon91371dc02015-05-08 13:52:09 -07001002 mIsEnabled = in.readByte() == 1;
Tyler Gunnef829ec2015-10-08 09:46:23 -07001003 mExtras = in.readBundle();
Brad Ebinger7298f3b2016-06-10 17:19:42 -07001004 mGroupId = in.readString();
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001005 mSupportedAudioRoutes = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -07001006 }
Tyler Gunn76c01a52014-09-30 14:47:51 -07001007
1008 @Override
1009 public String toString() {
Santos Cordon91371dc02015-05-08 13:52:09 -07001010 StringBuilder sb = new StringBuilder().append("[[")
1011 .append(mIsEnabled ? 'X' : ' ')
1012 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -07001013 .append(mAccountHandle)
1014 .append(" Capabilities: ")
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001015 .append(capabilitiesToString())
1016 .append(" Audio Routes: ")
1017 .append(audioRoutesToString())
Tyler Gunn76c01a52014-09-30 14:47:51 -07001018 .append(" Schemes: ");
1019 for (String scheme : mSupportedUriSchemes) {
1020 sb.append(scheme)
1021 .append(" ");
1022 }
Tyler Gunnef829ec2015-10-08 09:46:23 -07001023 sb.append(" Extras: ");
Tyler Gunn25ed2d72015-10-05 14:14:38 -07001024 sb.append(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -07001025 sb.append(" GroupId: ");
1026 sb.append(Log.pii(mGroupId));
Tyler Gunn76c01a52014-09-30 14:47:51 -07001027 sb.append("]");
1028 return sb.toString();
1029 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001030
1031 /**
1032 * Generates a string representation of a capabilities bitmask.
1033 *
Tyler Gunn3e122f72016-01-11 19:25:00 -08001034 * @return String representation of the capabilities bitmask.
Tyler Gunn1847b4e2018-11-09 08:43:02 -08001035 * @hide
Tyler Gunn3e122f72016-01-11 19:25:00 -08001036 */
Tyler Gunn1847b4e2018-11-09 08:43:02 -08001037 public String capabilitiesToString() {
Tyler Gunn3e122f72016-01-11 19:25:00 -08001038 StringBuilder sb = new StringBuilder();
Tyler Gunnf5035432017-01-09 09:43:12 -08001039 if (hasCapabilities(CAPABILITY_SELF_MANAGED)) {
1040 sb.append("SelfManaged ");
1041 }
Tyler Gunn58cbd7a2016-11-11 11:31:28 -08001042 if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) {
1043 sb.append("SuppVideo ");
1044 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001045 if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) {
1046 sb.append("Video ");
1047 }
1048 if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
1049 sb.append("Presence ");
1050 }
1051 if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) {
1052 sb.append("CallProvider ");
1053 }
1054 if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) {
1055 sb.append("CallSubject ");
1056 }
1057 if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) {
1058 sb.append("ConnectionMgr ");
1059 }
1060 if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) {
1061 sb.append("EmergOnly ");
1062 }
1063 if (hasCapabilities(CAPABILITY_MULTI_USER)) {
1064 sb.append("MultiUser ");
1065 }
1066 if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) {
1067 sb.append("PlaceEmerg ");
1068 }
Brad Ebinger3636d742019-05-21 15:28:19 -07001069 if (hasCapabilities(CAPABILITY_EMERGENCY_PREFERRED)) {
1070 sb.append("EmerPrefer ");
1071 }
Tyler Gunncee9ea62016-03-24 11:45:43 -07001072 if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
1073 sb.append("EmergVideo ");
1074 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001075 if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) {
1076 sb.append("SimSub ");
1077 }
Hall Liu47ed6202017-11-20 16:25:39 -08001078 if (hasCapabilities(CAPABILITY_RTT)) {
1079 sb.append("Rtt");
1080 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05301081 if (hasCapabilities(CAPABILITY_ADHOC_CONFERENCE_CALLING)) {
1082 sb.append("AdhocConf");
1083 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001084 return sb.toString();
1085 }
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001086
1087 private String audioRoutesToString() {
1088 StringBuilder sb = new StringBuilder();
1089
1090 if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) {
1091 sb.append("B");
1092 }
1093 if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) {
1094 sb.append("E");
1095 }
1096 if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) {
1097 sb.append("S");
1098 }
1099 if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) {
1100 sb.append("W");
1101 }
1102
1103 return sb.toString();
1104 }
Tyler Gunn3b347812018-08-24 14:17:05 -07001105
1106 /**
1107 * Determines if two {@link Bundle}s are equal.
1108 * @param extras First {@link Bundle} to check.
1109 * @param newExtras {@link Bundle} to compare against.
1110 * @return {@code true} if the {@link Bundle}s are equal, {@code false} otherwise.
1111 */
1112 private static boolean areBundlesEqual(Bundle extras, Bundle newExtras) {
1113 if (extras == null || newExtras == null) {
1114 return extras == newExtras;
1115 }
1116
1117 if (extras.size() != newExtras.size()) {
1118 return false;
1119 }
1120
1121 for(String key : extras.keySet()) {
1122 if (key != null) {
1123 final Object value = extras.get(key);
1124 final Object newValue = newExtras.get(key);
1125 if (!Objects.equals(value, newValue)) {
1126 return false;
1127 }
1128 }
1129 }
1130 return true;
1131 }
Ihab Awad807fe0a2014-07-09 12:30:52 -07001132}