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 | |
Tyler Gunn | 711d876fd | 2014-09-19 11:17:02 -0700 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.content.pm.PackageManager; |
Santos Cordon | e8dc4be | 2014-07-21 01:28:28 -0700 | [diff] [blame] | 22 | import android.content.res.Resources.NotFoundException; |
Divya Sharma | 1cb8f69 | 2015-02-24 16:25:55 -0800 | [diff] [blame] | 23 | import android.graphics.Bitmap; |
| 24 | import android.graphics.Color; |
| 25 | import android.graphics.drawable.BitmapDrawable; |
| 26 | import android.graphics.drawable.ColorDrawable; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 27 | import android.graphics.drawable.Drawable; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 28 | import android.net.Uri; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 29 | import android.os.Parcel; |
| 30 | import android.os.Parcelable; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 31 | import android.text.TextUtils; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 32 | |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 33 | import java.lang.String; |
| 34 | import java.util.ArrayList; |
Sandeep Kunta | 0f8bfc5 | 2014-09-01 17:21:05 +0530 | [diff] [blame] | 35 | import java.util.BitSet; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 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 | /** |
Evan Charlton | f6a3fef | 2014-11-08 15:49:16 -0800 | [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. |
Tyler Gunn | 711d876fd | 2014-09-19 11:17:02 -0700 | [diff] [blame] | 49 | * @hide |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 50 | */ |
Tyler Gunn | 711d876fd | 2014-09-19 11:17:02 -0700 | [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 |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 73 | * calls from or use the built-in telephony stack to place its calls. |
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 | 7522bbd | 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 | 7522bbd | 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 | 7522bbd | 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 | /** |
Evan Charlton | c62310e | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 108 | * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This |
| 109 | * should only be used by system apps (and will be ignored for all other apps trying to use it). |
| 110 | * <p> |
| 111 | * See {@link #getCapabilities} |
| 112 | * @hide |
| 113 | */ |
| 114 | public static final int CAPABILITY_MULTI_USER = 0x20; |
| 115 | |
| 116 | /** |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 117 | * URI scheme for telephone number URIs. |
| 118 | */ |
| 119 | public static final String SCHEME_TEL = "tel"; |
| 120 | |
| 121 | /** |
| 122 | * URI scheme for voicemail URIs. |
| 123 | */ |
| 124 | public static final String SCHEME_VOICEMAIL = "voicemail"; |
| 125 | |
| 126 | /** |
| 127 | * URI scheme for SIP URIs. |
| 128 | */ |
| 129 | public static final String SCHEME_SIP = "sip"; |
| 130 | |
Natiq Ahmed | c67d48d | 2014-09-16 21:34:44 +0530 | [diff] [blame] | 131 | /** |
| 132 | * {@hide} |
| 133 | */ |
| 134 | public static final String SCHEME_SMSTO = "smsto"; |
| 135 | |
Nancy Chen | 54563bc | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 136 | /** |
| 137 | * Indicating no color is set. |
Divya Sharma | 1cb8f69 | 2015-02-24 16:25:55 -0800 | [diff] [blame] | 138 | * @hide |
Nancy Chen | 54563bc | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 139 | */ |
| 140 | public static final int NO_COLOR = -1; |
| 141 | |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 142 | /** |
Ihab Awad | 4a0d272 | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 143 | * Indicating no icon tint is set. |
| 144 | */ |
| 145 | public static final int NO_ICON_TINT = 0; |
| 146 | |
| 147 | /** |
| 148 | * Indicating no hightlight color is set. |
| 149 | */ |
| 150 | public static final int NO_HIGHLIGHT_COLOR = 0; |
| 151 | |
| 152 | /** |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 153 | * Indicating no resource ID is set. |
| 154 | */ |
| 155 | public static final int NO_RESOURCE_ID = -1; |
| 156 | |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 157 | private final PhoneAccountHandle mAccountHandle; |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 158 | private final Uri mAddress; |
| 159 | private final Uri mSubscriptionAddress; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 160 | private final int mCapabilities; |
| 161 | private final int mIconResId; |
Divya Sharma | 1cb8f69 | 2015-02-24 16:25:55 -0800 | [diff] [blame] | 162 | private final String mIconPackageName; |
| 163 | private final Bitmap mIconBitmap; |
Nancy Chen | 54563bc | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 164 | private final int mColor; |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 165 | private final int mIconTint; |
| 166 | private final int mHighlightColor; |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 167 | private final CharSequence mLabel; |
| 168 | private final CharSequence mShortDescription; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 169 | private final List<String> mSupportedUriSchemes; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 170 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 171 | public static class Builder { |
| 172 | private PhoneAccountHandle mAccountHandle; |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 173 | private Uri mAddress; |
| 174 | private Uri mSubscriptionAddress; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 175 | private int mCapabilities; |
| 176 | private int mIconResId; |
Divya Sharma | 1cb8f69 | 2015-02-24 16:25:55 -0800 | [diff] [blame] | 177 | private String mIconPackageName; |
| 178 | private Bitmap mIconBitmap; |
Nancy Chen | 54563bc | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 179 | private int mColor = NO_COLOR; |
Ihab Awad | 4a0d272 | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 180 | private int mIconTint = NO_ICON_TINT; |
| 181 | private int mHighlightColor = NO_HIGHLIGHT_COLOR; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 182 | private CharSequence mLabel; |
| 183 | private CharSequence mShortDescription; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 184 | private List<String> mSupportedUriSchemes = new ArrayList<String>(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 185 | |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 186 | public Builder(PhoneAccountHandle accountHandle, CharSequence label) { |
| 187 | this.mAccountHandle = accountHandle; |
| 188 | this.mLabel = label; |
| 189 | } |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 190 | |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 191 | /** |
| 192 | * Creates an instance of the {@link PhoneAccount.Builder} from an existing |
| 193 | * {@link PhoneAccount}. |
| 194 | * |
| 195 | * @param phoneAccount The {@link PhoneAccount} used to initialize the builder. |
| 196 | */ |
| 197 | public Builder(PhoneAccount phoneAccount) { |
| 198 | mAccountHandle = phoneAccount.getAccountHandle(); |
| 199 | mAddress = phoneAccount.getAddress(); |
| 200 | mSubscriptionAddress = phoneAccount.getSubscriptionAddress(); |
| 201 | mCapabilities = phoneAccount.getCapabilities(); |
| 202 | mIconResId = phoneAccount.getIconResId(); |
Nancy Chen | 54563bc | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 203 | mColor = phoneAccount.getColor(); |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 204 | mIconTint = phoneAccount.getIconTint(); |
| 205 | mHighlightColor = phoneAccount.getHighlightColor(); |
Divya Sharma | 1cb8f69 | 2015-02-24 16:25:55 -0800 | [diff] [blame] | 206 | mIconPackageName = phoneAccount.getIconPackageName(); |
| 207 | mIconBitmap = phoneAccount.getIconBitmap(); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 208 | mLabel = phoneAccount.getLabel(); |
| 209 | mShortDescription = phoneAccount.getShortDescription(); |
| 210 | mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes()); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Evan Charlton | c62310e | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 213 | /** @hide */ |
| 214 | public Builder setAccountHandle(PhoneAccountHandle accountHandle) { |
| 215 | mAccountHandle = accountHandle; |
| 216 | return this; |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Sets the address. See {@link PhoneAccount#getAddress}. |
| 221 | * |
| 222 | * @param value The address of the phone account. |
| 223 | * @return The builder. |
| 224 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 225 | public Builder setAddress(Uri value) { |
| 226 | this.mAddress = value; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 227 | return this; |
| 228 | } |
| 229 | |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 230 | public Builder setSubscriptionAddress(Uri value) { |
| 231 | this.mSubscriptionAddress = value; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 232 | return this; |
| 233 | } |
| 234 | |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 235 | public Builder setCapabilities(int value) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 236 | this.mCapabilities = value; |
| 237 | return this; |
| 238 | } |
| 239 | |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 240 | /** |
| 241 | * Sets the icon. See {@link PhoneAccount#createIconDrawable}. |
| 242 | * |
| 243 | * @param packageContext The package from which to load an icon. |
| 244 | * @param iconResId The resource in {@code iconPackageName} representing the icon. |
| 245 | * @return The builder. |
| 246 | */ |
| 247 | public Builder setIcon(Context packageContext, int iconResId) { |
| 248 | return setIcon(packageContext.getPackageName(), iconResId); |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Sets the icon. See {@link PhoneAccount#createIconDrawable}. |
| 253 | * |
| 254 | * @param iconPackageName The package from which to load an icon. |
| 255 | * @param iconResId The resource in {@code iconPackageName} representing the icon. |
| 256 | * @return The builder. |
| 257 | */ |
| 258 | public Builder setIcon(String iconPackageName, int iconResId) { |
Ihab Awad | 4a0d272 | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 259 | return setIcon(iconPackageName, iconResId, NO_ICON_TINT); |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Sets the icon. See {@link PhoneAccount#createIconDrawable}. |
| 264 | * |
| 265 | * @param packageContext The package from which to load an icon. |
| 266 | * @param iconResId The resource in {@code iconPackageName} representing the icon. |
| 267 | * @param iconTint A color with which to tint this icon. |
| 268 | * @return The builder. |
| 269 | */ |
| 270 | public Builder setIcon(Context packageContext, int iconResId, int iconTint) { |
| 271 | return setIcon(packageContext.getPackageName(), iconResId, iconTint); |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * Sets the icon. See {@link PhoneAccount#createIconDrawable}. |
| 276 | * |
| 277 | * @param iconPackageName The package from which to load an icon. |
| 278 | * @param iconResId The resource in {@code iconPackageName} representing the icon. |
| 279 | * @param iconTint A color with which to tint this icon. |
| 280 | * @return The builder. |
| 281 | */ |
| 282 | public Builder setIcon(String iconPackageName, int iconResId, int iconTint) { |
| 283 | this.mIconPackageName = iconPackageName; |
| 284 | this.mIconResId = iconResId; |
| 285 | this.mIconTint = iconTint; |
| 286 | return this; |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * Sets the icon. See {@link PhoneAccount#createIconDrawable}. |
| 291 | * |
| 292 | * @param iconBitmap The icon bitmap. |
| 293 | * @return The builder. |
| 294 | */ |
| 295 | public Builder setIcon(Bitmap iconBitmap) { |
| 296 | this.mIconBitmap = iconBitmap; |
| 297 | this.mIconPackageName = null; |
| 298 | this.mIconResId = NO_RESOURCE_ID; |
Ihab Awad | 4a0d272 | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 299 | this.mIconTint = NO_ICON_TINT; |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 300 | return this; |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}. |
| 305 | * |
| 306 | * @param value The highlight color. |
| 307 | * @return The builder. |
| 308 | */ |
| 309 | public Builder setHighlightColor(int value) { |
| 310 | this.mHighlightColor = value; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 311 | return this; |
| 312 | } |
| 313 | |
Divya Sharma | 1cb8f69 | 2015-02-24 16:25:55 -0800 | [diff] [blame] | 314 | /** @hide */ |
Nancy Chen | 54563bc | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 315 | public Builder setColor(int value) { |
| 316 | this.mColor = value; |
| 317 | return this; |
| 318 | } |
| 319 | |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 320 | /** |
Divya Sharma | 1cb8f69 | 2015-02-24 16:25:55 -0800 | [diff] [blame] | 321 | * Sets the icon package name. See {@link PhoneAccount#getIconPackageName}. |
| 322 | * |
| 323 | * @param value The name of the package from which to load the icon. |
| 324 | * @return The builder. |
| 325 | * @hide |
| 326 | */ |
| 327 | public Builder setIconPackageName(String value) { |
| 328 | this.mIconPackageName = value; |
| 329 | return this; |
| 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Sets the icon bitmap. See {@link PhoneAccount#getIconBitmap}. |
| 334 | * |
| 335 | * @param value The icon bitmap. |
| 336 | * @return The builder. |
| 337 | * @hide |
| 338 | */ |
| 339 | public Builder setIconBitmap(Bitmap value) { |
| 340 | this.mIconBitmap = value; |
| 341 | return this; |
| 342 | } |
| 343 | |
| 344 | /** |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 345 | * Sets the short description. See {@link PhoneAccount#getShortDescription}. |
| 346 | * |
| 347 | * @param value The short description. |
| 348 | * @return The builder. |
| 349 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 350 | public Builder setShortDescription(CharSequence value) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 351 | this.mShortDescription = value; |
| 352 | return this; |
| 353 | } |
| 354 | |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 355 | /** |
| 356 | * Specifies an additional URI scheme supported by the {@link PhoneAccount}. |
| 357 | * |
| 358 | * @param uriScheme The URI scheme. |
| 359 | * @return The Builder. |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 360 | * @hide |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 361 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 362 | public Builder addSupportedUriScheme(String uriScheme) { |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 363 | if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) { |
| 364 | this.mSupportedUriSchemes.add(uriScheme); |
| 365 | } |
| 366 | return this; |
| 367 | } |
| 368 | |
| 369 | /** |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 370 | * Specifies the URI schemes supported by the {@link PhoneAccount}. |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 371 | * |
| 372 | * @param uriSchemes The URI schemes. |
| 373 | * @return The Builder. |
| 374 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 375 | public Builder setSupportedUriSchemes(List<String> uriSchemes) { |
| 376 | mSupportedUriSchemes.clear(); |
| 377 | |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 378 | if (uriSchemes != null && !uriSchemes.isEmpty()) { |
| 379 | for (String uriScheme : uriSchemes) { |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 380 | addSupportedUriScheme(uriScheme); |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | return this; |
| 384 | } |
| 385 | |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 386 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 387 | * Creates an instance of a {@link PhoneAccount} based on the current builder settings. |
| 388 | * |
| 389 | * @return The {@link PhoneAccount}. |
| 390 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 391 | public PhoneAccount build() { |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 392 | // If no supported URI schemes were defined, assume "tel" is supported. |
| 393 | if (mSupportedUriSchemes.isEmpty()) { |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 394 | addSupportedUriScheme(SCHEME_TEL); |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 397 | return new PhoneAccount( |
| 398 | mAccountHandle, |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 399 | mAddress, |
| 400 | mSubscriptionAddress, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 401 | mCapabilities, |
| 402 | mIconResId, |
Nancy Chen | 54563bc | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 403 | mColor, |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 404 | mIconTint, |
| 405 | mHighlightColor, |
Divya Sharma | 1cb8f69 | 2015-02-24 16:25:55 -0800 | [diff] [blame] | 406 | mIconPackageName, |
| 407 | mIconBitmap, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 408 | mLabel, |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 409 | mShortDescription, |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame] | 410 | mSupportedUriSchemes); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | |
| 414 | private PhoneAccount( |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 415 | PhoneAccountHandle account, |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 416 | Uri address, |
| 417 | Uri subscriptionAddress, |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 418 | int capabilities, |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 419 | int iconResId, |
Nancy Chen | 54563bc | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 420 | int color, |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 421 | int iconTint, |
| 422 | int highlightColor, |
Divya Sharma | 1cb8f69 | 2015-02-24 16:25:55 -0800 | [diff] [blame] | 423 | String iconPackageName, |
| 424 | Bitmap iconBitmap, |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 425 | CharSequence label, |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 426 | CharSequence shortDescription, |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame] | 427 | List<String> supportedUriSchemes) { |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 428 | mAccountHandle = account; |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 429 | mAddress = address; |
| 430 | mSubscriptionAddress = subscriptionAddress; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 431 | mCapabilities = capabilities; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 432 | mIconResId = iconResId; |
Nancy Chen | 54563bc | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 433 | mColor = color; |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 434 | mIconTint = iconTint; |
| 435 | mHighlightColor = highlightColor; |
Divya Sharma | 1cb8f69 | 2015-02-24 16:25:55 -0800 | [diff] [blame] | 436 | mIconPackageName = iconPackageName; |
| 437 | mIconBitmap = iconBitmap; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 438 | mLabel = label; |
| 439 | mShortDescription = shortDescription; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 440 | mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 443 | public static Builder builder( |
| 444 | PhoneAccountHandle accountHandle, |
| 445 | CharSequence label) { |
| 446 | return new Builder(accountHandle, label); |
| 447 | } |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 448 | |
Sandeep Kunta | 0f8bfc5 | 2014-09-01 17:21:05 +0530 | [diff] [blame] | 449 | private BitSet dsda = new BitSet(); |
| 450 | |
| 451 | /** |
| 452 | * {@hide} |
| 453 | */ |
| 454 | public static final int LCH = 1; |
| 455 | |
| 456 | /** |
| 457 | * {@hide} |
| 458 | */ |
| 459 | public static final int ACTIVE = 2; |
| 460 | |
| 461 | /** |
| 462 | * {@hide} |
| 463 | */ |
| 464 | public static final int LCHMUTE = 3; |
| 465 | |
| 466 | /** |
| 467 | * {@hide} |
| 468 | */ |
| 469 | public void setBit(int bit) { |
| 470 | dsda.set(bit); |
| 471 | } |
| 472 | |
| 473 | /** |
| 474 | * {@hide} |
| 475 | */ |
| 476 | public void unSetBit(int bit) { |
| 477 | dsda.set(bit, false); |
| 478 | } |
| 479 | |
| 480 | /** |
| 481 | * {@hide} |
| 482 | */ |
| 483 | public boolean isSet(int bit) { |
| 484 | return dsda.get(bit); |
| 485 | } |
| 486 | |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 487 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 488 | * Returns a builder initialized with the current {@link PhoneAccount} instance. |
| 489 | * |
| 490 | * @return The builder. |
| 491 | * @hide |
| 492 | */ |
| 493 | public Builder toBuilder() { return new Builder(this); } |
| 494 | |
| 495 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 496 | * The unique identifier of this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 497 | * |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 498 | * @return A {@code PhoneAccountHandle}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 499 | */ |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 500 | public PhoneAccountHandle getAccountHandle() { |
| 501 | return mAccountHandle; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | /** |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 505 | * 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] | 506 | * represents the destination from which outgoing calls using this {@code PhoneAccount} |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 507 | * 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] | 508 | * {@code PhoneAccount} may be addressed. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 509 | * |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 510 | * @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] | 511 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 512 | public Uri getAddress() { |
| 513 | return mAddress; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 517 | * The raw callback number used for this {@code PhoneAccount}, as distinct from |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 518 | * {@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] | 519 | * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration |
Junda Liu | dd0a320 | 2014-09-25 17:36:48 +0000 | [diff] [blame] | 520 | * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)} |
| 521 | * has been used to alter the callback number. |
| 522 | * <p> |
Evan Charlton | 222db52 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 523 | * |
| 524 | * @return The subscription number, suitable for display to the user. |
| 525 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 526 | public Uri getSubscriptionAddress() { |
| 527 | return mSubscriptionAddress; |
Evan Charlton | 222db52 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 531 | * The capabilities of this {@code PhoneAccount}. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 532 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 533 | * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 534 | */ |
| 535 | public int getCapabilities() { |
| 536 | return mCapabilities; |
| 537 | } |
| 538 | |
| 539 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 540 | * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in |
| 541 | * bit mask. |
| 542 | * |
| 543 | * @param capability The capabilities to check. |
| 544 | * @return {@code True} if the phone account has the capability. |
| 545 | */ |
| 546 | public boolean hasCapabilities(int capability) { |
| 547 | return (mCapabilities & capability) == capability; |
| 548 | } |
| 549 | |
| 550 | /** |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 551 | * A short label describing a {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 552 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 553 | * @return A label for this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 554 | */ |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 555 | public CharSequence getLabel() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 556 | return mLabel; |
| 557 | } |
| 558 | |
| 559 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 560 | * A short paragraph describing this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 561 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 562 | * @return A description for this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 563 | */ |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 564 | public CharSequence getShortDescription() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 565 | return mShortDescription; |
| 566 | } |
| 567 | |
| 568 | /** |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 569 | * The URI schemes supported by this {@code PhoneAccount}. |
| 570 | * |
| 571 | * @return The URI schemes. |
| 572 | */ |
| 573 | public List<String> getSupportedUriSchemes() { |
| 574 | return mSupportedUriSchemes; |
| 575 | } |
| 576 | |
| 577 | /** |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 578 | * 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] | 579 | * scheme. |
| 580 | * |
| 581 | * @param uriScheme The URI scheme to check. |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 582 | * @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] | 583 | * specified URI scheme. |
| 584 | */ |
| 585 | public boolean supportsUriScheme(String uriScheme) { |
| 586 | if (mSupportedUriSchemes == null || uriScheme == null) { |
| 587 | return false; |
| 588 | } |
| 589 | |
| 590 | for (String scheme : mSupportedUriSchemes) { |
| 591 | if (scheme != null && scheme.equals(uriScheme)) { |
| 592 | return true; |
| 593 | } |
| 594 | } |
| 595 | return false; |
| 596 | } |
| 597 | |
| 598 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 599 | * The icon resource ID for the icon of this {@code PhoneAccount}. |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 600 | * Clients wishing to display a {@code PhoneAccount} should use {@link #createIconDrawable(Context)}. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 601 | * |
| 602 | * @return A resource ID. |
| 603 | */ |
| 604 | public int getIconResId() { |
| 605 | return mIconResId; |
| 606 | } |
| 607 | |
| 608 | /** |
Nancy Chen | 54563bc | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 609 | * A highlight color to use in displaying information about this {@code PhoneAccount}. |
| 610 | * |
| 611 | * @return A hexadecimal color value. |
Divya Sharma | 1cb8f69 | 2015-02-24 16:25:55 -0800 | [diff] [blame] | 612 | * @hide |
Nancy Chen | 54563bc | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 613 | */ |
| 614 | public int getColor() { |
| 615 | return mColor; |
| 616 | } |
| 617 | |
| 618 | /** |
Divya Sharma | 1cb8f69 | 2015-02-24 16:25:55 -0800 | [diff] [blame] | 619 | * The package name from which to load the icon of this {@code PhoneAccount}. |
| 620 | * <p> |
| 621 | * If this property is {@code null}, the resource {@link #getIconResId()} will be loaded from |
| 622 | * the package in the {@link ComponentName} of the {@link #getAccountHandle()}. |
| 623 | * <p> |
| 624 | * Clients wishing to display a {@code PhoneAccount} should use {@link #getIcon(Context)}. |
| 625 | * |
| 626 | * @return A package name. |
| 627 | */ |
| 628 | public String getIconPackageName() { |
| 629 | return mIconPackageName; |
| 630 | } |
| 631 | |
| 632 | /** |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 633 | * A tint to apply to the icon of this {@code PhoneAccount}. |
| 634 | * |
| 635 | * @return A hexadecimal color value. |
| 636 | */ |
| 637 | public int getIconTint() { |
| 638 | return mIconTint; |
| 639 | } |
| 640 | |
| 641 | /** |
| 642 | * A literal icon bitmap to represent this {@code PhoneAccount} in a user interface. |
| 643 | * <p> |
| 644 | * If this property is specified, it is to be considered the preferred icon. Otherwise, the |
| 645 | * resource specified by {@link #getIconResId()} should be used. |
| 646 | * <p> |
| 647 | * Clients wishing to display a {@code PhoneAccount} should use |
| 648 | * {@link #createIconDrawable(Context)}. |
| 649 | * |
| 650 | * @return A bitmap. |
| 651 | */ |
| 652 | public Bitmap getIconBitmap() { |
| 653 | return mIconBitmap; |
| 654 | } |
| 655 | |
| 656 | /** |
| 657 | * A highlight color to use in displaying information about this {@code PhoneAccount}. |
| 658 | * |
| 659 | * @return A hexadecimal color value. |
| 660 | */ |
| 661 | public int getHighlightColor() { |
| 662 | return mHighlightColor; |
| 663 | } |
| 664 | |
| 665 | /** |
| 666 | * Builds and returns an icon {@code Drawable} to represent this {@code PhoneAccount} in a user |
| 667 | * interface. Uses the properties {@link #getIconResId()}, {@link #getIconPackageName()}, and |
| 668 | * {@link #getIconBitmap()} as necessary. |
| 669 | * |
| 670 | * @param context A {@code Context} to use for loading {@code Drawable}s. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 671 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 672 | * @return An icon for this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 673 | */ |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 674 | public Drawable createIconDrawable(Context context) { |
| 675 | if (mIconBitmap != null) { |
| 676 | return new BitmapDrawable(context.getResources(), mIconBitmap); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 677 | } |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 678 | |
| 679 | if (mIconResId != 0) { |
| 680 | try { |
| 681 | Context packageContext = context.createPackageContext(mIconPackageName, 0); |
| 682 | try { |
| 683 | Drawable iconDrawable = packageContext.getDrawable(mIconResId); |
Ihab Awad | 4a0d272 | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 684 | if (mIconTint != NO_ICON_TINT) { |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 685 | iconDrawable.setTint(mIconTint); |
| 686 | } |
| 687 | return iconDrawable; |
| 688 | } catch (NotFoundException | MissingResourceException e) { |
| 689 | Log.e(this, e, "Cannot find icon %d in package %s", |
| 690 | mIconResId, mIconPackageName); |
| 691 | } |
| 692 | } catch (PackageManager.NameNotFoundException e) { |
| 693 | Log.w(this, "Cannot find package %s", mIconPackageName); |
| 694 | } |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 695 | } |
Divya Sharma | 1cb8f69 | 2015-02-24 16:25:55 -0800 | [diff] [blame] | 696 | return new ColorDrawable(Color.TRANSPARENT); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | // |
| 700 | // Parcelable implementation |
| 701 | // |
| 702 | |
| 703 | @Override |
| 704 | public int describeContents() { |
| 705 | return 0; |
| 706 | } |
| 707 | |
| 708 | @Override |
| 709 | public void writeToParcel(Parcel out, int flags) { |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 710 | if (mAccountHandle == null) { |
| 711 | out.writeInt(0); |
| 712 | } else { |
| 713 | out.writeInt(1); |
| 714 | mAccountHandle.writeToParcel(out, flags); |
| 715 | } |
| 716 | if (mAddress == null) { |
| 717 | out.writeInt(0); |
| 718 | } else { |
| 719 | out.writeInt(1); |
| 720 | mAddress.writeToParcel(out, flags); |
| 721 | } |
| 722 | if (mSubscriptionAddress == null) { |
| 723 | out.writeInt(0); |
| 724 | } else { |
| 725 | out.writeInt(1); |
| 726 | mSubscriptionAddress.writeToParcel(out, flags); |
| 727 | } |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 728 | out.writeInt(mCapabilities); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 729 | out.writeInt(mIconResId); |
Nancy Chen | 54563bc | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 730 | out.writeInt(mColor); |
Divya Sharma | fdb095d | 2015-02-27 20:14:33 -0800 | [diff] [blame] | 731 | out.writeString(mIconPackageName); |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 732 | if (mIconBitmap == null) { |
| 733 | out.writeInt(0); |
| 734 | } else { |
Ihab Awad | 77a7903 | 2014-11-11 18:41:39 -0800 | [diff] [blame] | 735 | out.writeInt(1); |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 736 | mIconBitmap.writeToParcel(out, flags); |
| 737 | } |
| 738 | out.writeInt(mIconTint); |
| 739 | out.writeInt(mHighlightColor); |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 740 | out.writeCharSequence(mLabel); |
| 741 | out.writeCharSequence(mShortDescription); |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 742 | out.writeStringList(mSupportedUriSchemes); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 743 | } |
| 744 | |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 745 | public static final Creator<PhoneAccount> CREATOR |
| 746 | = new Creator<PhoneAccount>() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 747 | @Override |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 748 | public PhoneAccount createFromParcel(Parcel in) { |
| 749 | return new PhoneAccount(in); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | @Override |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 753 | public PhoneAccount[] newArray(int size) { |
| 754 | return new PhoneAccount[size]; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 755 | } |
| 756 | }; |
| 757 | |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 758 | private PhoneAccount(Parcel in) { |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 759 | if (in.readInt() > 0) { |
| 760 | mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in); |
| 761 | } else { |
| 762 | mAccountHandle = null; |
| 763 | } |
| 764 | if (in.readInt() > 0) { |
| 765 | mAddress = Uri.CREATOR.createFromParcel(in); |
| 766 | } else { |
| 767 | mAddress = null; |
| 768 | } |
| 769 | if (in.readInt() > 0) { |
| 770 | mSubscriptionAddress = Uri.CREATOR.createFromParcel(in); |
| 771 | } else { |
| 772 | mSubscriptionAddress = null; |
| 773 | } |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 774 | mCapabilities = in.readInt(); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 775 | mIconResId = in.readInt(); |
Nancy Chen | 54563bc | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 776 | mColor = in.readInt(); |
Divya Sharma | 1cb8f69 | 2015-02-24 16:25:55 -0800 | [diff] [blame] | 777 | mIconPackageName = in.readString(); |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 778 | if (in.readInt() > 0) { |
| 779 | mIconBitmap = Bitmap.CREATOR.createFromParcel(in); |
| 780 | } else { |
| 781 | mIconBitmap = null; |
| 782 | } |
| 783 | mIconTint = in.readInt(); |
| 784 | mHighlightColor = in.readInt(); |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 785 | mLabel = in.readCharSequence(); |
| 786 | mShortDescription = in.readCharSequence(); |
Ihab Awad | c7af434 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 787 | mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList()); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 788 | } |
Tyler Gunn | edc1efb | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 789 | |
| 790 | @Override |
| 791 | public String toString() { |
| 792 | StringBuilder sb = new StringBuilder().append("[PhoneAccount: ") |
| 793 | .append(mAccountHandle) |
| 794 | .append(" Capabilities: ") |
| 795 | .append(mCapabilities) |
| 796 | .append(" Schemes: "); |
| 797 | for (String scheme : mSupportedUriSchemes) { |
| 798 | sb.append(scheme) |
| 799 | .append(" "); |
| 800 | } |
| 801 | sb.append("]"); |
| 802 | return sb.toString(); |
| 803 | } |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 804 | } |