blob: f9ee5d2444c9488ae1cfaed2bacc498497088bcf [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 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700108 * URI scheme for telephone number URIs.
109 */
110 public static final String SCHEME_TEL = "tel";
111
112 /**
113 * URI scheme for voicemail URIs.
114 */
115 public static final String SCHEME_VOICEMAIL = "voicemail";
116
117 /**
118 * URI scheme for SIP URIs.
119 */
120 public static final String SCHEME_SIP = "sip";
121
Nancy Chen3ace54b2014-10-22 17:45:26 -0700122 /**
123 * Indicating no color is set.
124 */
125 public static final int NO_COLOR = -1;
126
Evan Charlton8c8a0622014-07-20 12:31:00 -0700127 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700128 private final Uri mAddress;
129 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700130 private final int mCapabilities;
131 private final int mIconResId;
Ihab Awad074bf102014-10-24 11:42:32 -0700132 private final String mIconPackageName;
133 private final Bitmap mIconBitmap;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700134 private final int mColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700135 private final CharSequence mLabel;
136 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700137 private final List<String> mSupportedUriSchemes;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700138
Santos Cordon32c65a52014-10-27 14:57:49 -0700139 /**
140 * Helper class for creating a {@link PhoneAccount}.
141 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700142 public static class Builder {
143 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700144 private Uri mAddress;
145 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700146 private int mCapabilities;
147 private int mIconResId;
Ihab Awad074bf102014-10-24 11:42:32 -0700148 private String mIconPackageName;
149 private Bitmap mIconBitmap;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700150 private int mColor = NO_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700151 private CharSequence mLabel;
152 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700153 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700154
Santos Cordon32c65a52014-10-27 14:57:49 -0700155 /**
156 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
157 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700158 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
159 this.mAccountHandle = accountHandle;
160 this.mLabel = label;
161 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700162
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700163 /**
164 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
165 * {@link PhoneAccount}.
166 *
167 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
168 */
169 public Builder(PhoneAccount phoneAccount) {
170 mAccountHandle = phoneAccount.getAccountHandle();
171 mAddress = phoneAccount.getAddress();
172 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
173 mCapabilities = phoneAccount.getCapabilities();
174 mIconResId = phoneAccount.getIconResId();
Ihab Awad074bf102014-10-24 11:42:32 -0700175 mIconPackageName = phoneAccount.getIconPackageName();
176 mIconBitmap = phoneAccount.getIconBitmap();
Nancy Chen3ace54b2014-10-22 17:45:26 -0700177 mColor = phoneAccount.getColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700178 mLabel = phoneAccount.getLabel();
179 mShortDescription = phoneAccount.getShortDescription();
180 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700181 }
182
Santos Cordon32c65a52014-10-27 14:57:49 -0700183 /**
184 * Sets the address. See {@link PhoneAccount#getAddress}.
185 *
186 * @param value The address of the phone account.
187 * @return The builder.
188 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700189 public Builder setAddress(Uri value) {
190 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700191 return this;
192 }
193
Santos Cordon32c65a52014-10-27 14:57:49 -0700194 /**
195 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
196 *
197 * @param value The subscription address.
198 * @return The builder.
199 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700200 public Builder setSubscriptionAddress(Uri value) {
201 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700202 return this;
203 }
204
Santos Cordon32c65a52014-10-27 14:57:49 -0700205 /**
206 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
207 *
208 * @param value The capabilities to set.
209 * @return The builder.
210 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700211 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700212 this.mCapabilities = value;
213 return this;
214 }
215
Santos Cordon32c65a52014-10-27 14:57:49 -0700216 /**
217 * Sets the icon resource ID. See {@link PhoneAccount#getIconResId}.
218 *
219 * @param value The resource ID of the icon.
220 * @return The builder.
221 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700222 public Builder setIconResId(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700223 this.mIconResId = value;
224 return this;
225 }
226
Ihab Awad074bf102014-10-24 11:42:32 -0700227 /**
228 * Sets the icon package name. See {@link PhoneAccount#getIconPackageName}.
229 *
230 * @param value The name of the package from which to load the icon.
231 * @return The builder.
232 */
233 public Builder setIconPackageName(String value) {
234 this.mIconPackageName = value;
235 return this;
236 }
237
238 /**
239 * Sets the icon bitmap. See {@link PhoneAccount#getIconBitmap}.
240 *
241 * @param value The icon bitmap.
242 * @return The builder.
243 */
244 public Builder setIconBitmap(Bitmap value) {
245 this.mIconBitmap = value;
246 return this;
247 }
248
249 /**
250 * Sets the color. See {@link PhoneAccount#getColor}.
251 *
252 * @param value The resource ID of the icon.
253 * @return The builder.
254 */
Nancy Chen3ace54b2014-10-22 17:45:26 -0700255 public Builder setColor(int value) {
256 this.mColor = value;
257 return this;
258 }
259
Santos Cordon32c65a52014-10-27 14:57:49 -0700260 /**
261 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
262 *
263 * @param value The short description.
264 * @return The builder.
265 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700266 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700267 this.mShortDescription = value;
268 return this;
269 }
270
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700271 /**
272 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
273 *
274 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700275 * @return The builder.
Andrew Lee3085a6c2014-09-04 10:59:13 -0700276 * @hide
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 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700303 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
304 *
305 * @return The {@link PhoneAccount}.
306 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700307 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700308 // If no supported URI schemes were defined, assume "tel" is supported.
309 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700310 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700311 }
312
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700313 return new PhoneAccount(
314 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700315 mAddress,
316 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700317 mCapabilities,
318 mIconResId,
Ihab Awad074bf102014-10-24 11:42:32 -0700319 mIconPackageName,
320 mIconBitmap,
Nancy Chen3ace54b2014-10-22 17:45:26 -0700321 mColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700322 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700323 mShortDescription,
Nancy Chen210ef032014-09-15 17:58:42 -0700324 mSupportedUriSchemes);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700325 }
326 }
327
328 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700329 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700330 Uri address,
331 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700332 int capabilities,
Ihab Awad807fe0a2014-07-09 12:30:52 -0700333 int iconResId,
Ihab Awad074bf102014-10-24 11:42:32 -0700334 String iconPackageName,
335 Bitmap iconBitmap,
Nancy Chen3ace54b2014-10-22 17:45:26 -0700336 int color,
Santos Cordon146a3e32014-07-21 00:00:44 -0700337 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700338 CharSequence shortDescription,
Nancy Chen210ef032014-09-15 17:58:42 -0700339 List<String> supportedUriSchemes) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700340 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700341 mAddress = address;
342 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700343 mCapabilities = capabilities;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700344 mIconResId = iconResId;
Ihab Awad074bf102014-10-24 11:42:32 -0700345 mIconPackageName = iconPackageName;
346 mIconBitmap = iconBitmap;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700347 mColor = color;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700348 mLabel = label;
349 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700350 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
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.
363 * @hide
364 */
365 public Builder toBuilder() { return new Builder(this); }
366
367 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700368 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700369 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700370 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700371 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700372 public PhoneAccountHandle getAccountHandle() {
373 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700374 }
375
376 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700377 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700378 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700379 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700380 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700381 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700382 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700383 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700384 public Uri getAddress() {
385 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700386 }
387
388 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700389 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700390 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700391 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000392 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
393 * has been used to alter the callback number.
394 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700395 *
396 * @return The subscription number, suitable for display to the user.
397 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700398 public Uri getSubscriptionAddress() {
399 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700400 }
401
402 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700403 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700404 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700405 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700406 */
407 public int getCapabilities() {
408 return mCapabilities;
409 }
410
411 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700412 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
413 * bit mask.
414 *
415 * @param capability The capabilities to check.
416 * @return {@code True} if the phone account has the capability.
417 */
418 public boolean hasCapabilities(int capability) {
419 return (mCapabilities & capability) == capability;
420 }
421
422 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700423 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700424 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700425 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700426 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700427 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700428 return mLabel;
429 }
430
431 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700432 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700433 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700434 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700435 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700436 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700437 return mShortDescription;
438 }
439
440 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700441 * The URI schemes supported by this {@code PhoneAccount}.
442 *
443 * @return The URI schemes.
444 */
445 public List<String> getSupportedUriSchemes() {
446 return mSupportedUriSchemes;
447 }
448
449 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700450 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700451 * scheme.
452 *
453 * @param uriScheme The URI scheme to check.
Andrew Lee3085a6c2014-09-04 10:59:13 -0700454 * @return {@code True} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700455 * specified URI scheme.
456 */
457 public boolean supportsUriScheme(String uriScheme) {
458 if (mSupportedUriSchemes == null || uriScheme == null) {
459 return false;
460 }
461
462 for (String scheme : mSupportedUriSchemes) {
463 if (scheme != null && scheme.equals(uriScheme)) {
464 return true;
465 }
466 }
467 return false;
468 }
469
470 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700471 * The icon resource ID for the icon of this {@code PhoneAccount}.
472 * <p>
473 * Creators of a {@code PhoneAccount} who possess the icon in static resources should prefer
474 * this method of indicating the icon rather than using {@link #getIconBitmap()}, since it
475 * leads to less resource usage.
476 * <p>
477 * Clients wishing to display a {@code PhoneAccount} should use {@link #getIcon(Context)}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700478 *
479 * @return A resource ID.
480 */
481 public int getIconResId() {
482 return mIconResId;
483 }
484
485 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700486 * The package name from which to load the icon of this {@code PhoneAccount}.
487 * <p>
488 * If this property is {@code null}, the resource {@link #getIconResId()} will be loaded from
489 * the package in the {@link ComponentName} of the {@link #getAccountHandle()}.
490 * <p>
491 * Clients wishing to display a {@code PhoneAccount} should use {@link #getIcon(Context)}.
492 *
493 * @return A package name.
494 */
495 public String getIconPackageName() {
496 return mIconPackageName;
497 }
498
499 /**
Nancy Chen3ace54b2014-10-22 17:45:26 -0700500 * A highlight color to use in displaying information about this {@code PhoneAccount}.
501 *
502 * @return A hexadecimal color value.
503 */
504 public int getColor() {
505 return mColor;
506 }
507
508 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700509 * A literal icon bitmap to represent this {@code PhoneAccount} in a user interface.
510 * <p>
511 * If this property is specified, it is to be considered the preferred icon. Otherwise, the
512 * resource specified by {@link #getIconResId()} should be used.
513 * <p>
514 * Clients wishing to display a {@code PhoneAccount} should use {@link #getIcon(Context)}.
515 *
516 * @return A bitmap.
517 */
518 public Bitmap getIconBitmap() {
519 return mIconBitmap;
520 }
521
522 /**
523 * Builds and returns an icon {@code Drawable} to represent this {@code PhoneAccount} in a user
524 * interface. Uses the properties {@link #getIconResId()}, {@link #getIconPackageName()}, and
525 * {@link #getIconBitmap()} as necessary.
526 *
527 * @param context A {@code Context} to use for loading {@code Drawable}s.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700528 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700529 * @return An icon for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700530 */
531 public Drawable getIcon(Context context) {
Ihab Awad074bf102014-10-24 11:42:32 -0700532 if (mIconBitmap != null) {
533 return new BitmapDrawable(context.getResources(), mIconBitmap);
Sailesh Nepal77780a42014-09-26 18:12:00 -0700534 }
535
Ihab Awad074bf102014-10-24 11:42:32 -0700536 if (mIconResId != 0) {
537 String packageName = mIconPackageName == null
538 ? mAccountHandle.getComponentName().getPackageName()
539 : mIconPackageName;
540
541 try {
542 Context packageContext = context.createPackageContext(packageName, 0);
543 try {
544 return packageContext.getDrawable(mIconResId);
545 } catch (NotFoundException | MissingResourceException e) {
546 Log.e(this, e, "Cannot find icon %d in package %s", mIconResId, packageName);
547 }
548 } catch (PackageManager.NameNotFoundException e) {
549 Log.w(this, "Cannot find package %s", packageName);
550 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700551 }
Ihab Awad074bf102014-10-24 11:42:32 -0700552
553 return new ColorDrawable(Color.TRANSPARENT);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700554 }
555
556 //
557 // Parcelable implementation
558 //
559
560 @Override
561 public int describeContents() {
562 return 0;
563 }
564
565 @Override
566 public void writeToParcel(Parcel out, int flags) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700567 out.writeParcelable(mAccountHandle, 0);
Andrew Lee3085a6c2014-09-04 10:59:13 -0700568 out.writeParcelable(mAddress, 0);
569 out.writeParcelable(mSubscriptionAddress, 0);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700570 out.writeInt(mCapabilities);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700571 out.writeInt(mIconResId);
Ihab Awad074bf102014-10-24 11:42:32 -0700572 out.writeString(mIconPackageName);
573 out.writeParcelable(mIconBitmap, 0);
Nancy Chen3ace54b2014-10-22 17:45:26 -0700574 out.writeInt(mColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700575 out.writeCharSequence(mLabel);
576 out.writeCharSequence(mShortDescription);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700577 out.writeList(mSupportedUriSchemes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700578 }
579
Evan Charlton8c8a0622014-07-20 12:31:00 -0700580 public static final Creator<PhoneAccount> CREATOR
581 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700582 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700583 public PhoneAccount createFromParcel(Parcel in) {
584 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700585 }
586
587 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700588 public PhoneAccount[] newArray(int size) {
589 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700590 }
591 };
592
Evan Charlton8c8a0622014-07-20 12:31:00 -0700593 private PhoneAccount(Parcel in) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700594 ClassLoader classLoader = PhoneAccount.class.getClassLoader();
595
Evan Charlton8c8a0622014-07-20 12:31:00 -0700596 mAccountHandle = in.readParcelable(getClass().getClassLoader());
Andrew Lee3085a6c2014-09-04 10:59:13 -0700597 mAddress = in.readParcelable(getClass().getClassLoader());
598 mSubscriptionAddress = in.readParcelable(getClass().getClassLoader());
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700599 mCapabilities = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700600 mIconResId = in.readInt();
Ihab Awad074bf102014-10-24 11:42:32 -0700601 mIconPackageName = in.readString();
602 mIconBitmap = in.readParcelable(getClass().getClassLoader());
Nancy Chen3ace54b2014-10-22 17:45:26 -0700603 mColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700604 mLabel = in.readCharSequence();
605 mShortDescription = in.readCharSequence();
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700606
607 List<String> supportedUriSchemes = new ArrayList<>();
608 in.readList(supportedUriSchemes, classLoader);
609 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700610 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700611
612 @Override
613 public String toString() {
614 StringBuilder sb = new StringBuilder().append("[PhoneAccount: ")
615 .append(mAccountHandle)
616 .append(" Capabilities: ")
617 .append(mCapabilities)
618 .append(" Schemes: ");
619 for (String scheme : mSupportedUriSchemes) {
620 sb.append(scheme)
621 .append(" ");
622 }
623 sb.append("]");
624 return sb.toString();
625 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700626}