blob: 23600f23ca2ee4db8dc15d8df7dd0233d3994e23 [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
79 /**
Tyler Gunn8bf76572017-04-06 15:30:08 -070080 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
81 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
82 * connection (see {@link android.telecom.Call#EVENT_REQUEST_HANDOVER}) to this
83 * {@link PhoneAccount} from a {@link PhoneAccount} specifying
84 * {@link #EXTRA_SUPPORTS_HANDOVER_FROM}.
85 * <p>
86 * A handover request is initiated by the user from the default dialer app to indicate a desire
87 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
88 * @hide
89 */
90 public static final String EXTRA_SUPPORTS_HANDOVER_TO =
91 "android.telecom.extra.SUPPORTS_HANDOVER_TO";
92
93 /**
94 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
95 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
96 * connection from this {@link PhoneAccount} to another {@link PhoneAccount}.
97 * (see {@link android.telecom.Call#EVENT_REQUEST_HANDOVER}) which specifies
98 * {@link #EXTRA_SUPPORTS_HANDOVER_TO}.
99 * <p>
100 * A handover request is initiated by the user from the default dialer app to indicate a desire
101 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
102 * @hide
103 */
104 public static final String EXTRA_SUPPORTS_HANDOVER_FROM =
105 "android.telecom.extra.SUPPORTS_HANDOVER_FROM";
106
107 /**
Ihab Awadf8b69882014-07-25 15:14:01 -0700108 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
109 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
110 * will be allowed to manage phone calls including using its own proprietary phone-call
111 * implementation (like VoIP calling) to make calls instead of the telephony stack.
112 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700113 * When a user opts to place a call using the SIM-based telephony stack, the
114 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
115 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700116 * <p>
117 * See {@link #getCapabilities}
118 */
Ihab Awadf8b69882014-07-25 15:14:01 -0700119 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700120
121 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700122 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -0700123 * traditional SIM-based telephony calls. This account will be treated as a distinct method
124 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -0700125 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -0700126 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700127 * <p>
128 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700129 * <p>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700130 */
131 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
132
Ihab Awad7522bbd62014-07-18 15:53:17 -0700133 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700134 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -0700135 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -0700136 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700137 * Only the Android framework can register a {@code PhoneAccount} having this capability.
138 * <p>
139 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -0700140 */
141 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
142
Ihab Awadf8b69882014-07-25 15:14:01 -0700143 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800144 * Flag indicating that this {@code PhoneAccount} is currently able to place video calls.
145 * <p>
146 * See also {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING} which indicates whether the
147 * {@code PhoneAccount} supports placing video calls.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700148 * <p>
149 * See {@link #getCapabilities}
Ihab Awadf8b69882014-07-25 15:14:01 -0700150 */
151 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
152
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700153 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700154 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
155 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
156 * <p>
157 * See {@link #getCapabilities}
158 */
159 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
160
161 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800162 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
163 * should only be used by system apps (and will be ignored for all other apps trying to use it).
164 * <p>
165 * See {@link #getCapabilities}
166 * @hide
167 */
Brian Attwellad147f42014-12-19 11:37:16 -0800168 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800169 public static final int CAPABILITY_MULTI_USER = 0x20;
170
171 /**
Tyler Gunn65a3d342015-07-27 16:06:16 -0700172 * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a
173 * caller is able to specify a short subject line for an outgoing call. A capable receiving
174 * device displays the call subject on the incoming call screen.
175 * <p>
176 * See {@link #getCapabilities}
177 */
178 public static final int CAPABILITY_CALL_SUBJECT = 0x40;
179
180 /**
Bryce Leeb96d89c2015-10-14 16:48:40 -0700181 * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls.
182 * <p>
183 * See {@link #getCapabilities}
184 * @hide
185 */
186 public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80;
187
188 /**
Tyler Gunn9a365752015-12-09 15:00:18 -0800189 * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a
190 * number relies on presence. Should only be set if the {@code PhoneAccount} also has
191 * {@link #CAPABILITY_VIDEO_CALLING}.
192 * <p>
193 * When set, the {@link ConnectionService} is responsible for toggling the
194 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the
195 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether
196 * a contact's phone number supports video calling.
197 * <p>
198 * See {@link #getCapabilities}
199 */
200 public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100;
201
202 /**
Tyler Gunncee9ea62016-03-24 11:45:43 -0700203 * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed.
204 * <p>
205 * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will
206 * convert all outgoing video calls to emergency numbers to audio-only.
207 * @hide
208 */
209 public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200;
210
211 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800212 * Flag indicating that this {@link PhoneAccount} supports video calling.
213 * This is not an indication that the {@link PhoneAccount} is currently able to make a video
214 * call, but rather that it has the ability to make video calls (but not necessarily at this
215 * time).
216 * <p>
217 * Whether a {@link PhoneAccount} can make a video call is ultimately controlled by
218 * {@link #CAPABILITY_VIDEO_CALLING}, which indicates whether the {@link PhoneAccount} is
219 * currently capable of making a video call. Consider a case where, for example, a
220 * {@link PhoneAccount} supports making video calls (e.g.
221 * {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING}), but a current lack of network connectivity
222 * prevents video calls from being made (e.g. {@link #CAPABILITY_VIDEO_CALLING}).
223 * <p>
224 * See {@link #getCapabilities}
225 */
226 public static final int CAPABILITY_SUPPORTS_VIDEO_CALLING = 0x400;
227
228 /**
Tyler Gunnf5035432017-01-09 09:43:12 -0800229 * Flag indicating that this {@link PhoneAccount} is responsible for managing its own
230 * {@link Connection}s. This type of {@link PhoneAccount} is ideal for use with standalone
231 * calling apps which do not wish to use the default phone app for {@link Connection} UX,
232 * but which want to leverage the call and audio routing capabilities of the Telecom framework.
233 * <p>
234 * When set, {@link Connection}s created by the self-managed {@link ConnectionService} will not
235 * be surfaced to implementations of the {@link InCallService} API. Thus it is the
236 * responsibility of a self-managed {@link ConnectionService} to provide a user interface for
237 * its {@link Connection}s.
238 * <p>
239 * Self-managed {@link Connection}s will, however, be displayed on connected Bluetooth devices.
240 */
241 public static final int CAPABILITY_SELF_MANAGED = 0x800;
242
243 /**
Hall Liu95d55872017-01-25 17:12:49 -0800244 * Flag indicating that this {@link PhoneAccount} is capable of making a call with an
245 * RTT (Real-time text) session.
246 * When set, Telecom will attempt to open an RTT session on outgoing calls that specify
247 * that they should be placed with an RTT session , and the in-call app will be displayed
248 * with text entry fields for RTT. Likewise, the in-call app can request that an RTT
249 * session be opened during a call if this bit is set.
250 */
251 public static final int CAPABILITY_RTT = 0x1000;
252
253 /* NEXT CAPABILITY: 0x2000 */
254
255 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700256 * URI scheme for telephone number URIs.
257 */
258 public static final String SCHEME_TEL = "tel";
259
260 /**
261 * URI scheme for voicemail URIs.
262 */
263 public static final String SCHEME_VOICEMAIL = "voicemail";
264
265 /**
266 * URI scheme for SIP URIs.
267 */
268 public static final String SCHEME_SIP = "sip";
269
Nancy Chen3ace54b2014-10-22 17:45:26 -0700270 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800271 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700272 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700273 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800274 public static final int NO_ICON_TINT = 0;
275
276 /**
277 * Indicating no hightlight color is set.
278 */
279 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700280
Ihab Awad476cc832014-11-03 09:47:51 -0800281 /**
282 * Indicating no resource ID is set.
283 */
284 public static final int NO_RESOURCE_ID = -1;
285
Evan Charlton8c8a0622014-07-20 12:31:00 -0700286 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700287 private final Uri mAddress;
288 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700289 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800290 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700291 private final CharSequence mLabel;
292 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700293 private final List<String> mSupportedUriSchemes;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800294 private final int mSupportedAudioRoutes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700295 private final Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700296 private final Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700297 private boolean mIsEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700298 private String mGroupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700299
Santos Cordon32c65a52014-10-27 14:57:49 -0700300 /**
301 * Helper class for creating a {@link PhoneAccount}.
302 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700303 public static class Builder {
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800304
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700305 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700306 private Uri mAddress;
307 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700308 private int mCapabilities;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800309 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800310 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700311 private CharSequence mLabel;
312 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700313 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700314 private Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700315 private Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700316 private boolean mIsEnabled = false;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700317 private String mGroupId = "";
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700318
Santos Cordon32c65a52014-10-27 14:57:49 -0700319 /**
320 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
321 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700322 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
323 this.mAccountHandle = accountHandle;
324 this.mLabel = label;
325 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700326
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700327 /**
328 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
329 * {@link PhoneAccount}.
330 *
331 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
332 */
333 public Builder(PhoneAccount phoneAccount) {
334 mAccountHandle = phoneAccount.getAccountHandle();
335 mAddress = phoneAccount.getAddress();
336 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
337 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800338 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700339 mLabel = phoneAccount.getLabel();
340 mShortDescription = phoneAccount.getShortDescription();
341 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700342 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc02015-05-08 13:52:09 -0700343 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunnd426b202015-10-13 13:33:53 -0700344 mExtras = phoneAccount.getExtras();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700345 mGroupId = phoneAccount.getGroupId();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800346 mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700347 }
348
Santos Cordon32c65a52014-10-27 14:57:49 -0700349 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700350 * Sets the label. See {@link PhoneAccount#getLabel()}.
351 *
352 * @param label The label of the phone account.
353 * @return The builder.
354 * @hide
355 */
356 public Builder setLabel(CharSequence label) {
357 this.mLabel = label;
358 return this;
359 }
360
361 /**
Santos Cordon32c65a52014-10-27 14:57:49 -0700362 * Sets the address. See {@link PhoneAccount#getAddress}.
363 *
364 * @param value The address of the phone account.
365 * @return The builder.
366 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700367 public Builder setAddress(Uri value) {
368 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700369 return this;
370 }
371
Santos Cordon32c65a52014-10-27 14:57:49 -0700372 /**
373 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
374 *
375 * @param value The subscription address.
376 * @return The builder.
377 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700378 public Builder setSubscriptionAddress(Uri value) {
379 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700380 return this;
381 }
382
Santos Cordon32c65a52014-10-27 14:57:49 -0700383 /**
384 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
385 *
386 * @param value The capabilities to set.
387 * @return The builder.
388 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700389 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700390 this.mCapabilities = value;
391 return this;
392 }
393
Santos Cordon32c65a52014-10-27 14:57:49 -0700394 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700395 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700396 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700397 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700398 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700399 public Builder setIcon(Icon icon) {
400 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700401 return this;
402 }
403
404 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800405 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700406 *
Ihab Awad476cc832014-11-03 09:47:51 -0800407 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700408 * @return The builder.
409 */
Ihab Awad476cc832014-11-03 09:47:51 -0800410 public Builder setHighlightColor(int value) {
411 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700412 return this;
413 }
414
Santos Cordon32c65a52014-10-27 14:57:49 -0700415 /**
416 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
417 *
418 * @param value The short description.
419 * @return The builder.
420 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700421 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700422 this.mShortDescription = value;
423 return this;
424 }
425
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700426 /**
427 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
428 *
429 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700430 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700431 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700432 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700433 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
434 this.mSupportedUriSchemes.add(uriScheme);
435 }
436 return this;
437 }
438
439 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700440 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700441 *
442 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700443 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700444 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700445 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
446 mSupportedUriSchemes.clear();
447
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700448 if (uriSchemes != null && !uriSchemes.isEmpty()) {
449 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700450 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700451 }
452 }
453 return this;
454 }
455
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700456 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700457 * Specifies the extras associated with the {@link PhoneAccount}.
458 * <p>
459 * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer},
460 * and {@link Boolean}. Extras which are not of these types are ignored.
461 *
462 * @param extras
463 * @return
464 */
465 public Builder setExtras(Bundle extras) {
466 mExtras = extras;
467 return this;
468 }
469
470 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700471 * Sets the enabled state of the phone account.
472 *
473 * @param isEnabled The enabled state.
474 * @return The builder.
475 * @hide
476 */
477 public Builder setIsEnabled(boolean isEnabled) {
478 mIsEnabled = isEnabled;
479 return this;
480 }
481
482 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700483 * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is
484 * registered to Telecom, it will replace another {@link PhoneAccount} that is already
485 * registered in Telecom and take on the current user defaults and enabled status. There can
486 * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a
487 * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only
488 * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced.
489 * @param groupId The group Id of the {@link PhoneAccount} that will replace any other
490 * registered {@link PhoneAccount} in Telecom with the same Group Id.
491 * @return The builder
492 * @hide
493 */
494 public Builder setGroupId(String groupId) {
495 if (groupId != null) {
496 mGroupId = groupId;
497 } else {
498 mGroupId = "";
499 }
500 return this;
501 }
502
503 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800504 * Sets the audio routes supported by this {@link PhoneAccount}.
505 *
506 * @param routes bit mask of available routes.
507 * @return The builder.
508 * @hide
509 */
510 public Builder setSupportedAudioRoutes(int routes) {
511 mSupportedAudioRoutes = routes;
512 return this;
513 }
514
515 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700516 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
517 *
518 * @return The {@link PhoneAccount}.
519 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700520 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700521 // If no supported URI schemes were defined, assume "tel" is supported.
522 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700523 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700524 }
525
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700526 return new PhoneAccount(
527 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700528 mAddress,
529 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700530 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700531 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800532 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700533 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700534 mShortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700535 mSupportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700536 mExtras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800537 mSupportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700538 mIsEnabled,
539 mGroupId);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700540 }
541 }
542
543 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700544 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700545 Uri address,
546 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700547 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700548 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800549 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700550 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700551 CharSequence shortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700552 List<String> supportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700553 Bundle extras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800554 int supportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700555 boolean isEnabled,
556 String groupId) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700557 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700558 mAddress = address;
559 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700560 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700561 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800562 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700563 mLabel = label;
564 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700565 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700566 mExtras = extras;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800567 mSupportedAudioRoutes = supportedAudioRoutes;
Santos Cordon91371dc02015-05-08 13:52:09 -0700568 mIsEnabled = isEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700569 mGroupId = groupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700570 }
571
Andrew Lee3085a6c2014-09-04 10:59:13 -0700572 public static Builder builder(
573 PhoneAccountHandle accountHandle,
574 CharSequence label) {
575 return new Builder(accountHandle, label);
576 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700577
Ihab Awad807fe0a2014-07-09 12:30:52 -0700578 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700579 * Returns a builder initialized with the current {@link PhoneAccount} instance.
580 *
581 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700582 */
583 public Builder toBuilder() { return new Builder(this); }
584
585 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700586 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700587 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700588 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700589 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700590 public PhoneAccountHandle getAccountHandle() {
591 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700592 }
593
594 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700595 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700596 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700597 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700598 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700599 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700600 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700601 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700602 public Uri getAddress() {
603 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700604 }
605
606 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700607 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700608 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700609 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000610 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
611 * has been used to alter the callback number.
612 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700613 *
614 * @return The subscription number, suitable for display to the user.
615 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700616 public Uri getSubscriptionAddress() {
617 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700618 }
619
620 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700621 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700622 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700623 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700624 */
625 public int getCapabilities() {
626 return mCapabilities;
627 }
628
629 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700630 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
631 * bit mask.
632 *
633 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700634 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700635 */
636 public boolean hasCapabilities(int capability) {
637 return (mCapabilities & capability) == capability;
638 }
639
640 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800641 * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask.
642 *
643 * @param route The routes to check.
644 * @return {@code true} if the phone account has the routes.
645 * @hide
646 */
647 public boolean hasAudioRoutes(int routes) {
648 return (mSupportedAudioRoutes & routes) == routes;
649 }
650
651 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700652 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700653 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700654 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700655 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700656 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700657 return mLabel;
658 }
659
660 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700661 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700662 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700663 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700664 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700665 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700666 return mShortDescription;
667 }
668
669 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700670 * The URI schemes supported by this {@code PhoneAccount}.
671 *
672 * @return The URI schemes.
673 */
674 public List<String> getSupportedUriSchemes() {
675 return mSupportedUriSchemes;
676 }
677
678 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700679 * The extras associated with this {@code PhoneAccount}.
680 * <p>
681 * A {@link ConnectionService} may provide implementation specific information about the
682 * {@link PhoneAccount} via the extras.
683 *
684 * @return The extras.
685 */
686 public Bundle getExtras() {
687 return mExtras;
688 }
689
690 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800691 * The audio routes supported by this {@code PhoneAccount}.
692 *
693 * @hide
694 */
695 public int getSupportedAudioRoutes() {
696 return mSupportedAudioRoutes;
697 }
698
699 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700700 * The icon to represent this {@code PhoneAccount}.
701 *
702 * @return The icon.
703 */
704 public Icon getIcon() {
705 return mIcon;
706 }
707
708 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700709 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
710 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc02015-05-08 13:52:09 -0700711 *
Santos Cordon895d4b82015-06-25 16:41:48 -0700712 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc02015-05-08 13:52:09 -0700713 */
714 public boolean isEnabled() {
715 return mIsEnabled;
716 }
717
718 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700719 * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an
720 * empty {@link String} if the {@link PhoneAccount} is not in a group. If this
721 * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered
722 * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced,
723 * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}.
724 * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced.
725 *
726 * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group.
727 * @hide
728 */
729 public String getGroupId() {
730 return mGroupId;
731 }
732
733 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700734 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700735 * scheme.
736 *
737 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700738 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700739 * specified URI scheme.
740 */
741 public boolean supportsUriScheme(String uriScheme) {
742 if (mSupportedUriSchemes == null || uriScheme == null) {
743 return false;
744 }
745
746 for (String scheme : mSupportedUriSchemes) {
747 if (scheme != null && scheme.equals(uriScheme)) {
748 return true;
749 }
750 }
751 return false;
752 }
753
754 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800755 * A highlight color to use in displaying information about this {@code PhoneAccount}.
756 *
757 * @return A hexadecimal color value.
758 */
759 public int getHighlightColor() {
760 return mHighlightColor;
761 }
762
Santos Cordon91371dc02015-05-08 13:52:09 -0700763 /**
764 * Sets the enabled state of the phone account.
765 * @hide
766 */
767 public void setIsEnabled(boolean isEnabled) {
768 mIsEnabled = isEnabled;
769 }
770
Tyler Gunnf5035432017-01-09 09:43:12 -0800771 /**
772 * @return {@code true} if the {@link PhoneAccount} is self-managed, {@code false} otherwise.
773 * @hide
774 */
775 public boolean isSelfManaged() {
776 return (mCapabilities & CAPABILITY_SELF_MANAGED) == CAPABILITY_SELF_MANAGED;
777 }
778
Ihab Awad807fe0a2014-07-09 12:30:52 -0700779 //
780 // Parcelable implementation
781 //
782
783 @Override
784 public int describeContents() {
785 return 0;
786 }
787
788 @Override
789 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800790 if (mAccountHandle == null) {
791 out.writeInt(0);
792 } else {
793 out.writeInt(1);
794 mAccountHandle.writeToParcel(out, flags);
795 }
796 if (mAddress == null) {
797 out.writeInt(0);
798 } else {
799 out.writeInt(1);
800 mAddress.writeToParcel(out, flags);
801 }
802 if (mSubscriptionAddress == null) {
803 out.writeInt(0);
804 } else {
805 out.writeInt(1);
806 mSubscriptionAddress.writeToParcel(out, flags);
807 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700808 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800809 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700810 out.writeCharSequence(mLabel);
811 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800812 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc02015-05-08 13:52:09 -0700813
Santos Cordoncad84a22015-05-13 11:17:25 -0700814 if (mIcon == null) {
815 out.writeInt(0);
816 } else {
817 out.writeInt(1);
818 mIcon.writeToParcel(out, flags);
819 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700820 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Tyler Gunnef829ec2015-10-08 09:46:23 -0700821 out.writeBundle(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700822 out.writeString(mGroupId);
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800823 out.writeInt(mSupportedAudioRoutes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700824 }
825
Evan Charlton8c8a0622014-07-20 12:31:00 -0700826 public static final Creator<PhoneAccount> CREATOR
827 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700828 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700829 public PhoneAccount createFromParcel(Parcel in) {
830 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700831 }
832
833 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700834 public PhoneAccount[] newArray(int size) {
835 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700836 }
837 };
838
Evan Charlton8c8a0622014-07-20 12:31:00 -0700839 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800840 if (in.readInt() > 0) {
841 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
842 } else {
843 mAccountHandle = null;
844 }
845 if (in.readInt() > 0) {
846 mAddress = Uri.CREATOR.createFromParcel(in);
847 } else {
848 mAddress = null;
849 }
850 if (in.readInt() > 0) {
851 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
852 } else {
853 mSubscriptionAddress = null;
854 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700855 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -0800856 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700857 mLabel = in.readCharSequence();
858 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800859 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -0700860 if (in.readInt() > 0) {
861 mIcon = Icon.CREATOR.createFromParcel(in);
862 } else {
863 mIcon = null;
864 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700865 mIsEnabled = in.readByte() == 1;
Tyler Gunnef829ec2015-10-08 09:46:23 -0700866 mExtras = in.readBundle();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700867 mGroupId = in.readString();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800868 mSupportedAudioRoutes = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700869 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700870
871 @Override
872 public String toString() {
Santos Cordon91371dc02015-05-08 13:52:09 -0700873 StringBuilder sb = new StringBuilder().append("[[")
874 .append(mIsEnabled ? 'X' : ' ')
875 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700876 .append(mAccountHandle)
877 .append(" Capabilities: ")
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800878 .append(capabilitiesToString())
879 .append(" Audio Routes: ")
880 .append(audioRoutesToString())
Tyler Gunn76c01a52014-09-30 14:47:51 -0700881 .append(" Schemes: ");
882 for (String scheme : mSupportedUriSchemes) {
883 sb.append(scheme)
884 .append(" ");
885 }
Tyler Gunnef829ec2015-10-08 09:46:23 -0700886 sb.append(" Extras: ");
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700887 sb.append(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700888 sb.append(" GroupId: ");
889 sb.append(Log.pii(mGroupId));
Tyler Gunn76c01a52014-09-30 14:47:51 -0700890 sb.append("]");
891 return sb.toString();
892 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800893
894 /**
895 * Generates a string representation of a capabilities bitmask.
896 *
897 * @param capabilities The capabilities bitmask.
898 * @return String representation of the capabilities bitmask.
899 */
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800900 private String capabilitiesToString() {
Tyler Gunn3e122f72016-01-11 19:25:00 -0800901 StringBuilder sb = new StringBuilder();
Tyler Gunnf5035432017-01-09 09:43:12 -0800902 if (hasCapabilities(CAPABILITY_SELF_MANAGED)) {
903 sb.append("SelfManaged ");
904 }
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800905 if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) {
906 sb.append("SuppVideo ");
907 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800908 if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) {
909 sb.append("Video ");
910 }
911 if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
912 sb.append("Presence ");
913 }
914 if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) {
915 sb.append("CallProvider ");
916 }
917 if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) {
918 sb.append("CallSubject ");
919 }
920 if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) {
921 sb.append("ConnectionMgr ");
922 }
923 if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) {
924 sb.append("EmergOnly ");
925 }
926 if (hasCapabilities(CAPABILITY_MULTI_USER)) {
927 sb.append("MultiUser ");
928 }
929 if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) {
930 sb.append("PlaceEmerg ");
931 }
Tyler Gunncee9ea62016-03-24 11:45:43 -0700932 if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
933 sb.append("EmergVideo ");
934 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800935 if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) {
936 sb.append("SimSub ");
937 }
938 return sb.toString();
939 }
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800940
941 private String audioRoutesToString() {
942 StringBuilder sb = new StringBuilder();
943
944 if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) {
945 sb.append("B");
946 }
947 if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) {
948 sb.append("E");
949 }
950 if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) {
951 sb.append("S");
952 }
953 if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) {
954 sb.append("W");
955 }
956
957 return sb.toString();
958 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700959}