blob: 95eb14ada3547e4a816e2f44772929b49db3a37d [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 Gunn9f6f0472017-04-17 18:25:22 -0700132 */
133 public static final String EXTRA_LOG_SELF_MANAGED_CALLS =
134 "android.telecom.extra.LOG_SELF_MANAGED_CALLS";
135
Tyler Gunn8bf76572017-04-06 15:30:08 -0700136 /**
Tyler Gunnacdb6862018-01-29 14:30:52 -0800137 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
138 * indicates whether calls for a {@link PhoneAccount} should generate a "call recording tone"
139 * when the user is recording audio on the device.
140 * <p>
141 * The call recording tone is played over the telephony audio stream so that the remote party
142 * has an audible indication that it is possible their call is being recorded using a call
143 * recording app on the device.
144 * <p>
145 * This extra only has an effect for calls placed via Telephony (e.g.
146 * {@link #CAPABILITY_SIM_SUBSCRIPTION}).
147 * <p>
148 * The call recording tone is a 1400 hz tone which repeats every 15 seconds while recording is
149 * in progress.
150 * @hide
151 */
152 public static final String EXTRA_PLAY_CALL_RECORDING_TONE =
153 "android.telecom.extra.PLAY_CALL_RECORDING_TONE";
154
155 /**
Ihab Awadf8b69882014-07-25 15:14:01 -0700156 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
157 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
158 * will be allowed to manage phone calls including using its own proprietary phone-call
159 * implementation (like VoIP calling) to make calls instead of the telephony stack.
160 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700161 * When a user opts to place a call using the SIM-based telephony stack, the
162 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
163 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700164 * <p>
165 * See {@link #getCapabilities}
166 */
Ihab Awadf8b69882014-07-25 15:14:01 -0700167 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700168
169 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700170 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -0700171 * traditional SIM-based telephony calls. This account will be treated as a distinct method
172 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -0700173 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -0700174 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700175 * <p>
176 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700177 * <p>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700178 */
179 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
180
Ihab Awad7522bbd62014-07-18 15:53:17 -0700181 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700182 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -0700183 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -0700184 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700185 * Only the Android framework can register a {@code PhoneAccount} having this capability.
186 * <p>
187 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -0700188 */
189 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
190
Ihab Awadf8b69882014-07-25 15:14:01 -0700191 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800192 * Flag indicating that this {@code PhoneAccount} is currently able to place video calls.
193 * <p>
194 * See also {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING} which indicates whether the
195 * {@code PhoneAccount} supports placing video calls.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700196 * <p>
197 * See {@link #getCapabilities}
Ihab Awadf8b69882014-07-25 15:14:01 -0700198 */
199 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
200
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700201 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700202 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
203 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
204 * <p>
205 * See {@link #getCapabilities}
206 */
207 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
208
209 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800210 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
211 * should only be used by system apps (and will be ignored for all other apps trying to use it).
212 * <p>
213 * See {@link #getCapabilities}
214 * @hide
215 */
Brian Attwellad147f42014-12-19 11:37:16 -0800216 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800217 public static final int CAPABILITY_MULTI_USER = 0x20;
218
219 /**
Tyler Gunn65a3d342015-07-27 16:06:16 -0700220 * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a
221 * caller is able to specify a short subject line for an outgoing call. A capable receiving
222 * device displays the call subject on the incoming call screen.
223 * <p>
224 * See {@link #getCapabilities}
225 */
226 public static final int CAPABILITY_CALL_SUBJECT = 0x40;
227
228 /**
Bryce Leeb96d89c2015-10-14 16:48:40 -0700229 * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls.
230 * <p>
231 * See {@link #getCapabilities}
232 * @hide
233 */
234 public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80;
235
236 /**
Tyler Gunn9a365752015-12-09 15:00:18 -0800237 * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a
238 * number relies on presence. Should only be set if the {@code PhoneAccount} also has
239 * {@link #CAPABILITY_VIDEO_CALLING}.
240 * <p>
241 * When set, the {@link ConnectionService} is responsible for toggling the
242 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the
243 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether
244 * a contact's phone number supports video calling.
245 * <p>
246 * See {@link #getCapabilities}
247 */
248 public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100;
249
250 /**
Tyler Gunncee9ea62016-03-24 11:45:43 -0700251 * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed.
252 * <p>
253 * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will
254 * convert all outgoing video calls to emergency numbers to audio-only.
255 * @hide
256 */
257 public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200;
258
259 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800260 * Flag indicating that this {@link PhoneAccount} supports video calling.
261 * This is not an indication that the {@link PhoneAccount} is currently able to make a video
262 * call, but rather that it has the ability to make video calls (but not necessarily at this
263 * time).
264 * <p>
265 * Whether a {@link PhoneAccount} can make a video call is ultimately controlled by
266 * {@link #CAPABILITY_VIDEO_CALLING}, which indicates whether the {@link PhoneAccount} is
267 * currently capable of making a video call. Consider a case where, for example, a
268 * {@link PhoneAccount} supports making video calls (e.g.
269 * {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING}), but a current lack of network connectivity
270 * prevents video calls from being made (e.g. {@link #CAPABILITY_VIDEO_CALLING}).
271 * <p>
272 * See {@link #getCapabilities}
273 */
274 public static final int CAPABILITY_SUPPORTS_VIDEO_CALLING = 0x400;
275
276 /**
Tyler Gunnf5035432017-01-09 09:43:12 -0800277 * Flag indicating that this {@link PhoneAccount} is responsible for managing its own
278 * {@link Connection}s. This type of {@link PhoneAccount} is ideal for use with standalone
279 * calling apps which do not wish to use the default phone app for {@link Connection} UX,
280 * but which want to leverage the call and audio routing capabilities of the Telecom framework.
281 * <p>
282 * When set, {@link Connection}s created by the self-managed {@link ConnectionService} will not
283 * be surfaced to implementations of the {@link InCallService} API. Thus it is the
284 * responsibility of a self-managed {@link ConnectionService} to provide a user interface for
285 * its {@link Connection}s.
286 * <p>
287 * Self-managed {@link Connection}s will, however, be displayed on connected Bluetooth devices.
288 */
289 public static final int CAPABILITY_SELF_MANAGED = 0x800;
290
291 /**
Hall Liu95d55872017-01-25 17:12:49 -0800292 * Flag indicating that this {@link PhoneAccount} is capable of making a call with an
293 * RTT (Real-time text) session.
294 * When set, Telecom will attempt to open an RTT session on outgoing calls that specify
295 * that they should be placed with an RTT session , and the in-call app will be displayed
296 * with text entry fields for RTT. Likewise, the in-call app can request that an RTT
297 * session be opened during a call if this bit is set.
298 */
299 public static final int CAPABILITY_RTT = 0x1000;
300
301 /* NEXT CAPABILITY: 0x2000 */
302
303 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700304 * URI scheme for telephone number URIs.
305 */
306 public static final String SCHEME_TEL = "tel";
307
308 /**
309 * URI scheme for voicemail URIs.
310 */
311 public static final String SCHEME_VOICEMAIL = "voicemail";
312
313 /**
314 * URI scheme for SIP URIs.
315 */
316 public static final String SCHEME_SIP = "sip";
317
Nancy Chen3ace54b2014-10-22 17:45:26 -0700318 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800319 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700320 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700321 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800322 public static final int NO_ICON_TINT = 0;
323
324 /**
325 * Indicating no hightlight color is set.
326 */
327 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700328
Ihab Awad476cc832014-11-03 09:47:51 -0800329 /**
330 * Indicating no resource ID is set.
331 */
332 public static final int NO_RESOURCE_ID = -1;
333
Evan Charlton8c8a0622014-07-20 12:31:00 -0700334 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700335 private final Uri mAddress;
336 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700337 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800338 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700339 private final CharSequence mLabel;
340 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700341 private final List<String> mSupportedUriSchemes;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800342 private final int mSupportedAudioRoutes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700343 private final Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700344 private final Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700345 private boolean mIsEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700346 private String mGroupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700347
Santos Cordon32c65a52014-10-27 14:57:49 -0700348 /**
349 * Helper class for creating a {@link PhoneAccount}.
350 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700351 public static class Builder {
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800352
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700353 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700354 private Uri mAddress;
355 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700356 private int mCapabilities;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800357 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800358 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700359 private CharSequence mLabel;
360 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700361 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700362 private Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700363 private Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700364 private boolean mIsEnabled = false;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700365 private String mGroupId = "";
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700366
Santos Cordon32c65a52014-10-27 14:57:49 -0700367 /**
368 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
369 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700370 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
371 this.mAccountHandle = accountHandle;
372 this.mLabel = label;
373 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700374
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700375 /**
376 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
377 * {@link PhoneAccount}.
378 *
379 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
380 */
381 public Builder(PhoneAccount phoneAccount) {
382 mAccountHandle = phoneAccount.getAccountHandle();
383 mAddress = phoneAccount.getAddress();
384 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
385 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800386 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700387 mLabel = phoneAccount.getLabel();
388 mShortDescription = phoneAccount.getShortDescription();
389 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700390 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc02015-05-08 13:52:09 -0700391 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunnd426b202015-10-13 13:33:53 -0700392 mExtras = phoneAccount.getExtras();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700393 mGroupId = phoneAccount.getGroupId();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800394 mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700395 }
396
Santos Cordon32c65a52014-10-27 14:57:49 -0700397 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700398 * Sets the label. See {@link PhoneAccount#getLabel()}.
399 *
400 * @param label The label of the phone account.
401 * @return The builder.
402 * @hide
403 */
404 public Builder setLabel(CharSequence label) {
405 this.mLabel = label;
406 return this;
407 }
408
409 /**
Santos Cordon32c65a52014-10-27 14:57:49 -0700410 * Sets the address. See {@link PhoneAccount#getAddress}.
411 *
412 * @param value The address of the phone account.
413 * @return The builder.
414 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700415 public Builder setAddress(Uri value) {
416 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700417 return this;
418 }
419
Santos Cordon32c65a52014-10-27 14:57:49 -0700420 /**
421 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
422 *
423 * @param value The subscription address.
424 * @return The builder.
425 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700426 public Builder setSubscriptionAddress(Uri value) {
427 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700428 return this;
429 }
430
Santos Cordon32c65a52014-10-27 14:57:49 -0700431 /**
432 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
433 *
434 * @param value The capabilities to set.
435 * @return The builder.
436 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700437 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700438 this.mCapabilities = value;
439 return this;
440 }
441
Santos Cordon32c65a52014-10-27 14:57:49 -0700442 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700443 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700444 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700445 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700446 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700447 public Builder setIcon(Icon icon) {
448 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700449 return this;
450 }
451
452 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800453 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700454 *
Ihab Awad476cc832014-11-03 09:47:51 -0800455 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700456 * @return The builder.
457 */
Ihab Awad476cc832014-11-03 09:47:51 -0800458 public Builder setHighlightColor(int value) {
459 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700460 return this;
461 }
462
Santos Cordon32c65a52014-10-27 14:57:49 -0700463 /**
464 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
465 *
466 * @param value The short description.
467 * @return The builder.
468 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700469 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700470 this.mShortDescription = value;
471 return this;
472 }
473
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700474 /**
475 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
476 *
477 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700478 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700479 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700480 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700481 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
482 this.mSupportedUriSchemes.add(uriScheme);
483 }
484 return this;
485 }
486
487 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700488 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700489 *
490 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700491 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700492 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700493 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
494 mSupportedUriSchemes.clear();
495
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700496 if (uriSchemes != null && !uriSchemes.isEmpty()) {
497 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700498 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700499 }
500 }
501 return this;
502 }
503
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700504 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700505 * Specifies the extras associated with the {@link PhoneAccount}.
506 * <p>
507 * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer},
508 * and {@link Boolean}. Extras which are not of these types are ignored.
509 *
510 * @param extras
511 * @return
512 */
513 public Builder setExtras(Bundle extras) {
514 mExtras = extras;
515 return this;
516 }
517
518 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700519 * Sets the enabled state of the phone account.
520 *
521 * @param isEnabled The enabled state.
522 * @return The builder.
523 * @hide
524 */
525 public Builder setIsEnabled(boolean isEnabled) {
526 mIsEnabled = isEnabled;
527 return this;
528 }
529
530 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700531 * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is
532 * registered to Telecom, it will replace another {@link PhoneAccount} that is already
533 * registered in Telecom and take on the current user defaults and enabled status. There can
534 * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a
535 * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only
536 * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced.
537 * @param groupId The group Id of the {@link PhoneAccount} that will replace any other
538 * registered {@link PhoneAccount} in Telecom with the same Group Id.
539 * @return The builder
540 * @hide
541 */
542 public Builder setGroupId(String groupId) {
543 if (groupId != null) {
544 mGroupId = groupId;
545 } else {
546 mGroupId = "";
547 }
548 return this;
549 }
550
551 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800552 * Sets the audio routes supported by this {@link PhoneAccount}.
553 *
554 * @param routes bit mask of available routes.
555 * @return The builder.
556 * @hide
557 */
558 public Builder setSupportedAudioRoutes(int routes) {
559 mSupportedAudioRoutes = routes;
560 return this;
561 }
562
563 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700564 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
565 *
566 * @return The {@link PhoneAccount}.
567 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700568 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700569 // If no supported URI schemes were defined, assume "tel" is supported.
570 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700571 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700572 }
573
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700574 return new PhoneAccount(
575 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700576 mAddress,
577 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700578 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700579 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800580 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700581 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700582 mShortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700583 mSupportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700584 mExtras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800585 mSupportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700586 mIsEnabled,
587 mGroupId);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700588 }
589 }
590
591 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700592 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700593 Uri address,
594 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700595 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700596 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800597 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700598 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700599 CharSequence shortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700600 List<String> supportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700601 Bundle extras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800602 int supportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700603 boolean isEnabled,
604 String groupId) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700605 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700606 mAddress = address;
607 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700608 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700609 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800610 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700611 mLabel = label;
612 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700613 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700614 mExtras = extras;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800615 mSupportedAudioRoutes = supportedAudioRoutes;
Santos Cordon91371dc02015-05-08 13:52:09 -0700616 mIsEnabled = isEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700617 mGroupId = groupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700618 }
619
Andrew Lee3085a6c2014-09-04 10:59:13 -0700620 public static Builder builder(
621 PhoneAccountHandle accountHandle,
622 CharSequence label) {
623 return new Builder(accountHandle, label);
624 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700625
Ihab Awad807fe0a2014-07-09 12:30:52 -0700626 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700627 * Returns a builder initialized with the current {@link PhoneAccount} instance.
628 *
629 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700630 */
631 public Builder toBuilder() { return new Builder(this); }
632
633 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700634 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700635 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700636 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700637 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700638 public PhoneAccountHandle getAccountHandle() {
639 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700640 }
641
642 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700643 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700644 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700645 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700646 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700647 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700648 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700649 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700650 public Uri getAddress() {
651 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700652 }
653
654 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700655 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700656 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700657 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000658 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
659 * has been used to alter the callback number.
660 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700661 *
662 * @return The subscription number, suitable for display to the user.
663 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700664 public Uri getSubscriptionAddress() {
665 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700666 }
667
668 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700669 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700670 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700671 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700672 */
673 public int getCapabilities() {
674 return mCapabilities;
675 }
676
677 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700678 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
679 * bit mask.
680 *
681 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700682 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700683 */
684 public boolean hasCapabilities(int capability) {
685 return (mCapabilities & capability) == capability;
686 }
687
688 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800689 * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask.
690 *
691 * @param route The routes to check.
692 * @return {@code true} if the phone account has the routes.
693 * @hide
694 */
695 public boolean hasAudioRoutes(int routes) {
696 return (mSupportedAudioRoutes & routes) == routes;
697 }
698
699 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700700 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700701 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700702 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700703 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700704 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700705 return mLabel;
706 }
707
708 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700709 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700710 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700711 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700712 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700713 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700714 return mShortDescription;
715 }
716
717 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700718 * The URI schemes supported by this {@code PhoneAccount}.
719 *
720 * @return The URI schemes.
721 */
722 public List<String> getSupportedUriSchemes() {
723 return mSupportedUriSchemes;
724 }
725
726 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700727 * The extras associated with this {@code PhoneAccount}.
728 * <p>
729 * A {@link ConnectionService} may provide implementation specific information about the
730 * {@link PhoneAccount} via the extras.
731 *
732 * @return The extras.
733 */
734 public Bundle getExtras() {
735 return mExtras;
736 }
737
738 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800739 * The audio routes supported by this {@code PhoneAccount}.
740 *
741 * @hide
742 */
743 public int getSupportedAudioRoutes() {
744 return mSupportedAudioRoutes;
745 }
746
747 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700748 * The icon to represent this {@code PhoneAccount}.
749 *
750 * @return The icon.
751 */
752 public Icon getIcon() {
753 return mIcon;
754 }
755
756 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700757 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
758 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc02015-05-08 13:52:09 -0700759 *
Santos Cordon895d4b82015-06-25 16:41:48 -0700760 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc02015-05-08 13:52:09 -0700761 */
762 public boolean isEnabled() {
763 return mIsEnabled;
764 }
765
766 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700767 * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an
768 * empty {@link String} if the {@link PhoneAccount} is not in a group. If this
769 * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered
770 * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced,
771 * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}.
772 * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced.
773 *
774 * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group.
775 * @hide
776 */
777 public String getGroupId() {
778 return mGroupId;
779 }
780
781 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700782 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700783 * scheme.
784 *
785 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700786 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700787 * specified URI scheme.
788 */
789 public boolean supportsUriScheme(String uriScheme) {
790 if (mSupportedUriSchemes == null || uriScheme == null) {
791 return false;
792 }
793
794 for (String scheme : mSupportedUriSchemes) {
795 if (scheme != null && scheme.equals(uriScheme)) {
796 return true;
797 }
798 }
799 return false;
800 }
801
802 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800803 * A highlight color to use in displaying information about this {@code PhoneAccount}.
804 *
805 * @return A hexadecimal color value.
806 */
807 public int getHighlightColor() {
808 return mHighlightColor;
809 }
810
Santos Cordon91371dc02015-05-08 13:52:09 -0700811 /**
812 * Sets the enabled state of the phone account.
813 * @hide
814 */
815 public void setIsEnabled(boolean isEnabled) {
816 mIsEnabled = isEnabled;
817 }
818
Tyler Gunnf5035432017-01-09 09:43:12 -0800819 /**
820 * @return {@code true} if the {@link PhoneAccount} is self-managed, {@code false} otherwise.
821 * @hide
822 */
823 public boolean isSelfManaged() {
824 return (mCapabilities & CAPABILITY_SELF_MANAGED) == CAPABILITY_SELF_MANAGED;
825 }
826
Ihab Awad807fe0a2014-07-09 12:30:52 -0700827 //
828 // Parcelable implementation
829 //
830
831 @Override
832 public int describeContents() {
833 return 0;
834 }
835
836 @Override
837 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800838 if (mAccountHandle == null) {
839 out.writeInt(0);
840 } else {
841 out.writeInt(1);
842 mAccountHandle.writeToParcel(out, flags);
843 }
844 if (mAddress == null) {
845 out.writeInt(0);
846 } else {
847 out.writeInt(1);
848 mAddress.writeToParcel(out, flags);
849 }
850 if (mSubscriptionAddress == null) {
851 out.writeInt(0);
852 } else {
853 out.writeInt(1);
854 mSubscriptionAddress.writeToParcel(out, flags);
855 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700856 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800857 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700858 out.writeCharSequence(mLabel);
859 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800860 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc02015-05-08 13:52:09 -0700861
Santos Cordoncad84a22015-05-13 11:17:25 -0700862 if (mIcon == null) {
863 out.writeInt(0);
864 } else {
865 out.writeInt(1);
866 mIcon.writeToParcel(out, flags);
867 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700868 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Tyler Gunnef829ec2015-10-08 09:46:23 -0700869 out.writeBundle(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700870 out.writeString(mGroupId);
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800871 out.writeInt(mSupportedAudioRoutes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700872 }
873
Evan Charlton8c8a0622014-07-20 12:31:00 -0700874 public static final Creator<PhoneAccount> CREATOR
875 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700876 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700877 public PhoneAccount createFromParcel(Parcel in) {
878 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700879 }
880
881 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700882 public PhoneAccount[] newArray(int size) {
883 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700884 }
885 };
886
Evan Charlton8c8a0622014-07-20 12:31:00 -0700887 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800888 if (in.readInt() > 0) {
889 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
890 } else {
891 mAccountHandle = null;
892 }
893 if (in.readInt() > 0) {
894 mAddress = Uri.CREATOR.createFromParcel(in);
895 } else {
896 mAddress = null;
897 }
898 if (in.readInt() > 0) {
899 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
900 } else {
901 mSubscriptionAddress = null;
902 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700903 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -0800904 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700905 mLabel = in.readCharSequence();
906 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800907 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -0700908 if (in.readInt() > 0) {
909 mIcon = Icon.CREATOR.createFromParcel(in);
910 } else {
911 mIcon = null;
912 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700913 mIsEnabled = in.readByte() == 1;
Tyler Gunnef829ec2015-10-08 09:46:23 -0700914 mExtras = in.readBundle();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700915 mGroupId = in.readString();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800916 mSupportedAudioRoutes = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700917 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700918
919 @Override
920 public String toString() {
Santos Cordon91371dc02015-05-08 13:52:09 -0700921 StringBuilder sb = new StringBuilder().append("[[")
922 .append(mIsEnabled ? 'X' : ' ')
923 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700924 .append(mAccountHandle)
925 .append(" Capabilities: ")
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800926 .append(capabilitiesToString())
927 .append(" Audio Routes: ")
928 .append(audioRoutesToString())
Tyler Gunn76c01a52014-09-30 14:47:51 -0700929 .append(" Schemes: ");
930 for (String scheme : mSupportedUriSchemes) {
931 sb.append(scheme)
932 .append(" ");
933 }
Tyler Gunnef829ec2015-10-08 09:46:23 -0700934 sb.append(" Extras: ");
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700935 sb.append(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700936 sb.append(" GroupId: ");
937 sb.append(Log.pii(mGroupId));
Tyler Gunn76c01a52014-09-30 14:47:51 -0700938 sb.append("]");
939 return sb.toString();
940 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800941
942 /**
943 * Generates a string representation of a capabilities bitmask.
944 *
945 * @param capabilities The capabilities bitmask.
946 * @return String representation of the capabilities bitmask.
947 */
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800948 private String capabilitiesToString() {
Tyler Gunn3e122f72016-01-11 19:25:00 -0800949 StringBuilder sb = new StringBuilder();
Tyler Gunnf5035432017-01-09 09:43:12 -0800950 if (hasCapabilities(CAPABILITY_SELF_MANAGED)) {
951 sb.append("SelfManaged ");
952 }
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800953 if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) {
954 sb.append("SuppVideo ");
955 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800956 if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) {
957 sb.append("Video ");
958 }
959 if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
960 sb.append("Presence ");
961 }
962 if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) {
963 sb.append("CallProvider ");
964 }
965 if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) {
966 sb.append("CallSubject ");
967 }
968 if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) {
969 sb.append("ConnectionMgr ");
970 }
971 if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) {
972 sb.append("EmergOnly ");
973 }
974 if (hasCapabilities(CAPABILITY_MULTI_USER)) {
975 sb.append("MultiUser ");
976 }
977 if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) {
978 sb.append("PlaceEmerg ");
979 }
Tyler Gunncee9ea62016-03-24 11:45:43 -0700980 if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
981 sb.append("EmergVideo ");
982 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800983 if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) {
984 sb.append("SimSub ");
985 }
Hall Liu47ed6202017-11-20 16:25:39 -0800986 if (hasCapabilities(CAPABILITY_RTT)) {
987 sb.append("Rtt");
988 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800989 return sb.toString();
990 }
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800991
992 private String audioRoutesToString() {
993 StringBuilder sb = new StringBuilder();
994
995 if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) {
996 sb.append("B");
997 }
998 if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) {
999 sb.append("E");
1000 }
1001 if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) {
1002 sb.append("S");
1003 }
1004 if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) {
1005 sb.append("W");
1006 }
1007
1008 return sb.toString();
1009 }
Ihab Awad807fe0a2014-07-09 12:30:52 -07001010}