| 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 | /** |
| Tyler Gunn | 58cbd7a | 2016-11-11 11:31:28 -0800 | [diff] [blame] | 117 | * Flag indicating that this {@code PhoneAccount} is currently able to place video calls. |
| 118 | * <p> |
| 119 | * See also {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING} which indicates whether the |
| 120 | * {@code PhoneAccount} supports placing video calls. |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 121 | * <p> |
| 122 | * See {@link #getCapabilities} |
| Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 123 | */ |
| 124 | public static final int CAPABILITY_VIDEO_CALLING = 0x8; |
| 125 | |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 126 | /** |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 127 | * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls. |
| 128 | * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls. |
| 129 | * <p> |
| 130 | * See {@link #getCapabilities} |
| 131 | */ |
| 132 | public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10; |
| 133 | |
| 134 | /** |
| Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 135 | * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This |
| 136 | * should only be used by system apps (and will be ignored for all other apps trying to use it). |
| 137 | * <p> |
| 138 | * See {@link #getCapabilities} |
| 139 | * @hide |
| 140 | */ |
| Brian Attwell | ad147f4 | 2014-12-19 11:37:16 -0800 | [diff] [blame] | 141 | @SystemApi |
| Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 142 | public static final int CAPABILITY_MULTI_USER = 0x20; |
| 143 | |
| 144 | /** |
| Tyler Gunn | 65a3d34 | 2015-07-27 16:06:16 -0700 | [diff] [blame] | 145 | * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a |
| 146 | * caller is able to specify a short subject line for an outgoing call. A capable receiving |
| 147 | * device displays the call subject on the incoming call screen. |
| 148 | * <p> |
| 149 | * See {@link #getCapabilities} |
| 150 | */ |
| 151 | public static final int CAPABILITY_CALL_SUBJECT = 0x40; |
| 152 | |
| 153 | /** |
| Bryce Lee | b96d89c | 2015-10-14 16:48:40 -0700 | [diff] [blame] | 154 | * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls. |
| 155 | * <p> |
| 156 | * See {@link #getCapabilities} |
| 157 | * @hide |
| 158 | */ |
| 159 | public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80; |
| 160 | |
| 161 | /** |
| Tyler Gunn | 9a36575 | 2015-12-09 15:00:18 -0800 | [diff] [blame] | 162 | * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a |
| 163 | * number relies on presence. Should only be set if the {@code PhoneAccount} also has |
| 164 | * {@link #CAPABILITY_VIDEO_CALLING}. |
| 165 | * <p> |
| 166 | * When set, the {@link ConnectionService} is responsible for toggling the |
| 167 | * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the |
| 168 | * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether |
| 169 | * a contact's phone number supports video calling. |
| 170 | * <p> |
| 171 | * See {@link #getCapabilities} |
| 172 | */ |
| 173 | public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100; |
| 174 | |
| 175 | /** |
| Tyler Gunn | cee9ea6 | 2016-03-24 11:45:43 -0700 | [diff] [blame] | 176 | * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed. |
| 177 | * <p> |
| 178 | * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will |
| 179 | * convert all outgoing video calls to emergency numbers to audio-only. |
| 180 | * @hide |
| 181 | */ |
| 182 | public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200; |
| 183 | |
| 184 | /** |
| Tyler Gunn | 58cbd7a | 2016-11-11 11:31:28 -0800 | [diff] [blame] | 185 | * Flag indicating that this {@link PhoneAccount} supports video calling. |
| 186 | * This is not an indication that the {@link PhoneAccount} is currently able to make a video |
| 187 | * call, but rather that it has the ability to make video calls (but not necessarily at this |
| 188 | * time). |
| 189 | * <p> |
| 190 | * Whether a {@link PhoneAccount} can make a video call is ultimately controlled by |
| 191 | * {@link #CAPABILITY_VIDEO_CALLING}, which indicates whether the {@link PhoneAccount} is |
| 192 | * currently capable of making a video call. Consider a case where, for example, a |
| 193 | * {@link PhoneAccount} supports making video calls (e.g. |
| 194 | * {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING}), but a current lack of network connectivity |
| 195 | * prevents video calls from being made (e.g. {@link #CAPABILITY_VIDEO_CALLING}). |
| 196 | * <p> |
| 197 | * See {@link #getCapabilities} |
| 198 | */ |
| 199 | public static final int CAPABILITY_SUPPORTS_VIDEO_CALLING = 0x400; |
| 200 | |
| 201 | /** |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 202 | * URI scheme for telephone number URIs. |
| 203 | */ |
| 204 | public static final String SCHEME_TEL = "tel"; |
| 205 | |
| 206 | /** |
| 207 | * URI scheme for voicemail URIs. |
| 208 | */ |
| 209 | public static final String SCHEME_VOICEMAIL = "voicemail"; |
| 210 | |
| 211 | /** |
| 212 | * URI scheme for SIP URIs. |
| 213 | */ |
| 214 | public static final String SCHEME_SIP = "sip"; |
| 215 | |
| Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 216 | /** |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 217 | * Indicating no icon tint is set. |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 218 | * @hide |
| Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 219 | */ |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 220 | public static final int NO_ICON_TINT = 0; |
| 221 | |
| 222 | /** |
| 223 | * Indicating no hightlight color is set. |
| 224 | */ |
| 225 | public static final int NO_HIGHLIGHT_COLOR = 0; |
| Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 226 | |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 227 | /** |
| 228 | * Indicating no resource ID is set. |
| 229 | */ |
| 230 | public static final int NO_RESOURCE_ID = -1; |
| 231 | |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 232 | private final PhoneAccountHandle mAccountHandle; |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 233 | private final Uri mAddress; |
| 234 | private final Uri mSubscriptionAddress; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 235 | private final int mCapabilities; |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 236 | private final int mHighlightColor; |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 237 | private final CharSequence mLabel; |
| 238 | private final CharSequence mShortDescription; |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 239 | private final List<String> mSupportedUriSchemes; |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 240 | private final Icon mIcon; |
| Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 241 | private final Bundle mExtras; |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 242 | private boolean mIsEnabled; |
| Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 243 | private String mGroupId; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 244 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 245 | /** |
| 246 | * Helper class for creating a {@link PhoneAccount}. |
| 247 | */ |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 248 | public static class Builder { |
| 249 | private PhoneAccountHandle mAccountHandle; |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 250 | private Uri mAddress; |
| 251 | private Uri mSubscriptionAddress; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 252 | private int mCapabilities; |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 253 | private int mHighlightColor = NO_HIGHLIGHT_COLOR; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 254 | private CharSequence mLabel; |
| 255 | private CharSequence mShortDescription; |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 256 | private List<String> mSupportedUriSchemes = new ArrayList<String>(); |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 257 | private Icon mIcon; |
| Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 258 | private Bundle mExtras; |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 259 | private boolean mIsEnabled = false; |
| Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 260 | private String mGroupId = ""; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 261 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 262 | /** |
| 263 | * Creates a builder with the specified {@link PhoneAccountHandle} and label. |
| 264 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 265 | public Builder(PhoneAccountHandle accountHandle, CharSequence label) { |
| 266 | this.mAccountHandle = accountHandle; |
| 267 | this.mLabel = label; |
| 268 | } |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 269 | |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 270 | /** |
| 271 | * Creates an instance of the {@link PhoneAccount.Builder} from an existing |
| 272 | * {@link PhoneAccount}. |
| 273 | * |
| 274 | * @param phoneAccount The {@link PhoneAccount} used to initialize the builder. |
| 275 | */ |
| 276 | public Builder(PhoneAccount phoneAccount) { |
| 277 | mAccountHandle = phoneAccount.getAccountHandle(); |
| 278 | mAddress = phoneAccount.getAddress(); |
| 279 | mSubscriptionAddress = phoneAccount.getSubscriptionAddress(); |
| 280 | mCapabilities = phoneAccount.getCapabilities(); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 281 | mHighlightColor = phoneAccount.getHighlightColor(); |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 282 | mLabel = phoneAccount.getLabel(); |
| 283 | mShortDescription = phoneAccount.getShortDescription(); |
| 284 | mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes()); |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 285 | mIcon = phoneAccount.getIcon(); |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 286 | mIsEnabled = phoneAccount.isEnabled(); |
| Tyler Gunn | d426b20 | 2015-10-13 13:33:53 -0700 | [diff] [blame] | 287 | mExtras = phoneAccount.getExtras(); |
| Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 288 | mGroupId = phoneAccount.getGroupId(); |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 289 | } |
| 290 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 291 | /** |
| 292 | * Sets the address. See {@link PhoneAccount#getAddress}. |
| 293 | * |
| 294 | * @param value The address of the phone account. |
| 295 | * @return The builder. |
| 296 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 297 | public Builder setAddress(Uri value) { |
| 298 | this.mAddress = value; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 299 | return this; |
| 300 | } |
| 301 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 302 | /** |
| 303 | * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}. |
| 304 | * |
| 305 | * @param value The subscription address. |
| 306 | * @return The builder. |
| 307 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 308 | public Builder setSubscriptionAddress(Uri value) { |
| 309 | this.mSubscriptionAddress = value; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 310 | return this; |
| 311 | } |
| 312 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 313 | /** |
| 314 | * Sets the capabilities. See {@link PhoneAccount#getCapabilities}. |
| 315 | * |
| 316 | * @param value The capabilities to set. |
| 317 | * @return The builder. |
| 318 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 319 | public Builder setCapabilities(int value) { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 320 | this.mCapabilities = value; |
| 321 | return this; |
| 322 | } |
| 323 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 324 | /** |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 325 | * Sets the icon. See {@link PhoneAccount#getIcon}. |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 326 | * |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 327 | * @param icon The icon to set. |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 328 | */ |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 329 | public Builder setIcon(Icon icon) { |
| 330 | mIcon = icon; |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 331 | return this; |
| 332 | } |
| 333 | |
| 334 | /** |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 335 | * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}. |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 336 | * |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 337 | * @param value The highlight color. |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 338 | * @return The builder. |
| 339 | */ |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 340 | public Builder setHighlightColor(int value) { |
| 341 | this.mHighlightColor = value; |
| Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 342 | return this; |
| 343 | } |
| 344 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 345 | /** |
| 346 | * Sets the short description. See {@link PhoneAccount#getShortDescription}. |
| 347 | * |
| 348 | * @param value The short description. |
| 349 | * @return The builder. |
| 350 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 351 | public Builder setShortDescription(CharSequence value) { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 352 | this.mShortDescription = value; |
| 353 | return this; |
| 354 | } |
| 355 | |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 356 | /** |
| 357 | * Specifies an additional URI scheme supported by the {@link PhoneAccount}. |
| 358 | * |
| 359 | * @param uriScheme The URI scheme. |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 360 | * @return The builder. |
| 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. |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 373 | * @return The builder. |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 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 | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 387 | * Specifies the extras associated with the {@link PhoneAccount}. |
| 388 | * <p> |
| 389 | * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer}, |
| 390 | * and {@link Boolean}. Extras which are not of these types are ignored. |
| 391 | * |
| 392 | * @param extras |
| 393 | * @return |
| 394 | */ |
| 395 | public Builder setExtras(Bundle extras) { |
| 396 | mExtras = extras; |
| 397 | return this; |
| 398 | } |
| 399 | |
| 400 | /** |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 401 | * Sets the enabled state of the phone account. |
| 402 | * |
| 403 | * @param isEnabled The enabled state. |
| 404 | * @return The builder. |
| 405 | * @hide |
| 406 | */ |
| 407 | public Builder setIsEnabled(boolean isEnabled) { |
| 408 | mIsEnabled = isEnabled; |
| 409 | return this; |
| 410 | } |
| 411 | |
| 412 | /** |
| Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 413 | * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is |
| 414 | * registered to Telecom, it will replace another {@link PhoneAccount} that is already |
| 415 | * registered in Telecom and take on the current user defaults and enabled status. There can |
| 416 | * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a |
| 417 | * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only |
| 418 | * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced. |
| 419 | * @param groupId The group Id of the {@link PhoneAccount} that will replace any other |
| 420 | * registered {@link PhoneAccount} in Telecom with the same Group Id. |
| 421 | * @return The builder |
| 422 | * @hide |
| 423 | */ |
| 424 | public Builder setGroupId(String groupId) { |
| 425 | if (groupId != null) { |
| 426 | mGroupId = groupId; |
| 427 | } else { |
| 428 | mGroupId = ""; |
| 429 | } |
| 430 | return this; |
| 431 | } |
| 432 | |
| 433 | /** |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 434 | * Creates an instance of a {@link PhoneAccount} based on the current builder settings. |
| 435 | * |
| 436 | * @return The {@link PhoneAccount}. |
| 437 | */ |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 438 | public PhoneAccount build() { |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 439 | // If no supported URI schemes were defined, assume "tel" is supported. |
| 440 | if (mSupportedUriSchemes.isEmpty()) { |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 441 | addSupportedUriScheme(SCHEME_TEL); |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 442 | } |
| 443 | |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 444 | return new PhoneAccount( |
| 445 | mAccountHandle, |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 446 | mAddress, |
| 447 | mSubscriptionAddress, |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 448 | mCapabilities, |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 449 | mIcon, |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 450 | mHighlightColor, |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 451 | mLabel, |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 452 | mShortDescription, |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 453 | mSupportedUriSchemes, |
| Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 454 | mExtras, |
| Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 455 | mIsEnabled, |
| 456 | mGroupId); |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | |
| 460 | private PhoneAccount( |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 461 | PhoneAccountHandle account, |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 462 | Uri address, |
| 463 | Uri subscriptionAddress, |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 464 | int capabilities, |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 465 | Icon icon, |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 466 | int highlightColor, |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 467 | CharSequence label, |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 468 | CharSequence shortDescription, |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 469 | List<String> supportedUriSchemes, |
| Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 470 | Bundle extras, |
| Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 471 | boolean isEnabled, |
| 472 | String groupId) { |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 473 | mAccountHandle = account; |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 474 | mAddress = address; |
| 475 | mSubscriptionAddress = subscriptionAddress; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 476 | mCapabilities = capabilities; |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 477 | mIcon = icon; |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 478 | mHighlightColor = highlightColor; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 479 | mLabel = label; |
| 480 | mShortDescription = shortDescription; |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 481 | mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes); |
| Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 482 | mExtras = extras; |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 483 | mIsEnabled = isEnabled; |
| Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 484 | mGroupId = groupId; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 485 | } |
| 486 | |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 487 | public static Builder builder( |
| 488 | PhoneAccountHandle accountHandle, |
| 489 | CharSequence label) { |
| 490 | return new Builder(accountHandle, label); |
| 491 | } |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 492 | |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 493 | /** |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 494 | * Returns a builder initialized with the current {@link PhoneAccount} instance. |
| 495 | * |
| 496 | * @return The builder. |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 497 | */ |
| 498 | public Builder toBuilder() { return new Builder(this); } |
| 499 | |
| 500 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 501 | * The unique identifier of this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 502 | * |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 503 | * @return A {@code PhoneAccountHandle}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 504 | */ |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 505 | public PhoneAccountHandle getAccountHandle() { |
| 506 | return mAccountHandle; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | /** |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 510 | * 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] | 511 | * represents the destination from which outgoing calls using this {@code PhoneAccount} |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 512 | * 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] | 513 | * {@code PhoneAccount} may be addressed. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 514 | * |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 515 | * @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] | 516 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 517 | public Uri getAddress() { |
| 518 | return mAddress; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 522 | * The raw callback number used for this {@code PhoneAccount}, as distinct from |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 523 | * {@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] | 524 | * 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] | 525 | * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)} |
| 526 | * has been used to alter the callback number. |
| 527 | * <p> |
| Evan Charlton | 222db525 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 528 | * |
| 529 | * @return The subscription number, suitable for display to the user. |
| 530 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 531 | public Uri getSubscriptionAddress() { |
| 532 | return mSubscriptionAddress; |
| Evan Charlton | 222db525 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | /** |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 536 | * The capabilities of this {@code PhoneAccount}. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 537 | * |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 538 | * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 539 | */ |
| 540 | public int getCapabilities() { |
| 541 | return mCapabilities; |
| 542 | } |
| 543 | |
| 544 | /** |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 545 | * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in |
| 546 | * bit mask. |
| 547 | * |
| 548 | * @param capability The capabilities to check. |
| Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 549 | * @return {@code true} if the phone account has the capability. |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 550 | */ |
| 551 | public boolean hasCapabilities(int capability) { |
| 552 | return (mCapabilities & capability) == capability; |
| 553 | } |
| 554 | |
| 555 | /** |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 556 | * A short label describing a {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 557 | * |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 558 | * @return A label for this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 559 | */ |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 560 | public CharSequence getLabel() { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 561 | return mLabel; |
| 562 | } |
| 563 | |
| 564 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 565 | * A short paragraph describing this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 566 | * |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 567 | * @return A description for this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 568 | */ |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 569 | public CharSequence getShortDescription() { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 570 | return mShortDescription; |
| 571 | } |
| 572 | |
| 573 | /** |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 574 | * The URI schemes supported by this {@code PhoneAccount}. |
| 575 | * |
| 576 | * @return The URI schemes. |
| 577 | */ |
| 578 | public List<String> getSupportedUriSchemes() { |
| 579 | return mSupportedUriSchemes; |
| 580 | } |
| 581 | |
| 582 | /** |
| Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 583 | * The extras associated with this {@code PhoneAccount}. |
| 584 | * <p> |
| 585 | * A {@link ConnectionService} may provide implementation specific information about the |
| 586 | * {@link PhoneAccount} via the extras. |
| 587 | * |
| 588 | * @return The extras. |
| 589 | */ |
| 590 | public Bundle getExtras() { |
| 591 | return mExtras; |
| 592 | } |
| 593 | |
| 594 | /** |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 595 | * The icon to represent this {@code PhoneAccount}. |
| 596 | * |
| 597 | * @return The icon. |
| 598 | */ |
| 599 | public Icon getIcon() { |
| 600 | return mIcon; |
| 601 | } |
| 602 | |
| 603 | /** |
| Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 604 | * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only |
| 605 | * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}. |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 606 | * |
| Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 607 | * @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] | 608 | */ |
| 609 | public boolean isEnabled() { |
| 610 | return mIsEnabled; |
| 611 | } |
| 612 | |
| 613 | /** |
| Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 614 | * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an |
| 615 | * empty {@link String} if the {@link PhoneAccount} is not in a group. If this |
| 616 | * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered |
| 617 | * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced, |
| 618 | * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}. |
| 619 | * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced. |
| 620 | * |
| 621 | * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group. |
| 622 | * @hide |
| 623 | */ |
| 624 | public String getGroupId() { |
| 625 | return mGroupId; |
| 626 | } |
| 627 | |
| 628 | /** |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 629 | * 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] | 630 | * scheme. |
| 631 | * |
| 632 | * @param uriScheme The URI scheme to check. |
| Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 633 | * @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] | 634 | * specified URI scheme. |
| 635 | */ |
| 636 | public boolean supportsUriScheme(String uriScheme) { |
| 637 | if (mSupportedUriSchemes == null || uriScheme == null) { |
| 638 | return false; |
| 639 | } |
| 640 | |
| 641 | for (String scheme : mSupportedUriSchemes) { |
| 642 | if (scheme != null && scheme.equals(uriScheme)) { |
| 643 | return true; |
| 644 | } |
| 645 | } |
| 646 | return false; |
| 647 | } |
| 648 | |
| 649 | /** |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 650 | * A highlight color to use in displaying information about this {@code PhoneAccount}. |
| 651 | * |
| 652 | * @return A hexadecimal color value. |
| 653 | */ |
| 654 | public int getHighlightColor() { |
| 655 | return mHighlightColor; |
| 656 | } |
| 657 | |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 658 | /** |
| 659 | * Sets the enabled state of the phone account. |
| 660 | * @hide |
| 661 | */ |
| 662 | public void setIsEnabled(boolean isEnabled) { |
| 663 | mIsEnabled = isEnabled; |
| 664 | } |
| 665 | |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 666 | // |
| 667 | // Parcelable implementation |
| 668 | // |
| 669 | |
| 670 | @Override |
| 671 | public int describeContents() { |
| 672 | return 0; |
| 673 | } |
| 674 | |
| 675 | @Override |
| 676 | public void writeToParcel(Parcel out, int flags) { |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 677 | if (mAccountHandle == null) { |
| 678 | out.writeInt(0); |
| 679 | } else { |
| 680 | out.writeInt(1); |
| 681 | mAccountHandle.writeToParcel(out, flags); |
| 682 | } |
| 683 | if (mAddress == null) { |
| 684 | out.writeInt(0); |
| 685 | } else { |
| 686 | out.writeInt(1); |
| 687 | mAddress.writeToParcel(out, flags); |
| 688 | } |
| 689 | if (mSubscriptionAddress == null) { |
| 690 | out.writeInt(0); |
| 691 | } else { |
| 692 | out.writeInt(1); |
| 693 | mSubscriptionAddress.writeToParcel(out, flags); |
| 694 | } |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 695 | out.writeInt(mCapabilities); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 696 | out.writeInt(mHighlightColor); |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 697 | out.writeCharSequence(mLabel); |
| 698 | out.writeCharSequence(mShortDescription); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 699 | out.writeStringList(mSupportedUriSchemes); |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 700 | |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 701 | if (mIcon == null) { |
| 702 | out.writeInt(0); |
| 703 | } else { |
| 704 | out.writeInt(1); |
| 705 | mIcon.writeToParcel(out, flags); |
| 706 | } |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 707 | out.writeByte((byte) (mIsEnabled ? 1 : 0)); |
| Tyler Gunn | ef829ec | 2015-10-08 09:46:23 -0700 | [diff] [blame] | 708 | out.writeBundle(mExtras); |
| Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 709 | out.writeString(mGroupId); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 710 | } |
| 711 | |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 712 | public static final Creator<PhoneAccount> CREATOR |
| 713 | = new Creator<PhoneAccount>() { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 714 | @Override |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 715 | public PhoneAccount createFromParcel(Parcel in) { |
| 716 | return new PhoneAccount(in); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | @Override |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 720 | public PhoneAccount[] newArray(int size) { |
| 721 | return new PhoneAccount[size]; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 722 | } |
| 723 | }; |
| 724 | |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 725 | private PhoneAccount(Parcel in) { |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 726 | if (in.readInt() > 0) { |
| 727 | mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in); |
| 728 | } else { |
| 729 | mAccountHandle = null; |
| 730 | } |
| 731 | if (in.readInt() > 0) { |
| 732 | mAddress = Uri.CREATOR.createFromParcel(in); |
| 733 | } else { |
| 734 | mAddress = null; |
| 735 | } |
| 736 | if (in.readInt() > 0) { |
| 737 | mSubscriptionAddress = Uri.CREATOR.createFromParcel(in); |
| 738 | } else { |
| 739 | mSubscriptionAddress = null; |
| 740 | } |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 741 | mCapabilities = in.readInt(); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 742 | mHighlightColor = in.readInt(); |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 743 | mLabel = in.readCharSequence(); |
| 744 | mShortDescription = in.readCharSequence(); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 745 | mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList()); |
| Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 746 | if (in.readInt() > 0) { |
| 747 | mIcon = Icon.CREATOR.createFromParcel(in); |
| 748 | } else { |
| 749 | mIcon = null; |
| 750 | } |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 751 | mIsEnabled = in.readByte() == 1; |
| Tyler Gunn | ef829ec | 2015-10-08 09:46:23 -0700 | [diff] [blame] | 752 | mExtras = in.readBundle(); |
| Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 753 | mGroupId = in.readString(); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 754 | } |
| Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 755 | |
| 756 | @Override |
| 757 | public String toString() { |
| Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 758 | StringBuilder sb = new StringBuilder().append("[[") |
| 759 | .append(mIsEnabled ? 'X' : ' ') |
| 760 | .append("] PhoneAccount: ") |
| Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 761 | .append(mAccountHandle) |
| 762 | .append(" Capabilities: ") |
| Tyler Gunn | 3e122f7 | 2016-01-11 19:25:00 -0800 | [diff] [blame] | 763 | .append(capabilitiesToString(mCapabilities)) |
| Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 764 | .append(" Schemes: "); |
| 765 | for (String scheme : mSupportedUriSchemes) { |
| 766 | sb.append(scheme) |
| 767 | .append(" "); |
| 768 | } |
| Tyler Gunn | ef829ec | 2015-10-08 09:46:23 -0700 | [diff] [blame] | 769 | sb.append(" Extras: "); |
| Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 770 | sb.append(mExtras); |
| Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 771 | sb.append(" GroupId: "); |
| 772 | sb.append(Log.pii(mGroupId)); |
| Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 773 | sb.append("]"); |
| 774 | return sb.toString(); |
| 775 | } |
| Tyler Gunn | 3e122f7 | 2016-01-11 19:25:00 -0800 | [diff] [blame] | 776 | |
| 777 | /** |
| 778 | * Generates a string representation of a capabilities bitmask. |
| 779 | * |
| 780 | * @param capabilities The capabilities bitmask. |
| 781 | * @return String representation of the capabilities bitmask. |
| 782 | */ |
| 783 | private String capabilitiesToString(int capabilities) { |
| 784 | StringBuilder sb = new StringBuilder(); |
| Tyler Gunn | 58cbd7a | 2016-11-11 11:31:28 -0800 | [diff] [blame] | 785 | if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) { |
| 786 | sb.append("SuppVideo "); |
| 787 | } |
| Tyler Gunn | 3e122f7 | 2016-01-11 19:25:00 -0800 | [diff] [blame] | 788 | if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) { |
| 789 | sb.append("Video "); |
| 790 | } |
| 791 | if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) { |
| 792 | sb.append("Presence "); |
| 793 | } |
| 794 | if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) { |
| 795 | sb.append("CallProvider "); |
| 796 | } |
| 797 | if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) { |
| 798 | sb.append("CallSubject "); |
| 799 | } |
| 800 | if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) { |
| 801 | sb.append("ConnectionMgr "); |
| 802 | } |
| 803 | if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) { |
| 804 | sb.append("EmergOnly "); |
| 805 | } |
| 806 | if (hasCapabilities(CAPABILITY_MULTI_USER)) { |
| 807 | sb.append("MultiUser "); |
| 808 | } |
| 809 | if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) { |
| 810 | sb.append("PlaceEmerg "); |
| 811 | } |
| Tyler Gunn | cee9ea6 | 2016-03-24 11:45:43 -0700 | [diff] [blame] | 812 | if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) { |
| 813 | sb.append("EmergVideo "); |
| 814 | } |
| Tyler Gunn | 3e122f7 | 2016-01-11 19:25:00 -0800 | [diff] [blame] | 815 | if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) { |
| 816 | sb.append("SimSub "); |
| 817 | } |
| 818 | return sb.toString(); |
| 819 | } |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 820 | } |