blob: a49c204f6aed7dfb0848014f719a0dd53d8c9a29 [file] [log] [blame]
Ihab Awad807fe0a2014-07-09 12:30:52 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad807fe0a2014-07-09 12:30:52 -070018
Evan Charlton0e094d92014-11-08 15:49:16 -080019import android.annotation.SystemApi;
Ihab Awad074bf102014-10-24 11:42:32 -070020import android.content.ComponentName;
Ihab Awad807fe0a2014-07-09 12:30:52 -070021import android.content.Context;
22import android.content.pm.PackageManager;
Santos Cordone8dc4be2014-07-21 01:28:28 -070023import android.content.res.Resources.NotFoundException;
Ihab Awad074bf102014-10-24 11:42:32 -070024import android.graphics.Bitmap;
25import android.graphics.Color;
26import android.graphics.drawable.BitmapDrawable;
27import android.graphics.drawable.ColorDrawable;
Ihab Awad807fe0a2014-07-09 12:30:52 -070028import android.graphics.drawable.Drawable;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070029import android.net.Uri;
Ihab Awad807fe0a2014-07-09 12:30:52 -070030import android.os.Parcel;
31import android.os.Parcelable;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070032import android.text.TextUtils;
Ihab Awad807fe0a2014-07-09 12:30:52 -070033
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070034import java.lang.String;
35import java.util.ArrayList;
36import java.util.Collections;
37import java.util.List;
Ihab Awad807fe0a2014-07-09 12:30:52 -070038import java.util.MissingResourceException;
39
40/**
Santos Cordon32c65a52014-10-27 14:57:49 -070041 * Represents a distinct method to place or receive a phone call. Apps which can place calls and
42 * want those calls to be integrated into the dialer and in-call UI should build an instance of
43 * this class and register it with the system using {@link TelecomManager#registerPhoneAccount}.
44 * <p>
45 * {@link TelecomManager} uses registered {@link PhoneAccount}s to present the user with
46 * alternative options when placing a phone call. When building a {@link PhoneAccount}, the app
47 * should supply a valid {@link PhoneAccountHandle} that references the {@link ConnectionService}
48 * implementation Telecom will use to interact with the app.
Evan Charlton0e094d92014-11-08 15:49:16 -080049 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -070050 */
Evan Charlton0e094d92014-11-08 15:49:16 -080051@SystemApi
Evan Charlton8c8a0622014-07-20 12:31:00 -070052public class PhoneAccount implements Parcelable {
Ihab Awad94cf4bf2014-07-17 11:21:19 -070053
54 /**
Ihab Awadf8b69882014-07-25 15:14:01 -070055 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
56 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
57 * will be allowed to manage phone calls including using its own proprietary phone-call
58 * implementation (like VoIP calling) to make calls instead of the telephony stack.
59 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -070060 * When a user opts to place a call using the SIM-based telephony stack, the
61 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
62 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -070063 * <p>
64 * See {@link #getCapabilities}
65 */
Ihab Awadf8b69882014-07-25 15:14:01 -070066 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070067
68 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -070069 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -070070 * traditional SIM-based telephony calls. This account will be treated as a distinct method
71 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -070072 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -070073 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -070074 * <p>
75 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -070076 * <p>
Evan Charlton7800fb72014-07-20 18:09:38 -070077 * {@hide}
Ihab Awad94cf4bf2014-07-17 11:21:19 -070078 */
79 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
80
Ihab Awad7522bbd62014-07-18 15:53:17 -070081 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070082 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -070083 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -070084 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -070085 * Only the Android framework can register a {@code PhoneAccount} having this capability.
86 * <p>
87 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -070088 */
89 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
90
Ihab Awadf8b69882014-07-25 15:14:01 -070091 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070092 * Flag indicating that this {@code PhoneAccount} is capable of placing video calls.
93 * <p>
94 * See {@link #getCapabilities}
Tyler Gunnbe74de02014-08-29 14:51:48 -070095 * @hide
Ihab Awadf8b69882014-07-25 15:14:01 -070096 */
97 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
98
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070099 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700100 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
101 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
102 * <p>
103 * See {@link #getCapabilities}
104 */
105 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
106
107 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700108 * URI scheme for telephone number URIs.
109 */
110 public static final String SCHEME_TEL = "tel";
111
112 /**
113 * URI scheme for voicemail URIs.
114 */
115 public static final String SCHEME_VOICEMAIL = "voicemail";
116
117 /**
118 * URI scheme for SIP URIs.
119 */
120 public static final String SCHEME_SIP = "sip";
121
Nancy Chen3ace54b2014-10-22 17:45:26 -0700122 /**
123 * Indicating no color is set.
124 */
125 public static final int NO_COLOR = -1;
126
Ihab Awad476cc832014-11-03 09:47:51 -0800127 /**
128 * Indicating no resource ID is set.
129 */
130 public static final int NO_RESOURCE_ID = -1;
131
Evan Charlton8c8a0622014-07-20 12:31:00 -0700132 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700133 private final Uri mAddress;
134 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700135 private final int mCapabilities;
136 private final int mIconResId;
Ihab Awad074bf102014-10-24 11:42:32 -0700137 private final String mIconPackageName;
138 private final Bitmap mIconBitmap;
Ihab Awad476cc832014-11-03 09:47:51 -0800139 private final int mIconTint;
140 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700141 private final CharSequence mLabel;
142 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700143 private final List<String> mSupportedUriSchemes;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700144
Santos Cordon32c65a52014-10-27 14:57:49 -0700145 /**
146 * Helper class for creating a {@link PhoneAccount}.
147 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700148 public static class Builder {
149 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700150 private Uri mAddress;
151 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700152 private int mCapabilities;
153 private int mIconResId;
Ihab Awad074bf102014-10-24 11:42:32 -0700154 private String mIconPackageName;
155 private Bitmap mIconBitmap;
Ihab Awad476cc832014-11-03 09:47:51 -0800156 private int mIconTint = NO_COLOR;
157 private int mHighlightColor = NO_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700158 private CharSequence mLabel;
159 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700160 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700161
Santos Cordon32c65a52014-10-27 14:57:49 -0700162 /**
163 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
164 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700165 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
166 this.mAccountHandle = accountHandle;
167 this.mLabel = label;
168 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700169
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700170 /**
171 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
172 * {@link PhoneAccount}.
173 *
174 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
175 */
176 public Builder(PhoneAccount phoneAccount) {
177 mAccountHandle = phoneAccount.getAccountHandle();
178 mAddress = phoneAccount.getAddress();
179 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
180 mCapabilities = phoneAccount.getCapabilities();
181 mIconResId = phoneAccount.getIconResId();
Ihab Awad074bf102014-10-24 11:42:32 -0700182 mIconPackageName = phoneAccount.getIconPackageName();
183 mIconBitmap = phoneAccount.getIconBitmap();
Ihab Awad476cc832014-11-03 09:47:51 -0800184 mIconTint = phoneAccount.getIconTint();
185 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700186 mLabel = phoneAccount.getLabel();
187 mShortDescription = phoneAccount.getShortDescription();
188 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700189 }
190
Santos Cordon32c65a52014-10-27 14:57:49 -0700191 /**
192 * Sets the address. See {@link PhoneAccount#getAddress}.
193 *
194 * @param value The address of the phone account.
195 * @return The builder.
196 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700197 public Builder setAddress(Uri value) {
198 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700199 return this;
200 }
201
Santos Cordon32c65a52014-10-27 14:57:49 -0700202 /**
203 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
204 *
205 * @param value The subscription address.
206 * @return The builder.
207 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700208 public Builder setSubscriptionAddress(Uri value) {
209 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700210 return this;
211 }
212
Santos Cordon32c65a52014-10-27 14:57:49 -0700213 /**
214 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
215 *
216 * @param value The capabilities to set.
217 * @return The builder.
218 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700219 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700220 this.mCapabilities = value;
221 return this;
222 }
223
Santos Cordon32c65a52014-10-27 14:57:49 -0700224 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800225 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700226 *
Ihab Awad476cc832014-11-03 09:47:51 -0800227 * @param packageContext The package from which to load an icon.
228 * @param iconResId The resource in {@code iconPackageName} representing the icon.
Santos Cordon32c65a52014-10-27 14:57:49 -0700229 * @return The builder.
230 */
Ihab Awad476cc832014-11-03 09:47:51 -0800231 public Builder setIcon(Context packageContext, int iconResId) {
232 return setIcon(packageContext.getPackageName(), iconResId);
233 }
234
235 /**
236 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
237 *
238 * @param iconPackageName The package from which to load an icon.
239 * @param iconResId The resource in {@code iconPackageName} representing the icon.
240 * @return The builder.
241 */
242 public Builder setIcon(String iconPackageName, int iconResId) {
243 return setIcon(iconPackageName, iconResId, NO_COLOR);
244 }
245
246 /**
247 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
248 *
249 * @param packageContext The package from which to load an icon.
250 * @param iconResId The resource in {@code iconPackageName} representing the icon.
251 * @param iconTint A color with which to tint this icon.
252 * @return The builder.
253 */
254 public Builder setIcon(Context packageContext, int iconResId, int iconTint) {
255 return setIcon(packageContext.getPackageName(), iconResId, iconTint);
256 }
257
258 /**
259 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
260 *
261 * @param iconPackageName The package from which to load an icon.
262 * @param iconResId The resource in {@code iconPackageName} representing the icon.
263 * @param iconTint A color with which to tint this icon.
264 * @return The builder.
265 */
266 public Builder setIcon(String iconPackageName, int iconResId, int iconTint) {
267 this.mIconPackageName = iconPackageName;
268 this.mIconResId = iconResId;
269 this.mIconTint = iconTint;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700270 return this;
271 }
272
Ihab Awad074bf102014-10-24 11:42:32 -0700273 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800274 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
Ihab Awad074bf102014-10-24 11:42:32 -0700275 *
Ihab Awad476cc832014-11-03 09:47:51 -0800276 * @param iconBitmap The icon bitmap.
Ihab Awad074bf102014-10-24 11:42:32 -0700277 * @return The builder.
278 */
Ihab Awad476cc832014-11-03 09:47:51 -0800279 public Builder setIcon(Bitmap iconBitmap) {
280 this.mIconBitmap = iconBitmap;
281 this.mIconPackageName = null;
282 this.mIconResId = NO_RESOURCE_ID;
283 this.mIconTint = NO_COLOR;
Ihab Awad074bf102014-10-24 11:42:32 -0700284 return this;
285 }
286
287 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800288 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700289 *
Ihab Awad476cc832014-11-03 09:47:51 -0800290 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700291 * @return The builder.
292 */
Ihab Awad476cc832014-11-03 09:47:51 -0800293 public Builder setHighlightColor(int value) {
294 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700295 return this;
296 }
297
Santos Cordon32c65a52014-10-27 14:57:49 -0700298 /**
299 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
300 *
301 * @param value The short description.
302 * @return The builder.
303 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700304 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700305 this.mShortDescription = value;
306 return this;
307 }
308
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700309 /**
310 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
311 *
312 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700313 * @return The builder.
Andrew Lee3085a6c2014-09-04 10:59:13 -0700314 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700315 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700316 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700317 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
318 this.mSupportedUriSchemes.add(uriScheme);
319 }
320 return this;
321 }
322
323 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700324 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700325 *
326 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700327 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700328 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700329 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
330 mSupportedUriSchemes.clear();
331
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700332 if (uriSchemes != null && !uriSchemes.isEmpty()) {
333 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700334 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700335 }
336 }
337 return this;
338 }
339
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700340 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700341 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
342 *
343 * @return The {@link PhoneAccount}.
344 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700345 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700346 // If no supported URI schemes were defined, assume "tel" is supported.
347 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700348 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700349 }
350
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700351 return new PhoneAccount(
352 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700353 mAddress,
354 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700355 mCapabilities,
356 mIconResId,
Ihab Awad074bf102014-10-24 11:42:32 -0700357 mIconPackageName,
358 mIconBitmap,
Ihab Awad476cc832014-11-03 09:47:51 -0800359 mIconTint,
360 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700361 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700362 mShortDescription,
Nancy Chen210ef032014-09-15 17:58:42 -0700363 mSupportedUriSchemes);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700364 }
365 }
366
367 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700368 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700369 Uri address,
370 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700371 int capabilities,
Ihab Awad807fe0a2014-07-09 12:30:52 -0700372 int iconResId,
Ihab Awad074bf102014-10-24 11:42:32 -0700373 String iconPackageName,
374 Bitmap iconBitmap,
Ihab Awad476cc832014-11-03 09:47:51 -0800375 int iconTint,
376 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700377 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700378 CharSequence shortDescription,
Nancy Chen210ef032014-09-15 17:58:42 -0700379 List<String> supportedUriSchemes) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700380 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700381 mAddress = address;
382 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700383 mCapabilities = capabilities;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700384 mIconResId = iconResId;
Ihab Awad074bf102014-10-24 11:42:32 -0700385 mIconPackageName = iconPackageName;
386 mIconBitmap = iconBitmap;
Ihab Awad476cc832014-11-03 09:47:51 -0800387 mIconTint = iconTint;
388 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700389 mLabel = label;
390 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700391 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700392 }
393
Andrew Lee3085a6c2014-09-04 10:59:13 -0700394 public static Builder builder(
395 PhoneAccountHandle accountHandle,
396 CharSequence label) {
397 return new Builder(accountHandle, label);
398 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700399
Ihab Awad807fe0a2014-07-09 12:30:52 -0700400 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700401 * Returns a builder initialized with the current {@link PhoneAccount} instance.
402 *
403 * @return The builder.
404 * @hide
405 */
406 public Builder toBuilder() { return new Builder(this); }
407
408 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700409 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700410 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700411 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700412 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700413 public PhoneAccountHandle getAccountHandle() {
414 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700415 }
416
417 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700418 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700419 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700420 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700421 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700422 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700423 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700424 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700425 public Uri getAddress() {
426 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700427 }
428
429 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700430 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700431 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700432 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000433 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
434 * has been used to alter the callback number.
435 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700436 *
437 * @return The subscription number, suitable for display to the user.
438 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700439 public Uri getSubscriptionAddress() {
440 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700441 }
442
443 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700444 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700445 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700446 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700447 */
448 public int getCapabilities() {
449 return mCapabilities;
450 }
451
452 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700453 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
454 * bit mask.
455 *
456 * @param capability The capabilities to check.
457 * @return {@code True} if the phone account has the capability.
458 */
459 public boolean hasCapabilities(int capability) {
460 return (mCapabilities & capability) == capability;
461 }
462
463 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700464 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700465 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700466 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700467 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700468 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700469 return mLabel;
470 }
471
472 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700473 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700474 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700475 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700476 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700477 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700478 return mShortDescription;
479 }
480
481 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700482 * The URI schemes supported by this {@code PhoneAccount}.
483 *
484 * @return The URI schemes.
485 */
486 public List<String> getSupportedUriSchemes() {
487 return mSupportedUriSchemes;
488 }
489
490 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700491 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700492 * scheme.
493 *
494 * @param uriScheme The URI scheme to check.
Andrew Lee3085a6c2014-09-04 10:59:13 -0700495 * @return {@code True} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700496 * specified URI scheme.
497 */
498 public boolean supportsUriScheme(String uriScheme) {
499 if (mSupportedUriSchemes == null || uriScheme == null) {
500 return false;
501 }
502
503 for (String scheme : mSupportedUriSchemes) {
504 if (scheme != null && scheme.equals(uriScheme)) {
505 return true;
506 }
507 }
508 return false;
509 }
510
511 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700512 * The icon resource ID for the icon of this {@code PhoneAccount}.
513 * <p>
514 * Creators of a {@code PhoneAccount} who possess the icon in static resources should prefer
515 * this method of indicating the icon rather than using {@link #getIconBitmap()}, since it
516 * leads to less resource usage.
517 * <p>
Ihab Awad476cc832014-11-03 09:47:51 -0800518 * Clients wishing to display a {@code PhoneAccount} should use {@link #createIconDrawable(Context)}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700519 *
520 * @return A resource ID.
521 */
522 public int getIconResId() {
523 return mIconResId;
524 }
525
526 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700527 * The package name from which to load the icon of this {@code PhoneAccount}.
528 * <p>
529 * If this property is {@code null}, the resource {@link #getIconResId()} will be loaded from
530 * the package in the {@link ComponentName} of the {@link #getAccountHandle()}.
531 * <p>
Ihab Awad476cc832014-11-03 09:47:51 -0800532 * Clients wishing to display a {@code PhoneAccount} should use {@link #createIconDrawable(Context)}.
Ihab Awad074bf102014-10-24 11:42:32 -0700533 *
534 * @return A package name.
535 */
536 public String getIconPackageName() {
537 return mIconPackageName;
538 }
539
540 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800541 * A tint to apply to the icon of this {@code PhoneAccount}.
Nancy Chen3ace54b2014-10-22 17:45:26 -0700542 *
543 * @return A hexadecimal color value.
544 */
Ihab Awad476cc832014-11-03 09:47:51 -0800545 public int getIconTint() {
546 return mIconTint;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700547 }
548
549 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700550 * A literal icon bitmap to represent this {@code PhoneAccount} in a user interface.
551 * <p>
552 * If this property is specified, it is to be considered the preferred icon. Otherwise, the
553 * resource specified by {@link #getIconResId()} should be used.
554 * <p>
Ihab Awad476cc832014-11-03 09:47:51 -0800555 * Clients wishing to display a {@code PhoneAccount} should use
556 * {@link #createIconDrawable(Context)}.
Ihab Awad074bf102014-10-24 11:42:32 -0700557 *
558 * @return A bitmap.
559 */
560 public Bitmap getIconBitmap() {
561 return mIconBitmap;
562 }
563
564 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800565 * A highlight color to use in displaying information about this {@code PhoneAccount}.
566 *
567 * @return A hexadecimal color value.
568 */
569 public int getHighlightColor() {
570 return mHighlightColor;
571 }
572
573 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700574 * Builds and returns an icon {@code Drawable} to represent this {@code PhoneAccount} in a user
575 * interface. Uses the properties {@link #getIconResId()}, {@link #getIconPackageName()}, and
576 * {@link #getIconBitmap()} as necessary.
577 *
578 * @param context A {@code Context} to use for loading {@code Drawable}s.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700579 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700580 * @return An icon for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700581 */
Ihab Awad476cc832014-11-03 09:47:51 -0800582 public Drawable createIconDrawable(Context context) {
Ihab Awad074bf102014-10-24 11:42:32 -0700583 if (mIconBitmap != null) {
584 return new BitmapDrawable(context.getResources(), mIconBitmap);
Sailesh Nepal77780a42014-09-26 18:12:00 -0700585 }
586
Ihab Awad074bf102014-10-24 11:42:32 -0700587 if (mIconResId != 0) {
Ihab Awad074bf102014-10-24 11:42:32 -0700588 try {
Ihab Awad476cc832014-11-03 09:47:51 -0800589 Context packageContext = context.createPackageContext(mIconPackageName, 0);
Ihab Awad074bf102014-10-24 11:42:32 -0700590 try {
Ihab Awad476cc832014-11-03 09:47:51 -0800591 Drawable iconDrawable = packageContext.getDrawable(mIconResId);
592 if (mIconTint != NO_COLOR) {
593 iconDrawable.setTint(mIconTint);
594 }
595 return iconDrawable;
Ihab Awad074bf102014-10-24 11:42:32 -0700596 } catch (NotFoundException | MissingResourceException e) {
Ihab Awad476cc832014-11-03 09:47:51 -0800597 Log.e(this, e, "Cannot find icon %d in package %s",
598 mIconResId, mIconPackageName);
Ihab Awad074bf102014-10-24 11:42:32 -0700599 }
600 } catch (PackageManager.NameNotFoundException e) {
Ihab Awad476cc832014-11-03 09:47:51 -0800601 Log.w(this, "Cannot find package %s", mIconPackageName);
Ihab Awad074bf102014-10-24 11:42:32 -0700602 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700603 }
Ihab Awad074bf102014-10-24 11:42:32 -0700604
605 return new ColorDrawable(Color.TRANSPARENT);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700606 }
607
608 //
609 // Parcelable implementation
610 //
611
612 @Override
613 public int describeContents() {
614 return 0;
615 }
616
617 @Override
618 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800619 if (mAccountHandle == null) {
620 out.writeInt(0);
621 } else {
622 out.writeInt(1);
623 mAccountHandle.writeToParcel(out, flags);
624 }
625 if (mAddress == null) {
626 out.writeInt(0);
627 } else {
628 out.writeInt(1);
629 mAddress.writeToParcel(out, flags);
630 }
631 if (mSubscriptionAddress == null) {
632 out.writeInt(0);
633 } else {
634 out.writeInt(1);
635 mSubscriptionAddress.writeToParcel(out, flags);
636 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700637 out.writeInt(mCapabilities);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700638 out.writeInt(mIconResId);
Ihab Awad074bf102014-10-24 11:42:32 -0700639 out.writeString(mIconPackageName);
Ihab Awad476cc832014-11-03 09:47:51 -0800640 if (mIconBitmap == null) {
641 out.writeInt(0);
642 } else {
643 mIconBitmap.writeToParcel(out, flags);
644 }
645 out.writeInt(mIconTint);
646 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700647 out.writeCharSequence(mLabel);
648 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800649 out.writeStringList(mSupportedUriSchemes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700650 }
651
Evan Charlton8c8a0622014-07-20 12:31:00 -0700652 public static final Creator<PhoneAccount> CREATOR
653 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700654 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700655 public PhoneAccount createFromParcel(Parcel in) {
656 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700657 }
658
659 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700660 public PhoneAccount[] newArray(int size) {
661 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700662 }
663 };
664
Evan Charlton8c8a0622014-07-20 12:31:00 -0700665 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800666 if (in.readInt() > 0) {
667 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
668 } else {
669 mAccountHandle = null;
670 }
671 if (in.readInt() > 0) {
672 mAddress = Uri.CREATOR.createFromParcel(in);
673 } else {
674 mAddress = null;
675 }
676 if (in.readInt() > 0) {
677 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
678 } else {
679 mSubscriptionAddress = null;
680 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700681 mCapabilities = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700682 mIconResId = in.readInt();
Ihab Awad074bf102014-10-24 11:42:32 -0700683 mIconPackageName = in.readString();
Ihab Awad476cc832014-11-03 09:47:51 -0800684 if (in.readInt() > 0) {
685 mIconBitmap = Bitmap.CREATOR.createFromParcel(in);
686 } else {
687 mIconBitmap = null;
688 }
689 mIconTint = in.readInt();
690 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700691 mLabel = in.readCharSequence();
692 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800693 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700694 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700695
696 @Override
697 public String toString() {
698 StringBuilder sb = new StringBuilder().append("[PhoneAccount: ")
699 .append(mAccountHandle)
700 .append(" Capabilities: ")
701 .append(mCapabilities)
702 .append(" Schemes: ");
703 for (String scheme : mSupportedUriSchemes) {
704 sb.append(scheme)
705 .append(" ");
706 }
707 sb.append("]");
708 return sb.toString();
709 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700710}