blob: 4390fae226e562e17c1d9a0593f9c9caafd60b48 [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
Ta-wei Yen9d20d982017-06-02 11:07:07 -070095 * indicates whether this {@link PhoneAccount} supports using a fallback if video calling is
96 * not available. This extra is for device level support, {@link
97 * android.telephony.CarrierConfigManager#KEY_ALLOW_VIDEO_CALLING_FALLBACK_BOOL} should also
98 * be checked to ensure it is not disabled by individual carrier.
99 *
100 * @hide
101 */
102 public static final String EXTRA_SUPPORTS_VIDEO_CALLING_FALLBACK =
103 "android.telecom.extra.SUPPORTS_VIDEO_CALLING_FALLBACK";
104
105 /**
106 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Tyler Gunn8bf76572017-04-06 15:30:08 -0700107 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
108 * connection from this {@link PhoneAccount} to another {@link PhoneAccount}.
109 * (see {@link android.telecom.Call#EVENT_REQUEST_HANDOVER}) which specifies
110 * {@link #EXTRA_SUPPORTS_HANDOVER_TO}.
111 * <p>
112 * A handover request is initiated by the user from the default dialer app to indicate a desire
113 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
114 * @hide
115 */
116 public static final String EXTRA_SUPPORTS_HANDOVER_FROM =
117 "android.telecom.extra.SUPPORTS_HANDOVER_FROM";
118
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700119
120 /**
121 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
122 * indicates whether a Self-Managed {@link PhoneAccount} should log its calls to the call log.
123 * <p>
124 * By default, Self-Managed {@link PhoneAccount}s do not log their calls to the call log.
125 * Setting this extra to {@code true} provides a means for them to log their calls.
126 * @hide
127 */
128 public static final String EXTRA_LOG_SELF_MANAGED_CALLS =
129 "android.telecom.extra.LOG_SELF_MANAGED_CALLS";
130
Tyler Gunn8bf76572017-04-06 15:30:08 -0700131 /**
Ihab Awadf8b69882014-07-25 15:14:01 -0700132 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
133 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
134 * will be allowed to manage phone calls including using its own proprietary phone-call
135 * implementation (like VoIP calling) to make calls instead of the telephony stack.
136 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700137 * When a user opts to place a call using the SIM-based telephony stack, the
138 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
139 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700140 * <p>
141 * See {@link #getCapabilities}
142 */
Ihab Awadf8b69882014-07-25 15:14:01 -0700143 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700144
145 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700146 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -0700147 * traditional SIM-based telephony calls. This account will be treated as a distinct method
148 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -0700149 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -0700150 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700151 * <p>
152 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700153 * <p>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700154 */
155 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
156
Ihab Awad7522bbd62014-07-18 15:53:17 -0700157 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700158 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -0700159 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -0700160 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700161 * Only the Android framework can register a {@code PhoneAccount} having this capability.
162 * <p>
163 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -0700164 */
165 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
166
Ihab Awadf8b69882014-07-25 15:14:01 -0700167 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800168 * Flag indicating that this {@code PhoneAccount} is currently able to place video calls.
169 * <p>
170 * See also {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING} which indicates whether the
171 * {@code PhoneAccount} supports placing video calls.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700172 * <p>
173 * See {@link #getCapabilities}
Ihab Awadf8b69882014-07-25 15:14:01 -0700174 */
175 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
176
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700177 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700178 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
179 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
180 * <p>
181 * See {@link #getCapabilities}
182 */
183 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
184
185 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800186 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
187 * should only be used by system apps (and will be ignored for all other apps trying to use it).
188 * <p>
189 * See {@link #getCapabilities}
190 * @hide
191 */
Brian Attwellad147f42014-12-19 11:37:16 -0800192 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800193 public static final int CAPABILITY_MULTI_USER = 0x20;
194
195 /**
Tyler Gunn65a3d342015-07-27 16:06:16 -0700196 * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a
197 * caller is able to specify a short subject line for an outgoing call. A capable receiving
198 * device displays the call subject on the incoming call screen.
199 * <p>
200 * See {@link #getCapabilities}
201 */
202 public static final int CAPABILITY_CALL_SUBJECT = 0x40;
203
204 /**
Bryce Leeb96d89c2015-10-14 16:48:40 -0700205 * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls.
206 * <p>
207 * See {@link #getCapabilities}
208 * @hide
209 */
210 public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80;
211
212 /**
Tyler Gunn9a365752015-12-09 15:00:18 -0800213 * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a
214 * number relies on presence. Should only be set if the {@code PhoneAccount} also has
215 * {@link #CAPABILITY_VIDEO_CALLING}.
216 * <p>
217 * When set, the {@link ConnectionService} is responsible for toggling the
218 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the
219 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether
220 * a contact's phone number supports video calling.
221 * <p>
222 * See {@link #getCapabilities}
223 */
224 public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100;
225
226 /**
Tyler Gunncee9ea62016-03-24 11:45:43 -0700227 * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed.
228 * <p>
229 * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will
230 * convert all outgoing video calls to emergency numbers to audio-only.
231 * @hide
232 */
233 public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200;
234
235 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800236 * Flag indicating that this {@link PhoneAccount} supports video calling.
237 * This is not an indication that the {@link PhoneAccount} is currently able to make a video
238 * call, but rather that it has the ability to make video calls (but not necessarily at this
239 * time).
240 * <p>
241 * Whether a {@link PhoneAccount} can make a video call is ultimately controlled by
242 * {@link #CAPABILITY_VIDEO_CALLING}, which indicates whether the {@link PhoneAccount} is
243 * currently capable of making a video call. Consider a case where, for example, a
244 * {@link PhoneAccount} supports making video calls (e.g.
245 * {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING}), but a current lack of network connectivity
246 * prevents video calls from being made (e.g. {@link #CAPABILITY_VIDEO_CALLING}).
247 * <p>
248 * See {@link #getCapabilities}
249 */
250 public static final int CAPABILITY_SUPPORTS_VIDEO_CALLING = 0x400;
251
252 /**
Tyler Gunnf5035432017-01-09 09:43:12 -0800253 * Flag indicating that this {@link PhoneAccount} is responsible for managing its own
254 * {@link Connection}s. This type of {@link PhoneAccount} is ideal for use with standalone
255 * calling apps which do not wish to use the default phone app for {@link Connection} UX,
256 * but which want to leverage the call and audio routing capabilities of the Telecom framework.
257 * <p>
258 * When set, {@link Connection}s created by the self-managed {@link ConnectionService} will not
259 * be surfaced to implementations of the {@link InCallService} API. Thus it is the
260 * responsibility of a self-managed {@link ConnectionService} to provide a user interface for
261 * its {@link Connection}s.
262 * <p>
263 * Self-managed {@link Connection}s will, however, be displayed on connected Bluetooth devices.
264 */
265 public static final int CAPABILITY_SELF_MANAGED = 0x800;
266
267 /**
Hall Liu95d55872017-01-25 17:12:49 -0800268 * Flag indicating that this {@link PhoneAccount} is capable of making a call with an
269 * RTT (Real-time text) session.
270 * When set, Telecom will attempt to open an RTT session on outgoing calls that specify
271 * that they should be placed with an RTT session , and the in-call app will be displayed
272 * with text entry fields for RTT. Likewise, the in-call app can request that an RTT
273 * session be opened during a call if this bit is set.
274 */
275 public static final int CAPABILITY_RTT = 0x1000;
276
277 /* NEXT CAPABILITY: 0x2000 */
278
279 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700280 * URI scheme for telephone number URIs.
281 */
282 public static final String SCHEME_TEL = "tel";
283
284 /**
285 * URI scheme for voicemail URIs.
286 */
287 public static final String SCHEME_VOICEMAIL = "voicemail";
288
289 /**
290 * URI scheme for SIP URIs.
291 */
292 public static final String SCHEME_SIP = "sip";
293
Nancy Chen3ace54b2014-10-22 17:45:26 -0700294 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800295 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700296 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700297 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800298 public static final int NO_ICON_TINT = 0;
299
300 /**
301 * Indicating no hightlight color is set.
302 */
303 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700304
Ihab Awad476cc832014-11-03 09:47:51 -0800305 /**
306 * Indicating no resource ID is set.
307 */
308 public static final int NO_RESOURCE_ID = -1;
309
Evan Charlton8c8a0622014-07-20 12:31:00 -0700310 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700311 private final Uri mAddress;
312 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700313 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800314 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700315 private final CharSequence mLabel;
316 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700317 private final List<String> mSupportedUriSchemes;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800318 private final int mSupportedAudioRoutes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700319 private final Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700320 private final Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700321 private boolean mIsEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700322 private String mGroupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700323
Santos Cordon32c65a52014-10-27 14:57:49 -0700324 /**
325 * Helper class for creating a {@link PhoneAccount}.
326 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700327 public static class Builder {
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800328
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700329 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700330 private Uri mAddress;
331 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700332 private int mCapabilities;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800333 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800334 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700335 private CharSequence mLabel;
336 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700337 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700338 private Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700339 private Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700340 private boolean mIsEnabled = false;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700341 private String mGroupId = "";
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700342
Santos Cordon32c65a52014-10-27 14:57:49 -0700343 /**
344 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
345 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700346 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
347 this.mAccountHandle = accountHandle;
348 this.mLabel = label;
349 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700350
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700351 /**
352 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
353 * {@link PhoneAccount}.
354 *
355 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
356 */
357 public Builder(PhoneAccount phoneAccount) {
358 mAccountHandle = phoneAccount.getAccountHandle();
359 mAddress = phoneAccount.getAddress();
360 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
361 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800362 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700363 mLabel = phoneAccount.getLabel();
364 mShortDescription = phoneAccount.getShortDescription();
365 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700366 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc02015-05-08 13:52:09 -0700367 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunnd426b202015-10-13 13:33:53 -0700368 mExtras = phoneAccount.getExtras();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700369 mGroupId = phoneAccount.getGroupId();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800370 mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700371 }
372
Santos Cordon32c65a52014-10-27 14:57:49 -0700373 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700374 * Sets the label. See {@link PhoneAccount#getLabel()}.
375 *
376 * @param label The label of the phone account.
377 * @return The builder.
378 * @hide
379 */
380 public Builder setLabel(CharSequence label) {
381 this.mLabel = label;
382 return this;
383 }
384
385 /**
Santos Cordon32c65a52014-10-27 14:57:49 -0700386 * Sets the address. See {@link PhoneAccount#getAddress}.
387 *
388 * @param value The address of the phone account.
389 * @return The builder.
390 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700391 public Builder setAddress(Uri value) {
392 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700393 return this;
394 }
395
Santos Cordon32c65a52014-10-27 14:57:49 -0700396 /**
397 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
398 *
399 * @param value The subscription address.
400 * @return The builder.
401 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700402 public Builder setSubscriptionAddress(Uri value) {
403 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700404 return this;
405 }
406
Santos Cordon32c65a52014-10-27 14:57:49 -0700407 /**
408 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
409 *
410 * @param value The capabilities to set.
411 * @return The builder.
412 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700413 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700414 this.mCapabilities = value;
415 return this;
416 }
417
Santos Cordon32c65a52014-10-27 14:57:49 -0700418 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700419 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700420 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700421 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700422 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700423 public Builder setIcon(Icon icon) {
424 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700425 return this;
426 }
427
428 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800429 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700430 *
Ihab Awad476cc832014-11-03 09:47:51 -0800431 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700432 * @return The builder.
433 */
Ihab Awad476cc832014-11-03 09:47:51 -0800434 public Builder setHighlightColor(int value) {
435 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700436 return this;
437 }
438
Santos Cordon32c65a52014-10-27 14:57:49 -0700439 /**
440 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
441 *
442 * @param value The short description.
443 * @return The builder.
444 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700445 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700446 this.mShortDescription = value;
447 return this;
448 }
449
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700450 /**
451 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
452 *
453 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700454 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700455 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700456 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700457 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
458 this.mSupportedUriSchemes.add(uriScheme);
459 }
460 return this;
461 }
462
463 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700464 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700465 *
466 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700467 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700468 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700469 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
470 mSupportedUriSchemes.clear();
471
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700472 if (uriSchemes != null && !uriSchemes.isEmpty()) {
473 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700474 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700475 }
476 }
477 return this;
478 }
479
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700480 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700481 * Specifies the extras associated with the {@link PhoneAccount}.
482 * <p>
483 * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer},
484 * and {@link Boolean}. Extras which are not of these types are ignored.
485 *
486 * @param extras
487 * @return
488 */
489 public Builder setExtras(Bundle extras) {
490 mExtras = extras;
491 return this;
492 }
493
494 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700495 * Sets the enabled state of the phone account.
496 *
497 * @param isEnabled The enabled state.
498 * @return The builder.
499 * @hide
500 */
501 public Builder setIsEnabled(boolean isEnabled) {
502 mIsEnabled = isEnabled;
503 return this;
504 }
505
506 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700507 * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is
508 * registered to Telecom, it will replace another {@link PhoneAccount} that is already
509 * registered in Telecom and take on the current user defaults and enabled status. There can
510 * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a
511 * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only
512 * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced.
513 * @param groupId The group Id of the {@link PhoneAccount} that will replace any other
514 * registered {@link PhoneAccount} in Telecom with the same Group Id.
515 * @return The builder
516 * @hide
517 */
518 public Builder setGroupId(String groupId) {
519 if (groupId != null) {
520 mGroupId = groupId;
521 } else {
522 mGroupId = "";
523 }
524 return this;
525 }
526
527 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800528 * Sets the audio routes supported by this {@link PhoneAccount}.
529 *
530 * @param routes bit mask of available routes.
531 * @return The builder.
532 * @hide
533 */
534 public Builder setSupportedAudioRoutes(int routes) {
535 mSupportedAudioRoutes = routes;
536 return this;
537 }
538
539 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700540 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
541 *
542 * @return The {@link PhoneAccount}.
543 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700544 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700545 // If no supported URI schemes were defined, assume "tel" is supported.
546 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700547 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700548 }
549
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700550 return new PhoneAccount(
551 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700552 mAddress,
553 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700554 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700555 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800556 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700557 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700558 mShortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700559 mSupportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700560 mExtras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800561 mSupportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700562 mIsEnabled,
563 mGroupId);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700564 }
565 }
566
567 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700568 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700569 Uri address,
570 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700571 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700572 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800573 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700574 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700575 CharSequence shortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700576 List<String> supportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700577 Bundle extras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800578 int supportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700579 boolean isEnabled,
580 String groupId) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700581 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700582 mAddress = address;
583 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700584 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700585 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800586 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700587 mLabel = label;
588 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700589 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700590 mExtras = extras;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800591 mSupportedAudioRoutes = supportedAudioRoutes;
Santos Cordon91371dc02015-05-08 13:52:09 -0700592 mIsEnabled = isEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700593 mGroupId = groupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700594 }
595
Andrew Lee3085a6c2014-09-04 10:59:13 -0700596 public static Builder builder(
597 PhoneAccountHandle accountHandle,
598 CharSequence label) {
599 return new Builder(accountHandle, label);
600 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700601
Ihab Awad807fe0a2014-07-09 12:30:52 -0700602 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700603 * Returns a builder initialized with the current {@link PhoneAccount} instance.
604 *
605 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700606 */
607 public Builder toBuilder() { return new Builder(this); }
608
609 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700610 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700611 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700612 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700613 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700614 public PhoneAccountHandle getAccountHandle() {
615 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700616 }
617
618 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700619 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700620 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700621 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700622 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700623 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700624 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700625 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700626 public Uri getAddress() {
627 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700628 }
629
630 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700631 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700632 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700633 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000634 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
635 * has been used to alter the callback number.
636 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700637 *
638 * @return The subscription number, suitable for display to the user.
639 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700640 public Uri getSubscriptionAddress() {
641 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700642 }
643
644 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700645 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700646 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700647 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700648 */
649 public int getCapabilities() {
650 return mCapabilities;
651 }
652
653 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700654 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
655 * bit mask.
656 *
657 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700658 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700659 */
660 public boolean hasCapabilities(int capability) {
661 return (mCapabilities & capability) == capability;
662 }
663
664 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800665 * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask.
666 *
667 * @param route The routes to check.
668 * @return {@code true} if the phone account has the routes.
669 * @hide
670 */
671 public boolean hasAudioRoutes(int routes) {
672 return (mSupportedAudioRoutes & routes) == routes;
673 }
674
675 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700676 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700677 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700678 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700679 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700680 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700681 return mLabel;
682 }
683
684 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700685 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700686 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700687 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700688 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700689 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700690 return mShortDescription;
691 }
692
693 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700694 * The URI schemes supported by this {@code PhoneAccount}.
695 *
696 * @return The URI schemes.
697 */
698 public List<String> getSupportedUriSchemes() {
699 return mSupportedUriSchemes;
700 }
701
702 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700703 * The extras associated with this {@code PhoneAccount}.
704 * <p>
705 * A {@link ConnectionService} may provide implementation specific information about the
706 * {@link PhoneAccount} via the extras.
707 *
708 * @return The extras.
709 */
710 public Bundle getExtras() {
711 return mExtras;
712 }
713
714 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800715 * The audio routes supported by this {@code PhoneAccount}.
716 *
717 * @hide
718 */
719 public int getSupportedAudioRoutes() {
720 return mSupportedAudioRoutes;
721 }
722
723 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700724 * The icon to represent this {@code PhoneAccount}.
725 *
726 * @return The icon.
727 */
728 public Icon getIcon() {
729 return mIcon;
730 }
731
732 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700733 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
734 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc02015-05-08 13:52:09 -0700735 *
Santos Cordon895d4b82015-06-25 16:41:48 -0700736 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc02015-05-08 13:52:09 -0700737 */
738 public boolean isEnabled() {
739 return mIsEnabled;
740 }
741
742 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700743 * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an
744 * empty {@link String} if the {@link PhoneAccount} is not in a group. If this
745 * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered
746 * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced,
747 * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}.
748 * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced.
749 *
750 * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group.
751 * @hide
752 */
753 public String getGroupId() {
754 return mGroupId;
755 }
756
757 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700758 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700759 * scheme.
760 *
761 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700762 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700763 * specified URI scheme.
764 */
765 public boolean supportsUriScheme(String uriScheme) {
766 if (mSupportedUriSchemes == null || uriScheme == null) {
767 return false;
768 }
769
770 for (String scheme : mSupportedUriSchemes) {
771 if (scheme != null && scheme.equals(uriScheme)) {
772 return true;
773 }
774 }
775 return false;
776 }
777
778 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800779 * A highlight color to use in displaying information about this {@code PhoneAccount}.
780 *
781 * @return A hexadecimal color value.
782 */
783 public int getHighlightColor() {
784 return mHighlightColor;
785 }
786
Santos Cordon91371dc02015-05-08 13:52:09 -0700787 /**
788 * Sets the enabled state of the phone account.
789 * @hide
790 */
791 public void setIsEnabled(boolean isEnabled) {
792 mIsEnabled = isEnabled;
793 }
794
Tyler Gunnf5035432017-01-09 09:43:12 -0800795 /**
796 * @return {@code true} if the {@link PhoneAccount} is self-managed, {@code false} otherwise.
797 * @hide
798 */
799 public boolean isSelfManaged() {
800 return (mCapabilities & CAPABILITY_SELF_MANAGED) == CAPABILITY_SELF_MANAGED;
801 }
802
Ihab Awad807fe0a2014-07-09 12:30:52 -0700803 //
804 // Parcelable implementation
805 //
806
807 @Override
808 public int describeContents() {
809 return 0;
810 }
811
812 @Override
813 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800814 if (mAccountHandle == null) {
815 out.writeInt(0);
816 } else {
817 out.writeInt(1);
818 mAccountHandle.writeToParcel(out, flags);
819 }
820 if (mAddress == null) {
821 out.writeInt(0);
822 } else {
823 out.writeInt(1);
824 mAddress.writeToParcel(out, flags);
825 }
826 if (mSubscriptionAddress == null) {
827 out.writeInt(0);
828 } else {
829 out.writeInt(1);
830 mSubscriptionAddress.writeToParcel(out, flags);
831 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700832 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800833 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700834 out.writeCharSequence(mLabel);
835 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800836 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc02015-05-08 13:52:09 -0700837
Santos Cordoncad84a22015-05-13 11:17:25 -0700838 if (mIcon == null) {
839 out.writeInt(0);
840 } else {
841 out.writeInt(1);
842 mIcon.writeToParcel(out, flags);
843 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700844 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Tyler Gunnef829ec2015-10-08 09:46:23 -0700845 out.writeBundle(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700846 out.writeString(mGroupId);
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800847 out.writeInt(mSupportedAudioRoutes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700848 }
849
Evan Charlton8c8a0622014-07-20 12:31:00 -0700850 public static final Creator<PhoneAccount> CREATOR
851 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700852 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700853 public PhoneAccount createFromParcel(Parcel in) {
854 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700855 }
856
857 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700858 public PhoneAccount[] newArray(int size) {
859 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700860 }
861 };
862
Evan Charlton8c8a0622014-07-20 12:31:00 -0700863 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800864 if (in.readInt() > 0) {
865 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
866 } else {
867 mAccountHandle = null;
868 }
869 if (in.readInt() > 0) {
870 mAddress = Uri.CREATOR.createFromParcel(in);
871 } else {
872 mAddress = null;
873 }
874 if (in.readInt() > 0) {
875 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
876 } else {
877 mSubscriptionAddress = null;
878 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700879 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -0800880 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700881 mLabel = in.readCharSequence();
882 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800883 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -0700884 if (in.readInt() > 0) {
885 mIcon = Icon.CREATOR.createFromParcel(in);
886 } else {
887 mIcon = null;
888 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700889 mIsEnabled = in.readByte() == 1;
Tyler Gunnef829ec2015-10-08 09:46:23 -0700890 mExtras = in.readBundle();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700891 mGroupId = in.readString();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800892 mSupportedAudioRoutes = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700893 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700894
895 @Override
896 public String toString() {
Santos Cordon91371dc02015-05-08 13:52:09 -0700897 StringBuilder sb = new StringBuilder().append("[[")
898 .append(mIsEnabled ? 'X' : ' ')
899 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700900 .append(mAccountHandle)
901 .append(" Capabilities: ")
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800902 .append(capabilitiesToString())
903 .append(" Audio Routes: ")
904 .append(audioRoutesToString())
Tyler Gunn76c01a52014-09-30 14:47:51 -0700905 .append(" Schemes: ");
906 for (String scheme : mSupportedUriSchemes) {
907 sb.append(scheme)
908 .append(" ");
909 }
Tyler Gunnef829ec2015-10-08 09:46:23 -0700910 sb.append(" Extras: ");
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700911 sb.append(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700912 sb.append(" GroupId: ");
913 sb.append(Log.pii(mGroupId));
Tyler Gunn76c01a52014-09-30 14:47:51 -0700914 sb.append("]");
915 return sb.toString();
916 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800917
918 /**
919 * Generates a string representation of a capabilities bitmask.
920 *
921 * @param capabilities The capabilities bitmask.
922 * @return String representation of the capabilities bitmask.
923 */
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800924 private String capabilitiesToString() {
Tyler Gunn3e122f72016-01-11 19:25:00 -0800925 StringBuilder sb = new StringBuilder();
Tyler Gunnf5035432017-01-09 09:43:12 -0800926 if (hasCapabilities(CAPABILITY_SELF_MANAGED)) {
927 sb.append("SelfManaged ");
928 }
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800929 if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) {
930 sb.append("SuppVideo ");
931 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800932 if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) {
933 sb.append("Video ");
934 }
935 if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
936 sb.append("Presence ");
937 }
938 if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) {
939 sb.append("CallProvider ");
940 }
941 if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) {
942 sb.append("CallSubject ");
943 }
944 if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) {
945 sb.append("ConnectionMgr ");
946 }
947 if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) {
948 sb.append("EmergOnly ");
949 }
950 if (hasCapabilities(CAPABILITY_MULTI_USER)) {
951 sb.append("MultiUser ");
952 }
953 if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) {
954 sb.append("PlaceEmerg ");
955 }
Tyler Gunncee9ea62016-03-24 11:45:43 -0700956 if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
957 sb.append("EmergVideo ");
958 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800959 if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) {
960 sb.append("SimSub ");
961 }
962 return sb.toString();
963 }
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800964
965 private String audioRoutesToString() {
966 StringBuilder sb = new StringBuilder();
967
968 if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) {
969 sb.append("B");
970 }
971 if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) {
972 sb.append("E");
973 }
974 if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) {
975 sb.append("S");
976 }
977 if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) {
978 sb.append("W");
979 }
980
981 return sb.toString();
982 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700983}