blob: dbc2b0c9f85058100511297f44faf46ca7e948a7 [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;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700223
Santos Cordon32c65a52014-10-27 14:57:49 -0700224 /**
225 * Helper class for creating a {@link PhoneAccount}.
226 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700227 public static class Builder {
228 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700229 private Uri mAddress;
230 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700231 private int mCapabilities;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800232 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700233 private CharSequence mLabel;
234 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700235 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700236 private Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700237 private Bundle mExtras;
Santos Cordon91371dc2015-05-08 13:52:09 -0700238 private boolean mIsEnabled = false;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700239
Santos Cordon32c65a52014-10-27 14:57:49 -0700240 /**
241 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
242 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700243 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
244 this.mAccountHandle = accountHandle;
245 this.mLabel = label;
246 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700247
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700248 /**
249 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
250 * {@link PhoneAccount}.
251 *
252 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
253 */
254 public Builder(PhoneAccount phoneAccount) {
255 mAccountHandle = phoneAccount.getAccountHandle();
256 mAddress = phoneAccount.getAddress();
257 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
258 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800259 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700260 mLabel = phoneAccount.getLabel();
261 mShortDescription = phoneAccount.getShortDescription();
262 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700263 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc2015-05-08 13:52:09 -0700264 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunnd426b202015-10-13 13:33:53 -0700265 mExtras = phoneAccount.getExtras();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700266 }
267
Santos Cordon32c65a52014-10-27 14:57:49 -0700268 /**
269 * Sets the address. See {@link PhoneAccount#getAddress}.
270 *
271 * @param value The address of the phone account.
272 * @return The builder.
273 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700274 public Builder setAddress(Uri value) {
275 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700276 return this;
277 }
278
Santos Cordon32c65a52014-10-27 14:57:49 -0700279 /**
280 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
281 *
282 * @param value The subscription address.
283 * @return The builder.
284 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700285 public Builder setSubscriptionAddress(Uri value) {
286 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700287 return this;
288 }
289
Santos Cordon32c65a52014-10-27 14:57:49 -0700290 /**
291 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
292 *
293 * @param value The capabilities to set.
294 * @return The builder.
295 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700296 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700297 this.mCapabilities = value;
298 return this;
299 }
300
Santos Cordon32c65a52014-10-27 14:57:49 -0700301 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700302 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700303 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700304 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700305 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700306 public Builder setIcon(Icon icon) {
307 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700308 return this;
309 }
310
311 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800312 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700313 *
Ihab Awad476cc832014-11-03 09:47:51 -0800314 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700315 * @return The builder.
316 */
Ihab Awad476cc832014-11-03 09:47:51 -0800317 public Builder setHighlightColor(int value) {
318 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700319 return this;
320 }
321
Santos Cordon32c65a52014-10-27 14:57:49 -0700322 /**
323 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
324 *
325 * @param value The short description.
326 * @return The builder.
327 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700328 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700329 this.mShortDescription = value;
330 return this;
331 }
332
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700333 /**
334 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
335 *
336 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700337 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700338 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700339 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700340 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
341 this.mSupportedUriSchemes.add(uriScheme);
342 }
343 return this;
344 }
345
346 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700347 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700348 *
349 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700350 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700351 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700352 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
353 mSupportedUriSchemes.clear();
354
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700355 if (uriSchemes != null && !uriSchemes.isEmpty()) {
356 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700357 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700358 }
359 }
360 return this;
361 }
362
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700363 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700364 * Specifies the extras associated with the {@link PhoneAccount}.
365 * <p>
366 * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer},
367 * and {@link Boolean}. Extras which are not of these types are ignored.
368 *
369 * @param extras
370 * @return
371 */
372 public Builder setExtras(Bundle extras) {
373 mExtras = extras;
374 return this;
375 }
376
377 /**
Santos Cordon91371dc2015-05-08 13:52:09 -0700378 * Sets the enabled state of the phone account.
379 *
380 * @param isEnabled The enabled state.
381 * @return The builder.
382 * @hide
383 */
384 public Builder setIsEnabled(boolean isEnabled) {
385 mIsEnabled = isEnabled;
386 return this;
387 }
388
389 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700390 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
391 *
392 * @return The {@link PhoneAccount}.
393 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700394 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700395 // If no supported URI schemes were defined, assume "tel" is supported.
396 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700397 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700398 }
399
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700400 return new PhoneAccount(
401 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700402 mAddress,
403 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700404 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700405 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800406 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700407 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700408 mShortDescription,
Santos Cordon91371dc2015-05-08 13:52:09 -0700409 mSupportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700410 mExtras,
Santos Cordon91371dc2015-05-08 13:52:09 -0700411 mIsEnabled);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700412 }
413 }
414
415 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700416 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700417 Uri address,
418 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700419 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700420 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800421 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700422 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700423 CharSequence shortDescription,
Santos Cordon91371dc2015-05-08 13:52:09 -0700424 List<String> supportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700425 Bundle extras,
Santos Cordon91371dc2015-05-08 13:52:09 -0700426 boolean isEnabled) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700427 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700428 mAddress = address;
429 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700430 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700431 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800432 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700433 mLabel = label;
434 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700435 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700436 mExtras = extras;
Santos Cordon91371dc2015-05-08 13:52:09 -0700437 mIsEnabled = isEnabled;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700438 }
439
Andrew Lee3085a6c2014-09-04 10:59:13 -0700440 public static Builder builder(
441 PhoneAccountHandle accountHandle,
442 CharSequence label) {
443 return new Builder(accountHandle, label);
444 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700445
Ihab Awad807fe0a2014-07-09 12:30:52 -0700446 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700447 * Returns a builder initialized with the current {@link PhoneAccount} instance.
448 *
449 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700450 */
451 public Builder toBuilder() { return new Builder(this); }
452
453 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700454 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700455 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700456 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700457 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700458 public PhoneAccountHandle getAccountHandle() {
459 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700460 }
461
462 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700463 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700464 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700465 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700466 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700467 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700468 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700469 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700470 public Uri getAddress() {
471 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700472 }
473
474 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700475 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700476 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700477 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000478 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
479 * has been used to alter the callback number.
480 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700481 *
482 * @return The subscription number, suitable for display to the user.
483 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700484 public Uri getSubscriptionAddress() {
485 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700486 }
487
488 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700489 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700490 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700491 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700492 */
493 public int getCapabilities() {
494 return mCapabilities;
495 }
496
497 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700498 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
499 * bit mask.
500 *
501 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700502 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700503 */
504 public boolean hasCapabilities(int capability) {
505 return (mCapabilities & capability) == capability;
506 }
507
508 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700509 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700510 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700511 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700512 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700513 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700514 return mLabel;
515 }
516
517 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700518 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700519 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700520 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700521 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700522 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700523 return mShortDescription;
524 }
525
526 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700527 * The URI schemes supported by this {@code PhoneAccount}.
528 *
529 * @return The URI schemes.
530 */
531 public List<String> getSupportedUriSchemes() {
532 return mSupportedUriSchemes;
533 }
534
535 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700536 * The extras associated with this {@code PhoneAccount}.
537 * <p>
538 * A {@link ConnectionService} may provide implementation specific information about the
539 * {@link PhoneAccount} via the extras.
540 *
541 * @return The extras.
542 */
543 public Bundle getExtras() {
544 return mExtras;
545 }
546
547 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700548 * The icon to represent this {@code PhoneAccount}.
549 *
550 * @return The icon.
551 */
552 public Icon getIcon() {
553 return mIcon;
554 }
555
556 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700557 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
558 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc2015-05-08 13:52:09 -0700559 *
Santos Cordon895d4b82015-06-25 16:41:48 -0700560 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc2015-05-08 13:52:09 -0700561 */
562 public boolean isEnabled() {
563 return mIsEnabled;
564 }
565
566 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700567 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700568 * scheme.
569 *
570 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700571 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700572 * specified URI scheme.
573 */
574 public boolean supportsUriScheme(String uriScheme) {
575 if (mSupportedUriSchemes == null || uriScheme == null) {
576 return false;
577 }
578
579 for (String scheme : mSupportedUriSchemes) {
580 if (scheme != null && scheme.equals(uriScheme)) {
581 return true;
582 }
583 }
584 return false;
585 }
586
587 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800588 * A highlight color to use in displaying information about this {@code PhoneAccount}.
589 *
590 * @return A hexadecimal color value.
591 */
592 public int getHighlightColor() {
593 return mHighlightColor;
594 }
595
Santos Cordon91371dc2015-05-08 13:52:09 -0700596 /**
597 * Sets the enabled state of the phone account.
598 * @hide
599 */
600 public void setIsEnabled(boolean isEnabled) {
601 mIsEnabled = isEnabled;
602 }
603
Ihab Awad807fe0a2014-07-09 12:30:52 -0700604 //
605 // Parcelable implementation
606 //
607
608 @Override
609 public int describeContents() {
610 return 0;
611 }
612
613 @Override
614 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800615 if (mAccountHandle == null) {
616 out.writeInt(0);
617 } else {
618 out.writeInt(1);
619 mAccountHandle.writeToParcel(out, flags);
620 }
621 if (mAddress == null) {
622 out.writeInt(0);
623 } else {
624 out.writeInt(1);
625 mAddress.writeToParcel(out, flags);
626 }
627 if (mSubscriptionAddress == null) {
628 out.writeInt(0);
629 } else {
630 out.writeInt(1);
631 mSubscriptionAddress.writeToParcel(out, flags);
632 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700633 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800634 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700635 out.writeCharSequence(mLabel);
636 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800637 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc2015-05-08 13:52:09 -0700638
Santos Cordoncad84a22015-05-13 11:17:25 -0700639 if (mIcon == null) {
640 out.writeInt(0);
641 } else {
642 out.writeInt(1);
643 mIcon.writeToParcel(out, flags);
644 }
Santos Cordon91371dc2015-05-08 13:52:09 -0700645 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Tyler Gunnef829ec2015-10-08 09:46:23 -0700646 out.writeBundle(mExtras);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700647 }
648
Evan Charlton8c8a0622014-07-20 12:31:00 -0700649 public static final Creator<PhoneAccount> CREATOR
650 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700651 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700652 public PhoneAccount createFromParcel(Parcel in) {
653 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700654 }
655
656 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700657 public PhoneAccount[] newArray(int size) {
658 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700659 }
660 };
661
Evan Charlton8c8a0622014-07-20 12:31:00 -0700662 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800663 if (in.readInt() > 0) {
664 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
665 } else {
666 mAccountHandle = null;
667 }
668 if (in.readInt() > 0) {
669 mAddress = Uri.CREATOR.createFromParcel(in);
670 } else {
671 mAddress = null;
672 }
673 if (in.readInt() > 0) {
674 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
675 } else {
676 mSubscriptionAddress = null;
677 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700678 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -0800679 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700680 mLabel = in.readCharSequence();
681 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800682 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -0700683 if (in.readInt() > 0) {
684 mIcon = Icon.CREATOR.createFromParcel(in);
685 } else {
686 mIcon = null;
687 }
Santos Cordon91371dc2015-05-08 13:52:09 -0700688 mIsEnabled = in.readByte() == 1;
Tyler Gunnef829ec2015-10-08 09:46:23 -0700689 mExtras = in.readBundle();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700690 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700691
692 @Override
693 public String toString() {
Santos Cordon91371dc2015-05-08 13:52:09 -0700694 StringBuilder sb = new StringBuilder().append("[[")
695 .append(mIsEnabled ? 'X' : ' ')
696 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700697 .append(mAccountHandle)
698 .append(" Capabilities: ")
Tyler Gunn3e122f72016-01-11 19:25:00 -0800699 .append(capabilitiesToString(mCapabilities))
Tyler Gunn76c01a52014-09-30 14:47:51 -0700700 .append(" Schemes: ");
701 for (String scheme : mSupportedUriSchemes) {
702 sb.append(scheme)
703 .append(" ");
704 }
Tyler Gunnef829ec2015-10-08 09:46:23 -0700705 sb.append(" Extras: ");
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700706 sb.append(mExtras);
Tyler Gunn76c01a52014-09-30 14:47:51 -0700707 sb.append("]");
708 return sb.toString();
709 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800710
711 /**
712 * Generates a string representation of a capabilities bitmask.
713 *
714 * @param capabilities The capabilities bitmask.
715 * @return String representation of the capabilities bitmask.
716 */
717 private String capabilitiesToString(int capabilities) {
718 StringBuilder sb = new StringBuilder();
719 if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) {
720 sb.append("Video ");
721 }
722 if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
723 sb.append("Presence ");
724 }
725 if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) {
726 sb.append("CallProvider ");
727 }
728 if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) {
729 sb.append("CallSubject ");
730 }
731 if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) {
732 sb.append("ConnectionMgr ");
733 }
734 if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) {
735 sb.append("EmergOnly ");
736 }
737 if (hasCapabilities(CAPABILITY_MULTI_USER)) {
738 sb.append("MultiUser ");
739 }
740 if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) {
741 sb.append("PlaceEmerg ");
742 }
Tyler Gunncee9ea62016-03-24 11:45:43 -0700743 if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
744 sb.append("EmergVideo ");
745 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800746 if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) {
747 sb.append("SimSub ");
748 }
749 return sb.toString();
750 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700751}