blob: 080ead1a2c0f2f8bf7e9a0326257ad433dd756b2 [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
46 * maximum permitted length of a call subject specified via the
47 * {@link TelecomManager#EXTRA_CALL_SUBJECT} extra on an
48 * {@link android.content.Intent#ACTION_CALL} intent. Ultimately a {@link ConnectionService} is
49 * responsible for enforcing the maximum call subject length when sending the message, however
50 * this extra is provided so that the user interface can proactively limit the length of the
51 * call subject as the user types it.
52 */
53 public static final String EXTRA_CALL_SUBJECT_MAX_LENGTH =
54 "android.telecom.extra.CALL_SUBJECT_MAX_LENGTH";
55
56 /**
57 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
58 * character encoding to be used when determining the length of messages.
59 * The user interface can use this when determining the number of characters the user may type
60 * in a call subject. If empty-string, the call subject message size limit will be enforced on
61 * a 1:1 basis. That is, each character will count towards the messages size limit as a single
62 * character. If a character encoding is specified, the message size limit will be based on the
63 * number of bytes in the message per the specified encoding. See
64 * {@link #EXTRA_CALL_SUBJECT_MAX_LENGTH} for more information on the call subject maximum
65 * length.
66 */
67 public static final String EXTRA_CALL_SUBJECT_CHARACTER_ENCODING =
68 "android.telecom.extra.CALL_SUBJECT_CHARACTER_ENCODING";
69
70 /**
Tyler Gunn8bf76572017-04-06 15:30:08 -070071 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
72 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
73 * connection (see {@link android.telecom.Call#EVENT_REQUEST_HANDOVER}) to this
74 * {@link PhoneAccount} from a {@link PhoneAccount} specifying
75 * {@link #EXTRA_SUPPORTS_HANDOVER_FROM}.
76 * <p>
77 * A handover request is initiated by the user from the default dialer app to indicate a desire
78 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
79 * @hide
80 */
81 public static final String EXTRA_SUPPORTS_HANDOVER_TO =
82 "android.telecom.extra.SUPPORTS_HANDOVER_TO";
83
84 /**
85 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
86 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
87 * connection from this {@link PhoneAccount} to another {@link PhoneAccount}.
88 * (see {@link android.telecom.Call#EVENT_REQUEST_HANDOVER}) which specifies
89 * {@link #EXTRA_SUPPORTS_HANDOVER_TO}.
90 * <p>
91 * A handover request is initiated by the user from the default dialer app to indicate a desire
92 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
93 * @hide
94 */
95 public static final String EXTRA_SUPPORTS_HANDOVER_FROM =
96 "android.telecom.extra.SUPPORTS_HANDOVER_FROM";
97
98 /**
Ihab Awadf8b69882014-07-25 15:14:01 -070099 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
100 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
101 * will be allowed to manage phone calls including using its own proprietary phone-call
102 * implementation (like VoIP calling) to make calls instead of the telephony stack.
103 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700104 * When a user opts to place a call using the SIM-based telephony stack, the
105 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
106 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700107 * <p>
108 * See {@link #getCapabilities}
109 */
Ihab Awadf8b69882014-07-25 15:14:01 -0700110 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700111
112 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700113 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -0700114 * traditional SIM-based telephony calls. This account will be treated as a distinct method
115 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -0700116 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -0700117 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700118 * <p>
119 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700120 * <p>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700121 */
122 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
123
Ihab Awad7522bbd62014-07-18 15:53:17 -0700124 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700125 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -0700126 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -0700127 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700128 * Only the Android framework can register a {@code PhoneAccount} having this capability.
129 * <p>
130 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -0700131 */
132 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
133
Ihab Awadf8b69882014-07-25 15:14:01 -0700134 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800135 * Flag indicating that this {@code PhoneAccount} is currently able to place video calls.
136 * <p>
137 * See also {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING} which indicates whether the
138 * {@code PhoneAccount} supports placing video calls.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700139 * <p>
140 * See {@link #getCapabilities}
Ihab Awadf8b69882014-07-25 15:14:01 -0700141 */
142 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
143
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700144 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700145 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
146 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
147 * <p>
148 * See {@link #getCapabilities}
149 */
150 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
151
152 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800153 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
154 * should only be used by system apps (and will be ignored for all other apps trying to use it).
155 * <p>
156 * See {@link #getCapabilities}
157 * @hide
158 */
Brian Attwellad147f42014-12-19 11:37:16 -0800159 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800160 public static final int CAPABILITY_MULTI_USER = 0x20;
161
162 /**
Tyler Gunn65a3d342015-07-27 16:06:16 -0700163 * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a
164 * caller is able to specify a short subject line for an outgoing call. A capable receiving
165 * device displays the call subject on the incoming call screen.
166 * <p>
167 * See {@link #getCapabilities}
168 */
169 public static final int CAPABILITY_CALL_SUBJECT = 0x40;
170
171 /**
Bryce Leeb96d89c2015-10-14 16:48:40 -0700172 * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls.
173 * <p>
174 * See {@link #getCapabilities}
175 * @hide
176 */
177 public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80;
178
179 /**
Tyler Gunn9a365752015-12-09 15:00:18 -0800180 * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a
181 * number relies on presence. Should only be set if the {@code PhoneAccount} also has
182 * {@link #CAPABILITY_VIDEO_CALLING}.
183 * <p>
184 * When set, the {@link ConnectionService} is responsible for toggling the
185 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the
186 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether
187 * a contact's phone number supports video calling.
188 * <p>
189 * See {@link #getCapabilities}
190 */
191 public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100;
192
193 /**
Tyler Gunncee9ea62016-03-24 11:45:43 -0700194 * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed.
195 * <p>
196 * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will
197 * convert all outgoing video calls to emergency numbers to audio-only.
198 * @hide
199 */
200 public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200;
201
202 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800203 * Flag indicating that this {@link PhoneAccount} supports video calling.
204 * This is not an indication that the {@link PhoneAccount} is currently able to make a video
205 * call, but rather that it has the ability to make video calls (but not necessarily at this
206 * time).
207 * <p>
208 * Whether a {@link PhoneAccount} can make a video call is ultimately controlled by
209 * {@link #CAPABILITY_VIDEO_CALLING}, which indicates whether the {@link PhoneAccount} is
210 * currently capable of making a video call. Consider a case where, for example, a
211 * {@link PhoneAccount} supports making video calls (e.g.
212 * {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING}), but a current lack of network connectivity
213 * prevents video calls from being made (e.g. {@link #CAPABILITY_VIDEO_CALLING}).
214 * <p>
215 * See {@link #getCapabilities}
216 */
217 public static final int CAPABILITY_SUPPORTS_VIDEO_CALLING = 0x400;
218
219 /**
Tyler Gunnf5035432017-01-09 09:43:12 -0800220 * Flag indicating that this {@link PhoneAccount} is responsible for managing its own
221 * {@link Connection}s. This type of {@link PhoneAccount} is ideal for use with standalone
222 * calling apps which do not wish to use the default phone app for {@link Connection} UX,
223 * but which want to leverage the call and audio routing capabilities of the Telecom framework.
224 * <p>
225 * When set, {@link Connection}s created by the self-managed {@link ConnectionService} will not
226 * be surfaced to implementations of the {@link InCallService} API. Thus it is the
227 * responsibility of a self-managed {@link ConnectionService} to provide a user interface for
228 * its {@link Connection}s.
229 * <p>
230 * Self-managed {@link Connection}s will, however, be displayed on connected Bluetooth devices.
231 */
232 public static final int CAPABILITY_SELF_MANAGED = 0x800;
233
234 /**
Hall Liu95d55872017-01-25 17:12:49 -0800235 * Flag indicating that this {@link PhoneAccount} is capable of making a call with an
236 * RTT (Real-time text) session.
237 * When set, Telecom will attempt to open an RTT session on outgoing calls that specify
238 * that they should be placed with an RTT session , and the in-call app will be displayed
239 * with text entry fields for RTT. Likewise, the in-call app can request that an RTT
240 * session be opened during a call if this bit is set.
241 */
242 public static final int CAPABILITY_RTT = 0x1000;
243
244 /* NEXT CAPABILITY: 0x2000 */
245
246 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700247 * URI scheme for telephone number URIs.
248 */
249 public static final String SCHEME_TEL = "tel";
250
251 /**
252 * URI scheme for voicemail URIs.
253 */
254 public static final String SCHEME_VOICEMAIL = "voicemail";
255
256 /**
257 * URI scheme for SIP URIs.
258 */
259 public static final String SCHEME_SIP = "sip";
260
Nancy Chen3ace54b2014-10-22 17:45:26 -0700261 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800262 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700263 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700264 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800265 public static final int NO_ICON_TINT = 0;
266
267 /**
268 * Indicating no hightlight color is set.
269 */
270 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700271
Ihab Awad476cc832014-11-03 09:47:51 -0800272 /**
273 * Indicating no resource ID is set.
274 */
275 public static final int NO_RESOURCE_ID = -1;
276
Evan Charlton8c8a0622014-07-20 12:31:00 -0700277 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700278 private final Uri mAddress;
279 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700280 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800281 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700282 private final CharSequence mLabel;
283 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700284 private final List<String> mSupportedUriSchemes;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800285 private final int mSupportedAudioRoutes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700286 private final Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700287 private final Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700288 private boolean mIsEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700289 private String mGroupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700290
Santos Cordon32c65a52014-10-27 14:57:49 -0700291 /**
292 * Helper class for creating a {@link PhoneAccount}.
293 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700294 public static class Builder {
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800295
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700296 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700297 private Uri mAddress;
298 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700299 private int mCapabilities;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800300 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800301 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700302 private CharSequence mLabel;
303 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700304 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700305 private Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700306 private Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700307 private boolean mIsEnabled = false;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700308 private String mGroupId = "";
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700309
Santos Cordon32c65a52014-10-27 14:57:49 -0700310 /**
311 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
312 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700313 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
314 this.mAccountHandle = accountHandle;
315 this.mLabel = label;
316 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700317
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700318 /**
319 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
320 * {@link PhoneAccount}.
321 *
322 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
323 */
324 public Builder(PhoneAccount phoneAccount) {
325 mAccountHandle = phoneAccount.getAccountHandle();
326 mAddress = phoneAccount.getAddress();
327 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
328 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800329 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700330 mLabel = phoneAccount.getLabel();
331 mShortDescription = phoneAccount.getShortDescription();
332 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700333 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc02015-05-08 13:52:09 -0700334 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunnd426b202015-10-13 13:33:53 -0700335 mExtras = phoneAccount.getExtras();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700336 mGroupId = phoneAccount.getGroupId();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800337 mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700338 }
339
Santos Cordon32c65a52014-10-27 14:57:49 -0700340 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700341 * Sets the label. See {@link PhoneAccount#getLabel()}.
342 *
343 * @param label The label of the phone account.
344 * @return The builder.
345 * @hide
346 */
347 public Builder setLabel(CharSequence label) {
348 this.mLabel = label;
349 return this;
350 }
351
352 /**
Santos Cordon32c65a52014-10-27 14:57:49 -0700353 * Sets the address. See {@link PhoneAccount#getAddress}.
354 *
355 * @param value The address of the phone account.
356 * @return The builder.
357 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700358 public Builder setAddress(Uri value) {
359 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700360 return this;
361 }
362
Santos Cordon32c65a52014-10-27 14:57:49 -0700363 /**
364 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
365 *
366 * @param value The subscription address.
367 * @return The builder.
368 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700369 public Builder setSubscriptionAddress(Uri value) {
370 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700371 return this;
372 }
373
Santos Cordon32c65a52014-10-27 14:57:49 -0700374 /**
375 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
376 *
377 * @param value The capabilities to set.
378 * @return The builder.
379 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700380 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700381 this.mCapabilities = value;
382 return this;
383 }
384
Santos Cordon32c65a52014-10-27 14:57:49 -0700385 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700386 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700387 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700388 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700389 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700390 public Builder setIcon(Icon icon) {
391 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700392 return this;
393 }
394
395 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800396 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700397 *
Ihab Awad476cc832014-11-03 09:47:51 -0800398 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700399 * @return The builder.
400 */
Ihab Awad476cc832014-11-03 09:47:51 -0800401 public Builder setHighlightColor(int value) {
402 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700403 return this;
404 }
405
Santos Cordon32c65a52014-10-27 14:57:49 -0700406 /**
407 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
408 *
409 * @param value The short description.
410 * @return The builder.
411 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700412 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700413 this.mShortDescription = value;
414 return this;
415 }
416
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700417 /**
418 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
419 *
420 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700421 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700422 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700423 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700424 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
425 this.mSupportedUriSchemes.add(uriScheme);
426 }
427 return this;
428 }
429
430 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700431 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700432 *
433 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700434 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700435 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700436 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
437 mSupportedUriSchemes.clear();
438
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700439 if (uriSchemes != null && !uriSchemes.isEmpty()) {
440 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700441 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700442 }
443 }
444 return this;
445 }
446
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700447 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700448 * Specifies the extras associated with the {@link PhoneAccount}.
449 * <p>
450 * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer},
451 * and {@link Boolean}. Extras which are not of these types are ignored.
452 *
453 * @param extras
454 * @return
455 */
456 public Builder setExtras(Bundle extras) {
457 mExtras = extras;
458 return this;
459 }
460
461 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700462 * Sets the enabled state of the phone account.
463 *
464 * @param isEnabled The enabled state.
465 * @return The builder.
466 * @hide
467 */
468 public Builder setIsEnabled(boolean isEnabled) {
469 mIsEnabled = isEnabled;
470 return this;
471 }
472
473 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700474 * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is
475 * registered to Telecom, it will replace another {@link PhoneAccount} that is already
476 * registered in Telecom and take on the current user defaults and enabled status. There can
477 * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a
478 * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only
479 * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced.
480 * @param groupId The group Id of the {@link PhoneAccount} that will replace any other
481 * registered {@link PhoneAccount} in Telecom with the same Group Id.
482 * @return The builder
483 * @hide
484 */
485 public Builder setGroupId(String groupId) {
486 if (groupId != null) {
487 mGroupId = groupId;
488 } else {
489 mGroupId = "";
490 }
491 return this;
492 }
493
494 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800495 * Sets the audio routes supported by this {@link PhoneAccount}.
496 *
497 * @param routes bit mask of available routes.
498 * @return The builder.
499 * @hide
500 */
501 public Builder setSupportedAudioRoutes(int routes) {
502 mSupportedAudioRoutes = routes;
503 return this;
504 }
505
506 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700507 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
508 *
509 * @return The {@link PhoneAccount}.
510 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700511 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700512 // If no supported URI schemes were defined, assume "tel" is supported.
513 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700514 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700515 }
516
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700517 return new PhoneAccount(
518 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700519 mAddress,
520 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700521 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700522 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800523 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700524 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700525 mShortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700526 mSupportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700527 mExtras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800528 mSupportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700529 mIsEnabled,
530 mGroupId);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700531 }
532 }
533
534 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700535 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700536 Uri address,
537 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700538 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700539 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800540 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700541 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700542 CharSequence shortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700543 List<String> supportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700544 Bundle extras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800545 int supportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700546 boolean isEnabled,
547 String groupId) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700548 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700549 mAddress = address;
550 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700551 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700552 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800553 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700554 mLabel = label;
555 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700556 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700557 mExtras = extras;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800558 mSupportedAudioRoutes = supportedAudioRoutes;
Santos Cordon91371dc02015-05-08 13:52:09 -0700559 mIsEnabled = isEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700560 mGroupId = groupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700561 }
562
Andrew Lee3085a6c2014-09-04 10:59:13 -0700563 public static Builder builder(
564 PhoneAccountHandle accountHandle,
565 CharSequence label) {
566 return new Builder(accountHandle, label);
567 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700568
Ihab Awad807fe0a2014-07-09 12:30:52 -0700569 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700570 * Returns a builder initialized with the current {@link PhoneAccount} instance.
571 *
572 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700573 */
574 public Builder toBuilder() { return new Builder(this); }
575
576 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700577 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700578 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700579 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700580 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700581 public PhoneAccountHandle getAccountHandle() {
582 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700583 }
584
585 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700586 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700587 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700588 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700589 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700590 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700591 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700592 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700593 public Uri getAddress() {
594 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700595 }
596
597 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700598 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700599 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700600 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000601 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
602 * has been used to alter the callback number.
603 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700604 *
605 * @return The subscription number, suitable for display to the user.
606 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700607 public Uri getSubscriptionAddress() {
608 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700609 }
610
611 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700612 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700613 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700614 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700615 */
616 public int getCapabilities() {
617 return mCapabilities;
618 }
619
620 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700621 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
622 * bit mask.
623 *
624 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700625 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700626 */
627 public boolean hasCapabilities(int capability) {
628 return (mCapabilities & capability) == capability;
629 }
630
631 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800632 * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask.
633 *
634 * @param route The routes to check.
635 * @return {@code true} if the phone account has the routes.
636 * @hide
637 */
638 public boolean hasAudioRoutes(int routes) {
639 return (mSupportedAudioRoutes & routes) == routes;
640 }
641
642 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700643 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700644 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700645 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700646 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700647 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700648 return mLabel;
649 }
650
651 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700652 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700653 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700654 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700655 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700656 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700657 return mShortDescription;
658 }
659
660 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700661 * The URI schemes supported by this {@code PhoneAccount}.
662 *
663 * @return The URI schemes.
664 */
665 public List<String> getSupportedUriSchemes() {
666 return mSupportedUriSchemes;
667 }
668
669 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700670 * The extras associated with this {@code PhoneAccount}.
671 * <p>
672 * A {@link ConnectionService} may provide implementation specific information about the
673 * {@link PhoneAccount} via the extras.
674 *
675 * @return The extras.
676 */
677 public Bundle getExtras() {
678 return mExtras;
679 }
680
681 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800682 * The audio routes supported by this {@code PhoneAccount}.
683 *
684 * @hide
685 */
686 public int getSupportedAudioRoutes() {
687 return mSupportedAudioRoutes;
688 }
689
690 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700691 * The icon to represent this {@code PhoneAccount}.
692 *
693 * @return The icon.
694 */
695 public Icon getIcon() {
696 return mIcon;
697 }
698
699 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700700 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
701 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc02015-05-08 13:52:09 -0700702 *
Santos Cordon895d4b82015-06-25 16:41:48 -0700703 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc02015-05-08 13:52:09 -0700704 */
705 public boolean isEnabled() {
706 return mIsEnabled;
707 }
708
709 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700710 * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an
711 * empty {@link String} if the {@link PhoneAccount} is not in a group. If this
712 * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered
713 * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced,
714 * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}.
715 * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced.
716 *
717 * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group.
718 * @hide
719 */
720 public String getGroupId() {
721 return mGroupId;
722 }
723
724 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700725 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700726 * scheme.
727 *
728 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700729 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700730 * specified URI scheme.
731 */
732 public boolean supportsUriScheme(String uriScheme) {
733 if (mSupportedUriSchemes == null || uriScheme == null) {
734 return false;
735 }
736
737 for (String scheme : mSupportedUriSchemes) {
738 if (scheme != null && scheme.equals(uriScheme)) {
739 return true;
740 }
741 }
742 return false;
743 }
744
745 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800746 * A highlight color to use in displaying information about this {@code PhoneAccount}.
747 *
748 * @return A hexadecimal color value.
749 */
750 public int getHighlightColor() {
751 return mHighlightColor;
752 }
753
Santos Cordon91371dc02015-05-08 13:52:09 -0700754 /**
755 * Sets the enabled state of the phone account.
756 * @hide
757 */
758 public void setIsEnabled(boolean isEnabled) {
759 mIsEnabled = isEnabled;
760 }
761
Tyler Gunnf5035432017-01-09 09:43:12 -0800762 /**
763 * @return {@code true} if the {@link PhoneAccount} is self-managed, {@code false} otherwise.
764 * @hide
765 */
766 public boolean isSelfManaged() {
767 return (mCapabilities & CAPABILITY_SELF_MANAGED) == CAPABILITY_SELF_MANAGED;
768 }
769
Ihab Awad807fe0a2014-07-09 12:30:52 -0700770 //
771 // Parcelable implementation
772 //
773
774 @Override
775 public int describeContents() {
776 return 0;
777 }
778
779 @Override
780 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800781 if (mAccountHandle == null) {
782 out.writeInt(0);
783 } else {
784 out.writeInt(1);
785 mAccountHandle.writeToParcel(out, flags);
786 }
787 if (mAddress == null) {
788 out.writeInt(0);
789 } else {
790 out.writeInt(1);
791 mAddress.writeToParcel(out, flags);
792 }
793 if (mSubscriptionAddress == null) {
794 out.writeInt(0);
795 } else {
796 out.writeInt(1);
797 mSubscriptionAddress.writeToParcel(out, flags);
798 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700799 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800800 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700801 out.writeCharSequence(mLabel);
802 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800803 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc02015-05-08 13:52:09 -0700804
Santos Cordoncad84a22015-05-13 11:17:25 -0700805 if (mIcon == null) {
806 out.writeInt(0);
807 } else {
808 out.writeInt(1);
809 mIcon.writeToParcel(out, flags);
810 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700811 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Tyler Gunnef829ec2015-10-08 09:46:23 -0700812 out.writeBundle(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700813 out.writeString(mGroupId);
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800814 out.writeInt(mSupportedAudioRoutes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700815 }
816
Evan Charlton8c8a0622014-07-20 12:31:00 -0700817 public static final Creator<PhoneAccount> CREATOR
818 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700819 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700820 public PhoneAccount createFromParcel(Parcel in) {
821 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700822 }
823
824 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700825 public PhoneAccount[] newArray(int size) {
826 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700827 }
828 };
829
Evan Charlton8c8a0622014-07-20 12:31:00 -0700830 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800831 if (in.readInt() > 0) {
832 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
833 } else {
834 mAccountHandle = null;
835 }
836 if (in.readInt() > 0) {
837 mAddress = Uri.CREATOR.createFromParcel(in);
838 } else {
839 mAddress = null;
840 }
841 if (in.readInt() > 0) {
842 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
843 } else {
844 mSubscriptionAddress = null;
845 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700846 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -0800847 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700848 mLabel = in.readCharSequence();
849 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800850 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -0700851 if (in.readInt() > 0) {
852 mIcon = Icon.CREATOR.createFromParcel(in);
853 } else {
854 mIcon = null;
855 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700856 mIsEnabled = in.readByte() == 1;
Tyler Gunnef829ec2015-10-08 09:46:23 -0700857 mExtras = in.readBundle();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700858 mGroupId = in.readString();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800859 mSupportedAudioRoutes = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700860 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700861
862 @Override
863 public String toString() {
Santos Cordon91371dc02015-05-08 13:52:09 -0700864 StringBuilder sb = new StringBuilder().append("[[")
865 .append(mIsEnabled ? 'X' : ' ')
866 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700867 .append(mAccountHandle)
868 .append(" Capabilities: ")
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800869 .append(capabilitiesToString())
870 .append(" Audio Routes: ")
871 .append(audioRoutesToString())
Tyler Gunn76c01a52014-09-30 14:47:51 -0700872 .append(" Schemes: ");
873 for (String scheme : mSupportedUriSchemes) {
874 sb.append(scheme)
875 .append(" ");
876 }
Tyler Gunnef829ec2015-10-08 09:46:23 -0700877 sb.append(" Extras: ");
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700878 sb.append(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700879 sb.append(" GroupId: ");
880 sb.append(Log.pii(mGroupId));
Tyler Gunn76c01a52014-09-30 14:47:51 -0700881 sb.append("]");
882 return sb.toString();
883 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800884
885 /**
886 * Generates a string representation of a capabilities bitmask.
887 *
888 * @param capabilities The capabilities bitmask.
889 * @return String representation of the capabilities bitmask.
890 */
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800891 private String capabilitiesToString() {
Tyler Gunn3e122f72016-01-11 19:25:00 -0800892 StringBuilder sb = new StringBuilder();
Tyler Gunnf5035432017-01-09 09:43:12 -0800893 if (hasCapabilities(CAPABILITY_SELF_MANAGED)) {
894 sb.append("SelfManaged ");
895 }
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800896 if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) {
897 sb.append("SuppVideo ");
898 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800899 if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) {
900 sb.append("Video ");
901 }
902 if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
903 sb.append("Presence ");
904 }
905 if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) {
906 sb.append("CallProvider ");
907 }
908 if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) {
909 sb.append("CallSubject ");
910 }
911 if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) {
912 sb.append("ConnectionMgr ");
913 }
914 if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) {
915 sb.append("EmergOnly ");
916 }
917 if (hasCapabilities(CAPABILITY_MULTI_USER)) {
918 sb.append("MultiUser ");
919 }
920 if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) {
921 sb.append("PlaceEmerg ");
922 }
Tyler Gunncee9ea62016-03-24 11:45:43 -0700923 if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
924 sb.append("EmergVideo ");
925 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800926 if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) {
927 sb.append("SimSub ");
928 }
929 return sb.toString();
930 }
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800931
932 private String audioRoutesToString() {
933 StringBuilder sb = new StringBuilder();
934
935 if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) {
936 sb.append("B");
937 }
938 if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) {
939 sb.append("E");
940 }
941 if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) {
942 sb.append("S");
943 }
944 if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) {
945 sb.append("W");
946 }
947
948 return sb.toString();
949 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700950}