blob: 67b63288b46115450e78398481f634fa25074898 [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
Tyler Gunn711d876fd2014-09-19 11:17:02 -070019import android.annotation.SystemApi;
Ihab Awad807fe0a2014-07-09 12:30:52 -070020import android.content.Context;
21import android.content.pm.PackageManager;
Santos Cordone8dc4be2014-07-21 01:28:28 -070022import android.content.res.Resources.NotFoundException;
Ihab Awad807fe0a2014-07-09 12:30:52 -070023import android.graphics.drawable.Drawable;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070024import android.net.Uri;
Ihab Awad807fe0a2014-07-09 12:30:52 -070025import android.os.Parcel;
26import android.os.Parcelable;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070027import android.text.TextUtils;
Ihab Awad807fe0a2014-07-09 12:30:52 -070028
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070029import java.lang.String;
30import java.util.ArrayList;
31import java.util.Collections;
32import java.util.List;
Ihab Awad807fe0a2014-07-09 12:30:52 -070033import java.util.MissingResourceException;
34
35/**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070036 * Describes a distinct account, line of service or call placement method that the system
37 * can use to place phone calls.
Tyler Gunn711d876fd2014-09-19 11:17:02 -070038 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -070039 */
Tyler Gunn711d876fd2014-09-19 11:17:02 -070040@SystemApi
Evan Charlton8c8a0622014-07-20 12:31:00 -070041public class PhoneAccount implements Parcelable {
Ihab Awad94cf4bf2014-07-17 11:21:19 -070042
43 /**
Ihab Awadf8b69882014-07-25 15:14:01 -070044 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
45 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
46 * will be allowed to manage phone calls including using its own proprietary phone-call
47 * implementation (like VoIP calling) to make calls instead of the telephony stack.
48 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -070049 * When a user opts to place a call using the SIM-based telephony stack, the
50 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
51 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -070052 * <p>
53 * See {@link #getCapabilities}
54 */
Ihab Awadf8b69882014-07-25 15:14:01 -070055 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070056
57 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -070058 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -070059 * traditional SIM-based telephony calls. This account will be treated as a distinct method
60 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -070061 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Evan Charlton6eb262c2014-07-19 18:18:19 -070062 * calls from or use the built-in telephony stack to place its calls.
Ihab Awad94cf4bf2014-07-17 11:21:19 -070063 * <p>
64 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -070065 * <p>
Evan Charlton7800fb72014-07-20 18:09:38 -070066 * {@hide}
Ihab Awad94cf4bf2014-07-17 11:21:19 -070067 */
68 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
69
Ihab Awad7522bbd2014-07-18 15:53:17 -070070 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070071 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -070072 * subscription.
Ihab Awad7522bbd2014-07-18 15:53:17 -070073 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -070074 * Only the Android framework can register a {@code PhoneAccount} having this capability.
75 * <p>
76 * See {@link #getCapabilities}
Ihab Awad7522bbd2014-07-18 15:53:17 -070077 */
78 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
79
Ihab Awadf8b69882014-07-25 15:14:01 -070080 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070081 * Flag indicating that this {@code PhoneAccount} is capable of placing video calls.
82 * <p>
83 * See {@link #getCapabilities}
Tyler Gunnbe74de02014-08-29 14:51:48 -070084 * @hide
Ihab Awadf8b69882014-07-25 15:14:01 -070085 */
86 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
87
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070088 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -070089 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
90 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
91 * <p>
92 * See {@link #getCapabilities}
93 */
94 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
95
96 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070097 * URI scheme for telephone number URIs.
98 */
99 public static final String SCHEME_TEL = "tel";
100
101 /**
102 * URI scheme for voicemail URIs.
103 */
104 public static final String SCHEME_VOICEMAIL = "voicemail";
105
106 /**
107 * URI scheme for SIP URIs.
108 */
109 public static final String SCHEME_SIP = "sip";
110
Nancy Chen3ace54b2014-10-22 17:45:26 -0700111 /**
112 * Indicating no color is set.
113 */
114 public static final int NO_COLOR = -1;
115
Evan Charlton8c8a0622014-07-20 12:31:00 -0700116 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700117 private final Uri mAddress;
118 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700119 private final int mCapabilities;
120 private final int mIconResId;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700121 private final int mColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700122 private final CharSequence mLabel;
123 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700124 private final List<String> mSupportedUriSchemes;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700125
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700126 public static class Builder {
127 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700128 private Uri mAddress;
129 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700130 private int mCapabilities;
131 private int mIconResId;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700132 private int mColor = NO_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700133 private CharSequence mLabel;
134 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700135 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700136
Andrew Lee3085a6c2014-09-04 10:59:13 -0700137 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
138 this.mAccountHandle = accountHandle;
139 this.mLabel = label;
140 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700141
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700142 /**
143 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
144 * {@link PhoneAccount}.
145 *
146 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
147 */
148 public Builder(PhoneAccount phoneAccount) {
149 mAccountHandle = phoneAccount.getAccountHandle();
150 mAddress = phoneAccount.getAddress();
151 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
152 mCapabilities = phoneAccount.getCapabilities();
153 mIconResId = phoneAccount.getIconResId();
Nancy Chen3ace54b2014-10-22 17:45:26 -0700154 mColor = phoneAccount.getColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700155 mLabel = phoneAccount.getLabel();
156 mShortDescription = phoneAccount.getShortDescription();
157 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700158 }
159
Andrew Lee3085a6c2014-09-04 10:59:13 -0700160 public Builder setAddress(Uri value) {
161 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700162 return this;
163 }
164
Andrew Lee3085a6c2014-09-04 10:59:13 -0700165 public Builder setSubscriptionAddress(Uri value) {
166 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700167 return this;
168 }
169
Andrew Lee3085a6c2014-09-04 10:59:13 -0700170 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700171 this.mCapabilities = value;
172 return this;
173 }
174
Andrew Lee3085a6c2014-09-04 10:59:13 -0700175 public Builder setIconResId(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700176 this.mIconResId = value;
177 return this;
178 }
179
Nancy Chen3ace54b2014-10-22 17:45:26 -0700180 public Builder setColor(int value) {
181 this.mColor = value;
182 return this;
183 }
184
Andrew Lee3085a6c2014-09-04 10:59:13 -0700185 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700186 this.mShortDescription = value;
187 return this;
188 }
189
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700190 /**
191 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
192 *
193 * @param uriScheme The URI scheme.
194 * @return The Builder.
Andrew Lee3085a6c2014-09-04 10:59:13 -0700195 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700196 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700197 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700198 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
199 this.mSupportedUriSchemes.add(uriScheme);
200 }
201 return this;
202 }
203
204 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700205 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700206 *
207 * @param uriSchemes The URI schemes.
208 * @return The Builder.
209 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700210 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
211 mSupportedUriSchemes.clear();
212
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700213 if (uriSchemes != null && !uriSchemes.isEmpty()) {
214 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700215 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700216 }
217 }
218 return this;
219 }
220
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700221 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700222 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
223 *
224 * @return The {@link PhoneAccount}.
225 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700226 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700227 // If no supported URI schemes were defined, assume "tel" is supported.
228 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700229 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700230 }
231
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700232 return new PhoneAccount(
233 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700234 mAddress,
235 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700236 mCapabilities,
237 mIconResId,
Nancy Chen3ace54b2014-10-22 17:45:26 -0700238 mColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700239 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700240 mShortDescription,
Nancy Chen210ef032014-09-15 17:58:42 -0700241 mSupportedUriSchemes);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700242 }
243 }
244
245 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700246 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700247 Uri address,
248 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700249 int capabilities,
Ihab Awad807fe0a2014-07-09 12:30:52 -0700250 int iconResId,
Nancy Chen3ace54b2014-10-22 17:45:26 -0700251 int color,
Santos Cordon146a3e32014-07-21 00:00:44 -0700252 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700253 CharSequence shortDescription,
Nancy Chen210ef032014-09-15 17:58:42 -0700254 List<String> supportedUriSchemes) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700255 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700256 mAddress = address;
257 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700258 mCapabilities = capabilities;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700259 mIconResId = iconResId;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700260 mColor = color;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700261 mLabel = label;
262 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700263 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700264 }
265
Andrew Lee3085a6c2014-09-04 10:59:13 -0700266 public static Builder builder(
267 PhoneAccountHandle accountHandle,
268 CharSequence label) {
269 return new Builder(accountHandle, label);
270 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700271
Ihab Awad807fe0a2014-07-09 12:30:52 -0700272 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700273 * Returns a builder initialized with the current {@link PhoneAccount} instance.
274 *
275 * @return The builder.
276 * @hide
277 */
278 public Builder toBuilder() { return new Builder(this); }
279
280 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700281 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700282 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700283 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700284 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700285 public PhoneAccountHandle getAccountHandle() {
286 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700287 }
288
289 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700290 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700291 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700292 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700293 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700294 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700295 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700296 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700297 public Uri getAddress() {
298 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700299 }
300
301 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700302 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700303 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700304 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Evan Charlton222db522014-07-17 16:59:18 -0700305 *
306 * @return The subscription number, suitable for display to the user.
307 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700308 public Uri getSubscriptionAddress() {
309 return mSubscriptionAddress;
Evan Charlton222db522014-07-17 16:59:18 -0700310 }
311
312 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700313 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700314 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700315 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700316 */
317 public int getCapabilities() {
318 return mCapabilities;
319 }
320
321 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700322 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
323 * bit mask.
324 *
325 * @param capability The capabilities to check.
326 * @return {@code True} if the phone account has the capability.
327 */
328 public boolean hasCapabilities(int capability) {
329 return (mCapabilities & capability) == capability;
330 }
331
332 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700333 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700334 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700335 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700336 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700337 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700338 return mLabel;
339 }
340
341 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700342 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700343 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700344 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700345 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700346 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700347 return mShortDescription;
348 }
349
350 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700351 * The URI schemes supported by this {@code PhoneAccount}.
352 *
353 * @return The URI schemes.
354 */
355 public List<String> getSupportedUriSchemes() {
356 return mSupportedUriSchemes;
357 }
358
359 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700360 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700361 * scheme.
362 *
363 * @param uriScheme The URI scheme to check.
Andrew Lee3085a6c2014-09-04 10:59:13 -0700364 * @return {@code True} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700365 * specified URI scheme.
366 */
367 public boolean supportsUriScheme(String uriScheme) {
368 if (mSupportedUriSchemes == null || uriScheme == null) {
369 return false;
370 }
371
372 for (String scheme : mSupportedUriSchemes) {
373 if (scheme != null && scheme.equals(uriScheme)) {
374 return true;
375 }
376 }
377 return false;
378 }
379
380 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700381 * The icon resource ID for the icon of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700382 *
383 * @return A resource ID.
384 */
385 public int getIconResId() {
386 return mIconResId;
387 }
388
389 /**
Nancy Chen3ace54b2014-10-22 17:45:26 -0700390 * A highlight color to use in displaying information about this {@code PhoneAccount}.
391 *
392 * @return A hexadecimal color value.
393 */
394 public int getColor() {
395 return mColor;
396 }
397
398 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700399 * An icon to represent this {@code PhoneAccount} in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700400 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700401 * @return An icon for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700402 */
403 public Drawable getIcon(Context context) {
404 return getIcon(context, mIconResId);
405 }
406
407 private Drawable getIcon(Context context, int resId) {
408 Context packageContext;
409 try {
410 packageContext = context.createPackageContext(
Evan Charlton8c8a0622014-07-20 12:31:00 -0700411 mAccountHandle.getComponentName().getPackageName(), 0);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700412 } catch (PackageManager.NameNotFoundException e) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700413 Log.w(this, "Cannot find package %s", mAccountHandle.getComponentName().getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700414 return null;
415 }
416 try {
Alan Viverette03d30a52014-08-14 12:59:10 -0700417 return packageContext.getDrawable(resId);
Santos Cordone8dc4be2014-07-21 01:28:28 -0700418 } catch (NotFoundException|MissingResourceException e) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700419 Log.e(this, e, "Cannot find icon %d in package %s",
Evan Charlton8c8a0622014-07-20 12:31:00 -0700420 resId, mAccountHandle.getComponentName().getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700421 return null;
422 }
423 }
424
425 //
426 // Parcelable implementation
427 //
428
429 @Override
430 public int describeContents() {
431 return 0;
432 }
433
434 @Override
435 public void writeToParcel(Parcel out, int flags) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700436 out.writeParcelable(mAccountHandle, 0);
Andrew Lee3085a6c2014-09-04 10:59:13 -0700437 out.writeParcelable(mAddress, 0);
438 out.writeParcelable(mSubscriptionAddress, 0);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700439 out.writeInt(mCapabilities);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700440 out.writeInt(mIconResId);
Nancy Chen3ace54b2014-10-22 17:45:26 -0700441 out.writeInt(mColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700442 out.writeCharSequence(mLabel);
443 out.writeCharSequence(mShortDescription);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700444 out.writeList(mSupportedUriSchemes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700445 }
446
Evan Charlton8c8a0622014-07-20 12:31:00 -0700447 public static final Creator<PhoneAccount> CREATOR
448 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700449 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700450 public PhoneAccount createFromParcel(Parcel in) {
451 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700452 }
453
454 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700455 public PhoneAccount[] newArray(int size) {
456 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700457 }
458 };
459
Evan Charlton8c8a0622014-07-20 12:31:00 -0700460 private PhoneAccount(Parcel in) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700461 ClassLoader classLoader = PhoneAccount.class.getClassLoader();
462
Evan Charlton8c8a0622014-07-20 12:31:00 -0700463 mAccountHandle = in.readParcelable(getClass().getClassLoader());
Andrew Lee3085a6c2014-09-04 10:59:13 -0700464 mAddress = in.readParcelable(getClass().getClassLoader());
465 mSubscriptionAddress = in.readParcelable(getClass().getClassLoader());
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700466 mCapabilities = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700467 mIconResId = in.readInt();
Nancy Chen3ace54b2014-10-22 17:45:26 -0700468 mColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700469 mLabel = in.readCharSequence();
470 mShortDescription = in.readCharSequence();
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700471
472 List<String> supportedUriSchemes = new ArrayList<>();
473 in.readList(supportedUriSchemes, classLoader);
474 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700475 }
476}