blob: 691e7cf1d34f1bf22adbe380d545028ec9315615 [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
89 * connection (see {@link android.telecom.Call#EVENT_REQUEST_HANDOVER}) to this
90 * {@link PhoneAccount} from a {@link PhoneAccount} specifying
91 * {@link #EXTRA_SUPPORTS_HANDOVER_FROM}.
92 * <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.
95 * @hide
96 */
97 public static final String EXTRA_SUPPORTS_HANDOVER_TO =
98 "android.telecom.extra.SUPPORTS_HANDOVER_TO";
99
100 /**
101 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Ta-wei Yen9d20d982017-06-02 11:07:07 -0700102 * indicates whether this {@link PhoneAccount} supports using a fallback if video calling is
103 * not available. This extra is for device level support, {@link
104 * android.telephony.CarrierConfigManager#KEY_ALLOW_VIDEO_CALLING_FALLBACK_BOOL} should also
105 * be checked to ensure it is not disabled by individual carrier.
106 *
107 * @hide
108 */
109 public static final String EXTRA_SUPPORTS_VIDEO_CALLING_FALLBACK =
110 "android.telecom.extra.SUPPORTS_VIDEO_CALLING_FALLBACK";
111
112 /**
113 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Tyler Gunn8bf76572017-04-06 15:30:08 -0700114 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
115 * connection from this {@link PhoneAccount} to another {@link PhoneAccount}.
116 * (see {@link android.telecom.Call#EVENT_REQUEST_HANDOVER}) which specifies
117 * {@link #EXTRA_SUPPORTS_HANDOVER_TO}.
118 * <p>
119 * A handover request is initiated by the user from the default dialer app to indicate a desire
120 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
121 * @hide
122 */
123 public static final String EXTRA_SUPPORTS_HANDOVER_FROM =
124 "android.telecom.extra.SUPPORTS_HANDOVER_FROM";
125
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700126
127 /**
128 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
129 * indicates whether a Self-Managed {@link PhoneAccount} should log its calls to the call log.
Brad Ebingerbb1a55f2017-06-26 13:26:14 -0700130 * Self-Managed {@link PhoneAccount}s are responsible for their own notifications, so the system
131 * will not create a notification when a missed call is logged.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700132 * <p>
133 * By default, Self-Managed {@link PhoneAccount}s do not log their calls to the call log.
134 * Setting this extra to {@code true} provides a means for them to log their calls.
135 * @hide
136 */
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 /**
Ihab Awadf8b69882014-07-25 15:14:01 -0700141 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
142 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
143 * will be allowed to manage phone calls including using its own proprietary phone-call
144 * implementation (like VoIP calling) to make calls instead of the telephony stack.
145 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700146 * When a user opts to place a call using the SIM-based telephony stack, the
147 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
148 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700149 * <p>
150 * See {@link #getCapabilities}
151 */
Ihab Awadf8b69882014-07-25 15:14:01 -0700152 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700153
154 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700155 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -0700156 * traditional SIM-based telephony calls. This account will be treated as a distinct method
157 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -0700158 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -0700159 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700160 * <p>
161 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700162 * <p>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700163 */
164 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
165
Ihab Awad7522bbd2014-07-18 15:53:17 -0700166 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700167 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -0700168 * subscription.
Ihab Awad7522bbd2014-07-18 15:53:17 -0700169 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700170 * Only the Android framework can register a {@code PhoneAccount} having this capability.
171 * <p>
172 * See {@link #getCapabilities}
Ihab Awad7522bbd2014-07-18 15:53:17 -0700173 */
174 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
175
Ihab Awadf8b69882014-07-25 15:14:01 -0700176 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800177 * Flag indicating that this {@code PhoneAccount} is currently able to place video calls.
178 * <p>
179 * See also {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING} which indicates whether the
180 * {@code PhoneAccount} supports placing video calls.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700181 * <p>
182 * See {@link #getCapabilities}
Ihab Awadf8b69882014-07-25 15:14:01 -0700183 */
184 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
185
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700186 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700187 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
188 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
189 * <p>
190 * See {@link #getCapabilities}
191 */
192 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
193
194 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800195 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
196 * should only be used by system apps (and will be ignored for all other apps trying to use it).
197 * <p>
198 * See {@link #getCapabilities}
199 * @hide
200 */
Brian Attwellad147f42014-12-19 11:37:16 -0800201 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800202 public static final int CAPABILITY_MULTI_USER = 0x20;
203
204 /**
Tyler Gunn65a3d342015-07-27 16:06:16 -0700205 * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a
206 * caller is able to specify a short subject line for an outgoing call. A capable receiving
207 * device displays the call subject on the incoming call screen.
208 * <p>
209 * See {@link #getCapabilities}
210 */
211 public static final int CAPABILITY_CALL_SUBJECT = 0x40;
212
213 /**
Bryce Leeb96d89c2015-10-14 16:48:40 -0700214 * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls.
215 * <p>
216 * See {@link #getCapabilities}
217 * @hide
218 */
219 public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80;
220
221 /**
Tyler Gunn9a365752015-12-09 15:00:18 -0800222 * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a
223 * number relies on presence. Should only be set if the {@code PhoneAccount} also has
224 * {@link #CAPABILITY_VIDEO_CALLING}.
225 * <p>
226 * When set, the {@link ConnectionService} is responsible for toggling the
227 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the
228 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether
229 * a contact's phone number supports video calling.
230 * <p>
231 * See {@link #getCapabilities}
232 */
233 public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100;
234
235 /**
Tyler Gunncee9ea62016-03-24 11:45:43 -0700236 * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed.
237 * <p>
238 * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will
239 * convert all outgoing video calls to emergency numbers to audio-only.
240 * @hide
241 */
242 public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200;
243
244 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800245 * Flag indicating that this {@link PhoneAccount} supports video calling.
246 * This is not an indication that the {@link PhoneAccount} is currently able to make a video
247 * call, but rather that it has the ability to make video calls (but not necessarily at this
248 * time).
249 * <p>
250 * Whether a {@link PhoneAccount} can make a video call is ultimately controlled by
251 * {@link #CAPABILITY_VIDEO_CALLING}, which indicates whether the {@link PhoneAccount} is
252 * currently capable of making a video call. Consider a case where, for example, a
253 * {@link PhoneAccount} supports making video calls (e.g.
254 * {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING}), but a current lack of network connectivity
255 * prevents video calls from being made (e.g. {@link #CAPABILITY_VIDEO_CALLING}).
256 * <p>
257 * See {@link #getCapabilities}
258 */
259 public static final int CAPABILITY_SUPPORTS_VIDEO_CALLING = 0x400;
260
261 /**
Tyler Gunnf5035432017-01-09 09:43:12 -0800262 * Flag indicating that this {@link PhoneAccount} is responsible for managing its own
263 * {@link Connection}s. This type of {@link PhoneAccount} is ideal for use with standalone
264 * calling apps which do not wish to use the default phone app for {@link Connection} UX,
265 * but which want to leverage the call and audio routing capabilities of the Telecom framework.
266 * <p>
267 * When set, {@link Connection}s created by the self-managed {@link ConnectionService} will not
268 * be surfaced to implementations of the {@link InCallService} API. Thus it is the
269 * responsibility of a self-managed {@link ConnectionService} to provide a user interface for
270 * its {@link Connection}s.
271 * <p>
272 * Self-managed {@link Connection}s will, however, be displayed on connected Bluetooth devices.
273 */
274 public static final int CAPABILITY_SELF_MANAGED = 0x800;
275
276 /**
Hall Liu95d55872017-01-25 17:12:49 -0800277 * Flag indicating that this {@link PhoneAccount} is capable of making a call with an
278 * RTT (Real-time text) session.
279 * When set, Telecom will attempt to open an RTT session on outgoing calls that specify
280 * that they should be placed with an RTT session , and the in-call app will be displayed
281 * with text entry fields for RTT. Likewise, the in-call app can request that an RTT
282 * session be opened during a call if this bit is set.
283 */
284 public static final int CAPABILITY_RTT = 0x1000;
285
286 /* NEXT CAPABILITY: 0x2000 */
287
288 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700289 * URI scheme for telephone number URIs.
290 */
291 public static final String SCHEME_TEL = "tel";
292
293 /**
294 * URI scheme for voicemail URIs.
295 */
296 public static final String SCHEME_VOICEMAIL = "voicemail";
297
298 /**
299 * URI scheme for SIP URIs.
300 */
301 public static final String SCHEME_SIP = "sip";
302
Nancy Chen3ace54b2014-10-22 17:45:26 -0700303 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800304 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700305 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700306 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800307 public static final int NO_ICON_TINT = 0;
308
309 /**
310 * Indicating no hightlight color is set.
311 */
312 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700313
Ihab Awad476cc832014-11-03 09:47:51 -0800314 /**
315 * Indicating no resource ID is set.
316 */
317 public static final int NO_RESOURCE_ID = -1;
318
Evan Charlton8c8a0622014-07-20 12:31:00 -0700319 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700320 private final Uri mAddress;
321 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700322 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800323 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700324 private final CharSequence mLabel;
325 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700326 private final List<String> mSupportedUriSchemes;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800327 private final int mSupportedAudioRoutes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700328 private final Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700329 private final Bundle mExtras;
Santos Cordon91371dc2015-05-08 13:52:09 -0700330 private boolean mIsEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700331 private String mGroupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700332
Santos Cordon32c65a52014-10-27 14:57:49 -0700333 /**
334 * Helper class for creating a {@link PhoneAccount}.
335 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700336 public static class Builder {
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800337
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700338 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700339 private Uri mAddress;
340 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700341 private int mCapabilities;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800342 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800343 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700344 private CharSequence mLabel;
345 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700346 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700347 private Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700348 private Bundle mExtras;
Santos Cordon91371dc2015-05-08 13:52:09 -0700349 private boolean mIsEnabled = false;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700350 private String mGroupId = "";
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700351
Santos Cordon32c65a52014-10-27 14:57:49 -0700352 /**
353 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
354 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700355 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
356 this.mAccountHandle = accountHandle;
357 this.mLabel = label;
358 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700359
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700360 /**
361 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
362 * {@link PhoneAccount}.
363 *
364 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
365 */
366 public Builder(PhoneAccount phoneAccount) {
367 mAccountHandle = phoneAccount.getAccountHandle();
368 mAddress = phoneAccount.getAddress();
369 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
370 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800371 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700372 mLabel = phoneAccount.getLabel();
373 mShortDescription = phoneAccount.getShortDescription();
374 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700375 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc2015-05-08 13:52:09 -0700376 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunnd426b202015-10-13 13:33:53 -0700377 mExtras = phoneAccount.getExtras();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700378 mGroupId = phoneAccount.getGroupId();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800379 mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700380 }
381
Santos Cordon32c65a52014-10-27 14:57:49 -0700382 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700383 * Sets the label. See {@link PhoneAccount#getLabel()}.
384 *
385 * @param label The label of the phone account.
386 * @return The builder.
387 * @hide
388 */
389 public Builder setLabel(CharSequence label) {
390 this.mLabel = label;
391 return this;
392 }
393
394 /**
Santos Cordon32c65a52014-10-27 14:57:49 -0700395 * Sets the address. See {@link PhoneAccount#getAddress}.
396 *
397 * @param value The address of the phone account.
398 * @return The builder.
399 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700400 public Builder setAddress(Uri value) {
401 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700402 return this;
403 }
404
Santos Cordon32c65a52014-10-27 14:57:49 -0700405 /**
406 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
407 *
408 * @param value The subscription address.
409 * @return The builder.
410 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700411 public Builder setSubscriptionAddress(Uri value) {
412 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700413 return this;
414 }
415
Santos Cordon32c65a52014-10-27 14:57:49 -0700416 /**
417 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
418 *
419 * @param value The capabilities to set.
420 * @return The builder.
421 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700422 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700423 this.mCapabilities = value;
424 return this;
425 }
426
Santos Cordon32c65a52014-10-27 14:57:49 -0700427 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700428 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700429 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700430 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700431 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700432 public Builder setIcon(Icon icon) {
433 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700434 return this;
435 }
436
437 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800438 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700439 *
Ihab Awad476cc832014-11-03 09:47:51 -0800440 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700441 * @return The builder.
442 */
Ihab Awad476cc832014-11-03 09:47:51 -0800443 public Builder setHighlightColor(int value) {
444 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700445 return this;
446 }
447
Santos Cordon32c65a52014-10-27 14:57:49 -0700448 /**
449 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
450 *
451 * @param value The short description.
452 * @return The builder.
453 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700454 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700455 this.mShortDescription = value;
456 return this;
457 }
458
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700459 /**
460 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
461 *
462 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700463 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700464 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700465 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700466 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
467 this.mSupportedUriSchemes.add(uriScheme);
468 }
469 return this;
470 }
471
472 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700473 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700474 *
475 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700476 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700477 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700478 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
479 mSupportedUriSchemes.clear();
480
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700481 if (uriSchemes != null && !uriSchemes.isEmpty()) {
482 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700483 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700484 }
485 }
486 return this;
487 }
488
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700489 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700490 * Specifies the extras associated with the {@link PhoneAccount}.
491 * <p>
492 * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer},
493 * and {@link Boolean}. Extras which are not of these types are ignored.
494 *
495 * @param extras
496 * @return
497 */
498 public Builder setExtras(Bundle extras) {
499 mExtras = extras;
500 return this;
501 }
502
503 /**
Santos Cordon91371dc2015-05-08 13:52:09 -0700504 * Sets the enabled state of the phone account.
505 *
506 * @param isEnabled The enabled state.
507 * @return The builder.
508 * @hide
509 */
510 public Builder setIsEnabled(boolean isEnabled) {
511 mIsEnabled = isEnabled;
512 return this;
513 }
514
515 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700516 * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is
517 * registered to Telecom, it will replace another {@link PhoneAccount} that is already
518 * registered in Telecom and take on the current user defaults and enabled status. There can
519 * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a
520 * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only
521 * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced.
522 * @param groupId The group Id of the {@link PhoneAccount} that will replace any other
523 * registered {@link PhoneAccount} in Telecom with the same Group Id.
524 * @return The builder
525 * @hide
526 */
527 public Builder setGroupId(String groupId) {
528 if (groupId != null) {
529 mGroupId = groupId;
530 } else {
531 mGroupId = "";
532 }
533 return this;
534 }
535
536 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800537 * Sets the audio routes supported by this {@link PhoneAccount}.
538 *
539 * @param routes bit mask of available routes.
540 * @return The builder.
541 * @hide
542 */
543 public Builder setSupportedAudioRoutes(int routes) {
544 mSupportedAudioRoutes = routes;
545 return this;
546 }
547
548 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700549 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
550 *
551 * @return The {@link PhoneAccount}.
552 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700553 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700554 // If no supported URI schemes were defined, assume "tel" is supported.
555 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700556 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700557 }
558
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700559 return new PhoneAccount(
560 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700561 mAddress,
562 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700563 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700564 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800565 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700566 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700567 mShortDescription,
Santos Cordon91371dc2015-05-08 13:52:09 -0700568 mSupportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700569 mExtras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800570 mSupportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700571 mIsEnabled,
572 mGroupId);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700573 }
574 }
575
576 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700577 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700578 Uri address,
579 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700580 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700581 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800582 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700583 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700584 CharSequence shortDescription,
Santos Cordon91371dc2015-05-08 13:52:09 -0700585 List<String> supportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700586 Bundle extras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800587 int supportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700588 boolean isEnabled,
589 String groupId) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700590 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700591 mAddress = address;
592 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700593 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700594 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800595 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700596 mLabel = label;
597 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700598 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700599 mExtras = extras;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800600 mSupportedAudioRoutes = supportedAudioRoutes;
Santos Cordon91371dc2015-05-08 13:52:09 -0700601 mIsEnabled = isEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700602 mGroupId = groupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700603 }
604
Andrew Lee3085a6c2014-09-04 10:59:13 -0700605 public static Builder builder(
606 PhoneAccountHandle accountHandle,
607 CharSequence label) {
608 return new Builder(accountHandle, label);
609 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700610
Ihab Awad807fe0a2014-07-09 12:30:52 -0700611 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700612 * Returns a builder initialized with the current {@link PhoneAccount} instance.
613 *
614 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700615 */
616 public Builder toBuilder() { return new Builder(this); }
617
618 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700619 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700620 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700621 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700622 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700623 public PhoneAccountHandle getAccountHandle() {
624 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700625 }
626
627 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700628 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700629 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700630 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700631 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700632 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700633 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700634 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700635 public Uri getAddress() {
636 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700637 }
638
639 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700640 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700641 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700642 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000643 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
644 * has been used to alter the callback number.
645 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700646 *
647 * @return The subscription number, suitable for display to the user.
648 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700649 public Uri getSubscriptionAddress() {
650 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700651 }
652
653 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700654 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700655 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700656 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700657 */
658 public int getCapabilities() {
659 return mCapabilities;
660 }
661
662 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700663 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
664 * bit mask.
665 *
666 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700667 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700668 */
669 public boolean hasCapabilities(int capability) {
670 return (mCapabilities & capability) == capability;
671 }
672
673 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800674 * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask.
675 *
676 * @param route The routes to check.
677 * @return {@code true} if the phone account has the routes.
678 * @hide
679 */
680 public boolean hasAudioRoutes(int routes) {
681 return (mSupportedAudioRoutes & routes) == routes;
682 }
683
684 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700685 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700686 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700687 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700688 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700689 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700690 return mLabel;
691 }
692
693 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700694 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700695 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700696 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700697 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700698 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700699 return mShortDescription;
700 }
701
702 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700703 * The URI schemes supported by this {@code PhoneAccount}.
704 *
705 * @return The URI schemes.
706 */
707 public List<String> getSupportedUriSchemes() {
708 return mSupportedUriSchemes;
709 }
710
711 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700712 * The extras associated with this {@code PhoneAccount}.
713 * <p>
714 * A {@link ConnectionService} may provide implementation specific information about the
715 * {@link PhoneAccount} via the extras.
716 *
717 * @return The extras.
718 */
719 public Bundle getExtras() {
720 return mExtras;
721 }
722
723 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800724 * The audio routes supported by this {@code PhoneAccount}.
725 *
726 * @hide
727 */
728 public int getSupportedAudioRoutes() {
729 return mSupportedAudioRoutes;
730 }
731
732 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700733 * The icon to represent this {@code PhoneAccount}.
734 *
735 * @return The icon.
736 */
737 public Icon getIcon() {
738 return mIcon;
739 }
740
741 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700742 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
743 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc2015-05-08 13:52:09 -0700744 *
Santos Cordon895d4b82015-06-25 16:41:48 -0700745 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc2015-05-08 13:52:09 -0700746 */
747 public boolean isEnabled() {
748 return mIsEnabled;
749 }
750
751 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700752 * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an
753 * empty {@link String} if the {@link PhoneAccount} is not in a group. If this
754 * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered
755 * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced,
756 * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}.
757 * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced.
758 *
759 * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group.
760 * @hide
761 */
762 public String getGroupId() {
763 return mGroupId;
764 }
765
766 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700767 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700768 * scheme.
769 *
770 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700771 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700772 * specified URI scheme.
773 */
774 public boolean supportsUriScheme(String uriScheme) {
775 if (mSupportedUriSchemes == null || uriScheme == null) {
776 return false;
777 }
778
779 for (String scheme : mSupportedUriSchemes) {
780 if (scheme != null && scheme.equals(uriScheme)) {
781 return true;
782 }
783 }
784 return false;
785 }
786
787 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800788 * A highlight color to use in displaying information about this {@code PhoneAccount}.
789 *
790 * @return A hexadecimal color value.
791 */
792 public int getHighlightColor() {
793 return mHighlightColor;
794 }
795
Santos Cordon91371dc2015-05-08 13:52:09 -0700796 /**
797 * Sets the enabled state of the phone account.
798 * @hide
799 */
800 public void setIsEnabled(boolean isEnabled) {
801 mIsEnabled = isEnabled;
802 }
803
Tyler Gunnf5035432017-01-09 09:43:12 -0800804 /**
805 * @return {@code true} if the {@link PhoneAccount} is self-managed, {@code false} otherwise.
806 * @hide
807 */
808 public boolean isSelfManaged() {
809 return (mCapabilities & CAPABILITY_SELF_MANAGED) == CAPABILITY_SELF_MANAGED;
810 }
811
Ihab Awad807fe0a2014-07-09 12:30:52 -0700812 //
813 // Parcelable implementation
814 //
815
816 @Override
817 public int describeContents() {
818 return 0;
819 }
820
821 @Override
822 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800823 if (mAccountHandle == null) {
824 out.writeInt(0);
825 } else {
826 out.writeInt(1);
827 mAccountHandle.writeToParcel(out, flags);
828 }
829 if (mAddress == null) {
830 out.writeInt(0);
831 } else {
832 out.writeInt(1);
833 mAddress.writeToParcel(out, flags);
834 }
835 if (mSubscriptionAddress == null) {
836 out.writeInt(0);
837 } else {
838 out.writeInt(1);
839 mSubscriptionAddress.writeToParcel(out, flags);
840 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700841 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800842 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700843 out.writeCharSequence(mLabel);
844 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800845 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc2015-05-08 13:52:09 -0700846
Santos Cordoncad84a22015-05-13 11:17:25 -0700847 if (mIcon == null) {
848 out.writeInt(0);
849 } else {
850 out.writeInt(1);
851 mIcon.writeToParcel(out, flags);
852 }
Santos Cordon91371dc2015-05-08 13:52:09 -0700853 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Tyler Gunnef829ec2015-10-08 09:46:23 -0700854 out.writeBundle(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700855 out.writeString(mGroupId);
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800856 out.writeInt(mSupportedAudioRoutes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700857 }
858
Evan Charlton8c8a0622014-07-20 12:31:00 -0700859 public static final Creator<PhoneAccount> CREATOR
860 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700861 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700862 public PhoneAccount createFromParcel(Parcel in) {
863 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700864 }
865
866 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700867 public PhoneAccount[] newArray(int size) {
868 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700869 }
870 };
871
Evan Charlton8c8a0622014-07-20 12:31:00 -0700872 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800873 if (in.readInt() > 0) {
874 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
875 } else {
876 mAccountHandle = null;
877 }
878 if (in.readInt() > 0) {
879 mAddress = Uri.CREATOR.createFromParcel(in);
880 } else {
881 mAddress = null;
882 }
883 if (in.readInt() > 0) {
884 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
885 } else {
886 mSubscriptionAddress = null;
887 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700888 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -0800889 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700890 mLabel = in.readCharSequence();
891 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800892 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -0700893 if (in.readInt() > 0) {
894 mIcon = Icon.CREATOR.createFromParcel(in);
895 } else {
896 mIcon = null;
897 }
Santos Cordon91371dc2015-05-08 13:52:09 -0700898 mIsEnabled = in.readByte() == 1;
Tyler Gunnef829ec2015-10-08 09:46:23 -0700899 mExtras = in.readBundle();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700900 mGroupId = in.readString();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800901 mSupportedAudioRoutes = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700902 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700903
904 @Override
905 public String toString() {
Santos Cordon91371dc2015-05-08 13:52:09 -0700906 StringBuilder sb = new StringBuilder().append("[[")
907 .append(mIsEnabled ? 'X' : ' ')
908 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700909 .append(mAccountHandle)
910 .append(" Capabilities: ")
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800911 .append(capabilitiesToString())
912 .append(" Audio Routes: ")
913 .append(audioRoutesToString())
Tyler Gunn76c01a52014-09-30 14:47:51 -0700914 .append(" Schemes: ");
915 for (String scheme : mSupportedUriSchemes) {
916 sb.append(scheme)
917 .append(" ");
918 }
Tyler Gunnef829ec2015-10-08 09:46:23 -0700919 sb.append(" Extras: ");
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700920 sb.append(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700921 sb.append(" GroupId: ");
922 sb.append(Log.pii(mGroupId));
Tyler Gunn76c01a52014-09-30 14:47:51 -0700923 sb.append("]");
924 return sb.toString();
925 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800926
927 /**
928 * Generates a string representation of a capabilities bitmask.
929 *
930 * @param capabilities The capabilities bitmask.
931 * @return String representation of the capabilities bitmask.
932 */
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800933 private String capabilitiesToString() {
Tyler Gunn3e122f72016-01-11 19:25:00 -0800934 StringBuilder sb = new StringBuilder();
Tyler Gunnf5035432017-01-09 09:43:12 -0800935 if (hasCapabilities(CAPABILITY_SELF_MANAGED)) {
936 sb.append("SelfManaged ");
937 }
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800938 if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) {
939 sb.append("SuppVideo ");
940 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800941 if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) {
942 sb.append("Video ");
943 }
944 if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
945 sb.append("Presence ");
946 }
947 if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) {
948 sb.append("CallProvider ");
949 }
950 if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) {
951 sb.append("CallSubject ");
952 }
953 if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) {
954 sb.append("ConnectionMgr ");
955 }
956 if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) {
957 sb.append("EmergOnly ");
958 }
959 if (hasCapabilities(CAPABILITY_MULTI_USER)) {
960 sb.append("MultiUser ");
961 }
962 if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) {
963 sb.append("PlaceEmerg ");
964 }
Tyler Gunncee9ea62016-03-24 11:45:43 -0700965 if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
966 sb.append("EmergVideo ");
967 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800968 if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) {
969 sb.append("SimSub ");
970 }
971 return sb.toString();
972 }
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800973
974 private String audioRoutesToString() {
975 StringBuilder sb = new StringBuilder();
976
977 if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) {
978 sb.append("B");
979 }
980 if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) {
981 sb.append("E");
982 }
983 if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) {
984 sb.append("S");
985 }
986 if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) {
987 sb.append("W");
988 }
989
990 return sb.toString();
991 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700992}