blob: a94c2f6487a47a15834f8651c252c83c8cc65e8a [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 Attwell48d8442e2014-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 Attwell48d8442e2014-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}
Brian Attwell48d8442e2014-12-19 11:37:16 -080063 * @hide
Ihab Awad94cf4bf2014-07-17 11:21:19 -070064 */
Brian Attwell48d8442e2014-12-19 11:37:16 -080065 @SystemApi
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 */
Brian Attwell48d8442e2014-12-19 11:37:16 -080079 @SystemApi
Ihab Awad94cf4bf2014-07-17 11:21:19 -070080 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
81
Ihab Awad7522bbd62014-07-18 15:53:17 -070082 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070083 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -070084 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -070085 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -070086 * Only the Android framework can register a {@code PhoneAccount} having this capability.
87 * <p>
88 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -070089 */
90 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
91
Ihab Awadf8b69882014-07-25 15:14:01 -070092 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070093 * Flag indicating that this {@code PhoneAccount} is capable of placing video calls.
94 * <p>
95 * See {@link #getCapabilities}
Tyler Gunnbe74de02014-08-29 14:51:48 -070096 * @hide
Ihab Awadf8b69882014-07-25 15:14:01 -070097 */
Brian Attwell48d8442e2014-12-19 11:37:16 -080098 @SystemApi
Ihab Awadf8b69882014-07-25 15:14:01 -070099 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
100
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700101 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700102 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
103 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
104 * <p>
105 * See {@link #getCapabilities}
106 */
107 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
108
109 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800110 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
111 * should only be used by system apps (and will be ignored for all other apps trying to use it).
112 * <p>
113 * See {@link #getCapabilities}
114 * @hide
115 */
Brian Attwell48d8442e2014-12-19 11:37:16 -0800116 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800117 public static final int CAPABILITY_MULTI_USER = 0x20;
118
119 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700120 * URI scheme for telephone number URIs.
121 */
122 public static final String SCHEME_TEL = "tel";
123
124 /**
125 * URI scheme for voicemail URIs.
126 */
127 public static final String SCHEME_VOICEMAIL = "voicemail";
128
129 /**
130 * URI scheme for SIP URIs.
131 */
132 public static final String SCHEME_SIP = "sip";
133
Nancy Chen3ace54b2014-10-22 17:45:26 -0700134 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800135 * Indicating no icon tint is set.
Nancy Chen3ace54b2014-10-22 17:45:26 -0700136 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800137 public static final int NO_ICON_TINT = 0;
138
139 /**
140 * Indicating no hightlight color is set.
141 */
142 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700143
Ihab Awad476cc832014-11-03 09:47:51 -0800144 /**
145 * Indicating no resource ID is set.
146 */
147 public static final int NO_RESOURCE_ID = -1;
148
Evan Charlton8c8a0622014-07-20 12:31:00 -0700149 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700150 private final Uri mAddress;
151 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700152 private final int mCapabilities;
153 private final int mIconResId;
Ihab Awad074bf102014-10-24 11:42:32 -0700154 private final String mIconPackageName;
155 private final Bitmap mIconBitmap;
Ihab Awad476cc832014-11-03 09:47:51 -0800156 private final int mIconTint;
157 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700158 private final CharSequence mLabel;
159 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700160 private final List<String> mSupportedUriSchemes;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700161
Santos Cordon32c65a52014-10-27 14:57:49 -0700162 /**
163 * Helper class for creating a {@link PhoneAccount}.
164 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700165 public static class Builder {
166 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700167 private Uri mAddress;
168 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700169 private int mCapabilities;
170 private int mIconResId;
Ihab Awad074bf102014-10-24 11:42:32 -0700171 private String mIconPackageName;
172 private Bitmap mIconBitmap;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800173 private int mIconTint = NO_ICON_TINT;
174 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700175 private CharSequence mLabel;
176 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700177 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700178
Santos Cordon32c65a52014-10-27 14:57:49 -0700179 /**
180 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
181 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700182 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
183 this.mAccountHandle = accountHandle;
184 this.mLabel = label;
185 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700186
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700187 /**
188 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
189 * {@link PhoneAccount}.
190 *
191 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
192 */
193 public Builder(PhoneAccount phoneAccount) {
194 mAccountHandle = phoneAccount.getAccountHandle();
195 mAddress = phoneAccount.getAddress();
196 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
197 mCapabilities = phoneAccount.getCapabilities();
198 mIconResId = phoneAccount.getIconResId();
Ihab Awad074bf102014-10-24 11:42:32 -0700199 mIconPackageName = phoneAccount.getIconPackageName();
200 mIconBitmap = phoneAccount.getIconBitmap();
Ihab Awad476cc832014-11-03 09:47:51 -0800201 mIconTint = phoneAccount.getIconTint();
202 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700203 mLabel = phoneAccount.getLabel();
204 mShortDescription = phoneAccount.getShortDescription();
205 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700206 }
207
Evan Charlton134dd682014-11-25 14:12:57 -0800208 /** @hide */
Brian Attwell48d8442e2014-12-19 11:37:16 -0800209 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800210 public Builder setAccountHandle(PhoneAccountHandle accountHandle) {
211 mAccountHandle = accountHandle;
212 return this;
213 }
214
Santos Cordon32c65a52014-10-27 14:57:49 -0700215 /**
216 * Sets the address. See {@link PhoneAccount#getAddress}.
217 *
218 * @param value The address of the phone account.
219 * @return The builder.
220 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700221 public Builder setAddress(Uri value) {
222 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700223 return this;
224 }
225
Santos Cordon32c65a52014-10-27 14:57:49 -0700226 /**
227 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
228 *
229 * @param value The subscription address.
230 * @return The builder.
231 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700232 public Builder setSubscriptionAddress(Uri value) {
233 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700234 return this;
235 }
236
Santos Cordon32c65a52014-10-27 14:57:49 -0700237 /**
238 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
239 *
240 * @param value The capabilities to set.
241 * @return The builder.
242 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700243 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700244 this.mCapabilities = value;
245 return this;
246 }
247
Santos Cordon32c65a52014-10-27 14:57:49 -0700248 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800249 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700250 *
Ihab Awad476cc832014-11-03 09:47:51 -0800251 * @param packageContext The package from which to load an icon.
252 * @param iconResId The resource in {@code iconPackageName} representing the icon.
Santos Cordon32c65a52014-10-27 14:57:49 -0700253 * @return The builder.
254 */
Ihab Awad476cc832014-11-03 09:47:51 -0800255 public Builder setIcon(Context packageContext, int iconResId) {
256 return setIcon(packageContext.getPackageName(), iconResId);
257 }
258
259 /**
260 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
261 *
262 * @param iconPackageName The package from which to load an icon.
263 * @param iconResId The resource in {@code iconPackageName} representing the icon.
264 * @return The builder.
265 */
266 public Builder setIcon(String iconPackageName, int iconResId) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800267 return setIcon(iconPackageName, iconResId, NO_ICON_TINT);
Ihab Awad476cc832014-11-03 09:47:51 -0800268 }
269
270 /**
271 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
272 *
273 * @param packageContext The package from which to load an icon.
274 * @param iconResId The resource in {@code iconPackageName} representing the icon.
275 * @param iconTint A color with which to tint this icon.
276 * @return The builder.
277 */
278 public Builder setIcon(Context packageContext, int iconResId, int iconTint) {
279 return setIcon(packageContext.getPackageName(), iconResId, iconTint);
280 }
281
282 /**
283 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
284 *
285 * @param iconPackageName The package from which to load an icon.
286 * @param iconResId The resource in {@code iconPackageName} representing the icon.
287 * @param iconTint A color with which to tint this icon.
288 * @return The builder.
289 */
290 public Builder setIcon(String iconPackageName, int iconResId, int iconTint) {
291 this.mIconPackageName = iconPackageName;
292 this.mIconResId = iconResId;
293 this.mIconTint = iconTint;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700294 return this;
295 }
296
Ihab Awad074bf102014-10-24 11:42:32 -0700297 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800298 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
Ihab Awad074bf102014-10-24 11:42:32 -0700299 *
Ihab Awad476cc832014-11-03 09:47:51 -0800300 * @param iconBitmap The icon bitmap.
Ihab Awad074bf102014-10-24 11:42:32 -0700301 * @return The builder.
302 */
Ihab Awad476cc832014-11-03 09:47:51 -0800303 public Builder setIcon(Bitmap iconBitmap) {
304 this.mIconBitmap = iconBitmap;
305 this.mIconPackageName = null;
306 this.mIconResId = NO_RESOURCE_ID;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800307 this.mIconTint = NO_ICON_TINT;
Ihab Awad074bf102014-10-24 11:42:32 -0700308 return this;
309 }
310
311 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800312 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700313 *
Ihab Awad476cc832014-11-03 09:47:51 -0800314 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700315 * @return The builder.
316 */
Ihab Awad476cc832014-11-03 09:47:51 -0800317 public Builder setHighlightColor(int value) {
318 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700319 return this;
320 }
321
Santos Cordon32c65a52014-10-27 14:57:49 -0700322 /**
323 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
324 *
325 * @param value The short description.
326 * @return The builder.
327 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700328 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700329 this.mShortDescription = value;
330 return this;
331 }
332
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700333 /**
334 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
335 *
336 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700337 * @return The builder.
Andrew Lee3085a6c2014-09-04 10:59:13 -0700338 * @hide
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700339 */
Brian Attwell48d8442e2014-12-19 11:37:16 -0800340 @SystemApi
Andrew Lee3085a6c2014-09-04 10:59:13 -0700341 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700342 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
343 this.mSupportedUriSchemes.add(uriScheme);
344 }
345 return this;
346 }
347
348 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700349 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700350 *
351 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700352 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700353 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700354 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
355 mSupportedUriSchemes.clear();
356
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700357 if (uriSchemes != null && !uriSchemes.isEmpty()) {
358 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700359 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700360 }
361 }
362 return this;
363 }
364
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700365 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700366 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
367 *
368 * @return The {@link PhoneAccount}.
369 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700370 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700371 // If no supported URI schemes were defined, assume "tel" is supported.
372 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700373 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700374 }
375
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700376 return new PhoneAccount(
377 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700378 mAddress,
379 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700380 mCapabilities,
381 mIconResId,
Ihab Awad074bf102014-10-24 11:42:32 -0700382 mIconPackageName,
383 mIconBitmap,
Ihab Awad476cc832014-11-03 09:47:51 -0800384 mIconTint,
385 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700386 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700387 mShortDescription,
Nancy Chen210ef032014-09-15 17:58:42 -0700388 mSupportedUriSchemes);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700389 }
390 }
391
392 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700393 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700394 Uri address,
395 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700396 int capabilities,
Ihab Awad807fe0a2014-07-09 12:30:52 -0700397 int iconResId,
Ihab Awad074bf102014-10-24 11:42:32 -0700398 String iconPackageName,
399 Bitmap iconBitmap,
Ihab Awad476cc832014-11-03 09:47:51 -0800400 int iconTint,
401 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700402 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700403 CharSequence shortDescription,
Nancy Chen210ef032014-09-15 17:58:42 -0700404 List<String> supportedUriSchemes) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700405 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700406 mAddress = address;
407 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700408 mCapabilities = capabilities;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700409 mIconResId = iconResId;
Ihab Awad074bf102014-10-24 11:42:32 -0700410 mIconPackageName = iconPackageName;
411 mIconBitmap = iconBitmap;
Ihab Awad476cc832014-11-03 09:47:51 -0800412 mIconTint = iconTint;
413 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700414 mLabel = label;
415 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700416 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700417 }
418
Andrew Lee3085a6c2014-09-04 10:59:13 -0700419 public static Builder builder(
420 PhoneAccountHandle accountHandle,
421 CharSequence label) {
422 return new Builder(accountHandle, label);
423 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700424
Ihab Awad807fe0a2014-07-09 12:30:52 -0700425 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700426 * Returns a builder initialized with the current {@link PhoneAccount} instance.
427 *
428 * @return The builder.
429 * @hide
430 */
Brian Attwell48d8442e2014-12-19 11:37:16 -0800431 @SystemApi
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700432 public Builder toBuilder() { return new Builder(this); }
433
434 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700435 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700436 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700437 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700438 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700439 public PhoneAccountHandle getAccountHandle() {
440 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700441 }
442
443 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700444 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700445 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700446 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700447 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700448 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700449 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700450 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700451 public Uri getAddress() {
452 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700453 }
454
455 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700456 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700457 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700458 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000459 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
460 * has been used to alter the callback number.
461 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700462 *
463 * @return The subscription number, suitable for display to the user.
464 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700465 public Uri getSubscriptionAddress() {
466 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700467 }
468
469 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700470 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700471 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700472 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700473 */
474 public int getCapabilities() {
475 return mCapabilities;
476 }
477
478 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700479 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
480 * bit mask.
481 *
482 * @param capability The capabilities to check.
483 * @return {@code True} if the phone account has the capability.
484 */
485 public boolean hasCapabilities(int capability) {
486 return (mCapabilities & capability) == capability;
487 }
488
489 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700490 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700491 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700492 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700493 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700494 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700495 return mLabel;
496 }
497
498 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700499 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700500 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700501 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700502 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700503 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700504 return mShortDescription;
505 }
506
507 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700508 * The URI schemes supported by this {@code PhoneAccount}.
509 *
510 * @return The URI schemes.
511 */
512 public List<String> getSupportedUriSchemes() {
513 return mSupportedUriSchemes;
514 }
515
516 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700517 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700518 * scheme.
519 *
520 * @param uriScheme The URI scheme to check.
Andrew Lee3085a6c2014-09-04 10:59:13 -0700521 * @return {@code True} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700522 * specified URI scheme.
523 */
524 public boolean supportsUriScheme(String uriScheme) {
525 if (mSupportedUriSchemes == null || uriScheme == null) {
526 return false;
527 }
528
529 for (String scheme : mSupportedUriSchemes) {
530 if (scheme != null && scheme.equals(uriScheme)) {
531 return true;
532 }
533 }
534 return false;
535 }
536
537 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700538 * The icon resource ID for the icon of this {@code PhoneAccount}.
539 * <p>
540 * Creators of a {@code PhoneAccount} who possess the icon in static resources should prefer
541 * this method of indicating the icon rather than using {@link #getIconBitmap()}, since it
542 * leads to less resource usage.
543 * <p>
Ihab Awad476cc832014-11-03 09:47:51 -0800544 * Clients wishing to display a {@code PhoneAccount} should use {@link #createIconDrawable(Context)}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700545 *
546 * @return A resource ID.
547 */
548 public int getIconResId() {
549 return mIconResId;
550 }
551
552 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700553 * The package name from which to load the icon of this {@code PhoneAccount}.
554 * <p>
555 * If this property is {@code null}, the resource {@link #getIconResId()} will be loaded from
556 * the package in the {@link ComponentName} of the {@link #getAccountHandle()}.
557 * <p>
Ihab Awad476cc832014-11-03 09:47:51 -0800558 * Clients wishing to display a {@code PhoneAccount} should use {@link #createIconDrawable(Context)}.
Ihab Awad074bf102014-10-24 11:42:32 -0700559 *
560 * @return A package name.
561 */
562 public String getIconPackageName() {
563 return mIconPackageName;
564 }
565
566 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800567 * A tint to apply to the icon of this {@code PhoneAccount}.
Nancy Chen3ace54b2014-10-22 17:45:26 -0700568 *
569 * @return A hexadecimal color value.
570 */
Ihab Awad476cc832014-11-03 09:47:51 -0800571 public int getIconTint() {
572 return mIconTint;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700573 }
574
575 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700576 * A literal icon bitmap to represent this {@code PhoneAccount} in a user interface.
577 * <p>
578 * If this property is specified, it is to be considered the preferred icon. Otherwise, the
579 * resource specified by {@link #getIconResId()} should be used.
580 * <p>
Ihab Awad476cc832014-11-03 09:47:51 -0800581 * Clients wishing to display a {@code PhoneAccount} should use
582 * {@link #createIconDrawable(Context)}.
Ihab Awad074bf102014-10-24 11:42:32 -0700583 *
584 * @return A bitmap.
585 */
586 public Bitmap getIconBitmap() {
587 return mIconBitmap;
588 }
589
590 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800591 * A highlight color to use in displaying information about this {@code PhoneAccount}.
592 *
593 * @return A hexadecimal color value.
594 */
595 public int getHighlightColor() {
596 return mHighlightColor;
597 }
598
599 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700600 * Builds and returns an icon {@code Drawable} to represent this {@code PhoneAccount} in a user
601 * interface. Uses the properties {@link #getIconResId()}, {@link #getIconPackageName()}, and
602 * {@link #getIconBitmap()} as necessary.
603 *
604 * @param context A {@code Context} to use for loading {@code Drawable}s.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700605 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700606 * @return An icon for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700607 */
Ihab Awad476cc832014-11-03 09:47:51 -0800608 public Drawable createIconDrawable(Context context) {
Ihab Awad074bf102014-10-24 11:42:32 -0700609 if (mIconBitmap != null) {
610 return new BitmapDrawable(context.getResources(), mIconBitmap);
Sailesh Nepal77780a42014-09-26 18:12:00 -0700611 }
612
Ihab Awad074bf102014-10-24 11:42:32 -0700613 if (mIconResId != 0) {
Ihab Awad074bf102014-10-24 11:42:32 -0700614 try {
Ihab Awad476cc832014-11-03 09:47:51 -0800615 Context packageContext = context.createPackageContext(mIconPackageName, 0);
Ihab Awad074bf102014-10-24 11:42:32 -0700616 try {
Ihab Awad476cc832014-11-03 09:47:51 -0800617 Drawable iconDrawable = packageContext.getDrawable(mIconResId);
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800618 if (mIconTint != NO_ICON_TINT) {
Ihab Awad476cc832014-11-03 09:47:51 -0800619 iconDrawable.setTint(mIconTint);
620 }
621 return iconDrawable;
Ihab Awad074bf102014-10-24 11:42:32 -0700622 } catch (NotFoundException | MissingResourceException e) {
Ihab Awad476cc832014-11-03 09:47:51 -0800623 Log.e(this, e, "Cannot find icon %d in package %s",
624 mIconResId, mIconPackageName);
Ihab Awad074bf102014-10-24 11:42:32 -0700625 }
626 } catch (PackageManager.NameNotFoundException e) {
Ihab Awad476cc832014-11-03 09:47:51 -0800627 Log.w(this, "Cannot find package %s", mIconPackageName);
Ihab Awad074bf102014-10-24 11:42:32 -0700628 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700629 }
Ihab Awad074bf102014-10-24 11:42:32 -0700630
631 return new ColorDrawable(Color.TRANSPARENT);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700632 }
633
634 //
635 // Parcelable implementation
636 //
637
638 @Override
639 public int describeContents() {
640 return 0;
641 }
642
643 @Override
644 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800645 if (mAccountHandle == null) {
646 out.writeInt(0);
647 } else {
648 out.writeInt(1);
649 mAccountHandle.writeToParcel(out, flags);
650 }
651 if (mAddress == null) {
652 out.writeInt(0);
653 } else {
654 out.writeInt(1);
655 mAddress.writeToParcel(out, flags);
656 }
657 if (mSubscriptionAddress == null) {
658 out.writeInt(0);
659 } else {
660 out.writeInt(1);
661 mSubscriptionAddress.writeToParcel(out, flags);
662 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700663 out.writeInt(mCapabilities);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700664 out.writeInt(mIconResId);
Ihab Awad074bf102014-10-24 11:42:32 -0700665 out.writeString(mIconPackageName);
Ihab Awad476cc832014-11-03 09:47:51 -0800666 if (mIconBitmap == null) {
667 out.writeInt(0);
668 } else {
Ihab Awad96802ad2014-11-11 18:41:39 -0800669 out.writeInt(1);
Ihab Awad476cc832014-11-03 09:47:51 -0800670 mIconBitmap.writeToParcel(out, flags);
671 }
672 out.writeInt(mIconTint);
673 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700674 out.writeCharSequence(mLabel);
675 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800676 out.writeStringList(mSupportedUriSchemes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700677 }
678
Evan Charlton8c8a0622014-07-20 12:31:00 -0700679 public static final Creator<PhoneAccount> CREATOR
680 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700681 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700682 public PhoneAccount createFromParcel(Parcel in) {
683 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700684 }
685
686 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700687 public PhoneAccount[] newArray(int size) {
688 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700689 }
690 };
691
Evan Charlton8c8a0622014-07-20 12:31:00 -0700692 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800693 if (in.readInt() > 0) {
694 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
695 } else {
696 mAccountHandle = null;
697 }
698 if (in.readInt() > 0) {
699 mAddress = Uri.CREATOR.createFromParcel(in);
700 } else {
701 mAddress = null;
702 }
703 if (in.readInt() > 0) {
704 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
705 } else {
706 mSubscriptionAddress = null;
707 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700708 mCapabilities = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700709 mIconResId = in.readInt();
Ihab Awad074bf102014-10-24 11:42:32 -0700710 mIconPackageName = in.readString();
Ihab Awad476cc832014-11-03 09:47:51 -0800711 if (in.readInt() > 0) {
712 mIconBitmap = Bitmap.CREATOR.createFromParcel(in);
713 } else {
714 mIconBitmap = null;
715 }
716 mIconTint = in.readInt();
717 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700718 mLabel = in.readCharSequence();
719 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800720 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700721 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700722
723 @Override
724 public String toString() {
725 StringBuilder sb = new StringBuilder().append("[PhoneAccount: ")
726 .append(mAccountHandle)
727 .append(" Capabilities: ")
728 .append(mCapabilities)
729 .append(" Schemes: ");
730 for (String scheme : mSupportedUriSchemes) {
731 sb.append(scheme)
732 .append(" ");
733 }
734 sb.append("]");
735 return sb.toString();
736 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700737}