blob: 9480b5fc98d4c9d8a21f70db076a909d64014418 [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 /**
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 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700151 * URI scheme for telephone number URIs.
152 */
153 public static final String SCHEME_TEL = "tel";
154
155 /**
156 * URI scheme for voicemail URIs.
157 */
158 public static final String SCHEME_VOICEMAIL = "voicemail";
159
160 /**
161 * URI scheme for SIP URIs.
162 */
163 public static final String SCHEME_SIP = "sip";
164
Nancy Chen3ace54b2014-10-22 17:45:26 -0700165 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800166 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700167 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700168 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800169 public static final int NO_ICON_TINT = 0;
170
171 /**
172 * Indicating no hightlight color is set.
173 */
174 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700175
Ihab Awad476cc832014-11-03 09:47:51 -0800176 /**
177 * Indicating no resource ID is set.
178 */
179 public static final int NO_RESOURCE_ID = -1;
180
Evan Charlton8c8a0622014-07-20 12:31:00 -0700181 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700182 private final Uri mAddress;
183 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700184 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800185 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700186 private final CharSequence mLabel;
187 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700188 private final List<String> mSupportedUriSchemes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700189 private final Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700190 private final Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700191 private boolean mIsEnabled;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700192
Santos Cordon32c65a52014-10-27 14:57:49 -0700193 /**
194 * Helper class for creating a {@link PhoneAccount}.
195 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700196 public static class Builder {
197 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700198 private Uri mAddress;
199 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700200 private int mCapabilities;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800201 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700202 private CharSequence mLabel;
203 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700204 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700205 private Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700206 private Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700207 private boolean mIsEnabled = false;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700208
Santos Cordon32c65a52014-10-27 14:57:49 -0700209 /**
210 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
211 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700212 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
213 this.mAccountHandle = accountHandle;
214 this.mLabel = label;
215 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700216
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700217 /**
218 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
219 * {@link PhoneAccount}.
220 *
221 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
222 */
223 public Builder(PhoneAccount phoneAccount) {
224 mAccountHandle = phoneAccount.getAccountHandle();
225 mAddress = phoneAccount.getAddress();
226 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
227 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800228 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700229 mLabel = phoneAccount.getLabel();
230 mShortDescription = phoneAccount.getShortDescription();
231 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700232 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc02015-05-08 13:52:09 -0700233 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunnd426b202015-10-13 13:33:53 -0700234 mExtras = phoneAccount.getExtras();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700235 }
236
Santos Cordon32c65a52014-10-27 14:57:49 -0700237 /**
238 * Sets the address. See {@link PhoneAccount#getAddress}.
239 *
240 * @param value The address of the phone account.
241 * @return The builder.
242 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700243 public Builder setAddress(Uri value) {
244 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700245 return this;
246 }
247
Santos Cordon32c65a52014-10-27 14:57:49 -0700248 /**
249 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
250 *
251 * @param value The subscription address.
252 * @return The builder.
253 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700254 public Builder setSubscriptionAddress(Uri value) {
255 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700256 return this;
257 }
258
Santos Cordon32c65a52014-10-27 14:57:49 -0700259 /**
260 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
261 *
262 * @param value The capabilities to set.
263 * @return The builder.
264 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700265 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700266 this.mCapabilities = value;
267 return this;
268 }
269
Santos Cordon32c65a52014-10-27 14:57:49 -0700270 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700271 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700272 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700273 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700274 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700275 public Builder setIcon(Icon icon) {
276 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700277 return this;
278 }
279
280 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800281 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700282 *
Ihab Awad476cc832014-11-03 09:47:51 -0800283 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700284 * @return The builder.
285 */
Ihab Awad476cc832014-11-03 09:47:51 -0800286 public Builder setHighlightColor(int value) {
287 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700288 return this;
289 }
290
Santos Cordon32c65a52014-10-27 14:57:49 -0700291 /**
292 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
293 *
294 * @param value The short description.
295 * @return The builder.
296 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700297 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700298 this.mShortDescription = value;
299 return this;
300 }
301
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700302 /**
303 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
304 *
305 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700306 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700307 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700308 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700309 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
310 this.mSupportedUriSchemes.add(uriScheme);
311 }
312 return this;
313 }
314
315 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700316 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700317 *
318 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700319 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700320 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700321 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
322 mSupportedUriSchemes.clear();
323
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700324 if (uriSchemes != null && !uriSchemes.isEmpty()) {
325 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700326 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700327 }
328 }
329 return this;
330 }
331
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700332 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700333 * Specifies the extras associated with the {@link PhoneAccount}.
334 * <p>
335 * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer},
336 * and {@link Boolean}. Extras which are not of these types are ignored.
337 *
338 * @param extras
339 * @return
340 */
341 public Builder setExtras(Bundle extras) {
342 mExtras = extras;
343 return this;
344 }
345
346 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700347 * Sets the enabled state of the phone account.
348 *
349 * @param isEnabled The enabled state.
350 * @return The builder.
351 * @hide
352 */
353 public Builder setIsEnabled(boolean isEnabled) {
354 mIsEnabled = isEnabled;
355 return this;
356 }
357
358 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700359 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
360 *
361 * @return The {@link PhoneAccount}.
362 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700363 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700364 // If no supported URI schemes were defined, assume "tel" is supported.
365 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700366 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700367 }
368
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700369 return new PhoneAccount(
370 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700371 mAddress,
372 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700373 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700374 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800375 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700376 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700377 mShortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700378 mSupportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700379 mExtras,
Santos Cordon91371dc02015-05-08 13:52:09 -0700380 mIsEnabled);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700381 }
382 }
383
384 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700385 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700386 Uri address,
387 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700388 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700389 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800390 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700391 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700392 CharSequence shortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700393 List<String> supportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700394 Bundle extras,
Santos Cordon91371dc02015-05-08 13:52:09 -0700395 boolean isEnabled) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700396 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700397 mAddress = address;
398 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700399 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700400 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800401 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700402 mLabel = label;
403 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700404 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700405 mExtras = extras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700406 mIsEnabled = isEnabled;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700407 }
408
Andrew Lee3085a6c2014-09-04 10:59:13 -0700409 public static Builder builder(
410 PhoneAccountHandle accountHandle,
411 CharSequence label) {
412 return new Builder(accountHandle, label);
413 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700414
Ihab Awad807fe0a2014-07-09 12:30:52 -0700415 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700416 * Returns a builder initialized with the current {@link PhoneAccount} instance.
417 *
418 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700419 */
420 public Builder toBuilder() { return new Builder(this); }
421
422 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700423 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700424 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700425 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700426 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700427 public PhoneAccountHandle getAccountHandle() {
428 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700429 }
430
431 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700432 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700433 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700434 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700435 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700436 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700437 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700438 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700439 public Uri getAddress() {
440 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700441 }
442
443 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700444 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700445 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700446 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000447 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
448 * has been used to alter the callback number.
449 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700450 *
451 * @return The subscription number, suitable for display to the user.
452 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700453 public Uri getSubscriptionAddress() {
454 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700455 }
456
457 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700458 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700459 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700460 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700461 */
462 public int getCapabilities() {
463 return mCapabilities;
464 }
465
466 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700467 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
468 * bit mask.
469 *
470 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700471 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700472 */
473 public boolean hasCapabilities(int capability) {
474 return (mCapabilities & capability) == capability;
475 }
476
477 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700478 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700479 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700480 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700481 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700482 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700483 return mLabel;
484 }
485
486 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700487 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700488 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700489 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700490 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700491 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700492 return mShortDescription;
493 }
494
495 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700496 * The URI schemes supported by this {@code PhoneAccount}.
497 *
498 * @return The URI schemes.
499 */
500 public List<String> getSupportedUriSchemes() {
501 return mSupportedUriSchemes;
502 }
503
504 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700505 * The extras associated with this {@code PhoneAccount}.
506 * <p>
507 * A {@link ConnectionService} may provide implementation specific information about the
508 * {@link PhoneAccount} via the extras.
509 *
510 * @return The extras.
511 */
512 public Bundle getExtras() {
513 return mExtras;
514 }
515
516 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700517 * The icon to represent this {@code PhoneAccount}.
518 *
519 * @return The icon.
520 */
521 public Icon getIcon() {
522 return mIcon;
523 }
524
525 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700526 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
527 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc02015-05-08 13:52:09 -0700528 *
Santos Cordon895d4b82015-06-25 16:41:48 -0700529 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc02015-05-08 13:52:09 -0700530 */
531 public boolean isEnabled() {
532 return mIsEnabled;
533 }
534
535 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700536 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700537 * scheme.
538 *
539 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700540 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700541 * specified URI scheme.
542 */
543 public boolean supportsUriScheme(String uriScheme) {
544 if (mSupportedUriSchemes == null || uriScheme == null) {
545 return false;
546 }
547
548 for (String scheme : mSupportedUriSchemes) {
549 if (scheme != null && scheme.equals(uriScheme)) {
550 return true;
551 }
552 }
553 return false;
554 }
555
556 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800557 * A highlight color to use in displaying information about this {@code PhoneAccount}.
558 *
559 * @return A hexadecimal color value.
560 */
561 public int getHighlightColor() {
562 return mHighlightColor;
563 }
564
Santos Cordon91371dc02015-05-08 13:52:09 -0700565 /**
566 * Sets the enabled state of the phone account.
567 * @hide
568 */
569 public void setIsEnabled(boolean isEnabled) {
570 mIsEnabled = isEnabled;
571 }
572
Ihab Awad807fe0a2014-07-09 12:30:52 -0700573 //
574 // Parcelable implementation
575 //
576
577 @Override
578 public int describeContents() {
579 return 0;
580 }
581
582 @Override
583 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800584 if (mAccountHandle == null) {
585 out.writeInt(0);
586 } else {
587 out.writeInt(1);
588 mAccountHandle.writeToParcel(out, flags);
589 }
590 if (mAddress == null) {
591 out.writeInt(0);
592 } else {
593 out.writeInt(1);
594 mAddress.writeToParcel(out, flags);
595 }
596 if (mSubscriptionAddress == null) {
597 out.writeInt(0);
598 } else {
599 out.writeInt(1);
600 mSubscriptionAddress.writeToParcel(out, flags);
601 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700602 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800603 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700604 out.writeCharSequence(mLabel);
605 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800606 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc02015-05-08 13:52:09 -0700607
Santos Cordoncad84a22015-05-13 11:17:25 -0700608 if (mIcon == null) {
609 out.writeInt(0);
610 } else {
611 out.writeInt(1);
612 mIcon.writeToParcel(out, flags);
613 }
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700614
615 out.writeBundle(mExtras);
Santos Cordon91371dc02015-05-08 13:52:09 -0700616 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Ihab Awad807fe0a2014-07-09 12:30:52 -0700617 }
618
Evan Charlton8c8a0622014-07-20 12:31:00 -0700619 public static final Creator<PhoneAccount> CREATOR
620 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700621 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700622 public PhoneAccount createFromParcel(Parcel in) {
623 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700624 }
625
626 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700627 public PhoneAccount[] newArray(int size) {
628 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700629 }
630 };
631
Evan Charlton8c8a0622014-07-20 12:31:00 -0700632 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800633 if (in.readInt() > 0) {
634 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
635 } else {
636 mAccountHandle = null;
637 }
638 if (in.readInt() > 0) {
639 mAddress = Uri.CREATOR.createFromParcel(in);
640 } else {
641 mAddress = null;
642 }
643 if (in.readInt() > 0) {
644 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
645 } else {
646 mSubscriptionAddress = null;
647 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700648 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -0800649 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700650 mLabel = in.readCharSequence();
651 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800652 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -0700653 if (in.readInt() > 0) {
654 mIcon = Icon.CREATOR.createFromParcel(in);
655 } else {
656 mIcon = null;
657 }
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700658 mExtras = in.readBundle();
Santos Cordon91371dc02015-05-08 13:52:09 -0700659 mIsEnabled = in.readByte() == 1;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700660 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700661
662 @Override
663 public String toString() {
Santos Cordon91371dc02015-05-08 13:52:09 -0700664 StringBuilder sb = new StringBuilder().append("[[")
665 .append(mIsEnabled ? 'X' : ' ')
666 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700667 .append(mAccountHandle)
668 .append(" Capabilities: ")
669 .append(mCapabilities)
670 .append(" Schemes: ");
671 for (String scheme : mSupportedUriSchemes) {
672 sb.append(scheme)
673 .append(" ");
674 }
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700675 sb.append(" Extras : ");
676 sb.append(mExtras);
Tyler Gunn76c01a52014-09-30 14:47:51 -0700677 sb.append("]");
678 return sb.toString();
679 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700680}