blob: d0c4b217b2188a4232bb1b85585dfffd95b68602 [file] [log] [blame]
Ihab Awad807fe0a2014-07-09 12:30:52 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad807fe0a2014-07-09 12:30:52 -070018
Tyler Gunn711d876fd2014-09-19 11:17:02 -070019import android.annotation.SystemApi;
Ihab Awad807fe0a2014-07-09 12:30:52 -070020import android.content.Context;
21import android.content.pm.PackageManager;
Santos Cordone8dc4be2014-07-21 01:28:28 -070022import android.content.res.Resources.NotFoundException;
Divya Sharma1cb8f692015-02-24 16:25:55 -080023import android.graphics.Bitmap;
24import android.graphics.Color;
25import android.graphics.drawable.BitmapDrawable;
26import android.graphics.drawable.ColorDrawable;
Ihab Awad807fe0a2014-07-09 12:30:52 -070027import android.graphics.drawable.Drawable;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070028import android.net.Uri;
Ihab Awad807fe0a2014-07-09 12:30:52 -070029import android.os.Parcel;
30import android.os.Parcelable;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070031import android.text.TextUtils;
Ihab Awad807fe0a2014-07-09 12:30:52 -070032
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070033import java.lang.String;
34import java.util.ArrayList;
Sandeep Kunta0f8bfc52014-09-01 17:21:05 +053035import java.util.BitSet;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070036import java.util.Collections;
37import java.util.List;
Ihab Awad807fe0a2014-07-09 12:30:52 -070038import java.util.MissingResourceException;
39
40/**
Evan Charltonf6a3fef2014-11-08 15:49:16 -080041 * 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.
Tyler Gunn711d876fd2014-09-19 11:17:02 -070049 * @hide
Ihab Awad807fe0a2014-07-09 12:30:52 -070050 */
Tyler Gunn711d876fd2014-09-19 11:17:02 -070051@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
Evan Charlton6eb262c2014-07-19 18:18:19 -070073 * calls from or use the built-in telephony stack to place its calls.
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 Awad7522bbd2014-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 Awad7522bbd2014-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 Awad7522bbd2014-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 /**
Evan Charltonc62310e2014-11-25 14:12:57 -0800108 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
109 * should only be used by system apps (and will be ignored for all other apps trying to use it).
110 * <p>
111 * See {@link #getCapabilities}
112 * @hide
113 */
114 public static final int CAPABILITY_MULTI_USER = 0x20;
115
116 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700117 * URI scheme for telephone number URIs.
118 */
119 public static final String SCHEME_TEL = "tel";
120
121 /**
122 * URI scheme for voicemail URIs.
123 */
124 public static final String SCHEME_VOICEMAIL = "voicemail";
125
126 /**
127 * URI scheme for SIP URIs.
128 */
129 public static final String SCHEME_SIP = "sip";
130
Natiq Ahmedc67d48d2014-09-16 21:34:44 +0530131 /**
132 * {@hide}
133 */
134 public static final String SCHEME_SMSTO = "smsto";
135
Nancy Chen54563bc2014-10-22 17:45:26 -0700136 /**
137 * Indicating no color is set.
Divya Sharma1cb8f692015-02-24 16:25:55 -0800138 * @hide
Nancy Chen54563bc2014-10-22 17:45:26 -0700139 */
140 public static final int NO_COLOR = -1;
141
Ihab Awadc7af4342014-11-03 09:47:51 -0800142 /**
Ihab Awad4a0d2722014-11-12 13:41:16 -0800143 * Indicating no icon tint is set.
144 */
145 public static final int NO_ICON_TINT = 0;
146
147 /**
148 * Indicating no hightlight color is set.
149 */
150 public static final int NO_HIGHLIGHT_COLOR = 0;
151
152 /**
Ihab Awadc7af4342014-11-03 09:47:51 -0800153 * Indicating no resource ID is set.
154 */
155 public static final int NO_RESOURCE_ID = -1;
156
Evan Charlton8c8a0622014-07-20 12:31:00 -0700157 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700158 private final Uri mAddress;
159 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700160 private final int mCapabilities;
161 private final int mIconResId;
Divya Sharma1cb8f692015-02-24 16:25:55 -0800162 private final String mIconPackageName;
163 private final Bitmap mIconBitmap;
Nancy Chen54563bc2014-10-22 17:45:26 -0700164 private final int mColor;
Ihab Awadc7af4342014-11-03 09:47:51 -0800165 private final int mIconTint;
166 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700167 private final CharSequence mLabel;
168 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700169 private final List<String> mSupportedUriSchemes;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700170
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700171 public static class Builder {
172 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700173 private Uri mAddress;
174 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700175 private int mCapabilities;
176 private int mIconResId;
Divya Sharma1cb8f692015-02-24 16:25:55 -0800177 private String mIconPackageName;
178 private Bitmap mIconBitmap;
Nancy Chen54563bc2014-10-22 17:45:26 -0700179 private int mColor = NO_COLOR;
Ihab Awad4a0d2722014-11-12 13:41:16 -0800180 private int mIconTint = NO_ICON_TINT;
181 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700182 private CharSequence mLabel;
183 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700184 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700185
Andrew Lee3085a6c2014-09-04 10:59:13 -0700186 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
187 this.mAccountHandle = accountHandle;
188 this.mLabel = label;
189 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700190
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700191 /**
192 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
193 * {@link PhoneAccount}.
194 *
195 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
196 */
197 public Builder(PhoneAccount phoneAccount) {
198 mAccountHandle = phoneAccount.getAccountHandle();
199 mAddress = phoneAccount.getAddress();
200 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
201 mCapabilities = phoneAccount.getCapabilities();
202 mIconResId = phoneAccount.getIconResId();
Nancy Chen54563bc2014-10-22 17:45:26 -0700203 mColor = phoneAccount.getColor();
Ihab Awadc7af4342014-11-03 09:47:51 -0800204 mIconTint = phoneAccount.getIconTint();
205 mHighlightColor = phoneAccount.getHighlightColor();
Divya Sharma1cb8f692015-02-24 16:25:55 -0800206 mIconPackageName = phoneAccount.getIconPackageName();
207 mIconBitmap = phoneAccount.getIconBitmap();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700208 mLabel = phoneAccount.getLabel();
209 mShortDescription = phoneAccount.getShortDescription();
210 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700211 }
212
Evan Charltonc62310e2014-11-25 14:12:57 -0800213 /** @hide */
214 public Builder setAccountHandle(PhoneAccountHandle accountHandle) {
215 mAccountHandle = accountHandle;
216 return this;
217 }
218
219 /**
220 * Sets the address. See {@link PhoneAccount#getAddress}.
221 *
222 * @param value The address of the phone account.
223 * @return The builder.
224 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700225 public Builder setAddress(Uri value) {
226 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700227 return this;
228 }
229
Andrew Lee3085a6c2014-09-04 10:59:13 -0700230 public Builder setSubscriptionAddress(Uri value) {
231 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700232 return this;
233 }
234
Andrew Lee3085a6c2014-09-04 10:59:13 -0700235 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700236 this.mCapabilities = value;
237 return this;
238 }
239
Ihab Awadc7af4342014-11-03 09:47:51 -0800240 /**
241 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
242 *
243 * @param packageContext The package from which to load an icon.
244 * @param iconResId The resource in {@code iconPackageName} representing the icon.
245 * @return The builder.
246 */
247 public Builder setIcon(Context packageContext, int iconResId) {
248 return setIcon(packageContext.getPackageName(), iconResId);
249 }
250
251 /**
252 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
253 *
254 * @param iconPackageName The package from which to load an icon.
255 * @param iconResId The resource in {@code iconPackageName} representing the icon.
256 * @return The builder.
257 */
258 public Builder setIcon(String iconPackageName, int iconResId) {
Ihab Awad4a0d2722014-11-12 13:41:16 -0800259 return setIcon(iconPackageName, iconResId, NO_ICON_TINT);
Ihab Awadc7af4342014-11-03 09:47:51 -0800260 }
261
262 /**
263 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
264 *
265 * @param packageContext The package from which to load an icon.
266 * @param iconResId The resource in {@code iconPackageName} representing the icon.
267 * @param iconTint A color with which to tint this icon.
268 * @return The builder.
269 */
270 public Builder setIcon(Context packageContext, int iconResId, int iconTint) {
271 return setIcon(packageContext.getPackageName(), iconResId, iconTint);
272 }
273
274 /**
275 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
276 *
277 * @param iconPackageName The package from which to load an icon.
278 * @param iconResId The resource in {@code iconPackageName} representing the icon.
279 * @param iconTint A color with which to tint this icon.
280 * @return The builder.
281 */
282 public Builder setIcon(String iconPackageName, int iconResId, int iconTint) {
283 this.mIconPackageName = iconPackageName;
284 this.mIconResId = iconResId;
285 this.mIconTint = iconTint;
286 return this;
287 }
288
289 /**
290 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
291 *
292 * @param iconBitmap The icon bitmap.
293 * @return The builder.
294 */
295 public Builder setIcon(Bitmap iconBitmap) {
296 this.mIconBitmap = iconBitmap;
297 this.mIconPackageName = null;
298 this.mIconResId = NO_RESOURCE_ID;
Ihab Awad4a0d2722014-11-12 13:41:16 -0800299 this.mIconTint = NO_ICON_TINT;
Ihab Awadc7af4342014-11-03 09:47:51 -0800300 return this;
301 }
302
303 /**
304 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
305 *
306 * @param value The highlight color.
307 * @return The builder.
308 */
309 public Builder setHighlightColor(int value) {
310 this.mHighlightColor = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700311 return this;
312 }
313
Divya Sharma1cb8f692015-02-24 16:25:55 -0800314 /** @hide */
Nancy Chen54563bc2014-10-22 17:45:26 -0700315 public Builder setColor(int value) {
316 this.mColor = value;
317 return this;
318 }
319
Ihab Awadc7af4342014-11-03 09:47:51 -0800320 /**
Divya Sharma1cb8f692015-02-24 16:25:55 -0800321 * Sets the icon package name. See {@link PhoneAccount#getIconPackageName}.
322 *
323 * @param value The name of the package from which to load the icon.
324 * @return The builder.
325 * @hide
326 */
327 public Builder setIconPackageName(String value) {
328 this.mIconPackageName = value;
329 return this;
330 }
331
332 /**
333 * Sets the icon bitmap. See {@link PhoneAccount#getIconBitmap}.
334 *
335 * @param value The icon bitmap.
336 * @return The builder.
337 * @hide
338 */
339 public Builder setIconBitmap(Bitmap value) {
340 this.mIconBitmap = value;
341 return this;
342 }
343
344 /**
Ihab Awadc7af4342014-11-03 09:47:51 -0800345 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
346 *
347 * @param value The short description.
348 * @return The builder.
349 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700350 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700351 this.mShortDescription = value;
352 return this;
353 }
354
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700355 /**
356 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
357 *
358 * @param uriScheme The URI scheme.
359 * @return The Builder.
Andrew Lee3085a6c2014-09-04 10:59:13 -0700360 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700361 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700362 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700363 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
364 this.mSupportedUriSchemes.add(uriScheme);
365 }
366 return this;
367 }
368
369 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700370 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700371 *
372 * @param uriSchemes The URI schemes.
373 * @return The Builder.
374 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700375 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
376 mSupportedUriSchemes.clear();
377
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700378 if (uriSchemes != null && !uriSchemes.isEmpty()) {
379 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700380 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700381 }
382 }
383 return this;
384 }
385
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700386 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700387 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
388 *
389 * @return The {@link PhoneAccount}.
390 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700391 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700392 // If no supported URI schemes were defined, assume "tel" is supported.
393 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700394 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700395 }
396
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700397 return new PhoneAccount(
398 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700399 mAddress,
400 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700401 mCapabilities,
402 mIconResId,
Nancy Chen54563bc2014-10-22 17:45:26 -0700403 mColor,
Ihab Awadc7af4342014-11-03 09:47:51 -0800404 mIconTint,
405 mHighlightColor,
Divya Sharma1cb8f692015-02-24 16:25:55 -0800406 mIconPackageName,
407 mIconBitmap,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700408 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700409 mShortDescription,
Nancy Chen210ef032014-09-15 17:58:42 -0700410 mSupportedUriSchemes);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700411 }
412 }
413
414 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700415 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700416 Uri address,
417 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700418 int capabilities,
Ihab Awad807fe0a2014-07-09 12:30:52 -0700419 int iconResId,
Nancy Chen54563bc2014-10-22 17:45:26 -0700420 int color,
Ihab Awadc7af4342014-11-03 09:47:51 -0800421 int iconTint,
422 int highlightColor,
Divya Sharma1cb8f692015-02-24 16:25:55 -0800423 String iconPackageName,
424 Bitmap iconBitmap,
Santos Cordon146a3e32014-07-21 00:00:44 -0700425 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700426 CharSequence shortDescription,
Nancy Chen210ef032014-09-15 17:58:42 -0700427 List<String> supportedUriSchemes) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700428 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700429 mAddress = address;
430 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700431 mCapabilities = capabilities;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700432 mIconResId = iconResId;
Nancy Chen54563bc2014-10-22 17:45:26 -0700433 mColor = color;
Ihab Awadc7af4342014-11-03 09:47:51 -0800434 mIconTint = iconTint;
435 mHighlightColor = highlightColor;
Divya Sharma1cb8f692015-02-24 16:25:55 -0800436 mIconPackageName = iconPackageName;
437 mIconBitmap = iconBitmap;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700438 mLabel = label;
439 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700440 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700441 }
442
Andrew Lee3085a6c2014-09-04 10:59:13 -0700443 public static Builder builder(
444 PhoneAccountHandle accountHandle,
445 CharSequence label) {
446 return new Builder(accountHandle, label);
447 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700448
Sandeep Kunta0f8bfc52014-09-01 17:21:05 +0530449 private BitSet dsda = new BitSet();
450
451 /**
452 * {@hide}
453 */
454 public static final int LCH = 1;
455
456 /**
457 * {@hide}
458 */
459 public static final int ACTIVE = 2;
460
461 /**
462 * {@hide}
463 */
464 public static final int LCHMUTE = 3;
465
466 /**
467 * {@hide}
468 */
469 public void setBit(int bit) {
470 dsda.set(bit);
471 }
472
473 /**
474 * {@hide}
475 */
476 public void unSetBit(int bit) {
477 dsda.set(bit, false);
478 }
479
480 /**
481 * {@hide}
482 */
483 public boolean isSet(int bit) {
484 return dsda.get(bit);
485 }
486
Ihab Awad807fe0a2014-07-09 12:30:52 -0700487 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700488 * Returns a builder initialized with the current {@link PhoneAccount} instance.
489 *
490 * @return The builder.
491 * @hide
492 */
493 public Builder toBuilder() { return new Builder(this); }
494
495 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700496 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700497 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700498 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700499 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700500 public PhoneAccountHandle getAccountHandle() {
501 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700502 }
503
504 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700505 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700506 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700507 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700508 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700509 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700510 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700511 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700512 public Uri getAddress() {
513 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700514 }
515
516 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700517 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700518 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700519 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liudd0a3202014-09-25 17:36:48 +0000520 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
521 * has been used to alter the callback number.
522 * <p>
Evan Charlton222db522014-07-17 16:59:18 -0700523 *
524 * @return The subscription number, suitable for display to the user.
525 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700526 public Uri getSubscriptionAddress() {
527 return mSubscriptionAddress;
Evan Charlton222db522014-07-17 16:59:18 -0700528 }
529
530 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700531 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700532 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700533 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700534 */
535 public int getCapabilities() {
536 return mCapabilities;
537 }
538
539 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700540 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
541 * bit mask.
542 *
543 * @param capability The capabilities to check.
544 * @return {@code True} if the phone account has the capability.
545 */
546 public boolean hasCapabilities(int capability) {
547 return (mCapabilities & capability) == capability;
548 }
549
550 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700551 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700552 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700553 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700554 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700555 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700556 return mLabel;
557 }
558
559 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700560 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700561 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700562 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700563 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700564 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700565 return mShortDescription;
566 }
567
568 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700569 * The URI schemes supported by this {@code PhoneAccount}.
570 *
571 * @return The URI schemes.
572 */
573 public List<String> getSupportedUriSchemes() {
574 return mSupportedUriSchemes;
575 }
576
577 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700578 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700579 * scheme.
580 *
581 * @param uriScheme The URI scheme to check.
Andrew Lee3085a6c2014-09-04 10:59:13 -0700582 * @return {@code True} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700583 * specified URI scheme.
584 */
585 public boolean supportsUriScheme(String uriScheme) {
586 if (mSupportedUriSchemes == null || uriScheme == null) {
587 return false;
588 }
589
590 for (String scheme : mSupportedUriSchemes) {
591 if (scheme != null && scheme.equals(uriScheme)) {
592 return true;
593 }
594 }
595 return false;
596 }
597
598 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700599 * The icon resource ID for the icon of this {@code PhoneAccount}.
Ihab Awadc7af4342014-11-03 09:47:51 -0800600 * Clients wishing to display a {@code PhoneAccount} should use {@link #createIconDrawable(Context)}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700601 *
602 * @return A resource ID.
603 */
604 public int getIconResId() {
605 return mIconResId;
606 }
607
608 /**
Nancy Chen54563bc2014-10-22 17:45:26 -0700609 * A highlight color to use in displaying information about this {@code PhoneAccount}.
610 *
611 * @return A hexadecimal color value.
Divya Sharma1cb8f692015-02-24 16:25:55 -0800612 * @hide
Nancy Chen54563bc2014-10-22 17:45:26 -0700613 */
614 public int getColor() {
615 return mColor;
616 }
617
618 /**
Divya Sharma1cb8f692015-02-24 16:25:55 -0800619 * The package name from which to load the icon of this {@code PhoneAccount}.
620 * <p>
621 * If this property is {@code null}, the resource {@link #getIconResId()} will be loaded from
622 * the package in the {@link ComponentName} of the {@link #getAccountHandle()}.
623 * <p>
624 * Clients wishing to display a {@code PhoneAccount} should use {@link #getIcon(Context)}.
625 *
626 * @return A package name.
627 */
628 public String getIconPackageName() {
629 return mIconPackageName;
630 }
631
632 /**
Ihab Awadc7af4342014-11-03 09:47:51 -0800633 * A tint to apply to the icon of this {@code PhoneAccount}.
634 *
635 * @return A hexadecimal color value.
636 */
637 public int getIconTint() {
638 return mIconTint;
639 }
640
641 /**
642 * A literal icon bitmap to represent this {@code PhoneAccount} in a user interface.
643 * <p>
644 * If this property is specified, it is to be considered the preferred icon. Otherwise, the
645 * resource specified by {@link #getIconResId()} should be used.
646 * <p>
647 * Clients wishing to display a {@code PhoneAccount} should use
648 * {@link #createIconDrawable(Context)}.
649 *
650 * @return A bitmap.
651 */
652 public Bitmap getIconBitmap() {
653 return mIconBitmap;
654 }
655
656 /**
657 * A highlight color to use in displaying information about this {@code PhoneAccount}.
658 *
659 * @return A hexadecimal color value.
660 */
661 public int getHighlightColor() {
662 return mHighlightColor;
663 }
664
665 /**
666 * Builds and returns an icon {@code Drawable} to represent this {@code PhoneAccount} in a user
667 * interface. Uses the properties {@link #getIconResId()}, {@link #getIconPackageName()}, and
668 * {@link #getIconBitmap()} as necessary.
669 *
670 * @param context A {@code Context} to use for loading {@code Drawable}s.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700671 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700672 * @return An icon for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700673 */
Ihab Awadc7af4342014-11-03 09:47:51 -0800674 public Drawable createIconDrawable(Context context) {
675 if (mIconBitmap != null) {
676 return new BitmapDrawable(context.getResources(), mIconBitmap);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700677 }
Ihab Awadc7af4342014-11-03 09:47:51 -0800678
679 if (mIconResId != 0) {
680 try {
681 Context packageContext = context.createPackageContext(mIconPackageName, 0);
682 try {
683 Drawable iconDrawable = packageContext.getDrawable(mIconResId);
Ihab Awad4a0d2722014-11-12 13:41:16 -0800684 if (mIconTint != NO_ICON_TINT) {
Ihab Awadc7af4342014-11-03 09:47:51 -0800685 iconDrawable.setTint(mIconTint);
686 }
687 return iconDrawable;
688 } catch (NotFoundException | MissingResourceException e) {
689 Log.e(this, e, "Cannot find icon %d in package %s",
690 mIconResId, mIconPackageName);
691 }
692 } catch (PackageManager.NameNotFoundException e) {
693 Log.w(this, "Cannot find package %s", mIconPackageName);
694 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700695 }
Divya Sharma1cb8f692015-02-24 16:25:55 -0800696 return new ColorDrawable(Color.TRANSPARENT);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700697 }
698
699 //
700 // Parcelable implementation
701 //
702
703 @Override
704 public int describeContents() {
705 return 0;
706 }
707
708 @Override
709 public void writeToParcel(Parcel out, int flags) {
Ihab Awadc7af4342014-11-03 09:47:51 -0800710 if (mAccountHandle == null) {
711 out.writeInt(0);
712 } else {
713 out.writeInt(1);
714 mAccountHandle.writeToParcel(out, flags);
715 }
716 if (mAddress == null) {
717 out.writeInt(0);
718 } else {
719 out.writeInt(1);
720 mAddress.writeToParcel(out, flags);
721 }
722 if (mSubscriptionAddress == null) {
723 out.writeInt(0);
724 } else {
725 out.writeInt(1);
726 mSubscriptionAddress.writeToParcel(out, flags);
727 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700728 out.writeInt(mCapabilities);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700729 out.writeInt(mIconResId);
Nancy Chen54563bc2014-10-22 17:45:26 -0700730 out.writeInt(mColor);
Divya Sharmafdb095d2015-02-27 20:14:33 -0800731 out.writeString(mIconPackageName);
Ihab Awadc7af4342014-11-03 09:47:51 -0800732 if (mIconBitmap == null) {
733 out.writeInt(0);
734 } else {
Ihab Awad77a79032014-11-11 18:41:39 -0800735 out.writeInt(1);
Ihab Awadc7af4342014-11-03 09:47:51 -0800736 mIconBitmap.writeToParcel(out, flags);
737 }
738 out.writeInt(mIconTint);
739 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700740 out.writeCharSequence(mLabel);
741 out.writeCharSequence(mShortDescription);
Ihab Awadc7af4342014-11-03 09:47:51 -0800742 out.writeStringList(mSupportedUriSchemes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700743 }
744
Evan Charlton8c8a0622014-07-20 12:31:00 -0700745 public static final Creator<PhoneAccount> CREATOR
746 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700747 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700748 public PhoneAccount createFromParcel(Parcel in) {
749 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700750 }
751
752 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700753 public PhoneAccount[] newArray(int size) {
754 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700755 }
756 };
757
Evan Charlton8c8a0622014-07-20 12:31:00 -0700758 private PhoneAccount(Parcel in) {
Ihab Awadc7af4342014-11-03 09:47:51 -0800759 if (in.readInt() > 0) {
760 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
761 } else {
762 mAccountHandle = null;
763 }
764 if (in.readInt() > 0) {
765 mAddress = Uri.CREATOR.createFromParcel(in);
766 } else {
767 mAddress = null;
768 }
769 if (in.readInt() > 0) {
770 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
771 } else {
772 mSubscriptionAddress = null;
773 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700774 mCapabilities = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700775 mIconResId = in.readInt();
Nancy Chen54563bc2014-10-22 17:45:26 -0700776 mColor = in.readInt();
Divya Sharma1cb8f692015-02-24 16:25:55 -0800777 mIconPackageName = in.readString();
Ihab Awadc7af4342014-11-03 09:47:51 -0800778 if (in.readInt() > 0) {
779 mIconBitmap = Bitmap.CREATOR.createFromParcel(in);
780 } else {
781 mIconBitmap = null;
782 }
783 mIconTint = in.readInt();
784 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700785 mLabel = in.readCharSequence();
786 mShortDescription = in.readCharSequence();
Ihab Awadc7af4342014-11-03 09:47:51 -0800787 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700788 }
Tyler Gunnedc1efb2014-09-30 14:47:51 -0700789
790 @Override
791 public String toString() {
792 StringBuilder sb = new StringBuilder().append("[PhoneAccount: ")
793 .append(mAccountHandle)
794 .append(" Capabilities: ")
795 .append(mCapabilities)
796 .append(" Schemes: ");
797 for (String scheme : mSupportedUriSchemes) {
798 sb.append(scheme)
799 .append(" ");
800 }
801 sb.append("]");
802 return sb.toString();
803 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700804}