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 | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 192 | * URI scheme for telephone number URIs. |
| 193 | */ |
| 194 | public static final String SCHEME_TEL = "tel"; |
| 195 | |
| 196 | /** |
| 197 | * URI scheme for voicemail URIs. |
| 198 | */ |
| 199 | public static final String SCHEME_VOICEMAIL = "voicemail"; |
| 200 | |
| 201 | /** |
| 202 | * URI scheme for SIP URIs. |
| 203 | */ |
| 204 | public static final String SCHEME_SIP = "sip"; |
| 205 | |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 206 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 207 | * Indicating no icon tint is set. |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 208 | * @hide |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 209 | */ |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 210 | public static final int NO_ICON_TINT = 0; |
| 211 | |
| 212 | /** |
| 213 | * Indicating no hightlight color is set. |
| 214 | */ |
| 215 | public static final int NO_HIGHLIGHT_COLOR = 0; |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 216 | |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 217 | /** |
| 218 | * Indicating no resource ID is set. |
| 219 | */ |
| 220 | public static final int NO_RESOURCE_ID = -1; |
| 221 | |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 222 | private final PhoneAccountHandle mAccountHandle; |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 223 | private final Uri mAddress; |
| 224 | private final Uri mSubscriptionAddress; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 225 | private final int mCapabilities; |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 226 | private final int mHighlightColor; |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 227 | private final CharSequence mLabel; |
| 228 | private final CharSequence mShortDescription; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 229 | private final List<String> mSupportedUriSchemes; |
Christine Hallstrom | 4e22d6d | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 230 | private final int mSupportedAudioRoutes; |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 231 | private final Icon mIcon; |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 232 | private final Bundle mExtras; |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 233 | private boolean mIsEnabled; |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 234 | private String mGroupId; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 235 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 236 | /** |
| 237 | * Helper class for creating a {@link PhoneAccount}. |
| 238 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 239 | public static class Builder { |
Christine Hallstrom | 4e22d6d | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 240 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 241 | private PhoneAccountHandle mAccountHandle; |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 242 | private Uri mAddress; |
| 243 | private Uri mSubscriptionAddress; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 244 | private int mCapabilities; |
Christine Hallstrom | 4e22d6d | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 245 | private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 246 | private int mHighlightColor = NO_HIGHLIGHT_COLOR; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 247 | private CharSequence mLabel; |
| 248 | private CharSequence mShortDescription; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 249 | private List<String> mSupportedUriSchemes = new ArrayList<String>(); |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 250 | private Icon mIcon; |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 251 | private Bundle mExtras; |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 252 | private boolean mIsEnabled = false; |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 253 | private String mGroupId = ""; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 254 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 255 | /** |
| 256 | * Creates a builder with the specified {@link PhoneAccountHandle} and label. |
| 257 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 258 | public Builder(PhoneAccountHandle accountHandle, CharSequence label) { |
| 259 | this.mAccountHandle = accountHandle; |
| 260 | this.mLabel = label; |
| 261 | } |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 262 | |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 263 | /** |
| 264 | * Creates an instance of the {@link PhoneAccount.Builder} from an existing |
| 265 | * {@link PhoneAccount}. |
| 266 | * |
| 267 | * @param phoneAccount The {@link PhoneAccount} used to initialize the builder. |
| 268 | */ |
| 269 | public Builder(PhoneAccount phoneAccount) { |
| 270 | mAccountHandle = phoneAccount.getAccountHandle(); |
| 271 | mAddress = phoneAccount.getAddress(); |
| 272 | mSubscriptionAddress = phoneAccount.getSubscriptionAddress(); |
| 273 | mCapabilities = phoneAccount.getCapabilities(); |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 274 | mHighlightColor = phoneAccount.getHighlightColor(); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 275 | mLabel = phoneAccount.getLabel(); |
| 276 | mShortDescription = phoneAccount.getShortDescription(); |
| 277 | mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes()); |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 278 | mIcon = phoneAccount.getIcon(); |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 279 | mIsEnabled = phoneAccount.isEnabled(); |
Tyler Gunn | d426b20 | 2015-10-13 13:33:53 -0700 | [diff] [blame] | 280 | mExtras = phoneAccount.getExtras(); |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 281 | mGroupId = phoneAccount.getGroupId(); |
Christine Hallstrom | 4e22d6d | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 282 | mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes(); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 285 | /** |
| 286 | * Sets the address. See {@link PhoneAccount#getAddress}. |
| 287 | * |
| 288 | * @param value The address of the phone account. |
| 289 | * @return The builder. |
| 290 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 291 | public Builder setAddress(Uri value) { |
| 292 | this.mAddress = value; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 293 | return this; |
| 294 | } |
| 295 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 296 | /** |
| 297 | * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}. |
| 298 | * |
| 299 | * @param value The subscription address. |
| 300 | * @return The builder. |
| 301 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 302 | public Builder setSubscriptionAddress(Uri value) { |
| 303 | this.mSubscriptionAddress = value; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 304 | return this; |
| 305 | } |
| 306 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 307 | /** |
| 308 | * Sets the capabilities. See {@link PhoneAccount#getCapabilities}. |
| 309 | * |
| 310 | * @param value The capabilities to set. |
| 311 | * @return The builder. |
| 312 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 313 | public Builder setCapabilities(int value) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 314 | this.mCapabilities = value; |
| 315 | return this; |
| 316 | } |
| 317 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 318 | /** |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 319 | * Sets the icon. See {@link PhoneAccount#getIcon}. |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 320 | * |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 321 | * @param icon The icon to set. |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 322 | */ |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 323 | public Builder setIcon(Icon icon) { |
| 324 | mIcon = icon; |
Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 325 | return this; |
| 326 | } |
| 327 | |
| 328 | /** |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 329 | * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}. |
Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 330 | * |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 331 | * @param value The highlight color. |
Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 332 | * @return The builder. |
| 333 | */ |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 334 | public Builder setHighlightColor(int value) { |
| 335 | this.mHighlightColor = value; |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 336 | return this; |
| 337 | } |
| 338 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 339 | /** |
| 340 | * Sets the short description. See {@link PhoneAccount#getShortDescription}. |
| 341 | * |
| 342 | * @param value The short description. |
| 343 | * @return The builder. |
| 344 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 345 | public Builder setShortDescription(CharSequence value) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 346 | this.mShortDescription = value; |
| 347 | return this; |
| 348 | } |
| 349 | |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 350 | /** |
| 351 | * Specifies an additional URI scheme supported by the {@link PhoneAccount}. |
| 352 | * |
| 353 | * @param uriScheme The URI scheme. |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 354 | * @return The builder. |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 355 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 356 | public Builder addSupportedUriScheme(String uriScheme) { |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 357 | if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) { |
| 358 | this.mSupportedUriSchemes.add(uriScheme); |
| 359 | } |
| 360 | return this; |
| 361 | } |
| 362 | |
| 363 | /** |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 364 | * Specifies the URI schemes supported by the {@link PhoneAccount}. |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 365 | * |
| 366 | * @param uriSchemes The URI schemes. |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 367 | * @return The builder. |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 368 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 369 | public Builder setSupportedUriSchemes(List<String> uriSchemes) { |
| 370 | mSupportedUriSchemes.clear(); |
| 371 | |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 372 | if (uriSchemes != null && !uriSchemes.isEmpty()) { |
| 373 | for (String uriScheme : uriSchemes) { |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 374 | addSupportedUriScheme(uriScheme); |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 375 | } |
| 376 | } |
| 377 | return this; |
| 378 | } |
| 379 | |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 380 | /** |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 381 | * Specifies the extras associated with the {@link PhoneAccount}. |
| 382 | * <p> |
| 383 | * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer}, |
| 384 | * and {@link Boolean}. Extras which are not of these types are ignored. |
| 385 | * |
| 386 | * @param extras |
| 387 | * @return |
| 388 | */ |
| 389 | public Builder setExtras(Bundle extras) { |
| 390 | mExtras = extras; |
| 391 | return this; |
| 392 | } |
| 393 | |
| 394 | /** |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 395 | * Sets the enabled state of the phone account. |
| 396 | * |
| 397 | * @param isEnabled The enabled state. |
| 398 | * @return The builder. |
| 399 | * @hide |
| 400 | */ |
| 401 | public Builder setIsEnabled(boolean isEnabled) { |
| 402 | mIsEnabled = isEnabled; |
| 403 | return this; |
| 404 | } |
| 405 | |
| 406 | /** |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 407 | * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is |
| 408 | * registered to Telecom, it will replace another {@link PhoneAccount} that is already |
| 409 | * registered in Telecom and take on the current user defaults and enabled status. There can |
| 410 | * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a |
| 411 | * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only |
| 412 | * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced. |
| 413 | * @param groupId The group Id of the {@link PhoneAccount} that will replace any other |
| 414 | * registered {@link PhoneAccount} in Telecom with the same Group Id. |
| 415 | * @return The builder |
| 416 | * @hide |
| 417 | */ |
| 418 | public Builder setGroupId(String groupId) { |
| 419 | if (groupId != null) { |
| 420 | mGroupId = groupId; |
| 421 | } else { |
| 422 | mGroupId = ""; |
| 423 | } |
| 424 | return this; |
| 425 | } |
| 426 | |
| 427 | /** |
Christine Hallstrom | 4e22d6d | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 428 | * Sets the audio routes supported by this {@link PhoneAccount}. |
| 429 | * |
| 430 | * @param routes bit mask of available routes. |
| 431 | * @return The builder. |
| 432 | * @hide |
| 433 | */ |
| 434 | public Builder setSupportedAudioRoutes(int routes) { |
| 435 | mSupportedAudioRoutes = routes; |
| 436 | return this; |
| 437 | } |
| 438 | |
| 439 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 440 | * Creates an instance of a {@link PhoneAccount} based on the current builder settings. |
| 441 | * |
| 442 | * @return The {@link PhoneAccount}. |
| 443 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 444 | public PhoneAccount build() { |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 445 | // If no supported URI schemes were defined, assume "tel" is supported. |
| 446 | if (mSupportedUriSchemes.isEmpty()) { |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 447 | addSupportedUriScheme(SCHEME_TEL); |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 450 | return new PhoneAccount( |
| 451 | mAccountHandle, |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 452 | mAddress, |
| 453 | mSubscriptionAddress, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 454 | mCapabilities, |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 455 | mIcon, |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 456 | mHighlightColor, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 457 | mLabel, |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 458 | mShortDescription, |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 459 | mSupportedUriSchemes, |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 460 | mExtras, |
Christine Hallstrom | 4e22d6d | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 461 | mSupportedAudioRoutes, |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 462 | mIsEnabled, |
| 463 | mGroupId); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 464 | } |
| 465 | } |
| 466 | |
| 467 | private PhoneAccount( |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 468 | PhoneAccountHandle account, |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 469 | Uri address, |
| 470 | Uri subscriptionAddress, |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 471 | int capabilities, |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 472 | Icon icon, |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 473 | int highlightColor, |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 474 | CharSequence label, |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 475 | CharSequence shortDescription, |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 476 | List<String> supportedUriSchemes, |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 477 | Bundle extras, |
Christine Hallstrom | 4e22d6d | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 478 | int supportedAudioRoutes, |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 479 | boolean isEnabled, |
| 480 | String groupId) { |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 481 | mAccountHandle = account; |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 482 | mAddress = address; |
| 483 | mSubscriptionAddress = subscriptionAddress; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 484 | mCapabilities = capabilities; |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 485 | mIcon = icon; |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 486 | mHighlightColor = highlightColor; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 487 | mLabel = label; |
| 488 | mShortDescription = shortDescription; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 489 | mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes); |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 490 | mExtras = extras; |
Christine Hallstrom | 4e22d6d | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 491 | mSupportedAudioRoutes = supportedAudioRoutes; |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 492 | mIsEnabled = isEnabled; |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 493 | mGroupId = groupId; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 496 | public static Builder builder( |
| 497 | PhoneAccountHandle accountHandle, |
| 498 | CharSequence label) { |
| 499 | return new Builder(accountHandle, label); |
| 500 | } |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 501 | |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 502 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 503 | * Returns a builder initialized with the current {@link PhoneAccount} instance. |
| 504 | * |
| 505 | * @return The builder. |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 506 | */ |
| 507 | public Builder toBuilder() { return new Builder(this); } |
| 508 | |
| 509 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 510 | * The unique identifier of this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 511 | * |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 512 | * @return A {@code PhoneAccountHandle}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 513 | */ |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 514 | public PhoneAccountHandle getAccountHandle() { |
| 515 | return mAccountHandle; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | /** |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 519 | * 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] | 520 | * represents the destination from which outgoing calls using this {@code PhoneAccount} |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 521 | * 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] | 522 | * {@code PhoneAccount} may be addressed. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 523 | * |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 524 | * @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] | 525 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 526 | public Uri getAddress() { |
| 527 | return mAddress; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 531 | * The raw callback number used for this {@code PhoneAccount}, as distinct from |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 532 | * {@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] | 533 | * 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] | 534 | * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)} |
| 535 | * has been used to alter the callback number. |
| 536 | * <p> |
Evan Charlton | 222db525 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 537 | * |
| 538 | * @return The subscription number, suitable for display to the user. |
| 539 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 540 | public Uri getSubscriptionAddress() { |
| 541 | return mSubscriptionAddress; |
Evan Charlton | 222db525 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 545 | * The capabilities of this {@code PhoneAccount}. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 546 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 547 | * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 548 | */ |
| 549 | public int getCapabilities() { |
| 550 | return mCapabilities; |
| 551 | } |
| 552 | |
| 553 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 554 | * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in |
| 555 | * bit mask. |
| 556 | * |
| 557 | * @param capability The capabilities to check. |
Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 558 | * @return {@code true} if the phone account has the capability. |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 559 | */ |
| 560 | public boolean hasCapabilities(int capability) { |
| 561 | return (mCapabilities & capability) == capability; |
| 562 | } |
| 563 | |
| 564 | /** |
Christine Hallstrom | 4e22d6d | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 565 | * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask. |
| 566 | * |
| 567 | * @param route The routes to check. |
| 568 | * @return {@code true} if the phone account has the routes. |
| 569 | * @hide |
| 570 | */ |
| 571 | public boolean hasAudioRoutes(int routes) { |
| 572 | return (mSupportedAudioRoutes & routes) == routes; |
| 573 | } |
| 574 | |
| 575 | /** |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 576 | * A short label describing a {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 577 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 578 | * @return A label for this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 579 | */ |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 580 | public CharSequence getLabel() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 581 | return mLabel; |
| 582 | } |
| 583 | |
| 584 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 585 | * A short paragraph describing this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 586 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 587 | * @return A description for this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 588 | */ |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 589 | public CharSequence getShortDescription() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 590 | return mShortDescription; |
| 591 | } |
| 592 | |
| 593 | /** |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 594 | * The URI schemes supported by this {@code PhoneAccount}. |
| 595 | * |
| 596 | * @return The URI schemes. |
| 597 | */ |
| 598 | public List<String> getSupportedUriSchemes() { |
| 599 | return mSupportedUriSchemes; |
| 600 | } |
| 601 | |
| 602 | /** |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 603 | * The extras associated with this {@code PhoneAccount}. |
| 604 | * <p> |
| 605 | * A {@link ConnectionService} may provide implementation specific information about the |
| 606 | * {@link PhoneAccount} via the extras. |
| 607 | * |
| 608 | * @return The extras. |
| 609 | */ |
| 610 | public Bundle getExtras() { |
| 611 | return mExtras; |
| 612 | } |
| 613 | |
| 614 | /** |
Christine Hallstrom | 4e22d6d | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 615 | * The audio routes supported by this {@code PhoneAccount}. |
| 616 | * |
| 617 | * @hide |
| 618 | */ |
| 619 | public int getSupportedAudioRoutes() { |
| 620 | return mSupportedAudioRoutes; |
| 621 | } |
| 622 | |
| 623 | /** |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 624 | * The icon to represent this {@code PhoneAccount}. |
| 625 | * |
| 626 | * @return The icon. |
| 627 | */ |
| 628 | public Icon getIcon() { |
| 629 | return mIcon; |
| 630 | } |
| 631 | |
| 632 | /** |
Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 633 | * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only |
| 634 | * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}. |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 635 | * |
Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 636 | * @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] | 637 | */ |
| 638 | public boolean isEnabled() { |
| 639 | return mIsEnabled; |
| 640 | } |
| 641 | |
| 642 | /** |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 643 | * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an |
| 644 | * empty {@link String} if the {@link PhoneAccount} is not in a group. If this |
| 645 | * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered |
| 646 | * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced, |
| 647 | * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}. |
| 648 | * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced. |
| 649 | * |
| 650 | * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group. |
| 651 | * @hide |
| 652 | */ |
| 653 | public String getGroupId() { |
| 654 | return mGroupId; |
| 655 | } |
| 656 | |
| 657 | /** |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 658 | * 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] | 659 | * scheme. |
| 660 | * |
| 661 | * @param uriScheme The URI scheme to check. |
Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 662 | * @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] | 663 | * specified URI scheme. |
| 664 | */ |
| 665 | public boolean supportsUriScheme(String uriScheme) { |
| 666 | if (mSupportedUriSchemes == null || uriScheme == null) { |
| 667 | return false; |
| 668 | } |
| 669 | |
| 670 | for (String scheme : mSupportedUriSchemes) { |
| 671 | if (scheme != null && scheme.equals(uriScheme)) { |
| 672 | return true; |
| 673 | } |
| 674 | } |
| 675 | return false; |
| 676 | } |
| 677 | |
| 678 | /** |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 679 | * A highlight color to use in displaying information about this {@code PhoneAccount}. |
| 680 | * |
| 681 | * @return A hexadecimal color value. |
| 682 | */ |
| 683 | public int getHighlightColor() { |
| 684 | return mHighlightColor; |
| 685 | } |
| 686 | |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 687 | /** |
| 688 | * Sets the enabled state of the phone account. |
| 689 | * @hide |
| 690 | */ |
| 691 | public void setIsEnabled(boolean isEnabled) { |
| 692 | mIsEnabled = isEnabled; |
| 693 | } |
| 694 | |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 695 | // |
| 696 | // Parcelable implementation |
| 697 | // |
| 698 | |
| 699 | @Override |
| 700 | public int describeContents() { |
| 701 | return 0; |
| 702 | } |
| 703 | |
| 704 | @Override |
| 705 | public void writeToParcel(Parcel out, int flags) { |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 706 | if (mAccountHandle == null) { |
| 707 | out.writeInt(0); |
| 708 | } else { |
| 709 | out.writeInt(1); |
| 710 | mAccountHandle.writeToParcel(out, flags); |
| 711 | } |
| 712 | if (mAddress == null) { |
| 713 | out.writeInt(0); |
| 714 | } else { |
| 715 | out.writeInt(1); |
| 716 | mAddress.writeToParcel(out, flags); |
| 717 | } |
| 718 | if (mSubscriptionAddress == null) { |
| 719 | out.writeInt(0); |
| 720 | } else { |
| 721 | out.writeInt(1); |
| 722 | mSubscriptionAddress.writeToParcel(out, flags); |
| 723 | } |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 724 | out.writeInt(mCapabilities); |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 725 | out.writeInt(mHighlightColor); |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 726 | out.writeCharSequence(mLabel); |
| 727 | out.writeCharSequence(mShortDescription); |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 728 | out.writeStringList(mSupportedUriSchemes); |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 729 | |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 730 | if (mIcon == null) { |
| 731 | out.writeInt(0); |
| 732 | } else { |
| 733 | out.writeInt(1); |
| 734 | mIcon.writeToParcel(out, flags); |
| 735 | } |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 736 | out.writeByte((byte) (mIsEnabled ? 1 : 0)); |
Tyler Gunn | ef829ec | 2015-10-08 09:46:23 -0700 | [diff] [blame] | 737 | out.writeBundle(mExtras); |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 738 | out.writeString(mGroupId); |
Christine Hallstrom | 4e22d6d | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 739 | out.writeInt(mSupportedAudioRoutes); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 740 | } |
| 741 | |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 742 | public static final Creator<PhoneAccount> CREATOR |
| 743 | = new Creator<PhoneAccount>() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 744 | @Override |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 745 | public PhoneAccount createFromParcel(Parcel in) { |
| 746 | return new PhoneAccount(in); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | @Override |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 750 | public PhoneAccount[] newArray(int size) { |
| 751 | return new PhoneAccount[size]; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 752 | } |
| 753 | }; |
| 754 | |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 755 | private PhoneAccount(Parcel in) { |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 756 | if (in.readInt() > 0) { |
| 757 | mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in); |
| 758 | } else { |
| 759 | mAccountHandle = null; |
| 760 | } |
| 761 | if (in.readInt() > 0) { |
| 762 | mAddress = Uri.CREATOR.createFromParcel(in); |
| 763 | } else { |
| 764 | mAddress = null; |
| 765 | } |
| 766 | if (in.readInt() > 0) { |
| 767 | mSubscriptionAddress = Uri.CREATOR.createFromParcel(in); |
| 768 | } else { |
| 769 | mSubscriptionAddress = null; |
| 770 | } |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 771 | mCapabilities = in.readInt(); |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 772 | mHighlightColor = in.readInt(); |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 773 | mLabel = in.readCharSequence(); |
| 774 | mShortDescription = in.readCharSequence(); |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 775 | mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList()); |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 776 | if (in.readInt() > 0) { |
| 777 | mIcon = Icon.CREATOR.createFromParcel(in); |
| 778 | } else { |
| 779 | mIcon = null; |
| 780 | } |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 781 | mIsEnabled = in.readByte() == 1; |
Tyler Gunn | ef829ec | 2015-10-08 09:46:23 -0700 | [diff] [blame] | 782 | mExtras = in.readBundle(); |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 783 | mGroupId = in.readString(); |
Christine Hallstrom | 4e22d6d | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 784 | mSupportedAudioRoutes = in.readInt(); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 785 | } |
Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 786 | |
| 787 | @Override |
| 788 | public String toString() { |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 789 | StringBuilder sb = new StringBuilder().append("[[") |
| 790 | .append(mIsEnabled ? 'X' : ' ') |
| 791 | .append("] PhoneAccount: ") |
Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 792 | .append(mAccountHandle) |
| 793 | .append(" Capabilities: ") |
Christine Hallstrom | 4e22d6d | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 794 | .append(capabilitiesToString()) |
| 795 | .append(" Audio Routes: ") |
| 796 | .append(audioRoutesToString()) |
Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 797 | .append(" Schemes: "); |
| 798 | for (String scheme : mSupportedUriSchemes) { |
| 799 | sb.append(scheme) |
| 800 | .append(" "); |
| 801 | } |
Tyler Gunn | ef829ec | 2015-10-08 09:46:23 -0700 | [diff] [blame] | 802 | sb.append(" Extras: "); |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 803 | sb.append(mExtras); |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 804 | sb.append(" GroupId: "); |
| 805 | sb.append(Log.pii(mGroupId)); |
Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 806 | sb.append("]"); |
| 807 | return sb.toString(); |
| 808 | } |
Tyler Gunn | 3e122f7 | 2016-01-11 19:25:00 -0800 | [diff] [blame] | 809 | |
| 810 | /** |
| 811 | * Generates a string representation of a capabilities bitmask. |
| 812 | * |
| 813 | * @param capabilities The capabilities bitmask. |
| 814 | * @return String representation of the capabilities bitmask. |
| 815 | */ |
Christine Hallstrom | 4e22d6d | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 816 | private String capabilitiesToString() { |
Tyler Gunn | 3e122f7 | 2016-01-11 19:25:00 -0800 | [diff] [blame] | 817 | StringBuilder sb = new StringBuilder(); |
Tyler Gunn | 58cbd7a | 2016-11-11 11:31:28 -0800 | [diff] [blame] | 818 | if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) { |
| 819 | sb.append("SuppVideo "); |
| 820 | } |
Tyler Gunn | 3e122f7 | 2016-01-11 19:25:00 -0800 | [diff] [blame] | 821 | if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) { |
| 822 | sb.append("Video "); |
| 823 | } |
| 824 | if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) { |
| 825 | sb.append("Presence "); |
| 826 | } |
| 827 | if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) { |
| 828 | sb.append("CallProvider "); |
| 829 | } |
| 830 | if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) { |
| 831 | sb.append("CallSubject "); |
| 832 | } |
| 833 | if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) { |
| 834 | sb.append("ConnectionMgr "); |
| 835 | } |
| 836 | if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) { |
| 837 | sb.append("EmergOnly "); |
| 838 | } |
| 839 | if (hasCapabilities(CAPABILITY_MULTI_USER)) { |
| 840 | sb.append("MultiUser "); |
| 841 | } |
| 842 | if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) { |
| 843 | sb.append("PlaceEmerg "); |
| 844 | } |
Tyler Gunn | cee9ea6 | 2016-03-24 11:45:43 -0700 | [diff] [blame] | 845 | if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) { |
| 846 | sb.append("EmergVideo "); |
| 847 | } |
Tyler Gunn | 3e122f7 | 2016-01-11 19:25:00 -0800 | [diff] [blame] | 848 | if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) { |
| 849 | sb.append("SimSub "); |
| 850 | } |
| 851 | return sb.toString(); |
| 852 | } |
Christine Hallstrom | 4e22d6d | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 853 | |
| 854 | private String audioRoutesToString() { |
| 855 | StringBuilder sb = new StringBuilder(); |
| 856 | |
| 857 | if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) { |
| 858 | sb.append("B"); |
| 859 | } |
| 860 | if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) { |
| 861 | sb.append("E"); |
| 862 | } |
| 863 | if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) { |
| 864 | sb.append("S"); |
| 865 | } |
| 866 | if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) { |
| 867 | sb.append("W"); |
| 868 | } |
| 869 | |
| 870 | return sb.toString(); |
| 871 | } |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 872 | } |