blob: 00d170fb98ba7888020fdef13937272dc58763ff [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}
63 */
Ihab Awadf8b69882014-07-25 15:14:01 -070064 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070065
66 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -070067 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -070068 * traditional SIM-based telephony calls. This account will be treated as a distinct method
69 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -070070 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -070071 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -070072 * <p>
73 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -070074 * <p>
Ihab Awad94cf4bf2014-07-17 11:21:19 -070075 */
76 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
77
Ihab Awad7522bbd62014-07-18 15:53:17 -070078 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070079 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -070080 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -070081 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -070082 * Only the Android framework can register a {@code PhoneAccount} having this capability.
83 * <p>
84 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -070085 */
86 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
87
Ihab Awadf8b69882014-07-25 15:14:01 -070088 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070089 * Flag indicating that this {@code PhoneAccount} is capable of placing video calls.
90 * <p>
91 * See {@link #getCapabilities}
Tyler Gunnbe74de02014-08-29 14:51:48 -070092 * @hide
Ihab Awadf8b69882014-07-25 15:14:01 -070093 */
Brian Attwell48d8442e2014-12-19 11:37:16 -080094 @SystemApi
Ihab Awadf8b69882014-07-25 15:14:01 -070095 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
96
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070097 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -070098 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
99 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
100 * <p>
101 * See {@link #getCapabilities}
102 */
103 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
104
105 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800106 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
107 * should only be used by system apps (and will be ignored for all other apps trying to use it).
108 * <p>
109 * See {@link #getCapabilities}
110 * @hide
111 */
Brian Attwell48d8442e2014-12-19 11:37:16 -0800112 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800113 public static final int CAPABILITY_MULTI_USER = 0x20;
114
115 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700116 * URI scheme for telephone number URIs.
117 */
118 public static final String SCHEME_TEL = "tel";
119
120 /**
121 * URI scheme for voicemail URIs.
122 */
123 public static final String SCHEME_VOICEMAIL = "voicemail";
124
125 /**
126 * URI scheme for SIP URIs.
127 */
128 public static final String SCHEME_SIP = "sip";
129
Nancy Chen3ace54b2014-10-22 17:45:26 -0700130 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800131 * Indicating no icon tint is set.
Nancy Chen3ace54b2014-10-22 17:45:26 -0700132 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800133 public static final int NO_ICON_TINT = 0;
134
135 /**
136 * Indicating no hightlight color is set.
137 */
138 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700139
Ihab Awad476cc832014-11-03 09:47:51 -0800140 /**
141 * Indicating no resource ID is set.
142 */
143 public static final int NO_RESOURCE_ID = -1;
144
Evan Charlton8c8a0622014-07-20 12:31:00 -0700145 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700146 private final Uri mAddress;
147 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700148 private final int mCapabilities;
149 private final int mIconResId;
Ihab Awad074bf102014-10-24 11:42:32 -0700150 private final String mIconPackageName;
151 private final Bitmap mIconBitmap;
Ihab Awad476cc832014-11-03 09:47:51 -0800152 private final int mIconTint;
153 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700154 private final CharSequence mLabel;
155 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700156 private final List<String> mSupportedUriSchemes;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700157
Santos Cordon32c65a52014-10-27 14:57:49 -0700158 /**
159 * Helper class for creating a {@link PhoneAccount}.
160 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700161 public static class Builder {
162 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700163 private Uri mAddress;
164 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700165 private int mCapabilities;
166 private int mIconResId;
Ihab Awad074bf102014-10-24 11:42:32 -0700167 private String mIconPackageName;
168 private Bitmap mIconBitmap;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800169 private int mIconTint = NO_ICON_TINT;
170 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700171 private CharSequence mLabel;
172 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700173 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700174
Santos Cordon32c65a52014-10-27 14:57:49 -0700175 /**
176 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
177 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700178 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
179 this.mAccountHandle = accountHandle;
180 this.mLabel = label;
181 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700182
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700183 /**
184 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
185 * {@link PhoneAccount}.
186 *
187 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
188 */
189 public Builder(PhoneAccount phoneAccount) {
190 mAccountHandle = phoneAccount.getAccountHandle();
191 mAddress = phoneAccount.getAddress();
192 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
193 mCapabilities = phoneAccount.getCapabilities();
194 mIconResId = phoneAccount.getIconResId();
Ihab Awad074bf102014-10-24 11:42:32 -0700195 mIconPackageName = phoneAccount.getIconPackageName();
196 mIconBitmap = phoneAccount.getIconBitmap();
Ihab Awad476cc832014-11-03 09:47:51 -0800197 mIconTint = phoneAccount.getIconTint();
198 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700199 mLabel = phoneAccount.getLabel();
200 mShortDescription = phoneAccount.getShortDescription();
201 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700202 }
203
Santos Cordon32c65a52014-10-27 14:57:49 -0700204 /**
205 * Sets the address. See {@link PhoneAccount#getAddress}.
206 *
207 * @param value The address of the phone account.
208 * @return The builder.
209 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700210 public Builder setAddress(Uri value) {
211 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700212 return this;
213 }
214
Santos Cordon32c65a52014-10-27 14:57:49 -0700215 /**
216 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
217 *
218 * @param value The subscription address.
219 * @return The builder.
220 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700221 public Builder setSubscriptionAddress(Uri value) {
222 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700223 return this;
224 }
225
Santos Cordon32c65a52014-10-27 14:57:49 -0700226 /**
227 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
228 *
229 * @param value The capabilities to set.
230 * @return The builder.
231 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700232 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700233 this.mCapabilities = value;
234 return this;
235 }
236
Santos Cordon32c65a52014-10-27 14:57:49 -0700237 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800238 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700239 *
Ihab Awad476cc832014-11-03 09:47:51 -0800240 * @param packageContext The package from which to load an icon.
241 * @param iconResId The resource in {@code iconPackageName} representing the icon.
Santos Cordon32c65a52014-10-27 14:57:49 -0700242 * @return The builder.
243 */
Ihab Awad476cc832014-11-03 09:47:51 -0800244 public Builder setIcon(Context packageContext, int iconResId) {
245 return setIcon(packageContext.getPackageName(), iconResId);
246 }
247
248 /**
249 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
250 *
251 * @param iconPackageName The package from which to load an icon.
252 * @param iconResId The resource in {@code iconPackageName} representing the icon.
253 * @return The builder.
254 */
255 public Builder setIcon(String iconPackageName, int iconResId) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800256 return setIcon(iconPackageName, iconResId, NO_ICON_TINT);
Ihab Awad476cc832014-11-03 09:47:51 -0800257 }
258
259 /**
260 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
261 *
262 * @param packageContext The package from which to load an icon.
263 * @param iconResId The resource in {@code iconPackageName} representing the icon.
264 * @param iconTint A color with which to tint this icon.
265 * @return The builder.
266 */
267 public Builder setIcon(Context packageContext, int iconResId, int iconTint) {
268 return setIcon(packageContext.getPackageName(), iconResId, iconTint);
269 }
270
271 /**
272 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
273 *
274 * @param iconPackageName The package from which to load an icon.
275 * @param iconResId The resource in {@code iconPackageName} representing the icon.
276 * @param iconTint A color with which to tint this icon.
277 * @return The builder.
278 */
279 public Builder setIcon(String iconPackageName, int iconResId, int iconTint) {
280 this.mIconPackageName = iconPackageName;
281 this.mIconResId = iconResId;
282 this.mIconTint = iconTint;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700283 return this;
284 }
285
Ihab Awad074bf102014-10-24 11:42:32 -0700286 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800287 * Sets the icon. See {@link PhoneAccount#createIconDrawable}.
Ihab Awad074bf102014-10-24 11:42:32 -0700288 *
Ihab Awad476cc832014-11-03 09:47:51 -0800289 * @param iconBitmap The icon bitmap.
Ihab Awad074bf102014-10-24 11:42:32 -0700290 * @return The builder.
291 */
Ihab Awad476cc832014-11-03 09:47:51 -0800292 public Builder setIcon(Bitmap iconBitmap) {
293 this.mIconBitmap = iconBitmap;
294 this.mIconPackageName = null;
295 this.mIconResId = NO_RESOURCE_ID;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800296 this.mIconTint = NO_ICON_TINT;
Ihab Awad074bf102014-10-24 11:42:32 -0700297 return this;
298 }
299
300 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800301 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700302 *
Ihab Awad476cc832014-11-03 09:47:51 -0800303 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700304 * @return The builder.
305 */
Ihab Awad476cc832014-11-03 09:47:51 -0800306 public Builder setHighlightColor(int value) {
307 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700308 return this;
309 }
310
Santos Cordon32c65a52014-10-27 14:57:49 -0700311 /**
312 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
313 *
314 * @param value The short description.
315 * @return The builder.
316 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700317 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700318 this.mShortDescription = value;
319 return this;
320 }
321
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700322 /**
323 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
324 *
325 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700326 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700327 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700328 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700329 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
330 this.mSupportedUriSchemes.add(uriScheme);
331 }
332 return this;
333 }
334
335 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700336 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700337 *
338 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700339 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700340 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700341 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
342 mSupportedUriSchemes.clear();
343
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700344 if (uriSchemes != null && !uriSchemes.isEmpty()) {
345 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700346 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700347 }
348 }
349 return this;
350 }
351
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700352 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700353 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
354 *
355 * @return The {@link PhoneAccount}.
356 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700357 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700358 // If no supported URI schemes were defined, assume "tel" is supported.
359 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700360 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700361 }
362
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700363 return new PhoneAccount(
364 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700365 mAddress,
366 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700367 mCapabilities,
368 mIconResId,
Ihab Awad074bf102014-10-24 11:42:32 -0700369 mIconPackageName,
370 mIconBitmap,
Ihab Awad476cc832014-11-03 09:47:51 -0800371 mIconTint,
372 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700373 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700374 mShortDescription,
Nancy Chen210ef032014-09-15 17:58:42 -0700375 mSupportedUriSchemes);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700376 }
377 }
378
379 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700380 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700381 Uri address,
382 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700383 int capabilities,
Ihab Awad807fe0a2014-07-09 12:30:52 -0700384 int iconResId,
Ihab Awad074bf102014-10-24 11:42:32 -0700385 String iconPackageName,
386 Bitmap iconBitmap,
Ihab Awad476cc832014-11-03 09:47:51 -0800387 int iconTint,
388 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700389 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700390 CharSequence shortDescription,
Nancy Chen210ef032014-09-15 17:58:42 -0700391 List<String> supportedUriSchemes) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700392 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700393 mAddress = address;
394 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700395 mCapabilities = capabilities;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700396 mIconResId = iconResId;
Ihab Awad074bf102014-10-24 11:42:32 -0700397 mIconPackageName = iconPackageName;
398 mIconBitmap = iconBitmap;
Ihab Awad476cc832014-11-03 09:47:51 -0800399 mIconTint = iconTint;
400 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700401 mLabel = label;
402 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700403 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700404 }
405
Andrew Lee3085a6c2014-09-04 10:59:13 -0700406 public static Builder builder(
407 PhoneAccountHandle accountHandle,
408 CharSequence label) {
409 return new Builder(accountHandle, label);
410 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700411
Ihab Awad807fe0a2014-07-09 12:30:52 -0700412 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700413 * Returns a builder initialized with the current {@link PhoneAccount} instance.
414 *
415 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700416 */
417 public Builder toBuilder() { return new Builder(this); }
418
419 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700420 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700421 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700422 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700423 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700424 public PhoneAccountHandle getAccountHandle() {
425 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700426 }
427
428 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700429 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700430 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700431 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700432 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700433 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700434 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700435 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700436 public Uri getAddress() {
437 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700438 }
439
440 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700441 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700442 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700443 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000444 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
445 * has been used to alter the callback number.
446 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700447 *
448 * @return The subscription number, suitable for display to the user.
449 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700450 public Uri getSubscriptionAddress() {
451 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700452 }
453
454 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700455 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700456 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700457 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700458 */
459 public int getCapabilities() {
460 return mCapabilities;
461 }
462
463 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700464 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
465 * bit mask.
466 *
467 * @param capability The capabilities to check.
468 * @return {@code True} if the phone account has the capability.
469 */
470 public boolean hasCapabilities(int capability) {
471 return (mCapabilities & capability) == capability;
472 }
473
474 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700475 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700476 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700477 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700478 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700479 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700480 return mLabel;
481 }
482
483 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700484 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700485 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700486 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700487 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700488 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700489 return mShortDescription;
490 }
491
492 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700493 * The URI schemes supported by this {@code PhoneAccount}.
494 *
495 * @return The URI schemes.
496 */
497 public List<String> getSupportedUriSchemes() {
498 return mSupportedUriSchemes;
499 }
500
501 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700502 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700503 * scheme.
504 *
505 * @param uriScheme The URI scheme to check.
Andrew Lee3085a6c2014-09-04 10:59:13 -0700506 * @return {@code True} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700507 * specified URI scheme.
508 */
509 public boolean supportsUriScheme(String uriScheme) {
510 if (mSupportedUriSchemes == null || uriScheme == null) {
511 return false;
512 }
513
514 for (String scheme : mSupportedUriSchemes) {
515 if (scheme != null && scheme.equals(uriScheme)) {
516 return true;
517 }
518 }
519 return false;
520 }
521
522 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700523 * The icon resource ID for the icon of this {@code PhoneAccount}.
524 * <p>
525 * Creators of a {@code PhoneAccount} who possess the icon in static resources should prefer
526 * this method of indicating the icon rather than using {@link #getIconBitmap()}, since it
527 * leads to less resource usage.
528 * <p>
Ihab Awad476cc832014-11-03 09:47:51 -0800529 * Clients wishing to display a {@code PhoneAccount} should use {@link #createIconDrawable(Context)}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700530 *
531 * @return A resource ID.
532 */
533 public int getIconResId() {
534 return mIconResId;
535 }
536
537 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700538 * The package name from which to load the icon of this {@code PhoneAccount}.
539 * <p>
540 * If this property is {@code null}, the resource {@link #getIconResId()} will be loaded from
541 * the package in the {@link ComponentName} of the {@link #getAccountHandle()}.
542 * <p>
Ihab Awad476cc832014-11-03 09:47:51 -0800543 * Clients wishing to display a {@code PhoneAccount} should use {@link #createIconDrawable(Context)}.
Ihab Awad074bf102014-10-24 11:42:32 -0700544 *
545 * @return A package name.
546 */
547 public String getIconPackageName() {
548 return mIconPackageName;
549 }
550
551 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800552 * A tint to apply to the icon of this {@code PhoneAccount}.
Nancy Chen3ace54b2014-10-22 17:45:26 -0700553 *
554 * @return A hexadecimal color value.
555 */
Ihab Awad476cc832014-11-03 09:47:51 -0800556 public int getIconTint() {
557 return mIconTint;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700558 }
559
560 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700561 * A literal icon bitmap to represent this {@code PhoneAccount} in a user interface.
562 * <p>
563 * If this property is specified, it is to be considered the preferred icon. Otherwise, the
564 * resource specified by {@link #getIconResId()} should be used.
565 * <p>
Ihab Awad476cc832014-11-03 09:47:51 -0800566 * Clients wishing to display a {@code PhoneAccount} should use
567 * {@link #createIconDrawable(Context)}.
Ihab Awad074bf102014-10-24 11:42:32 -0700568 *
569 * @return A bitmap.
570 */
571 public Bitmap getIconBitmap() {
572 return mIconBitmap;
573 }
574
575 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800576 * A highlight color to use in displaying information about this {@code PhoneAccount}.
577 *
578 * @return A hexadecimal color value.
579 */
580 public int getHighlightColor() {
581 return mHighlightColor;
582 }
583
584 /**
Ihab Awad074bf102014-10-24 11:42:32 -0700585 * Builds and returns an icon {@code Drawable} to represent this {@code PhoneAccount} in a user
586 * interface. Uses the properties {@link #getIconResId()}, {@link #getIconPackageName()}, and
587 * {@link #getIconBitmap()} as necessary.
588 *
589 * @param context A {@code Context} to use for loading {@code Drawable}s.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700590 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700591 * @return An icon for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700592 */
Ihab Awad476cc832014-11-03 09:47:51 -0800593 public Drawable createIconDrawable(Context context) {
Ihab Awad074bf102014-10-24 11:42:32 -0700594 if (mIconBitmap != null) {
595 return new BitmapDrawable(context.getResources(), mIconBitmap);
Sailesh Nepal77780a42014-09-26 18:12:00 -0700596 }
597
Ihab Awad074bf102014-10-24 11:42:32 -0700598 if (mIconResId != 0) {
Ihab Awad074bf102014-10-24 11:42:32 -0700599 try {
Ihab Awad476cc832014-11-03 09:47:51 -0800600 Context packageContext = context.createPackageContext(mIconPackageName, 0);
Ihab Awad074bf102014-10-24 11:42:32 -0700601 try {
Ihab Awad476cc832014-11-03 09:47:51 -0800602 Drawable iconDrawable = packageContext.getDrawable(mIconResId);
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800603 if (mIconTint != NO_ICON_TINT) {
Ihab Awad476cc832014-11-03 09:47:51 -0800604 iconDrawable.setTint(mIconTint);
605 }
606 return iconDrawable;
Ihab Awad074bf102014-10-24 11:42:32 -0700607 } catch (NotFoundException | MissingResourceException e) {
Ihab Awad476cc832014-11-03 09:47:51 -0800608 Log.e(this, e, "Cannot find icon %d in package %s",
609 mIconResId, mIconPackageName);
Ihab Awad074bf102014-10-24 11:42:32 -0700610 }
611 } catch (PackageManager.NameNotFoundException e) {
Ihab Awad476cc832014-11-03 09:47:51 -0800612 Log.w(this, "Cannot find package %s", mIconPackageName);
Ihab Awad074bf102014-10-24 11:42:32 -0700613 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700614 }
Ihab Awad074bf102014-10-24 11:42:32 -0700615
616 return new ColorDrawable(Color.TRANSPARENT);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700617 }
618
619 //
620 // Parcelable implementation
621 //
622
623 @Override
624 public int describeContents() {
625 return 0;
626 }
627
628 @Override
629 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800630 if (mAccountHandle == null) {
631 out.writeInt(0);
632 } else {
633 out.writeInt(1);
634 mAccountHandle.writeToParcel(out, flags);
635 }
636 if (mAddress == null) {
637 out.writeInt(0);
638 } else {
639 out.writeInt(1);
640 mAddress.writeToParcel(out, flags);
641 }
642 if (mSubscriptionAddress == null) {
643 out.writeInt(0);
644 } else {
645 out.writeInt(1);
646 mSubscriptionAddress.writeToParcel(out, flags);
647 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700648 out.writeInt(mCapabilities);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700649 out.writeInt(mIconResId);
Ihab Awad074bf102014-10-24 11:42:32 -0700650 out.writeString(mIconPackageName);
Ihab Awad476cc832014-11-03 09:47:51 -0800651 if (mIconBitmap == null) {
652 out.writeInt(0);
653 } else {
Ihab Awad96802ad2014-11-11 18:41:39 -0800654 out.writeInt(1);
Ihab Awad476cc832014-11-03 09:47:51 -0800655 mIconBitmap.writeToParcel(out, flags);
656 }
657 out.writeInt(mIconTint);
658 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700659 out.writeCharSequence(mLabel);
660 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800661 out.writeStringList(mSupportedUriSchemes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700662 }
663
Evan Charlton8c8a0622014-07-20 12:31:00 -0700664 public static final Creator<PhoneAccount> CREATOR
665 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700666 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700667 public PhoneAccount createFromParcel(Parcel in) {
668 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700669 }
670
671 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700672 public PhoneAccount[] newArray(int size) {
673 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700674 }
675 };
676
Evan Charlton8c8a0622014-07-20 12:31:00 -0700677 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800678 if (in.readInt() > 0) {
679 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
680 } else {
681 mAccountHandle = null;
682 }
683 if (in.readInt() > 0) {
684 mAddress = Uri.CREATOR.createFromParcel(in);
685 } else {
686 mAddress = null;
687 }
688 if (in.readInt() > 0) {
689 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
690 } else {
691 mSubscriptionAddress = null;
692 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700693 mCapabilities = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700694 mIconResId = in.readInt();
Ihab Awad074bf102014-10-24 11:42:32 -0700695 mIconPackageName = in.readString();
Ihab Awad476cc832014-11-03 09:47:51 -0800696 if (in.readInt() > 0) {
697 mIconBitmap = Bitmap.CREATOR.createFromParcel(in);
698 } else {
699 mIconBitmap = null;
700 }
701 mIconTint = in.readInt();
702 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700703 mLabel = in.readCharSequence();
704 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800705 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Ihab Awad807fe0a2014-07-09 12:30:52 -0700706 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700707
708 @Override
709 public String toString() {
710 StringBuilder sb = new StringBuilder().append("[PhoneAccount: ")
711 .append(mAccountHandle)
712 .append(" Capabilities: ")
713 .append(mCapabilities)
714 .append(" Schemes: ");
715 for (String scheme : mSupportedUriSchemes) {
716 sb.append(scheme)
717 .append(" ");
718 }
719 sb.append("]");
720 return sb.toString();
721 }
Ihab Awad807fe0a2014-07-09 12:30:52 -0700722}