blob: 473e39457f5847ff2d1e969d731ee14a49076b82 [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;
Ihab Awad074bf102014-10-24 11:42:32 -070020import android.content.ComponentName;
Ihab Awad807fe0a2014-07-09 12:30:52 -070021import android.content.Context;
22import android.content.pm.PackageManager;
Santos Cordone8dc4be2014-07-21 01:28:28 -070023import android.content.res.Resources.NotFoundException;
Ihab Awad074bf102014-10-24 11:42:32 -070024import android.graphics.Bitmap;
25import android.graphics.Color;
26import android.graphics.drawable.BitmapDrawable;
27import android.graphics.drawable.ColorDrawable;
Ihab Awad807fe0a2014-07-09 12:30:52 -070028import android.graphics.drawable.Drawable;
Santos Cordoncad84a22015-05-13 11:17:25 -070029import android.graphics.drawable.Icon;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070030import android.net.Uri;
Tyler Gunn25ed2d72015-10-05 14:14:38 -070031import android.os.Bundle;
Ihab Awad807fe0a2014-07-09 12:30:52 -070032import android.os.Parcel;
33import android.os.Parcelable;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070034import android.text.TextUtils;
Ihab Awad807fe0a2014-07-09 12:30:52 -070035
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070036import java.lang.String;
37import java.util.ArrayList;
38import java.util.Collections;
39import java.util.List;
Ihab Awad807fe0a2014-07-09 12:30:52 -070040import java.util.MissingResourceException;
41
42/**
Santos Cordon32c65a52014-10-27 14:57:49 -070043 * Represents a distinct method to place or receive a phone call. Apps which can place calls and
44 * 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 -080045 * this class and register it with the system using {@link TelecomManager}.
Santos Cordon32c65a52014-10-27 14:57:49 -070046 * <p>
47 * {@link TelecomManager} uses registered {@link PhoneAccount}s to present the user with
48 * alternative options when placing a phone call. When building a {@link PhoneAccount}, the app
Brian Attwellad147f42014-12-19 11:37:16 -080049 * should supply a valid {@link PhoneAccountHandle} that references the connection service
Santos Cordon32c65a52014-10-27 14:57:49 -070050 * implementation Telecom will use to interact with the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -070051 */
Yorke Lee400470f2015-05-12 13:31:25 -070052public final class PhoneAccount implements Parcelable {
Ihab Awad94cf4bf2014-07-17 11:21:19 -070053
54 /**
Tyler Gunnd426b202015-10-13 13:33:53 -070055 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
56 * maximum permitted length of a call subject specified via the
57 * {@link TelecomManager#EXTRA_CALL_SUBJECT} extra on an
58 * {@link android.content.Intent#ACTION_CALL} intent. Ultimately a {@link ConnectionService} is
59 * responsible for enforcing the maximum call subject length when sending the message, however
60 * this extra is provided so that the user interface can proactively limit the length of the
61 * call subject as the user types it.
62 */
63 public static final String EXTRA_CALL_SUBJECT_MAX_LENGTH =
64 "android.telecom.extra.CALL_SUBJECT_MAX_LENGTH";
65
66 /**
67 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
68 * character encoding to be used when determining the length of messages.
69 * The user interface can use this when determining the number of characters the user may type
70 * in a call subject. If empty-string, the call subject message size limit will be enforced on
71 * a 1:1 basis. That is, each character will count towards the messages size limit as a single
72 * character. If a character encoding is specified, the message size limit will be based on the
73 * number of bytes in the message per the specified encoding. See
74 * {@link #EXTRA_CALL_SUBJECT_MAX_LENGTH} for more information on the call subject maximum
75 * length.
76 */
77 public static final String EXTRA_CALL_SUBJECT_CHARACTER_ENCODING =
78 "android.telecom.extra.CALL_SUBJECT_CHARACTER_ENCODING";
79
80 /**
Ihab Awadf8b69882014-07-25 15:14:01 -070081 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
82 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
83 * will be allowed to manage phone calls including using its own proprietary phone-call
84 * implementation (like VoIP calling) to make calls instead of the telephony stack.
85 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -070086 * When a user opts to place a call using the SIM-based telephony stack, the
87 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
88 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -070089 * <p>
90 * See {@link #getCapabilities}
91 */
Ihab Awadf8b69882014-07-25 15:14:01 -070092 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070093
94 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -070095 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -070096 * traditional SIM-based telephony calls. This account will be treated as a distinct method
97 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -070098 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -070099 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700100 * <p>
101 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700102 * <p>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700103 */
104 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
105
Ihab Awad7522bbd2014-07-18 15:53:17 -0700106 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700107 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -0700108 * subscription.
Ihab Awad7522bbd2014-07-18 15:53:17 -0700109 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700110 * Only the Android framework can register a {@code PhoneAccount} having this capability.
111 * <p>
112 * See {@link #getCapabilities}
Ihab Awad7522bbd2014-07-18 15:53:17 -0700113 */
114 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
115
Ihab Awadf8b69882014-07-25 15:14:01 -0700116 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700117 * Flag indicating that this {@code PhoneAccount} is capable of placing video calls.
118 * <p>
119 * See {@link #getCapabilities}
Ihab Awadf8b69882014-07-25 15:14:01 -0700120 */
121 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
122
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700123 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700124 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
125 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
126 * <p>
127 * See {@link #getCapabilities}
128 */
129 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
130
131 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800132 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
133 * should only be used by system apps (and will be ignored for all other apps trying to use it).
134 * <p>
135 * See {@link #getCapabilities}
136 * @hide
137 */
Brian Attwellad147f42014-12-19 11:37:16 -0800138 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800139 public static final int CAPABILITY_MULTI_USER = 0x20;
140
141 /**
Tyler Gunn65a3d342015-07-27 16:06:16 -0700142 * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a
143 * caller is able to specify a short subject line for an outgoing call. A capable receiving
144 * device displays the call subject on the incoming call screen.
145 * <p>
146 * See {@link #getCapabilities}
147 */
148 public static final int CAPABILITY_CALL_SUBJECT = 0x40;
149
150 /**
Bryce Leeb96d89c2015-10-14 16:48:40 -0700151 * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls.
152 * <p>
153 * See {@link #getCapabilities}
154 * @hide
155 */
156 public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80;
157
158 /**
Tyler Gunn9a365752015-12-09 15:00:18 -0800159 * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a
160 * number relies on presence. Should only be set if the {@code PhoneAccount} also has
161 * {@link #CAPABILITY_VIDEO_CALLING}.
162 * <p>
163 * When set, the {@link ConnectionService} is responsible for toggling the
164 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the
165 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether
166 * a contact's phone number supports video calling.
167 * <p>
168 * See {@link #getCapabilities}
169 */
170 public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100;
171
172 /**
Tyler Gunncee9ea62016-03-24 11:45:43 -0700173 * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed.
174 * <p>
175 * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will
176 * convert all outgoing video calls to emergency numbers to audio-only.
177 * @hide
178 */
179 public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200;
180
181 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700182 * URI scheme for telephone number URIs.
183 */
184 public static final String SCHEME_TEL = "tel";
185
186 /**
187 * URI scheme for voicemail URIs.
188 */
189 public static final String SCHEME_VOICEMAIL = "voicemail";
190
191 /**
192 * URI scheme for SIP URIs.
193 */
194 public static final String SCHEME_SIP = "sip";
195
Nancy Chen3ace54b2014-10-22 17:45:26 -0700196 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800197 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700198 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700199 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800200 public static final int NO_ICON_TINT = 0;
201
202 /**
203 * Indicating no hightlight color is set.
204 */
205 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700206
Ihab Awad476cc832014-11-03 09:47:51 -0800207 /**
208 * Indicating no resource ID is set.
209 */
210 public static final int NO_RESOURCE_ID = -1;
211
Evan Charlton8c8a0622014-07-20 12:31:00 -0700212 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700213 private final Uri mAddress;
214 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700215 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800216 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700217 private final CharSequence mLabel;
218 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700219 private final List<String> mSupportedUriSchemes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700220 private final Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700221 private final Bundle mExtras;
Santos Cordon91371dc2015-05-08 13:52:09 -0700222 private boolean mIsEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700223 private String mGroupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700224
Santos Cordon32c65a52014-10-27 14:57:49 -0700225 /**
226 * Helper class for creating a {@link PhoneAccount}.
227 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700228 public static class Builder {
229 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700230 private Uri mAddress;
231 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700232 private int mCapabilities;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800233 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700234 private CharSequence mLabel;
235 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700236 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700237 private Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700238 private Bundle mExtras;
Santos Cordon91371dc2015-05-08 13:52:09 -0700239 private boolean mIsEnabled = false;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700240 private String mGroupId = "";
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700241
Santos Cordon32c65a52014-10-27 14:57:49 -0700242 /**
243 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
244 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700245 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
246 this.mAccountHandle = accountHandle;
247 this.mLabel = label;
248 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700249
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700250 /**
251 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
252 * {@link PhoneAccount}.
253 *
254 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
255 */
256 public Builder(PhoneAccount phoneAccount) {
257 mAccountHandle = phoneAccount.getAccountHandle();
258 mAddress = phoneAccount.getAddress();
259 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
260 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800261 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700262 mLabel = phoneAccount.getLabel();
263 mShortDescription = phoneAccount.getShortDescription();
264 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700265 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc2015-05-08 13:52:09 -0700266 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunnd426b202015-10-13 13:33:53 -0700267 mExtras = phoneAccount.getExtras();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700268 mGroupId = phoneAccount.getGroupId();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700269 }
270
Santos Cordon32c65a52014-10-27 14:57:49 -0700271 /**
272 * Sets the address. See {@link PhoneAccount#getAddress}.
273 *
274 * @param value The address of the phone account.
275 * @return The builder.
276 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700277 public Builder setAddress(Uri value) {
278 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700279 return this;
280 }
281
Santos Cordon32c65a52014-10-27 14:57:49 -0700282 /**
283 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
284 *
285 * @param value The subscription address.
286 * @return The builder.
287 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700288 public Builder setSubscriptionAddress(Uri value) {
289 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700290 return this;
291 }
292
Santos Cordon32c65a52014-10-27 14:57:49 -0700293 /**
294 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
295 *
296 * @param value The capabilities to set.
297 * @return The builder.
298 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700299 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700300 this.mCapabilities = value;
301 return this;
302 }
303
Santos Cordon32c65a52014-10-27 14:57:49 -0700304 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700305 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700306 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700307 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700308 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700309 public Builder setIcon(Icon icon) {
310 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700311 return this;
312 }
313
314 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800315 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700316 *
Ihab Awad476cc832014-11-03 09:47:51 -0800317 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700318 * @return The builder.
319 */
Ihab Awad476cc832014-11-03 09:47:51 -0800320 public Builder setHighlightColor(int value) {
321 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700322 return this;
323 }
324
Santos Cordon32c65a52014-10-27 14:57:49 -0700325 /**
326 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
327 *
328 * @param value The short description.
329 * @return The builder.
330 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700331 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700332 this.mShortDescription = value;
333 return this;
334 }
335
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700336 /**
337 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
338 *
339 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700340 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700341 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700342 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700343 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
344 this.mSupportedUriSchemes.add(uriScheme);
345 }
346 return this;
347 }
348
349 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700350 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700351 *
352 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700353 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700354 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700355 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
356 mSupportedUriSchemes.clear();
357
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700358 if (uriSchemes != null && !uriSchemes.isEmpty()) {
359 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700360 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700361 }
362 }
363 return this;
364 }
365
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700366 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700367 * Specifies the extras associated with the {@link PhoneAccount}.
368 * <p>
369 * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer},
370 * and {@link Boolean}. Extras which are not of these types are ignored.
371 *
372 * @param extras
373 * @return
374 */
375 public Builder setExtras(Bundle extras) {
376 mExtras = extras;
377 return this;
378 }
379
380 /**
Santos Cordon91371dc2015-05-08 13:52:09 -0700381 * Sets the enabled state of the phone account.
382 *
383 * @param isEnabled The enabled state.
384 * @return The builder.
385 * @hide
386 */
387 public Builder setIsEnabled(boolean isEnabled) {
388 mIsEnabled = isEnabled;
389 return this;
390 }
391
392 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700393 * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is
394 * registered to Telecom, it will replace another {@link PhoneAccount} that is already
395 * registered in Telecom and take on the current user defaults and enabled status. There can
396 * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a
397 * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only
398 * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced.
399 * @param groupId The group Id of the {@link PhoneAccount} that will replace any other
400 * registered {@link PhoneAccount} in Telecom with the same Group Id.
401 * @return The builder
402 * @hide
403 */
404 public Builder setGroupId(String groupId) {
405 if (groupId != null) {
406 mGroupId = groupId;
407 } else {
408 mGroupId = "";
409 }
410 return this;
411 }
412
413 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700414 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
415 *
416 * @return The {@link PhoneAccount}.
417 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700418 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700419 // If no supported URI schemes were defined, assume "tel" is supported.
420 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700421 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700422 }
423
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700424 return new PhoneAccount(
425 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700426 mAddress,
427 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700428 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700429 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800430 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700431 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700432 mShortDescription,
Santos Cordon91371dc2015-05-08 13:52:09 -0700433 mSupportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700434 mExtras,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700435 mIsEnabled,
436 mGroupId);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700437 }
438 }
439
440 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700441 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700442 Uri address,
443 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700444 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700445 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800446 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700447 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700448 CharSequence shortDescription,
Santos Cordon91371dc2015-05-08 13:52:09 -0700449 List<String> supportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700450 Bundle extras,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700451 boolean isEnabled,
452 String groupId) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700453 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700454 mAddress = address;
455 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700456 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700457 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800458 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700459 mLabel = label;
460 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700461 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700462 mExtras = extras;
Santos Cordon91371dc2015-05-08 13:52:09 -0700463 mIsEnabled = isEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700464 mGroupId = groupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700465 }
466
Andrew Lee3085a6c2014-09-04 10:59:13 -0700467 public static Builder builder(
468 PhoneAccountHandle accountHandle,
469 CharSequence label) {
470 return new Builder(accountHandle, label);
471 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700472
Ihab Awad807fe0a2014-07-09 12:30:52 -0700473 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700474 * Returns a builder initialized with the current {@link PhoneAccount} instance.
475 *
476 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700477 */
478 public Builder toBuilder() { return new Builder(this); }
479
480 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700481 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700482 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700483 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700484 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700485 public PhoneAccountHandle getAccountHandle() {
486 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700487 }
488
489 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700490 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700491 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700492 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700493 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700494 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700495 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700496 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700497 public Uri getAddress() {
498 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700499 }
500
501 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700502 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700503 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700504 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000505 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
506 * has been used to alter the callback number.
507 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700508 *
509 * @return The subscription number, suitable for display to the user.
510 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700511 public Uri getSubscriptionAddress() {
512 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700513 }
514
515 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700516 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700517 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700518 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700519 */
520 public int getCapabilities() {
521 return mCapabilities;
522 }
523
524 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700525 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
526 * bit mask.
527 *
528 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700529 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700530 */
531 public boolean hasCapabilities(int capability) {
532 return (mCapabilities & capability) == capability;
533 }
534
535 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700536 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700537 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700538 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700539 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700540 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700541 return mLabel;
542 }
543
544 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700545 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700546 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700547 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700548 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700549 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700550 return mShortDescription;
551 }
552
553 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700554 * The URI schemes supported by this {@code PhoneAccount}.
555 *
556 * @return The URI schemes.
557 */
558 public List<String> getSupportedUriSchemes() {
559 return mSupportedUriSchemes;
560 }
561
562 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700563 * The extras associated with this {@code PhoneAccount}.
564 * <p>
565 * A {@link ConnectionService} may provide implementation specific information about the
566 * {@link PhoneAccount} via the extras.
567 *
568 * @return The extras.
569 */
570 public Bundle getExtras() {
571 return mExtras;
572 }
573
574 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700575 * The icon to represent this {@code PhoneAccount}.
576 *
577 * @return The icon.
578 */
579 public Icon getIcon() {
580 return mIcon;
581 }
582
583 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700584 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
585 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc2015-05-08 13:52:09 -0700586 *
Santos Cordon895d4b82015-06-25 16:41:48 -0700587 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc2015-05-08 13:52:09 -0700588 */
589 public boolean isEnabled() {
590 return mIsEnabled;
591 }
592
593 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700594 * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an
595 * empty {@link String} if the {@link PhoneAccount} is not in a group. If this
596 * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered
597 * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced,
598 * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}.
599 * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced.
600 *
601 * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group.
602 * @hide
603 */
604 public String getGroupId() {
605 return mGroupId;
606 }
607
608 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700609 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700610 * scheme.
611 *
612 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700613 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700614 * specified URI scheme.
615 */
616 public boolean supportsUriScheme(String uriScheme) {
617 if (mSupportedUriSchemes == null || uriScheme == null) {
618 return false;
619 }
620
621 for (String scheme : mSupportedUriSchemes) {
622 if (scheme != null && scheme.equals(uriScheme)) {
623 return true;
624 }
625 }
626 return false;
627 }
628
629 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800630 * A highlight color to use in displaying information about this {@code PhoneAccount}.
631 *
632 * @return A hexadecimal color value.
633 */
634 public int getHighlightColor() {
635 return mHighlightColor;
636 }
637
Santos Cordon91371dc2015-05-08 13:52:09 -0700638 /**
639 * Sets the enabled state of the phone account.
640 * @hide
641 */
642 public void setIsEnabled(boolean isEnabled) {
643 mIsEnabled = isEnabled;
644 }
645
Ihab Awad807fe0a2014-07-09 12:30:52 -0700646 //
647 // Parcelable implementation
648 //
649
650 @Override
651 public int describeContents() {
652 return 0;
653 }
654
655 @Override
656 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800657 if (mAccountHandle == null) {
658 out.writeInt(0);
659 } else {
660 out.writeInt(1);
661 mAccountHandle.writeToParcel(out, flags);
662 }
663 if (mAddress == null) {
664 out.writeInt(0);
665 } else {
666 out.writeInt(1);
667 mAddress.writeToParcel(out, flags);
668 }
669 if (mSubscriptionAddress == null) {
670 out.writeInt(0);
671 } else {
672 out.writeInt(1);
673 mSubscriptionAddress.writeToParcel(out, flags);
674 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700675 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800676 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700677 out.writeCharSequence(mLabel);
678 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800679 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc2015-05-08 13:52:09 -0700680
Santos Cordoncad84a22015-05-13 11:17:25 -0700681 if (mIcon == null) {
682 out.writeInt(0);
683 } else {
684 out.writeInt(1);
685 mIcon.writeToParcel(out, flags);
686 }
Santos Cordon91371dc2015-05-08 13:52:09 -0700687 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Tyler Gunnef829ec2015-10-08 09:46:23 -0700688 out.writeBundle(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700689 out.writeString(mGroupId);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700690 }
691
Evan Charlton8c8a0622014-07-20 12:31:00 -0700692 public static final Creator<PhoneAccount> CREATOR
693 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700694 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700695 public PhoneAccount createFromParcel(Parcel in) {
696 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700697 }
698
699 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700700 public PhoneAccount[] newArray(int size) {
701 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700702 }
703 };
704
Evan Charlton8c8a0622014-07-20 12:31:00 -0700705 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800706 if (in.readInt() > 0) {
707 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
708 } else {
709 mAccountHandle = null;
710 }
711 if (in.readInt() > 0) {
712 mAddress = Uri.CREATOR.createFromParcel(in);
713 } else {
714 mAddress = null;
715 }
716 if (in.readInt() > 0) {
717 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
718 } else {
719 mSubscriptionAddress = null;
720 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700721 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -0800722 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700723 mLabel = in.readCharSequence();
724 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800725 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -0700726 if (in.readInt() > 0) {
727 mIcon = Icon.CREATOR.createFromParcel(in);
728 } else {
729 mIcon = null;
730 }
Santos Cordon91371dc2015-05-08 13:52:09 -0700731 mIsEnabled = in.readByte() == 1;
Tyler Gunnef829ec2015-10-08 09:46:23 -0700732 mExtras = in.readBundle();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700733 mGroupId = in.readString();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700734 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700735
736 @Override
737 public String toString() {
Santos Cordon91371dc2015-05-08 13:52:09 -0700738 StringBuilder sb = new StringBuilder().append("[[")
739 .append(mIsEnabled ? 'X' : ' ')
740 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700741 .append(mAccountHandle)
742 .append(" Capabilities: ")
Tyler Gunn3e122f72016-01-11 19:25:00 -0800743 .append(capabilitiesToString(mCapabilities))
Tyler Gunn76c01a52014-09-30 14:47:51 -0700744 .append(" Schemes: ");
745 for (String scheme : mSupportedUriSchemes) {
746 sb.append(scheme)
747 .append(" ");
748 }
Tyler Gunnef829ec2015-10-08 09:46:23 -0700749 sb.append(" Extras: ");
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700750 sb.append(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700751 sb.append(" GroupId: ");
752 sb.append(Log.pii(mGroupId));
Tyler Gunn76c01a52014-09-30 14:47:51 -0700753 sb.append("]");
754 return sb.toString();
755 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800756
757 /**
758 * Generates a string representation of a capabilities bitmask.
759 *
760 * @param capabilities The capabilities bitmask.
761 * @return String representation of the capabilities bitmask.
762 */
763 private String capabilitiesToString(int capabilities) {
764 StringBuilder sb = new StringBuilder();
765 if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) {
766 sb.append("Video ");
767 }
768 if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
769 sb.append("Presence ");
770 }
771 if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) {
772 sb.append("CallProvider ");
773 }
774 if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) {
775 sb.append("CallSubject ");
776 }
777 if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) {
778 sb.append("ConnectionMgr ");
779 }
780 if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) {
781 sb.append("EmergOnly ");
782 }
783 if (hasCapabilities(CAPABILITY_MULTI_USER)) {
784 sb.append("MultiUser ");
785 }
786 if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) {
787 sb.append("PlaceEmerg ");
788 }
Tyler Gunncee9ea62016-03-24 11:45:43 -0700789 if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
790 sb.append("EmergVideo ");
791 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800792 if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) {
793 sb.append("SimSub ");
794 }
795 return sb.toString();
796 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700797}