blob: 052a481f1ab28e55e883a355a22c44a7d120e064 [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;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070029import android.net.Uri;
Ihab Awad807fe0a2014-07-09 12:30:52 -070030import android.os.Parcel;
31import android.os.Parcelable;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070032import android.text.TextUtils;
Ihab Awad807fe0a2014-07-09 12:30:52 -070033
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070034import java.lang.String;
35import java.util.ArrayList;
36import java.util.Collections;
37import java.util.List;
Ihab Awad807fe0a2014-07-09 12:30:52 -070038import java.util.MissingResourceException;
39
40/**
Santos Cordon32c65a52014-10-27 14:57:49 -070041 * Represents a distinct method to place or receive a phone call. Apps which can place calls and
42 * want those calls to be integrated into the dialer and in-call UI should build an instance of
43 * this class and register it with the system using {@link TelecomManager#registerPhoneAccount}.
44 * <p>
45 * {@link TelecomManager} uses registered {@link PhoneAccount}s to present the user with
46 * alternative options when placing a phone call. When building a {@link PhoneAccount}, the app
47 * should supply a valid {@link PhoneAccountHandle} that references the {@link ConnectionService}
48 * implementation Telecom will use to interact with the app.
Evan Charlton0e094d92014-11-08 15:49:16 -080049 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -070050 */
Evan Charlton0e094d92014-11-08 15:49:16 -080051@SystemApi
Evan Charlton8c8a0622014-07-20 12:31:00 -070052public class PhoneAccount implements Parcelable {
Ihab Awad94cf4bf2014-07-17 11:21:19 -070053
54 /**
Ihab Awadf8b69882014-07-25 15:14:01 -070055 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
56 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
57 * will be allowed to manage phone calls including using its own proprietary phone-call
58 * implementation (like VoIP calling) to make calls instead of the telephony stack.
59 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -070060 * When a user opts to place a call using the SIM-based telephony stack, the
61 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
62 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -070063 * <p>
64 * See {@link #getCapabilities}
65 */
Ihab Awadf8b69882014-07-25 15:14:01 -070066 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070067
68 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -070069 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -070070 * traditional SIM-based telephony calls. This account will be treated as a distinct method
71 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -070072 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -070073 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -070074 * <p>
75 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -070076 * <p>
Evan Charlton7800fb72014-07-20 18:09:38 -070077 * {@hide}
Ihab Awad94cf4bf2014-07-17 11:21:19 -070078 */
79 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
80
Ihab Awad7522bbd62014-07-18 15:53:17 -070081 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070082 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -070083 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -070084 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -070085 * Only the Android framework can register a {@code PhoneAccount} having this capability.
86 * <p>
87 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -070088 */
89 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
90
Ihab Awadf8b69882014-07-25 15:14:01 -070091 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070092 * Flag indicating that this {@code PhoneAccount} is capable of placing video calls.
93 * <p>
94 * See {@link #getCapabilities}
Tyler Gunnbe74de02014-08-29 14:51:48 -070095 * @hide
Ihab Awadf8b69882014-07-25 15:14:01 -070096 */
97 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
98
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070099 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700100 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
101 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
102 * <p>
103 * See {@link #getCapabilities}
104 */
105 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
106
107 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800108 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
109 * should only be used by system apps (and will be ignored for all other apps trying to use it).
110 * <p>
111 * See {@link #getCapabilities}
112 * @hide
113 */
114 public static final int CAPABILITY_MULTI_USER = 0x20;
115
116 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700117 * URI scheme for telephone number URIs.
118 */
119 public static final String SCHEME_TEL = "tel";
120
121 /**
122 * URI scheme for voicemail URIs.
123 */
124 public static final String SCHEME_VOICEMAIL = "voicemail";
125
126 /**
127 * URI scheme for SIP URIs.
128 */
129 public static final String SCHEME_SIP = "sip";
130
Nancy Chen3ace54b2014-10-22 17:45:26 -0700131 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800132 * Indicating no icon tint is set.
Nancy Chen3ace54b2014-10-22 17:45:26 -0700133 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800134 public static final int NO_ICON_TINT = 0;
135
136 /**
137 * Indicating no hightlight color is set.
138 */
139 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700140
Ihab Awad476cc832014-11-03 09:47:51 -0800141 /**
142 * Indicating no resource ID is set.
143 */
144 public static final int NO_RESOURCE_ID = -1;
145
Evan Charlton8c8a0622014-07-20 12:31:00 -0700146 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700147 private final Uri mAddress;
148 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700149 private final int mCapabilities;
150 private final int mIconResId;
Ihab Awad074bf102014-10-24 11:42:32 -0700151 private final String mIconPackageName;
152 private final Bitmap mIconBitmap;
Ihab Awad476cc832014-11-03 09:47:51 -0800153 private final int mIconTint;
154 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700155 private final CharSequence mLabel;
156 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700157 private final List<String> mSupportedUriSchemes;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700158
Santos Cordon32c65a52014-10-27 14:57:49 -0700159 /**
160 * Helper class for creating a {@link PhoneAccount}.
161 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700162 public static class Builder {
163 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700164 private Uri mAddress;
165 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700166 private int mCapabilities;
167 private int mIconResId;
Ihab Awad074bf102014-10-24 11:42:32 -0700168 private String mIconPackageName;
169 private Bitmap mIconBitmap;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800170 private int mIconTint = NO_ICON_TINT;
171 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700172 private CharSequence mLabel;
173 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700174 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700175
Santos Cordon32c65a52014-10-27 14:57:49 -0700176 /**
177 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
178 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700179 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
180 this.mAccountHandle = accountHandle;
181 this.mLabel = label;
182 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700183
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700184 /**
185 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
186 * {@link PhoneAccount}.
187 *
188 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
189 */
190 public Builder(PhoneAccount phoneAccount) {
191 mAccountHandle = phoneAccount.getAccountHandle();
192 mAddress = phoneAccount.getAddress();
193 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
194 mCapabilities = phoneAccount.getCapabilities();
195 mIconResId = phoneAccount.getIconResId();
Ihab Awad074bf102014-10-24 11:42:32 -0700196 mIconPackageName = phoneAccount.getIconPackageName();
197 mIconBitmap = phoneAccount.getIconBitmap();
Ihab Awad476cc832014-11-03 09:47:51 -0800198 mIconTint = phoneAccount.getIconTint();
199 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700200 mLabel = phoneAccount.getLabel();
201 mShortDescription = phoneAccount.getShortDescription();
202 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700203 }
204
Evan Charlton134dd682014-11-25 14:12:57 -0800205 /** @hide */
206 public Builder setAccountHandle(PhoneAccountHandle accountHandle) {
207 mAccountHandle = accountHandle;
208 return this;
209 }
210
Santos Cordon32c65a52014-10-27 14:57:49 -0700211 /**
212 * Sets the address. See {@link PhoneAccount#getAddress}.
213 *
214 * @param value The address of the phone account.
215 * @return The builder.
216 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700217 public Builder setAddress(Uri value) {
218 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700219 return this;
220 }
221
Santos Cordon32c65a52014-10-27 14:57:49 -0700222 /**
223 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
224 *
225 * @param value The subscription address.
226 * @return The builder.
227 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700228 public Builder setSubscriptionAddress(Uri value) {
229 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700230 return this;
231 }
232
Santos Cordon32c65a52014-10-27 14:57:49 -0700233 /**
234 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
235 *
236 * @param value The capabilities to set.
237 * @return The builder.
238 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700239 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700240 this.mCapabilities = value;
241 return this;
242 }
243
Santos Cordon32c65a52014-10-27 14:57:49 -0700244 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800245 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700246 *
Ihab Awad476cc832014-11-03 09:47:51 -0800247 * @param packageContext The package from which to load an icon.
248 * @param iconResId The resource in {@code iconPackageName} representing the icon.
Santos Cordon32c65a52014-10-27 14:57:49 -0700249 * @return The builder.
250 */
Ihab Awad476cc832014-11-03 09:47:51 -0800251 public Builder setIcon(Context packageContext, int iconResId) {
252 return setIcon(packageContext.getPackageName(), iconResId);
253 }
254
255 /**
256 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
257 *
258 * @param iconPackageName The package from which to load an icon.
259 * @param iconResId The resource in {@code iconPackageName} representing the icon.
260 * @return The builder.
261 */
262 public Builder setIcon(String iconPackageName, int iconResId) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800263 return setIcon(iconPackageName, iconResId, NO_ICON_TINT);
Ihab Awad476cc832014-11-03 09:47:51 -0800264 }
265
266 /**
267 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
268 *
269 * @param packageContext The package from which to load an icon.
270 * @param iconResId The resource in {@code iconPackageName} representing the icon.
271 * @param iconTint A color with which to tint this icon.
272 * @return The builder.
273 */
274 public Builder setIcon(Context packageContext, int iconResId, int iconTint) {
275 return setIcon(packageContext.getPackageName(), iconResId, iconTint);
276 }
277
278 /**
279 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
280 *
281 * @param iconPackageName The package from which to load an icon.
282 * @param iconResId The resource in {@code iconPackageName} representing the icon.
283 * @param iconTint A color with which to tint this icon.
284 * @return The builder.
285 */
286 public Builder setIcon(String iconPackageName, int iconResId, int iconTint) {
287 this.mIconPackageName = iconPackageName;
288 this.mIconResId = iconResId;
289 this.mIconTint = iconTint;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700290 return this;
291 }
292
Ihab Awad074bf102014-10-24 11:42:32 -0700293 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800294 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
Ihab Awad074bf102014-10-24 11:42:32 -0700295 *
Ihab Awad476cc832014-11-03 09:47:51 -0800296 * @param iconBitmap The icon bitmap.
Ihab Awad074bf102014-10-24 11:42:32 -0700297 * @return The builder.
298 */
Ihab Awad476cc832014-11-03 09:47:51 -0800299 public Builder setIcon(Bitmap iconBitmap) {
300 this.mIconBitmap = iconBitmap;
301 this.mIconPackageName = null;
302 this.mIconResId = NO_RESOURCE_ID;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800303 this.mIconTint = NO_ICON_TINT;
Ihab Awad074bf102014-10-24 11:42:32 -0700304 return this;
305 }
306
307 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800308 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700309 *
Ihab Awad476cc832014-11-03 09:47:51 -0800310 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700311 * @return The builder.
312 */
Ihab Awad476cc832014-11-03 09:47:51 -0800313 public Builder setHighlightColor(int value) {
314 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700315 return this;
316 }
317
Santos Cordon32c65a52014-10-27 14:57:49 -0700318 /**
319 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
320 *
321 * @param value The short description.
322 * @return The builder.
323 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700324 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700325 this.mShortDescription = value;
326 return this;
327 }
328
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700329 /**
330 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
331 *
332 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700333 * @return The builder.
Andrew Lee3085a6c2014-09-04 10:59:13 -0700334 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700335 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700336 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700337 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
338 this.mSupportedUriSchemes.add(uriScheme);
339 }
340 return this;
341 }
342
343 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700344 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700345 *
346 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700347 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700348 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700349 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
350 mSupportedUriSchemes.clear();
351
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700352 if (uriSchemes != null && !uriSchemes.isEmpty()) {
353 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700354 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700355 }
356 }
357 return this;
358 }
359
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700360 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700361 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
362 *
363 * @return The {@link PhoneAccount}.
364 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700365 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700366 // If no supported URI schemes were defined, assume "tel" is supported.
367 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700368 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700369 }
370
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700371 return new PhoneAccount(
372 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700373 mAddress,
374 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700375 mCapabilities,
376 mIconResId,
Ihab Awad074bf102014-10-24 11:42:32 -0700377 mIconPackageName,
378 mIconBitmap,
Ihab Awad476cc832014-11-03 09:47:51 -0800379 mIconTint,
380 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700381 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700382 mShortDescription,
Nancy Chen210ef032014-09-15 17:58:42 -0700383 mSupportedUriSchemes);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700384 }
385 }
386
387 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700388 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700389 Uri address,
390 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700391 int capabilities,
Ihab Awad807fe0a2014-07-09 12:30:52 -0700392 int iconResId,
Ihab Awad074bf102014-10-24 11:42:32 -0700393 String iconPackageName,
394 Bitmap iconBitmap,
Ihab Awad476cc832014-11-03 09:47:51 -0800395 int iconTint,
396 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700397 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700398 CharSequence shortDescription,
Nancy Chen210ef032014-09-15 17:58:42 -0700399 List<String> supportedUriSchemes) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700400 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700401 mAddress = address;
402 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700403 mCapabilities = capabilities;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700404 mIconResId = iconResId;
Ihab Awad074bf102014-10-24 11:42:32 -0700405 mIconPackageName = iconPackageName;
406 mIconBitmap = iconBitmap;
Ihab Awad476cc832014-11-03 09:47:51 -0800407 mIconTint = iconTint;
408 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700409 mLabel = label;
410 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700411 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700412 }
413
Andrew Lee3085a6c2014-09-04 10:59:13 -0700414 public static Builder builder(
415 PhoneAccountHandle accountHandle,
416 CharSequence label) {
417 return new Builder(accountHandle, label);
418 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700419
Ihab Awad807fe0a2014-07-09 12:30:52 -0700420 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700421 * Returns a builder initialized with the current {@link PhoneAccount} instance.
422 *
423 * @return The builder.
424 * @hide
425 */
426 public Builder toBuilder() { return new Builder(this); }
427
428 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700429 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700430 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700431 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700432 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700433 public PhoneAccountHandle getAccountHandle() {
434 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700435 }
436
437 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700438 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700439 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700440 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700441 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700442 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700443 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700444 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700445 public Uri getAddress() {
446 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700447 }
448
449 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700450 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700451 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700452 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000453 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
454 * has been used to alter the callback number.
455 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700456 *
457 * @return The subscription number, suitable for display to the user.
458 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700459 public Uri getSubscriptionAddress() {
460 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700461 }
462
463 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700464 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700465 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700466 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700467 */
468 public int getCapabilities() {
469 return mCapabilities;
470 }
471
472 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700473 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
474 * bit mask.
475 *
476 * @param capability The capabilities to check.
477 * @return {@code True} if the phone account has the capability.
478 */
479 public boolean hasCapabilities(int capability) {
480 return (mCapabilities & capability) == capability;
481 }
482
483 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700484 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700485 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700486 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700487 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700488 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700489 return mLabel;
490 }
491
492 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700493 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700494 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700495 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700496 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700497 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700498 return mShortDescription;
499 }
500
501 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700502 * The URI schemes supported by this {@code PhoneAccount}.
503 *
504 * @return The URI schemes.
505 */
506 public List<String> getSupportedUriSchemes() {
507 return mSupportedUriSchemes;
508 }
509
510 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700511 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700512 * scheme.
513 *
514 * @param uriScheme The URI scheme to check.
Andrew Lee3085a6c2014-09-04 10:59:13 -0700515 * @return {@code True} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700516 * specified URI scheme.
517 */
518 public boolean supportsUriScheme(String uriScheme) {
519 if (mSupportedUriSchemes == null || uriScheme == null) {
520 return false;
521 }
522
523 for (String scheme : mSupportedUriSchemes) {
524 if (scheme != null && scheme.equals(uriScheme)) {
525 return true;
526 }
527 }
528 return false;
529 }
530
531 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700532 * The icon resource ID for the icon of this {@code PhoneAccount}.
533 * <p>
534 * Creators of a {@code PhoneAccount} who possess the icon in static resources should prefer
535 * this method of indicating the icon rather than using {@link #getIconBitmap()}, since it
536 * leads to less resource usage.
537 * <p>
Ihab Awad476cc832014-11-03 09:47:51 -0800538 * Clients wishing to display a {@code PhoneAccount} should use {@link #createIconDrawable(Context)}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700539 *
540 * @return A resource ID.
541 */
542 public int getIconResId() {
543 return mIconResId;
544 }
545
546 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700547 * The package name from which to load the icon of this {@code PhoneAccount}.
548 * <p>
549 * If this property is {@code null}, the resource {@link #getIconResId()} will be loaded from
550 * the package in the {@link ComponentName} of the {@link #getAccountHandle()}.
551 * <p>
Ihab Awad476cc832014-11-03 09:47:51 -0800552 * Clients wishing to display a {@code PhoneAccount} should use {@link #createIconDrawable(Context)}.
Ihab Awad074bf102014-10-24 11:42:32 -0700553 *
554 * @return A package name.
555 */
556 public String getIconPackageName() {
557 return mIconPackageName;
558 }
559
560 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800561 * A tint to apply to the icon of this {@code PhoneAccount}.
Nancy Chen3ace54b2014-10-22 17:45:26 -0700562 *
563 * @return A hexadecimal color value.
564 */
Ihab Awad476cc832014-11-03 09:47:51 -0800565 public int getIconTint() {
566 return mIconTint;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700567 }
568
569 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700570 * A literal icon bitmap to represent this {@code PhoneAccount} in a user interface.
571 * <p>
572 * If this property is specified, it is to be considered the preferred icon. Otherwise, the
573 * resource specified by {@link #getIconResId()} should be used.
574 * <p>
Ihab Awad476cc832014-11-03 09:47:51 -0800575 * Clients wishing to display a {@code PhoneAccount} should use
576 * {@link #createIconDrawable(Context)}.
Ihab Awad074bf102014-10-24 11:42:32 -0700577 *
578 * @return A bitmap.
579 */
580 public Bitmap getIconBitmap() {
581 return mIconBitmap;
582 }
583
584 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800585 * A highlight color to use in displaying information about this {@code PhoneAccount}.
586 *
587 * @return A hexadecimal color value.
588 */
589 public int getHighlightColor() {
590 return mHighlightColor;
591 }
592
593 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700594 * Builds and returns an icon {@code Drawable} to represent this {@code PhoneAccount} in a user
595 * interface. Uses the properties {@link #getIconResId()}, {@link #getIconPackageName()}, and
596 * {@link #getIconBitmap()} as necessary.
597 *
598 * @param context A {@code Context} to use for loading {@code Drawable}s.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700599 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700600 * @return An icon for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700601 */
Ihab Awad476cc832014-11-03 09:47:51 -0800602 public Drawable createIconDrawable(Context context) {
Ihab Awad074bf102014-10-24 11:42:32 -0700603 if (mIconBitmap != null) {
604 return new BitmapDrawable(context.getResources(), mIconBitmap);
Sailesh Nepal77780a42014-09-26 18:12:00 -0700605 }
606
Ihab Awad074bf102014-10-24 11:42:32 -0700607 if (mIconResId != 0) {
Ihab Awad074bf102014-10-24 11:42:32 -0700608 try {
Ihab Awad476cc832014-11-03 09:47:51 -0800609 Context packageContext = context.createPackageContext(mIconPackageName, 0);
Ihab Awad074bf102014-10-24 11:42:32 -0700610 try {
Ihab Awad476cc832014-11-03 09:47:51 -0800611 Drawable iconDrawable = packageContext.getDrawable(mIconResId);
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800612 if (mIconTint != NO_ICON_TINT) {
Ihab Awad476cc832014-11-03 09:47:51 -0800613 iconDrawable.setTint(mIconTint);
614 }
615 return iconDrawable;
Ihab Awad074bf102014-10-24 11:42:32 -0700616 } catch (NotFoundException | MissingResourceException e) {
Ihab Awad476cc832014-11-03 09:47:51 -0800617 Log.e(this, e, "Cannot find icon %d in package %s",
618 mIconResId, mIconPackageName);
Ihab Awad074bf102014-10-24 11:42:32 -0700619 }
620 } catch (PackageManager.NameNotFoundException e) {
Ihab Awad476cc832014-11-03 09:47:51 -0800621 Log.w(this, "Cannot find package %s", mIconPackageName);
Ihab Awad074bf102014-10-24 11:42:32 -0700622 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700623 }
Ihab Awad074bf102014-10-24 11:42:32 -0700624
625 return new ColorDrawable(Color.TRANSPARENT);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700626 }
627
628 //
629 // Parcelable implementation
630 //
631
632 @Override
633 public int describeContents() {
634 return 0;
635 }
636
637 @Override
638 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800639 if (mAccountHandle == null) {
640 out.writeInt(0);
641 } else {
642 out.writeInt(1);
643 mAccountHandle.writeToParcel(out, flags);
644 }
645 if (mAddress == null) {
646 out.writeInt(0);
647 } else {
648 out.writeInt(1);
649 mAddress.writeToParcel(out, flags);
650 }
651 if (mSubscriptionAddress == null) {
652 out.writeInt(0);
653 } else {
654 out.writeInt(1);
655 mSubscriptionAddress.writeToParcel(out, flags);
656 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700657 out.writeInt(mCapabilities);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700658 out.writeInt(mIconResId);
Ihab Awad074bf102014-10-24 11:42:32 -0700659 out.writeString(mIconPackageName);
Ihab Awad476cc832014-11-03 09:47:51 -0800660 if (mIconBitmap == null) {
661 out.writeInt(0);
662 } else {
Ihab Awad96802ad2014-11-11 18:41:39 -0800663 out.writeInt(1);
Ihab Awad476cc832014-11-03 09:47:51 -0800664 mIconBitmap.writeToParcel(out, flags);
665 }
666 out.writeInt(mIconTint);
667 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700668 out.writeCharSequence(mLabel);
669 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800670 out.writeStringList(mSupportedUriSchemes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700671 }
672
Evan Charlton8c8a0622014-07-20 12:31:00 -0700673 public static final Creator<PhoneAccount> CREATOR
674 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700675 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700676 public PhoneAccount createFromParcel(Parcel in) {
677 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700678 }
679
680 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700681 public PhoneAccount[] newArray(int size) {
682 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700683 }
684 };
685
Evan Charlton8c8a0622014-07-20 12:31:00 -0700686 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800687 if (in.readInt() > 0) {
688 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
689 } else {
690 mAccountHandle = null;
691 }
692 if (in.readInt() > 0) {
693 mAddress = Uri.CREATOR.createFromParcel(in);
694 } else {
695 mAddress = null;
696 }
697 if (in.readInt() > 0) {
698 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
699 } else {
700 mSubscriptionAddress = null;
701 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700702 mCapabilities = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700703 mIconResId = in.readInt();
Ihab Awad074bf102014-10-24 11:42:32 -0700704 mIconPackageName = in.readString();
Ihab Awad476cc832014-11-03 09:47:51 -0800705 if (in.readInt() > 0) {
706 mIconBitmap = Bitmap.CREATOR.createFromParcel(in);
707 } else {
708 mIconBitmap = null;
709 }
710 mIconTint = in.readInt();
711 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700712 mLabel = in.readCharSequence();
713 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800714 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700715 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700716
717 @Override
718 public String toString() {
719 StringBuilder sb = new StringBuilder().append("[PhoneAccount: ")
720 .append(mAccountHandle)
721 .append(" Capabilities: ")
722 .append(mCapabilities)
723 .append(" Schemes: ");
724 for (String scheme : mSupportedUriSchemes) {
725 sb.append(scheme)
726 .append(" ");
727 }
728 sb.append("]");
729 return sb.toString();
730 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700731}