blob: 0457d6372d8bd936b5b5d17ff614f7b2a50ebf6b [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 Awad7522bbd62014-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 Awad7522bbd62014-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 Awad7522bbd62014-07-18 15:53:17 -0700113 */
114 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
115
Ihab Awadf8b69882014-07-25 15:14:01 -0700116 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800117 * Flag indicating that this {@code PhoneAccount} is currently able to place video calls.
118 * <p>
119 * See also {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING} which indicates whether the
120 * {@code PhoneAccount} supports placing video calls.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700121 * <p>
122 * See {@link #getCapabilities}
Ihab Awadf8b69882014-07-25 15:14:01 -0700123 */
124 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
125
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700126 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700127 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
128 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
129 * <p>
130 * See {@link #getCapabilities}
131 */
132 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
133
134 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800135 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
136 * should only be used by system apps (and will be ignored for all other apps trying to use it).
137 * <p>
138 * See {@link #getCapabilities}
139 * @hide
140 */
Brian Attwellad147f42014-12-19 11:37:16 -0800141 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800142 public static final int CAPABILITY_MULTI_USER = 0x20;
143
144 /**
Tyler Gunn65a3d342015-07-27 16:06:16 -0700145 * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a
146 * caller is able to specify a short subject line for an outgoing call. A capable receiving
147 * device displays the call subject on the incoming call screen.
148 * <p>
149 * See {@link #getCapabilities}
150 */
151 public static final int CAPABILITY_CALL_SUBJECT = 0x40;
152
153 /**
Bryce Leeb96d89c2015-10-14 16:48:40 -0700154 * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls.
155 * <p>
156 * See {@link #getCapabilities}
157 * @hide
158 */
159 public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80;
160
161 /**
Tyler Gunn9a365752015-12-09 15:00:18 -0800162 * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a
163 * number relies on presence. Should only be set if the {@code PhoneAccount} also has
164 * {@link #CAPABILITY_VIDEO_CALLING}.
165 * <p>
166 * When set, the {@link ConnectionService} is responsible for toggling the
167 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the
168 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether
169 * a contact's phone number supports video calling.
170 * <p>
171 * See {@link #getCapabilities}
172 */
173 public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100;
174
175 /**
Tyler Gunncee9ea62016-03-24 11:45:43 -0700176 * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed.
177 * <p>
178 * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will
179 * convert all outgoing video calls to emergency numbers to audio-only.
180 * @hide
181 */
182 public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200;
183
184 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800185 * Flag indicating that this {@link PhoneAccount} supports video calling.
186 * This is not an indication that the {@link PhoneAccount} is currently able to make a video
187 * call, but rather that it has the ability to make video calls (but not necessarily at this
188 * time).
189 * <p>
190 * Whether a {@link PhoneAccount} can make a video call is ultimately controlled by
191 * {@link #CAPABILITY_VIDEO_CALLING}, which indicates whether the {@link PhoneAccount} is
192 * currently capable of making a video call. Consider a case where, for example, a
193 * {@link PhoneAccount} supports making video calls (e.g.
194 * {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING}), but a current lack of network connectivity
195 * prevents video calls from being made (e.g. {@link #CAPABILITY_VIDEO_CALLING}).
196 * <p>
197 * See {@link #getCapabilities}
198 */
199 public static final int CAPABILITY_SUPPORTS_VIDEO_CALLING = 0x400;
200
201 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700202 * URI scheme for telephone number URIs.
203 */
204 public static final String SCHEME_TEL = "tel";
205
206 /**
207 * URI scheme for voicemail URIs.
208 */
209 public static final String SCHEME_VOICEMAIL = "voicemail";
210
211 /**
212 * URI scheme for SIP URIs.
213 */
214 public static final String SCHEME_SIP = "sip";
215
Nancy Chen3ace54b2014-10-22 17:45:26 -0700216 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800217 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700218 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700219 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800220 public static final int NO_ICON_TINT = 0;
221
222 /**
223 * Indicating no hightlight color is set.
224 */
225 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700226
Ihab Awad476cc832014-11-03 09:47:51 -0800227 /**
228 * Indicating no resource ID is set.
229 */
230 public static final int NO_RESOURCE_ID = -1;
231
Evan Charlton8c8a0622014-07-20 12:31:00 -0700232 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700233 private final Uri mAddress;
234 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700235 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800236 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700237 private final CharSequence mLabel;
238 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700239 private final List<String> mSupportedUriSchemes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700240 private final Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700241 private final Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700242 private boolean mIsEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700243 private String mGroupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700244
Santos Cordon32c65a52014-10-27 14:57:49 -0700245 /**
246 * Helper class for creating a {@link PhoneAccount}.
247 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700248 public static class Builder {
249 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700250 private Uri mAddress;
251 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700252 private int mCapabilities;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800253 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700254 private CharSequence mLabel;
255 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700256 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700257 private Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700258 private Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700259 private boolean mIsEnabled = false;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700260 private String mGroupId = "";
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700261
Santos Cordon32c65a52014-10-27 14:57:49 -0700262 /**
263 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
264 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700265 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
266 this.mAccountHandle = accountHandle;
267 this.mLabel = label;
268 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700269
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700270 /**
271 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
272 * {@link PhoneAccount}.
273 *
274 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
275 */
276 public Builder(PhoneAccount phoneAccount) {
277 mAccountHandle = phoneAccount.getAccountHandle();
278 mAddress = phoneAccount.getAddress();
279 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
280 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800281 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700282 mLabel = phoneAccount.getLabel();
283 mShortDescription = phoneAccount.getShortDescription();
284 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700285 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc02015-05-08 13:52:09 -0700286 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunnd426b202015-10-13 13:33:53 -0700287 mExtras = phoneAccount.getExtras();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700288 mGroupId = phoneAccount.getGroupId();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700289 }
290
Santos Cordon32c65a52014-10-27 14:57:49 -0700291 /**
292 * Sets the address. See {@link PhoneAccount#getAddress}.
293 *
294 * @param value The address of the phone account.
295 * @return The builder.
296 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700297 public Builder setAddress(Uri value) {
298 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700299 return this;
300 }
301
Santos Cordon32c65a52014-10-27 14:57:49 -0700302 /**
303 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
304 *
305 * @param value The subscription address.
306 * @return The builder.
307 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700308 public Builder setSubscriptionAddress(Uri value) {
309 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700310 return this;
311 }
312
Santos Cordon32c65a52014-10-27 14:57:49 -0700313 /**
314 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
315 *
316 * @param value The capabilities to set.
317 * @return The builder.
318 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700319 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700320 this.mCapabilities = value;
321 return this;
322 }
323
Santos Cordon32c65a52014-10-27 14:57:49 -0700324 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700325 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700326 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700327 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700328 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700329 public Builder setIcon(Icon icon) {
330 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700331 return this;
332 }
333
334 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800335 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700336 *
Ihab Awad476cc832014-11-03 09:47:51 -0800337 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700338 * @return The builder.
339 */
Ihab Awad476cc832014-11-03 09:47:51 -0800340 public Builder setHighlightColor(int value) {
341 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700342 return this;
343 }
344
Santos Cordon32c65a52014-10-27 14:57:49 -0700345 /**
346 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
347 *
348 * @param value The short description.
349 * @return The builder.
350 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700351 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700352 this.mShortDescription = value;
353 return this;
354 }
355
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700356 /**
357 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
358 *
359 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700360 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700361 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700362 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700363 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
364 this.mSupportedUriSchemes.add(uriScheme);
365 }
366 return this;
367 }
368
369 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700370 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700371 *
372 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700373 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700374 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700375 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
376 mSupportedUriSchemes.clear();
377
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700378 if (uriSchemes != null && !uriSchemes.isEmpty()) {
379 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700380 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700381 }
382 }
383 return this;
384 }
385
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700386 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700387 * Specifies the extras associated with the {@link PhoneAccount}.
388 * <p>
389 * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer},
390 * and {@link Boolean}. Extras which are not of these types are ignored.
391 *
392 * @param extras
393 * @return
394 */
395 public Builder setExtras(Bundle extras) {
396 mExtras = extras;
397 return this;
398 }
399
400 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700401 * Sets the enabled state of the phone account.
402 *
403 * @param isEnabled The enabled state.
404 * @return The builder.
405 * @hide
406 */
407 public Builder setIsEnabled(boolean isEnabled) {
408 mIsEnabled = isEnabled;
409 return this;
410 }
411
412 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700413 * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is
414 * registered to Telecom, it will replace another {@link PhoneAccount} that is already
415 * registered in Telecom and take on the current user defaults and enabled status. There can
416 * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a
417 * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only
418 * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced.
419 * @param groupId The group Id of the {@link PhoneAccount} that will replace any other
420 * registered {@link PhoneAccount} in Telecom with the same Group Id.
421 * @return The builder
422 * @hide
423 */
424 public Builder setGroupId(String groupId) {
425 if (groupId != null) {
426 mGroupId = groupId;
427 } else {
428 mGroupId = "";
429 }
430 return this;
431 }
432
433 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700434 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
435 *
436 * @return The {@link PhoneAccount}.
437 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700438 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700439 // If no supported URI schemes were defined, assume "tel" is supported.
440 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700441 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700442 }
443
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700444 return new PhoneAccount(
445 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700446 mAddress,
447 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700448 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700449 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800450 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700451 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700452 mShortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700453 mSupportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700454 mExtras,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700455 mIsEnabled,
456 mGroupId);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700457 }
458 }
459
460 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700461 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700462 Uri address,
463 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700464 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700465 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800466 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700467 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700468 CharSequence shortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700469 List<String> supportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700470 Bundle extras,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700471 boolean isEnabled,
472 String groupId) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700473 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700474 mAddress = address;
475 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700476 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700477 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800478 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700479 mLabel = label;
480 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700481 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700482 mExtras = extras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700483 mIsEnabled = isEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700484 mGroupId = groupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700485 }
486
Andrew Lee3085a6c2014-09-04 10:59:13 -0700487 public static Builder builder(
488 PhoneAccountHandle accountHandle,
489 CharSequence label) {
490 return new Builder(accountHandle, label);
491 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700492
Ihab Awad807fe0a2014-07-09 12:30:52 -0700493 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700494 * Returns a builder initialized with the current {@link PhoneAccount} instance.
495 *
496 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700497 */
498 public Builder toBuilder() { return new Builder(this); }
499
500 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700501 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700502 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700503 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700504 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700505 public PhoneAccountHandle getAccountHandle() {
506 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700507 }
508
509 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700510 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700511 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700512 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700513 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700514 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700515 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700516 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700517 public Uri getAddress() {
518 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700519 }
520
521 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700522 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700523 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700524 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000525 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
526 * has been used to alter the callback number.
527 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700528 *
529 * @return The subscription number, suitable for display to the user.
530 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700531 public Uri getSubscriptionAddress() {
532 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700533 }
534
535 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700536 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700537 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700538 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700539 */
540 public int getCapabilities() {
541 return mCapabilities;
542 }
543
544 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700545 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
546 * bit mask.
547 *
548 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700549 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700550 */
551 public boolean hasCapabilities(int capability) {
552 return (mCapabilities & capability) == capability;
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 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700595 * The icon to represent this {@code PhoneAccount}.
596 *
597 * @return The icon.
598 */
599 public Icon getIcon() {
600 return mIcon;
601 }
602
603 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700604 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
605 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc02015-05-08 13:52:09 -0700606 *
Santos Cordon895d4b82015-06-25 16:41:48 -0700607 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc02015-05-08 13:52:09 -0700608 */
609 public boolean isEnabled() {
610 return mIsEnabled;
611 }
612
613 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700614 * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an
615 * empty {@link String} if the {@link PhoneAccount} is not in a group. If this
616 * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered
617 * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced,
618 * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}.
619 * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced.
620 *
621 * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group.
622 * @hide
623 */
624 public String getGroupId() {
625 return mGroupId;
626 }
627
628 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700629 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700630 * scheme.
631 *
632 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700633 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700634 * specified URI scheme.
635 */
636 public boolean supportsUriScheme(String uriScheme) {
637 if (mSupportedUriSchemes == null || uriScheme == null) {
638 return false;
639 }
640
641 for (String scheme : mSupportedUriSchemes) {
642 if (scheme != null && scheme.equals(uriScheme)) {
643 return true;
644 }
645 }
646 return false;
647 }
648
649 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800650 * A highlight color to use in displaying information about this {@code PhoneAccount}.
651 *
652 * @return A hexadecimal color value.
653 */
654 public int getHighlightColor() {
655 return mHighlightColor;
656 }
657
Santos Cordon91371dc02015-05-08 13:52:09 -0700658 /**
659 * Sets the enabled state of the phone account.
660 * @hide
661 */
662 public void setIsEnabled(boolean isEnabled) {
663 mIsEnabled = isEnabled;
664 }
665
Ihab Awad807fe0a2014-07-09 12:30:52 -0700666 //
667 // Parcelable implementation
668 //
669
670 @Override
671 public int describeContents() {
672 return 0;
673 }
674
675 @Override
676 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800677 if (mAccountHandle == null) {
678 out.writeInt(0);
679 } else {
680 out.writeInt(1);
681 mAccountHandle.writeToParcel(out, flags);
682 }
683 if (mAddress == null) {
684 out.writeInt(0);
685 } else {
686 out.writeInt(1);
687 mAddress.writeToParcel(out, flags);
688 }
689 if (mSubscriptionAddress == null) {
690 out.writeInt(0);
691 } else {
692 out.writeInt(1);
693 mSubscriptionAddress.writeToParcel(out, flags);
694 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700695 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800696 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700697 out.writeCharSequence(mLabel);
698 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800699 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc02015-05-08 13:52:09 -0700700
Santos Cordoncad84a22015-05-13 11:17:25 -0700701 if (mIcon == null) {
702 out.writeInt(0);
703 } else {
704 out.writeInt(1);
705 mIcon.writeToParcel(out, flags);
706 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700707 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Tyler Gunnef829ec2015-10-08 09:46:23 -0700708 out.writeBundle(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700709 out.writeString(mGroupId);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700710 }
711
Evan Charlton8c8a0622014-07-20 12:31:00 -0700712 public static final Creator<PhoneAccount> CREATOR
713 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700714 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700715 public PhoneAccount createFromParcel(Parcel in) {
716 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700717 }
718
719 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700720 public PhoneAccount[] newArray(int size) {
721 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700722 }
723 };
724
Evan Charlton8c8a0622014-07-20 12:31:00 -0700725 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800726 if (in.readInt() > 0) {
727 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
728 } else {
729 mAccountHandle = null;
730 }
731 if (in.readInt() > 0) {
732 mAddress = Uri.CREATOR.createFromParcel(in);
733 } else {
734 mAddress = null;
735 }
736 if (in.readInt() > 0) {
737 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
738 } else {
739 mSubscriptionAddress = null;
740 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700741 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -0800742 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700743 mLabel = in.readCharSequence();
744 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800745 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -0700746 if (in.readInt() > 0) {
747 mIcon = Icon.CREATOR.createFromParcel(in);
748 } else {
749 mIcon = null;
750 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700751 mIsEnabled = in.readByte() == 1;
Tyler Gunnef829ec2015-10-08 09:46:23 -0700752 mExtras = in.readBundle();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700753 mGroupId = in.readString();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700754 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700755
756 @Override
757 public String toString() {
Santos Cordon91371dc02015-05-08 13:52:09 -0700758 StringBuilder sb = new StringBuilder().append("[[")
759 .append(mIsEnabled ? 'X' : ' ')
760 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700761 .append(mAccountHandle)
762 .append(" Capabilities: ")
Tyler Gunn3e122f72016-01-11 19:25:00 -0800763 .append(capabilitiesToString(mCapabilities))
Tyler Gunn76c01a52014-09-30 14:47:51 -0700764 .append(" Schemes: ");
765 for (String scheme : mSupportedUriSchemes) {
766 sb.append(scheme)
767 .append(" ");
768 }
Tyler Gunnef829ec2015-10-08 09:46:23 -0700769 sb.append(" Extras: ");
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700770 sb.append(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700771 sb.append(" GroupId: ");
772 sb.append(Log.pii(mGroupId));
Tyler Gunn76c01a52014-09-30 14:47:51 -0700773 sb.append("]");
774 return sb.toString();
775 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800776
777 /**
778 * Generates a string representation of a capabilities bitmask.
779 *
780 * @param capabilities The capabilities bitmask.
781 * @return String representation of the capabilities bitmask.
782 */
783 private String capabilitiesToString(int capabilities) {
784 StringBuilder sb = new StringBuilder();
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800785 if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) {
786 sb.append("SuppVideo ");
787 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800788 if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) {
789 sb.append("Video ");
790 }
791 if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
792 sb.append("Presence ");
793 }
794 if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) {
795 sb.append("CallProvider ");
796 }
797 if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) {
798 sb.append("CallSubject ");
799 }
800 if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) {
801 sb.append("ConnectionMgr ");
802 }
803 if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) {
804 sb.append("EmergOnly ");
805 }
806 if (hasCapabilities(CAPABILITY_MULTI_USER)) {
807 sb.append("MultiUser ");
808 }
809 if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) {
810 sb.append("PlaceEmerg ");
811 }
Tyler Gunncee9ea62016-03-24 11:45:43 -0700812 if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
813 sb.append("EmergVideo ");
814 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800815 if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) {
816 sb.append("SimSub ");
817 }
818 return sb.toString();
819 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700820}