blob: d25e59f11495936febcbcd805156bd75e7c80cfe [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
Sanket Padawea8eddd42017-11-03 11:07:35 -070089 * connection (see {@code android.telecom.Call#handoverTo()}) to this {@link PhoneAccount} from
90 * a {@link PhoneAccount} specifying {@link #EXTRA_SUPPORTS_HANDOVER_FROM}.
Tyler Gunn8bf76572017-04-06 15:30:08 -070091 * <p>
92 * A handover request is initiated by the user from the default dialer app to indicate a desire
93 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
Tyler Gunn8bf76572017-04-06 15:30:08 -070094 */
95 public static final String EXTRA_SUPPORTS_HANDOVER_TO =
96 "android.telecom.extra.SUPPORTS_HANDOVER_TO";
97
98 /**
99 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Ta-wei Yen9d20d982017-06-02 11:07:07 -0700100 * indicates whether this {@link PhoneAccount} supports using a fallback if video calling is
101 * not available. This extra is for device level support, {@link
102 * android.telephony.CarrierConfigManager#KEY_ALLOW_VIDEO_CALLING_FALLBACK_BOOL} should also
103 * be checked to ensure it is not disabled by individual carrier.
104 *
105 * @hide
106 */
107 public static final String EXTRA_SUPPORTS_VIDEO_CALLING_FALLBACK =
108 "android.telecom.extra.SUPPORTS_VIDEO_CALLING_FALLBACK";
109
110 /**
111 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Tyler Gunn8bf76572017-04-06 15:30:08 -0700112 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
113 * connection from this {@link PhoneAccount} to another {@link PhoneAccount}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700114 * (see {@code android.telecom.Call#handoverTo()}) which specifies
Tyler Gunn8bf76572017-04-06 15:30:08 -0700115 * {@link #EXTRA_SUPPORTS_HANDOVER_TO}.
116 * <p>
117 * A handover request is initiated by the user from the default dialer app to indicate a desire
118 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700119 */
120 public static final String EXTRA_SUPPORTS_HANDOVER_FROM =
121 "android.telecom.extra.SUPPORTS_HANDOVER_FROM";
122
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700123
124 /**
125 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
126 * indicates whether a Self-Managed {@link PhoneAccount} should log its calls to the call log.
Brad Ebingerbb1a55f2017-06-26 13:26:14 -0700127 * Self-Managed {@link PhoneAccount}s are responsible for their own notifications, so the system
128 * will not create a notification when a missed call is logged.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700129 * <p>
130 * By default, Self-Managed {@link PhoneAccount}s do not log their calls to the call log.
131 * Setting this extra to {@code true} provides a means for them to log their calls.
Tyler Gunn2155c4c2018-04-05 09:43:41 -0700132 * <p>
133 * Note: Only calls where the {@link Call.Details#getHandle()} {@link Uri#getScheme()} is
134 * {@link #SCHEME_SIP} or {@link #SCHEME_TEL} will be logged at the current time.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700135 */
136 public static final String EXTRA_LOG_SELF_MANAGED_CALLS =
137 "android.telecom.extra.LOG_SELF_MANAGED_CALLS";
138
Tyler Gunn8bf76572017-04-06 15:30:08 -0700139 /**
Tyler Gunnacdb6862018-01-29 14:30:52 -0800140 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
141 * indicates whether calls for a {@link PhoneAccount} should generate a "call recording tone"
142 * when the user is recording audio on the device.
143 * <p>
144 * The call recording tone is played over the telephony audio stream so that the remote party
145 * has an audible indication that it is possible their call is being recorded using a call
146 * recording app on the device.
147 * <p>
148 * This extra only has an effect for calls placed via Telephony (e.g.
149 * {@link #CAPABILITY_SIM_SUBSCRIPTION}).
150 * <p>
151 * The call recording tone is a 1400 hz tone which repeats every 15 seconds while recording is
152 * in progress.
153 * @hide
154 */
155 public static final String EXTRA_PLAY_CALL_RECORDING_TONE =
156 "android.telecom.extra.PLAY_CALL_RECORDING_TONE";
157
158 /**
Sean Kelley4d3c1782018-05-22 14:35:27 -0700159 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()} which
160 * indicates whether calls for a {@link PhoneAccount} should skip call filtering.
161 * <p>
162 * If not specified, this will default to false; all calls will undergo call filtering unless
163 * specifically exempted (e.g. {@link Connection#PROPERTY_EMERGENCY_CALLBACK_MODE}.) However,
164 * this may be used to skip call filtering when it has already been performed on another device.
165 * @hide
166 */
167 public static final String EXTRA_SKIP_CALL_FILTERING =
168 "android.telecom.extra.SKIP_CALL_FILTERING";
169
170 /**
Ihab Awadf8b69882014-07-25 15:14:01 -0700171 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
172 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
173 * will be allowed to manage phone calls including using its own proprietary phone-call
174 * implementation (like VoIP calling) to make calls instead of the telephony stack.
175 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700176 * When a user opts to place a call using the SIM-based telephony stack, the
177 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
178 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700179 * <p>
180 * See {@link #getCapabilities}
181 */
Ihab Awadf8b69882014-07-25 15:14:01 -0700182 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700183
184 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700185 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -0700186 * traditional SIM-based telephony calls. This account will be treated as a distinct method
187 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -0700188 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -0700189 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700190 * <p>
191 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700192 * <p>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700193 */
194 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
195
Ihab Awad7522bbd62014-07-18 15:53:17 -0700196 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700197 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -0700198 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -0700199 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700200 * Only the Android framework can register a {@code PhoneAccount} having this capability.
201 * <p>
202 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -0700203 */
204 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
205
Ihab Awadf8b69882014-07-25 15:14:01 -0700206 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800207 * Flag indicating that this {@code PhoneAccount} is currently able to place video calls.
208 * <p>
209 * See also {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING} which indicates whether the
210 * {@code PhoneAccount} supports placing video calls.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700211 * <p>
212 * See {@link #getCapabilities}
Ihab Awadf8b69882014-07-25 15:14:01 -0700213 */
214 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
215
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700216 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700217 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
218 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
219 * <p>
220 * See {@link #getCapabilities}
221 */
222 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
223
224 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800225 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
226 * should only be used by system apps (and will be ignored for all other apps trying to use it).
227 * <p>
228 * See {@link #getCapabilities}
229 * @hide
230 */
Brian Attwellad147f42014-12-19 11:37:16 -0800231 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800232 public static final int CAPABILITY_MULTI_USER = 0x20;
233
234 /**
Tyler Gunn65a3d342015-07-27 16:06:16 -0700235 * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a
236 * caller is able to specify a short subject line for an outgoing call. A capable receiving
237 * device displays the call subject on the incoming call screen.
238 * <p>
239 * See {@link #getCapabilities}
240 */
241 public static final int CAPABILITY_CALL_SUBJECT = 0x40;
242
243 /**
Bryce Leeb96d89c2015-10-14 16:48:40 -0700244 * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls.
245 * <p>
246 * See {@link #getCapabilities}
247 * @hide
248 */
249 public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80;
250
251 /**
Tyler Gunn9a365752015-12-09 15:00:18 -0800252 * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a
253 * number relies on presence. Should only be set if the {@code PhoneAccount} also has
254 * {@link #CAPABILITY_VIDEO_CALLING}.
255 * <p>
256 * When set, the {@link ConnectionService} is responsible for toggling the
257 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the
258 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether
259 * a contact's phone number supports video calling.
260 * <p>
261 * See {@link #getCapabilities}
262 */
263 public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100;
264
265 /**
Tyler Gunncee9ea62016-03-24 11:45:43 -0700266 * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed.
267 * <p>
268 * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will
269 * convert all outgoing video calls to emergency numbers to audio-only.
270 * @hide
271 */
272 public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200;
273
274 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800275 * Flag indicating that this {@link PhoneAccount} supports video calling.
276 * This is not an indication that the {@link PhoneAccount} is currently able to make a video
277 * call, but rather that it has the ability to make video calls (but not necessarily at this
278 * time).
279 * <p>
280 * Whether a {@link PhoneAccount} can make a video call is ultimately controlled by
281 * {@link #CAPABILITY_VIDEO_CALLING}, which indicates whether the {@link PhoneAccount} is
282 * currently capable of making a video call. Consider a case where, for example, a
283 * {@link PhoneAccount} supports making video calls (e.g.
284 * {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING}), but a current lack of network connectivity
285 * prevents video calls from being made (e.g. {@link #CAPABILITY_VIDEO_CALLING}).
286 * <p>
287 * See {@link #getCapabilities}
288 */
289 public static final int CAPABILITY_SUPPORTS_VIDEO_CALLING = 0x400;
290
291 /**
Tyler Gunnf5035432017-01-09 09:43:12 -0800292 * Flag indicating that this {@link PhoneAccount} is responsible for managing its own
293 * {@link Connection}s. This type of {@link PhoneAccount} is ideal for use with standalone
294 * calling apps which do not wish to use the default phone app for {@link Connection} UX,
295 * but which want to leverage the call and audio routing capabilities of the Telecom framework.
296 * <p>
297 * When set, {@link Connection}s created by the self-managed {@link ConnectionService} will not
298 * be surfaced to implementations of the {@link InCallService} API. Thus it is the
299 * responsibility of a self-managed {@link ConnectionService} to provide a user interface for
300 * its {@link Connection}s.
301 * <p>
302 * Self-managed {@link Connection}s will, however, be displayed on connected Bluetooth devices.
303 */
304 public static final int CAPABILITY_SELF_MANAGED = 0x800;
305
306 /**
Hall Liu95d55872017-01-25 17:12:49 -0800307 * Flag indicating that this {@link PhoneAccount} is capable of making a call with an
308 * RTT (Real-time text) session.
309 * When set, Telecom will attempt to open an RTT session on outgoing calls that specify
310 * that they should be placed with an RTT session , and the in-call app will be displayed
311 * with text entry fields for RTT. Likewise, the in-call app can request that an RTT
312 * session be opened during a call if this bit is set.
313 */
314 public static final int CAPABILITY_RTT = 0x1000;
315
316 /* NEXT CAPABILITY: 0x2000 */
317
318 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700319 * URI scheme for telephone number URIs.
320 */
321 public static final String SCHEME_TEL = "tel";
322
323 /**
324 * URI scheme for voicemail URIs.
325 */
326 public static final String SCHEME_VOICEMAIL = "voicemail";
327
328 /**
329 * URI scheme for SIP URIs.
330 */
331 public static final String SCHEME_SIP = "sip";
332
Nancy Chen3ace54b2014-10-22 17:45:26 -0700333 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800334 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700335 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700336 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800337 public static final int NO_ICON_TINT = 0;
338
339 /**
340 * Indicating no hightlight color is set.
341 */
342 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700343
Ihab Awad476cc832014-11-03 09:47:51 -0800344 /**
345 * Indicating no resource ID is set.
346 */
347 public static final int NO_RESOURCE_ID = -1;
348
Evan Charlton8c8a0622014-07-20 12:31:00 -0700349 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700350 private final Uri mAddress;
351 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700352 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800353 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700354 private final CharSequence mLabel;
355 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700356 private final List<String> mSupportedUriSchemes;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800357 private final int mSupportedAudioRoutes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700358 private final Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700359 private final Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700360 private boolean mIsEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700361 private String mGroupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700362
Santos Cordon32c65a52014-10-27 14:57:49 -0700363 /**
364 * Helper class for creating a {@link PhoneAccount}.
365 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700366 public static class Builder {
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800367
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700368 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700369 private Uri mAddress;
370 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700371 private int mCapabilities;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800372 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800373 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700374 private CharSequence mLabel;
375 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700376 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700377 private Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700378 private Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700379 private boolean mIsEnabled = false;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700380 private String mGroupId = "";
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700381
Santos Cordon32c65a52014-10-27 14:57:49 -0700382 /**
383 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
384 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700385 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
386 this.mAccountHandle = accountHandle;
387 this.mLabel = label;
388 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700389
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700390 /**
391 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
392 * {@link PhoneAccount}.
393 *
394 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
395 */
396 public Builder(PhoneAccount phoneAccount) {
397 mAccountHandle = phoneAccount.getAccountHandle();
398 mAddress = phoneAccount.getAddress();
399 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
400 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800401 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700402 mLabel = phoneAccount.getLabel();
403 mShortDescription = phoneAccount.getShortDescription();
404 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700405 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc02015-05-08 13:52:09 -0700406 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunnd426b202015-10-13 13:33:53 -0700407 mExtras = phoneAccount.getExtras();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700408 mGroupId = phoneAccount.getGroupId();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800409 mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700410 }
411
Santos Cordon32c65a52014-10-27 14:57:49 -0700412 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700413 * Sets the label. See {@link PhoneAccount#getLabel()}.
414 *
415 * @param label The label of the phone account.
416 * @return The builder.
417 * @hide
418 */
419 public Builder setLabel(CharSequence label) {
420 this.mLabel = label;
421 return this;
422 }
423
424 /**
Santos Cordon32c65a52014-10-27 14:57:49 -0700425 * Sets the address. See {@link PhoneAccount#getAddress}.
426 *
427 * @param value The address of the phone account.
428 * @return The builder.
429 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700430 public Builder setAddress(Uri value) {
431 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700432 return this;
433 }
434
Santos Cordon32c65a52014-10-27 14:57:49 -0700435 /**
436 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
437 *
438 * @param value The subscription address.
439 * @return The builder.
440 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700441 public Builder setSubscriptionAddress(Uri value) {
442 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700443 return this;
444 }
445
Santos Cordon32c65a52014-10-27 14:57:49 -0700446 /**
447 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
448 *
449 * @param value The capabilities to set.
450 * @return The builder.
451 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700452 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700453 this.mCapabilities = value;
454 return this;
455 }
456
Santos Cordon32c65a52014-10-27 14:57:49 -0700457 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700458 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700459 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700460 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700461 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700462 public Builder setIcon(Icon icon) {
463 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700464 return this;
465 }
466
467 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800468 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700469 *
Ihab Awad476cc832014-11-03 09:47:51 -0800470 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700471 * @return The builder.
472 */
Ihab Awad476cc832014-11-03 09:47:51 -0800473 public Builder setHighlightColor(int value) {
474 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700475 return this;
476 }
477
Santos Cordon32c65a52014-10-27 14:57:49 -0700478 /**
479 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
480 *
481 * @param value The short description.
482 * @return The builder.
483 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700484 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700485 this.mShortDescription = value;
486 return this;
487 }
488
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700489 /**
490 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
491 *
492 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700493 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700494 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700495 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700496 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
497 this.mSupportedUriSchemes.add(uriScheme);
498 }
499 return this;
500 }
501
502 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700503 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700504 *
505 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700506 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700507 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700508 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
509 mSupportedUriSchemes.clear();
510
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700511 if (uriSchemes != null && !uriSchemes.isEmpty()) {
512 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700513 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700514 }
515 }
516 return this;
517 }
518
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700519 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700520 * Specifies the extras associated with the {@link PhoneAccount}.
521 * <p>
522 * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer},
523 * and {@link Boolean}. Extras which are not of these types are ignored.
524 *
525 * @param extras
526 * @return
527 */
528 public Builder setExtras(Bundle extras) {
529 mExtras = extras;
530 return this;
531 }
532
533 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700534 * Sets the enabled state of the phone account.
535 *
536 * @param isEnabled The enabled state.
537 * @return The builder.
538 * @hide
539 */
540 public Builder setIsEnabled(boolean isEnabled) {
541 mIsEnabled = isEnabled;
542 return this;
543 }
544
545 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700546 * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is
547 * registered to Telecom, it will replace another {@link PhoneAccount} that is already
548 * registered in Telecom and take on the current user defaults and enabled status. There can
549 * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a
550 * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only
551 * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced.
552 * @param groupId The group Id of the {@link PhoneAccount} that will replace any other
553 * registered {@link PhoneAccount} in Telecom with the same Group Id.
554 * @return The builder
555 * @hide
556 */
557 public Builder setGroupId(String groupId) {
558 if (groupId != null) {
559 mGroupId = groupId;
560 } else {
561 mGroupId = "";
562 }
563 return this;
564 }
565
566 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800567 * Sets the audio routes supported by this {@link PhoneAccount}.
568 *
569 * @param routes bit mask of available routes.
570 * @return The builder.
571 * @hide
572 */
573 public Builder setSupportedAudioRoutes(int routes) {
574 mSupportedAudioRoutes = routes;
575 return this;
576 }
577
578 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700579 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
580 *
581 * @return The {@link PhoneAccount}.
582 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700583 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700584 // If no supported URI schemes were defined, assume "tel" is supported.
585 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700586 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700587 }
588
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700589 return new PhoneAccount(
590 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700591 mAddress,
592 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700593 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700594 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800595 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700596 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700597 mShortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700598 mSupportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700599 mExtras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800600 mSupportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700601 mIsEnabled,
602 mGroupId);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700603 }
604 }
605
606 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700607 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700608 Uri address,
609 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700610 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700611 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800612 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700613 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700614 CharSequence shortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700615 List<String> supportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700616 Bundle extras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800617 int supportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700618 boolean isEnabled,
619 String groupId) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700620 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700621 mAddress = address;
622 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700623 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700624 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800625 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700626 mLabel = label;
627 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700628 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700629 mExtras = extras;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800630 mSupportedAudioRoutes = supportedAudioRoutes;
Santos Cordon91371dc02015-05-08 13:52:09 -0700631 mIsEnabled = isEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700632 mGroupId = groupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700633 }
634
Andrew Lee3085a6c2014-09-04 10:59:13 -0700635 public static Builder builder(
636 PhoneAccountHandle accountHandle,
637 CharSequence label) {
638 return new Builder(accountHandle, label);
639 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700640
Ihab Awad807fe0a2014-07-09 12:30:52 -0700641 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700642 * Returns a builder initialized with the current {@link PhoneAccount} instance.
643 *
644 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700645 */
646 public Builder toBuilder() { return new Builder(this); }
647
648 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700649 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700650 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700651 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700652 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700653 public PhoneAccountHandle getAccountHandle() {
654 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700655 }
656
657 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700658 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700659 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700660 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700661 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700662 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700663 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700664 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700665 public Uri getAddress() {
666 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700667 }
668
669 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700670 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700671 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700672 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000673 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
674 * has been used to alter the callback number.
675 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700676 *
677 * @return The subscription number, suitable for display to the user.
678 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700679 public Uri getSubscriptionAddress() {
680 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700681 }
682
683 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700684 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700685 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700686 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700687 */
688 public int getCapabilities() {
689 return mCapabilities;
690 }
691
692 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700693 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
694 * bit mask.
695 *
696 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700697 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700698 */
699 public boolean hasCapabilities(int capability) {
700 return (mCapabilities & capability) == capability;
701 }
702
703 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800704 * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask.
705 *
706 * @param route The routes to check.
707 * @return {@code true} if the phone account has the routes.
708 * @hide
709 */
710 public boolean hasAudioRoutes(int routes) {
711 return (mSupportedAudioRoutes & routes) == routes;
712 }
713
714 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700715 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700716 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700717 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700718 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700719 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700720 return mLabel;
721 }
722
723 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700724 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700725 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700726 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700727 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700728 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700729 return mShortDescription;
730 }
731
732 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700733 * The URI schemes supported by this {@code PhoneAccount}.
734 *
735 * @return The URI schemes.
736 */
737 public List<String> getSupportedUriSchemes() {
738 return mSupportedUriSchemes;
739 }
740
741 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700742 * The extras associated with this {@code PhoneAccount}.
743 * <p>
744 * A {@link ConnectionService} may provide implementation specific information about the
745 * {@link PhoneAccount} via the extras.
746 *
747 * @return The extras.
748 */
749 public Bundle getExtras() {
750 return mExtras;
751 }
752
753 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800754 * The audio routes supported by this {@code PhoneAccount}.
755 *
756 * @hide
757 */
758 public int getSupportedAudioRoutes() {
759 return mSupportedAudioRoutes;
760 }
761
762 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700763 * The icon to represent this {@code PhoneAccount}.
764 *
765 * @return The icon.
766 */
767 public Icon getIcon() {
768 return mIcon;
769 }
770
771 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700772 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
773 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc02015-05-08 13:52:09 -0700774 *
Santos Cordon895d4b82015-06-25 16:41:48 -0700775 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc02015-05-08 13:52:09 -0700776 */
777 public boolean isEnabled() {
778 return mIsEnabled;
779 }
780
781 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700782 * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an
783 * empty {@link String} if the {@link PhoneAccount} is not in a group. If this
784 * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered
785 * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced,
786 * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}.
787 * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced.
788 *
789 * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group.
790 * @hide
791 */
792 public String getGroupId() {
793 return mGroupId;
794 }
795
796 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700797 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700798 * scheme.
799 *
800 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700801 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700802 * specified URI scheme.
803 */
804 public boolean supportsUriScheme(String uriScheme) {
805 if (mSupportedUriSchemes == null || uriScheme == null) {
806 return false;
807 }
808
809 for (String scheme : mSupportedUriSchemes) {
810 if (scheme != null && scheme.equals(uriScheme)) {
811 return true;
812 }
813 }
814 return false;
815 }
816
817 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800818 * A highlight color to use in displaying information about this {@code PhoneAccount}.
819 *
820 * @return A hexadecimal color value.
821 */
822 public int getHighlightColor() {
823 return mHighlightColor;
824 }
825
Santos Cordon91371dc02015-05-08 13:52:09 -0700826 /**
827 * Sets the enabled state of the phone account.
828 * @hide
829 */
830 public void setIsEnabled(boolean isEnabled) {
831 mIsEnabled = isEnabled;
832 }
833
Tyler Gunnf5035432017-01-09 09:43:12 -0800834 /**
835 * @return {@code true} if the {@link PhoneAccount} is self-managed, {@code false} otherwise.
836 * @hide
837 */
838 public boolean isSelfManaged() {
839 return (mCapabilities & CAPABILITY_SELF_MANAGED) == CAPABILITY_SELF_MANAGED;
840 }
841
Ihab Awad807fe0a2014-07-09 12:30:52 -0700842 //
843 // Parcelable implementation
844 //
845
846 @Override
847 public int describeContents() {
848 return 0;
849 }
850
851 @Override
852 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800853 if (mAccountHandle == null) {
854 out.writeInt(0);
855 } else {
856 out.writeInt(1);
857 mAccountHandle.writeToParcel(out, flags);
858 }
859 if (mAddress == null) {
860 out.writeInt(0);
861 } else {
862 out.writeInt(1);
863 mAddress.writeToParcel(out, flags);
864 }
865 if (mSubscriptionAddress == null) {
866 out.writeInt(0);
867 } else {
868 out.writeInt(1);
869 mSubscriptionAddress.writeToParcel(out, flags);
870 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700871 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800872 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700873 out.writeCharSequence(mLabel);
874 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800875 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc02015-05-08 13:52:09 -0700876
Santos Cordoncad84a22015-05-13 11:17:25 -0700877 if (mIcon == null) {
878 out.writeInt(0);
879 } else {
880 out.writeInt(1);
881 mIcon.writeToParcel(out, flags);
882 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700883 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Tyler Gunnef829ec2015-10-08 09:46:23 -0700884 out.writeBundle(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700885 out.writeString(mGroupId);
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800886 out.writeInt(mSupportedAudioRoutes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700887 }
888
Evan Charlton8c8a0622014-07-20 12:31:00 -0700889 public static final Creator<PhoneAccount> CREATOR
890 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700891 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700892 public PhoneAccount createFromParcel(Parcel in) {
893 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700894 }
895
896 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700897 public PhoneAccount[] newArray(int size) {
898 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700899 }
900 };
901
Evan Charlton8c8a0622014-07-20 12:31:00 -0700902 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800903 if (in.readInt() > 0) {
904 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
905 } else {
906 mAccountHandle = null;
907 }
908 if (in.readInt() > 0) {
909 mAddress = Uri.CREATOR.createFromParcel(in);
910 } else {
911 mAddress = null;
912 }
913 if (in.readInt() > 0) {
914 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
915 } else {
916 mSubscriptionAddress = null;
917 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700918 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -0800919 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700920 mLabel = in.readCharSequence();
921 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800922 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -0700923 if (in.readInt() > 0) {
924 mIcon = Icon.CREATOR.createFromParcel(in);
925 } else {
926 mIcon = null;
927 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700928 mIsEnabled = in.readByte() == 1;
Tyler Gunnef829ec2015-10-08 09:46:23 -0700929 mExtras = in.readBundle();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700930 mGroupId = in.readString();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800931 mSupportedAudioRoutes = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700932 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700933
934 @Override
935 public String toString() {
Santos Cordon91371dc02015-05-08 13:52:09 -0700936 StringBuilder sb = new StringBuilder().append("[[")
937 .append(mIsEnabled ? 'X' : ' ')
938 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700939 .append(mAccountHandle)
940 .append(" Capabilities: ")
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800941 .append(capabilitiesToString())
942 .append(" Audio Routes: ")
943 .append(audioRoutesToString())
Tyler Gunn76c01a52014-09-30 14:47:51 -0700944 .append(" Schemes: ");
945 for (String scheme : mSupportedUriSchemes) {
946 sb.append(scheme)
947 .append(" ");
948 }
Tyler Gunnef829ec2015-10-08 09:46:23 -0700949 sb.append(" Extras: ");
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700950 sb.append(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700951 sb.append(" GroupId: ");
952 sb.append(Log.pii(mGroupId));
Tyler Gunn76c01a52014-09-30 14:47:51 -0700953 sb.append("]");
954 return sb.toString();
955 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800956
957 /**
958 * Generates a string representation of a capabilities bitmask.
959 *
960 * @param capabilities The capabilities bitmask.
961 * @return String representation of the capabilities bitmask.
962 */
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800963 private String capabilitiesToString() {
Tyler Gunn3e122f72016-01-11 19:25:00 -0800964 StringBuilder sb = new StringBuilder();
Tyler Gunnf5035432017-01-09 09:43:12 -0800965 if (hasCapabilities(CAPABILITY_SELF_MANAGED)) {
966 sb.append("SelfManaged ");
967 }
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800968 if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) {
969 sb.append("SuppVideo ");
970 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800971 if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) {
972 sb.append("Video ");
973 }
974 if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
975 sb.append("Presence ");
976 }
977 if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) {
978 sb.append("CallProvider ");
979 }
980 if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) {
981 sb.append("CallSubject ");
982 }
983 if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) {
984 sb.append("ConnectionMgr ");
985 }
986 if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) {
987 sb.append("EmergOnly ");
988 }
989 if (hasCapabilities(CAPABILITY_MULTI_USER)) {
990 sb.append("MultiUser ");
991 }
992 if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) {
993 sb.append("PlaceEmerg ");
994 }
Tyler Gunncee9ea62016-03-24 11:45:43 -0700995 if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
996 sb.append("EmergVideo ");
997 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800998 if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) {
999 sb.append("SimSub ");
1000 }
Hall Liu47ed6202017-11-20 16:25:39 -08001001 if (hasCapabilities(CAPABILITY_RTT)) {
1002 sb.append("Rtt");
1003 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001004 return sb.toString();
1005 }
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001006
1007 private String audioRoutesToString() {
1008 StringBuilder sb = new StringBuilder();
1009
1010 if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) {
1011 sb.append("B");
1012 }
1013 if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) {
1014 sb.append("E");
1015 }
1016 if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) {
1017 sb.append("S");
1018 }
1019 if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) {
1020 sb.append("W");
1021 }
1022
1023 return sb.toString();
1024 }
Ihab Awad807fe0a2014-07-09 12:30:52 -07001025}