blob: 8e22221d787616ddac885bc9eceb121d149fdd01 [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
Evan Charlton0e094d92014-11-08 15:49:16 -080019import android.annotation.SystemApi;
Santos Cordoncad84a22015-05-13 11:17:25 -070020import android.graphics.drawable.Icon;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070021import android.net.Uri;
Tyler Gunn25ed2d72015-10-05 14:14:38 -070022import android.os.Bundle;
Ihab Awad807fe0a2014-07-09 12:30:52 -070023import android.os.Parcel;
24import android.os.Parcelable;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070025import android.text.TextUtils;
Ihab Awad807fe0a2014-07-09 12:30:52 -070026
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070027import java.lang.String;
28import java.util.ArrayList;
29import java.util.Collections;
30import java.util.List;
Tyler Gunn3b347812018-08-24 14:17:05 -070031import java.util.Objects;
Ihab Awad807fe0a2014-07-09 12:30:52 -070032
33/**
Santos Cordon32c65a52014-10-27 14:57:49 -070034 * Represents a distinct method to place or receive a phone call. Apps which can place calls and
35 * 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 -080036 * this class and register it with the system using {@link TelecomManager}.
Santos Cordon32c65a52014-10-27 14:57:49 -070037 * <p>
38 * {@link TelecomManager} uses registered {@link PhoneAccount}s to present the user with
39 * alternative options when placing a phone call. When building a {@link PhoneAccount}, the app
Brian Attwellad147f42014-12-19 11:37:16 -080040 * should supply a valid {@link PhoneAccountHandle} that references the connection service
Santos Cordon32c65a52014-10-27 14:57:49 -070041 * implementation Telecom will use to interact with the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -070042 */
Yorke Lee400470f2015-05-12 13:31:25 -070043public final class PhoneAccount implements Parcelable {
Ihab Awad94cf4bf2014-07-17 11:21:19 -070044
45 /**
Tyler Gunnd426b202015-10-13 13:33:53 -070046 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
Srikanth Chintala62428402017-03-27 19:27:52 +053047 * sort order for {@link PhoneAccount}s from the same
48 * {@link android.telecom.ConnectionService}.
49 * @hide
50 */
51 public static final String EXTRA_SORT_ORDER =
52 "android.telecom.extra.SORT_ORDER";
53
54 /**
55 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
Tyler Gunnd426b202015-10-13 13:33:53 -070056 * maximum permitted length of a call subject specified via the
57 * {@link TelecomManager#EXTRA_CALL_SUBJECT} extra on an
58 * {@link android.content.Intent#ACTION_CALL} intent. Ultimately a {@link ConnectionService} is
59 * responsible for enforcing the maximum call subject length when sending the message, however
60 * this extra is provided so that the user interface can proactively limit the length of the
61 * call subject as the user types it.
62 */
63 public static final String EXTRA_CALL_SUBJECT_MAX_LENGTH =
64 "android.telecom.extra.CALL_SUBJECT_MAX_LENGTH";
65
66 /**
67 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
68 * character encoding to be used when determining the length of messages.
69 * The user interface can use this when determining the number of characters the user may type
70 * in a call subject. If empty-string, the call subject message size limit will be enforced on
71 * a 1:1 basis. That is, each character will count towards the messages size limit as a single
72 * character. If a character encoding is specified, the message size limit will be based on the
73 * number of bytes in the message per the specified encoding. See
74 * {@link #EXTRA_CALL_SUBJECT_MAX_LENGTH} for more information on the call subject maximum
75 * length.
76 */
77 public static final String EXTRA_CALL_SUBJECT_CHARACTER_ENCODING =
78 "android.telecom.extra.CALL_SUBJECT_CHARACTER_ENCODING";
79
Srikanth Chintalaf77d4a12017-04-03 18:08:14 +053080 /**
81 * Indicating flag for phone account whether to use voip audio mode for voip calls
82 * @hide
83 */
84 public static final String EXTRA_ALWAYS_USE_VOIP_AUDIO_MODE =
85 "android.telecom.extra.ALWAYS_USE_VOIP_AUDIO_MODE";
86
Tyler Gunnd426b202015-10-13 13:33:53 -070087 /**
Tyler Gunn8bf76572017-04-06 15:30:08 -070088 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
89 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
Sanket Padawea8eddd42017-11-03 11:07:35 -070090 * connection (see {@code android.telecom.Call#handoverTo()}) to this {@link PhoneAccount} from
91 * a {@link PhoneAccount} specifying {@link #EXTRA_SUPPORTS_HANDOVER_FROM}.
Tyler Gunn8bf76572017-04-06 15:30:08 -070092 * <p>
93 * A handover request is initiated by the user from the default dialer app to indicate a desire
94 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
Tyler Gunn8bf76572017-04-06 15:30:08 -070095 */
96 public static final String EXTRA_SUPPORTS_HANDOVER_TO =
97 "android.telecom.extra.SUPPORTS_HANDOVER_TO";
98
99 /**
100 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Ta-wei Yen9d20d982017-06-02 11:07:07 -0700101 * indicates whether this {@link PhoneAccount} supports using a fallback if video calling is
102 * not available. This extra is for device level support, {@link
103 * android.telephony.CarrierConfigManager#KEY_ALLOW_VIDEO_CALLING_FALLBACK_BOOL} should also
104 * be checked to ensure it is not disabled by individual carrier.
105 *
106 * @hide
107 */
108 public static final String EXTRA_SUPPORTS_VIDEO_CALLING_FALLBACK =
109 "android.telecom.extra.SUPPORTS_VIDEO_CALLING_FALLBACK";
110
111 /**
112 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Tyler Gunn8bf76572017-04-06 15:30:08 -0700113 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
114 * connection from this {@link PhoneAccount} to another {@link PhoneAccount}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700115 * (see {@code android.telecom.Call#handoverTo()}) which specifies
Tyler Gunn8bf76572017-04-06 15:30:08 -0700116 * {@link #EXTRA_SUPPORTS_HANDOVER_TO}.
117 * <p>
118 * A handover request is initiated by the user from the default dialer app to indicate a desire
119 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700120 */
121 public static final String EXTRA_SUPPORTS_HANDOVER_FROM =
122 "android.telecom.extra.SUPPORTS_HANDOVER_FROM";
123
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700124
125 /**
126 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
127 * indicates whether a Self-Managed {@link PhoneAccount} should log its calls to the call log.
Brad Ebingerbb1a55f2017-06-26 13:26:14 -0700128 * Self-Managed {@link PhoneAccount}s are responsible for their own notifications, so the system
129 * will not create a notification when a missed call is logged.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700130 * <p>
131 * By default, Self-Managed {@link PhoneAccount}s do not log their calls to the call log.
132 * Setting this extra to {@code true} provides a means for them to log their calls.
Tyler Gunn2155c4c2018-04-05 09:43:41 -0700133 * <p>
134 * Note: Only calls where the {@link Call.Details#getHandle()} {@link Uri#getScheme()} is
135 * {@link #SCHEME_SIP} or {@link #SCHEME_TEL} will be logged at the current time.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700136 */
137 public static final String EXTRA_LOG_SELF_MANAGED_CALLS =
138 "android.telecom.extra.LOG_SELF_MANAGED_CALLS";
139
Tyler Gunn8bf76572017-04-06 15:30:08 -0700140 /**
Tyler Gunnacdb6862018-01-29 14:30:52 -0800141 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
142 * indicates whether calls for a {@link PhoneAccount} should generate a "call recording tone"
143 * when the user is recording audio on the device.
144 * <p>
145 * The call recording tone is played over the telephony audio stream so that the remote party
146 * has an audible indication that it is possible their call is being recorded using a call
147 * recording app on the device.
148 * <p>
149 * This extra only has an effect for calls placed via Telephony (e.g.
150 * {@link #CAPABILITY_SIM_SUBSCRIPTION}).
151 * <p>
152 * The call recording tone is a 1400 hz tone which repeats every 15 seconds while recording is
153 * in progress.
154 * @hide
155 */
156 public static final String EXTRA_PLAY_CALL_RECORDING_TONE =
157 "android.telecom.extra.PLAY_CALL_RECORDING_TONE";
158
159 /**
Ihab Awadf8b69882014-07-25 15:14:01 -0700160 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
161 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
162 * will be allowed to manage phone calls including using its own proprietary phone-call
163 * implementation (like VoIP calling) to make calls instead of the telephony stack.
164 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700165 * When a user opts to place a call using the SIM-based telephony stack, the
166 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
167 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700168 * <p>
169 * See {@link #getCapabilities}
170 */
Ihab Awadf8b69882014-07-25 15:14:01 -0700171 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700172
173 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700174 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -0700175 * traditional SIM-based telephony calls. This account will be treated as a distinct method
176 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -0700177 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -0700178 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700179 * <p>
180 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700181 * <p>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700182 */
183 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
184
Ihab Awad7522bbd62014-07-18 15:53:17 -0700185 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700186 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -0700187 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -0700188 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700189 * Only the Android framework can register a {@code PhoneAccount} having this capability.
190 * <p>
191 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -0700192 */
193 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
194
Ihab Awadf8b69882014-07-25 15:14:01 -0700195 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800196 * Flag indicating that this {@code PhoneAccount} is currently able to place video calls.
197 * <p>
198 * See also {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING} which indicates whether the
199 * {@code PhoneAccount} supports placing video calls.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700200 * <p>
201 * See {@link #getCapabilities}
Ihab Awadf8b69882014-07-25 15:14:01 -0700202 */
203 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
204
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700205 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700206 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
207 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
208 * <p>
209 * See {@link #getCapabilities}
210 */
211 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
212
213 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800214 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
215 * should only be used by system apps (and will be ignored for all other apps trying to use it).
216 * <p>
217 * See {@link #getCapabilities}
218 * @hide
219 */
Brian Attwellad147f42014-12-19 11:37:16 -0800220 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800221 public static final int CAPABILITY_MULTI_USER = 0x20;
222
223 /**
Tyler Gunn65a3d342015-07-27 16:06:16 -0700224 * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a
225 * caller is able to specify a short subject line for an outgoing call. A capable receiving
226 * device displays the call subject on the incoming call screen.
227 * <p>
228 * See {@link #getCapabilities}
229 */
230 public static final int CAPABILITY_CALL_SUBJECT = 0x40;
231
232 /**
Bryce Leeb96d89c2015-10-14 16:48:40 -0700233 * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls.
234 * <p>
235 * See {@link #getCapabilities}
236 * @hide
237 */
238 public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80;
239
240 /**
Tyler Gunn9a365752015-12-09 15:00:18 -0800241 * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a
242 * number relies on presence. Should only be set if the {@code PhoneAccount} also has
243 * {@link #CAPABILITY_VIDEO_CALLING}.
244 * <p>
245 * When set, the {@link ConnectionService} is responsible for toggling the
246 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the
247 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether
248 * a contact's phone number supports video calling.
249 * <p>
250 * See {@link #getCapabilities}
251 */
252 public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100;
253
254 /**
Tyler Gunncee9ea62016-03-24 11:45:43 -0700255 * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed.
256 * <p>
257 * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will
258 * convert all outgoing video calls to emergency numbers to audio-only.
259 * @hide
260 */
261 public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200;
262
263 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800264 * Flag indicating that this {@link PhoneAccount} supports video calling.
265 * This is not an indication that the {@link PhoneAccount} is currently able to make a video
266 * call, but rather that it has the ability to make video calls (but not necessarily at this
267 * time).
268 * <p>
269 * Whether a {@link PhoneAccount} can make a video call is ultimately controlled by
270 * {@link #CAPABILITY_VIDEO_CALLING}, which indicates whether the {@link PhoneAccount} is
271 * currently capable of making a video call. Consider a case where, for example, a
272 * {@link PhoneAccount} supports making video calls (e.g.
273 * {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING}), but a current lack of network connectivity
274 * prevents video calls from being made (e.g. {@link #CAPABILITY_VIDEO_CALLING}).
275 * <p>
276 * See {@link #getCapabilities}
277 */
278 public static final int CAPABILITY_SUPPORTS_VIDEO_CALLING = 0x400;
279
280 /**
Tyler Gunnf5035432017-01-09 09:43:12 -0800281 * Flag indicating that this {@link PhoneAccount} is responsible for managing its own
282 * {@link Connection}s. This type of {@link PhoneAccount} is ideal for use with standalone
283 * calling apps which do not wish to use the default phone app for {@link Connection} UX,
284 * but which want to leverage the call and audio routing capabilities of the Telecom framework.
285 * <p>
286 * When set, {@link Connection}s created by the self-managed {@link ConnectionService} will not
287 * be surfaced to implementations of the {@link InCallService} API. Thus it is the
288 * responsibility of a self-managed {@link ConnectionService} to provide a user interface for
289 * its {@link Connection}s.
290 * <p>
291 * Self-managed {@link Connection}s will, however, be displayed on connected Bluetooth devices.
292 */
293 public static final int CAPABILITY_SELF_MANAGED = 0x800;
294
295 /**
Hall Liu95d55872017-01-25 17:12:49 -0800296 * Flag indicating that this {@link PhoneAccount} is capable of making a call with an
297 * RTT (Real-time text) session.
298 * When set, Telecom will attempt to open an RTT session on outgoing calls that specify
299 * that they should be placed with an RTT session , and the in-call app will be displayed
300 * with text entry fields for RTT. Likewise, the in-call app can request that an RTT
301 * session be opened during a call if this bit is set.
302 */
303 public static final int CAPABILITY_RTT = 0x1000;
304
305 /* NEXT CAPABILITY: 0x2000 */
306
307 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700308 * URI scheme for telephone number URIs.
309 */
310 public static final String SCHEME_TEL = "tel";
311
312 /**
313 * URI scheme for voicemail URIs.
314 */
315 public static final String SCHEME_VOICEMAIL = "voicemail";
316
317 /**
318 * URI scheme for SIP URIs.
319 */
320 public static final String SCHEME_SIP = "sip";
321
Nancy Chen3ace54b2014-10-22 17:45:26 -0700322 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800323 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700324 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700325 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800326 public static final int NO_ICON_TINT = 0;
327
328 /**
329 * Indicating no hightlight color is set.
330 */
331 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700332
Ihab Awad476cc832014-11-03 09:47:51 -0800333 /**
334 * Indicating no resource ID is set.
335 */
336 public static final int NO_RESOURCE_ID = -1;
337
Evan Charlton8c8a0622014-07-20 12:31:00 -0700338 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700339 private final Uri mAddress;
340 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700341 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800342 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700343 private final CharSequence mLabel;
344 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700345 private final List<String> mSupportedUriSchemes;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800346 private final int mSupportedAudioRoutes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700347 private final Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700348 private final Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700349 private boolean mIsEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700350 private String mGroupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700351
Tyler Gunn3b347812018-08-24 14:17:05 -0700352 @Override
353 public boolean equals(Object o) {
354 if (this == o) return true;
355 if (o == null || getClass() != o.getClass()) return false;
356 PhoneAccount that = (PhoneAccount) o;
357 return mCapabilities == that.mCapabilities &&
358 mHighlightColor == that.mHighlightColor &&
359 mSupportedAudioRoutes == that.mSupportedAudioRoutes &&
360 mIsEnabled == that.mIsEnabled &&
361 Objects.equals(mAccountHandle, that.mAccountHandle) &&
362 Objects.equals(mAddress, that.mAddress) &&
363 Objects.equals(mSubscriptionAddress, that.mSubscriptionAddress) &&
364 Objects.equals(mLabel, that.mLabel) &&
365 Objects.equals(mShortDescription, that.mShortDescription) &&
366 Objects.equals(mSupportedUriSchemes, that.mSupportedUriSchemes) &&
367 areBundlesEqual(mExtras, that.mExtras) &&
368 Objects.equals(mGroupId, that.mGroupId);
369 }
370
371 @Override
372 public int hashCode() {
373 return Objects.hash(mAccountHandle, mAddress, mSubscriptionAddress, mCapabilities,
374 mHighlightColor, mLabel, mShortDescription, mSupportedUriSchemes,
375 mSupportedAudioRoutes,
376 mExtras, mIsEnabled, mGroupId);
377 }
378
Santos Cordon32c65a52014-10-27 14:57:49 -0700379 /**
380 * Helper class for creating a {@link PhoneAccount}.
381 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700382 public static class Builder {
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800383
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700384 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700385 private Uri mAddress;
386 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700387 private int mCapabilities;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800388 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800389 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700390 private CharSequence mLabel;
391 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700392 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700393 private Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700394 private Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700395 private boolean mIsEnabled = false;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700396 private String mGroupId = "";
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700397
Santos Cordon32c65a52014-10-27 14:57:49 -0700398 /**
399 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
400 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700401 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
402 this.mAccountHandle = accountHandle;
403 this.mLabel = label;
404 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700405
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700406 /**
407 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
408 * {@link PhoneAccount}.
409 *
410 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
411 */
412 public Builder(PhoneAccount phoneAccount) {
413 mAccountHandle = phoneAccount.getAccountHandle();
414 mAddress = phoneAccount.getAddress();
415 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
416 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800417 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700418 mLabel = phoneAccount.getLabel();
419 mShortDescription = phoneAccount.getShortDescription();
420 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700421 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc02015-05-08 13:52:09 -0700422 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunnd426b202015-10-13 13:33:53 -0700423 mExtras = phoneAccount.getExtras();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700424 mGroupId = phoneAccount.getGroupId();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800425 mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700426 }
427
Santos Cordon32c65a52014-10-27 14:57:49 -0700428 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700429 * Sets the label. See {@link PhoneAccount#getLabel()}.
430 *
431 * @param label The label of the phone account.
432 * @return The builder.
433 * @hide
434 */
435 public Builder setLabel(CharSequence label) {
436 this.mLabel = label;
437 return this;
438 }
439
440 /**
Santos Cordon32c65a52014-10-27 14:57:49 -0700441 * Sets the address. See {@link PhoneAccount#getAddress}.
442 *
443 * @param value The address of the phone account.
444 * @return The builder.
445 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700446 public Builder setAddress(Uri value) {
447 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700448 return this;
449 }
450
Santos Cordon32c65a52014-10-27 14:57:49 -0700451 /**
452 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
453 *
454 * @param value The subscription address.
455 * @return The builder.
456 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700457 public Builder setSubscriptionAddress(Uri value) {
458 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700459 return this;
460 }
461
Santos Cordon32c65a52014-10-27 14:57:49 -0700462 /**
463 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
464 *
465 * @param value The capabilities to set.
466 * @return The builder.
467 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700468 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700469 this.mCapabilities = value;
470 return this;
471 }
472
Santos Cordon32c65a52014-10-27 14:57:49 -0700473 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700474 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700475 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700476 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700477 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700478 public Builder setIcon(Icon icon) {
479 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700480 return this;
481 }
482
483 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800484 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700485 *
Ihab Awad476cc832014-11-03 09:47:51 -0800486 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700487 * @return The builder.
488 */
Ihab Awad476cc832014-11-03 09:47:51 -0800489 public Builder setHighlightColor(int value) {
490 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700491 return this;
492 }
493
Santos Cordon32c65a52014-10-27 14:57:49 -0700494 /**
495 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
496 *
497 * @param value The short description.
498 * @return The builder.
499 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700500 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700501 this.mShortDescription = value;
502 return this;
503 }
504
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700505 /**
506 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
507 *
508 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700509 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700510 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700511 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700512 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
513 this.mSupportedUriSchemes.add(uriScheme);
514 }
515 return this;
516 }
517
518 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700519 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700520 *
521 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700522 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700523 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700524 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
525 mSupportedUriSchemes.clear();
526
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700527 if (uriSchemes != null && !uriSchemes.isEmpty()) {
528 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700529 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700530 }
531 }
532 return this;
533 }
534
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700535 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700536 * Specifies the extras associated with the {@link PhoneAccount}.
537 * <p>
538 * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer},
539 * and {@link Boolean}. Extras which are not of these types are ignored.
540 *
541 * @param extras
542 * @return
543 */
544 public Builder setExtras(Bundle extras) {
545 mExtras = extras;
546 return this;
547 }
548
549 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700550 * Sets the enabled state of the phone account.
551 *
552 * @param isEnabled The enabled state.
553 * @return The builder.
554 * @hide
555 */
556 public Builder setIsEnabled(boolean isEnabled) {
557 mIsEnabled = isEnabled;
558 return this;
559 }
560
561 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700562 * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is
563 * registered to Telecom, it will replace another {@link PhoneAccount} that is already
564 * registered in Telecom and take on the current user defaults and enabled status. There can
565 * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a
566 * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only
567 * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced.
568 * @param groupId The group Id of the {@link PhoneAccount} that will replace any other
569 * registered {@link PhoneAccount} in Telecom with the same Group Id.
570 * @return The builder
571 * @hide
572 */
573 public Builder setGroupId(String groupId) {
574 if (groupId != null) {
575 mGroupId = groupId;
576 } else {
577 mGroupId = "";
578 }
579 return this;
580 }
581
582 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800583 * Sets the audio routes supported by this {@link PhoneAccount}.
584 *
585 * @param routes bit mask of available routes.
586 * @return The builder.
587 * @hide
588 */
589 public Builder setSupportedAudioRoutes(int routes) {
590 mSupportedAudioRoutes = routes;
591 return this;
592 }
593
594 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700595 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
596 *
597 * @return The {@link PhoneAccount}.
598 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700599 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700600 // If no supported URI schemes were defined, assume "tel" is supported.
601 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700602 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700603 }
604
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700605 return new PhoneAccount(
606 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700607 mAddress,
608 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700609 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700610 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800611 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700612 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700613 mShortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700614 mSupportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700615 mExtras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800616 mSupportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700617 mIsEnabled,
618 mGroupId);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700619 }
620 }
621
622 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700623 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700624 Uri address,
625 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700626 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700627 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800628 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700629 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700630 CharSequence shortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700631 List<String> supportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700632 Bundle extras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800633 int supportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700634 boolean isEnabled,
635 String groupId) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700636 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700637 mAddress = address;
638 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700639 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700640 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800641 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700642 mLabel = label;
643 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700644 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700645 mExtras = extras;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800646 mSupportedAudioRoutes = supportedAudioRoutes;
Santos Cordon91371dc02015-05-08 13:52:09 -0700647 mIsEnabled = isEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700648 mGroupId = groupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700649 }
650
Andrew Lee3085a6c2014-09-04 10:59:13 -0700651 public static Builder builder(
652 PhoneAccountHandle accountHandle,
653 CharSequence label) {
654 return new Builder(accountHandle, label);
655 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700656
Ihab Awad807fe0a2014-07-09 12:30:52 -0700657 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700658 * Returns a builder initialized with the current {@link PhoneAccount} instance.
659 *
660 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700661 */
662 public Builder toBuilder() { return new Builder(this); }
663
664 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700665 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700666 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700667 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700668 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700669 public PhoneAccountHandle getAccountHandle() {
670 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700671 }
672
673 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700674 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700675 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700676 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700677 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700678 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700679 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700680 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700681 public Uri getAddress() {
682 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700683 }
684
685 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700686 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700687 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700688 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000689 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
690 * has been used to alter the callback number.
691 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700692 *
693 * @return The subscription number, suitable for display to the user.
694 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700695 public Uri getSubscriptionAddress() {
696 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700697 }
698
699 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700700 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700701 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700702 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700703 */
704 public int getCapabilities() {
705 return mCapabilities;
706 }
707
708 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700709 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
710 * bit mask.
711 *
712 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700713 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700714 */
715 public boolean hasCapabilities(int capability) {
716 return (mCapabilities & capability) == capability;
717 }
718
719 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800720 * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask.
721 *
722 * @param route The routes to check.
723 * @return {@code true} if the phone account has the routes.
724 * @hide
725 */
726 public boolean hasAudioRoutes(int routes) {
727 return (mSupportedAudioRoutes & routes) == routes;
728 }
729
730 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700731 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700732 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700733 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700734 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700735 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700736 return mLabel;
737 }
738
739 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700740 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700741 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700742 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700743 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700744 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700745 return mShortDescription;
746 }
747
748 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700749 * The URI schemes supported by this {@code PhoneAccount}.
750 *
751 * @return The URI schemes.
752 */
753 public List<String> getSupportedUriSchemes() {
754 return mSupportedUriSchemes;
755 }
756
757 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700758 * The extras associated with this {@code PhoneAccount}.
759 * <p>
760 * A {@link ConnectionService} may provide implementation specific information about the
761 * {@link PhoneAccount} via the extras.
762 *
763 * @return The extras.
764 */
765 public Bundle getExtras() {
766 return mExtras;
767 }
768
769 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800770 * The audio routes supported by this {@code PhoneAccount}.
771 *
772 * @hide
773 */
774 public int getSupportedAudioRoutes() {
775 return mSupportedAudioRoutes;
776 }
777
778 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700779 * The icon to represent this {@code PhoneAccount}.
780 *
781 * @return The icon.
782 */
783 public Icon getIcon() {
784 return mIcon;
785 }
786
787 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700788 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
789 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc02015-05-08 13:52:09 -0700790 *
Santos Cordon895d4b82015-06-25 16:41:48 -0700791 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc02015-05-08 13:52:09 -0700792 */
793 public boolean isEnabled() {
794 return mIsEnabled;
795 }
796
797 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700798 * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an
799 * empty {@link String} if the {@link PhoneAccount} is not in a group. If this
800 * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered
801 * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced,
802 * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}.
803 * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced.
804 *
805 * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group.
806 * @hide
807 */
808 public String getGroupId() {
809 return mGroupId;
810 }
811
812 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700813 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700814 * scheme.
815 *
816 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700817 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700818 * specified URI scheme.
819 */
820 public boolean supportsUriScheme(String uriScheme) {
821 if (mSupportedUriSchemes == null || uriScheme == null) {
822 return false;
823 }
824
825 for (String scheme : mSupportedUriSchemes) {
826 if (scheme != null && scheme.equals(uriScheme)) {
827 return true;
828 }
829 }
830 return false;
831 }
832
833 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800834 * A highlight color to use in displaying information about this {@code PhoneAccount}.
835 *
836 * @return A hexadecimal color value.
837 */
838 public int getHighlightColor() {
839 return mHighlightColor;
840 }
841
Santos Cordon91371dc02015-05-08 13:52:09 -0700842 /**
843 * Sets the enabled state of the phone account.
844 * @hide
845 */
846 public void setIsEnabled(boolean isEnabled) {
847 mIsEnabled = isEnabled;
848 }
849
Tyler Gunnf5035432017-01-09 09:43:12 -0800850 /**
851 * @return {@code true} if the {@link PhoneAccount} is self-managed, {@code false} otherwise.
852 * @hide
853 */
854 public boolean isSelfManaged() {
855 return (mCapabilities & CAPABILITY_SELF_MANAGED) == CAPABILITY_SELF_MANAGED;
856 }
857
Ihab Awad807fe0a2014-07-09 12:30:52 -0700858 //
859 // Parcelable implementation
860 //
861
862 @Override
863 public int describeContents() {
864 return 0;
865 }
866
867 @Override
868 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800869 if (mAccountHandle == null) {
870 out.writeInt(0);
871 } else {
872 out.writeInt(1);
873 mAccountHandle.writeToParcel(out, flags);
874 }
875 if (mAddress == null) {
876 out.writeInt(0);
877 } else {
878 out.writeInt(1);
879 mAddress.writeToParcel(out, flags);
880 }
881 if (mSubscriptionAddress == null) {
882 out.writeInt(0);
883 } else {
884 out.writeInt(1);
885 mSubscriptionAddress.writeToParcel(out, flags);
886 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700887 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800888 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700889 out.writeCharSequence(mLabel);
890 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800891 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc02015-05-08 13:52:09 -0700892
Santos Cordoncad84a22015-05-13 11:17:25 -0700893 if (mIcon == null) {
894 out.writeInt(0);
895 } else {
896 out.writeInt(1);
897 mIcon.writeToParcel(out, flags);
898 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700899 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Tyler Gunnef829ec2015-10-08 09:46:23 -0700900 out.writeBundle(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700901 out.writeString(mGroupId);
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800902 out.writeInt(mSupportedAudioRoutes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700903 }
904
Evan Charlton8c8a0622014-07-20 12:31:00 -0700905 public static final Creator<PhoneAccount> CREATOR
906 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700907 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700908 public PhoneAccount createFromParcel(Parcel in) {
909 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700910 }
911
912 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700913 public PhoneAccount[] newArray(int size) {
914 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700915 }
916 };
917
Evan Charlton8c8a0622014-07-20 12:31:00 -0700918 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800919 if (in.readInt() > 0) {
920 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
921 } else {
922 mAccountHandle = null;
923 }
924 if (in.readInt() > 0) {
925 mAddress = Uri.CREATOR.createFromParcel(in);
926 } else {
927 mAddress = null;
928 }
929 if (in.readInt() > 0) {
930 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
931 } else {
932 mSubscriptionAddress = null;
933 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700934 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -0800935 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700936 mLabel = in.readCharSequence();
937 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800938 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -0700939 if (in.readInt() > 0) {
940 mIcon = Icon.CREATOR.createFromParcel(in);
941 } else {
942 mIcon = null;
943 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700944 mIsEnabled = in.readByte() == 1;
Tyler Gunnef829ec2015-10-08 09:46:23 -0700945 mExtras = in.readBundle();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700946 mGroupId = in.readString();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800947 mSupportedAudioRoutes = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700948 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700949
950 @Override
951 public String toString() {
Santos Cordon91371dc02015-05-08 13:52:09 -0700952 StringBuilder sb = new StringBuilder().append("[[")
953 .append(mIsEnabled ? 'X' : ' ')
954 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700955 .append(mAccountHandle)
956 .append(" Capabilities: ")
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800957 .append(capabilitiesToString())
958 .append(" Audio Routes: ")
959 .append(audioRoutesToString())
Tyler Gunn76c01a52014-09-30 14:47:51 -0700960 .append(" Schemes: ");
961 for (String scheme : mSupportedUriSchemes) {
962 sb.append(scheme)
963 .append(" ");
964 }
Tyler Gunnef829ec2015-10-08 09:46:23 -0700965 sb.append(" Extras: ");
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700966 sb.append(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700967 sb.append(" GroupId: ");
968 sb.append(Log.pii(mGroupId));
Tyler Gunn76c01a52014-09-30 14:47:51 -0700969 sb.append("]");
970 return sb.toString();
971 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800972
973 /**
974 * Generates a string representation of a capabilities bitmask.
975 *
976 * @param capabilities The capabilities bitmask.
977 * @return String representation of the capabilities bitmask.
978 */
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800979 private String capabilitiesToString() {
Tyler Gunn3e122f72016-01-11 19:25:00 -0800980 StringBuilder sb = new StringBuilder();
Tyler Gunnf5035432017-01-09 09:43:12 -0800981 if (hasCapabilities(CAPABILITY_SELF_MANAGED)) {
982 sb.append("SelfManaged ");
983 }
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800984 if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) {
985 sb.append("SuppVideo ");
986 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800987 if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) {
988 sb.append("Video ");
989 }
990 if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
991 sb.append("Presence ");
992 }
993 if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) {
994 sb.append("CallProvider ");
995 }
996 if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) {
997 sb.append("CallSubject ");
998 }
999 if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) {
1000 sb.append("ConnectionMgr ");
1001 }
1002 if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) {
1003 sb.append("EmergOnly ");
1004 }
1005 if (hasCapabilities(CAPABILITY_MULTI_USER)) {
1006 sb.append("MultiUser ");
1007 }
1008 if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) {
1009 sb.append("PlaceEmerg ");
1010 }
Tyler Gunncee9ea62016-03-24 11:45:43 -07001011 if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
1012 sb.append("EmergVideo ");
1013 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001014 if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) {
1015 sb.append("SimSub ");
1016 }
Hall Liu47ed6202017-11-20 16:25:39 -08001017 if (hasCapabilities(CAPABILITY_RTT)) {
1018 sb.append("Rtt");
1019 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001020 return sb.toString();
1021 }
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001022
1023 private String audioRoutesToString() {
1024 StringBuilder sb = new StringBuilder();
1025
1026 if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) {
1027 sb.append("B");
1028 }
1029 if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) {
1030 sb.append("E");
1031 }
1032 if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) {
1033 sb.append("S");
1034 }
1035 if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) {
1036 sb.append("W");
1037 }
1038
1039 return sb.toString();
1040 }
Tyler Gunn3b347812018-08-24 14:17:05 -07001041
1042 /**
1043 * Determines if two {@link Bundle}s are equal.
1044 * @param extras First {@link Bundle} to check.
1045 * @param newExtras {@link Bundle} to compare against.
1046 * @return {@code true} if the {@link Bundle}s are equal, {@code false} otherwise.
1047 */
1048 private static boolean areBundlesEqual(Bundle extras, Bundle newExtras) {
1049 if (extras == null || newExtras == null) {
1050 return extras == newExtras;
1051 }
1052
1053 if (extras.size() != newExtras.size()) {
1054 return false;
1055 }
1056
1057 for(String key : extras.keySet()) {
1058 if (key != null) {
1059 final Object value = extras.get(key);
1060 final Object newValue = newExtras.get(key);
1061 if (!Objects.equals(value, newValue)) {
1062 return false;
1063 }
1064 }
1065 }
1066 return true;
1067 }
Ihab Awad807fe0a2014-07-09 12:30:52 -07001068}