blob: a25d327baf54504017c2dbcbbcdf9e48c573426f [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;
Ihab Awad807fe0a2014-07-09 12:30:52 -070031import android.os.Parcel;
32import android.os.Parcelable;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070033import android.text.TextUtils;
Ihab Awad807fe0a2014-07-09 12:30:52 -070034
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070035import java.lang.String;
36import java.util.ArrayList;
37import java.util.Collections;
38import java.util.List;
Ihab Awad807fe0a2014-07-09 12:30:52 -070039import java.util.MissingResourceException;
40
41/**
Santos Cordon32c65a52014-10-27 14:57:49 -070042 * Represents a distinct method to place or receive a phone call. Apps which can place calls and
43 * 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 -080044 * this class and register it with the system using {@link TelecomManager}.
Santos Cordon32c65a52014-10-27 14:57:49 -070045 * <p>
46 * {@link TelecomManager} uses registered {@link PhoneAccount}s to present the user with
47 * alternative options when placing a phone call. When building a {@link PhoneAccount}, the app
Brian Attwellad147f42014-12-19 11:37:16 -080048 * should supply a valid {@link PhoneAccountHandle} that references the connection service
Santos Cordon32c65a52014-10-27 14:57:49 -070049 * implementation Telecom will use to interact with the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -070050 */
Yorke Lee400470f2015-05-12 13:31:25 -070051public final class PhoneAccount implements Parcelable {
Ihab Awad94cf4bf2014-07-17 11:21:19 -070052
53 /**
Ihab Awadf8b69882014-07-25 15:14:01 -070054 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
55 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
56 * will be allowed to manage phone calls including using its own proprietary phone-call
57 * implementation (like VoIP calling) to make calls instead of the telephony stack.
58 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -070059 * When a user opts to place a call using the SIM-based telephony stack, the
60 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
61 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -070062 * <p>
63 * See {@link #getCapabilities}
64 */
Ihab Awadf8b69882014-07-25 15:14:01 -070065 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070066
67 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -070068 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -070069 * traditional SIM-based telephony calls. This account will be treated as a distinct method
70 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -070071 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -070072 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -070073 * <p>
74 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -070075 * <p>
Ihab Awad94cf4bf2014-07-17 11:21:19 -070076 */
77 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
78
Ihab Awad7522bbd62014-07-18 15:53:17 -070079 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070080 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -070081 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -070082 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -070083 * Only the Android framework can register a {@code PhoneAccount} having this capability.
84 * <p>
85 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -070086 */
87 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
88
Ihab Awadf8b69882014-07-25 15:14:01 -070089 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070090 * Flag indicating that this {@code PhoneAccount} is capable of placing video calls.
91 * <p>
92 * See {@link #getCapabilities}
Ihab Awadf8b69882014-07-25 15:14:01 -070093 */
94 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
95
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070096 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -070097 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
98 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
99 * <p>
100 * See {@link #getCapabilities}
101 */
102 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
103
104 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800105 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
106 * should only be used by system apps (and will be ignored for all other apps trying to use it).
107 * <p>
108 * See {@link #getCapabilities}
109 * @hide
110 */
Brian Attwellad147f42014-12-19 11:37:16 -0800111 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800112 public static final int CAPABILITY_MULTI_USER = 0x20;
113
114 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700115 * URI scheme for telephone number URIs.
116 */
117 public static final String SCHEME_TEL = "tel";
118
119 /**
120 * URI scheme for voicemail URIs.
121 */
122 public static final String SCHEME_VOICEMAIL = "voicemail";
123
124 /**
125 * URI scheme for SIP URIs.
126 */
127 public static final String SCHEME_SIP = "sip";
128
Nancy Chen3ace54b2014-10-22 17:45:26 -0700129 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800130 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700131 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700132 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800133 public static final int NO_ICON_TINT = 0;
134
135 /**
136 * Indicating no hightlight color is set.
137 */
138 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700139
Ihab Awad476cc832014-11-03 09:47:51 -0800140 /**
141 * Indicating no resource ID is set.
142 */
143 public static final int NO_RESOURCE_ID = -1;
144
Evan Charlton8c8a0622014-07-20 12:31:00 -0700145 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700146 private final Uri mAddress;
147 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700148 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800149 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700150 private final CharSequence mLabel;
151 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700152 private final List<String> mSupportedUriSchemes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700153 private final Icon mIcon;
Santos Cordon91371dc02015-05-08 13:52:09 -0700154 private boolean mIsEnabled;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700155
Santos Cordon32c65a52014-10-27 14:57:49 -0700156 /**
157 * Helper class for creating a {@link PhoneAccount}.
158 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700159 public static class Builder {
160 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700161 private Uri mAddress;
162 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700163 private int mCapabilities;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800164 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700165 private CharSequence mLabel;
166 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700167 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700168 private Icon mIcon;
Santos Cordon91371dc02015-05-08 13:52:09 -0700169 private boolean mIsEnabled = false;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700170
Santos Cordon32c65a52014-10-27 14:57:49 -0700171 /**
172 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
173 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700174 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
175 this.mAccountHandle = accountHandle;
176 this.mLabel = label;
177 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700178
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700179 /**
180 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
181 * {@link PhoneAccount}.
182 *
183 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
184 */
185 public Builder(PhoneAccount phoneAccount) {
186 mAccountHandle = phoneAccount.getAccountHandle();
187 mAddress = phoneAccount.getAddress();
188 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
189 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800190 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700191 mLabel = phoneAccount.getLabel();
192 mShortDescription = phoneAccount.getShortDescription();
193 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700194 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc02015-05-08 13:52:09 -0700195 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700196 }
197
Santos Cordon32c65a52014-10-27 14:57:49 -0700198 /**
199 * Sets the address. See {@link PhoneAccount#getAddress}.
200 *
201 * @param value The address of the phone account.
202 * @return The builder.
203 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700204 public Builder setAddress(Uri value) {
205 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700206 return this;
207 }
208
Santos Cordon32c65a52014-10-27 14:57:49 -0700209 /**
210 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
211 *
212 * @param value The subscription address.
213 * @return The builder.
214 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700215 public Builder setSubscriptionAddress(Uri value) {
216 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700217 return this;
218 }
219
Santos Cordon32c65a52014-10-27 14:57:49 -0700220 /**
221 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
222 *
223 * @param value The capabilities to set.
224 * @return The builder.
225 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700226 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700227 this.mCapabilities = value;
228 return this;
229 }
230
Santos Cordon32c65a52014-10-27 14:57:49 -0700231 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700232 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700233 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700234 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700235 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700236 public Builder setIcon(Icon icon) {
237 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700238 return this;
239 }
240
241 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800242 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700243 *
Ihab Awad476cc832014-11-03 09:47:51 -0800244 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700245 * @return The builder.
246 */
Ihab Awad476cc832014-11-03 09:47:51 -0800247 public Builder setHighlightColor(int value) {
248 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700249 return this;
250 }
251
Santos Cordon32c65a52014-10-27 14:57:49 -0700252 /**
253 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
254 *
255 * @param value The short description.
256 * @return The builder.
257 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700258 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700259 this.mShortDescription = value;
260 return this;
261 }
262
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700263 /**
264 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
265 *
266 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700267 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700268 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700269 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700270 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
271 this.mSupportedUriSchemes.add(uriScheme);
272 }
273 return this;
274 }
275
276 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700277 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700278 *
279 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700280 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700281 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700282 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
283 mSupportedUriSchemes.clear();
284
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700285 if (uriSchemes != null && !uriSchemes.isEmpty()) {
286 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700287 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700288 }
289 }
290 return this;
291 }
292
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700293 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700294 * Sets the enabled state of the phone account.
295 *
296 * @param isEnabled The enabled state.
297 * @return The builder.
298 * @hide
299 */
300 public Builder setIsEnabled(boolean isEnabled) {
301 mIsEnabled = isEnabled;
302 return this;
303 }
304
305 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700306 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
307 *
308 * @return The {@link PhoneAccount}.
309 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700310 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700311 // If no supported URI schemes were defined, assume "tel" is supported.
312 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700313 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700314 }
315
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700316 return new PhoneAccount(
317 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700318 mAddress,
319 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700320 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700321 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800322 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700323 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700324 mShortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700325 mSupportedUriSchemes,
326 mIsEnabled);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700327 }
328 }
329
330 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700331 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700332 Uri address,
333 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700334 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700335 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800336 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700337 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700338 CharSequence shortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700339 List<String> supportedUriSchemes,
340 boolean isEnabled) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700341 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700342 mAddress = address;
343 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700344 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700345 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800346 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700347 mLabel = label;
348 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700349 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Santos Cordon91371dc02015-05-08 13:52:09 -0700350 mIsEnabled = isEnabled;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700351 }
352
Andrew Lee3085a6c2014-09-04 10:59:13 -0700353 public static Builder builder(
354 PhoneAccountHandle accountHandle,
355 CharSequence label) {
356 return new Builder(accountHandle, label);
357 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700358
Ihab Awad807fe0a2014-07-09 12:30:52 -0700359 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700360 * Returns a builder initialized with the current {@link PhoneAccount} instance.
361 *
362 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700363 */
364 public Builder toBuilder() { return new Builder(this); }
365
366 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700367 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700368 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700369 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700370 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700371 public PhoneAccountHandle getAccountHandle() {
372 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700373 }
374
375 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700376 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700377 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700378 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700379 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700380 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700381 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700382 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700383 public Uri getAddress() {
384 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700385 }
386
387 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700388 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700389 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700390 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000391 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
392 * has been used to alter the callback number.
393 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700394 *
395 * @return The subscription number, suitable for display to the user.
396 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700397 public Uri getSubscriptionAddress() {
398 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700399 }
400
401 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700402 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700403 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700404 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700405 */
406 public int getCapabilities() {
407 return mCapabilities;
408 }
409
410 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700411 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
412 * bit mask.
413 *
414 * @param capability The capabilities to check.
415 * @return {@code True} if the phone account has the capability.
416 */
417 public boolean hasCapabilities(int capability) {
418 return (mCapabilities & capability) == capability;
419 }
420
421 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700422 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700423 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700424 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700425 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700426 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700427 return mLabel;
428 }
429
430 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700431 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700432 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700433 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700434 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700435 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700436 return mShortDescription;
437 }
438
439 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700440 * The URI schemes supported by this {@code PhoneAccount}.
441 *
442 * @return The URI schemes.
443 */
444 public List<String> getSupportedUriSchemes() {
445 return mSupportedUriSchemes;
446 }
447
448 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700449 * The icon to represent this {@code PhoneAccount}.
450 *
451 * @return The icon.
452 */
453 public Icon getIcon() {
454 return mIcon;
455 }
456
457 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700458 * Indicates whether the user has enabled this phone account or not {@code PhoneAccounts}.
459 *
460 * @return The {@code true} if the account is enabled by the user, {@code false} otherwise.
461 */
462 public boolean isEnabled() {
463 return mIsEnabled;
464 }
465
466 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700467 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700468 * scheme.
469 *
470 * @param uriScheme The URI scheme to check.
Andrew Lee3085a6c2014-09-04 10:59:13 -0700471 * @return {@code True} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700472 * specified URI scheme.
473 */
474 public boolean supportsUriScheme(String uriScheme) {
475 if (mSupportedUriSchemes == null || uriScheme == null) {
476 return false;
477 }
478
479 for (String scheme : mSupportedUriSchemes) {
480 if (scheme != null && scheme.equals(uriScheme)) {
481 return true;
482 }
483 }
484 return false;
485 }
486
487 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800488 * A highlight color to use in displaying information about this {@code PhoneAccount}.
489 *
490 * @return A hexadecimal color value.
491 */
492 public int getHighlightColor() {
493 return mHighlightColor;
494 }
495
Santos Cordon91371dc02015-05-08 13:52:09 -0700496 /**
497 * Sets the enabled state of the phone account.
498 * @hide
499 */
500 public void setIsEnabled(boolean isEnabled) {
501 mIsEnabled = isEnabled;
502 }
503
Ihab Awad807fe0a2014-07-09 12:30:52 -0700504 //
505 // Parcelable implementation
506 //
507
508 @Override
509 public int describeContents() {
510 return 0;
511 }
512
513 @Override
514 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800515 if (mAccountHandle == null) {
516 out.writeInt(0);
517 } else {
518 out.writeInt(1);
519 mAccountHandle.writeToParcel(out, flags);
520 }
521 if (mAddress == null) {
522 out.writeInt(0);
523 } else {
524 out.writeInt(1);
525 mAddress.writeToParcel(out, flags);
526 }
527 if (mSubscriptionAddress == null) {
528 out.writeInt(0);
529 } else {
530 out.writeInt(1);
531 mSubscriptionAddress.writeToParcel(out, flags);
532 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700533 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800534 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700535 out.writeCharSequence(mLabel);
536 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800537 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc02015-05-08 13:52:09 -0700538
Santos Cordoncad84a22015-05-13 11:17:25 -0700539 if (mIcon == null) {
540 out.writeInt(0);
541 } else {
542 out.writeInt(1);
543 mIcon.writeToParcel(out, flags);
544 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700545 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Ihab Awad807fe0a2014-07-09 12:30:52 -0700546 }
547
Evan Charlton8c8a0622014-07-20 12:31:00 -0700548 public static final Creator<PhoneAccount> CREATOR
549 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700550 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700551 public PhoneAccount createFromParcel(Parcel in) {
552 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700553 }
554
555 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700556 public PhoneAccount[] newArray(int size) {
557 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700558 }
559 };
560
Evan Charlton8c8a0622014-07-20 12:31:00 -0700561 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800562 if (in.readInt() > 0) {
563 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
564 } else {
565 mAccountHandle = null;
566 }
567 if (in.readInt() > 0) {
568 mAddress = Uri.CREATOR.createFromParcel(in);
569 } else {
570 mAddress = null;
571 }
572 if (in.readInt() > 0) {
573 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
574 } else {
575 mSubscriptionAddress = null;
576 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700577 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -0800578 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700579 mLabel = in.readCharSequence();
580 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800581 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -0700582 if (in.readInt() > 0) {
583 mIcon = Icon.CREATOR.createFromParcel(in);
584 } else {
585 mIcon = null;
586 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700587 mIsEnabled = in.readByte() == 1;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700588 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700589
590 @Override
591 public String toString() {
Santos Cordon91371dc02015-05-08 13:52:09 -0700592 StringBuilder sb = new StringBuilder().append("[[")
593 .append(mIsEnabled ? 'X' : ' ')
594 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700595 .append(mAccountHandle)
596 .append(" Capabilities: ")
597 .append(mCapabilities)
598 .append(" Schemes: ");
599 for (String scheme : mSupportedUriSchemes) {
600 sb.append(scheme)
601 .append(" ");
602 }
603 sb.append("]");
604 return sb.toString();
605 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700606}