blob: 0c233ebb1ebd41e169517408a8fbda91e3343f97 [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
19import android.content.Context;
20import android.content.pm.PackageManager;
Santos Cordone8dc4be2014-07-21 01:28:28 -070021import android.content.res.Resources.NotFoundException;
Ihab Awad807fe0a2014-07-09 12:30:52 -070022import android.graphics.drawable.Drawable;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070023import android.net.Uri;
Ihab Awad807fe0a2014-07-09 12:30:52 -070024import android.os.Parcel;
25import android.os.Parcelable;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070026import android.text.TextUtils;
Ihab Awad807fe0a2014-07-09 12:30:52 -070027
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070028import java.lang.String;
29import java.util.ArrayList;
30import java.util.Collections;
31import java.util.List;
Ihab Awad807fe0a2014-07-09 12:30:52 -070032import java.util.MissingResourceException;
33
34/**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070035 * Describes a distinct account, line of service or call placement method that the system
36 * can use to place phone calls.
Ihab Awad807fe0a2014-07-09 12:30:52 -070037 */
Evan Charlton8c8a0622014-07-20 12:31:00 -070038public class PhoneAccount implements Parcelable {
Ihab Awad94cf4bf2014-07-17 11:21:19 -070039
40 /**
Ihab Awadf8b69882014-07-25 15:14:01 -070041 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
42 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
43 * will be allowed to manage phone calls including using its own proprietary phone-call
44 * implementation (like VoIP calling) to make calls instead of the telephony stack.
45 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -070046 * When a user opts to place a call using the SIM-based telephony stack, the
47 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
48 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -070049 * <p>
50 * See {@link #getCapabilities}
51 */
Ihab Awadf8b69882014-07-25 15:14:01 -070052 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070053
54 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -070055 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -070056 * traditional SIM-based telephony calls. This account will be treated as a distinct method
57 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -070058 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Evan Charlton6eb262c2014-07-19 18:18:19 -070059 * calls from or use the built-in telephony stack to place its calls.
Ihab Awad94cf4bf2014-07-17 11:21:19 -070060 * <p>
61 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -070062 * <p>
Evan Charlton7800fb72014-07-20 18:09:38 -070063 * {@hide}
Ihab Awad94cf4bf2014-07-17 11:21:19 -070064 */
65 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
66
Ihab Awad7522bbd62014-07-18 15:53:17 -070067 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070068 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -070069 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -070070 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -070071 * Only the Android framework can register a {@code PhoneAccount} having this capability.
72 * <p>
73 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -070074 */
75 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
76
Ihab Awadf8b69882014-07-25 15:14:01 -070077 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070078 * Flag indicating that this {@code PhoneAccount} is capable of placing video calls.
79 * <p>
80 * See {@link #getCapabilities}
Tyler Gunnbe74de02014-08-29 14:51:48 -070081 * @hide
Ihab Awadf8b69882014-07-25 15:14:01 -070082 */
83 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
84
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070085 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -070086 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
87 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
88 * <p>
89 * See {@link #getCapabilities}
90 */
91 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
92
93 /**
94 * Flag indicating that this {@code PhoneAccount} is always enabled and cannot be disabled by
95 * the user.
96 * This capability is reserved for important {@code PhoneAccount}s such as the emergency calling
97 * only {@code PhoneAccount}.
98 * <p>
99 * See {@link #getCapabilities}
100 * @hide
101 */
102 public static final int CAPABILITY_ALWAYS_ENABLED = 0x20;
103
104 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700105 * URI scheme for telephone number URIs.
106 */
107 public static final String SCHEME_TEL = "tel";
108
109 /**
110 * URI scheme for voicemail URIs.
111 */
112 public static final String SCHEME_VOICEMAIL = "voicemail";
113
114 /**
115 * URI scheme for SIP URIs.
116 */
117 public static final String SCHEME_SIP = "sip";
118
Evan Charlton8c8a0622014-07-20 12:31:00 -0700119 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700120 private final Uri mAddress;
121 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700122 private final int mCapabilities;
123 private final int mIconResId;
Santos Cordon146a3e32014-07-21 00:00:44 -0700124 private final CharSequence mLabel;
125 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700126 private final List<String> mSupportedUriSchemes;
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700127 private final boolean mIsEnabled;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700128
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700129 public static class Builder {
130 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700131 private Uri mAddress;
132 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700133 private int mCapabilities;
134 private int mIconResId;
135 private CharSequence mLabel;
136 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700137 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700138 private boolean mIsEnabled = false;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700139
Andrew Lee3085a6c2014-09-04 10:59:13 -0700140 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
141 this.mAccountHandle = accountHandle;
142 this.mLabel = label;
143 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700144
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700145 /**
146 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
147 * {@link PhoneAccount}.
148 *
149 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
150 */
151 public Builder(PhoneAccount phoneAccount) {
152 mAccountHandle = phoneAccount.getAccountHandle();
153 mAddress = phoneAccount.getAddress();
154 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
155 mCapabilities = phoneAccount.getCapabilities();
156 mIconResId = phoneAccount.getIconResId();
157 mLabel = phoneAccount.getLabel();
158 mShortDescription = phoneAccount.getShortDescription();
159 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
160 mIsEnabled = phoneAccount.isEnabled();
161 }
162
Andrew Lee3085a6c2014-09-04 10:59:13 -0700163 public Builder setAddress(Uri value) {
164 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700165 return this;
166 }
167
Andrew Lee3085a6c2014-09-04 10:59:13 -0700168 public Builder setSubscriptionAddress(Uri value) {
169 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700170 return this;
171 }
172
Andrew Lee3085a6c2014-09-04 10:59:13 -0700173 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700174 this.mCapabilities = value;
175 return this;
176 }
177
Andrew Lee3085a6c2014-09-04 10:59:13 -0700178 public Builder setIconResId(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700179 this.mIconResId = value;
180 return this;
181 }
182
Andrew Lee3085a6c2014-09-04 10:59:13 -0700183 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700184 this.mShortDescription = value;
185 return this;
186 }
187
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700188 /**
189 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
190 *
191 * @param uriScheme The URI scheme.
192 * @return The Builder.
Andrew Lee3085a6c2014-09-04 10:59:13 -0700193 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700194 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700195 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700196 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
197 this.mSupportedUriSchemes.add(uriScheme);
198 }
199 return this;
200 }
201
202 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700203 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700204 *
205 * @param uriSchemes The URI schemes.
206 * @return The Builder.
207 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700208 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
209 mSupportedUriSchemes.clear();
210
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700211 if (uriSchemes != null && !uriSchemes.isEmpty()) {
212 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700213 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700214 }
215 }
216 return this;
217 }
218
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700219 /**
220 * Specifies whether the {@link PhoneAccount} is enabled or not. {@link PhoneAccount}s are
221 * by default not enabled.
222 *
223 * @param value {@code True} if the {@link PhoneAccount} is enabled.
224 * @return The Builder.
225 * @hide
226 */
227 public Builder setEnabled(boolean value) {
228 this.mIsEnabled = value;
229 return this;
230 }
231
232 /**
233 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
234 *
235 * @return The {@link PhoneAccount}.
236 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700237 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700238 // If no supported URI schemes were defined, assume "tel" is supported.
239 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700240 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700241 }
242
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700243 return new PhoneAccount(
244 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700245 mAddress,
246 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700247 mCapabilities,
248 mIconResId,
249 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700250 mShortDescription,
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700251 mSupportedUriSchemes,
252 mIsEnabled);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700253 }
254 }
255
256 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700257 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700258 Uri address,
259 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700260 int capabilities,
Ihab Awad807fe0a2014-07-09 12:30:52 -0700261 int iconResId,
Santos Cordon146a3e32014-07-21 00:00:44 -0700262 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700263 CharSequence shortDescription,
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700264 List<String> supportedUriSchemes,
265 boolean enabled) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700266 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700267 mAddress = address;
268 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700269 mCapabilities = capabilities;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700270 mIconResId = iconResId;
271 mLabel = label;
272 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700273 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700274 mIsEnabled = enabled;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700275 }
276
Andrew Lee3085a6c2014-09-04 10:59:13 -0700277 public static Builder builder(
278 PhoneAccountHandle accountHandle,
279 CharSequence label) {
280 return new Builder(accountHandle, label);
281 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700282
Ihab Awad807fe0a2014-07-09 12:30:52 -0700283 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700284 * Returns a builder initialized with the current {@link PhoneAccount} instance.
285 *
286 * @return The builder.
287 * @hide
288 */
289 public Builder toBuilder() { return new Builder(this); }
290
291 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700292 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700293 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700294 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700295 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700296 public PhoneAccountHandle getAccountHandle() {
297 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700298 }
299
300 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700301 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700302 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700303 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700304 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700305 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700306 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700307 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700308 public Uri getAddress() {
309 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700310 }
311
312 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700313 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700314 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700315 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
316 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700317 * has been used to alter the callback number.
318 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700319 *
320 * @return The subscription number, suitable for display to the user.
321 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700322 public Uri getSubscriptionAddress() {
323 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700324 }
325
326 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700327 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700328 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700329 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700330 */
331 public int getCapabilities() {
332 return mCapabilities;
333 }
334
335 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700336 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
337 * bit mask.
338 *
339 * @param capability The capabilities to check.
340 * @return {@code True} if the phone account has the capability.
341 */
342 public boolean hasCapabilities(int capability) {
343 return (mCapabilities & capability) == capability;
344 }
345
346 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700347 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700348 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700349 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700350 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700351 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700352 return mLabel;
353 }
354
355 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700356 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700357 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700358 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700359 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700360 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700361 return mShortDescription;
362 }
363
364 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700365 * The URI schemes supported by this {@code PhoneAccount}.
366 *
367 * @return The URI schemes.
368 */
369 public List<String> getSupportedUriSchemes() {
370 return mSupportedUriSchemes;
371 }
372
373 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700374 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700375 * scheme.
376 *
377 * @param uriScheme The URI scheme to check.
Andrew Lee3085a6c2014-09-04 10:59:13 -0700378 * @return {@code True} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700379 * specified URI scheme.
380 */
381 public boolean supportsUriScheme(String uriScheme) {
382 if (mSupportedUriSchemes == null || uriScheme == null) {
383 return false;
384 }
385
386 for (String scheme : mSupportedUriSchemes) {
387 if (scheme != null && scheme.equals(uriScheme)) {
388 return true;
389 }
390 }
391 return false;
392 }
393
394 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700395 * Determines whether this {@code PhoneAccount} is enabled.
396 *
397 * @return {@code True} if this {@code PhoneAccount} is enabled..
398 */
399 public boolean isEnabled() {
400 return mIsEnabled;
401 }
402
403 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700404 * The icon resource ID for the icon of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700405 *
406 * @return A resource ID.
407 */
408 public int getIconResId() {
409 return mIconResId;
410 }
411
412 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700413 * An icon to represent this {@code PhoneAccount} in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700414 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700415 * @return An icon for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700416 */
417 public Drawable getIcon(Context context) {
418 return getIcon(context, mIconResId);
419 }
420
421 private Drawable getIcon(Context context, int resId) {
422 Context packageContext;
423 try {
424 packageContext = context.createPackageContext(
Evan Charlton8c8a0622014-07-20 12:31:00 -0700425 mAccountHandle.getComponentName().getPackageName(), 0);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700426 } catch (PackageManager.NameNotFoundException e) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700427 Log.w(this, "Cannot find package %s", mAccountHandle.getComponentName().getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700428 return null;
429 }
430 try {
Alan Viverette03d30a52014-08-14 12:59:10 -0700431 return packageContext.getDrawable(resId);
Santos Cordone8dc4be2014-07-21 01:28:28 -0700432 } catch (NotFoundException|MissingResourceException e) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700433 Log.e(this, e, "Cannot find icon %d in package %s",
Evan Charlton8c8a0622014-07-20 12:31:00 -0700434 resId, mAccountHandle.getComponentName().getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700435 return null;
436 }
437 }
438
439 //
440 // Parcelable implementation
441 //
442
443 @Override
444 public int describeContents() {
445 return 0;
446 }
447
448 @Override
449 public void writeToParcel(Parcel out, int flags) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700450 out.writeParcelable(mAccountHandle, 0);
Andrew Lee3085a6c2014-09-04 10:59:13 -0700451 out.writeParcelable(mAddress, 0);
452 out.writeParcelable(mSubscriptionAddress, 0);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700453 out.writeInt(mCapabilities);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700454 out.writeInt(mIconResId);
Santos Cordon146a3e32014-07-21 00:00:44 -0700455 out.writeCharSequence(mLabel);
456 out.writeCharSequence(mShortDescription);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700457 out.writeList(mSupportedUriSchemes);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700458 out.writeInt(mIsEnabled ? 1 : 0);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700459 }
460
Evan Charlton8c8a0622014-07-20 12:31:00 -0700461 public static final Creator<PhoneAccount> CREATOR
462 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700463 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700464 public PhoneAccount createFromParcel(Parcel in) {
465 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700466 }
467
468 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700469 public PhoneAccount[] newArray(int size) {
470 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700471 }
472 };
473
Evan Charlton8c8a0622014-07-20 12:31:00 -0700474 private PhoneAccount(Parcel in) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700475 ClassLoader classLoader = PhoneAccount.class.getClassLoader();
476
Evan Charlton8c8a0622014-07-20 12:31:00 -0700477 mAccountHandle = in.readParcelable(getClass().getClassLoader());
Andrew Lee3085a6c2014-09-04 10:59:13 -0700478 mAddress = in.readParcelable(getClass().getClassLoader());
479 mSubscriptionAddress = in.readParcelable(getClass().getClassLoader());
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700480 mCapabilities = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700481 mIconResId = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700482 mLabel = in.readCharSequence();
483 mShortDescription = in.readCharSequence();
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700484
485 List<String> supportedUriSchemes = new ArrayList<>();
486 in.readList(supportedUriSchemes, classLoader);
487 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700488 mIsEnabled = in.readInt() == 1;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700489 }
490}