blob: 692dfb73b59b76fb0a3efb7f247f1b6341fa99b0 [file] [log] [blame]
Ihab Awad807fe0a2014-07-09 12:30:52 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad807fe0a2014-07-09 12:30:52 -070018
Evan Charlton0e094d92014-11-08 15:49:16 -080019import android.annotation.SystemApi;
Santos Cordoncad84a22015-05-13 11:17:25 -070020import android.graphics.drawable.Icon;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070021import android.net.Uri;
Tyler Gunn25ed2d72015-10-05 14:14:38 -070022import android.os.Bundle;
Ihab Awad807fe0a2014-07-09 12:30:52 -070023import android.os.Parcel;
24import android.os.Parcelable;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070025import android.text.TextUtils;
Ihab Awad807fe0a2014-07-09 12:30:52 -070026
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070027import java.lang.String;
28import java.util.ArrayList;
29import java.util.Collections;
30import java.util.List;
Ihab Awad807fe0a2014-07-09 12:30:52 -070031
32/**
Santos Cordon32c65a52014-10-27 14:57:49 -070033 * Represents a distinct method to place or receive a phone call. Apps which can place calls and
34 * want those calls to be integrated into the dialer and in-call UI should build an instance of
Brian Attwellad147f42014-12-19 11:37:16 -080035 * this class and register it with the system using {@link TelecomManager}.
Santos Cordon32c65a52014-10-27 14:57:49 -070036 * <p>
37 * {@link TelecomManager} uses registered {@link PhoneAccount}s to present the user with
38 * alternative options when placing a phone call. When building a {@link PhoneAccount}, the app
Brian Attwellad147f42014-12-19 11:37:16 -080039 * should supply a valid {@link PhoneAccountHandle} that references the connection service
Santos Cordon32c65a52014-10-27 14:57:49 -070040 * implementation Telecom will use to interact with the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -070041 */
Yorke Lee400470f2015-05-12 13:31:25 -070042public final class PhoneAccount implements Parcelable {
Ihab Awad94cf4bf2014-07-17 11:21:19 -070043
44 /**
Tyler Gunnd426b202015-10-13 13:33:53 -070045 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
46 * maximum permitted length of a call subject specified via the
47 * {@link TelecomManager#EXTRA_CALL_SUBJECT} extra on an
48 * {@link android.content.Intent#ACTION_CALL} intent. Ultimately a {@link ConnectionService} is
49 * responsible for enforcing the maximum call subject length when sending the message, however
50 * this extra is provided so that the user interface can proactively limit the length of the
51 * call subject as the user types it.
52 */
53 public static final String EXTRA_CALL_SUBJECT_MAX_LENGTH =
54 "android.telecom.extra.CALL_SUBJECT_MAX_LENGTH";
55
56 /**
57 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
58 * character encoding to be used when determining the length of messages.
59 * The user interface can use this when determining the number of characters the user may type
60 * in a call subject. If empty-string, the call subject message size limit will be enforced on
61 * a 1:1 basis. That is, each character will count towards the messages size limit as a single
62 * character. If a character encoding is specified, the message size limit will be based on the
63 * number of bytes in the message per the specified encoding. See
64 * {@link #EXTRA_CALL_SUBJECT_MAX_LENGTH} for more information on the call subject maximum
65 * length.
66 */
67 public static final String EXTRA_CALL_SUBJECT_CHARACTER_ENCODING =
68 "android.telecom.extra.CALL_SUBJECT_CHARACTER_ENCODING";
69
70 /**
Ihab Awadf8b69882014-07-25 15:14:01 -070071 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
72 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
73 * will be allowed to manage phone calls including using its own proprietary phone-call
74 * implementation (like VoIP calling) to make calls instead of the telephony stack.
75 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -070076 * When a user opts to place a call using the SIM-based telephony stack, the
77 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
78 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -070079 * <p>
80 * See {@link #getCapabilities}
81 */
Ihab Awadf8b69882014-07-25 15:14:01 -070082 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070083
84 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -070085 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -070086 * traditional SIM-based telephony calls. This account will be treated as a distinct method
87 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -070088 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -070089 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -070090 * <p>
91 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -070092 * <p>
Ihab Awad94cf4bf2014-07-17 11:21:19 -070093 */
94 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
95
Ihab Awad7522bbd62014-07-18 15:53:17 -070096 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070097 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -070098 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -070099 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700100 * Only the Android framework can register a {@code PhoneAccount} having this capability.
101 * <p>
102 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -0700103 */
104 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
105
Ihab Awadf8b69882014-07-25 15:14:01 -0700106 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700107 * Flag indicating that this {@code PhoneAccount} is capable of placing video calls.
108 * <p>
109 * See {@link #getCapabilities}
Ihab Awadf8b69882014-07-25 15:14:01 -0700110 */
111 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
112
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700113 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700114 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
115 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
116 * <p>
117 * See {@link #getCapabilities}
118 */
119 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
120
121 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800122 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
123 * should only be used by system apps (and will be ignored for all other apps trying to use it).
124 * <p>
125 * See {@link #getCapabilities}
126 * @hide
127 */
Brian Attwellad147f42014-12-19 11:37:16 -0800128 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800129 public static final int CAPABILITY_MULTI_USER = 0x20;
130
131 /**
Tyler Gunn65a3d342015-07-27 16:06:16 -0700132 * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a
133 * caller is able to specify a short subject line for an outgoing call. A capable receiving
134 * device displays the call subject on the incoming call screen.
135 * <p>
136 * See {@link #getCapabilities}
137 */
138 public static final int CAPABILITY_CALL_SUBJECT = 0x40;
139
140 /**
Bryce Leeb96d89c2015-10-14 16:48:40 -0700141 * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls.
142 * <p>
143 * See {@link #getCapabilities}
144 * @hide
145 */
146 public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80;
147
148 /**
Tyler Gunn9a365752015-12-09 15:00:18 -0800149 * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a
150 * number relies on presence. Should only be set if the {@code PhoneAccount} also has
151 * {@link #CAPABILITY_VIDEO_CALLING}.
152 * <p>
153 * When set, the {@link ConnectionService} is responsible for toggling the
154 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the
155 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether
156 * a contact's phone number supports video calling.
157 * <p>
158 * See {@link #getCapabilities}
159 */
160 public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100;
161
162 /**
Tyler Gunncee9ea62016-03-24 11:45:43 -0700163 * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed.
164 * <p>
165 * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will
166 * convert all outgoing video calls to emergency numbers to audio-only.
167 * @hide
168 */
169 public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200;
170
171 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700172 * URI scheme for telephone number URIs.
173 */
174 public static final String SCHEME_TEL = "tel";
175
176 /**
177 * URI scheme for voicemail URIs.
178 */
179 public static final String SCHEME_VOICEMAIL = "voicemail";
180
181 /**
182 * URI scheme for SIP URIs.
183 */
184 public static final String SCHEME_SIP = "sip";
185
Nancy Chen3ace54b2014-10-22 17:45:26 -0700186 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800187 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700188 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700189 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800190 public static final int NO_ICON_TINT = 0;
191
192 /**
193 * Indicating no hightlight color is set.
194 */
195 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700196
Ihab Awad476cc832014-11-03 09:47:51 -0800197 /**
198 * Indicating no resource ID is set.
199 */
200 public static final int NO_RESOURCE_ID = -1;
201
Evan Charlton8c8a0622014-07-20 12:31:00 -0700202 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700203 private final Uri mAddress;
204 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700205 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800206 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700207 private final CharSequence mLabel;
208 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700209 private final List<String> mSupportedUriSchemes;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800210 private final int mSupportedAudioRoutes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700211 private final Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700212 private final Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700213 private boolean mIsEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700214 private String mGroupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700215
Santos Cordon32c65a52014-10-27 14:57:49 -0700216 /**
217 * Helper class for creating a {@link PhoneAccount}.
218 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700219 public static class Builder {
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800220
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700221 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700222 private Uri mAddress;
223 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700224 private int mCapabilities;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800225 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800226 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700227 private CharSequence mLabel;
228 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700229 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700230 private Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700231 private Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700232 private boolean mIsEnabled = false;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700233 private String mGroupId = "";
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700234
Santos Cordon32c65a52014-10-27 14:57:49 -0700235 /**
236 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
237 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700238 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
239 this.mAccountHandle = accountHandle;
240 this.mLabel = label;
241 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700242
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700243 /**
244 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
245 * {@link PhoneAccount}.
246 *
247 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
248 */
249 public Builder(PhoneAccount phoneAccount) {
250 mAccountHandle = phoneAccount.getAccountHandle();
251 mAddress = phoneAccount.getAddress();
252 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
253 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800254 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700255 mLabel = phoneAccount.getLabel();
256 mShortDescription = phoneAccount.getShortDescription();
257 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700258 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc02015-05-08 13:52:09 -0700259 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunnd426b202015-10-13 13:33:53 -0700260 mExtras = phoneAccount.getExtras();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700261 mGroupId = phoneAccount.getGroupId();
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800262 mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700263 }
264
Santos Cordon32c65a52014-10-27 14:57:49 -0700265 /**
266 * Sets the address. See {@link PhoneAccount#getAddress}.
267 *
268 * @param value The address of the phone account.
269 * @return The builder.
270 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700271 public Builder setAddress(Uri value) {
272 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700273 return this;
274 }
275
Santos Cordon32c65a52014-10-27 14:57:49 -0700276 /**
277 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
278 *
279 * @param value The subscription address.
280 * @return The builder.
281 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700282 public Builder setSubscriptionAddress(Uri value) {
283 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700284 return this;
285 }
286
Santos Cordon32c65a52014-10-27 14:57:49 -0700287 /**
288 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
289 *
290 * @param value The capabilities to set.
291 * @return The builder.
292 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700293 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700294 this.mCapabilities = value;
295 return this;
296 }
297
Santos Cordon32c65a52014-10-27 14:57:49 -0700298 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700299 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700300 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700301 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700302 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700303 public Builder setIcon(Icon icon) {
304 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700305 return this;
306 }
307
308 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800309 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700310 *
Ihab Awad476cc832014-11-03 09:47:51 -0800311 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700312 * @return The builder.
313 */
Ihab Awad476cc832014-11-03 09:47:51 -0800314 public Builder setHighlightColor(int value) {
315 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700316 return this;
317 }
318
Santos Cordon32c65a52014-10-27 14:57:49 -0700319 /**
320 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
321 *
322 * @param value The short description.
323 * @return The builder.
324 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700325 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700326 this.mShortDescription = value;
327 return this;
328 }
329
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700330 /**
331 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
332 *
333 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700334 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700335 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700336 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700337 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
338 this.mSupportedUriSchemes.add(uriScheme);
339 }
340 return this;
341 }
342
343 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700344 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700345 *
346 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700347 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700348 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700349 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
350 mSupportedUriSchemes.clear();
351
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700352 if (uriSchemes != null && !uriSchemes.isEmpty()) {
353 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700354 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700355 }
356 }
357 return this;
358 }
359
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700360 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700361 * Specifies the extras associated with the {@link PhoneAccount}.
362 * <p>
363 * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer},
364 * and {@link Boolean}. Extras which are not of these types are ignored.
365 *
366 * @param extras
367 * @return
368 */
369 public Builder setExtras(Bundle extras) {
370 mExtras = extras;
371 return this;
372 }
373
374 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700375 * Sets the enabled state of the phone account.
376 *
377 * @param isEnabled The enabled state.
378 * @return The builder.
379 * @hide
380 */
381 public Builder setIsEnabled(boolean isEnabled) {
382 mIsEnabled = isEnabled;
383 return this;
384 }
385
386 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700387 * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is
388 * registered to Telecom, it will replace another {@link PhoneAccount} that is already
389 * registered in Telecom and take on the current user defaults and enabled status. There can
390 * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a
391 * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only
392 * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced.
393 * @param groupId The group Id of the {@link PhoneAccount} that will replace any other
394 * registered {@link PhoneAccount} in Telecom with the same Group Id.
395 * @return The builder
396 * @hide
397 */
398 public Builder setGroupId(String groupId) {
399 if (groupId != null) {
400 mGroupId = groupId;
401 } else {
402 mGroupId = "";
403 }
404 return this;
405 }
406
407 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800408 * Sets the audio routes supported by this {@link PhoneAccount}.
409 *
410 * @param routes bit mask of available routes.
411 * @return The builder.
412 * @hide
413 */
414 public Builder setSupportedAudioRoutes(int routes) {
415 mSupportedAudioRoutes = routes;
416 return this;
417 }
418
419 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700420 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
421 *
422 * @return The {@link PhoneAccount}.
423 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700424 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700425 // If no supported URI schemes were defined, assume "tel" is supported.
426 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700427 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700428 }
429
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700430 return new PhoneAccount(
431 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700432 mAddress,
433 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700434 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700435 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800436 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700437 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700438 mShortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700439 mSupportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700440 mExtras,
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800441 mSupportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700442 mIsEnabled,
443 mGroupId);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700444 }
445 }
446
447 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700448 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700449 Uri address,
450 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700451 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700452 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800453 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700454 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700455 CharSequence shortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700456 List<String> supportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700457 Bundle extras,
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800458 int supportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700459 boolean isEnabled,
460 String groupId) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700461 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700462 mAddress = address;
463 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700464 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700465 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800466 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700467 mLabel = label;
468 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700469 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700470 mExtras = extras;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800471 mSupportedAudioRoutes = supportedAudioRoutes;
Santos Cordon91371dc02015-05-08 13:52:09 -0700472 mIsEnabled = isEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700473 mGroupId = groupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700474 }
475
Andrew Lee3085a6c2014-09-04 10:59:13 -0700476 public static Builder builder(
477 PhoneAccountHandle accountHandle,
478 CharSequence label) {
479 return new Builder(accountHandle, label);
480 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700481
Ihab Awad807fe0a2014-07-09 12:30:52 -0700482 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700483 * Returns a builder initialized with the current {@link PhoneAccount} instance.
484 *
485 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700486 */
487 public Builder toBuilder() { return new Builder(this); }
488
489 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700490 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700491 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700492 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700493 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700494 public PhoneAccountHandle getAccountHandle() {
495 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700496 }
497
498 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700499 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700500 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700501 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700502 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700503 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700504 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700505 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700506 public Uri getAddress() {
507 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700508 }
509
510 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700511 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700512 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700513 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000514 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
515 * has been used to alter the callback number.
516 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700517 *
518 * @return The subscription number, suitable for display to the user.
519 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700520 public Uri getSubscriptionAddress() {
521 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700522 }
523
524 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700525 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700526 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700527 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700528 */
529 public int getCapabilities() {
530 return mCapabilities;
531 }
532
533 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700534 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
535 * bit mask.
536 *
537 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700538 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700539 */
540 public boolean hasCapabilities(int capability) {
541 return (mCapabilities & capability) == capability;
542 }
543
544 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800545 * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask.
546 *
547 * @param route The routes to check.
548 * @return {@code true} if the phone account has the routes.
549 * @hide
550 */
551 public boolean hasAudioRoutes(int routes) {
552 return (mSupportedAudioRoutes & routes) == routes;
553 }
554
555 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700556 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700557 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700558 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700559 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700560 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700561 return mLabel;
562 }
563
564 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700565 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700566 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700567 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700568 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700569 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700570 return mShortDescription;
571 }
572
573 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700574 * The URI schemes supported by this {@code PhoneAccount}.
575 *
576 * @return The URI schemes.
577 */
578 public List<String> getSupportedUriSchemes() {
579 return mSupportedUriSchemes;
580 }
581
582 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700583 * The extras associated with this {@code PhoneAccount}.
584 * <p>
585 * A {@link ConnectionService} may provide implementation specific information about the
586 * {@link PhoneAccount} via the extras.
587 *
588 * @return The extras.
589 */
590 public Bundle getExtras() {
591 return mExtras;
592 }
593
594 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800595 * The audio routes supported by this {@code PhoneAccount}.
596 *
597 * @hide
598 */
599 public int getSupportedAudioRoutes() {
600 return mSupportedAudioRoutes;
601 }
602
603 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700604 * The icon to represent this {@code PhoneAccount}.
605 *
606 * @return The icon.
607 */
608 public Icon getIcon() {
609 return mIcon;
610 }
611
612 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700613 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
614 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc02015-05-08 13:52:09 -0700615 *
Santos Cordon895d4b82015-06-25 16:41:48 -0700616 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc02015-05-08 13:52:09 -0700617 */
618 public boolean isEnabled() {
619 return mIsEnabled;
620 }
621
622 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700623 * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an
624 * empty {@link String} if the {@link PhoneAccount} is not in a group. If this
625 * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered
626 * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced,
627 * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}.
628 * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced.
629 *
630 * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group.
631 * @hide
632 */
633 public String getGroupId() {
634 return mGroupId;
635 }
636
637 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700638 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700639 * scheme.
640 *
641 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700642 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700643 * specified URI scheme.
644 */
645 public boolean supportsUriScheme(String uriScheme) {
646 if (mSupportedUriSchemes == null || uriScheme == null) {
647 return false;
648 }
649
650 for (String scheme : mSupportedUriSchemes) {
651 if (scheme != null && scheme.equals(uriScheme)) {
652 return true;
653 }
654 }
655 return false;
656 }
657
658 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800659 * A highlight color to use in displaying information about this {@code PhoneAccount}.
660 *
661 * @return A hexadecimal color value.
662 */
663 public int getHighlightColor() {
664 return mHighlightColor;
665 }
666
Santos Cordon91371dc02015-05-08 13:52:09 -0700667 /**
668 * Sets the enabled state of the phone account.
669 * @hide
670 */
671 public void setIsEnabled(boolean isEnabled) {
672 mIsEnabled = isEnabled;
673 }
674
Ihab Awad807fe0a2014-07-09 12:30:52 -0700675 //
676 // Parcelable implementation
677 //
678
679 @Override
680 public int describeContents() {
681 return 0;
682 }
683
684 @Override
685 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800686 if (mAccountHandle == null) {
687 out.writeInt(0);
688 } else {
689 out.writeInt(1);
690 mAccountHandle.writeToParcel(out, flags);
691 }
692 if (mAddress == null) {
693 out.writeInt(0);
694 } else {
695 out.writeInt(1);
696 mAddress.writeToParcel(out, flags);
697 }
698 if (mSubscriptionAddress == null) {
699 out.writeInt(0);
700 } else {
701 out.writeInt(1);
702 mSubscriptionAddress.writeToParcel(out, flags);
703 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700704 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800705 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700706 out.writeCharSequence(mLabel);
707 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800708 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc02015-05-08 13:52:09 -0700709
Santos Cordoncad84a22015-05-13 11:17:25 -0700710 if (mIcon == null) {
711 out.writeInt(0);
712 } else {
713 out.writeInt(1);
714 mIcon.writeToParcel(out, flags);
715 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700716 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Tyler Gunnef829ec2015-10-08 09:46:23 -0700717 out.writeBundle(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700718 out.writeString(mGroupId);
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800719 out.writeInt(mSupportedAudioRoutes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700720 }
721
Evan Charlton8c8a0622014-07-20 12:31:00 -0700722 public static final Creator<PhoneAccount> CREATOR
723 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700724 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700725 public PhoneAccount createFromParcel(Parcel in) {
726 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700727 }
728
729 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700730 public PhoneAccount[] newArray(int size) {
731 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700732 }
733 };
734
Evan Charlton8c8a0622014-07-20 12:31:00 -0700735 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800736 if (in.readInt() > 0) {
737 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
738 } else {
739 mAccountHandle = null;
740 }
741 if (in.readInt() > 0) {
742 mAddress = Uri.CREATOR.createFromParcel(in);
743 } else {
744 mAddress = null;
745 }
746 if (in.readInt() > 0) {
747 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
748 } else {
749 mSubscriptionAddress = null;
750 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700751 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -0800752 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700753 mLabel = in.readCharSequence();
754 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800755 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -0700756 if (in.readInt() > 0) {
757 mIcon = Icon.CREATOR.createFromParcel(in);
758 } else {
759 mIcon = null;
760 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700761 mIsEnabled = in.readByte() == 1;
Tyler Gunnef829ec2015-10-08 09:46:23 -0700762 mExtras = in.readBundle();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700763 mGroupId = in.readString();
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800764 mSupportedAudioRoutes = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700765 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700766
767 @Override
768 public String toString() {
Santos Cordon91371dc02015-05-08 13:52:09 -0700769 StringBuilder sb = new StringBuilder().append("[[")
770 .append(mIsEnabled ? 'X' : ' ')
771 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700772 .append(mAccountHandle)
773 .append(" Capabilities: ")
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800774 .append(capabilitiesToString())
775 .append(" Audio Routes: ")
776 .append(audioRoutesToString())
Tyler Gunn76c01a52014-09-30 14:47:51 -0700777 .append(" Schemes: ");
778 for (String scheme : mSupportedUriSchemes) {
779 sb.append(scheme)
780 .append(" ");
781 }
Tyler Gunnef829ec2015-10-08 09:46:23 -0700782 sb.append(" Extras: ");
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700783 sb.append(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700784 sb.append(" GroupId: ");
785 sb.append(Log.pii(mGroupId));
Tyler Gunn76c01a52014-09-30 14:47:51 -0700786 sb.append("]");
787 return sb.toString();
788 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800789
790 /**
791 * Generates a string representation of a capabilities bitmask.
792 *
793 * @param capabilities The capabilities bitmask.
794 * @return String representation of the capabilities bitmask.
795 */
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800796 private String capabilitiesToString() {
Tyler Gunn3e122f72016-01-11 19:25:00 -0800797 StringBuilder sb = new StringBuilder();
798 if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) {
799 sb.append("Video ");
800 }
801 if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
802 sb.append("Presence ");
803 }
804 if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) {
805 sb.append("CallProvider ");
806 }
807 if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) {
808 sb.append("CallSubject ");
809 }
810 if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) {
811 sb.append("ConnectionMgr ");
812 }
813 if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) {
814 sb.append("EmergOnly ");
815 }
816 if (hasCapabilities(CAPABILITY_MULTI_USER)) {
817 sb.append("MultiUser ");
818 }
819 if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) {
820 sb.append("PlaceEmerg ");
821 }
Tyler Gunncee9ea62016-03-24 11:45:43 -0700822 if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
823 sb.append("EmergVideo ");
824 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800825 if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) {
826 sb.append("SimSub ");
827 }
828 return sb.toString();
829 }
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800830
831 private String audioRoutesToString() {
832 StringBuilder sb = new StringBuilder();
833
834 if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) {
835 sb.append("B");
836 }
837 if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) {
838 sb.append("E");
839 }
840 if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) {
841 sb.append("S");
842 }
843 if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) {
844 sb.append("W");
845 }
846
847 return sb.toString();
848 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700849}