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 | 7522bbd | 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 | 7522bbd | 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 | 7522bbd | 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 | /** |
Bryce Lee | b96d89c | 2015-10-14 16:48:40 -0700 | [diff] [blame] | 151 | * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls. |
| 152 | * <p> |
| 153 | * See {@link #getCapabilities} |
| 154 | * @hide |
| 155 | */ |
| 156 | public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80; |
| 157 | |
| 158 | /** |
Tyler Gunn | 9a36575 | 2015-12-09 15:00:18 -0800 | [diff] [blame] | 159 | * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a |
| 160 | * number relies on presence. Should only be set if the {@code PhoneAccount} also has |
| 161 | * {@link #CAPABILITY_VIDEO_CALLING}. |
| 162 | * <p> |
| 163 | * When set, the {@link ConnectionService} is responsible for toggling the |
| 164 | * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the |
| 165 | * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether |
| 166 | * a contact's phone number supports video calling. |
| 167 | * <p> |
| 168 | * See {@link #getCapabilities} |
| 169 | */ |
| 170 | public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100; |
| 171 | |
| 172 | /** |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 173 | * URI scheme for telephone number URIs. |
| 174 | */ |
| 175 | public static final String SCHEME_TEL = "tel"; |
| 176 | |
| 177 | /** |
| 178 | * URI scheme for voicemail URIs. |
| 179 | */ |
| 180 | public static final String SCHEME_VOICEMAIL = "voicemail"; |
| 181 | |
| 182 | /** |
| 183 | * URI scheme for SIP URIs. |
| 184 | */ |
| 185 | public static final String SCHEME_SIP = "sip"; |
| 186 | |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 187 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 188 | * Indicating no icon tint is set. |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 189 | * @hide |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 190 | */ |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 191 | public static final int NO_ICON_TINT = 0; |
| 192 | |
| 193 | /** |
| 194 | * Indicating no hightlight color is set. |
| 195 | */ |
| 196 | public static final int NO_HIGHLIGHT_COLOR = 0; |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 197 | |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 198 | /** |
| 199 | * Indicating no resource ID is set. |
| 200 | */ |
| 201 | public static final int NO_RESOURCE_ID = -1; |
| 202 | |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 203 | private final PhoneAccountHandle mAccountHandle; |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 204 | private final Uri mAddress; |
| 205 | private final Uri mSubscriptionAddress; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 206 | private final int mCapabilities; |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 207 | private final int mHighlightColor; |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 208 | private final CharSequence mLabel; |
| 209 | private final CharSequence mShortDescription; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 210 | private final List<String> mSupportedUriSchemes; |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 211 | private final Icon mIcon; |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 212 | private final Bundle mExtras; |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 213 | private boolean mIsEnabled; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 214 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 215 | /** |
| 216 | * Helper class for creating a {@link PhoneAccount}. |
| 217 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 218 | public static class Builder { |
| 219 | private PhoneAccountHandle mAccountHandle; |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 220 | private Uri mAddress; |
| 221 | private Uri mSubscriptionAddress; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 222 | private int mCapabilities; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 223 | private int mHighlightColor = NO_HIGHLIGHT_COLOR; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 224 | private CharSequence mLabel; |
| 225 | private CharSequence mShortDescription; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 226 | private List<String> mSupportedUriSchemes = new ArrayList<String>(); |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 227 | private Icon mIcon; |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 228 | private Bundle mExtras; |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 229 | private boolean mIsEnabled = false; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 230 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 231 | /** |
| 232 | * Creates a builder with the specified {@link PhoneAccountHandle} and label. |
| 233 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 234 | public Builder(PhoneAccountHandle accountHandle, CharSequence label) { |
| 235 | this.mAccountHandle = accountHandle; |
| 236 | this.mLabel = label; |
| 237 | } |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 238 | |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 239 | /** |
| 240 | * Creates an instance of the {@link PhoneAccount.Builder} from an existing |
| 241 | * {@link PhoneAccount}. |
| 242 | * |
| 243 | * @param phoneAccount The {@link PhoneAccount} used to initialize the builder. |
| 244 | */ |
| 245 | public Builder(PhoneAccount phoneAccount) { |
| 246 | mAccountHandle = phoneAccount.getAccountHandle(); |
| 247 | mAddress = phoneAccount.getAddress(); |
| 248 | mSubscriptionAddress = phoneAccount.getSubscriptionAddress(); |
| 249 | mCapabilities = phoneAccount.getCapabilities(); |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 250 | mHighlightColor = phoneAccount.getHighlightColor(); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 251 | mLabel = phoneAccount.getLabel(); |
| 252 | mShortDescription = phoneAccount.getShortDescription(); |
| 253 | mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes()); |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 254 | mIcon = phoneAccount.getIcon(); |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 255 | mIsEnabled = phoneAccount.isEnabled(); |
Tyler Gunn | d426b20 | 2015-10-13 13:33:53 -0700 | [diff] [blame] | 256 | mExtras = phoneAccount.getExtras(); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 259 | /** |
| 260 | * Sets the address. See {@link PhoneAccount#getAddress}. |
| 261 | * |
| 262 | * @param value The address of the phone account. |
| 263 | * @return The builder. |
| 264 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 265 | public Builder setAddress(Uri value) { |
| 266 | this.mAddress = value; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 267 | return this; |
| 268 | } |
| 269 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 270 | /** |
| 271 | * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}. |
| 272 | * |
| 273 | * @param value The subscription address. |
| 274 | * @return The builder. |
| 275 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 276 | public Builder setSubscriptionAddress(Uri value) { |
| 277 | this.mSubscriptionAddress = value; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 278 | return this; |
| 279 | } |
| 280 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 281 | /** |
| 282 | * Sets the capabilities. See {@link PhoneAccount#getCapabilities}. |
| 283 | * |
| 284 | * @param value The capabilities to set. |
| 285 | * @return The builder. |
| 286 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 287 | public Builder setCapabilities(int value) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 288 | this.mCapabilities = value; |
| 289 | return this; |
| 290 | } |
| 291 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 292 | /** |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 293 | * Sets the icon. See {@link PhoneAccount#getIcon}. |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 294 | * |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 295 | * @param icon The icon to set. |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 296 | */ |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 297 | public Builder setIcon(Icon icon) { |
| 298 | mIcon = icon; |
Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 299 | return this; |
| 300 | } |
| 301 | |
| 302 | /** |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 303 | * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}. |
Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 304 | * |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 305 | * @param value The highlight color. |
Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 306 | * @return The builder. |
| 307 | */ |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 308 | public Builder setHighlightColor(int value) { |
| 309 | this.mHighlightColor = value; |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 310 | return this; |
| 311 | } |
| 312 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 313 | /** |
| 314 | * Sets the short description. See {@link PhoneAccount#getShortDescription}. |
| 315 | * |
| 316 | * @param value The short description. |
| 317 | * @return The builder. |
| 318 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 319 | public Builder setShortDescription(CharSequence value) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 320 | this.mShortDescription = value; |
| 321 | return this; |
| 322 | } |
| 323 | |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 324 | /** |
| 325 | * Specifies an additional URI scheme supported by the {@link PhoneAccount}. |
| 326 | * |
| 327 | * @param uriScheme The URI scheme. |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 328 | * @return The builder. |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 329 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 330 | public Builder addSupportedUriScheme(String uriScheme) { |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 331 | if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) { |
| 332 | this.mSupportedUriSchemes.add(uriScheme); |
| 333 | } |
| 334 | return this; |
| 335 | } |
| 336 | |
| 337 | /** |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 338 | * Specifies the URI schemes supported by the {@link PhoneAccount}. |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 339 | * |
| 340 | * @param uriSchemes The URI schemes. |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 341 | * @return The builder. |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 342 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 343 | public Builder setSupportedUriSchemes(List<String> uriSchemes) { |
| 344 | mSupportedUriSchemes.clear(); |
| 345 | |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 346 | if (uriSchemes != null && !uriSchemes.isEmpty()) { |
| 347 | for (String uriScheme : uriSchemes) { |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 348 | addSupportedUriScheme(uriScheme); |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | return this; |
| 352 | } |
| 353 | |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 354 | /** |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 355 | * Specifies the extras associated with the {@link PhoneAccount}. |
| 356 | * <p> |
| 357 | * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer}, |
| 358 | * and {@link Boolean}. Extras which are not of these types are ignored. |
| 359 | * |
| 360 | * @param extras |
| 361 | * @return |
| 362 | */ |
| 363 | public Builder setExtras(Bundle extras) { |
| 364 | mExtras = extras; |
| 365 | return this; |
| 366 | } |
| 367 | |
| 368 | /** |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 369 | * Sets the enabled state of the phone account. |
| 370 | * |
| 371 | * @param isEnabled The enabled state. |
| 372 | * @return The builder. |
| 373 | * @hide |
| 374 | */ |
| 375 | public Builder setIsEnabled(boolean isEnabled) { |
| 376 | mIsEnabled = isEnabled; |
| 377 | return this; |
| 378 | } |
| 379 | |
| 380 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 381 | * Creates an instance of a {@link PhoneAccount} based on the current builder settings. |
| 382 | * |
| 383 | * @return The {@link PhoneAccount}. |
| 384 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 385 | public PhoneAccount build() { |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 386 | // If no supported URI schemes were defined, assume "tel" is supported. |
| 387 | if (mSupportedUriSchemes.isEmpty()) { |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 388 | addSupportedUriScheme(SCHEME_TEL); |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 391 | return new PhoneAccount( |
| 392 | mAccountHandle, |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 393 | mAddress, |
| 394 | mSubscriptionAddress, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 395 | mCapabilities, |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 396 | mIcon, |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 397 | mHighlightColor, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 398 | mLabel, |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 399 | mShortDescription, |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 400 | mSupportedUriSchemes, |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 401 | mExtras, |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 402 | mIsEnabled); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | |
| 406 | private PhoneAccount( |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 407 | PhoneAccountHandle account, |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 408 | Uri address, |
| 409 | Uri subscriptionAddress, |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 410 | int capabilities, |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 411 | Icon icon, |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 412 | int highlightColor, |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 413 | CharSequence label, |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 414 | CharSequence shortDescription, |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 415 | List<String> supportedUriSchemes, |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 416 | Bundle extras, |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 417 | boolean isEnabled) { |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 418 | mAccountHandle = account; |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 419 | mAddress = address; |
| 420 | mSubscriptionAddress = subscriptionAddress; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 421 | mCapabilities = capabilities; |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 422 | mIcon = icon; |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 423 | mHighlightColor = highlightColor; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 424 | mLabel = label; |
| 425 | mShortDescription = shortDescription; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 426 | mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes); |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 427 | mExtras = extras; |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 428 | mIsEnabled = isEnabled; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 431 | public static Builder builder( |
| 432 | PhoneAccountHandle accountHandle, |
| 433 | CharSequence label) { |
| 434 | return new Builder(accountHandle, label); |
| 435 | } |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 436 | |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 437 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 438 | * Returns a builder initialized with the current {@link PhoneAccount} instance. |
| 439 | * |
| 440 | * @return The builder. |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 441 | */ |
| 442 | public Builder toBuilder() { return new Builder(this); } |
| 443 | |
| 444 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 445 | * The unique identifier of this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 446 | * |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 447 | * @return A {@code PhoneAccountHandle}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 448 | */ |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 449 | public PhoneAccountHandle getAccountHandle() { |
| 450 | return mAccountHandle; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | /** |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 454 | * 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] | 455 | * represents the destination from which outgoing calls using this {@code PhoneAccount} |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 456 | * 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] | 457 | * {@code PhoneAccount} may be addressed. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 458 | * |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 459 | * @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] | 460 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 461 | public Uri getAddress() { |
| 462 | return mAddress; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 466 | * The raw callback number used for this {@code PhoneAccount}, as distinct from |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 467 | * {@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] | 468 | * 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] | 469 | * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)} |
| 470 | * has been used to alter the callback number. |
| 471 | * <p> |
Evan Charlton | 222db525 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 472 | * |
| 473 | * @return The subscription number, suitable for display to the user. |
| 474 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 475 | public Uri getSubscriptionAddress() { |
| 476 | return mSubscriptionAddress; |
Evan Charlton | 222db525 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 480 | * The capabilities of this {@code PhoneAccount}. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 481 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 482 | * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 483 | */ |
| 484 | public int getCapabilities() { |
| 485 | return mCapabilities; |
| 486 | } |
| 487 | |
| 488 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 489 | * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in |
| 490 | * bit mask. |
| 491 | * |
| 492 | * @param capability The capabilities to check. |
Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 493 | * @return {@code true} if the phone account has the capability. |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 494 | */ |
| 495 | public boolean hasCapabilities(int capability) { |
| 496 | return (mCapabilities & capability) == capability; |
| 497 | } |
| 498 | |
| 499 | /** |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 500 | * A short label describing a {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 501 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 502 | * @return A label for this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 503 | */ |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 504 | public CharSequence getLabel() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 505 | return mLabel; |
| 506 | } |
| 507 | |
| 508 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 509 | * A short paragraph describing this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 510 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 511 | * @return A description for this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 512 | */ |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 513 | public CharSequence getShortDescription() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 514 | return mShortDescription; |
| 515 | } |
| 516 | |
| 517 | /** |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 518 | * The URI schemes supported by this {@code PhoneAccount}. |
| 519 | * |
| 520 | * @return The URI schemes. |
| 521 | */ |
| 522 | public List<String> getSupportedUriSchemes() { |
| 523 | return mSupportedUriSchemes; |
| 524 | } |
| 525 | |
| 526 | /** |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 527 | * The extras associated with this {@code PhoneAccount}. |
| 528 | * <p> |
| 529 | * A {@link ConnectionService} may provide implementation specific information about the |
| 530 | * {@link PhoneAccount} via the extras. |
| 531 | * |
| 532 | * @return The extras. |
| 533 | */ |
| 534 | public Bundle getExtras() { |
| 535 | return mExtras; |
| 536 | } |
| 537 | |
| 538 | /** |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 539 | * The icon to represent this {@code PhoneAccount}. |
| 540 | * |
| 541 | * @return The icon. |
| 542 | */ |
| 543 | public Icon getIcon() { |
| 544 | return mIcon; |
| 545 | } |
| 546 | |
| 547 | /** |
Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 548 | * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only |
| 549 | * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}. |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 550 | * |
Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 551 | * @return {@code true} if the account is enabled by the user, {@code false} otherwise. |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 552 | */ |
| 553 | public boolean isEnabled() { |
| 554 | return mIsEnabled; |
| 555 | } |
| 556 | |
| 557 | /** |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 558 | * 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] | 559 | * scheme. |
| 560 | * |
| 561 | * @param uriScheme The URI scheme to check. |
Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 562 | * @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] | 563 | * specified URI scheme. |
| 564 | */ |
| 565 | public boolean supportsUriScheme(String uriScheme) { |
| 566 | if (mSupportedUriSchemes == null || uriScheme == null) { |
| 567 | return false; |
| 568 | } |
| 569 | |
| 570 | for (String scheme : mSupportedUriSchemes) { |
| 571 | if (scheme != null && scheme.equals(uriScheme)) { |
| 572 | return true; |
| 573 | } |
| 574 | } |
| 575 | return false; |
| 576 | } |
| 577 | |
| 578 | /** |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 579 | * A highlight color to use in displaying information about this {@code PhoneAccount}. |
| 580 | * |
| 581 | * @return A hexadecimal color value. |
| 582 | */ |
| 583 | public int getHighlightColor() { |
| 584 | return mHighlightColor; |
| 585 | } |
| 586 | |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 587 | /** |
| 588 | * Sets the enabled state of the phone account. |
| 589 | * @hide |
| 590 | */ |
| 591 | public void setIsEnabled(boolean isEnabled) { |
| 592 | mIsEnabled = isEnabled; |
| 593 | } |
| 594 | |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 595 | // |
| 596 | // Parcelable implementation |
| 597 | // |
| 598 | |
| 599 | @Override |
| 600 | public int describeContents() { |
| 601 | return 0; |
| 602 | } |
| 603 | |
| 604 | @Override |
| 605 | public void writeToParcel(Parcel out, int flags) { |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 606 | if (mAccountHandle == null) { |
| 607 | out.writeInt(0); |
| 608 | } else { |
| 609 | out.writeInt(1); |
| 610 | mAccountHandle.writeToParcel(out, flags); |
| 611 | } |
| 612 | if (mAddress == null) { |
| 613 | out.writeInt(0); |
| 614 | } else { |
| 615 | out.writeInt(1); |
| 616 | mAddress.writeToParcel(out, flags); |
| 617 | } |
| 618 | if (mSubscriptionAddress == null) { |
| 619 | out.writeInt(0); |
| 620 | } else { |
| 621 | out.writeInt(1); |
| 622 | mSubscriptionAddress.writeToParcel(out, flags); |
| 623 | } |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 624 | out.writeInt(mCapabilities); |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 625 | out.writeInt(mHighlightColor); |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 626 | out.writeCharSequence(mLabel); |
| 627 | out.writeCharSequence(mShortDescription); |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 628 | out.writeStringList(mSupportedUriSchemes); |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 629 | |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 630 | if (mIcon == null) { |
| 631 | out.writeInt(0); |
| 632 | } else { |
| 633 | out.writeInt(1); |
| 634 | mIcon.writeToParcel(out, flags); |
| 635 | } |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 636 | out.writeByte((byte) (mIsEnabled ? 1 : 0)); |
Tyler Gunn | ef829ec | 2015-10-08 09:46:23 -0700 | [diff] [blame] | 637 | out.writeBundle(mExtras); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 638 | } |
| 639 | |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 640 | public static final Creator<PhoneAccount> CREATOR |
| 641 | = new Creator<PhoneAccount>() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 642 | @Override |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 643 | public PhoneAccount createFromParcel(Parcel in) { |
| 644 | return new PhoneAccount(in); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | @Override |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 648 | public PhoneAccount[] newArray(int size) { |
| 649 | return new PhoneAccount[size]; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 650 | } |
| 651 | }; |
| 652 | |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 653 | private PhoneAccount(Parcel in) { |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 654 | if (in.readInt() > 0) { |
| 655 | mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in); |
| 656 | } else { |
| 657 | mAccountHandle = null; |
| 658 | } |
| 659 | if (in.readInt() > 0) { |
| 660 | mAddress = Uri.CREATOR.createFromParcel(in); |
| 661 | } else { |
| 662 | mAddress = null; |
| 663 | } |
| 664 | if (in.readInt() > 0) { |
| 665 | mSubscriptionAddress = Uri.CREATOR.createFromParcel(in); |
| 666 | } else { |
| 667 | mSubscriptionAddress = null; |
| 668 | } |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 669 | mCapabilities = in.readInt(); |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 670 | mHighlightColor = in.readInt(); |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 671 | mLabel = in.readCharSequence(); |
| 672 | mShortDescription = in.readCharSequence(); |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 673 | mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList()); |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 674 | if (in.readInt() > 0) { |
| 675 | mIcon = Icon.CREATOR.createFromParcel(in); |
| 676 | } else { |
| 677 | mIcon = null; |
| 678 | } |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 679 | mIsEnabled = in.readByte() == 1; |
Tyler Gunn | ef829ec | 2015-10-08 09:46:23 -0700 | [diff] [blame] | 680 | mExtras = in.readBundle(); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 681 | } |
Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 682 | |
| 683 | @Override |
| 684 | public String toString() { |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 685 | StringBuilder sb = new StringBuilder().append("[[") |
| 686 | .append(mIsEnabled ? 'X' : ' ') |
| 687 | .append("] PhoneAccount: ") |
Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 688 | .append(mAccountHandle) |
| 689 | .append(" Capabilities: ") |
Tyler Gunn | 3e122f7 | 2016-01-11 19:25:00 -0800 | [diff] [blame] | 690 | .append(capabilitiesToString(mCapabilities)) |
Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 691 | .append(" Schemes: "); |
| 692 | for (String scheme : mSupportedUriSchemes) { |
| 693 | sb.append(scheme) |
| 694 | .append(" "); |
| 695 | } |
Tyler Gunn | ef829ec | 2015-10-08 09:46:23 -0700 | [diff] [blame] | 696 | sb.append(" Extras: "); |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 697 | sb.append(mExtras); |
Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 698 | sb.append("]"); |
| 699 | return sb.toString(); |
| 700 | } |
Tyler Gunn | 3e122f7 | 2016-01-11 19:25:00 -0800 | [diff] [blame] | 701 | |
| 702 | /** |
| 703 | * Generates a string representation of a capabilities bitmask. |
| 704 | * |
| 705 | * @param capabilities The capabilities bitmask. |
| 706 | * @return String representation of the capabilities bitmask. |
| 707 | */ |
| 708 | private String capabilitiesToString(int capabilities) { |
| 709 | StringBuilder sb = new StringBuilder(); |
| 710 | if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) { |
| 711 | sb.append("Video "); |
| 712 | } |
| 713 | if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) { |
| 714 | sb.append("Presence "); |
| 715 | } |
| 716 | if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) { |
| 717 | sb.append("CallProvider "); |
| 718 | } |
| 719 | if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) { |
| 720 | sb.append("CallSubject "); |
| 721 | } |
| 722 | if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) { |
| 723 | sb.append("ConnectionMgr "); |
| 724 | } |
| 725 | if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) { |
| 726 | sb.append("EmergOnly "); |
| 727 | } |
| 728 | if (hasCapabilities(CAPABILITY_MULTI_USER)) { |
| 729 | sb.append("MultiUser "); |
| 730 | } |
| 731 | if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) { |
| 732 | sb.append("PlaceEmerg "); |
| 733 | } |
| 734 | if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) { |
| 735 | sb.append("SimSub "); |
| 736 | } |
| 737 | return sb.toString(); |
| 738 | } |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 739 | } |