| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 1 | /* |
| 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 Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 17 | package android.telecom; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 18 | |
| Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 20 | import android.content.ComponentName; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 21 | import android.content.Context; |
| 22 | import android.content.pm.PackageManager; |
| Santos Cordon | e8dc4be | 2014-07-21 01:28:28 -0700 | [diff] [blame] | 23 | import android.content.res.Resources.NotFoundException; |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 24 | import android.graphics.Bitmap; |
| 25 | import android.graphics.Color; |
| 26 | import android.graphics.drawable.BitmapDrawable; |
| 27 | import android.graphics.drawable.ColorDrawable; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 28 | import android.graphics.drawable.Drawable; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 29 | import android.net.Uri; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 30 | import android.os.Parcel; |
| 31 | import android.os.Parcelable; |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 32 | import android.text.TextUtils; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 33 | |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 34 | import java.lang.String; |
| 35 | import java.util.ArrayList; |
| 36 | import java.util.Collections; |
| 37 | import java.util.List; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 38 | import java.util.MissingResourceException; |
| 39 | |
| 40 | /** |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 41 | * Represents a distinct method to place or receive a phone call. Apps which can place calls and |
| 42 | * want those calls to be integrated into the dialer and in-call UI should build an instance of |
| 43 | * this class and register it with the system using {@link TelecomManager#registerPhoneAccount}. |
| 44 | * <p> |
| 45 | * {@link TelecomManager} uses registered {@link PhoneAccount}s to present the user with |
| 46 | * alternative options when placing a phone call. When building a {@link PhoneAccount}, the app |
| 47 | * should supply a valid {@link PhoneAccountHandle} that references the {@link ConnectionService} |
| 48 | * implementation Telecom will use to interact with the app. |
| Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 49 | * @hide |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 50 | */ |
| Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 51 | @SystemApi |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 52 | public class PhoneAccount implements Parcelable { |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 53 | |
| 54 | /** |
| Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 55 | * 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 Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 60 | * 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 Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 63 | * <p> |
| 64 | * See {@link #getCapabilities} |
| 65 | */ |
| Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 66 | public static final int CAPABILITY_CONNECTION_MANAGER = 0x1; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 67 | |
| 68 | /** |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 69 | * Flag indicating that this {@code PhoneAccount} can make phone calls in place of |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 70 | * 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 Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 72 | * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 73 | * or place calls from the built-in telephony stack. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 74 | * <p> |
| 75 | * See {@link #getCapabilities} |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 76 | * <p> |
| Evan Charlton | 7800fb7 | 2014-07-20 18:09:38 -0700 | [diff] [blame] | 77 | * {@hide} |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 78 | */ |
| 79 | public static final int CAPABILITY_CALL_PROVIDER = 0x2; |
| 80 | |
| Ihab Awad | 7522bbd6 | 2014-07-18 15:53:17 -0700 | [diff] [blame] | 81 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 82 | * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 83 | * subscription. |
| Ihab Awad | 7522bbd6 | 2014-07-18 15:53:17 -0700 | [diff] [blame] | 84 | * <p> |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 85 | * Only the Android framework can register a {@code PhoneAccount} having this capability. |
| 86 | * <p> |
| 87 | * See {@link #getCapabilities} |
| Ihab Awad | 7522bbd6 | 2014-07-18 15:53:17 -0700 | [diff] [blame] | 88 | */ |
| 89 | public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4; |
| 90 | |
| Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 91 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 92 | * Flag indicating that this {@code PhoneAccount} is capable of placing video calls. |
| 93 | * <p> |
| 94 | * See {@link #getCapabilities} |
| Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 95 | * @hide |
| Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 96 | */ |
| 97 | public static final int CAPABILITY_VIDEO_CALLING = 0x8; |
| 98 | |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 99 | /** |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 100 | * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls. |
| 101 | * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls. |
| 102 | * <p> |
| 103 | * See {@link #getCapabilities} |
| 104 | */ |
| 105 | public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10; |
| 106 | |
| 107 | /** |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 108 | * URI scheme for telephone number URIs. |
| 109 | */ |
| 110 | public static final String SCHEME_TEL = "tel"; |
| 111 | |
| 112 | /** |
| 113 | * URI scheme for voicemail URIs. |
| 114 | */ |
| 115 | public static final String SCHEME_VOICEMAIL = "voicemail"; |
| 116 | |
| 117 | /** |
| 118 | * URI scheme for SIP URIs. |
| 119 | */ |
| 120 | public static final String SCHEME_SIP = "sip"; |
| 121 | |
| Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 122 | /** |
| 123 | * Indicating no color is set. |
| 124 | */ |
| 125 | public static final int NO_COLOR = -1; |
| 126 | |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 127 | /** |
| 128 | * Indicating no resource ID is set. |
| 129 | */ |
| 130 | public static final int NO_RESOURCE_ID = -1; |
| 131 | |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 132 | private final PhoneAccountHandle mAccountHandle; |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 133 | private final Uri mAddress; |
| 134 | private final Uri mSubscriptionAddress; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 135 | private final int mCapabilities; |
| 136 | private final int mIconResId; |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 137 | private final String mIconPackageName; |
| 138 | private final Bitmap mIconBitmap; |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 139 | private final int mIconTint; |
| 140 | private final int mHighlightColor; |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 141 | private final CharSequence mLabel; |
| 142 | private final CharSequence mShortDescription; |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 143 | private final List<String> mSupportedUriSchemes; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 144 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 145 | /** |
| 146 | * Helper class for creating a {@link PhoneAccount}. |
| 147 | */ |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 148 | public static class Builder { |
| 149 | private PhoneAccountHandle mAccountHandle; |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 150 | private Uri mAddress; |
| 151 | private Uri mSubscriptionAddress; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 152 | private int mCapabilities; |
| 153 | private int mIconResId; |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 154 | private String mIconPackageName; |
| 155 | private Bitmap mIconBitmap; |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 156 | private int mIconTint = NO_COLOR; |
| 157 | private int mHighlightColor = NO_COLOR; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 158 | private CharSequence mLabel; |
| 159 | private CharSequence mShortDescription; |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 160 | private List<String> mSupportedUriSchemes = new ArrayList<String>(); |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 161 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 162 | /** |
| 163 | * Creates a builder with the specified {@link PhoneAccountHandle} and label. |
| 164 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 165 | public Builder(PhoneAccountHandle accountHandle, CharSequence label) { |
| 166 | this.mAccountHandle = accountHandle; |
| 167 | this.mLabel = label; |
| 168 | } |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 169 | |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 170 | /** |
| 171 | * Creates an instance of the {@link PhoneAccount.Builder} from an existing |
| 172 | * {@link PhoneAccount}. |
| 173 | * |
| 174 | * @param phoneAccount The {@link PhoneAccount} used to initialize the builder. |
| 175 | */ |
| 176 | public Builder(PhoneAccount phoneAccount) { |
| 177 | mAccountHandle = phoneAccount.getAccountHandle(); |
| 178 | mAddress = phoneAccount.getAddress(); |
| 179 | mSubscriptionAddress = phoneAccount.getSubscriptionAddress(); |
| 180 | mCapabilities = phoneAccount.getCapabilities(); |
| 181 | mIconResId = phoneAccount.getIconResId(); |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 182 | mIconPackageName = phoneAccount.getIconPackageName(); |
| 183 | mIconBitmap = phoneAccount.getIconBitmap(); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 184 | mIconTint = phoneAccount.getIconTint(); |
| 185 | mHighlightColor = phoneAccount.getHighlightColor(); |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 186 | mLabel = phoneAccount.getLabel(); |
| 187 | mShortDescription = phoneAccount.getShortDescription(); |
| 188 | mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes()); |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 191 | /** |
| 192 | * Sets the address. See {@link PhoneAccount#getAddress}. |
| 193 | * |
| 194 | * @param value The address of the phone account. |
| 195 | * @return The builder. |
| 196 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 197 | public Builder setAddress(Uri value) { |
| 198 | this.mAddress = value; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 199 | return this; |
| 200 | } |
| 201 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 202 | /** |
| 203 | * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}. |
| 204 | * |
| 205 | * @param value The subscription address. |
| 206 | * @return The builder. |
| 207 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 208 | public Builder setSubscriptionAddress(Uri value) { |
| 209 | this.mSubscriptionAddress = value; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 210 | return this; |
| 211 | } |
| 212 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 213 | /** |
| 214 | * Sets the capabilities. See {@link PhoneAccount#getCapabilities}. |
| 215 | * |
| 216 | * @param value The capabilities to set. |
| 217 | * @return The builder. |
| 218 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 219 | public Builder setCapabilities(int value) { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 220 | this.mCapabilities = value; |
| 221 | return this; |
| 222 | } |
| 223 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 224 | /** |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 225 | * Sets the icon. See {@link PhoneAccount#createIconDrawable}. |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 226 | * |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 227 | * @param packageContext The package from which to load an icon. |
| 228 | * @param iconResId The resource in {@code iconPackageName} representing the icon. |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 229 | * @return The builder. |
| 230 | */ |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 231 | public Builder setIcon(Context packageContext, int iconResId) { |
| 232 | return setIcon(packageContext.getPackageName(), iconResId); |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Sets the icon. See {@link PhoneAccount#createIconDrawable}. |
| 237 | * |
| 238 | * @param iconPackageName The package from which to load an icon. |
| 239 | * @param iconResId The resource in {@code iconPackageName} representing the icon. |
| 240 | * @return The builder. |
| 241 | */ |
| 242 | public Builder setIcon(String iconPackageName, int iconResId) { |
| 243 | return setIcon(iconPackageName, iconResId, NO_COLOR); |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Sets the icon. See {@link PhoneAccount#createIconDrawable}. |
| 248 | * |
| 249 | * @param packageContext The package from which to load an icon. |
| 250 | * @param iconResId The resource in {@code iconPackageName} representing the icon. |
| 251 | * @param iconTint A color with which to tint this icon. |
| 252 | * @return The builder. |
| 253 | */ |
| 254 | public Builder setIcon(Context packageContext, int iconResId, int iconTint) { |
| 255 | return setIcon(packageContext.getPackageName(), iconResId, iconTint); |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Sets the icon. See {@link PhoneAccount#createIconDrawable}. |
| 260 | * |
| 261 | * @param iconPackageName The package from which to load an icon. |
| 262 | * @param iconResId The resource in {@code iconPackageName} representing the icon. |
| 263 | * @param iconTint A color with which to tint this icon. |
| 264 | * @return The builder. |
| 265 | */ |
| 266 | public Builder setIcon(String iconPackageName, int iconResId, int iconTint) { |
| 267 | this.mIconPackageName = iconPackageName; |
| 268 | this.mIconResId = iconResId; |
| 269 | this.mIconTint = iconTint; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 270 | return this; |
| 271 | } |
| 272 | |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 273 | /** |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 274 | * Sets the icon. See {@link PhoneAccount#createIconDrawable}. |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 275 | * |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 276 | * @param iconBitmap The icon bitmap. |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 277 | * @return The builder. |
| 278 | */ |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 279 | public Builder setIcon(Bitmap iconBitmap) { |
| 280 | this.mIconBitmap = iconBitmap; |
| 281 | this.mIconPackageName = null; |
| 282 | this.mIconResId = NO_RESOURCE_ID; |
| 283 | this.mIconTint = NO_COLOR; |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 284 | return this; |
| 285 | } |
| 286 | |
| 287 | /** |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 288 | * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}. |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 289 | * |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 290 | * @param value The highlight color. |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 291 | * @return The builder. |
| 292 | */ |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 293 | public Builder setHighlightColor(int value) { |
| 294 | this.mHighlightColor = value; |
| Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 295 | return this; |
| 296 | } |
| 297 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 298 | /** |
| 299 | * Sets the short description. See {@link PhoneAccount#getShortDescription}. |
| 300 | * |
| 301 | * @param value The short description. |
| 302 | * @return The builder. |
| 303 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 304 | public Builder setShortDescription(CharSequence value) { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 305 | this.mShortDescription = value; |
| 306 | return this; |
| 307 | } |
| 308 | |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 309 | /** |
| 310 | * Specifies an additional URI scheme supported by the {@link PhoneAccount}. |
| 311 | * |
| 312 | * @param uriScheme The URI scheme. |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 313 | * @return The builder. |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 314 | * @hide |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 315 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 316 | public Builder addSupportedUriScheme(String uriScheme) { |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 317 | if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) { |
| 318 | this.mSupportedUriSchemes.add(uriScheme); |
| 319 | } |
| 320 | return this; |
| 321 | } |
| 322 | |
| 323 | /** |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 324 | * Specifies the URI schemes supported by the {@link PhoneAccount}. |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 325 | * |
| 326 | * @param uriSchemes The URI schemes. |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 327 | * @return The builder. |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 328 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 329 | public Builder setSupportedUriSchemes(List<String> uriSchemes) { |
| 330 | mSupportedUriSchemes.clear(); |
| 331 | |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 332 | if (uriSchemes != null && !uriSchemes.isEmpty()) { |
| 333 | for (String uriScheme : uriSchemes) { |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 334 | addSupportedUriScheme(uriScheme); |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 335 | } |
| 336 | } |
| 337 | return this; |
| 338 | } |
| 339 | |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 340 | /** |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 341 | * Creates an instance of a {@link PhoneAccount} based on the current builder settings. |
| 342 | * |
| 343 | * @return The {@link PhoneAccount}. |
| 344 | */ |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 345 | public PhoneAccount build() { |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 346 | // If no supported URI schemes were defined, assume "tel" is supported. |
| 347 | if (mSupportedUriSchemes.isEmpty()) { |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 348 | addSupportedUriScheme(SCHEME_TEL); |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 351 | return new PhoneAccount( |
| 352 | mAccountHandle, |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 353 | mAddress, |
| 354 | mSubscriptionAddress, |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 355 | mCapabilities, |
| 356 | mIconResId, |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 357 | mIconPackageName, |
| 358 | mIconBitmap, |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 359 | mIconTint, |
| 360 | mHighlightColor, |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 361 | mLabel, |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 362 | mShortDescription, |
| Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame] | 363 | mSupportedUriSchemes); |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 364 | } |
| 365 | } |
| 366 | |
| 367 | private PhoneAccount( |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 368 | PhoneAccountHandle account, |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 369 | Uri address, |
| 370 | Uri subscriptionAddress, |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 371 | int capabilities, |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 372 | int iconResId, |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 373 | String iconPackageName, |
| 374 | Bitmap iconBitmap, |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 375 | int iconTint, |
| 376 | int highlightColor, |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 377 | CharSequence label, |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 378 | CharSequence shortDescription, |
| Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame] | 379 | List<String> supportedUriSchemes) { |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 380 | mAccountHandle = account; |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 381 | mAddress = address; |
| 382 | mSubscriptionAddress = subscriptionAddress; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 383 | mCapabilities = capabilities; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 384 | mIconResId = iconResId; |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 385 | mIconPackageName = iconPackageName; |
| 386 | mIconBitmap = iconBitmap; |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 387 | mIconTint = iconTint; |
| 388 | mHighlightColor = highlightColor; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 389 | mLabel = label; |
| 390 | mShortDescription = shortDescription; |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 391 | mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 394 | public static Builder builder( |
| 395 | PhoneAccountHandle accountHandle, |
| 396 | CharSequence label) { |
| 397 | return new Builder(accountHandle, label); |
| 398 | } |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 399 | |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 400 | /** |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 401 | * Returns a builder initialized with the current {@link PhoneAccount} instance. |
| 402 | * |
| 403 | * @return The builder. |
| 404 | * @hide |
| 405 | */ |
| 406 | public Builder toBuilder() { return new Builder(this); } |
| 407 | |
| 408 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 409 | * The unique identifier of this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 410 | * |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 411 | * @return A {@code PhoneAccountHandle}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 412 | */ |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 413 | public PhoneAccountHandle getAccountHandle() { |
| 414 | return mAccountHandle; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | /** |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 418 | * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 419 | * represents the destination from which outgoing calls using this {@code PhoneAccount} |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 420 | * will appear to come, if applicable, and the destination to which incoming calls using this |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 421 | * {@code PhoneAccount} may be addressed. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 422 | * |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 423 | * @return A address expressed as a {@code Uri}, for example, a phone number. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 424 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 425 | public Uri getAddress() { |
| 426 | return mAddress; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 430 | * The raw callback number used for this {@code PhoneAccount}, as distinct from |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 431 | * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 432 | * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration |
| Junda Liu | f52ac90 | 2014-09-25 17:36:48 +0000 | [diff] [blame] | 433 | * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)} |
| 434 | * has been used to alter the callback number. |
| 435 | * <p> |
| Evan Charlton | 222db525 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 436 | * |
| 437 | * @return The subscription number, suitable for display to the user. |
| 438 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 439 | public Uri getSubscriptionAddress() { |
| 440 | return mSubscriptionAddress; |
| Evan Charlton | 222db525 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | /** |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 444 | * The capabilities of this {@code PhoneAccount}. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 445 | * |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 446 | * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 447 | */ |
| 448 | public int getCapabilities() { |
| 449 | return mCapabilities; |
| 450 | } |
| 451 | |
| 452 | /** |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 453 | * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in |
| 454 | * bit mask. |
| 455 | * |
| 456 | * @param capability The capabilities to check. |
| 457 | * @return {@code True} if the phone account has the capability. |
| 458 | */ |
| 459 | public boolean hasCapabilities(int capability) { |
| 460 | return (mCapabilities & capability) == capability; |
| 461 | } |
| 462 | |
| 463 | /** |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 464 | * A short label describing a {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 465 | * |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 466 | * @return A label for this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 467 | */ |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 468 | public CharSequence getLabel() { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 469 | return mLabel; |
| 470 | } |
| 471 | |
| 472 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 473 | * A short paragraph describing this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 474 | * |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 475 | * @return A description for this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 476 | */ |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 477 | public CharSequence getShortDescription() { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 478 | return mShortDescription; |
| 479 | } |
| 480 | |
| 481 | /** |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 482 | * The URI schemes supported by this {@code PhoneAccount}. |
| 483 | * |
| 484 | * @return The URI schemes. |
| 485 | */ |
| 486 | public List<String> getSupportedUriSchemes() { |
| 487 | return mSupportedUriSchemes; |
| 488 | } |
| 489 | |
| 490 | /** |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 491 | * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 492 | * scheme. |
| 493 | * |
| 494 | * @param uriScheme The URI scheme to check. |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 495 | * @return {@code True} if the {@code PhoneAccount} supports calls to/from addresses with the |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 496 | * specified URI scheme. |
| 497 | */ |
| 498 | public boolean supportsUriScheme(String uriScheme) { |
| 499 | if (mSupportedUriSchemes == null || uriScheme == null) { |
| 500 | return false; |
| 501 | } |
| 502 | |
| 503 | for (String scheme : mSupportedUriSchemes) { |
| 504 | if (scheme != null && scheme.equals(uriScheme)) { |
| 505 | return true; |
| 506 | } |
| 507 | } |
| 508 | return false; |
| 509 | } |
| 510 | |
| 511 | /** |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 512 | * The icon resource ID for the icon of this {@code PhoneAccount}. |
| 513 | * <p> |
| 514 | * Creators of a {@code PhoneAccount} who possess the icon in static resources should prefer |
| 515 | * this method of indicating the icon rather than using {@link #getIconBitmap()}, since it |
| 516 | * leads to less resource usage. |
| 517 | * <p> |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 518 | * Clients wishing to display a {@code PhoneAccount} should use {@link #createIconDrawable(Context)}. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 519 | * |
| 520 | * @return A resource ID. |
| 521 | */ |
| 522 | public int getIconResId() { |
| 523 | return mIconResId; |
| 524 | } |
| 525 | |
| 526 | /** |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 527 | * The package name from which to load the icon of this {@code PhoneAccount}. |
| 528 | * <p> |
| 529 | * If this property is {@code null}, the resource {@link #getIconResId()} will be loaded from |
| 530 | * the package in the {@link ComponentName} of the {@link #getAccountHandle()}. |
| 531 | * <p> |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 532 | * Clients wishing to display a {@code PhoneAccount} should use {@link #createIconDrawable(Context)}. |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 533 | * |
| 534 | * @return A package name. |
| 535 | */ |
| 536 | public String getIconPackageName() { |
| 537 | return mIconPackageName; |
| 538 | } |
| 539 | |
| 540 | /** |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 541 | * A tint to apply to the icon of this {@code PhoneAccount}. |
| Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 542 | * |
| 543 | * @return A hexadecimal color value. |
| 544 | */ |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 545 | public int getIconTint() { |
| 546 | return mIconTint; |
| Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | /** |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 550 | * A literal icon bitmap to represent this {@code PhoneAccount} in a user interface. |
| 551 | * <p> |
| 552 | * If this property is specified, it is to be considered the preferred icon. Otherwise, the |
| 553 | * resource specified by {@link #getIconResId()} should be used. |
| 554 | * <p> |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 555 | * Clients wishing to display a {@code PhoneAccount} should use |
| 556 | * {@link #createIconDrawable(Context)}. |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 557 | * |
| 558 | * @return A bitmap. |
| 559 | */ |
| 560 | public Bitmap getIconBitmap() { |
| 561 | return mIconBitmap; |
| 562 | } |
| 563 | |
| 564 | /** |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 565 | * A highlight color to use in displaying information about this {@code PhoneAccount}. |
| 566 | * |
| 567 | * @return A hexadecimal color value. |
| 568 | */ |
| 569 | public int getHighlightColor() { |
| 570 | return mHighlightColor; |
| 571 | } |
| 572 | |
| 573 | /** |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 574 | * Builds and returns an icon {@code Drawable} to represent this {@code PhoneAccount} in a user |
| 575 | * interface. Uses the properties {@link #getIconResId()}, {@link #getIconPackageName()}, and |
| 576 | * {@link #getIconBitmap()} as necessary. |
| 577 | * |
| 578 | * @param context A {@code Context} to use for loading {@code Drawable}s. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 579 | * |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 580 | * @return An icon for this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 581 | */ |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 582 | public Drawable createIconDrawable(Context context) { |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 583 | if (mIconBitmap != null) { |
| 584 | return new BitmapDrawable(context.getResources(), mIconBitmap); |
| Sailesh Nepal | 77780a4 | 2014-09-26 18:12:00 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 587 | if (mIconResId != 0) { |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 588 | try { |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 589 | Context packageContext = context.createPackageContext(mIconPackageName, 0); |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 590 | try { |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 591 | Drawable iconDrawable = packageContext.getDrawable(mIconResId); |
| 592 | if (mIconTint != NO_COLOR) { |
| 593 | iconDrawable.setTint(mIconTint); |
| 594 | } |
| 595 | return iconDrawable; |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 596 | } catch (NotFoundException | MissingResourceException e) { |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 597 | Log.e(this, e, "Cannot find icon %d in package %s", |
| 598 | mIconResId, mIconPackageName); |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 599 | } |
| 600 | } catch (PackageManager.NameNotFoundException e) { |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 601 | Log.w(this, "Cannot find package %s", mIconPackageName); |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 602 | } |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 603 | } |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 604 | |
| 605 | return new ColorDrawable(Color.TRANSPARENT); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | // |
| 609 | // Parcelable implementation |
| 610 | // |
| 611 | |
| 612 | @Override |
| 613 | public int describeContents() { |
| 614 | return 0; |
| 615 | } |
| 616 | |
| 617 | @Override |
| 618 | public void writeToParcel(Parcel out, int flags) { |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 619 | if (mAccountHandle == null) { |
| 620 | out.writeInt(0); |
| 621 | } else { |
| 622 | out.writeInt(1); |
| 623 | mAccountHandle.writeToParcel(out, flags); |
| 624 | } |
| 625 | if (mAddress == null) { |
| 626 | out.writeInt(0); |
| 627 | } else { |
| 628 | out.writeInt(1); |
| 629 | mAddress.writeToParcel(out, flags); |
| 630 | } |
| 631 | if (mSubscriptionAddress == null) { |
| 632 | out.writeInt(0); |
| 633 | } else { |
| 634 | out.writeInt(1); |
| 635 | mSubscriptionAddress.writeToParcel(out, flags); |
| 636 | } |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 637 | out.writeInt(mCapabilities); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 638 | out.writeInt(mIconResId); |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 639 | out.writeString(mIconPackageName); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 640 | if (mIconBitmap == null) { |
| 641 | out.writeInt(0); |
| 642 | } else { |
| 643 | mIconBitmap.writeToParcel(out, flags); |
| 644 | } |
| 645 | out.writeInt(mIconTint); |
| 646 | out.writeInt(mHighlightColor); |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 647 | out.writeCharSequence(mLabel); |
| 648 | out.writeCharSequence(mShortDescription); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 649 | out.writeStringList(mSupportedUriSchemes); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 650 | } |
| 651 | |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 652 | public static final Creator<PhoneAccount> CREATOR |
| 653 | = new Creator<PhoneAccount>() { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 654 | @Override |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 655 | public PhoneAccount createFromParcel(Parcel in) { |
| 656 | return new PhoneAccount(in); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | @Override |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 660 | public PhoneAccount[] newArray(int size) { |
| 661 | return new PhoneAccount[size]; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 662 | } |
| 663 | }; |
| 664 | |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 665 | private PhoneAccount(Parcel in) { |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 666 | if (in.readInt() > 0) { |
| 667 | mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in); |
| 668 | } else { |
| 669 | mAccountHandle = null; |
| 670 | } |
| 671 | if (in.readInt() > 0) { |
| 672 | mAddress = Uri.CREATOR.createFromParcel(in); |
| 673 | } else { |
| 674 | mAddress = null; |
| 675 | } |
| 676 | if (in.readInt() > 0) { |
| 677 | mSubscriptionAddress = Uri.CREATOR.createFromParcel(in); |
| 678 | } else { |
| 679 | mSubscriptionAddress = null; |
| 680 | } |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 681 | mCapabilities = in.readInt(); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 682 | mIconResId = in.readInt(); |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 683 | mIconPackageName = in.readString(); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 684 | if (in.readInt() > 0) { |
| 685 | mIconBitmap = Bitmap.CREATOR.createFromParcel(in); |
| 686 | } else { |
| 687 | mIconBitmap = null; |
| 688 | } |
| 689 | mIconTint = in.readInt(); |
| 690 | mHighlightColor = in.readInt(); |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 691 | mLabel = in.readCharSequence(); |
| 692 | mShortDescription = in.readCharSequence(); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame^] | 693 | mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList()); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 694 | } |
| Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 695 | |
| 696 | @Override |
| 697 | public String toString() { |
| 698 | StringBuilder sb = new StringBuilder().append("[PhoneAccount: ") |
| 699 | .append(mAccountHandle) |
| 700 | .append(" Capabilities: ") |
| 701 | .append(mCapabilities) |
| 702 | .append(" Schemes: "); |
| 703 | for (String scheme : mSupportedUriSchemes) { |
| 704 | sb.append(scheme) |
| 705 | .append(" "); |
| 706 | } |
| 707 | sb.append("]"); |
| 708 | return sb.toString(); |
| 709 | } |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 710 | } |