blob: bb858cb0761bde2cd473dace47e003e259766bb7 [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 Gunn5567d742019-10-31 13:04:37 -070019import android.annotation.NonNull;
Evan Charlton0e094d92014-11-08 15:49:16 -080020import android.annotation.SystemApi;
Tyler Gunn5567d742019-10-31 13:04:37 -070021import android.annotation.TestApi;
Brad Ebinger3636d742019-05-21 15:28:19 -070022import android.content.Intent;
Santos Cordoncad84a22015-05-13 11:17:25 -070023import android.graphics.drawable.Icon;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070024import android.net.Uri;
Tyler Gunn25ed2d72015-10-05 14:14:38 -070025import android.os.Bundle;
Ihab Awad807fe0a2014-07-09 12:30:52 -070026import android.os.Parcel;
27import android.os.Parcelable;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070028import android.text.TextUtils;
Ihab Awad807fe0a2014-07-09 12:30:52 -070029
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070030import java.util.ArrayList;
31import java.util.Collections;
32import java.util.List;
Tyler Gunn3b347812018-08-24 14:17:05 -070033import java.util.Objects;
Ihab Awad807fe0a2014-07-09 12:30:52 -070034
35/**
Santos Cordon32c65a52014-10-27 14:57:49 -070036 * Represents a distinct method to place or receive a phone call. Apps which can place calls and
37 * 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 -080038 * this class and register it with the system using {@link TelecomManager}.
Santos Cordon32c65a52014-10-27 14:57:49 -070039 * <p>
40 * {@link TelecomManager} uses registered {@link PhoneAccount}s to present the user with
41 * alternative options when placing a phone call. When building a {@link PhoneAccount}, the app
Brian Attwellad147f42014-12-19 11:37:16 -080042 * should supply a valid {@link PhoneAccountHandle} that references the connection service
Santos Cordon32c65a52014-10-27 14:57:49 -070043 * implementation Telecom will use to interact with the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -070044 */
Yorke Lee400470f2015-05-12 13:31:25 -070045public final class PhoneAccount implements Parcelable {
Ihab Awad94cf4bf2014-07-17 11:21:19 -070046
47 /**
Tyler Gunnd426b202015-10-13 13:33:53 -070048 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
Srikanth Chintala62428402017-03-27 19:27:52 +053049 * sort order for {@link PhoneAccount}s from the same
50 * {@link android.telecom.ConnectionService}.
51 * @hide
52 */
53 public static final String EXTRA_SORT_ORDER =
54 "android.telecom.extra.SORT_ORDER";
55
56 /**
57 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
Tyler Gunnd426b202015-10-13 13:33:53 -070058 * maximum permitted length of a call subject specified via the
59 * {@link TelecomManager#EXTRA_CALL_SUBJECT} extra on an
60 * {@link android.content.Intent#ACTION_CALL} intent. Ultimately a {@link ConnectionService} is
61 * responsible for enforcing the maximum call subject length when sending the message, however
62 * this extra is provided so that the user interface can proactively limit the length of the
63 * call subject as the user types it.
64 */
65 public static final String EXTRA_CALL_SUBJECT_MAX_LENGTH =
66 "android.telecom.extra.CALL_SUBJECT_MAX_LENGTH";
67
68 /**
69 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
70 * character encoding to be used when determining the length of messages.
71 * The user interface can use this when determining the number of characters the user may type
72 * in a call subject. If empty-string, the call subject message size limit will be enforced on
73 * a 1:1 basis. That is, each character will count towards the messages size limit as a single
74 * character. If a character encoding is specified, the message size limit will be based on the
75 * number of bytes in the message per the specified encoding. See
76 * {@link #EXTRA_CALL_SUBJECT_MAX_LENGTH} for more information on the call subject maximum
77 * length.
78 */
79 public static final String EXTRA_CALL_SUBJECT_CHARACTER_ENCODING =
80 "android.telecom.extra.CALL_SUBJECT_CHARACTER_ENCODING";
81
Srikanth Chintalaf77d4a12017-04-03 18:08:14 +053082 /**
83 * Indicating flag for phone account whether to use voip audio mode for voip calls
84 * @hide
85 */
86 public static final String EXTRA_ALWAYS_USE_VOIP_AUDIO_MODE =
87 "android.telecom.extra.ALWAYS_USE_VOIP_AUDIO_MODE";
88
Tyler Gunnd426b202015-10-13 13:33:53 -070089 /**
Tyler Gunn8bf76572017-04-06 15:30:08 -070090 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
91 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
Sanket Padawea8eddd42017-11-03 11:07:35 -070092 * connection (see {@code android.telecom.Call#handoverTo()}) to this {@link PhoneAccount} from
93 * a {@link PhoneAccount} specifying {@link #EXTRA_SUPPORTS_HANDOVER_FROM}.
Tyler Gunn8bf76572017-04-06 15:30:08 -070094 * <p>
95 * A handover request is initiated by the user from the default dialer app to indicate a desire
96 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
Tyler Gunn8bf76572017-04-06 15:30:08 -070097 */
98 public static final String EXTRA_SUPPORTS_HANDOVER_TO =
99 "android.telecom.extra.SUPPORTS_HANDOVER_TO";
100
101 /**
102 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Ta-wei Yen9d20d982017-06-02 11:07:07 -0700103 * indicates whether this {@link PhoneAccount} supports using a fallback if video calling is
104 * not available. This extra is for device level support, {@link
105 * android.telephony.CarrierConfigManager#KEY_ALLOW_VIDEO_CALLING_FALLBACK_BOOL} should also
106 * be checked to ensure it is not disabled by individual carrier.
107 *
108 * @hide
109 */
110 public static final String EXTRA_SUPPORTS_VIDEO_CALLING_FALLBACK =
111 "android.telecom.extra.SUPPORTS_VIDEO_CALLING_FALLBACK";
112
113 /**
114 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Tyler Gunn8bf76572017-04-06 15:30:08 -0700115 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
116 * connection from this {@link PhoneAccount} to another {@link PhoneAccount}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700117 * (see {@code android.telecom.Call#handoverTo()}) which specifies
Tyler Gunn8bf76572017-04-06 15:30:08 -0700118 * {@link #EXTRA_SUPPORTS_HANDOVER_TO}.
119 * <p>
120 * A handover request is initiated by the user from the default dialer app to indicate a desire
121 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700122 */
123 public static final String EXTRA_SUPPORTS_HANDOVER_FROM =
124 "android.telecom.extra.SUPPORTS_HANDOVER_FROM";
125
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700126
127 /**
128 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
129 * indicates whether a Self-Managed {@link PhoneAccount} should log its calls to the call log.
Brad Ebingerbb1a55f2017-06-26 13:26:14 -0700130 * Self-Managed {@link PhoneAccount}s are responsible for their own notifications, so the system
131 * will not create a notification when a missed call is logged.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700132 * <p>
133 * By default, Self-Managed {@link PhoneAccount}s do not log their calls to the call log.
134 * Setting this extra to {@code true} provides a means for them to log their calls.
Tyler Gunn2155c4c2018-04-05 09:43:41 -0700135 * <p>
136 * Note: Only calls where the {@link Call.Details#getHandle()} {@link Uri#getScheme()} is
137 * {@link #SCHEME_SIP} or {@link #SCHEME_TEL} will be logged at the current time.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700138 */
139 public static final String EXTRA_LOG_SELF_MANAGED_CALLS =
140 "android.telecom.extra.LOG_SELF_MANAGED_CALLS";
141
Tyler Gunn8bf76572017-04-06 15:30:08 -0700142 /**
Tyler Gunnacdb6862018-01-29 14:30:52 -0800143 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
144 * indicates whether calls for a {@link PhoneAccount} should generate a "call recording tone"
145 * when the user is recording audio on the device.
146 * <p>
147 * The call recording tone is played over the telephony audio stream so that the remote party
148 * has an audible indication that it is possible their call is being recorded using a call
149 * recording app on the device.
150 * <p>
151 * This extra only has an effect for calls placed via Telephony (e.g.
152 * {@link #CAPABILITY_SIM_SUBSCRIPTION}).
153 * <p>
154 * The call recording tone is a 1400 hz tone which repeats every 15 seconds while recording is
155 * in progress.
156 * @hide
157 */
158 public static final String EXTRA_PLAY_CALL_RECORDING_TONE =
159 "android.telecom.extra.PLAY_CALL_RECORDING_TONE";
160
161 /**
Sean Kelley4d3c1782018-05-22 14:35:27 -0700162 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()} which
163 * indicates whether calls for a {@link PhoneAccount} should skip call filtering.
164 * <p>
165 * If not specified, this will default to false; all calls will undergo call filtering unless
166 * specifically exempted (e.g. {@link Connection#PROPERTY_EMERGENCY_CALLBACK_MODE}.) However,
167 * this may be used to skip call filtering when it has already been performed on another device.
168 * @hide
169 */
170 public static final String EXTRA_SKIP_CALL_FILTERING =
171 "android.telecom.extra.SKIP_CALL_FILTERING";
172
173 /**
Ihab Awadf8b69882014-07-25 15:14:01 -0700174 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
175 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
176 * will be allowed to manage phone calls including using its own proprietary phone-call
177 * implementation (like VoIP calling) to make calls instead of the telephony stack.
178 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700179 * When a user opts to place a call using the SIM-based telephony stack, the
180 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
181 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700182 * <p>
183 * See {@link #getCapabilities}
184 */
Ihab Awadf8b69882014-07-25 15:14:01 -0700185 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700186
187 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700188 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -0700189 * traditional SIM-based telephony calls. This account will be treated as a distinct method
190 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -0700191 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -0700192 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700193 * <p>
194 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700195 * <p>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700196 */
197 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
198
Ihab Awad7522bbd62014-07-18 15:53:17 -0700199 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700200 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -0700201 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -0700202 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700203 * Only the Android framework can register a {@code PhoneAccount} having this capability.
204 * <p>
205 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -0700206 */
207 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
208
Ihab Awadf8b69882014-07-25 15:14:01 -0700209 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800210 * Flag indicating that this {@code PhoneAccount} is currently able to place video calls.
211 * <p>
212 * See also {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING} which indicates whether the
213 * {@code PhoneAccount} supports placing video calls.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700214 * <p>
215 * See {@link #getCapabilities}
Ihab Awadf8b69882014-07-25 15:14:01 -0700216 */
217 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
218
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700219 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700220 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
221 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
222 * <p>
223 * See {@link #getCapabilities}
224 */
225 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
226
227 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800228 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
229 * should only be used by system apps (and will be ignored for all other apps trying to use it).
230 * <p>
231 * See {@link #getCapabilities}
232 * @hide
233 */
Brian Attwellad147f42014-12-19 11:37:16 -0800234 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800235 public static final int CAPABILITY_MULTI_USER = 0x20;
236
237 /**
Tyler Gunn65a3d342015-07-27 16:06:16 -0700238 * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a
239 * caller is able to specify a short subject line for an outgoing call. A capable receiving
240 * device displays the call subject on the incoming call screen.
241 * <p>
242 * See {@link #getCapabilities}
243 */
244 public static final int CAPABILITY_CALL_SUBJECT = 0x40;
245
246 /**
Bryce Leeb96d89c2015-10-14 16:48:40 -0700247 * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls.
248 * <p>
249 * See {@link #getCapabilities}
250 * @hide
251 */
252 public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80;
253
254 /**
Tyler Gunn9a365752015-12-09 15:00:18 -0800255 * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a
256 * number relies on presence. Should only be set if the {@code PhoneAccount} also has
257 * {@link #CAPABILITY_VIDEO_CALLING}.
258 * <p>
259 * When set, the {@link ConnectionService} is responsible for toggling the
260 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the
261 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether
262 * a contact's phone number supports video calling.
263 * <p>
264 * See {@link #getCapabilities}
265 */
266 public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100;
267
268 /**
Tyler Gunncee9ea62016-03-24 11:45:43 -0700269 * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed.
270 * <p>
271 * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will
272 * convert all outgoing video calls to emergency numbers to audio-only.
273 * @hide
274 */
275 public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200;
276
277 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800278 * Flag indicating that this {@link PhoneAccount} supports video calling.
279 * This is not an indication that the {@link PhoneAccount} is currently able to make a video
280 * call, but rather that it has the ability to make video calls (but not necessarily at this
281 * time).
282 * <p>
283 * Whether a {@link PhoneAccount} can make a video call is ultimately controlled by
284 * {@link #CAPABILITY_VIDEO_CALLING}, which indicates whether the {@link PhoneAccount} is
285 * currently capable of making a video call. Consider a case where, for example, a
286 * {@link PhoneAccount} supports making video calls (e.g.
287 * {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING}), but a current lack of network connectivity
288 * prevents video calls from being made (e.g. {@link #CAPABILITY_VIDEO_CALLING}).
289 * <p>
290 * See {@link #getCapabilities}
291 */
292 public static final int CAPABILITY_SUPPORTS_VIDEO_CALLING = 0x400;
293
294 /**
Tyler Gunnf5035432017-01-09 09:43:12 -0800295 * Flag indicating that this {@link PhoneAccount} is responsible for managing its own
296 * {@link Connection}s. This type of {@link PhoneAccount} is ideal for use with standalone
297 * calling apps which do not wish to use the default phone app for {@link Connection} UX,
298 * but which want to leverage the call and audio routing capabilities of the Telecom framework.
299 * <p>
300 * When set, {@link Connection}s created by the self-managed {@link ConnectionService} will not
301 * be surfaced to implementations of the {@link InCallService} API. Thus it is the
302 * responsibility of a self-managed {@link ConnectionService} to provide a user interface for
303 * its {@link Connection}s.
304 * <p>
305 * Self-managed {@link Connection}s will, however, be displayed on connected Bluetooth devices.
306 */
307 public static final int CAPABILITY_SELF_MANAGED = 0x800;
308
309 /**
Hall Liu95d55872017-01-25 17:12:49 -0800310 * Flag indicating that this {@link PhoneAccount} is capable of making a call with an
311 * RTT (Real-time text) session.
312 * When set, Telecom will attempt to open an RTT session on outgoing calls that specify
313 * that they should be placed with an RTT session , and the in-call app will be displayed
314 * with text entry fields for RTT. Likewise, the in-call app can request that an RTT
315 * session be opened during a call if this bit is set.
316 */
317 public static final int CAPABILITY_RTT = 0x1000;
318
Brad Ebinger3636d742019-05-21 15:28:19 -0700319 /**
320 * Flag indicating that this {@link PhoneAccount} is the preferred SIM subscription for
321 * emergency calls. A {@link PhoneAccount} that sets this capabilitiy must also
322 * set the {@link #CAPABILITY_SIM_SUBSCRIPTION} and {@link #CAPABILITY_PLACE_EMERGENCY_CALLS}
323 * capabilities. There should only be one emergency preferred {@link PhoneAccount}.
324 * <p>
325 * When set, Telecom will prefer this {@link PhoneAccount} over others for emergency calling,
326 * even if the emergency call was placed with a specific {@link PhoneAccount} set using the
327 * extra{@link TelecomManager#EXTRA_PHONE_ACCOUNT_HANDLE} in
328 * {@link Intent#ACTION_CALL_EMERGENCY} or {@link TelecomManager#placeCall(Uri, Bundle)}.
329 *
330 * @hide
331 */
332 public static final int CAPABILITY_EMERGENCY_PREFERRED = 0x2000;
333
334 /* NEXT CAPABILITY: 0x4000 */
Hall Liu95d55872017-01-25 17:12:49 -0800335
336 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700337 * URI scheme for telephone number URIs.
338 */
339 public static final String SCHEME_TEL = "tel";
340
341 /**
342 * URI scheme for voicemail URIs.
343 */
344 public static final String SCHEME_VOICEMAIL = "voicemail";
345
346 /**
347 * URI scheme for SIP URIs.
348 */
349 public static final String SCHEME_SIP = "sip";
350
Nancy Chen3ace54b2014-10-22 17:45:26 -0700351 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800352 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700353 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700354 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800355 public static final int NO_ICON_TINT = 0;
356
357 /**
358 * Indicating no hightlight color is set.
359 */
360 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700361
Ihab Awad476cc832014-11-03 09:47:51 -0800362 /**
363 * Indicating no resource ID is set.
364 */
365 public static final int NO_RESOURCE_ID = -1;
366
Evan Charlton8c8a0622014-07-20 12:31:00 -0700367 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700368 private final Uri mAddress;
369 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700370 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800371 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700372 private final CharSequence mLabel;
373 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700374 private final List<String> mSupportedUriSchemes;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800375 private final int mSupportedAudioRoutes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700376 private final Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700377 private final Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700378 private boolean mIsEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700379 private String mGroupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700380
Tyler Gunn3b347812018-08-24 14:17:05 -0700381 @Override
382 public boolean equals(Object o) {
383 if (this == o) return true;
384 if (o == null || getClass() != o.getClass()) return false;
385 PhoneAccount that = (PhoneAccount) o;
386 return mCapabilities == that.mCapabilities &&
387 mHighlightColor == that.mHighlightColor &&
388 mSupportedAudioRoutes == that.mSupportedAudioRoutes &&
389 mIsEnabled == that.mIsEnabled &&
390 Objects.equals(mAccountHandle, that.mAccountHandle) &&
391 Objects.equals(mAddress, that.mAddress) &&
392 Objects.equals(mSubscriptionAddress, that.mSubscriptionAddress) &&
393 Objects.equals(mLabel, that.mLabel) &&
394 Objects.equals(mShortDescription, that.mShortDescription) &&
395 Objects.equals(mSupportedUriSchemes, that.mSupportedUriSchemes) &&
396 areBundlesEqual(mExtras, that.mExtras) &&
397 Objects.equals(mGroupId, that.mGroupId);
398 }
399
400 @Override
401 public int hashCode() {
402 return Objects.hash(mAccountHandle, mAddress, mSubscriptionAddress, mCapabilities,
403 mHighlightColor, mLabel, mShortDescription, mSupportedUriSchemes,
404 mSupportedAudioRoutes,
405 mExtras, mIsEnabled, mGroupId);
406 }
407
Santos Cordon32c65a52014-10-27 14:57:49 -0700408 /**
409 * Helper class for creating a {@link PhoneAccount}.
410 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700411 public static class Builder {
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800412
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700413 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700414 private Uri mAddress;
415 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700416 private int mCapabilities;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800417 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800418 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700419 private CharSequence mLabel;
420 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700421 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700422 private Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700423 private Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700424 private boolean mIsEnabled = false;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700425 private String mGroupId = "";
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700426
Santos Cordon32c65a52014-10-27 14:57:49 -0700427 /**
428 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
429 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700430 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
431 this.mAccountHandle = accountHandle;
432 this.mLabel = label;
433 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700434
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700435 /**
436 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
437 * {@link PhoneAccount}.
438 *
439 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
440 */
441 public Builder(PhoneAccount phoneAccount) {
442 mAccountHandle = phoneAccount.getAccountHandle();
443 mAddress = phoneAccount.getAddress();
444 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
445 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800446 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700447 mLabel = phoneAccount.getLabel();
448 mShortDescription = phoneAccount.getShortDescription();
449 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700450 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc02015-05-08 13:52:09 -0700451 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunnd426b202015-10-13 13:33:53 -0700452 mExtras = phoneAccount.getExtras();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700453 mGroupId = phoneAccount.getGroupId();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800454 mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700455 }
456
Santos Cordon32c65a52014-10-27 14:57:49 -0700457 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700458 * Sets the label. See {@link PhoneAccount#getLabel()}.
459 *
460 * @param label The label of the phone account.
461 * @return The builder.
462 * @hide
463 */
464 public Builder setLabel(CharSequence label) {
465 this.mLabel = label;
466 return this;
467 }
468
469 /**
Santos Cordon32c65a52014-10-27 14:57:49 -0700470 * Sets the address. See {@link PhoneAccount#getAddress}.
471 *
472 * @param value The address of the phone account.
473 * @return The builder.
474 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700475 public Builder setAddress(Uri value) {
476 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700477 return this;
478 }
479
Santos Cordon32c65a52014-10-27 14:57:49 -0700480 /**
481 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
482 *
483 * @param value The subscription address.
484 * @return The builder.
485 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700486 public Builder setSubscriptionAddress(Uri value) {
487 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700488 return this;
489 }
490
Santos Cordon32c65a52014-10-27 14:57:49 -0700491 /**
492 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
493 *
494 * @param value The capabilities to set.
495 * @return The builder.
496 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700497 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700498 this.mCapabilities = value;
499 return this;
500 }
501
Santos Cordon32c65a52014-10-27 14:57:49 -0700502 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700503 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700504 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700505 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700506 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700507 public Builder setIcon(Icon icon) {
508 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700509 return this;
510 }
511
512 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800513 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700514 *
Ihab Awad476cc832014-11-03 09:47:51 -0800515 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700516 * @return The builder.
517 */
Ihab Awad476cc832014-11-03 09:47:51 -0800518 public Builder setHighlightColor(int value) {
519 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700520 return this;
521 }
522
Santos Cordon32c65a52014-10-27 14:57:49 -0700523 /**
524 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
525 *
526 * @param value The short description.
527 * @return The builder.
528 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700529 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700530 this.mShortDescription = value;
531 return this;
532 }
533
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700534 /**
535 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
536 *
537 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700538 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700539 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700540 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700541 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
542 this.mSupportedUriSchemes.add(uriScheme);
543 }
544 return this;
545 }
546
547 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700548 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700549 *
550 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700551 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700552 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700553 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
554 mSupportedUriSchemes.clear();
555
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700556 if (uriSchemes != null && !uriSchemes.isEmpty()) {
557 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700558 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700559 }
560 }
561 return this;
562 }
563
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700564 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700565 * Specifies the extras associated with the {@link PhoneAccount}.
566 * <p>
567 * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer},
568 * and {@link Boolean}. Extras which are not of these types are ignored.
569 *
570 * @param extras
571 * @return
572 */
573 public Builder setExtras(Bundle extras) {
574 mExtras = extras;
575 return this;
576 }
577
578 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700579 * Sets the enabled state of the phone account.
580 *
581 * @param isEnabled The enabled state.
582 * @return The builder.
583 * @hide
584 */
585 public Builder setIsEnabled(boolean isEnabled) {
586 mIsEnabled = isEnabled;
587 return this;
588 }
589
590 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700591 * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is
592 * registered to Telecom, it will replace another {@link PhoneAccount} that is already
593 * registered in Telecom and take on the current user defaults and enabled status. There can
594 * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a
595 * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only
596 * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced.
Tyler Gunn5567d742019-10-31 13:04:37 -0700597 * <p>
598 * Note: This is an API specific to the Telephony stack.
599 *
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700600 * @param groupId The group Id of the {@link PhoneAccount} that will replace any other
601 * registered {@link PhoneAccount} in Telecom with the same Group Id.
602 * @return The builder
603 * @hide
604 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700605 @SystemApi
606 @TestApi
607 public @NonNull Builder setGroupId(@NonNull String groupId) {
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700608 if (groupId != null) {
609 mGroupId = groupId;
610 } else {
611 mGroupId = "";
612 }
613 return this;
614 }
615
616 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800617 * Sets the audio routes supported by this {@link PhoneAccount}.
618 *
619 * @param routes bit mask of available routes.
620 * @return The builder.
621 * @hide
622 */
623 public Builder setSupportedAudioRoutes(int routes) {
624 mSupportedAudioRoutes = routes;
625 return this;
626 }
627
628 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700629 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
630 *
631 * @return The {@link PhoneAccount}.
632 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700633 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700634 // If no supported URI schemes were defined, assume "tel" is supported.
635 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700636 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700637 }
638
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700639 return new PhoneAccount(
640 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700641 mAddress,
642 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700643 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700644 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800645 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700646 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700647 mShortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700648 mSupportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700649 mExtras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800650 mSupportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700651 mIsEnabled,
652 mGroupId);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700653 }
654 }
655
656 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700657 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700658 Uri address,
659 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700660 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700661 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800662 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700663 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700664 CharSequence shortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700665 List<String> supportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700666 Bundle extras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800667 int supportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700668 boolean isEnabled,
669 String groupId) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700670 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700671 mAddress = address;
672 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700673 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700674 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800675 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700676 mLabel = label;
677 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700678 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700679 mExtras = extras;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800680 mSupportedAudioRoutes = supportedAudioRoutes;
Santos Cordon91371dc02015-05-08 13:52:09 -0700681 mIsEnabled = isEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700682 mGroupId = groupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700683 }
684
Andrew Lee3085a6c2014-09-04 10:59:13 -0700685 public static Builder builder(
686 PhoneAccountHandle accountHandle,
687 CharSequence label) {
688 return new Builder(accountHandle, label);
689 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700690
Ihab Awad807fe0a2014-07-09 12:30:52 -0700691 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700692 * Returns a builder initialized with the current {@link PhoneAccount} instance.
693 *
694 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700695 */
696 public Builder toBuilder() { return new Builder(this); }
697
698 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700699 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700700 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700701 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700702 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700703 public PhoneAccountHandle getAccountHandle() {
704 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700705 }
706
707 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700708 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700709 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700710 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700711 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700712 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700713 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700714 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700715 public Uri getAddress() {
716 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700717 }
718
719 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700720 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700721 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700722 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000723 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
724 * has been used to alter the callback number.
725 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700726 *
727 * @return The subscription number, suitable for display to the user.
728 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700729 public Uri getSubscriptionAddress() {
730 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700731 }
732
733 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700734 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700735 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700736 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700737 */
738 public int getCapabilities() {
739 return mCapabilities;
740 }
741
742 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700743 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
744 * bit mask.
745 *
746 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700747 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700748 */
749 public boolean hasCapabilities(int capability) {
750 return (mCapabilities & capability) == capability;
751 }
752
753 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800754 * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask.
755 *
756 * @param route The routes to check.
757 * @return {@code true} if the phone account has the routes.
758 * @hide
759 */
760 public boolean hasAudioRoutes(int routes) {
761 return (mSupportedAudioRoutes & routes) == routes;
762 }
763
764 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700765 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700766 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700767 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700768 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700769 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700770 return mLabel;
771 }
772
773 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700774 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700775 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700776 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700777 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700778 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700779 return mShortDescription;
780 }
781
782 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700783 * The URI schemes supported by this {@code PhoneAccount}.
784 *
785 * @return The URI schemes.
786 */
787 public List<String> getSupportedUriSchemes() {
788 return mSupportedUriSchemes;
789 }
790
791 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700792 * The extras associated with this {@code PhoneAccount}.
793 * <p>
794 * A {@link ConnectionService} may provide implementation specific information about the
795 * {@link PhoneAccount} via the extras.
796 *
797 * @return The extras.
798 */
799 public Bundle getExtras() {
800 return mExtras;
801 }
802
803 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800804 * The audio routes supported by this {@code PhoneAccount}.
805 *
806 * @hide
807 */
808 public int getSupportedAudioRoutes() {
809 return mSupportedAudioRoutes;
810 }
811
812 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700813 * The icon to represent this {@code PhoneAccount}.
814 *
815 * @return The icon.
816 */
817 public Icon getIcon() {
818 return mIcon;
819 }
820
821 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700822 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
823 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc02015-05-08 13:52:09 -0700824 *
Santos Cordon895d4b82015-06-25 16:41:48 -0700825 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc02015-05-08 13:52:09 -0700826 */
827 public boolean isEnabled() {
828 return mIsEnabled;
829 }
830
831 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700832 * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an
833 * empty {@link String} if the {@link PhoneAccount} is not in a group. If this
834 * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered
835 * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced,
836 * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}.
837 * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced.
838 *
839 * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group.
840 * @hide
841 */
842 public String getGroupId() {
843 return mGroupId;
844 }
845
846 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700847 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700848 * scheme.
849 *
850 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700851 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700852 * specified URI scheme.
853 */
854 public boolean supportsUriScheme(String uriScheme) {
855 if (mSupportedUriSchemes == null || uriScheme == null) {
856 return false;
857 }
858
859 for (String scheme : mSupportedUriSchemes) {
860 if (scheme != null && scheme.equals(uriScheme)) {
861 return true;
862 }
863 }
864 return false;
865 }
866
867 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800868 * A highlight color to use in displaying information about this {@code PhoneAccount}.
869 *
870 * @return A hexadecimal color value.
871 */
872 public int getHighlightColor() {
873 return mHighlightColor;
874 }
875
Santos Cordon91371dc02015-05-08 13:52:09 -0700876 /**
877 * Sets the enabled state of the phone account.
878 * @hide
879 */
880 public void setIsEnabled(boolean isEnabled) {
881 mIsEnabled = isEnabled;
882 }
883
Tyler Gunnf5035432017-01-09 09:43:12 -0800884 /**
885 * @return {@code true} if the {@link PhoneAccount} is self-managed, {@code false} otherwise.
886 * @hide
887 */
888 public boolean isSelfManaged() {
889 return (mCapabilities & CAPABILITY_SELF_MANAGED) == CAPABILITY_SELF_MANAGED;
890 }
891
Ihab Awad807fe0a2014-07-09 12:30:52 -0700892 //
893 // Parcelable implementation
894 //
895
896 @Override
897 public int describeContents() {
898 return 0;
899 }
900
901 @Override
902 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800903 if (mAccountHandle == null) {
904 out.writeInt(0);
905 } else {
906 out.writeInt(1);
907 mAccountHandle.writeToParcel(out, flags);
908 }
909 if (mAddress == null) {
910 out.writeInt(0);
911 } else {
912 out.writeInt(1);
913 mAddress.writeToParcel(out, flags);
914 }
915 if (mSubscriptionAddress == null) {
916 out.writeInt(0);
917 } else {
918 out.writeInt(1);
919 mSubscriptionAddress.writeToParcel(out, flags);
920 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700921 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800922 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700923 out.writeCharSequence(mLabel);
924 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800925 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc02015-05-08 13:52:09 -0700926
Santos Cordoncad84a22015-05-13 11:17:25 -0700927 if (mIcon == null) {
928 out.writeInt(0);
929 } else {
930 out.writeInt(1);
931 mIcon.writeToParcel(out, flags);
932 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700933 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Tyler Gunnef829ec2015-10-08 09:46:23 -0700934 out.writeBundle(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700935 out.writeString(mGroupId);
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800936 out.writeInt(mSupportedAudioRoutes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700937 }
938
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700939 public static final @android.annotation.NonNull Creator<PhoneAccount> CREATOR
Evan Charlton8c8a0622014-07-20 12:31:00 -0700940 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700941 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700942 public PhoneAccount createFromParcel(Parcel in) {
943 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700944 }
945
946 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700947 public PhoneAccount[] newArray(int size) {
948 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700949 }
950 };
951
Evan Charlton8c8a0622014-07-20 12:31:00 -0700952 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800953 if (in.readInt() > 0) {
954 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
955 } else {
956 mAccountHandle = null;
957 }
958 if (in.readInt() > 0) {
959 mAddress = Uri.CREATOR.createFromParcel(in);
960 } else {
961 mAddress = null;
962 }
963 if (in.readInt() > 0) {
964 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
965 } else {
966 mSubscriptionAddress = null;
967 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700968 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -0800969 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700970 mLabel = in.readCharSequence();
971 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800972 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -0700973 if (in.readInt() > 0) {
974 mIcon = Icon.CREATOR.createFromParcel(in);
975 } else {
976 mIcon = null;
977 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700978 mIsEnabled = in.readByte() == 1;
Tyler Gunnef829ec2015-10-08 09:46:23 -0700979 mExtras = in.readBundle();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700980 mGroupId = in.readString();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800981 mSupportedAudioRoutes = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700982 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700983
984 @Override
985 public String toString() {
Santos Cordon91371dc02015-05-08 13:52:09 -0700986 StringBuilder sb = new StringBuilder().append("[[")
987 .append(mIsEnabled ? 'X' : ' ')
988 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700989 .append(mAccountHandle)
990 .append(" Capabilities: ")
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800991 .append(capabilitiesToString())
992 .append(" Audio Routes: ")
993 .append(audioRoutesToString())
Tyler Gunn76c01a52014-09-30 14:47:51 -0700994 .append(" Schemes: ");
995 for (String scheme : mSupportedUriSchemes) {
996 sb.append(scheme)
997 .append(" ");
998 }
Tyler Gunnef829ec2015-10-08 09:46:23 -0700999 sb.append(" Extras: ");
Tyler Gunn25ed2d72015-10-05 14:14:38 -07001000 sb.append(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -07001001 sb.append(" GroupId: ");
1002 sb.append(Log.pii(mGroupId));
Tyler Gunn76c01a52014-09-30 14:47:51 -07001003 sb.append("]");
1004 return sb.toString();
1005 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001006
1007 /**
1008 * Generates a string representation of a capabilities bitmask.
1009 *
Tyler Gunn3e122f72016-01-11 19:25:00 -08001010 * @return String representation of the capabilities bitmask.
Tyler Gunn1847b4e2018-11-09 08:43:02 -08001011 * @hide
Tyler Gunn3e122f72016-01-11 19:25:00 -08001012 */
Tyler Gunn1847b4e2018-11-09 08:43:02 -08001013 public String capabilitiesToString() {
Tyler Gunn3e122f72016-01-11 19:25:00 -08001014 StringBuilder sb = new StringBuilder();
Tyler Gunnf5035432017-01-09 09:43:12 -08001015 if (hasCapabilities(CAPABILITY_SELF_MANAGED)) {
1016 sb.append("SelfManaged ");
1017 }
Tyler Gunn58cbd7a2016-11-11 11:31:28 -08001018 if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) {
1019 sb.append("SuppVideo ");
1020 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001021 if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) {
1022 sb.append("Video ");
1023 }
1024 if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
1025 sb.append("Presence ");
1026 }
1027 if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) {
1028 sb.append("CallProvider ");
1029 }
1030 if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) {
1031 sb.append("CallSubject ");
1032 }
1033 if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) {
1034 sb.append("ConnectionMgr ");
1035 }
1036 if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) {
1037 sb.append("EmergOnly ");
1038 }
1039 if (hasCapabilities(CAPABILITY_MULTI_USER)) {
1040 sb.append("MultiUser ");
1041 }
1042 if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) {
1043 sb.append("PlaceEmerg ");
1044 }
Brad Ebinger3636d742019-05-21 15:28:19 -07001045 if (hasCapabilities(CAPABILITY_EMERGENCY_PREFERRED)) {
1046 sb.append("EmerPrefer ");
1047 }
Tyler Gunncee9ea62016-03-24 11:45:43 -07001048 if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
1049 sb.append("EmergVideo ");
1050 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001051 if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) {
1052 sb.append("SimSub ");
1053 }
Hall Liu47ed6202017-11-20 16:25:39 -08001054 if (hasCapabilities(CAPABILITY_RTT)) {
1055 sb.append("Rtt");
1056 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001057 return sb.toString();
1058 }
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001059
1060 private String audioRoutesToString() {
1061 StringBuilder sb = new StringBuilder();
1062
1063 if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) {
1064 sb.append("B");
1065 }
1066 if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) {
1067 sb.append("E");
1068 }
1069 if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) {
1070 sb.append("S");
1071 }
1072 if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) {
1073 sb.append("W");
1074 }
1075
1076 return sb.toString();
1077 }
Tyler Gunn3b347812018-08-24 14:17:05 -07001078
1079 /**
1080 * Determines if two {@link Bundle}s are equal.
1081 * @param extras First {@link Bundle} to check.
1082 * @param newExtras {@link Bundle} to compare against.
1083 * @return {@code true} if the {@link Bundle}s are equal, {@code false} otherwise.
1084 */
1085 private static boolean areBundlesEqual(Bundle extras, Bundle newExtras) {
1086 if (extras == null || newExtras == null) {
1087 return extras == newExtras;
1088 }
1089
1090 if (extras.size() != newExtras.size()) {
1091 return false;
1092 }
1093
1094 for(String key : extras.keySet()) {
1095 if (key != null) {
1096 final Object value = extras.get(key);
1097 final Object newValue = newExtras.get(key);
1098 if (!Objects.equals(value, newValue)) {
1099 return false;
1100 }
1101 }
1102 }
1103 return true;
1104 }
Ihab Awad807fe0a2014-07-09 12:30:52 -07001105}