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