blob: 66b52ae1df20af53df1e2ef58d1b3430e4a78767 [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 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070094 * URI scheme for telephone number URIs.
95 */
96 public static final String SCHEME_TEL = "tel";
97
98 /**
99 * URI scheme for voicemail URIs.
100 */
101 public static final String SCHEME_VOICEMAIL = "voicemail";
102
103 /**
104 * URI scheme for SIP URIs.
105 */
106 public static final String SCHEME_SIP = "sip";
107
Evan Charlton8c8a0622014-07-20 12:31:00 -0700108 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700109 private final Uri mAddress;
110 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700111 private final int mCapabilities;
112 private final int mIconResId;
Santos Cordon146a3e32014-07-21 00:00:44 -0700113 private final CharSequence mLabel;
114 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700115 private final List<String> mSupportedUriSchemes;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700116
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700117 public static class Builder {
118 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700119 private Uri mAddress;
120 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700121 private int mCapabilities;
122 private int mIconResId;
123 private CharSequence mLabel;
124 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700125 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700126
Andrew Lee3085a6c2014-09-04 10:59:13 -0700127 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
128 this.mAccountHandle = accountHandle;
129 this.mLabel = label;
130 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700131
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700132 /**
133 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
134 * {@link PhoneAccount}.
135 *
136 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
137 */
138 public Builder(PhoneAccount phoneAccount) {
139 mAccountHandle = phoneAccount.getAccountHandle();
140 mAddress = phoneAccount.getAddress();
141 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
142 mCapabilities = phoneAccount.getCapabilities();
143 mIconResId = phoneAccount.getIconResId();
144 mLabel = phoneAccount.getLabel();
145 mShortDescription = phoneAccount.getShortDescription();
146 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700147 }
148
Andrew Lee3085a6c2014-09-04 10:59:13 -0700149 public Builder setAddress(Uri value) {
150 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700151 return this;
152 }
153
Andrew Lee3085a6c2014-09-04 10:59:13 -0700154 public Builder setSubscriptionAddress(Uri value) {
155 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700156 return this;
157 }
158
Andrew Lee3085a6c2014-09-04 10:59:13 -0700159 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700160 this.mCapabilities = value;
161 return this;
162 }
163
Andrew Lee3085a6c2014-09-04 10:59:13 -0700164 public Builder setIconResId(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700165 this.mIconResId = value;
166 return this;
167 }
168
Andrew Lee3085a6c2014-09-04 10:59:13 -0700169 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700170 this.mShortDescription = value;
171 return this;
172 }
173
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700174 /**
175 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
176 *
177 * @param uriScheme The URI scheme.
178 * @return The Builder.
Andrew Lee3085a6c2014-09-04 10:59:13 -0700179 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700180 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700181 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700182 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
183 this.mSupportedUriSchemes.add(uriScheme);
184 }
185 return this;
186 }
187
188 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700189 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700190 *
191 * @param uriSchemes The URI schemes.
192 * @return The Builder.
193 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700194 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
195 mSupportedUriSchemes.clear();
196
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700197 if (uriSchemes != null && !uriSchemes.isEmpty()) {
198 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700199 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700200 }
201 }
202 return this;
203 }
204
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700205 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700206 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
207 *
208 * @return The {@link PhoneAccount}.
209 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700210 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700211 // If no supported URI schemes were defined, assume "tel" is supported.
212 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700213 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700214 }
215
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700216 return new PhoneAccount(
217 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700218 mAddress,
219 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700220 mCapabilities,
221 mIconResId,
222 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700223 mShortDescription,
Nancy Chen210ef032014-09-15 17:58:42 -0700224 mSupportedUriSchemes);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700225 }
226 }
227
228 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700229 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700230 Uri address,
231 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700232 int capabilities,
Ihab Awad807fe0a2014-07-09 12:30:52 -0700233 int iconResId,
Santos Cordon146a3e32014-07-21 00:00:44 -0700234 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700235 CharSequence shortDescription,
Nancy Chen210ef032014-09-15 17:58:42 -0700236 List<String> supportedUriSchemes) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700237 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700238 mAddress = address;
239 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700240 mCapabilities = capabilities;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700241 mIconResId = iconResId;
242 mLabel = label;
243 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700244 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700245 }
246
Andrew Lee3085a6c2014-09-04 10:59:13 -0700247 public static Builder builder(
248 PhoneAccountHandle accountHandle,
249 CharSequence label) {
250 return new Builder(accountHandle, label);
251 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700252
Ihab Awad807fe0a2014-07-09 12:30:52 -0700253 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700254 * Returns a builder initialized with the current {@link PhoneAccount} instance.
255 *
256 * @return The builder.
257 * @hide
258 */
259 public Builder toBuilder() { return new Builder(this); }
260
261 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700262 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700263 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700264 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700265 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700266 public PhoneAccountHandle getAccountHandle() {
267 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700268 }
269
270 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700271 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700272 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700273 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700274 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700275 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700276 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700277 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700278 public Uri getAddress() {
279 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700280 }
281
282 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700283 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700284 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700285 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000286 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
287 * has been used to alter the callback number.
288 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700289 *
290 * @return The subscription number, suitable for display to the user.
291 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700292 public Uri getSubscriptionAddress() {
293 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700294 }
295
296 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700297 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700298 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700299 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700300 */
301 public int getCapabilities() {
302 return mCapabilities;
303 }
304
305 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700306 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
307 * bit mask.
308 *
309 * @param capability The capabilities to check.
310 * @return {@code True} if the phone account has the capability.
311 */
312 public boolean hasCapabilities(int capability) {
313 return (mCapabilities & capability) == capability;
314 }
315
316 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700317 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700318 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700319 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700320 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700321 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700322 return mLabel;
323 }
324
325 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700326 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700327 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700328 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700329 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700330 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700331 return mShortDescription;
332 }
333
334 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700335 * The URI schemes supported by this {@code PhoneAccount}.
336 *
337 * @return The URI schemes.
338 */
339 public List<String> getSupportedUriSchemes() {
340 return mSupportedUriSchemes;
341 }
342
343 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700344 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700345 * scheme.
346 *
347 * @param uriScheme The URI scheme to check.
Andrew Lee3085a6c2014-09-04 10:59:13 -0700348 * @return {@code True} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700349 * specified URI scheme.
350 */
351 public boolean supportsUriScheme(String uriScheme) {
352 if (mSupportedUriSchemes == null || uriScheme == null) {
353 return false;
354 }
355
356 for (String scheme : mSupportedUriSchemes) {
357 if (scheme != null && scheme.equals(uriScheme)) {
358 return true;
359 }
360 }
361 return false;
362 }
363
364 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700365 * The icon resource ID for the icon of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700366 *
367 * @return A resource ID.
368 */
369 public int getIconResId() {
370 return mIconResId;
371 }
372
373 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700374 * An icon to represent this {@code PhoneAccount} in a user interface.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700375 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700376 * @return An icon for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700377 */
378 public Drawable getIcon(Context context) {
379 return getIcon(context, mIconResId);
380 }
381
382 private Drawable getIcon(Context context, int resId) {
Sailesh Nepal77780a42014-09-26 18:12:00 -0700383 if (resId == 0) {
384 return null;
385 }
386
Ihab Awad807fe0a2014-07-09 12:30:52 -0700387 Context packageContext;
388 try {
389 packageContext = context.createPackageContext(
Evan Charlton8c8a0622014-07-20 12:31:00 -0700390 mAccountHandle.getComponentName().getPackageName(), 0);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700391 } catch (PackageManager.NameNotFoundException e) {
Sailesh Nepal77780a42014-09-26 18:12:00 -0700392 Log.w(this, "Cannot find package %s",
393 mAccountHandle.getComponentName().getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700394 return null;
395 }
396 try {
Alan Viverette03d30a52014-08-14 12:59:10 -0700397 return packageContext.getDrawable(resId);
Santos Cordone8dc4be2014-07-21 01:28:28 -0700398 } catch (NotFoundException|MissingResourceException e) {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700399 Log.e(this, e, "Cannot find icon %d in package %s",
Evan Charlton8c8a0622014-07-20 12:31:00 -0700400 resId, mAccountHandle.getComponentName().getPackageName());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700401 return null;
402 }
403 }
404
405 //
406 // Parcelable implementation
407 //
408
409 @Override
410 public int describeContents() {
411 return 0;
412 }
413
414 @Override
415 public void writeToParcel(Parcel out, int flags) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700416 out.writeParcelable(mAccountHandle, 0);
Andrew Lee3085a6c2014-09-04 10:59:13 -0700417 out.writeParcelable(mAddress, 0);
418 out.writeParcelable(mSubscriptionAddress, 0);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700419 out.writeInt(mCapabilities);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700420 out.writeInt(mIconResId);
Santos Cordon146a3e32014-07-21 00:00:44 -0700421 out.writeCharSequence(mLabel);
422 out.writeCharSequence(mShortDescription);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700423 out.writeList(mSupportedUriSchemes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700424 }
425
Evan Charlton8c8a0622014-07-20 12:31:00 -0700426 public static final Creator<PhoneAccount> CREATOR
427 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700428 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700429 public PhoneAccount createFromParcel(Parcel in) {
430 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700431 }
432
433 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700434 public PhoneAccount[] newArray(int size) {
435 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700436 }
437 };
438
Evan Charlton8c8a0622014-07-20 12:31:00 -0700439 private PhoneAccount(Parcel in) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700440 ClassLoader classLoader = PhoneAccount.class.getClassLoader();
441
Evan Charlton8c8a0622014-07-20 12:31:00 -0700442 mAccountHandle = in.readParcelable(getClass().getClassLoader());
Andrew Lee3085a6c2014-09-04 10:59:13 -0700443 mAddress = in.readParcelable(getClass().getClassLoader());
444 mSubscriptionAddress = in.readParcelable(getClass().getClassLoader());
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700445 mCapabilities = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700446 mIconResId = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700447 mLabel = in.readCharSequence();
448 mShortDescription = in.readCharSequence();
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700449
450 List<String> supportedUriSchemes = new ArrayList<>();
451 in.readList(supportedUriSchemes, classLoader);
452 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700453 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700454
455 @Override
456 public String toString() {
457 StringBuilder sb = new StringBuilder().append("[PhoneAccount: ")
458 .append(mAccountHandle)
459 .append(" Capabilities: ")
460 .append(mCapabilities)
461 .append(" Schemes: ");
462 for (String scheme : mSupportedUriSchemes) {
463 sb.append(scheme)
464 .append(" ");
465 }
466 sb.append("]");
467 return sb.toString();
468 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700469}