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; |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 20 | import android.graphics.drawable.Icon; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 21 | import android.net.Uri; |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 22 | import android.os.Bundle; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 23 | import android.os.Parcel; |
| 24 | import android.os.Parcelable; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 25 | import android.text.TextUtils; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 26 | |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 27 | import java.lang.String; |
| 28 | import java.util.ArrayList; |
| 29 | import java.util.Collections; |
| 30 | import java.util.List; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 31 | |
| 32 | /** |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 33 | * Represents a distinct method to place or receive a phone call. Apps which can place calls and |
| 34 | * 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] | 35 | * this class and register it with the system using {@link TelecomManager}. |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 36 | * <p> |
| 37 | * {@link TelecomManager} uses registered {@link PhoneAccount}s to present the user with |
| 38 | * 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] | 39 | * should supply a valid {@link PhoneAccountHandle} that references the connection service |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 40 | * implementation Telecom will use to interact with the app. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 41 | */ |
Yorke Lee | 400470f | 2015-05-12 13:31:25 -0700 | [diff] [blame] | 42 | public final class PhoneAccount implements Parcelable { |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 43 | |
| 44 | /** |
Tyler Gunn | d426b20 | 2015-10-13 13:33:53 -0700 | [diff] [blame] | 45 | * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the |
| 46 | * maximum permitted length of a call subject specified via the |
| 47 | * {@link TelecomManager#EXTRA_CALL_SUBJECT} extra on an |
| 48 | * {@link android.content.Intent#ACTION_CALL} intent. Ultimately a {@link ConnectionService} is |
| 49 | * responsible for enforcing the maximum call subject length when sending the message, however |
| 50 | * this extra is provided so that the user interface can proactively limit the length of the |
| 51 | * call subject as the user types it. |
| 52 | */ |
| 53 | public static final String EXTRA_CALL_SUBJECT_MAX_LENGTH = |
| 54 | "android.telecom.extra.CALL_SUBJECT_MAX_LENGTH"; |
| 55 | |
| 56 | /** |
| 57 | * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the |
| 58 | * character encoding to be used when determining the length of messages. |
| 59 | * The user interface can use this when determining the number of characters the user may type |
| 60 | * in a call subject. If empty-string, the call subject message size limit will be enforced on |
| 61 | * a 1:1 basis. That is, each character will count towards the messages size limit as a single |
| 62 | * character. If a character encoding is specified, the message size limit will be based on the |
| 63 | * number of bytes in the message per the specified encoding. See |
| 64 | * {@link #EXTRA_CALL_SUBJECT_MAX_LENGTH} for more information on the call subject maximum |
| 65 | * length. |
| 66 | */ |
| 67 | public static final String EXTRA_CALL_SUBJECT_CHARACTER_ENCODING = |
| 68 | "android.telecom.extra.CALL_SUBJECT_CHARACTER_ENCODING"; |
| 69 | |
| 70 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 71 | * Flag indicating that this {@code PhoneAccount} can act as a connection manager for |
| 72 | * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount} |
| 73 | * will be allowed to manage phone calls including using its own proprietary phone-call |
| 74 | * implementation (like VoIP calling) to make calls instead of the telephony stack. |
| 75 | * <p> |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 76 | * When a user opts to place a call using the SIM-based telephony stack, the |
| 77 | * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first |
| 78 | * 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] | 79 | * <p> |
| 80 | * See {@link #getCapabilities} |
| 81 | */ |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 82 | public static final int CAPABILITY_CONNECTION_MANAGER = 0x1; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 85 | * 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] | 86 | * traditional SIM-based telephony calls. This account will be treated as a distinct method |
| 87 | * 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] | 88 | * 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] | 89 | * or place calls from the built-in telephony stack. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 90 | * <p> |
| 91 | * See {@link #getCapabilities} |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 92 | * <p> |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 93 | */ |
| 94 | public static final int CAPABILITY_CALL_PROVIDER = 0x2; |
| 95 | |
Ihab Awad | 7522bbd | 2014-07-18 15:53:17 -0700 | [diff] [blame] | 96 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 97 | * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 98 | * subscription. |
Ihab Awad | 7522bbd | 2014-07-18 15:53:17 -0700 | [diff] [blame] | 99 | * <p> |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 100 | * Only the Android framework can register a {@code PhoneAccount} having this capability. |
| 101 | * <p> |
| 102 | * See {@link #getCapabilities} |
Ihab Awad | 7522bbd | 2014-07-18 15:53:17 -0700 | [diff] [blame] | 103 | */ |
| 104 | public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4; |
| 105 | |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 106 | /** |
Tyler Gunn | 58cbd7a | 2016-11-11 11:31:28 -0800 | [diff] [blame] | 107 | * Flag indicating that this {@code PhoneAccount} is currently able to place video calls. |
| 108 | * <p> |
| 109 | * See also {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING} which indicates whether the |
| 110 | * {@code PhoneAccount} supports placing video calls. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 111 | * <p> |
| 112 | * See {@link #getCapabilities} |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 113 | */ |
| 114 | public static final int CAPABILITY_VIDEO_CALLING = 0x8; |
| 115 | |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 116 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 117 | * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls. |
| 118 | * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls. |
| 119 | * <p> |
| 120 | * See {@link #getCapabilities} |
| 121 | */ |
| 122 | public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10; |
| 123 | |
| 124 | /** |
Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 125 | * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This |
| 126 | * should only be used by system apps (and will be ignored for all other apps trying to use it). |
| 127 | * <p> |
| 128 | * See {@link #getCapabilities} |
| 129 | * @hide |
| 130 | */ |
Brian Attwell | ad147f4 | 2014-12-19 11:37:16 -0800 | [diff] [blame] | 131 | @SystemApi |
Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 132 | public static final int CAPABILITY_MULTI_USER = 0x20; |
| 133 | |
| 134 | /** |
Tyler Gunn | 65a3d34 | 2015-07-27 16:06:16 -0700 | [diff] [blame] | 135 | * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a |
| 136 | * caller is able to specify a short subject line for an outgoing call. A capable receiving |
| 137 | * device displays the call subject on the incoming call screen. |
| 138 | * <p> |
| 139 | * See {@link #getCapabilities} |
| 140 | */ |
| 141 | public static final int CAPABILITY_CALL_SUBJECT = 0x40; |
| 142 | |
| 143 | /** |
Bryce Lee | b96d89c | 2015-10-14 16:48:40 -0700 | [diff] [blame] | 144 | * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls. |
| 145 | * <p> |
| 146 | * See {@link #getCapabilities} |
| 147 | * @hide |
| 148 | */ |
| 149 | public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80; |
| 150 | |
| 151 | /** |
Tyler Gunn | 9a36575 | 2015-12-09 15:00:18 -0800 | [diff] [blame] | 152 | * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a |
| 153 | * number relies on presence. Should only be set if the {@code PhoneAccount} also has |
| 154 | * {@link #CAPABILITY_VIDEO_CALLING}. |
| 155 | * <p> |
| 156 | * When set, the {@link ConnectionService} is responsible for toggling the |
| 157 | * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the |
| 158 | * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether |
| 159 | * a contact's phone number supports video calling. |
| 160 | * <p> |
| 161 | * See {@link #getCapabilities} |
| 162 | */ |
| 163 | public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100; |
| 164 | |
| 165 | /** |
Tyler Gunn | cee9ea6 | 2016-03-24 11:45:43 -0700 | [diff] [blame] | 166 | * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed. |
| 167 | * <p> |
| 168 | * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will |
| 169 | * convert all outgoing video calls to emergency numbers to audio-only. |
| 170 | * @hide |
| 171 | */ |
| 172 | public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200; |
| 173 | |
| 174 | /** |
Tyler Gunn | 58cbd7a | 2016-11-11 11:31:28 -0800 | [diff] [blame] | 175 | * Flag indicating that this {@link PhoneAccount} supports video calling. |
| 176 | * This is not an indication that the {@link PhoneAccount} is currently able to make a video |
| 177 | * call, but rather that it has the ability to make video calls (but not necessarily at this |
| 178 | * time). |
| 179 | * <p> |
| 180 | * Whether a {@link PhoneAccount} can make a video call is ultimately controlled by |
| 181 | * {@link #CAPABILITY_VIDEO_CALLING}, which indicates whether the {@link PhoneAccount} is |
| 182 | * currently capable of making a video call. Consider a case where, for example, a |
| 183 | * {@link PhoneAccount} supports making video calls (e.g. |
| 184 | * {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING}), but a current lack of network connectivity |
| 185 | * prevents video calls from being made (e.g. {@link #CAPABILITY_VIDEO_CALLING}). |
| 186 | * <p> |
| 187 | * See {@link #getCapabilities} |
| 188 | */ |
| 189 | public static final int CAPABILITY_SUPPORTS_VIDEO_CALLING = 0x400; |
| 190 | |
| 191 | /** |
Tyler Gunn | f503543 | 2017-01-09 09:43:12 -0800 | [diff] [blame] | 192 | * Flag indicating that this {@link PhoneAccount} is responsible for managing its own |
| 193 | * {@link Connection}s. This type of {@link PhoneAccount} is ideal for use with standalone |
| 194 | * calling apps which do not wish to use the default phone app for {@link Connection} UX, |
| 195 | * but which want to leverage the call and audio routing capabilities of the Telecom framework. |
| 196 | * <p> |
| 197 | * When set, {@link Connection}s created by the self-managed {@link ConnectionService} will not |
| 198 | * be surfaced to implementations of the {@link InCallService} API. Thus it is the |
| 199 | * responsibility of a self-managed {@link ConnectionService} to provide a user interface for |
| 200 | * its {@link Connection}s. |
| 201 | * <p> |
| 202 | * Self-managed {@link Connection}s will, however, be displayed on connected Bluetooth devices. |
| 203 | */ |
| 204 | public static final int CAPABILITY_SELF_MANAGED = 0x800; |
| 205 | |
| 206 | /** |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 207 | * URI scheme for telephone number URIs. |
| 208 | */ |
| 209 | public static final String SCHEME_TEL = "tel"; |
| 210 | |
| 211 | /** |
| 212 | * URI scheme for voicemail URIs. |
| 213 | */ |
| 214 | public static final String SCHEME_VOICEMAIL = "voicemail"; |
| 215 | |
| 216 | /** |
| 217 | * URI scheme for SIP URIs. |
| 218 | */ |
| 219 | public static final String SCHEME_SIP = "sip"; |
| 220 | |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 221 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 222 | * Indicating no icon tint is set. |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 223 | * @hide |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 224 | */ |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 225 | public static final int NO_ICON_TINT = 0; |
| 226 | |
| 227 | /** |
| 228 | * Indicating no hightlight color is set. |
| 229 | */ |
| 230 | public static final int NO_HIGHLIGHT_COLOR = 0; |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 231 | |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 232 | /** |
| 233 | * Indicating no resource ID is set. |
| 234 | */ |
| 235 | public static final int NO_RESOURCE_ID = -1; |
| 236 | |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 237 | private final PhoneAccountHandle mAccountHandle; |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 238 | private final Uri mAddress; |
| 239 | private final Uri mSubscriptionAddress; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 240 | private final int mCapabilities; |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 241 | private final int mHighlightColor; |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 242 | private final CharSequence mLabel; |
| 243 | private final CharSequence mShortDescription; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 244 | private final List<String> mSupportedUriSchemes; |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 245 | private final int mSupportedAudioRoutes; |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 246 | private final Icon mIcon; |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 247 | private final Bundle mExtras; |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 248 | private boolean mIsEnabled; |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 249 | private String mGroupId; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 250 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 251 | /** |
| 252 | * Helper class for creating a {@link PhoneAccount}. |
| 253 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 254 | public static class Builder { |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 255 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 256 | private PhoneAccountHandle mAccountHandle; |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 257 | private Uri mAddress; |
| 258 | private Uri mSubscriptionAddress; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 259 | private int mCapabilities; |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 260 | private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 261 | private int mHighlightColor = NO_HIGHLIGHT_COLOR; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 262 | private CharSequence mLabel; |
| 263 | private CharSequence mShortDescription; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 264 | private List<String> mSupportedUriSchemes = new ArrayList<String>(); |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 265 | private Icon mIcon; |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 266 | private Bundle mExtras; |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 267 | private boolean mIsEnabled = false; |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 268 | private String mGroupId = ""; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 269 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 270 | /** |
| 271 | * Creates a builder with the specified {@link PhoneAccountHandle} and label. |
| 272 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 273 | public Builder(PhoneAccountHandle accountHandle, CharSequence label) { |
| 274 | this.mAccountHandle = accountHandle; |
| 275 | this.mLabel = label; |
| 276 | } |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 277 | |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 278 | /** |
| 279 | * Creates an instance of the {@link PhoneAccount.Builder} from an existing |
| 280 | * {@link PhoneAccount}. |
| 281 | * |
| 282 | * @param phoneAccount The {@link PhoneAccount} used to initialize the builder. |
| 283 | */ |
| 284 | public Builder(PhoneAccount phoneAccount) { |
| 285 | mAccountHandle = phoneAccount.getAccountHandle(); |
| 286 | mAddress = phoneAccount.getAddress(); |
| 287 | mSubscriptionAddress = phoneAccount.getSubscriptionAddress(); |
| 288 | mCapabilities = phoneAccount.getCapabilities(); |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 289 | mHighlightColor = phoneAccount.getHighlightColor(); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 290 | mLabel = phoneAccount.getLabel(); |
| 291 | mShortDescription = phoneAccount.getShortDescription(); |
| 292 | mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes()); |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 293 | mIcon = phoneAccount.getIcon(); |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 294 | mIsEnabled = phoneAccount.isEnabled(); |
Tyler Gunn | d426b20 | 2015-10-13 13:33:53 -0700 | [diff] [blame] | 295 | mExtras = phoneAccount.getExtras(); |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 296 | mGroupId = phoneAccount.getGroupId(); |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 297 | mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes(); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 300 | /** |
| 301 | * Sets the address. See {@link PhoneAccount#getAddress}. |
| 302 | * |
| 303 | * @param value The address of the phone account. |
| 304 | * @return The builder. |
| 305 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 306 | public Builder setAddress(Uri value) { |
| 307 | this.mAddress = value; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 308 | return this; |
| 309 | } |
| 310 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 311 | /** |
| 312 | * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}. |
| 313 | * |
| 314 | * @param value The subscription address. |
| 315 | * @return The builder. |
| 316 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 317 | public Builder setSubscriptionAddress(Uri value) { |
| 318 | this.mSubscriptionAddress = value; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 319 | return this; |
| 320 | } |
| 321 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 322 | /** |
| 323 | * Sets the capabilities. See {@link PhoneAccount#getCapabilities}. |
| 324 | * |
| 325 | * @param value The capabilities to set. |
| 326 | * @return The builder. |
| 327 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 328 | public Builder setCapabilities(int value) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 329 | this.mCapabilities = value; |
| 330 | return this; |
| 331 | } |
| 332 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 333 | /** |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 334 | * Sets the icon. See {@link PhoneAccount#getIcon}. |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 335 | * |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 336 | * @param icon The icon to set. |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 337 | */ |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 338 | public Builder setIcon(Icon icon) { |
| 339 | mIcon = icon; |
Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 340 | return this; |
| 341 | } |
| 342 | |
| 343 | /** |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 344 | * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}. |
Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 345 | * |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 346 | * @param value The highlight color. |
Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 347 | * @return The builder. |
| 348 | */ |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 349 | public Builder setHighlightColor(int value) { |
| 350 | this.mHighlightColor = value; |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 351 | return this; |
| 352 | } |
| 353 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 354 | /** |
| 355 | * Sets the short description. See {@link PhoneAccount#getShortDescription}. |
| 356 | * |
| 357 | * @param value The short description. |
| 358 | * @return The builder. |
| 359 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 360 | public Builder setShortDescription(CharSequence value) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 361 | this.mShortDescription = value; |
| 362 | return this; |
| 363 | } |
| 364 | |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 365 | /** |
| 366 | * Specifies an additional URI scheme supported by the {@link PhoneAccount}. |
| 367 | * |
| 368 | * @param uriScheme The URI scheme. |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 369 | * @return The builder. |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 370 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 371 | public Builder addSupportedUriScheme(String uriScheme) { |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 372 | if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) { |
| 373 | this.mSupportedUriSchemes.add(uriScheme); |
| 374 | } |
| 375 | return this; |
| 376 | } |
| 377 | |
| 378 | /** |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 379 | * Specifies the URI schemes supported by the {@link PhoneAccount}. |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 380 | * |
| 381 | * @param uriSchemes The URI schemes. |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 382 | * @return The builder. |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 383 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 384 | public Builder setSupportedUriSchemes(List<String> uriSchemes) { |
| 385 | mSupportedUriSchemes.clear(); |
| 386 | |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 387 | if (uriSchemes != null && !uriSchemes.isEmpty()) { |
| 388 | for (String uriScheme : uriSchemes) { |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 389 | addSupportedUriScheme(uriScheme); |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 390 | } |
| 391 | } |
| 392 | return this; |
| 393 | } |
| 394 | |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 395 | /** |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 396 | * Specifies the extras associated with the {@link PhoneAccount}. |
| 397 | * <p> |
| 398 | * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer}, |
| 399 | * and {@link Boolean}. Extras which are not of these types are ignored. |
| 400 | * |
| 401 | * @param extras |
| 402 | * @return |
| 403 | */ |
| 404 | public Builder setExtras(Bundle extras) { |
| 405 | mExtras = extras; |
| 406 | return this; |
| 407 | } |
| 408 | |
| 409 | /** |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 410 | * Sets the enabled state of the phone account. |
| 411 | * |
| 412 | * @param isEnabled The enabled state. |
| 413 | * @return The builder. |
| 414 | * @hide |
| 415 | */ |
| 416 | public Builder setIsEnabled(boolean isEnabled) { |
| 417 | mIsEnabled = isEnabled; |
| 418 | return this; |
| 419 | } |
| 420 | |
| 421 | /** |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 422 | * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is |
| 423 | * registered to Telecom, it will replace another {@link PhoneAccount} that is already |
| 424 | * registered in Telecom and take on the current user defaults and enabled status. There can |
| 425 | * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a |
| 426 | * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only |
| 427 | * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced. |
| 428 | * @param groupId The group Id of the {@link PhoneAccount} that will replace any other |
| 429 | * registered {@link PhoneAccount} in Telecom with the same Group Id. |
| 430 | * @return The builder |
| 431 | * @hide |
| 432 | */ |
| 433 | public Builder setGroupId(String groupId) { |
| 434 | if (groupId != null) { |
| 435 | mGroupId = groupId; |
| 436 | } else { |
| 437 | mGroupId = ""; |
| 438 | } |
| 439 | return this; |
| 440 | } |
| 441 | |
| 442 | /** |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 443 | * Sets the audio routes supported by this {@link PhoneAccount}. |
| 444 | * |
| 445 | * @param routes bit mask of available routes. |
| 446 | * @return The builder. |
| 447 | * @hide |
| 448 | */ |
| 449 | public Builder setSupportedAudioRoutes(int routes) { |
| 450 | mSupportedAudioRoutes = routes; |
| 451 | return this; |
| 452 | } |
| 453 | |
| 454 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 455 | * Creates an instance of a {@link PhoneAccount} based on the current builder settings. |
| 456 | * |
| 457 | * @return The {@link PhoneAccount}. |
| 458 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 459 | public PhoneAccount build() { |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 460 | // If no supported URI schemes were defined, assume "tel" is supported. |
| 461 | if (mSupportedUriSchemes.isEmpty()) { |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 462 | addSupportedUriScheme(SCHEME_TEL); |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 465 | return new PhoneAccount( |
| 466 | mAccountHandle, |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 467 | mAddress, |
| 468 | mSubscriptionAddress, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 469 | mCapabilities, |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 470 | mIcon, |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 471 | mHighlightColor, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 472 | mLabel, |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 473 | mShortDescription, |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 474 | mSupportedUriSchemes, |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 475 | mExtras, |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 476 | mSupportedAudioRoutes, |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 477 | mIsEnabled, |
| 478 | mGroupId); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 479 | } |
| 480 | } |
| 481 | |
| 482 | private PhoneAccount( |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 483 | PhoneAccountHandle account, |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 484 | Uri address, |
| 485 | Uri subscriptionAddress, |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 486 | int capabilities, |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 487 | Icon icon, |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 488 | int highlightColor, |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 489 | CharSequence label, |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 490 | CharSequence shortDescription, |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 491 | List<String> supportedUriSchemes, |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 492 | Bundle extras, |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 493 | int supportedAudioRoutes, |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 494 | boolean isEnabled, |
| 495 | String groupId) { |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 496 | mAccountHandle = account; |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 497 | mAddress = address; |
| 498 | mSubscriptionAddress = subscriptionAddress; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 499 | mCapabilities = capabilities; |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 500 | mIcon = icon; |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 501 | mHighlightColor = highlightColor; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 502 | mLabel = label; |
| 503 | mShortDescription = shortDescription; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 504 | mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes); |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 505 | mExtras = extras; |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 506 | mSupportedAudioRoutes = supportedAudioRoutes; |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 507 | mIsEnabled = isEnabled; |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 508 | mGroupId = groupId; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 511 | public static Builder builder( |
| 512 | PhoneAccountHandle accountHandle, |
| 513 | CharSequence label) { |
| 514 | return new Builder(accountHandle, label); |
| 515 | } |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 516 | |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 517 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 518 | * Returns a builder initialized with the current {@link PhoneAccount} instance. |
| 519 | * |
| 520 | * @return The builder. |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 521 | */ |
| 522 | public Builder toBuilder() { return new Builder(this); } |
| 523 | |
| 524 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 525 | * The unique identifier of this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 526 | * |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 527 | * @return A {@code PhoneAccountHandle}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 528 | */ |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 529 | public PhoneAccountHandle getAccountHandle() { |
| 530 | return mAccountHandle; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | /** |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 534 | * 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] | 535 | * represents the destination from which outgoing calls using this {@code PhoneAccount} |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 536 | * 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] | 537 | * {@code PhoneAccount} may be addressed. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 538 | * |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 539 | * @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] | 540 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 541 | public Uri getAddress() { |
| 542 | return mAddress; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 546 | * The raw callback number used for this {@code PhoneAccount}, as distinct from |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 547 | * {@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] | 548 | * 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] | 549 | * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)} |
| 550 | * has been used to alter the callback number. |
| 551 | * <p> |
Evan Charlton | 222db525 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 552 | * |
| 553 | * @return The subscription number, suitable for display to the user. |
| 554 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 555 | public Uri getSubscriptionAddress() { |
| 556 | return mSubscriptionAddress; |
Evan Charlton | 222db525 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 560 | * The capabilities of this {@code PhoneAccount}. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 561 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 562 | * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 563 | */ |
| 564 | public int getCapabilities() { |
| 565 | return mCapabilities; |
| 566 | } |
| 567 | |
| 568 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 569 | * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in |
| 570 | * bit mask. |
| 571 | * |
| 572 | * @param capability The capabilities to check. |
Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 573 | * @return {@code true} if the phone account has the capability. |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 574 | */ |
| 575 | public boolean hasCapabilities(int capability) { |
| 576 | return (mCapabilities & capability) == capability; |
| 577 | } |
| 578 | |
| 579 | /** |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 580 | * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask. |
| 581 | * |
| 582 | * @param route The routes to check. |
| 583 | * @return {@code true} if the phone account has the routes. |
| 584 | * @hide |
| 585 | */ |
| 586 | public boolean hasAudioRoutes(int routes) { |
| 587 | return (mSupportedAudioRoutes & routes) == routes; |
| 588 | } |
| 589 | |
| 590 | /** |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 591 | * A short label describing a {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 592 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 593 | * @return A label for this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 594 | */ |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 595 | public CharSequence getLabel() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 596 | return mLabel; |
| 597 | } |
| 598 | |
| 599 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 600 | * A short paragraph describing this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 601 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 602 | * @return A description for this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 603 | */ |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 604 | public CharSequence getShortDescription() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 605 | return mShortDescription; |
| 606 | } |
| 607 | |
| 608 | /** |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 609 | * The URI schemes supported by this {@code PhoneAccount}. |
| 610 | * |
| 611 | * @return The URI schemes. |
| 612 | */ |
| 613 | public List<String> getSupportedUriSchemes() { |
| 614 | return mSupportedUriSchemes; |
| 615 | } |
| 616 | |
| 617 | /** |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 618 | * The extras associated with this {@code PhoneAccount}. |
| 619 | * <p> |
| 620 | * A {@link ConnectionService} may provide implementation specific information about the |
| 621 | * {@link PhoneAccount} via the extras. |
| 622 | * |
| 623 | * @return The extras. |
| 624 | */ |
| 625 | public Bundle getExtras() { |
| 626 | return mExtras; |
| 627 | } |
| 628 | |
| 629 | /** |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 630 | * The audio routes supported by this {@code PhoneAccount}. |
| 631 | * |
| 632 | * @hide |
| 633 | */ |
| 634 | public int getSupportedAudioRoutes() { |
| 635 | return mSupportedAudioRoutes; |
| 636 | } |
| 637 | |
| 638 | /** |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 639 | * The icon to represent this {@code PhoneAccount}. |
| 640 | * |
| 641 | * @return The icon. |
| 642 | */ |
| 643 | public Icon getIcon() { |
| 644 | return mIcon; |
| 645 | } |
| 646 | |
| 647 | /** |
Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 648 | * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only |
| 649 | * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}. |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 650 | * |
Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 651 | * @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] | 652 | */ |
| 653 | public boolean isEnabled() { |
| 654 | return mIsEnabled; |
| 655 | } |
| 656 | |
| 657 | /** |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 658 | * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an |
| 659 | * empty {@link String} if the {@link PhoneAccount} is not in a group. If this |
| 660 | * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered |
| 661 | * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced, |
| 662 | * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}. |
| 663 | * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced. |
| 664 | * |
| 665 | * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group. |
| 666 | * @hide |
| 667 | */ |
| 668 | public String getGroupId() { |
| 669 | return mGroupId; |
| 670 | } |
| 671 | |
| 672 | /** |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 673 | * 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] | 674 | * scheme. |
| 675 | * |
| 676 | * @param uriScheme The URI scheme to check. |
Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 677 | * @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] | 678 | * specified URI scheme. |
| 679 | */ |
| 680 | public boolean supportsUriScheme(String uriScheme) { |
| 681 | if (mSupportedUriSchemes == null || uriScheme == null) { |
| 682 | return false; |
| 683 | } |
| 684 | |
| 685 | for (String scheme : mSupportedUriSchemes) { |
| 686 | if (scheme != null && scheme.equals(uriScheme)) { |
| 687 | return true; |
| 688 | } |
| 689 | } |
| 690 | return false; |
| 691 | } |
| 692 | |
| 693 | /** |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 694 | * A highlight color to use in displaying information about this {@code PhoneAccount}. |
| 695 | * |
| 696 | * @return A hexadecimal color value. |
| 697 | */ |
| 698 | public int getHighlightColor() { |
| 699 | return mHighlightColor; |
| 700 | } |
| 701 | |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 702 | /** |
| 703 | * Sets the enabled state of the phone account. |
| 704 | * @hide |
| 705 | */ |
| 706 | public void setIsEnabled(boolean isEnabled) { |
| 707 | mIsEnabled = isEnabled; |
| 708 | } |
| 709 | |
Tyler Gunn | f503543 | 2017-01-09 09:43:12 -0800 | [diff] [blame] | 710 | /** |
| 711 | * @return {@code true} if the {@link PhoneAccount} is self-managed, {@code false} otherwise. |
| 712 | * @hide |
| 713 | */ |
| 714 | public boolean isSelfManaged() { |
| 715 | return (mCapabilities & CAPABILITY_SELF_MANAGED) == CAPABILITY_SELF_MANAGED; |
| 716 | } |
| 717 | |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 718 | // |
| 719 | // Parcelable implementation |
| 720 | // |
| 721 | |
| 722 | @Override |
| 723 | public int describeContents() { |
| 724 | return 0; |
| 725 | } |
| 726 | |
| 727 | @Override |
| 728 | public void writeToParcel(Parcel out, int flags) { |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 729 | if (mAccountHandle == null) { |
| 730 | out.writeInt(0); |
| 731 | } else { |
| 732 | out.writeInt(1); |
| 733 | mAccountHandle.writeToParcel(out, flags); |
| 734 | } |
| 735 | if (mAddress == null) { |
| 736 | out.writeInt(0); |
| 737 | } else { |
| 738 | out.writeInt(1); |
| 739 | mAddress.writeToParcel(out, flags); |
| 740 | } |
| 741 | if (mSubscriptionAddress == null) { |
| 742 | out.writeInt(0); |
| 743 | } else { |
| 744 | out.writeInt(1); |
| 745 | mSubscriptionAddress.writeToParcel(out, flags); |
| 746 | } |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 747 | out.writeInt(mCapabilities); |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 748 | out.writeInt(mHighlightColor); |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 749 | out.writeCharSequence(mLabel); |
| 750 | out.writeCharSequence(mShortDescription); |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 751 | out.writeStringList(mSupportedUriSchemes); |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 752 | |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 753 | if (mIcon == null) { |
| 754 | out.writeInt(0); |
| 755 | } else { |
| 756 | out.writeInt(1); |
| 757 | mIcon.writeToParcel(out, flags); |
| 758 | } |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 759 | out.writeByte((byte) (mIsEnabled ? 1 : 0)); |
Tyler Gunn | ef829ec | 2015-10-08 09:46:23 -0700 | [diff] [blame] | 760 | out.writeBundle(mExtras); |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 761 | out.writeString(mGroupId); |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 762 | out.writeInt(mSupportedAudioRoutes); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 763 | } |
| 764 | |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 765 | public static final Creator<PhoneAccount> CREATOR |
| 766 | = new Creator<PhoneAccount>() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 767 | @Override |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 768 | public PhoneAccount createFromParcel(Parcel in) { |
| 769 | return new PhoneAccount(in); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | @Override |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 773 | public PhoneAccount[] newArray(int size) { |
| 774 | return new PhoneAccount[size]; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 775 | } |
| 776 | }; |
| 777 | |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 778 | private PhoneAccount(Parcel in) { |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 779 | if (in.readInt() > 0) { |
| 780 | mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in); |
| 781 | } else { |
| 782 | mAccountHandle = null; |
| 783 | } |
| 784 | if (in.readInt() > 0) { |
| 785 | mAddress = Uri.CREATOR.createFromParcel(in); |
| 786 | } else { |
| 787 | mAddress = null; |
| 788 | } |
| 789 | if (in.readInt() > 0) { |
| 790 | mSubscriptionAddress = Uri.CREATOR.createFromParcel(in); |
| 791 | } else { |
| 792 | mSubscriptionAddress = null; |
| 793 | } |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 794 | mCapabilities = in.readInt(); |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 795 | mHighlightColor = in.readInt(); |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 796 | mLabel = in.readCharSequence(); |
| 797 | mShortDescription = in.readCharSequence(); |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 798 | mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList()); |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 799 | if (in.readInt() > 0) { |
| 800 | mIcon = Icon.CREATOR.createFromParcel(in); |
| 801 | } else { |
| 802 | mIcon = null; |
| 803 | } |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 804 | mIsEnabled = in.readByte() == 1; |
Tyler Gunn | ef829ec | 2015-10-08 09:46:23 -0700 | [diff] [blame] | 805 | mExtras = in.readBundle(); |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 806 | mGroupId = in.readString(); |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 807 | mSupportedAudioRoutes = in.readInt(); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 808 | } |
Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 809 | |
| 810 | @Override |
| 811 | public String toString() { |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 812 | StringBuilder sb = new StringBuilder().append("[[") |
| 813 | .append(mIsEnabled ? 'X' : ' ') |
| 814 | .append("] PhoneAccount: ") |
Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 815 | .append(mAccountHandle) |
| 816 | .append(" Capabilities: ") |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 817 | .append(capabilitiesToString()) |
| 818 | .append(" Audio Routes: ") |
| 819 | .append(audioRoutesToString()) |
Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 820 | .append(" Schemes: "); |
| 821 | for (String scheme : mSupportedUriSchemes) { |
| 822 | sb.append(scheme) |
| 823 | .append(" "); |
| 824 | } |
Tyler Gunn | ef829ec | 2015-10-08 09:46:23 -0700 | [diff] [blame] | 825 | sb.append(" Extras: "); |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 826 | sb.append(mExtras); |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 827 | sb.append(" GroupId: "); |
| 828 | sb.append(Log.pii(mGroupId)); |
Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 829 | sb.append("]"); |
| 830 | return sb.toString(); |
| 831 | } |
Tyler Gunn | 3e122f7 | 2016-01-11 19:25:00 -0800 | [diff] [blame] | 832 | |
| 833 | /** |
| 834 | * Generates a string representation of a capabilities bitmask. |
| 835 | * |
| 836 | * @param capabilities The capabilities bitmask. |
| 837 | * @return String representation of the capabilities bitmask. |
| 838 | */ |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 839 | private String capabilitiesToString() { |
Tyler Gunn | 3e122f7 | 2016-01-11 19:25:00 -0800 | [diff] [blame] | 840 | StringBuilder sb = new StringBuilder(); |
Tyler Gunn | f503543 | 2017-01-09 09:43:12 -0800 | [diff] [blame] | 841 | if (hasCapabilities(CAPABILITY_SELF_MANAGED)) { |
| 842 | sb.append("SelfManaged "); |
| 843 | } |
Tyler Gunn | 58cbd7a | 2016-11-11 11:31:28 -0800 | [diff] [blame] | 844 | if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) { |
| 845 | sb.append("SuppVideo "); |
| 846 | } |
Tyler Gunn | 3e122f7 | 2016-01-11 19:25:00 -0800 | [diff] [blame] | 847 | if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) { |
| 848 | sb.append("Video "); |
| 849 | } |
| 850 | if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) { |
| 851 | sb.append("Presence "); |
| 852 | } |
| 853 | if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) { |
| 854 | sb.append("CallProvider "); |
| 855 | } |
| 856 | if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) { |
| 857 | sb.append("CallSubject "); |
| 858 | } |
| 859 | if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) { |
| 860 | sb.append("ConnectionMgr "); |
| 861 | } |
| 862 | if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) { |
| 863 | sb.append("EmergOnly "); |
| 864 | } |
| 865 | if (hasCapabilities(CAPABILITY_MULTI_USER)) { |
| 866 | sb.append("MultiUser "); |
| 867 | } |
| 868 | if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) { |
| 869 | sb.append("PlaceEmerg "); |
| 870 | } |
Tyler Gunn | cee9ea6 | 2016-03-24 11:45:43 -0700 | [diff] [blame] | 871 | if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) { |
| 872 | sb.append("EmergVideo "); |
| 873 | } |
Tyler Gunn | 3e122f7 | 2016-01-11 19:25:00 -0800 | [diff] [blame] | 874 | if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) { |
| 875 | sb.append("SimSub "); |
| 876 | } |
| 877 | return sb.toString(); |
| 878 | } |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 879 | |
| 880 | private String audioRoutesToString() { |
| 881 | StringBuilder sb = new StringBuilder(); |
| 882 | |
| 883 | if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) { |
| 884 | sb.append("B"); |
| 885 | } |
| 886 | if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) { |
| 887 | sb.append("E"); |
| 888 | } |
| 889 | if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) { |
| 890 | sb.append("S"); |
| 891 | } |
| 892 | if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) { |
| 893 | sb.append("W"); |
| 894 | } |
| 895 | |
| 896 | return sb.toString(); |
| 897 | } |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 898 | } |