blob: 74b9465070c539a2e1cdb88d57a33c1f8c17c50b [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;
Ihab Awad807fe0a2014-07-09 12:30:52 -070031
32/**
Santos Cordon32c65a52014-10-27 14:57:49 -070033 * Represents a distinct method to place or receive a phone call. Apps which can place calls and
34 * 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 -080035 * this class and register it with the system using {@link TelecomManager}.
Santos Cordon32c65a52014-10-27 14:57:49 -070036 * <p>
37 * {@link TelecomManager} uses registered {@link PhoneAccount}s to present the user with
38 * alternative options when placing a phone call. When building a {@link PhoneAccount}, the app
Brian Attwellad147f42014-12-19 11:37:16 -080039 * should supply a valid {@link PhoneAccountHandle} that references the connection service
Santos Cordon32c65a52014-10-27 14:57:49 -070040 * implementation Telecom will use to interact with the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -070041 */
Yorke Lee400470f2015-05-12 13:31:25 -070042public final class PhoneAccount implements Parcelable {
Ihab Awad94cf4bf2014-07-17 11:21:19 -070043
44 /**
Tyler Gunnd426b202015-10-13 13:33:53 -070045 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
Srikanth Chintala62428402017-03-27 19:27:52 +053046 * sort order for {@link PhoneAccount}s from the same
47 * {@link android.telecom.ConnectionService}.
48 * @hide
49 */
50 public static final String EXTRA_SORT_ORDER =
51 "android.telecom.extra.SORT_ORDER";
52
53 /**
54 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
Tyler Gunnd426b202015-10-13 13:33:53 -070055 * maximum permitted length of a call subject specified via the
56 * {@link TelecomManager#EXTRA_CALL_SUBJECT} extra on an
57 * {@link android.content.Intent#ACTION_CALL} intent. Ultimately a {@link ConnectionService} is
58 * responsible for enforcing the maximum call subject length when sending the message, however
59 * this extra is provided so that the user interface can proactively limit the length of the
60 * call subject as the user types it.
61 */
62 public static final String EXTRA_CALL_SUBJECT_MAX_LENGTH =
63 "android.telecom.extra.CALL_SUBJECT_MAX_LENGTH";
64
65 /**
66 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
67 * character encoding to be used when determining the length of messages.
68 * The user interface can use this when determining the number of characters the user may type
69 * in a call subject. If empty-string, the call subject message size limit will be enforced on
70 * a 1:1 basis. That is, each character will count towards the messages size limit as a single
71 * character. If a character encoding is specified, the message size limit will be based on the
72 * number of bytes in the message per the specified encoding. See
73 * {@link #EXTRA_CALL_SUBJECT_MAX_LENGTH} for more information on the call subject maximum
74 * length.
75 */
76 public static final String EXTRA_CALL_SUBJECT_CHARACTER_ENCODING =
77 "android.telecom.extra.CALL_SUBJECT_CHARACTER_ENCODING";
78
Srikanth Chintalaf77d4a12017-04-03 18:08:14 +053079 /**
80 * Indicating flag for phone account whether to use voip audio mode for voip calls
81 * @hide
82 */
83 public static final String EXTRA_ALWAYS_USE_VOIP_AUDIO_MODE =
84 "android.telecom.extra.ALWAYS_USE_VOIP_AUDIO_MODE";
85
Tyler Gunnd426b202015-10-13 13:33:53 -070086 /**
Tyler Gunn8bf76572017-04-06 15:30:08 -070087 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
88 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
Sanket Padawea8eddd42017-11-03 11:07:35 -070089 * connection (see {@code android.telecom.Call#handoverTo()}) to this {@link PhoneAccount} from
90 * a {@link PhoneAccount} specifying {@link #EXTRA_SUPPORTS_HANDOVER_FROM}.
Tyler Gunn8bf76572017-04-06 15:30:08 -070091 * <p>
92 * A handover request is initiated by the user from the default dialer app to indicate a desire
93 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
Tyler Gunn8bf76572017-04-06 15:30:08 -070094 */
95 public static final String EXTRA_SUPPORTS_HANDOVER_TO =
96 "android.telecom.extra.SUPPORTS_HANDOVER_TO";
97
98 /**
99 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Ta-wei Yen9d20d982017-06-02 11:07:07 -0700100 * indicates whether this {@link PhoneAccount} supports using a fallback if video calling is
101 * not available. This extra is for device level support, {@link
102 * android.telephony.CarrierConfigManager#KEY_ALLOW_VIDEO_CALLING_FALLBACK_BOOL} should also
103 * be checked to ensure it is not disabled by individual carrier.
104 *
105 * @hide
106 */
107 public static final String EXTRA_SUPPORTS_VIDEO_CALLING_FALLBACK =
108 "android.telecom.extra.SUPPORTS_VIDEO_CALLING_FALLBACK";
109
110 /**
111 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Tyler Gunn8bf76572017-04-06 15:30:08 -0700112 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
113 * connection from this {@link PhoneAccount} to another {@link PhoneAccount}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700114 * (see {@code android.telecom.Call#handoverTo()}) which specifies
Tyler Gunn8bf76572017-04-06 15:30:08 -0700115 * {@link #EXTRA_SUPPORTS_HANDOVER_TO}.
116 * <p>
117 * A handover request is initiated by the user from the default dialer app to indicate a desire
118 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700119 */
120 public static final String EXTRA_SUPPORTS_HANDOVER_FROM =
121 "android.telecom.extra.SUPPORTS_HANDOVER_FROM";
122
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700123
124 /**
125 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
126 * indicates whether a Self-Managed {@link PhoneAccount} should log its calls to the call log.
Brad Ebingerbb1a55f2017-06-26 13:26:14 -0700127 * Self-Managed {@link PhoneAccount}s are responsible for their own notifications, so the system
128 * will not create a notification when a missed call is logged.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700129 * <p>
130 * By default, Self-Managed {@link PhoneAccount}s do not log their calls to the call log.
131 * Setting this extra to {@code true} provides a means for them to log their calls.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700132 */
133 public static final String EXTRA_LOG_SELF_MANAGED_CALLS =
134 "android.telecom.extra.LOG_SELF_MANAGED_CALLS";
135
Tyler Gunn8bf76572017-04-06 15:30:08 -0700136 /**
Ihab Awadf8b69882014-07-25 15:14:01 -0700137 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
138 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
139 * will be allowed to manage phone calls including using its own proprietary phone-call
140 * implementation (like VoIP calling) to make calls instead of the telephony stack.
141 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700142 * When a user opts to place a call using the SIM-based telephony stack, the
143 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
144 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700145 * <p>
146 * See {@link #getCapabilities}
147 */
Ihab Awadf8b69882014-07-25 15:14:01 -0700148 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700149
150 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700151 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -0700152 * traditional SIM-based telephony calls. This account will be treated as a distinct method
153 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -0700154 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -0700155 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700156 * <p>
157 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700158 * <p>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700159 */
160 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
161
Ihab Awad7522bbd62014-07-18 15:53:17 -0700162 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700163 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -0700164 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -0700165 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700166 * Only the Android framework can register a {@code PhoneAccount} having this capability.
167 * <p>
168 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -0700169 */
170 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
171
Ihab Awadf8b69882014-07-25 15:14:01 -0700172 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800173 * Flag indicating that this {@code PhoneAccount} is currently able to place video calls.
174 * <p>
175 * See also {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING} which indicates whether the
176 * {@code PhoneAccount} supports placing video calls.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700177 * <p>
178 * See {@link #getCapabilities}
Ihab Awadf8b69882014-07-25 15:14:01 -0700179 */
180 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
181
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700182 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700183 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
184 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
185 * <p>
186 * See {@link #getCapabilities}
187 */
188 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
189
190 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800191 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
192 * should only be used by system apps (and will be ignored for all other apps trying to use it).
193 * <p>
194 * See {@link #getCapabilities}
195 * @hide
196 */
Brian Attwellad147f42014-12-19 11:37:16 -0800197 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800198 public static final int CAPABILITY_MULTI_USER = 0x20;
199
200 /**
Tyler Gunn65a3d342015-07-27 16:06:16 -0700201 * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a
202 * caller is able to specify a short subject line for an outgoing call. A capable receiving
203 * device displays the call subject on the incoming call screen.
204 * <p>
205 * See {@link #getCapabilities}
206 */
207 public static final int CAPABILITY_CALL_SUBJECT = 0x40;
208
209 /**
Bryce Leeb96d89c2015-10-14 16:48:40 -0700210 * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls.
211 * <p>
212 * See {@link #getCapabilities}
213 * @hide
214 */
215 public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80;
216
217 /**
Tyler Gunn9a365752015-12-09 15:00:18 -0800218 * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a
219 * number relies on presence. Should only be set if the {@code PhoneAccount} also has
220 * {@link #CAPABILITY_VIDEO_CALLING}.
221 * <p>
222 * When set, the {@link ConnectionService} is responsible for toggling the
223 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the
224 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether
225 * a contact's phone number supports video calling.
226 * <p>
227 * See {@link #getCapabilities}
228 */
229 public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100;
230
231 /**
Tyler Gunncee9ea62016-03-24 11:45:43 -0700232 * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed.
233 * <p>
234 * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will
235 * convert all outgoing video calls to emergency numbers to audio-only.
236 * @hide
237 */
238 public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200;
239
240 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800241 * Flag indicating that this {@link PhoneAccount} supports video calling.
242 * This is not an indication that the {@link PhoneAccount} is currently able to make a video
243 * call, but rather that it has the ability to make video calls (but not necessarily at this
244 * time).
245 * <p>
246 * Whether a {@link PhoneAccount} can make a video call is ultimately controlled by
247 * {@link #CAPABILITY_VIDEO_CALLING}, which indicates whether the {@link PhoneAccount} is
248 * currently capable of making a video call. Consider a case where, for example, a
249 * {@link PhoneAccount} supports making video calls (e.g.
250 * {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING}), but a current lack of network connectivity
251 * prevents video calls from being made (e.g. {@link #CAPABILITY_VIDEO_CALLING}).
252 * <p>
253 * See {@link #getCapabilities}
254 */
255 public static final int CAPABILITY_SUPPORTS_VIDEO_CALLING = 0x400;
256
257 /**
Tyler Gunnf5035432017-01-09 09:43:12 -0800258 * Flag indicating that this {@link PhoneAccount} is responsible for managing its own
259 * {@link Connection}s. This type of {@link PhoneAccount} is ideal for use with standalone
260 * calling apps which do not wish to use the default phone app for {@link Connection} UX,
261 * but which want to leverage the call and audio routing capabilities of the Telecom framework.
262 * <p>
263 * When set, {@link Connection}s created by the self-managed {@link ConnectionService} will not
264 * be surfaced to implementations of the {@link InCallService} API. Thus it is the
265 * responsibility of a self-managed {@link ConnectionService} to provide a user interface for
266 * its {@link Connection}s.
267 * <p>
268 * Self-managed {@link Connection}s will, however, be displayed on connected Bluetooth devices.
269 */
270 public static final int CAPABILITY_SELF_MANAGED = 0x800;
271
272 /**
Hall Liu95d55872017-01-25 17:12:49 -0800273 * Flag indicating that this {@link PhoneAccount} is capable of making a call with an
274 * RTT (Real-time text) session.
275 * When set, Telecom will attempt to open an RTT session on outgoing calls that specify
276 * that they should be placed with an RTT session , and the in-call app will be displayed
277 * with text entry fields for RTT. Likewise, the in-call app can request that an RTT
278 * session be opened during a call if this bit is set.
279 */
280 public static final int CAPABILITY_RTT = 0x1000;
281
282 /* NEXT CAPABILITY: 0x2000 */
283
284 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700285 * URI scheme for telephone number URIs.
286 */
287 public static final String SCHEME_TEL = "tel";
288
289 /**
290 * URI scheme for voicemail URIs.
291 */
292 public static final String SCHEME_VOICEMAIL = "voicemail";
293
294 /**
295 * URI scheme for SIP URIs.
296 */
297 public static final String SCHEME_SIP = "sip";
298
Nancy Chen3ace54b2014-10-22 17:45:26 -0700299 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800300 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700301 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700302 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800303 public static final int NO_ICON_TINT = 0;
304
305 /**
306 * Indicating no hightlight color is set.
307 */
308 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700309
Ihab Awad476cc832014-11-03 09:47:51 -0800310 /**
311 * Indicating no resource ID is set.
312 */
313 public static final int NO_RESOURCE_ID = -1;
314
Evan Charlton8c8a0622014-07-20 12:31:00 -0700315 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700316 private final Uri mAddress;
317 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700318 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800319 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700320 private final CharSequence mLabel;
321 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700322 private final List<String> mSupportedUriSchemes;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800323 private final int mSupportedAudioRoutes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700324 private final Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700325 private final Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700326 private boolean mIsEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700327 private String mGroupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700328
Santos Cordon32c65a52014-10-27 14:57:49 -0700329 /**
330 * Helper class for creating a {@link PhoneAccount}.
331 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700332 public static class Builder {
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800333
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700334 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700335 private Uri mAddress;
336 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700337 private int mCapabilities;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800338 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800339 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700340 private CharSequence mLabel;
341 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700342 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700343 private Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700344 private Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700345 private boolean mIsEnabled = false;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700346 private String mGroupId = "";
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700347
Santos Cordon32c65a52014-10-27 14:57:49 -0700348 /**
349 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
350 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700351 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
352 this.mAccountHandle = accountHandle;
353 this.mLabel = label;
354 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700355
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700356 /**
357 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
358 * {@link PhoneAccount}.
359 *
360 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
361 */
362 public Builder(PhoneAccount phoneAccount) {
363 mAccountHandle = phoneAccount.getAccountHandle();
364 mAddress = phoneAccount.getAddress();
365 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
366 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800367 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700368 mLabel = phoneAccount.getLabel();
369 mShortDescription = phoneAccount.getShortDescription();
370 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700371 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc02015-05-08 13:52:09 -0700372 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunnd426b202015-10-13 13:33:53 -0700373 mExtras = phoneAccount.getExtras();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700374 mGroupId = phoneAccount.getGroupId();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800375 mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700376 }
377
Santos Cordon32c65a52014-10-27 14:57:49 -0700378 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700379 * Sets the label. See {@link PhoneAccount#getLabel()}.
380 *
381 * @param label The label of the phone account.
382 * @return The builder.
383 * @hide
384 */
385 public Builder setLabel(CharSequence label) {
386 this.mLabel = label;
387 return this;
388 }
389
390 /**
Santos Cordon32c65a52014-10-27 14:57:49 -0700391 * Sets the address. See {@link PhoneAccount#getAddress}.
392 *
393 * @param value The address of the phone account.
394 * @return The builder.
395 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700396 public Builder setAddress(Uri value) {
397 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700398 return this;
399 }
400
Santos Cordon32c65a52014-10-27 14:57:49 -0700401 /**
402 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
403 *
404 * @param value The subscription address.
405 * @return The builder.
406 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700407 public Builder setSubscriptionAddress(Uri value) {
408 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700409 return this;
410 }
411
Santos Cordon32c65a52014-10-27 14:57:49 -0700412 /**
413 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
414 *
415 * @param value The capabilities to set.
416 * @return The builder.
417 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700418 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700419 this.mCapabilities = value;
420 return this;
421 }
422
Santos Cordon32c65a52014-10-27 14:57:49 -0700423 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700424 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700425 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700426 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700427 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700428 public Builder setIcon(Icon icon) {
429 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700430 return this;
431 }
432
433 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800434 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700435 *
Ihab Awad476cc832014-11-03 09:47:51 -0800436 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700437 * @return The builder.
438 */
Ihab Awad476cc832014-11-03 09:47:51 -0800439 public Builder setHighlightColor(int value) {
440 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700441 return this;
442 }
443
Santos Cordon32c65a52014-10-27 14:57:49 -0700444 /**
445 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
446 *
447 * @param value The short description.
448 * @return The builder.
449 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700450 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700451 this.mShortDescription = value;
452 return this;
453 }
454
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700455 /**
456 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
457 *
458 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700459 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700460 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700461 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700462 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
463 this.mSupportedUriSchemes.add(uriScheme);
464 }
465 return this;
466 }
467
468 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700469 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700470 *
471 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700472 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700473 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700474 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
475 mSupportedUriSchemes.clear();
476
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700477 if (uriSchemes != null && !uriSchemes.isEmpty()) {
478 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700479 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700480 }
481 }
482 return this;
483 }
484
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700485 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700486 * Specifies the extras associated with the {@link PhoneAccount}.
487 * <p>
488 * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer},
489 * and {@link Boolean}. Extras which are not of these types are ignored.
490 *
491 * @param extras
492 * @return
493 */
494 public Builder setExtras(Bundle extras) {
495 mExtras = extras;
496 return this;
497 }
498
499 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700500 * Sets the enabled state of the phone account.
501 *
502 * @param isEnabled The enabled state.
503 * @return The builder.
504 * @hide
505 */
506 public Builder setIsEnabled(boolean isEnabled) {
507 mIsEnabled = isEnabled;
508 return this;
509 }
510
511 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700512 * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is
513 * registered to Telecom, it will replace another {@link PhoneAccount} that is already
514 * registered in Telecom and take on the current user defaults and enabled status. There can
515 * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a
516 * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only
517 * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced.
518 * @param groupId The group Id of the {@link PhoneAccount} that will replace any other
519 * registered {@link PhoneAccount} in Telecom with the same Group Id.
520 * @return The builder
521 * @hide
522 */
523 public Builder setGroupId(String groupId) {
524 if (groupId != null) {
525 mGroupId = groupId;
526 } else {
527 mGroupId = "";
528 }
529 return this;
530 }
531
532 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800533 * Sets the audio routes supported by this {@link PhoneAccount}.
534 *
535 * @param routes bit mask of available routes.
536 * @return The builder.
537 * @hide
538 */
539 public Builder setSupportedAudioRoutes(int routes) {
540 mSupportedAudioRoutes = routes;
541 return this;
542 }
543
544 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700545 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
546 *
547 * @return The {@link PhoneAccount}.
548 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700549 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700550 // If no supported URI schemes were defined, assume "tel" is supported.
551 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700552 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700553 }
554
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700555 return new PhoneAccount(
556 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700557 mAddress,
558 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700559 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700560 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800561 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700562 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700563 mShortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700564 mSupportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700565 mExtras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800566 mSupportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700567 mIsEnabled,
568 mGroupId);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700569 }
570 }
571
572 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700573 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700574 Uri address,
575 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700576 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700577 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800578 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700579 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700580 CharSequence shortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700581 List<String> supportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700582 Bundle extras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800583 int supportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700584 boolean isEnabled,
585 String groupId) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700586 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700587 mAddress = address;
588 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700589 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700590 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800591 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700592 mLabel = label;
593 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700594 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700595 mExtras = extras;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800596 mSupportedAudioRoutes = supportedAudioRoutes;
Santos Cordon91371dc02015-05-08 13:52:09 -0700597 mIsEnabled = isEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700598 mGroupId = groupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700599 }
600
Andrew Lee3085a6c2014-09-04 10:59:13 -0700601 public static Builder builder(
602 PhoneAccountHandle accountHandle,
603 CharSequence label) {
604 return new Builder(accountHandle, label);
605 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700606
Ihab Awad807fe0a2014-07-09 12:30:52 -0700607 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700608 * Returns a builder initialized with the current {@link PhoneAccount} instance.
609 *
610 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700611 */
612 public Builder toBuilder() { return new Builder(this); }
613
614 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700615 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700616 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700617 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700618 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700619 public PhoneAccountHandle getAccountHandle() {
620 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700621 }
622
623 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700624 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700625 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700626 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700627 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700628 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700629 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700630 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700631 public Uri getAddress() {
632 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700633 }
634
635 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700636 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700637 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700638 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000639 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
640 * has been used to alter the callback number.
641 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700642 *
643 * @return The subscription number, suitable for display to the user.
644 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700645 public Uri getSubscriptionAddress() {
646 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700647 }
648
649 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700650 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700651 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700652 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700653 */
654 public int getCapabilities() {
655 return mCapabilities;
656 }
657
658 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700659 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
660 * bit mask.
661 *
662 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700663 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700664 */
665 public boolean hasCapabilities(int capability) {
666 return (mCapabilities & capability) == capability;
667 }
668
669 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800670 * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask.
671 *
672 * @param route The routes to check.
673 * @return {@code true} if the phone account has the routes.
674 * @hide
675 */
676 public boolean hasAudioRoutes(int routes) {
677 return (mSupportedAudioRoutes & routes) == routes;
678 }
679
680 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700681 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700682 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700683 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700684 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700685 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700686 return mLabel;
687 }
688
689 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700690 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700691 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700692 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700693 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700694 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700695 return mShortDescription;
696 }
697
698 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700699 * The URI schemes supported by this {@code PhoneAccount}.
700 *
701 * @return The URI schemes.
702 */
703 public List<String> getSupportedUriSchemes() {
704 return mSupportedUriSchemes;
705 }
706
707 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700708 * The extras associated with this {@code PhoneAccount}.
709 * <p>
710 * A {@link ConnectionService} may provide implementation specific information about the
711 * {@link PhoneAccount} via the extras.
712 *
713 * @return The extras.
714 */
715 public Bundle getExtras() {
716 return mExtras;
717 }
718
719 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800720 * The audio routes supported by this {@code PhoneAccount}.
721 *
722 * @hide
723 */
724 public int getSupportedAudioRoutes() {
725 return mSupportedAudioRoutes;
726 }
727
728 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700729 * The icon to represent this {@code PhoneAccount}.
730 *
731 * @return The icon.
732 */
733 public Icon getIcon() {
734 return mIcon;
735 }
736
737 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700738 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
739 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc02015-05-08 13:52:09 -0700740 *
Santos Cordon895d4b82015-06-25 16:41:48 -0700741 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc02015-05-08 13:52:09 -0700742 */
743 public boolean isEnabled() {
744 return mIsEnabled;
745 }
746
747 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700748 * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an
749 * empty {@link String} if the {@link PhoneAccount} is not in a group. If this
750 * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered
751 * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced,
752 * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}.
753 * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced.
754 *
755 * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group.
756 * @hide
757 */
758 public String getGroupId() {
759 return mGroupId;
760 }
761
762 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700763 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700764 * scheme.
765 *
766 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700767 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700768 * specified URI scheme.
769 */
770 public boolean supportsUriScheme(String uriScheme) {
771 if (mSupportedUriSchemes == null || uriScheme == null) {
772 return false;
773 }
774
775 for (String scheme : mSupportedUriSchemes) {
776 if (scheme != null && scheme.equals(uriScheme)) {
777 return true;
778 }
779 }
780 return false;
781 }
782
783 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800784 * A highlight color to use in displaying information about this {@code PhoneAccount}.
785 *
786 * @return A hexadecimal color value.
787 */
788 public int getHighlightColor() {
789 return mHighlightColor;
790 }
791
Santos Cordon91371dc02015-05-08 13:52:09 -0700792 /**
793 * Sets the enabled state of the phone account.
794 * @hide
795 */
796 public void setIsEnabled(boolean isEnabled) {
797 mIsEnabled = isEnabled;
798 }
799
Tyler Gunnf5035432017-01-09 09:43:12 -0800800 /**
801 * @return {@code true} if the {@link PhoneAccount} is self-managed, {@code false} otherwise.
802 * @hide
803 */
804 public boolean isSelfManaged() {
805 return (mCapabilities & CAPABILITY_SELF_MANAGED) == CAPABILITY_SELF_MANAGED;
806 }
807
Ihab Awad807fe0a2014-07-09 12:30:52 -0700808 //
809 // Parcelable implementation
810 //
811
812 @Override
813 public int describeContents() {
814 return 0;
815 }
816
817 @Override
818 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800819 if (mAccountHandle == null) {
820 out.writeInt(0);
821 } else {
822 out.writeInt(1);
823 mAccountHandle.writeToParcel(out, flags);
824 }
825 if (mAddress == null) {
826 out.writeInt(0);
827 } else {
828 out.writeInt(1);
829 mAddress.writeToParcel(out, flags);
830 }
831 if (mSubscriptionAddress == null) {
832 out.writeInt(0);
833 } else {
834 out.writeInt(1);
835 mSubscriptionAddress.writeToParcel(out, flags);
836 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700837 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800838 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700839 out.writeCharSequence(mLabel);
840 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800841 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc02015-05-08 13:52:09 -0700842
Santos Cordoncad84a22015-05-13 11:17:25 -0700843 if (mIcon == null) {
844 out.writeInt(0);
845 } else {
846 out.writeInt(1);
847 mIcon.writeToParcel(out, flags);
848 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700849 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Tyler Gunnef829ec2015-10-08 09:46:23 -0700850 out.writeBundle(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700851 out.writeString(mGroupId);
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800852 out.writeInt(mSupportedAudioRoutes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700853 }
854
Evan Charlton8c8a0622014-07-20 12:31:00 -0700855 public static final Creator<PhoneAccount> CREATOR
856 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700857 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700858 public PhoneAccount createFromParcel(Parcel in) {
859 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700860 }
861
862 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700863 public PhoneAccount[] newArray(int size) {
864 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700865 }
866 };
867
Evan Charlton8c8a0622014-07-20 12:31:00 -0700868 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800869 if (in.readInt() > 0) {
870 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
871 } else {
872 mAccountHandle = null;
873 }
874 if (in.readInt() > 0) {
875 mAddress = Uri.CREATOR.createFromParcel(in);
876 } else {
877 mAddress = null;
878 }
879 if (in.readInt() > 0) {
880 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
881 } else {
882 mSubscriptionAddress = null;
883 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700884 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -0800885 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700886 mLabel = in.readCharSequence();
887 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800888 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -0700889 if (in.readInt() > 0) {
890 mIcon = Icon.CREATOR.createFromParcel(in);
891 } else {
892 mIcon = null;
893 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700894 mIsEnabled = in.readByte() == 1;
Tyler Gunnef829ec2015-10-08 09:46:23 -0700895 mExtras = in.readBundle();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700896 mGroupId = in.readString();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800897 mSupportedAudioRoutes = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700898 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700899
900 @Override
901 public String toString() {
Santos Cordon91371dc02015-05-08 13:52:09 -0700902 StringBuilder sb = new StringBuilder().append("[[")
903 .append(mIsEnabled ? 'X' : ' ')
904 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700905 .append(mAccountHandle)
906 .append(" Capabilities: ")
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800907 .append(capabilitiesToString())
908 .append(" Audio Routes: ")
909 .append(audioRoutesToString())
Tyler Gunn76c01a52014-09-30 14:47:51 -0700910 .append(" Schemes: ");
911 for (String scheme : mSupportedUriSchemes) {
912 sb.append(scheme)
913 .append(" ");
914 }
Tyler Gunnef829ec2015-10-08 09:46:23 -0700915 sb.append(" Extras: ");
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700916 sb.append(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700917 sb.append(" GroupId: ");
918 sb.append(Log.pii(mGroupId));
Tyler Gunn76c01a52014-09-30 14:47:51 -0700919 sb.append("]");
920 return sb.toString();
921 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800922
923 /**
924 * Generates a string representation of a capabilities bitmask.
925 *
926 * @param capabilities The capabilities bitmask.
927 * @return String representation of the capabilities bitmask.
928 */
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800929 private String capabilitiesToString() {
Tyler Gunn3e122f72016-01-11 19:25:00 -0800930 StringBuilder sb = new StringBuilder();
Tyler Gunnf5035432017-01-09 09:43:12 -0800931 if (hasCapabilities(CAPABILITY_SELF_MANAGED)) {
932 sb.append("SelfManaged ");
933 }
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800934 if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) {
935 sb.append("SuppVideo ");
936 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800937 if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) {
938 sb.append("Video ");
939 }
940 if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
941 sb.append("Presence ");
942 }
943 if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) {
944 sb.append("CallProvider ");
945 }
946 if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) {
947 sb.append("CallSubject ");
948 }
949 if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) {
950 sb.append("ConnectionMgr ");
951 }
952 if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) {
953 sb.append("EmergOnly ");
954 }
955 if (hasCapabilities(CAPABILITY_MULTI_USER)) {
956 sb.append("MultiUser ");
957 }
958 if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) {
959 sb.append("PlaceEmerg ");
960 }
Tyler Gunncee9ea62016-03-24 11:45:43 -0700961 if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
962 sb.append("EmergVideo ");
963 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800964 if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) {
965 sb.append("SimSub ");
966 }
967 return sb.toString();
968 }
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800969
970 private String audioRoutesToString() {
971 StringBuilder sb = new StringBuilder();
972
973 if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) {
974 sb.append("B");
975 }
976 if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) {
977 sb.append("E");
978 }
979 if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) {
980 sb.append("S");
981 }
982 if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) {
983 sb.append("W");
984 }
985
986 return sb.toString();
987 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700988}