blob: cdb0bf257baadfdebe9421f794392908a6f457e3 [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 Gunn65a3d342015-07-27 16:06:16 -0700115 * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a
116 * caller is able to specify a short subject line for an outgoing call. A capable receiving
117 * device displays the call subject on the incoming call screen.
118 * <p>
119 * See {@link #getCapabilities}
120 */
121 public static final int CAPABILITY_CALL_SUBJECT = 0x40;
122
123 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700124 * URI scheme for telephone number URIs.
125 */
126 public static final String SCHEME_TEL = "tel";
127
128 /**
129 * URI scheme for voicemail URIs.
130 */
131 public static final String SCHEME_VOICEMAIL = "voicemail";
132
133 /**
134 * URI scheme for SIP URIs.
135 */
136 public static final String SCHEME_SIP = "sip";
137
Nancy Chen3ace54b2014-10-22 17:45:26 -0700138 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800139 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700140 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700141 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800142 public static final int NO_ICON_TINT = 0;
143
144 /**
145 * Indicating no hightlight color is set.
146 */
147 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700148
Ihab Awad476cc832014-11-03 09:47:51 -0800149 /**
150 * Indicating no resource ID is set.
151 */
152 public static final int NO_RESOURCE_ID = -1;
153
Evan Charlton8c8a0622014-07-20 12:31:00 -0700154 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700155 private final Uri mAddress;
156 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700157 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800158 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700159 private final CharSequence mLabel;
160 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700161 private final List<String> mSupportedUriSchemes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700162 private final Icon mIcon;
Santos Cordon91371dc02015-05-08 13:52:09 -0700163 private boolean mIsEnabled;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700164
Santos Cordon32c65a52014-10-27 14:57:49 -0700165 /**
166 * Helper class for creating a {@link PhoneAccount}.
167 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700168 public static class Builder {
169 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700170 private Uri mAddress;
171 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700172 private int mCapabilities;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800173 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700174 private CharSequence mLabel;
175 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700176 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700177 private Icon mIcon;
Santos Cordon91371dc02015-05-08 13:52:09 -0700178 private boolean mIsEnabled = false;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700179
Santos Cordon32c65a52014-10-27 14:57:49 -0700180 /**
181 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
182 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700183 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
184 this.mAccountHandle = accountHandle;
185 this.mLabel = label;
186 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700187
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700188 /**
189 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
190 * {@link PhoneAccount}.
191 *
192 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
193 */
194 public Builder(PhoneAccount phoneAccount) {
195 mAccountHandle = phoneAccount.getAccountHandle();
196 mAddress = phoneAccount.getAddress();
197 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
198 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800199 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700200 mLabel = phoneAccount.getLabel();
201 mShortDescription = phoneAccount.getShortDescription();
202 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700203 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc02015-05-08 13:52:09 -0700204 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700205 }
206
Santos Cordon32c65a52014-10-27 14:57:49 -0700207 /**
208 * Sets the address. See {@link PhoneAccount#getAddress}.
209 *
210 * @param value The address of the phone account.
211 * @return The builder.
212 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700213 public Builder setAddress(Uri value) {
214 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700215 return this;
216 }
217
Santos Cordon32c65a52014-10-27 14:57:49 -0700218 /**
219 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
220 *
221 * @param value The subscription address.
222 * @return The builder.
223 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700224 public Builder setSubscriptionAddress(Uri value) {
225 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700226 return this;
227 }
228
Santos Cordon32c65a52014-10-27 14:57:49 -0700229 /**
230 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
231 *
232 * @param value The capabilities to set.
233 * @return The builder.
234 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700235 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700236 this.mCapabilities = value;
237 return this;
238 }
239
Santos Cordon32c65a52014-10-27 14:57:49 -0700240 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700241 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700242 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700243 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700244 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700245 public Builder setIcon(Icon icon) {
246 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700247 return this;
248 }
249
250 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800251 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700252 *
Ihab Awad476cc832014-11-03 09:47:51 -0800253 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700254 * @return The builder.
255 */
Ihab Awad476cc832014-11-03 09:47:51 -0800256 public Builder setHighlightColor(int value) {
257 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700258 return this;
259 }
260
Santos Cordon32c65a52014-10-27 14:57:49 -0700261 /**
262 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
263 *
264 * @param value The short description.
265 * @return The builder.
266 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700267 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700268 this.mShortDescription = value;
269 return this;
270 }
271
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700272 /**
273 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
274 *
275 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700276 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700277 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700278 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700279 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
280 this.mSupportedUriSchemes.add(uriScheme);
281 }
282 return this;
283 }
284
285 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700286 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700287 *
288 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700289 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700290 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700291 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
292 mSupportedUriSchemes.clear();
293
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700294 if (uriSchemes != null && !uriSchemes.isEmpty()) {
295 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700296 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700297 }
298 }
299 return this;
300 }
301
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700302 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700303 * Sets the enabled state of the phone account.
304 *
305 * @param isEnabled The enabled state.
306 * @return The builder.
307 * @hide
308 */
309 public Builder setIsEnabled(boolean isEnabled) {
310 mIsEnabled = isEnabled;
311 return this;
312 }
313
314 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700315 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
316 *
317 * @return The {@link PhoneAccount}.
318 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700319 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700320 // If no supported URI schemes were defined, assume "tel" is supported.
321 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700322 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700323 }
324
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700325 return new PhoneAccount(
326 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700327 mAddress,
328 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700329 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700330 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800331 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700332 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700333 mShortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700334 mSupportedUriSchemes,
335 mIsEnabled);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700336 }
337 }
338
339 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700340 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700341 Uri address,
342 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700343 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700344 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800345 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700346 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700347 CharSequence shortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700348 List<String> supportedUriSchemes,
349 boolean isEnabled) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700350 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700351 mAddress = address;
352 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700353 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700354 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800355 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700356 mLabel = label;
357 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700358 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Santos Cordon91371dc02015-05-08 13:52:09 -0700359 mIsEnabled = isEnabled;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700360 }
361
Andrew Lee3085a6c2014-09-04 10:59:13 -0700362 public static Builder builder(
363 PhoneAccountHandle accountHandle,
364 CharSequence label) {
365 return new Builder(accountHandle, label);
366 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700367
Ihab Awad807fe0a2014-07-09 12:30:52 -0700368 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700369 * Returns a builder initialized with the current {@link PhoneAccount} instance.
370 *
371 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700372 */
373 public Builder toBuilder() { return new Builder(this); }
374
375 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700376 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700377 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700378 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700379 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700380 public PhoneAccountHandle getAccountHandle() {
381 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700382 }
383
384 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700385 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700386 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700387 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700388 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700389 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700390 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700391 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700392 public Uri getAddress() {
393 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700394 }
395
396 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700397 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700398 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700399 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000400 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
401 * has been used to alter the callback number.
402 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700403 *
404 * @return The subscription number, suitable for display to the user.
405 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700406 public Uri getSubscriptionAddress() {
407 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700408 }
409
410 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700411 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700412 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700413 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700414 */
415 public int getCapabilities() {
416 return mCapabilities;
417 }
418
419 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700420 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
421 * bit mask.
422 *
423 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700424 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700425 */
426 public boolean hasCapabilities(int capability) {
427 return (mCapabilities & capability) == capability;
428 }
429
430 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700431 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700432 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700433 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700434 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700435 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700436 return mLabel;
437 }
438
439 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700440 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700441 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700442 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700443 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700444 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700445 return mShortDescription;
446 }
447
448 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700449 * The URI schemes supported by this {@code PhoneAccount}.
450 *
451 * @return The URI schemes.
452 */
453 public List<String> getSupportedUriSchemes() {
454 return mSupportedUriSchemes;
455 }
456
457 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700458 * The icon to represent this {@code PhoneAccount}.
459 *
460 * @return The icon.
461 */
462 public Icon getIcon() {
463 return mIcon;
464 }
465
466 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700467 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
468 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc02015-05-08 13:52:09 -0700469 *
Santos Cordon895d4b82015-06-25 16:41:48 -0700470 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc02015-05-08 13:52:09 -0700471 */
472 public boolean isEnabled() {
473 return mIsEnabled;
474 }
475
476 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700477 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700478 * scheme.
479 *
480 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700481 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700482 * specified URI scheme.
483 */
484 public boolean supportsUriScheme(String uriScheme) {
485 if (mSupportedUriSchemes == null || uriScheme == null) {
486 return false;
487 }
488
489 for (String scheme : mSupportedUriSchemes) {
490 if (scheme != null && scheme.equals(uriScheme)) {
491 return true;
492 }
493 }
494 return false;
495 }
496
497 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800498 * A highlight color to use in displaying information about this {@code PhoneAccount}.
499 *
500 * @return A hexadecimal color value.
501 */
502 public int getHighlightColor() {
503 return mHighlightColor;
504 }
505
Santos Cordon91371dc02015-05-08 13:52:09 -0700506 /**
507 * Sets the enabled state of the phone account.
508 * @hide
509 */
510 public void setIsEnabled(boolean isEnabled) {
511 mIsEnabled = isEnabled;
512 }
513
Ihab Awad807fe0a2014-07-09 12:30:52 -0700514 //
515 // Parcelable implementation
516 //
517
518 @Override
519 public int describeContents() {
520 return 0;
521 }
522
523 @Override
524 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800525 if (mAccountHandle == null) {
526 out.writeInt(0);
527 } else {
528 out.writeInt(1);
529 mAccountHandle.writeToParcel(out, flags);
530 }
531 if (mAddress == null) {
532 out.writeInt(0);
533 } else {
534 out.writeInt(1);
535 mAddress.writeToParcel(out, flags);
536 }
537 if (mSubscriptionAddress == null) {
538 out.writeInt(0);
539 } else {
540 out.writeInt(1);
541 mSubscriptionAddress.writeToParcel(out, flags);
542 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700543 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800544 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700545 out.writeCharSequence(mLabel);
546 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800547 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc02015-05-08 13:52:09 -0700548
Santos Cordoncad84a22015-05-13 11:17:25 -0700549 if (mIcon == null) {
550 out.writeInt(0);
551 } else {
552 out.writeInt(1);
553 mIcon.writeToParcel(out, flags);
554 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700555 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Ihab Awad807fe0a2014-07-09 12:30:52 -0700556 }
557
Evan Charlton8c8a0622014-07-20 12:31:00 -0700558 public static final Creator<PhoneAccount> CREATOR
559 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700560 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700561 public PhoneAccount createFromParcel(Parcel in) {
562 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700563 }
564
565 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700566 public PhoneAccount[] newArray(int size) {
567 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700568 }
569 };
570
Evan Charlton8c8a0622014-07-20 12:31:00 -0700571 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800572 if (in.readInt() > 0) {
573 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
574 } else {
575 mAccountHandle = null;
576 }
577 if (in.readInt() > 0) {
578 mAddress = Uri.CREATOR.createFromParcel(in);
579 } else {
580 mAddress = null;
581 }
582 if (in.readInt() > 0) {
583 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
584 } else {
585 mSubscriptionAddress = null;
586 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700587 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -0800588 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700589 mLabel = in.readCharSequence();
590 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800591 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -0700592 if (in.readInt() > 0) {
593 mIcon = Icon.CREATOR.createFromParcel(in);
594 } else {
595 mIcon = null;
596 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700597 mIsEnabled = in.readByte() == 1;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700598 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700599
600 @Override
601 public String toString() {
Santos Cordon91371dc02015-05-08 13:52:09 -0700602 StringBuilder sb = new StringBuilder().append("[[")
603 .append(mIsEnabled ? 'X' : ' ')
604 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700605 .append(mAccountHandle)
606 .append(" Capabilities: ")
607 .append(mCapabilities)
608 .append(" Schemes: ");
609 for (String scheme : mSupportedUriSchemes) {
610 sb.append(scheme)
611 .append(" ");
612 }
613 sb.append("]");
614 return sb.toString();
615 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700616}