blob: 31bb0647c9d71db2d2ab8c6dc3c839ac79cdcb8a [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.
130 * <p>
131 * By default, Self-Managed {@link PhoneAccount}s do not log their calls to the call log.
132 * Setting this extra to {@code true} provides a means for them to log their calls.
133 * @hide
134 */
135 public static final String EXTRA_LOG_SELF_MANAGED_CALLS =
136 "android.telecom.extra.LOG_SELF_MANAGED_CALLS";
137
Tyler Gunn8bf76572017-04-06 15:30:08 -0700138 /**
Ihab Awadf8b69882014-07-25 15:14:01 -0700139 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
140 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
141 * will be allowed to manage phone calls including using its own proprietary phone-call
142 * implementation (like VoIP calling) to make calls instead of the telephony stack.
143 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700144 * When a user opts to place a call using the SIM-based telephony stack, the
145 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
146 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700147 * <p>
148 * See {@link #getCapabilities}
149 */
Ihab Awadf8b69882014-07-25 15:14:01 -0700150 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700151
152 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700153 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -0700154 * traditional SIM-based telephony calls. This account will be treated as a distinct method
155 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -0700156 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -0700157 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700158 * <p>
159 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700160 * <p>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700161 */
162 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
163
Ihab Awad7522bbd62014-07-18 15:53:17 -0700164 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700165 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -0700166 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -0700167 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700168 * Only the Android framework can register a {@code PhoneAccount} having this capability.
169 * <p>
170 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -0700171 */
172 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
173
Ihab Awadf8b69882014-07-25 15:14:01 -0700174 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800175 * Flag indicating that this {@code PhoneAccount} is currently able to place video calls.
176 * <p>
177 * See also {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING} which indicates whether the
178 * {@code PhoneAccount} supports placing video calls.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700179 * <p>
180 * See {@link #getCapabilities}
Ihab Awadf8b69882014-07-25 15:14:01 -0700181 */
182 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
183
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700184 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700185 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
186 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
187 * <p>
188 * See {@link #getCapabilities}
189 */
190 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
191
192 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800193 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
194 * should only be used by system apps (and will be ignored for all other apps trying to use it).
195 * <p>
196 * See {@link #getCapabilities}
197 * @hide
198 */
Brian Attwellad147f42014-12-19 11:37:16 -0800199 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800200 public static final int CAPABILITY_MULTI_USER = 0x20;
201
202 /**
Tyler Gunn65a3d342015-07-27 16:06:16 -0700203 * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a
204 * caller is able to specify a short subject line for an outgoing call. A capable receiving
205 * device displays the call subject on the incoming call screen.
206 * <p>
207 * See {@link #getCapabilities}
208 */
209 public static final int CAPABILITY_CALL_SUBJECT = 0x40;
210
211 /**
Bryce Leeb96d89c2015-10-14 16:48:40 -0700212 * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls.
213 * <p>
214 * See {@link #getCapabilities}
215 * @hide
216 */
217 public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80;
218
219 /**
Tyler Gunn9a365752015-12-09 15:00:18 -0800220 * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a
221 * number relies on presence. Should only be set if the {@code PhoneAccount} also has
222 * {@link #CAPABILITY_VIDEO_CALLING}.
223 * <p>
224 * When set, the {@link ConnectionService} is responsible for toggling the
225 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the
226 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether
227 * a contact's phone number supports video calling.
228 * <p>
229 * See {@link #getCapabilities}
230 */
231 public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100;
232
233 /**
Tyler Gunncee9ea62016-03-24 11:45:43 -0700234 * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed.
235 * <p>
236 * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will
237 * convert all outgoing video calls to emergency numbers to audio-only.
238 * @hide
239 */
240 public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200;
241
242 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800243 * Flag indicating that this {@link PhoneAccount} supports video calling.
244 * This is not an indication that the {@link PhoneAccount} is currently able to make a video
245 * call, but rather that it has the ability to make video calls (but not necessarily at this
246 * time).
247 * <p>
248 * Whether a {@link PhoneAccount} can make a video call is ultimately controlled by
249 * {@link #CAPABILITY_VIDEO_CALLING}, which indicates whether the {@link PhoneAccount} is
250 * currently capable of making a video call. Consider a case where, for example, a
251 * {@link PhoneAccount} supports making video calls (e.g.
252 * {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING}), but a current lack of network connectivity
253 * prevents video calls from being made (e.g. {@link #CAPABILITY_VIDEO_CALLING}).
254 * <p>
255 * See {@link #getCapabilities}
256 */
257 public static final int CAPABILITY_SUPPORTS_VIDEO_CALLING = 0x400;
258
259 /**
Tyler Gunnf5035432017-01-09 09:43:12 -0800260 * Flag indicating that this {@link PhoneAccount} is responsible for managing its own
261 * {@link Connection}s. This type of {@link PhoneAccount} is ideal for use with standalone
262 * calling apps which do not wish to use the default phone app for {@link Connection} UX,
263 * but which want to leverage the call and audio routing capabilities of the Telecom framework.
264 * <p>
265 * When set, {@link Connection}s created by the self-managed {@link ConnectionService} will not
266 * be surfaced to implementations of the {@link InCallService} API. Thus it is the
267 * responsibility of a self-managed {@link ConnectionService} to provide a user interface for
268 * its {@link Connection}s.
269 * <p>
270 * Self-managed {@link Connection}s will, however, be displayed on connected Bluetooth devices.
271 */
272 public static final int CAPABILITY_SELF_MANAGED = 0x800;
273
274 /**
Hall Liu95d55872017-01-25 17:12:49 -0800275 * Flag indicating that this {@link PhoneAccount} is capable of making a call with an
276 * RTT (Real-time text) session.
277 * When set, Telecom will attempt to open an RTT session on outgoing calls that specify
278 * that they should be placed with an RTT session , and the in-call app will be displayed
279 * with text entry fields for RTT. Likewise, the in-call app can request that an RTT
280 * session be opened during a call if this bit is set.
281 */
282 public static final int CAPABILITY_RTT = 0x1000;
283
284 /* NEXT CAPABILITY: 0x2000 */
285
286 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700287 * URI scheme for telephone number URIs.
288 */
289 public static final String SCHEME_TEL = "tel";
290
291 /**
292 * URI scheme for voicemail URIs.
293 */
294 public static final String SCHEME_VOICEMAIL = "voicemail";
295
296 /**
297 * URI scheme for SIP URIs.
298 */
299 public static final String SCHEME_SIP = "sip";
300
Nancy Chen3ace54b2014-10-22 17:45:26 -0700301 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800302 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700303 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700304 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800305 public static final int NO_ICON_TINT = 0;
306
307 /**
308 * Indicating no hightlight color is set.
309 */
310 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700311
Ihab Awad476cc832014-11-03 09:47:51 -0800312 /**
313 * Indicating no resource ID is set.
314 */
315 public static final int NO_RESOURCE_ID = -1;
316
Evan Charlton8c8a0622014-07-20 12:31:00 -0700317 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700318 private final Uri mAddress;
319 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700320 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800321 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700322 private final CharSequence mLabel;
323 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700324 private final List<String> mSupportedUriSchemes;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800325 private final int mSupportedAudioRoutes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700326 private final Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700327 private final Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700328 private boolean mIsEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700329 private String mGroupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700330
Santos Cordon32c65a52014-10-27 14:57:49 -0700331 /**
332 * Helper class for creating a {@link PhoneAccount}.
333 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700334 public static class Builder {
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800335
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700336 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700337 private Uri mAddress;
338 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700339 private int mCapabilities;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800340 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800341 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700342 private CharSequence mLabel;
343 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700344 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700345 private Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700346 private Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700347 private boolean mIsEnabled = false;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700348 private String mGroupId = "";
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700349
Santos Cordon32c65a52014-10-27 14:57:49 -0700350 /**
351 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
352 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700353 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
354 this.mAccountHandle = accountHandle;
355 this.mLabel = label;
356 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700357
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700358 /**
359 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
360 * {@link PhoneAccount}.
361 *
362 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
363 */
364 public Builder(PhoneAccount phoneAccount) {
365 mAccountHandle = phoneAccount.getAccountHandle();
366 mAddress = phoneAccount.getAddress();
367 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
368 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800369 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700370 mLabel = phoneAccount.getLabel();
371 mShortDescription = phoneAccount.getShortDescription();
372 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700373 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc02015-05-08 13:52:09 -0700374 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunnd426b202015-10-13 13:33:53 -0700375 mExtras = phoneAccount.getExtras();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700376 mGroupId = phoneAccount.getGroupId();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800377 mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700378 }
379
Santos Cordon32c65a52014-10-27 14:57:49 -0700380 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700381 * Sets the label. See {@link PhoneAccount#getLabel()}.
382 *
383 * @param label The label of the phone account.
384 * @return The builder.
385 * @hide
386 */
387 public Builder setLabel(CharSequence label) {
388 this.mLabel = label;
389 return this;
390 }
391
392 /**
Santos Cordon32c65a52014-10-27 14:57:49 -0700393 * Sets the address. See {@link PhoneAccount#getAddress}.
394 *
395 * @param value The address of the phone account.
396 * @return The builder.
397 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700398 public Builder setAddress(Uri value) {
399 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700400 return this;
401 }
402
Santos Cordon32c65a52014-10-27 14:57:49 -0700403 /**
404 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
405 *
406 * @param value The subscription address.
407 * @return The builder.
408 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700409 public Builder setSubscriptionAddress(Uri value) {
410 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700411 return this;
412 }
413
Santos Cordon32c65a52014-10-27 14:57:49 -0700414 /**
415 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
416 *
417 * @param value The capabilities to set.
418 * @return The builder.
419 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700420 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700421 this.mCapabilities = value;
422 return this;
423 }
424
Santos Cordon32c65a52014-10-27 14:57:49 -0700425 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700426 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700427 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700428 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700429 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700430 public Builder setIcon(Icon icon) {
431 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700432 return this;
433 }
434
435 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800436 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700437 *
Ihab Awad476cc832014-11-03 09:47:51 -0800438 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700439 * @return The builder.
440 */
Ihab Awad476cc832014-11-03 09:47:51 -0800441 public Builder setHighlightColor(int value) {
442 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700443 return this;
444 }
445
Santos Cordon32c65a52014-10-27 14:57:49 -0700446 /**
447 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
448 *
449 * @param value The short description.
450 * @return The builder.
451 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700452 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700453 this.mShortDescription = value;
454 return this;
455 }
456
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700457 /**
458 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
459 *
460 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700461 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700462 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700463 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700464 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
465 this.mSupportedUriSchemes.add(uriScheme);
466 }
467 return this;
468 }
469
470 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700471 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700472 *
473 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700474 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700475 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700476 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
477 mSupportedUriSchemes.clear();
478
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700479 if (uriSchemes != null && !uriSchemes.isEmpty()) {
480 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700481 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700482 }
483 }
484 return this;
485 }
486
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700487 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700488 * Specifies the extras associated with the {@link PhoneAccount}.
489 * <p>
490 * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer},
491 * and {@link Boolean}. Extras which are not of these types are ignored.
492 *
493 * @param extras
494 * @return
495 */
496 public Builder setExtras(Bundle extras) {
497 mExtras = extras;
498 return this;
499 }
500
501 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700502 * Sets the enabled state of the phone account.
503 *
504 * @param isEnabled The enabled state.
505 * @return The builder.
506 * @hide
507 */
508 public Builder setIsEnabled(boolean isEnabled) {
509 mIsEnabled = isEnabled;
510 return this;
511 }
512
513 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700514 * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is
515 * registered to Telecom, it will replace another {@link PhoneAccount} that is already
516 * registered in Telecom and take on the current user defaults and enabled status. There can
517 * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a
518 * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only
519 * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced.
520 * @param groupId The group Id of the {@link PhoneAccount} that will replace any other
521 * registered {@link PhoneAccount} in Telecom with the same Group Id.
522 * @return The builder
523 * @hide
524 */
525 public Builder setGroupId(String groupId) {
526 if (groupId != null) {
527 mGroupId = groupId;
528 } else {
529 mGroupId = "";
530 }
531 return this;
532 }
533
534 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800535 * Sets the audio routes supported by this {@link PhoneAccount}.
536 *
537 * @param routes bit mask of available routes.
538 * @return The builder.
539 * @hide
540 */
541 public Builder setSupportedAudioRoutes(int routes) {
542 mSupportedAudioRoutes = routes;
543 return this;
544 }
545
546 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700547 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
548 *
549 * @return The {@link PhoneAccount}.
550 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700551 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700552 // If no supported URI schemes were defined, assume "tel" is supported.
553 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700554 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700555 }
556
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700557 return new PhoneAccount(
558 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700559 mAddress,
560 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700561 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700562 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800563 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700564 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700565 mShortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700566 mSupportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700567 mExtras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800568 mSupportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700569 mIsEnabled,
570 mGroupId);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700571 }
572 }
573
574 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700575 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700576 Uri address,
577 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700578 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700579 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800580 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700581 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700582 CharSequence shortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700583 List<String> supportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700584 Bundle extras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800585 int supportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700586 boolean isEnabled,
587 String groupId) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700588 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700589 mAddress = address;
590 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700591 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700592 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800593 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700594 mLabel = label;
595 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700596 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700597 mExtras = extras;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800598 mSupportedAudioRoutes = supportedAudioRoutes;
Santos Cordon91371dc02015-05-08 13:52:09 -0700599 mIsEnabled = isEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700600 mGroupId = groupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700601 }
602
Andrew Lee3085a6c2014-09-04 10:59:13 -0700603 public static Builder builder(
604 PhoneAccountHandle accountHandle,
605 CharSequence label) {
606 return new Builder(accountHandle, label);
607 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700608
Ihab Awad807fe0a2014-07-09 12:30:52 -0700609 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700610 * Returns a builder initialized with the current {@link PhoneAccount} instance.
611 *
612 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700613 */
614 public Builder toBuilder() { return new Builder(this); }
615
616 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700617 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700618 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700619 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700620 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700621 public PhoneAccountHandle getAccountHandle() {
622 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700623 }
624
625 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700626 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700627 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700628 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700629 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700630 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700631 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700632 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700633 public Uri getAddress() {
634 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700635 }
636
637 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700638 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700639 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700640 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000641 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
642 * has been used to alter the callback number.
643 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700644 *
645 * @return The subscription number, suitable for display to the user.
646 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700647 public Uri getSubscriptionAddress() {
648 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700649 }
650
651 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700652 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700653 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700654 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700655 */
656 public int getCapabilities() {
657 return mCapabilities;
658 }
659
660 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700661 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
662 * bit mask.
663 *
664 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700665 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700666 */
667 public boolean hasCapabilities(int capability) {
668 return (mCapabilities & capability) == capability;
669 }
670
671 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800672 * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask.
673 *
674 * @param route The routes to check.
675 * @return {@code true} if the phone account has the routes.
676 * @hide
677 */
678 public boolean hasAudioRoutes(int routes) {
679 return (mSupportedAudioRoutes & routes) == routes;
680 }
681
682 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700683 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700684 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700685 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700686 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700687 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700688 return mLabel;
689 }
690
691 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700692 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700693 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700694 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700695 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700696 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700697 return mShortDescription;
698 }
699
700 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700701 * The URI schemes supported by this {@code PhoneAccount}.
702 *
703 * @return The URI schemes.
704 */
705 public List<String> getSupportedUriSchemes() {
706 return mSupportedUriSchemes;
707 }
708
709 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700710 * The extras associated with this {@code PhoneAccount}.
711 * <p>
712 * A {@link ConnectionService} may provide implementation specific information about the
713 * {@link PhoneAccount} via the extras.
714 *
715 * @return The extras.
716 */
717 public Bundle getExtras() {
718 return mExtras;
719 }
720
721 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800722 * The audio routes supported by this {@code PhoneAccount}.
723 *
724 * @hide
725 */
726 public int getSupportedAudioRoutes() {
727 return mSupportedAudioRoutes;
728 }
729
730 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700731 * The icon to represent this {@code PhoneAccount}.
732 *
733 * @return The icon.
734 */
735 public Icon getIcon() {
736 return mIcon;
737 }
738
739 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700740 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
741 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc02015-05-08 13:52:09 -0700742 *
Santos Cordon895d4b82015-06-25 16:41:48 -0700743 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc02015-05-08 13:52:09 -0700744 */
745 public boolean isEnabled() {
746 return mIsEnabled;
747 }
748
749 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700750 * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an
751 * empty {@link String} if the {@link PhoneAccount} is not in a group. If this
752 * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered
753 * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced,
754 * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}.
755 * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced.
756 *
757 * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group.
758 * @hide
759 */
760 public String getGroupId() {
761 return mGroupId;
762 }
763
764 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700765 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700766 * scheme.
767 *
768 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700769 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700770 * specified URI scheme.
771 */
772 public boolean supportsUriScheme(String uriScheme) {
773 if (mSupportedUriSchemes == null || uriScheme == null) {
774 return false;
775 }
776
777 for (String scheme : mSupportedUriSchemes) {
778 if (scheme != null && scheme.equals(uriScheme)) {
779 return true;
780 }
781 }
782 return false;
783 }
784
785 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800786 * A highlight color to use in displaying information about this {@code PhoneAccount}.
787 *
788 * @return A hexadecimal color value.
789 */
790 public int getHighlightColor() {
791 return mHighlightColor;
792 }
793
Santos Cordon91371dc02015-05-08 13:52:09 -0700794 /**
795 * Sets the enabled state of the phone account.
796 * @hide
797 */
798 public void setIsEnabled(boolean isEnabled) {
799 mIsEnabled = isEnabled;
800 }
801
Tyler Gunnf5035432017-01-09 09:43:12 -0800802 /**
803 * @return {@code true} if the {@link PhoneAccount} is self-managed, {@code false} otherwise.
804 * @hide
805 */
806 public boolean isSelfManaged() {
807 return (mCapabilities & CAPABILITY_SELF_MANAGED) == CAPABILITY_SELF_MANAGED;
808 }
809
Ihab Awad807fe0a2014-07-09 12:30:52 -0700810 //
811 // Parcelable implementation
812 //
813
814 @Override
815 public int describeContents() {
816 return 0;
817 }
818
819 @Override
820 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800821 if (mAccountHandle == null) {
822 out.writeInt(0);
823 } else {
824 out.writeInt(1);
825 mAccountHandle.writeToParcel(out, flags);
826 }
827 if (mAddress == null) {
828 out.writeInt(0);
829 } else {
830 out.writeInt(1);
831 mAddress.writeToParcel(out, flags);
832 }
833 if (mSubscriptionAddress == null) {
834 out.writeInt(0);
835 } else {
836 out.writeInt(1);
837 mSubscriptionAddress.writeToParcel(out, flags);
838 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700839 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800840 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700841 out.writeCharSequence(mLabel);
842 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800843 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc02015-05-08 13:52:09 -0700844
Santos Cordoncad84a22015-05-13 11:17:25 -0700845 if (mIcon == null) {
846 out.writeInt(0);
847 } else {
848 out.writeInt(1);
849 mIcon.writeToParcel(out, flags);
850 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700851 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Tyler Gunnef829ec2015-10-08 09:46:23 -0700852 out.writeBundle(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700853 out.writeString(mGroupId);
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800854 out.writeInt(mSupportedAudioRoutes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700855 }
856
Evan Charlton8c8a0622014-07-20 12:31:00 -0700857 public static final Creator<PhoneAccount> CREATOR
858 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700859 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700860 public PhoneAccount createFromParcel(Parcel in) {
861 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700862 }
863
864 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700865 public PhoneAccount[] newArray(int size) {
866 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700867 }
868 };
869
Evan Charlton8c8a0622014-07-20 12:31:00 -0700870 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800871 if (in.readInt() > 0) {
872 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
873 } else {
874 mAccountHandle = null;
875 }
876 if (in.readInt() > 0) {
877 mAddress = Uri.CREATOR.createFromParcel(in);
878 } else {
879 mAddress = null;
880 }
881 if (in.readInt() > 0) {
882 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
883 } else {
884 mSubscriptionAddress = null;
885 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700886 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -0800887 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700888 mLabel = in.readCharSequence();
889 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800890 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -0700891 if (in.readInt() > 0) {
892 mIcon = Icon.CREATOR.createFromParcel(in);
893 } else {
894 mIcon = null;
895 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700896 mIsEnabled = in.readByte() == 1;
Tyler Gunnef829ec2015-10-08 09:46:23 -0700897 mExtras = in.readBundle();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700898 mGroupId = in.readString();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800899 mSupportedAudioRoutes = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700900 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700901
902 @Override
903 public String toString() {
Santos Cordon91371dc02015-05-08 13:52:09 -0700904 StringBuilder sb = new StringBuilder().append("[[")
905 .append(mIsEnabled ? 'X' : ' ')
906 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700907 .append(mAccountHandle)
908 .append(" Capabilities: ")
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800909 .append(capabilitiesToString())
910 .append(" Audio Routes: ")
911 .append(audioRoutesToString())
Tyler Gunn76c01a52014-09-30 14:47:51 -0700912 .append(" Schemes: ");
913 for (String scheme : mSupportedUriSchemes) {
914 sb.append(scheme)
915 .append(" ");
916 }
Tyler Gunnef829ec2015-10-08 09:46:23 -0700917 sb.append(" Extras: ");
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700918 sb.append(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700919 sb.append(" GroupId: ");
920 sb.append(Log.pii(mGroupId));
Tyler Gunn76c01a52014-09-30 14:47:51 -0700921 sb.append("]");
922 return sb.toString();
923 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800924
925 /**
926 * Generates a string representation of a capabilities bitmask.
927 *
928 * @param capabilities The capabilities bitmask.
929 * @return String representation of the capabilities bitmask.
930 */
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800931 private String capabilitiesToString() {
Tyler Gunn3e122f72016-01-11 19:25:00 -0800932 StringBuilder sb = new StringBuilder();
Tyler Gunnf5035432017-01-09 09:43:12 -0800933 if (hasCapabilities(CAPABILITY_SELF_MANAGED)) {
934 sb.append("SelfManaged ");
935 }
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800936 if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) {
937 sb.append("SuppVideo ");
938 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800939 if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) {
940 sb.append("Video ");
941 }
942 if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
943 sb.append("Presence ");
944 }
945 if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) {
946 sb.append("CallProvider ");
947 }
948 if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) {
949 sb.append("CallSubject ");
950 }
951 if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) {
952 sb.append("ConnectionMgr ");
953 }
954 if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) {
955 sb.append("EmergOnly ");
956 }
957 if (hasCapabilities(CAPABILITY_MULTI_USER)) {
958 sb.append("MultiUser ");
959 }
960 if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) {
961 sb.append("PlaceEmerg ");
962 }
Tyler Gunncee9ea62016-03-24 11:45:43 -0700963 if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
964 sb.append("EmergVideo ");
965 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800966 if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) {
967 sb.append("SimSub ");
968 }
969 return sb.toString();
970 }
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800971
972 private String audioRoutesToString() {
973 StringBuilder sb = new StringBuilder();
974
975 if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) {
976 sb.append("B");
977 }
978 if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) {
979 sb.append("E");
980 }
981 if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) {
982 sb.append("S");
983 }
984 if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) {
985 sb.append("W");
986 }
987
988 return sb.toString();
989 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700990}