| 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; |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 29 | import android.graphics.drawable.Icon; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 30 | import android.net.Uri; |
| Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 31 | import android.os.Bundle; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 32 | import android.os.Parcel; |
| 33 | import android.os.Parcelable; |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 34 | import android.text.TextUtils; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 35 | |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 36 | import java.lang.String; |
| 37 | import java.util.ArrayList; |
| 38 | import java.util.Collections; |
| 39 | import java.util.List; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 40 | import java.util.MissingResourceException; |
| 41 | |
| 42 | /** |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 43 | * Represents a distinct method to place or receive a phone call. Apps which can place calls and |
| 44 | * want those calls to be integrated into the dialer and in-call UI should build an instance of |
| Brian Attwell | ad147f4 | 2014-12-19 11:37:16 -0800 | [diff] [blame] | 45 | * this class and register it with the system using {@link TelecomManager}. |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 46 | * <p> |
| 47 | * {@link TelecomManager} uses registered {@link PhoneAccount}s to present the user with |
| 48 | * alternative options when placing a phone call. When building a {@link PhoneAccount}, the app |
| Brian Attwell | ad147f4 | 2014-12-19 11:37:16 -0800 | [diff] [blame] | 49 | * should supply a valid {@link PhoneAccountHandle} that references the connection service |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 50 | * implementation Telecom will use to interact with the app. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 51 | */ |
| Yorke Lee | 400470f | 2015-05-12 13:31:25 -0700 | [diff] [blame] | 52 | public final class PhoneAccount implements Parcelable { |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 53 | |
| 54 | /** |
| Tyler Gunn | d426b20 | 2015-10-13 13:33:53 -0700 | [diff] [blame^] | 55 | * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the |
| 56 | * maximum permitted length of a call subject specified via the |
| 57 | * {@link TelecomManager#EXTRA_CALL_SUBJECT} extra on an |
| 58 | * {@link android.content.Intent#ACTION_CALL} intent. Ultimately a {@link ConnectionService} is |
| 59 | * responsible for enforcing the maximum call subject length when sending the message, however |
| 60 | * this extra is provided so that the user interface can proactively limit the length of the |
| 61 | * call subject as the user types it. |
| 62 | */ |
| 63 | public static final String EXTRA_CALL_SUBJECT_MAX_LENGTH = |
| 64 | "android.telecom.extra.CALL_SUBJECT_MAX_LENGTH"; |
| 65 | |
| 66 | /** |
| 67 | * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the |
| 68 | * character encoding to be used when determining the length of messages. |
| 69 | * The user interface can use this when determining the number of characters the user may type |
| 70 | * in a call subject. If empty-string, the call subject message size limit will be enforced on |
| 71 | * a 1:1 basis. That is, each character will count towards the messages size limit as a single |
| 72 | * character. If a character encoding is specified, the message size limit will be based on the |
| 73 | * number of bytes in the message per the specified encoding. See |
| 74 | * {@link #EXTRA_CALL_SUBJECT_MAX_LENGTH} for more information on the call subject maximum |
| 75 | * length. |
| 76 | */ |
| 77 | public static final String EXTRA_CALL_SUBJECT_CHARACTER_ENCODING = |
| 78 | "android.telecom.extra.CALL_SUBJECT_CHARACTER_ENCODING"; |
| 79 | |
| 80 | /** |
| Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 81 | * Flag indicating that this {@code PhoneAccount} can act as a connection manager for |
| 82 | * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount} |
| 83 | * will be allowed to manage phone calls including using its own proprietary phone-call |
| 84 | * implementation (like VoIP calling) to make calls instead of the telephony stack. |
| 85 | * <p> |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 86 | * When a user opts to place a call using the SIM-based telephony stack, the |
| 87 | * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first |
| 88 | * 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] | 89 | * <p> |
| 90 | * See {@link #getCapabilities} |
| 91 | */ |
| Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 92 | public static final int CAPABILITY_CONNECTION_MANAGER = 0x1; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 93 | |
| 94 | /** |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 95 | * 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] | 96 | * traditional SIM-based telephony calls. This account will be treated as a distinct method |
| 97 | * 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] | 98 | * 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] | 99 | * or place calls from the built-in telephony stack. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 100 | * <p> |
| 101 | * See {@link #getCapabilities} |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 102 | * <p> |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 103 | */ |
| 104 | public static final int CAPABILITY_CALL_PROVIDER = 0x2; |
| 105 | |
| Ihab Awad | 7522bbd6 | 2014-07-18 15:53:17 -0700 | [diff] [blame] | 106 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 107 | * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 108 | * subscription. |
| Ihab Awad | 7522bbd6 | 2014-07-18 15:53:17 -0700 | [diff] [blame] | 109 | * <p> |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 110 | * Only the Android framework can register a {@code PhoneAccount} having this capability. |
| 111 | * <p> |
| 112 | * See {@link #getCapabilities} |
| Ihab Awad | 7522bbd6 | 2014-07-18 15:53:17 -0700 | [diff] [blame] | 113 | */ |
| 114 | public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4; |
| 115 | |
| Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 116 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 117 | * Flag indicating that this {@code PhoneAccount} is capable of placing video calls. |
| 118 | * <p> |
| 119 | * See {@link #getCapabilities} |
| Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 120 | */ |
| 121 | public static final int CAPABILITY_VIDEO_CALLING = 0x8; |
| 122 | |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 123 | /** |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 124 | * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls. |
| 125 | * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls. |
| 126 | * <p> |
| 127 | * See {@link #getCapabilities} |
| 128 | */ |
| 129 | public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10; |
| 130 | |
| 131 | /** |
| Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 132 | * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This |
| 133 | * should only be used by system apps (and will be ignored for all other apps trying to use it). |
| 134 | * <p> |
| 135 | * See {@link #getCapabilities} |
| 136 | * @hide |
| 137 | */ |
| Brian Attwell | ad147f4 | 2014-12-19 11:37:16 -0800 | [diff] [blame] | 138 | @SystemApi |
| Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 139 | public static final int CAPABILITY_MULTI_USER = 0x20; |
| 140 | |
| 141 | /** |
| Tyler Gunn | 65a3d34 | 2015-07-27 16:06:16 -0700 | [diff] [blame] | 142 | * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a |
| 143 | * caller is able to specify a short subject line for an outgoing call. A capable receiving |
| 144 | * device displays the call subject on the incoming call screen. |
| 145 | * <p> |
| 146 | * See {@link #getCapabilities} |
| 147 | */ |
| 148 | public static final int CAPABILITY_CALL_SUBJECT = 0x40; |
| 149 | |
| 150 | /** |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 151 | * URI scheme for telephone number URIs. |
| 152 | */ |
| 153 | public static final String SCHEME_TEL = "tel"; |
| 154 | |
| 155 | /** |
| 156 | * URI scheme for voicemail URIs. |
| 157 | */ |
| 158 | public static final String SCHEME_VOICEMAIL = "voicemail"; |
| 159 | |
| 160 | /** |
| 161 | * URI scheme for SIP URIs. |
| 162 | */ |
| 163 | public static final String SCHEME_SIP = "sip"; |
| 164 | |
| Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 165 | /** |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 166 | * Indicating no icon tint is set. |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 167 | * @hide |
| Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 168 | */ |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 169 | public static final int NO_ICON_TINT = 0; |
| 170 | |
| 171 | /** |
| 172 | * Indicating no hightlight color is set. |
| 173 | */ |
| 174 | public static final int NO_HIGHLIGHT_COLOR = 0; |
| Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 175 | |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 176 | /** |
| 177 | * Indicating no resource ID is set. |
| 178 | */ |
| 179 | public static final int NO_RESOURCE_ID = -1; |
| 180 | |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 181 | private final PhoneAccountHandle mAccountHandle; |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 182 | private final Uri mAddress; |
| 183 | private final Uri mSubscriptionAddress; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 184 | private final int mCapabilities; |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 185 | private final int mHighlightColor; |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 186 | private final CharSequence mLabel; |
| 187 | private final CharSequence mShortDescription; |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 188 | private final List<String> mSupportedUriSchemes; |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 189 | private final Icon mIcon; |
| Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 190 | private final Bundle mExtras; |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 191 | private boolean mIsEnabled; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 192 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 193 | /** |
| 194 | * Helper class for creating a {@link PhoneAccount}. |
| 195 | */ |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 196 | public static class Builder { |
| 197 | private PhoneAccountHandle mAccountHandle; |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 198 | private Uri mAddress; |
| 199 | private Uri mSubscriptionAddress; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 200 | private int mCapabilities; |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 201 | private int mHighlightColor = NO_HIGHLIGHT_COLOR; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 202 | private CharSequence mLabel; |
| 203 | private CharSequence mShortDescription; |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 204 | private List<String> mSupportedUriSchemes = new ArrayList<String>(); |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 205 | private Icon mIcon; |
| Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 206 | private Bundle mExtras; |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 207 | private boolean mIsEnabled = false; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 208 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 209 | /** |
| 210 | * Creates a builder with the specified {@link PhoneAccountHandle} and label. |
| 211 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 212 | public Builder(PhoneAccountHandle accountHandle, CharSequence label) { |
| 213 | this.mAccountHandle = accountHandle; |
| 214 | this.mLabel = label; |
| 215 | } |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 216 | |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 217 | /** |
| 218 | * Creates an instance of the {@link PhoneAccount.Builder} from an existing |
| 219 | * {@link PhoneAccount}. |
| 220 | * |
| 221 | * @param phoneAccount The {@link PhoneAccount} used to initialize the builder. |
| 222 | */ |
| 223 | public Builder(PhoneAccount phoneAccount) { |
| 224 | mAccountHandle = phoneAccount.getAccountHandle(); |
| 225 | mAddress = phoneAccount.getAddress(); |
| 226 | mSubscriptionAddress = phoneAccount.getSubscriptionAddress(); |
| 227 | mCapabilities = phoneAccount.getCapabilities(); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 228 | mHighlightColor = phoneAccount.getHighlightColor(); |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 229 | mLabel = phoneAccount.getLabel(); |
| 230 | mShortDescription = phoneAccount.getShortDescription(); |
| 231 | mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes()); |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 232 | mIcon = phoneAccount.getIcon(); |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 233 | mIsEnabled = phoneAccount.isEnabled(); |
| Tyler Gunn | d426b20 | 2015-10-13 13:33:53 -0700 | [diff] [blame^] | 234 | mExtras = phoneAccount.getExtras(); |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 237 | /** |
| 238 | * Sets the address. See {@link PhoneAccount#getAddress}. |
| 239 | * |
| 240 | * @param value The address of the phone account. |
| 241 | * @return The builder. |
| 242 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 243 | public Builder setAddress(Uri value) { |
| 244 | this.mAddress = value; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 245 | return this; |
| 246 | } |
| 247 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 248 | /** |
| 249 | * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}. |
| 250 | * |
| 251 | * @param value The subscription address. |
| 252 | * @return The builder. |
| 253 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 254 | public Builder setSubscriptionAddress(Uri value) { |
| 255 | this.mSubscriptionAddress = value; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 256 | return this; |
| 257 | } |
| 258 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 259 | /** |
| 260 | * Sets the capabilities. See {@link PhoneAccount#getCapabilities}. |
| 261 | * |
| 262 | * @param value The capabilities to set. |
| 263 | * @return The builder. |
| 264 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 265 | public Builder setCapabilities(int value) { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 266 | this.mCapabilities = value; |
| 267 | return this; |
| 268 | } |
| 269 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 270 | /** |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 271 | * Sets the icon. See {@link PhoneAccount#getIcon}. |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 272 | * |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 273 | * @param icon The icon to set. |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 274 | */ |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 275 | public Builder setIcon(Icon icon) { |
| 276 | mIcon = icon; |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 277 | return this; |
| 278 | } |
| 279 | |
| 280 | /** |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 281 | * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}. |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 282 | * |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 283 | * @param value The highlight color. |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 284 | * @return The builder. |
| 285 | */ |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 286 | public Builder setHighlightColor(int value) { |
| 287 | this.mHighlightColor = value; |
| Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 288 | return this; |
| 289 | } |
| 290 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 291 | /** |
| 292 | * Sets the short description. See {@link PhoneAccount#getShortDescription}. |
| 293 | * |
| 294 | * @param value The short description. |
| 295 | * @return The builder. |
| 296 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 297 | public Builder setShortDescription(CharSequence value) { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 298 | this.mShortDescription = value; |
| 299 | return this; |
| 300 | } |
| 301 | |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 302 | /** |
| 303 | * Specifies an additional URI scheme supported by the {@link PhoneAccount}. |
| 304 | * |
| 305 | * @param uriScheme The URI scheme. |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 306 | * @return The builder. |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 307 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 308 | public Builder addSupportedUriScheme(String uriScheme) { |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 309 | if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) { |
| 310 | this.mSupportedUriSchemes.add(uriScheme); |
| 311 | } |
| 312 | return this; |
| 313 | } |
| 314 | |
| 315 | /** |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 316 | * Specifies the URI schemes supported by the {@link PhoneAccount}. |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 317 | * |
| 318 | * @param uriSchemes The URI schemes. |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 319 | * @return The builder. |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 320 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 321 | public Builder setSupportedUriSchemes(List<String> uriSchemes) { |
| 322 | mSupportedUriSchemes.clear(); |
| 323 | |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 324 | if (uriSchemes != null && !uriSchemes.isEmpty()) { |
| 325 | for (String uriScheme : uriSchemes) { |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 326 | addSupportedUriScheme(uriScheme); |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 327 | } |
| 328 | } |
| 329 | return this; |
| 330 | } |
| 331 | |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 332 | /** |
| Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 333 | * Specifies the extras associated with the {@link PhoneAccount}. |
| 334 | * <p> |
| 335 | * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer}, |
| 336 | * and {@link Boolean}. Extras which are not of these types are ignored. |
| 337 | * |
| 338 | * @param extras |
| 339 | * @return |
| 340 | */ |
| 341 | public Builder setExtras(Bundle extras) { |
| 342 | mExtras = extras; |
| 343 | return this; |
| 344 | } |
| 345 | |
| 346 | /** |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 347 | * Sets the enabled state of the phone account. |
| 348 | * |
| 349 | * @param isEnabled The enabled state. |
| 350 | * @return The builder. |
| 351 | * @hide |
| 352 | */ |
| 353 | public Builder setIsEnabled(boolean isEnabled) { |
| 354 | mIsEnabled = isEnabled; |
| 355 | return this; |
| 356 | } |
| 357 | |
| 358 | /** |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 359 | * Creates an instance of a {@link PhoneAccount} based on the current builder settings. |
| 360 | * |
| 361 | * @return The {@link PhoneAccount}. |
| 362 | */ |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 363 | public PhoneAccount build() { |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 364 | // If no supported URI schemes were defined, assume "tel" is supported. |
| 365 | if (mSupportedUriSchemes.isEmpty()) { |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 366 | addSupportedUriScheme(SCHEME_TEL); |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 369 | return new PhoneAccount( |
| 370 | mAccountHandle, |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 371 | mAddress, |
| 372 | mSubscriptionAddress, |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 373 | mCapabilities, |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 374 | mIcon, |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 375 | mHighlightColor, |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 376 | mLabel, |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 377 | mShortDescription, |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 378 | mSupportedUriSchemes, |
| Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 379 | mExtras, |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 380 | mIsEnabled); |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | |
| 384 | private PhoneAccount( |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 385 | PhoneAccountHandle account, |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 386 | Uri address, |
| 387 | Uri subscriptionAddress, |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 388 | int capabilities, |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 389 | Icon icon, |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 390 | int highlightColor, |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 391 | CharSequence label, |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 392 | CharSequence shortDescription, |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 393 | List<String> supportedUriSchemes, |
| Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 394 | Bundle extras, |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 395 | boolean isEnabled) { |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 396 | mAccountHandle = account; |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 397 | mAddress = address; |
| 398 | mSubscriptionAddress = subscriptionAddress; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 399 | mCapabilities = capabilities; |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 400 | mIcon = icon; |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 401 | mHighlightColor = highlightColor; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 402 | mLabel = label; |
| 403 | mShortDescription = shortDescription; |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 404 | mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes); |
| Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 405 | mExtras = extras; |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 406 | mIsEnabled = isEnabled; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 407 | } |
| 408 | |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 409 | public static Builder builder( |
| 410 | PhoneAccountHandle accountHandle, |
| 411 | CharSequence label) { |
| 412 | return new Builder(accountHandle, label); |
| 413 | } |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 414 | |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 415 | /** |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 416 | * Returns a builder initialized with the current {@link PhoneAccount} instance. |
| 417 | * |
| 418 | * @return The builder. |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 419 | */ |
| 420 | public Builder toBuilder() { return new Builder(this); } |
| 421 | |
| 422 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 423 | * The unique identifier of this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 424 | * |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 425 | * @return A {@code PhoneAccountHandle}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 426 | */ |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 427 | public PhoneAccountHandle getAccountHandle() { |
| 428 | return mAccountHandle; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | /** |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 432 | * 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] | 433 | * represents the destination from which outgoing calls using this {@code PhoneAccount} |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 434 | * 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] | 435 | * {@code PhoneAccount} may be addressed. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 436 | * |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 437 | * @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] | 438 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 439 | public Uri getAddress() { |
| 440 | return mAddress; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 444 | * The raw callback number used for this {@code PhoneAccount}, as distinct from |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 445 | * {@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] | 446 | * 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] | 447 | * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)} |
| 448 | * has been used to alter the callback number. |
| 449 | * <p> |
| Evan Charlton | 222db525 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 450 | * |
| 451 | * @return The subscription number, suitable for display to the user. |
| 452 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 453 | public Uri getSubscriptionAddress() { |
| 454 | return mSubscriptionAddress; |
| Evan Charlton | 222db525 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | /** |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 458 | * The capabilities of this {@code PhoneAccount}. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 459 | * |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 460 | * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 461 | */ |
| 462 | public int getCapabilities() { |
| 463 | return mCapabilities; |
| 464 | } |
| 465 | |
| 466 | /** |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 467 | * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in |
| 468 | * bit mask. |
| 469 | * |
| 470 | * @param capability The capabilities to check. |
| Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 471 | * @return {@code true} if the phone account has the capability. |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 472 | */ |
| 473 | public boolean hasCapabilities(int capability) { |
| 474 | return (mCapabilities & capability) == capability; |
| 475 | } |
| 476 | |
| 477 | /** |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 478 | * A short label describing a {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 479 | * |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 480 | * @return A label for this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 481 | */ |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 482 | public CharSequence getLabel() { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 483 | return mLabel; |
| 484 | } |
| 485 | |
| 486 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 487 | * A short paragraph describing this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 488 | * |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 489 | * @return A description for this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 490 | */ |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 491 | public CharSequence getShortDescription() { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 492 | return mShortDescription; |
| 493 | } |
| 494 | |
| 495 | /** |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 496 | * The URI schemes supported by this {@code PhoneAccount}. |
| 497 | * |
| 498 | * @return The URI schemes. |
| 499 | */ |
| 500 | public List<String> getSupportedUriSchemes() { |
| 501 | return mSupportedUriSchemes; |
| 502 | } |
| 503 | |
| 504 | /** |
| Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 505 | * The extras associated with this {@code PhoneAccount}. |
| 506 | * <p> |
| 507 | * A {@link ConnectionService} may provide implementation specific information about the |
| 508 | * {@link PhoneAccount} via the extras. |
| 509 | * |
| 510 | * @return The extras. |
| 511 | */ |
| 512 | public Bundle getExtras() { |
| 513 | return mExtras; |
| 514 | } |
| 515 | |
| 516 | /** |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 517 | * The icon to represent this {@code PhoneAccount}. |
| 518 | * |
| 519 | * @return The icon. |
| 520 | */ |
| 521 | public Icon getIcon() { |
| 522 | return mIcon; |
| 523 | } |
| 524 | |
| 525 | /** |
| Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 526 | * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only |
| 527 | * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}. |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 528 | * |
| Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 529 | * @return {@code true} if the account is enabled by the user, {@code false} otherwise. |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 530 | */ |
| 531 | public boolean isEnabled() { |
| 532 | return mIsEnabled; |
| 533 | } |
| 534 | |
| 535 | /** |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 536 | * 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] | 537 | * scheme. |
| 538 | * |
| 539 | * @param uriScheme The URI scheme to check. |
| Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 540 | * @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] | 541 | * specified URI scheme. |
| 542 | */ |
| 543 | public boolean supportsUriScheme(String uriScheme) { |
| 544 | if (mSupportedUriSchemes == null || uriScheme == null) { |
| 545 | return false; |
| 546 | } |
| 547 | |
| 548 | for (String scheme : mSupportedUriSchemes) { |
| 549 | if (scheme != null && scheme.equals(uriScheme)) { |
| 550 | return true; |
| 551 | } |
| 552 | } |
| 553 | return false; |
| 554 | } |
| 555 | |
| 556 | /** |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 557 | * A highlight color to use in displaying information about this {@code PhoneAccount}. |
| 558 | * |
| 559 | * @return A hexadecimal color value. |
| 560 | */ |
| 561 | public int getHighlightColor() { |
| 562 | return mHighlightColor; |
| 563 | } |
| 564 | |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 565 | /** |
| 566 | * Sets the enabled state of the phone account. |
| 567 | * @hide |
| 568 | */ |
| 569 | public void setIsEnabled(boolean isEnabled) { |
| 570 | mIsEnabled = isEnabled; |
| 571 | } |
| 572 | |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 573 | // |
| 574 | // Parcelable implementation |
| 575 | // |
| 576 | |
| 577 | @Override |
| 578 | public int describeContents() { |
| 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | @Override |
| 583 | public void writeToParcel(Parcel out, int flags) { |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 584 | if (mAccountHandle == null) { |
| 585 | out.writeInt(0); |
| 586 | } else { |
| 587 | out.writeInt(1); |
| 588 | mAccountHandle.writeToParcel(out, flags); |
| 589 | } |
| 590 | if (mAddress == null) { |
| 591 | out.writeInt(0); |
| 592 | } else { |
| 593 | out.writeInt(1); |
| 594 | mAddress.writeToParcel(out, flags); |
| 595 | } |
| 596 | if (mSubscriptionAddress == null) { |
| 597 | out.writeInt(0); |
| 598 | } else { |
| 599 | out.writeInt(1); |
| 600 | mSubscriptionAddress.writeToParcel(out, flags); |
| 601 | } |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 602 | out.writeInt(mCapabilities); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 603 | out.writeInt(mHighlightColor); |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 604 | out.writeCharSequence(mLabel); |
| 605 | out.writeCharSequence(mShortDescription); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 606 | out.writeStringList(mSupportedUriSchemes); |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 607 | |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 608 | if (mIcon == null) { |
| 609 | out.writeInt(0); |
| 610 | } else { |
| 611 | out.writeInt(1); |
| 612 | mIcon.writeToParcel(out, flags); |
| 613 | } |
| Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 614 | |
| 615 | out.writeBundle(mExtras); |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 616 | out.writeByte((byte) (mIsEnabled ? 1 : 0)); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 619 | public static final Creator<PhoneAccount> CREATOR |
| 620 | = new Creator<PhoneAccount>() { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 621 | @Override |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 622 | public PhoneAccount createFromParcel(Parcel in) { |
| 623 | return new PhoneAccount(in); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | @Override |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 627 | public PhoneAccount[] newArray(int size) { |
| 628 | return new PhoneAccount[size]; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 629 | } |
| 630 | }; |
| 631 | |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 632 | private PhoneAccount(Parcel in) { |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 633 | if (in.readInt() > 0) { |
| 634 | mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in); |
| 635 | } else { |
| 636 | mAccountHandle = null; |
| 637 | } |
| 638 | if (in.readInt() > 0) { |
| 639 | mAddress = Uri.CREATOR.createFromParcel(in); |
| 640 | } else { |
| 641 | mAddress = null; |
| 642 | } |
| 643 | if (in.readInt() > 0) { |
| 644 | mSubscriptionAddress = Uri.CREATOR.createFromParcel(in); |
| 645 | } else { |
| 646 | mSubscriptionAddress = null; |
| 647 | } |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 648 | mCapabilities = in.readInt(); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 649 | mHighlightColor = in.readInt(); |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 650 | mLabel = in.readCharSequence(); |
| 651 | mShortDescription = in.readCharSequence(); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 652 | mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList()); |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 653 | if (in.readInt() > 0) { |
| 654 | mIcon = Icon.CREATOR.createFromParcel(in); |
| 655 | } else { |
| 656 | mIcon = null; |
| 657 | } |
| Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 658 | mExtras = in.readBundle(); |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 659 | mIsEnabled = in.readByte() == 1; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 660 | } |
| Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 661 | |
| 662 | @Override |
| 663 | public String toString() { |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 664 | StringBuilder sb = new StringBuilder().append("[[") |
| 665 | .append(mIsEnabled ? 'X' : ' ') |
| 666 | .append("] PhoneAccount: ") |
| Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 667 | .append(mAccountHandle) |
| 668 | .append(" Capabilities: ") |
| 669 | .append(mCapabilities) |
| 670 | .append(" Schemes: "); |
| 671 | for (String scheme : mSupportedUriSchemes) { |
| 672 | sb.append(scheme) |
| 673 | .append(" "); |
| 674 | } |
| Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 675 | sb.append(" Extras : "); |
| 676 | sb.append(mExtras); |
| Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 677 | sb.append("]"); |
| 678 | return sb.toString(); |
| 679 | } |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 680 | } |