blob: bab460dfb71e8cace21c5a064844f29f0be5c18c [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
Brian Attwellad147f42014-12-19 11:37:16 -080043 * this class and register it with the system using {@link TelecomManager}.
Santos Cordon32c65a52014-10-27 14:57:49 -070044 * <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
Brian Attwellad147f42014-12-19 11:37:16 -080047 * should supply a valid {@link PhoneAccountHandle} that references the connection service
Santos Cordon32c65a52014-10-27 14:57:49 -070048 * implementation Telecom will use to interact with the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -070049 */
Evan Charlton8c8a0622014-07-20 12:31:00 -070050public class PhoneAccount implements Parcelable {
Ihab Awad94cf4bf2014-07-17 11:21:19 -070051
52 /**
Ihab Awadf8b69882014-07-25 15:14:01 -070053 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
54 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
55 * will be allowed to manage phone calls including using its own proprietary phone-call
56 * implementation (like VoIP calling) to make calls instead of the telephony stack.
57 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -070058 * When a user opts to place a call using the SIM-based telephony stack, the
59 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
60 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -070061 * <p>
62 * See {@link #getCapabilities}
63 */
Ihab Awadf8b69882014-07-25 15:14:01 -070064 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070065
66 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -070067 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -070068 * traditional SIM-based telephony calls. This account will be treated as a distinct method
69 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -070070 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -070071 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -070072 * <p>
73 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -070074 * <p>
Ihab Awad94cf4bf2014-07-17 11:21:19 -070075 */
76 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
77
Ihab Awad7522bbd62014-07-18 15:53:17 -070078 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070079 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -070080 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -070081 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -070082 * Only the Android framework can register a {@code PhoneAccount} having this capability.
83 * <p>
84 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -070085 */
86 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
87
Ihab Awadf8b69882014-07-25 15:14:01 -070088 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070089 * Flag indicating that this {@code PhoneAccount} is capable of placing video calls.
90 * <p>
91 * See {@link #getCapabilities}
Ihab Awadf8b69882014-07-25 15:14:01 -070092 */
93 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
94
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070095 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -070096 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
97 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
98 * <p>
99 * See {@link #getCapabilities}
100 */
101 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
102
103 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800104 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
105 * should only be used by system apps (and will be ignored for all other apps trying to use it).
106 * <p>
107 * See {@link #getCapabilities}
108 * @hide
109 */
Brian Attwellad147f42014-12-19 11:37:16 -0800110 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800111 public static final int CAPABILITY_MULTI_USER = 0x20;
112
113 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700114 * URI scheme for telephone number URIs.
115 */
116 public static final String SCHEME_TEL = "tel";
117
118 /**
119 * URI scheme for voicemail URIs.
120 */
121 public static final String SCHEME_VOICEMAIL = "voicemail";
122
123 /**
124 * URI scheme for SIP URIs.
125 */
126 public static final String SCHEME_SIP = "sip";
127
Nancy Chen3ace54b2014-10-22 17:45:26 -0700128 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800129 * Indicating no icon tint is set.
Nancy Chen3ace54b2014-10-22 17:45:26 -0700130 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800131 public static final int NO_ICON_TINT = 0;
132
133 /**
134 * Indicating no hightlight color is set.
135 */
136 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700137
Ihab Awad476cc832014-11-03 09:47:51 -0800138 /**
139 * Indicating no resource ID is set.
140 */
141 public static final int NO_RESOURCE_ID = -1;
142
Evan Charlton8c8a0622014-07-20 12:31:00 -0700143 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700144 private final Uri mAddress;
145 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700146 private final int mCapabilities;
147 private final int mIconResId;
Ihab Awad074bf102014-10-24 11:42:32 -0700148 private final String mIconPackageName;
149 private final Bitmap mIconBitmap;
Ihab Awad476cc832014-11-03 09:47:51 -0800150 private final int mIconTint;
151 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700152 private final CharSequence mLabel;
153 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700154 private final List<String> mSupportedUriSchemes;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700155
Santos Cordon32c65a52014-10-27 14:57:49 -0700156 /**
157 * Helper class for creating a {@link PhoneAccount}.
158 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700159 public static class Builder {
160 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700161 private Uri mAddress;
162 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700163 private int mCapabilities;
164 private int mIconResId;
Ihab Awad074bf102014-10-24 11:42:32 -0700165 private String mIconPackageName;
166 private Bitmap mIconBitmap;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800167 private int mIconTint = NO_ICON_TINT;
168 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700169 private CharSequence mLabel;
170 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700171 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700172
Santos Cordon32c65a52014-10-27 14:57:49 -0700173 /**
174 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
175 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700176 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
177 this.mAccountHandle = accountHandle;
178 this.mLabel = label;
179 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700180
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700181 /**
182 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
183 * {@link PhoneAccount}.
184 *
185 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
186 */
187 public Builder(PhoneAccount phoneAccount) {
188 mAccountHandle = phoneAccount.getAccountHandle();
189 mAddress = phoneAccount.getAddress();
190 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
191 mCapabilities = phoneAccount.getCapabilities();
192 mIconResId = phoneAccount.getIconResId();
Ihab Awad074bf102014-10-24 11:42:32 -0700193 mIconPackageName = phoneAccount.getIconPackageName();
194 mIconBitmap = phoneAccount.getIconBitmap();
Ihab Awad476cc832014-11-03 09:47:51 -0800195 mIconTint = phoneAccount.getIconTint();
196 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700197 mLabel = phoneAccount.getLabel();
198 mShortDescription = phoneAccount.getShortDescription();
199 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700200 }
201
Santos Cordon32c65a52014-10-27 14:57:49 -0700202 /**
203 * Sets the address. See {@link PhoneAccount#getAddress}.
204 *
205 * @param value The address of the phone account.
206 * @return The builder.
207 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700208 public Builder setAddress(Uri value) {
209 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700210 return this;
211 }
212
Santos Cordon32c65a52014-10-27 14:57:49 -0700213 /**
214 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
215 *
216 * @param value The subscription address.
217 * @return The builder.
218 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700219 public Builder setSubscriptionAddress(Uri value) {
220 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700221 return this;
222 }
223
Santos Cordon32c65a52014-10-27 14:57:49 -0700224 /**
225 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
226 *
227 * @param value The capabilities to set.
228 * @return The builder.
229 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700230 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700231 this.mCapabilities = value;
232 return this;
233 }
234
Santos Cordon32c65a52014-10-27 14:57:49 -0700235 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800236 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700237 *
Ihab Awad476cc832014-11-03 09:47:51 -0800238 * @param packageContext The package from which to load an icon.
239 * @param iconResId The resource in {@code iconPackageName} representing the icon.
Santos Cordon32c65a52014-10-27 14:57:49 -0700240 * @return The builder.
241 */
Ihab Awad476cc832014-11-03 09:47:51 -0800242 public Builder setIcon(Context packageContext, int iconResId) {
243 return setIcon(packageContext.getPackageName(), iconResId);
244 }
245
246 /**
247 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
248 *
249 * @param iconPackageName The package from which to load an icon.
250 * @param iconResId The resource in {@code iconPackageName} representing the icon.
251 * @return The builder.
252 */
253 public Builder setIcon(String iconPackageName, int iconResId) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800254 return setIcon(iconPackageName, iconResId, NO_ICON_TINT);
Ihab Awad476cc832014-11-03 09:47:51 -0800255 }
256
257 /**
258 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
259 *
260 * @param packageContext The package from which to load an icon.
261 * @param iconResId The resource in {@code iconPackageName} representing the icon.
262 * @param iconTint A color with which to tint this icon.
263 * @return The builder.
264 */
265 public Builder setIcon(Context packageContext, int iconResId, int iconTint) {
266 return setIcon(packageContext.getPackageName(), iconResId, iconTint);
267 }
268
269 /**
270 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
271 *
272 * @param iconPackageName The package from which to load an icon.
273 * @param iconResId The resource in {@code iconPackageName} representing the icon.
274 * @param iconTint A color with which to tint this icon.
275 * @return The builder.
276 */
277 public Builder setIcon(String iconPackageName, int iconResId, int iconTint) {
278 this.mIconPackageName = iconPackageName;
279 this.mIconResId = iconResId;
280 this.mIconTint = iconTint;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700281 return this;
282 }
283
Ihab Awad074bf102014-10-24 11:42:32 -0700284 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800285 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
Ihab Awad074bf102014-10-24 11:42:32 -0700286 *
Ihab Awad476cc832014-11-03 09:47:51 -0800287 * @param iconBitmap The icon bitmap.
Ihab Awad074bf102014-10-24 11:42:32 -0700288 * @return The builder.
289 */
Ihab Awad476cc832014-11-03 09:47:51 -0800290 public Builder setIcon(Bitmap iconBitmap) {
291 this.mIconBitmap = iconBitmap;
292 this.mIconPackageName = null;
293 this.mIconResId = NO_RESOURCE_ID;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800294 this.mIconTint = NO_ICON_TINT;
Ihab Awad074bf102014-10-24 11:42:32 -0700295 return this;
296 }
297
298 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800299 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700300 *
Ihab Awad476cc832014-11-03 09:47:51 -0800301 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700302 * @return The builder.
303 */
Ihab Awad476cc832014-11-03 09:47:51 -0800304 public Builder setHighlightColor(int value) {
305 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700306 return this;
307 }
308
Santos Cordon32c65a52014-10-27 14:57:49 -0700309 /**
310 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
311 *
312 * @param value The short description.
313 * @return The builder.
314 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700315 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700316 this.mShortDescription = value;
317 return this;
318 }
319
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700320 /**
321 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
322 *
323 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700324 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700325 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700326 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700327 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
328 this.mSupportedUriSchemes.add(uriScheme);
329 }
330 return this;
331 }
332
333 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700334 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700335 *
336 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700337 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700338 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700339 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
340 mSupportedUriSchemes.clear();
341
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700342 if (uriSchemes != null && !uriSchemes.isEmpty()) {
343 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700344 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700345 }
346 }
347 return this;
348 }
349
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700350 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700351 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
352 *
353 * @return The {@link PhoneAccount}.
354 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700355 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700356 // If no supported URI schemes were defined, assume "tel" is supported.
357 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700358 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700359 }
360
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700361 return new PhoneAccount(
362 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700363 mAddress,
364 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700365 mCapabilities,
366 mIconResId,
Ihab Awad074bf102014-10-24 11:42:32 -0700367 mIconPackageName,
368 mIconBitmap,
Ihab Awad476cc832014-11-03 09:47:51 -0800369 mIconTint,
370 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700371 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700372 mShortDescription,
Nancy Chen210ef032014-09-15 17:58:42 -0700373 mSupportedUriSchemes);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700374 }
375 }
376
377 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700378 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700379 Uri address,
380 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700381 int capabilities,
Ihab Awad807fe0a2014-07-09 12:30:52 -0700382 int iconResId,
Ihab Awad074bf102014-10-24 11:42:32 -0700383 String iconPackageName,
384 Bitmap iconBitmap,
Ihab Awad476cc832014-11-03 09:47:51 -0800385 int iconTint,
386 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700387 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700388 CharSequence shortDescription,
Nancy Chen210ef032014-09-15 17:58:42 -0700389 List<String> supportedUriSchemes) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700390 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700391 mAddress = address;
392 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700393 mCapabilities = capabilities;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700394 mIconResId = iconResId;
Ihab Awad074bf102014-10-24 11:42:32 -0700395 mIconPackageName = iconPackageName;
396 mIconBitmap = iconBitmap;
Ihab Awad476cc832014-11-03 09:47:51 -0800397 mIconTint = iconTint;
398 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700399 mLabel = label;
400 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700401 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700402 }
403
Andrew Lee3085a6c2014-09-04 10:59:13 -0700404 public static Builder builder(
405 PhoneAccountHandle accountHandle,
406 CharSequence label) {
407 return new Builder(accountHandle, label);
408 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700409
Ihab Awad807fe0a2014-07-09 12:30:52 -0700410 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700411 * Returns a builder initialized with the current {@link PhoneAccount} instance.
412 *
413 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700414 */
415 public Builder toBuilder() { return new Builder(this); }
416
417 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700418 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700419 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700420 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700421 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700422 public PhoneAccountHandle getAccountHandle() {
423 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700424 }
425
426 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700427 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700428 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700429 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700430 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700431 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700432 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700433 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700434 public Uri getAddress() {
435 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700436 }
437
438 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700439 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700440 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700441 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000442 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
443 * has been used to alter the callback number.
444 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700445 *
446 * @return The subscription number, suitable for display to the user.
447 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700448 public Uri getSubscriptionAddress() {
449 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700450 }
451
452 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700453 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700454 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700455 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700456 */
457 public int getCapabilities() {
458 return mCapabilities;
459 }
460
461 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700462 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
463 * bit mask.
464 *
465 * @param capability The capabilities to check.
466 * @return {@code True} if the phone account has the capability.
467 */
468 public boolean hasCapabilities(int capability) {
469 return (mCapabilities & capability) == capability;
470 }
471
472 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700473 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700474 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700475 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700476 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700477 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700478 return mLabel;
479 }
480
481 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700482 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700483 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700484 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700485 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700486 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700487 return mShortDescription;
488 }
489
490 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700491 * The URI schemes supported by this {@code PhoneAccount}.
492 *
493 * @return The URI schemes.
494 */
495 public List<String> getSupportedUriSchemes() {
496 return mSupportedUriSchemes;
497 }
498
499 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700500 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700501 * scheme.
502 *
503 * @param uriScheme The URI scheme to check.
Andrew Lee3085a6c2014-09-04 10:59:13 -0700504 * @return {@code True} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700505 * specified URI scheme.
506 */
507 public boolean supportsUriScheme(String uriScheme) {
508 if (mSupportedUriSchemes == null || uriScheme == null) {
509 return false;
510 }
511
512 for (String scheme : mSupportedUriSchemes) {
513 if (scheme != null && scheme.equals(uriScheme)) {
514 return true;
515 }
516 }
517 return false;
518 }
519
520 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700521 * The icon resource ID for the icon of this {@code PhoneAccount}.
522 * <p>
523 * Creators of a {@code PhoneAccount} who possess the icon in static resources should prefer
524 * this method of indicating the icon rather than using {@link #getIconBitmap()}, since it
525 * leads to less resource usage.
526 * <p>
Ihab Awad476cc832014-11-03 09:47:51 -0800527 * Clients wishing to display a {@code PhoneAccount} should use {@link #createIconDrawable(Context)}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700528 *
529 * @return A resource ID.
530 */
531 public int getIconResId() {
532 return mIconResId;
533 }
534
535 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700536 * The package name from which to load the icon of this {@code PhoneAccount}.
537 * <p>
538 * If this property is {@code null}, the resource {@link #getIconResId()} will be loaded from
539 * the package in the {@link ComponentName} of the {@link #getAccountHandle()}.
540 * <p>
Ihab Awad476cc832014-11-03 09:47:51 -0800541 * Clients wishing to display a {@code PhoneAccount} should use {@link #createIconDrawable(Context)}.
Ihab Awad074bf102014-10-24 11:42:32 -0700542 *
543 * @return A package name.
544 */
545 public String getIconPackageName() {
546 return mIconPackageName;
547 }
548
549 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800550 * A tint to apply to the icon of this {@code PhoneAccount}.
Nancy Chen3ace54b2014-10-22 17:45:26 -0700551 *
552 * @return A hexadecimal color value.
553 */
Ihab Awad476cc832014-11-03 09:47:51 -0800554 public int getIconTint() {
555 return mIconTint;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700556 }
557
558 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700559 * A literal icon bitmap to represent this {@code PhoneAccount} in a user interface.
560 * <p>
561 * If this property is specified, it is to be considered the preferred icon. Otherwise, the
562 * resource specified by {@link #getIconResId()} should be used.
563 * <p>
Ihab Awad476cc832014-11-03 09:47:51 -0800564 * Clients wishing to display a {@code PhoneAccount} should use
565 * {@link #createIconDrawable(Context)}.
Ihab Awad074bf102014-10-24 11:42:32 -0700566 *
567 * @return A bitmap.
568 */
569 public Bitmap getIconBitmap() {
570 return mIconBitmap;
571 }
572
573 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800574 * A highlight color to use in displaying information about this {@code PhoneAccount}.
575 *
576 * @return A hexadecimal color value.
577 */
578 public int getHighlightColor() {
579 return mHighlightColor;
580 }
581
582 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700583 * Builds and returns an icon {@code Drawable} to represent this {@code PhoneAccount} in a user
584 * interface. Uses the properties {@link #getIconResId()}, {@link #getIconPackageName()}, and
585 * {@link #getIconBitmap()} as necessary.
586 *
587 * @param context A {@code Context} to use for loading {@code Drawable}s.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700588 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700589 * @return An icon for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700590 */
Ihab Awad476cc832014-11-03 09:47:51 -0800591 public Drawable createIconDrawable(Context context) {
Ihab Awad074bf102014-10-24 11:42:32 -0700592 if (mIconBitmap != null) {
593 return new BitmapDrawable(context.getResources(), mIconBitmap);
Sailesh Nepal77780a42014-09-26 18:12:00 -0700594 }
595
Ihab Awad074bf102014-10-24 11:42:32 -0700596 if (mIconResId != 0) {
Ihab Awad074bf102014-10-24 11:42:32 -0700597 try {
Ihab Awad476cc832014-11-03 09:47:51 -0800598 Context packageContext = context.createPackageContext(mIconPackageName, 0);
Ihab Awad074bf102014-10-24 11:42:32 -0700599 try {
Ihab Awad476cc832014-11-03 09:47:51 -0800600 Drawable iconDrawable = packageContext.getDrawable(mIconResId);
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800601 if (mIconTint != NO_ICON_TINT) {
Ihab Awad476cc832014-11-03 09:47:51 -0800602 iconDrawable.setTint(mIconTint);
603 }
604 return iconDrawable;
Ihab Awad074bf102014-10-24 11:42:32 -0700605 } catch (NotFoundException | MissingResourceException e) {
Ihab Awad476cc832014-11-03 09:47:51 -0800606 Log.e(this, e, "Cannot find icon %d in package %s",
607 mIconResId, mIconPackageName);
Ihab Awad074bf102014-10-24 11:42:32 -0700608 }
609 } catch (PackageManager.NameNotFoundException e) {
Ihab Awad476cc832014-11-03 09:47:51 -0800610 Log.w(this, "Cannot find package %s", mIconPackageName);
Ihab Awad074bf102014-10-24 11:42:32 -0700611 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700612 }
Ihab Awad074bf102014-10-24 11:42:32 -0700613
614 return new ColorDrawable(Color.TRANSPARENT);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700615 }
616
617 //
618 // Parcelable implementation
619 //
620
621 @Override
622 public int describeContents() {
623 return 0;
624 }
625
626 @Override
627 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800628 if (mAccountHandle == null) {
629 out.writeInt(0);
630 } else {
631 out.writeInt(1);
632 mAccountHandle.writeToParcel(out, flags);
633 }
634 if (mAddress == null) {
635 out.writeInt(0);
636 } else {
637 out.writeInt(1);
638 mAddress.writeToParcel(out, flags);
639 }
640 if (mSubscriptionAddress == null) {
641 out.writeInt(0);
642 } else {
643 out.writeInt(1);
644 mSubscriptionAddress.writeToParcel(out, flags);
645 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700646 out.writeInt(mCapabilities);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700647 out.writeInt(mIconResId);
Ihab Awad074bf102014-10-24 11:42:32 -0700648 out.writeString(mIconPackageName);
Ihab Awad476cc832014-11-03 09:47:51 -0800649 if (mIconBitmap == null) {
650 out.writeInt(0);
651 } else {
Ihab Awad96802ad2014-11-11 18:41:39 -0800652 out.writeInt(1);
Ihab Awad476cc832014-11-03 09:47:51 -0800653 mIconBitmap.writeToParcel(out, flags);
654 }
655 out.writeInt(mIconTint);
656 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700657 out.writeCharSequence(mLabel);
658 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800659 out.writeStringList(mSupportedUriSchemes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700660 }
661
Evan Charlton8c8a0622014-07-20 12:31:00 -0700662 public static final Creator<PhoneAccount> CREATOR
663 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700664 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700665 public PhoneAccount createFromParcel(Parcel in) {
666 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700667 }
668
669 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700670 public PhoneAccount[] newArray(int size) {
671 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700672 }
673 };
674
Evan Charlton8c8a0622014-07-20 12:31:00 -0700675 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800676 if (in.readInt() > 0) {
677 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
678 } else {
679 mAccountHandle = null;
680 }
681 if (in.readInt() > 0) {
682 mAddress = Uri.CREATOR.createFromParcel(in);
683 } else {
684 mAddress = null;
685 }
686 if (in.readInt() > 0) {
687 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
688 } else {
689 mSubscriptionAddress = null;
690 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700691 mCapabilities = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700692 mIconResId = in.readInt();
Ihab Awad074bf102014-10-24 11:42:32 -0700693 mIconPackageName = in.readString();
Ihab Awad476cc832014-11-03 09:47:51 -0800694 if (in.readInt() > 0) {
695 mIconBitmap = Bitmap.CREATOR.createFromParcel(in);
696 } else {
697 mIconBitmap = null;
698 }
699 mIconTint = in.readInt();
700 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700701 mLabel = in.readCharSequence();
702 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800703 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700704 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700705
706 @Override
707 public String toString() {
708 StringBuilder sb = new StringBuilder().append("[PhoneAccount: ")
709 .append(mAccountHandle)
710 .append(" Capabilities: ")
711 .append(mCapabilities)
712 .append(" Schemes: ");
713 for (String scheme : mSupportedUriSchemes) {
714 sb.append(scheme)
715 .append(" ");
716 }
717 sb.append("]");
718 return sb.toString();
719 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700720}