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 | |
Tyler Gunn | c9503d6 | 2020-01-27 10:30:51 -0800 | [diff] [blame] | 19 | import static android.Manifest.permission.MODIFY_PHONE_STATE; |
| 20 | |
Tyler Gunn | 5567d74 | 2019-10-31 13:04:37 -0700 | [diff] [blame] | 21 | import android.annotation.NonNull; |
Tyler Gunn | c9503d6 | 2020-01-27 10:30:51 -0800 | [diff] [blame] | 22 | import android.annotation.RequiresPermission; |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 23 | import android.annotation.SystemApi; |
Tyler Gunn | 5567d74 | 2019-10-31 13:04:37 -0700 | [diff] [blame] | 24 | import android.annotation.TestApi; |
Brad Ebinger | 3636d74 | 2019-05-21 15:28:19 -0700 | [diff] [blame] | 25 | import android.content.Intent; |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 26 | import android.graphics.drawable.Icon; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 27 | import android.net.Uri; |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 28 | import android.os.Bundle; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 29 | import android.os.Parcel; |
| 30 | import android.os.Parcelable; |
Hall Liu | 221f804 | 2020-09-23 15:36:58 -0700 | [diff] [blame^] | 31 | import android.telephony.TelephonyManager; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 32 | import android.text.TextUtils; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 33 | |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 34 | import java.util.ArrayList; |
| 35 | import java.util.Collections; |
| 36 | import java.util.List; |
Tyler Gunn | 3b34781 | 2018-08-24 14:17:05 -0700 | [diff] [blame] | 37 | import java.util.Objects; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 40 | * Represents a distinct method to place or receive a phone call. Apps which can place calls and |
| 41 | * 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] | 42 | * this class and register it with the system using {@link TelecomManager}. |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 43 | * <p> |
| 44 | * {@link TelecomManager} uses registered {@link PhoneAccount}s to present the user with |
| 45 | * 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] | 46 | * should supply a valid {@link PhoneAccountHandle} that references the connection service |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 47 | * implementation Telecom will use to interact with the app. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 48 | */ |
Yorke Lee | 400470f | 2015-05-12 13:31:25 -0700 | [diff] [blame] | 49 | public final class PhoneAccount implements Parcelable { |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 50 | |
| 51 | /** |
Hall Liu | 2ef0411 | 2020-09-14 18:34:10 -0700 | [diff] [blame] | 52 | * String extra which determines the order in which {@link PhoneAccount}s are sorted |
| 53 | * |
| 54 | * This is an extras key set via {@link Builder#setExtras} which determines the order in which |
| 55 | * {@link PhoneAccount}s from the same {@link ConnectionService} are sorted. The accounts |
Hall Liu | 221f804 | 2020-09-23 15:36:58 -0700 | [diff] [blame^] | 56 | * are sorted by this key via standard lexicographical order, (as implemented in |
| 57 | * {@link String#compareTo}), and this ordering is used to |
Hall Liu | 2ef0411 | 2020-09-14 18:34:10 -0700 | [diff] [blame] | 58 | * determine priority when a call can be placed via multiple accounts. |
Hall Liu | 221f804 | 2020-09-23 15:36:58 -0700 | [diff] [blame^] | 59 | * |
| 60 | * When multiple {@link PhoneAccount}s are supplied with the same sort order key, no ordering is |
| 61 | * guaranteed between those {@link PhoneAccount}s. Additionally, no ordering is guaranteed |
| 62 | * between {@link PhoneAccount}s that do not supply this extra, and all such accounts |
| 63 | * will be sorted after the accounts that do supply this extra. |
| 64 | * |
| 65 | * An example of a sort order key is slot index (see {@link TelephonyManager#getSlotIndex()}), |
| 66 | * which is the one used by the cell Telephony stack. |
Srikanth Chintala | 6242840 | 2017-03-27 19:27:52 +0530 | [diff] [blame] | 67 | * @hide |
| 68 | */ |
Hall Liu | 2ef0411 | 2020-09-14 18:34:10 -0700 | [diff] [blame] | 69 | @SystemApi |
Srikanth Chintala | 6242840 | 2017-03-27 19:27:52 +0530 | [diff] [blame] | 70 | public static final String EXTRA_SORT_ORDER = |
| 71 | "android.telecom.extra.SORT_ORDER"; |
| 72 | |
| 73 | /** |
| 74 | * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the |
Tyler Gunn | d426b20 | 2015-10-13 13:33:53 -0700 | [diff] [blame] | 75 | * maximum permitted length of a call subject specified via the |
| 76 | * {@link TelecomManager#EXTRA_CALL_SUBJECT} extra on an |
| 77 | * {@link android.content.Intent#ACTION_CALL} intent. Ultimately a {@link ConnectionService} is |
| 78 | * responsible for enforcing the maximum call subject length when sending the message, however |
| 79 | * this extra is provided so that the user interface can proactively limit the length of the |
| 80 | * call subject as the user types it. |
| 81 | */ |
| 82 | public static final String EXTRA_CALL_SUBJECT_MAX_LENGTH = |
| 83 | "android.telecom.extra.CALL_SUBJECT_MAX_LENGTH"; |
| 84 | |
| 85 | /** |
| 86 | * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the |
| 87 | * character encoding to be used when determining the length of messages. |
| 88 | * The user interface can use this when determining the number of characters the user may type |
| 89 | * in a call subject. If empty-string, the call subject message size limit will be enforced on |
| 90 | * a 1:1 basis. That is, each character will count towards the messages size limit as a single |
| 91 | * character. If a character encoding is specified, the message size limit will be based on the |
| 92 | * number of bytes in the message per the specified encoding. See |
| 93 | * {@link #EXTRA_CALL_SUBJECT_MAX_LENGTH} for more information on the call subject maximum |
| 94 | * length. |
| 95 | */ |
| 96 | public static final String EXTRA_CALL_SUBJECT_CHARACTER_ENCODING = |
| 97 | "android.telecom.extra.CALL_SUBJECT_CHARACTER_ENCODING"; |
| 98 | |
Hall Liu | e576fc4 | 2020-01-22 17:17:13 -0800 | [diff] [blame] | 99 | /** |
| 100 | * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which |
| 101 | * indicates that all calls from this {@link PhoneAccount} should be treated as VoIP calls |
Hall Liu | 2ef0411 | 2020-09-14 18:34:10 -0700 | [diff] [blame] | 102 | * rather than cellular calls by the Telecom audio handling logic. |
Srikanth Chintala | f77d4a1 | 2017-04-03 18:08:14 +0530 | [diff] [blame] | 103 | */ |
| 104 | public static final String EXTRA_ALWAYS_USE_VOIP_AUDIO_MODE = |
| 105 | "android.telecom.extra.ALWAYS_USE_VOIP_AUDIO_MODE"; |
| 106 | |
Tyler Gunn | d426b20 | 2015-10-13 13:33:53 -0700 | [diff] [blame] | 107 | /** |
Tyler Gunn | 8bf7657 | 2017-04-06 15:30:08 -0700 | [diff] [blame] | 108 | * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which |
| 109 | * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a |
Sanket Padawe | a8eddd4 | 2017-11-03 11:07:35 -0700 | [diff] [blame] | 110 | * connection (see {@code android.telecom.Call#handoverTo()}) to this {@link PhoneAccount} from |
| 111 | * a {@link PhoneAccount} specifying {@link #EXTRA_SUPPORTS_HANDOVER_FROM}. |
Tyler Gunn | 8bf7657 | 2017-04-06 15:30:08 -0700 | [diff] [blame] | 112 | * <p> |
| 113 | * A handover request is initiated by the user from the default dialer app to indicate a desire |
| 114 | * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another. |
Tyler Gunn | 8bf7657 | 2017-04-06 15:30:08 -0700 | [diff] [blame] | 115 | */ |
| 116 | public static final String EXTRA_SUPPORTS_HANDOVER_TO = |
| 117 | "android.telecom.extra.SUPPORTS_HANDOVER_TO"; |
| 118 | |
| 119 | /** |
| 120 | * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which |
Ta-wei Yen | 9d20d98 | 2017-06-02 11:07:07 -0700 | [diff] [blame] | 121 | * indicates whether this {@link PhoneAccount} supports using a fallback if video calling is |
| 122 | * not available. This extra is for device level support, {@link |
| 123 | * android.telephony.CarrierConfigManager#KEY_ALLOW_VIDEO_CALLING_FALLBACK_BOOL} should also |
| 124 | * be checked to ensure it is not disabled by individual carrier. |
| 125 | * |
| 126 | * @hide |
| 127 | */ |
| 128 | public static final String EXTRA_SUPPORTS_VIDEO_CALLING_FALLBACK = |
| 129 | "android.telecom.extra.SUPPORTS_VIDEO_CALLING_FALLBACK"; |
| 130 | |
| 131 | /** |
| 132 | * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which |
Tyler Gunn | 8bf7657 | 2017-04-06 15:30:08 -0700 | [diff] [blame] | 133 | * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a |
| 134 | * connection from this {@link PhoneAccount} to another {@link PhoneAccount}. |
Sanket Padawe | a8eddd4 | 2017-11-03 11:07:35 -0700 | [diff] [blame] | 135 | * (see {@code android.telecom.Call#handoverTo()}) which specifies |
Tyler Gunn | 8bf7657 | 2017-04-06 15:30:08 -0700 | [diff] [blame] | 136 | * {@link #EXTRA_SUPPORTS_HANDOVER_TO}. |
| 137 | * <p> |
| 138 | * A handover request is initiated by the user from the default dialer app to indicate a desire |
| 139 | * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another. |
Tyler Gunn | 8bf7657 | 2017-04-06 15:30:08 -0700 | [diff] [blame] | 140 | */ |
| 141 | public static final String EXTRA_SUPPORTS_HANDOVER_FROM = |
| 142 | "android.telecom.extra.SUPPORTS_HANDOVER_FROM"; |
| 143 | |
Tyler Gunn | 9f6f047 | 2017-04-17 18:25:22 -0700 | [diff] [blame] | 144 | |
| 145 | /** |
| 146 | * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which |
| 147 | * indicates whether a Self-Managed {@link PhoneAccount} should log its calls to the call log. |
Brad Ebinger | bb1a55f | 2017-06-26 13:26:14 -0700 | [diff] [blame] | 148 | * Self-Managed {@link PhoneAccount}s are responsible for their own notifications, so the system |
| 149 | * will not create a notification when a missed call is logged. |
Tyler Gunn | 9f6f047 | 2017-04-17 18:25:22 -0700 | [diff] [blame] | 150 | * <p> |
| 151 | * By default, Self-Managed {@link PhoneAccount}s do not log their calls to the call log. |
| 152 | * Setting this extra to {@code true} provides a means for them to log their calls. |
Tyler Gunn | 2155c4c | 2018-04-05 09:43:41 -0700 | [diff] [blame] | 153 | * <p> |
| 154 | * Note: Only calls where the {@link Call.Details#getHandle()} {@link Uri#getScheme()} is |
| 155 | * {@link #SCHEME_SIP} or {@link #SCHEME_TEL} will be logged at the current time. |
Tyler Gunn | 9f6f047 | 2017-04-17 18:25:22 -0700 | [diff] [blame] | 156 | */ |
| 157 | public static final String EXTRA_LOG_SELF_MANAGED_CALLS = |
| 158 | "android.telecom.extra.LOG_SELF_MANAGED_CALLS"; |
| 159 | |
Tyler Gunn | 8bf7657 | 2017-04-06 15:30:08 -0700 | [diff] [blame] | 160 | /** |
Tyler Gunn | acdb686 | 2018-01-29 14:30:52 -0800 | [diff] [blame] | 161 | * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which |
| 162 | * indicates whether calls for a {@link PhoneAccount} should generate a "call recording tone" |
| 163 | * when the user is recording audio on the device. |
| 164 | * <p> |
| 165 | * The call recording tone is played over the telephony audio stream so that the remote party |
| 166 | * has an audible indication that it is possible their call is being recorded using a call |
| 167 | * recording app on the device. |
| 168 | * <p> |
| 169 | * This extra only has an effect for calls placed via Telephony (e.g. |
| 170 | * {@link #CAPABILITY_SIM_SUBSCRIPTION}). |
| 171 | * <p> |
| 172 | * The call recording tone is a 1400 hz tone which repeats every 15 seconds while recording is |
| 173 | * in progress. |
| 174 | * @hide |
| 175 | */ |
Hall Liu | 2ef0411 | 2020-09-14 18:34:10 -0700 | [diff] [blame] | 176 | @SystemApi |
Tyler Gunn | acdb686 | 2018-01-29 14:30:52 -0800 | [diff] [blame] | 177 | public static final String EXTRA_PLAY_CALL_RECORDING_TONE = |
| 178 | "android.telecom.extra.PLAY_CALL_RECORDING_TONE"; |
| 179 | |
| 180 | /** |
Sean Kelley | 4d3c178 | 2018-05-22 14:35:27 -0700 | [diff] [blame] | 181 | * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()} which |
| 182 | * indicates whether calls for a {@link PhoneAccount} should skip call filtering. |
| 183 | * <p> |
| 184 | * If not specified, this will default to false; all calls will undergo call filtering unless |
| 185 | * specifically exempted (e.g. {@link Connection#PROPERTY_EMERGENCY_CALLBACK_MODE}.) However, |
| 186 | * this may be used to skip call filtering when it has already been performed on another device. |
| 187 | * @hide |
| 188 | */ |
| 189 | public static final String EXTRA_SKIP_CALL_FILTERING = |
| 190 | "android.telecom.extra.SKIP_CALL_FILTERING"; |
| 191 | |
| 192 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 193 | * Flag indicating that this {@code PhoneAccount} can act as a connection manager for |
| 194 | * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount} |
| 195 | * will be allowed to manage phone calls including using its own proprietary phone-call |
| 196 | * implementation (like VoIP calling) to make calls instead of the telephony stack. |
| 197 | * <p> |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 198 | * When a user opts to place a call using the SIM-based telephony stack, the |
| 199 | * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first |
| 200 | * 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] | 201 | * <p> |
| 202 | * See {@link #getCapabilities} |
| 203 | */ |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 204 | public static final int CAPABILITY_CONNECTION_MANAGER = 0x1; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 205 | |
| 206 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 207 | * 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] | 208 | * traditional SIM-based telephony calls. This account will be treated as a distinct method |
| 209 | * 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] | 210 | * 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] | 211 | * or place calls from the built-in telephony stack. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 212 | * <p> |
| 213 | * See {@link #getCapabilities} |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 214 | * <p> |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 215 | */ |
| 216 | public static final int CAPABILITY_CALL_PROVIDER = 0x2; |
| 217 | |
Ihab Awad | 7522bbd6 | 2014-07-18 15:53:17 -0700 | [diff] [blame] | 218 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 219 | * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 220 | * subscription. |
Ihab Awad | 7522bbd6 | 2014-07-18 15:53:17 -0700 | [diff] [blame] | 221 | * <p> |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 222 | * Only the Android framework can register a {@code PhoneAccount} having this capability. |
| 223 | * <p> |
| 224 | * See {@link #getCapabilities} |
Ihab Awad | 7522bbd6 | 2014-07-18 15:53:17 -0700 | [diff] [blame] | 225 | */ |
| 226 | public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4; |
| 227 | |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 228 | /** |
Tyler Gunn | 58cbd7a | 2016-11-11 11:31:28 -0800 | [diff] [blame] | 229 | * Flag indicating that this {@code PhoneAccount} is currently able to place video calls. |
| 230 | * <p> |
| 231 | * See also {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING} which indicates whether the |
| 232 | * {@code PhoneAccount} supports placing video calls. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 233 | * <p> |
| 234 | * See {@link #getCapabilities} |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 235 | */ |
| 236 | public static final int CAPABILITY_VIDEO_CALLING = 0x8; |
| 237 | |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 238 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 239 | * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls. |
| 240 | * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls. |
| 241 | * <p> |
| 242 | * See {@link #getCapabilities} |
| 243 | */ |
| 244 | public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10; |
| 245 | |
| 246 | /** |
Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 247 | * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This |
| 248 | * should only be used by system apps (and will be ignored for all other apps trying to use it). |
| 249 | * <p> |
| 250 | * See {@link #getCapabilities} |
| 251 | * @hide |
| 252 | */ |
Brian Attwell | ad147f4 | 2014-12-19 11:37:16 -0800 | [diff] [blame] | 253 | @SystemApi |
Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 254 | public static final int CAPABILITY_MULTI_USER = 0x20; |
| 255 | |
| 256 | /** |
Tyler Gunn | 65a3d34 | 2015-07-27 16:06:16 -0700 | [diff] [blame] | 257 | * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a |
| 258 | * caller is able to specify a short subject line for an outgoing call. A capable receiving |
| 259 | * device displays the call subject on the incoming call screen. |
| 260 | * <p> |
| 261 | * See {@link #getCapabilities} |
| 262 | */ |
| 263 | public static final int CAPABILITY_CALL_SUBJECT = 0x40; |
| 264 | |
| 265 | /** |
Bryce Lee | b96d89c | 2015-10-14 16:48:40 -0700 | [diff] [blame] | 266 | * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls. |
| 267 | * <p> |
| 268 | * See {@link #getCapabilities} |
| 269 | * @hide |
| 270 | */ |
Hall Liu | 2ef0411 | 2020-09-14 18:34:10 -0700 | [diff] [blame] | 271 | @SystemApi |
Bryce Lee | b96d89c | 2015-10-14 16:48:40 -0700 | [diff] [blame] | 272 | public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80; |
| 273 | |
| 274 | /** |
Tyler Gunn | 9a36575 | 2015-12-09 15:00:18 -0800 | [diff] [blame] | 275 | * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a |
| 276 | * number relies on presence. Should only be set if the {@code PhoneAccount} also has |
| 277 | * {@link #CAPABILITY_VIDEO_CALLING}. |
| 278 | * <p> |
| 279 | * When set, the {@link ConnectionService} is responsible for toggling the |
| 280 | * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the |
| 281 | * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether |
| 282 | * a contact's phone number supports video calling. |
| 283 | * <p> |
| 284 | * See {@link #getCapabilities} |
| 285 | */ |
| 286 | public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100; |
| 287 | |
| 288 | /** |
Tyler Gunn | cee9ea6 | 2016-03-24 11:45:43 -0700 | [diff] [blame] | 289 | * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed. |
| 290 | * <p> |
| 291 | * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will |
| 292 | * convert all outgoing video calls to emergency numbers to audio-only. |
| 293 | * @hide |
| 294 | */ |
Hall Liu | 2ef0411 | 2020-09-14 18:34:10 -0700 | [diff] [blame] | 295 | @SystemApi |
Tyler Gunn | cee9ea6 | 2016-03-24 11:45:43 -0700 | [diff] [blame] | 296 | public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200; |
| 297 | |
| 298 | /** |
Tyler Gunn | 58cbd7a | 2016-11-11 11:31:28 -0800 | [diff] [blame] | 299 | * Flag indicating that this {@link PhoneAccount} supports video calling. |
| 300 | * This is not an indication that the {@link PhoneAccount} is currently able to make a video |
| 301 | * call, but rather that it has the ability to make video calls (but not necessarily at this |
| 302 | * time). |
| 303 | * <p> |
| 304 | * Whether a {@link PhoneAccount} can make a video call is ultimately controlled by |
| 305 | * {@link #CAPABILITY_VIDEO_CALLING}, which indicates whether the {@link PhoneAccount} is |
| 306 | * currently capable of making a video call. Consider a case where, for example, a |
| 307 | * {@link PhoneAccount} supports making video calls (e.g. |
| 308 | * {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING}), but a current lack of network connectivity |
| 309 | * prevents video calls from being made (e.g. {@link #CAPABILITY_VIDEO_CALLING}). |
| 310 | * <p> |
| 311 | * See {@link #getCapabilities} |
| 312 | */ |
| 313 | public static final int CAPABILITY_SUPPORTS_VIDEO_CALLING = 0x400; |
| 314 | |
| 315 | /** |
Tyler Gunn | f503543 | 2017-01-09 09:43:12 -0800 | [diff] [blame] | 316 | * Flag indicating that this {@link PhoneAccount} is responsible for managing its own |
| 317 | * {@link Connection}s. This type of {@link PhoneAccount} is ideal for use with standalone |
| 318 | * calling apps which do not wish to use the default phone app for {@link Connection} UX, |
| 319 | * but which want to leverage the call and audio routing capabilities of the Telecom framework. |
| 320 | * <p> |
| 321 | * When set, {@link Connection}s created by the self-managed {@link ConnectionService} will not |
| 322 | * be surfaced to implementations of the {@link InCallService} API. Thus it is the |
| 323 | * responsibility of a self-managed {@link ConnectionService} to provide a user interface for |
| 324 | * its {@link Connection}s. |
| 325 | * <p> |
| 326 | * Self-managed {@link Connection}s will, however, be displayed on connected Bluetooth devices. |
| 327 | */ |
| 328 | public static final int CAPABILITY_SELF_MANAGED = 0x800; |
| 329 | |
| 330 | /** |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 331 | * Flag indicating that this {@link PhoneAccount} is capable of making a call with an |
| 332 | * RTT (Real-time text) session. |
| 333 | * When set, Telecom will attempt to open an RTT session on outgoing calls that specify |
| 334 | * that they should be placed with an RTT session , and the in-call app will be displayed |
| 335 | * with text entry fields for RTT. Likewise, the in-call app can request that an RTT |
| 336 | * session be opened during a call if this bit is set. |
| 337 | */ |
| 338 | public static final int CAPABILITY_RTT = 0x1000; |
| 339 | |
Brad Ebinger | 3636d74 | 2019-05-21 15:28:19 -0700 | [diff] [blame] | 340 | /** |
| 341 | * Flag indicating that this {@link PhoneAccount} is the preferred SIM subscription for |
Hall Liu | 2ef0411 | 2020-09-14 18:34:10 -0700 | [diff] [blame] | 342 | * emergency calls. A {@link PhoneAccount} that sets this capability must also |
Brad Ebinger | 3636d74 | 2019-05-21 15:28:19 -0700 | [diff] [blame] | 343 | * set the {@link #CAPABILITY_SIM_SUBSCRIPTION} and {@link #CAPABILITY_PLACE_EMERGENCY_CALLS} |
Hall Liu | 2ef0411 | 2020-09-14 18:34:10 -0700 | [diff] [blame] | 344 | * capabilities. There must only be one emergency preferred {@link PhoneAccount} on the device. |
Brad Ebinger | 3636d74 | 2019-05-21 15:28:19 -0700 | [diff] [blame] | 345 | * <p> |
| 346 | * When set, Telecom will prefer this {@link PhoneAccount} over others for emergency calling, |
| 347 | * even if the emergency call was placed with a specific {@link PhoneAccount} set using the |
| 348 | * extra{@link TelecomManager#EXTRA_PHONE_ACCOUNT_HANDLE} in |
| 349 | * {@link Intent#ACTION_CALL_EMERGENCY} or {@link TelecomManager#placeCall(Uri, Bundle)}. |
| 350 | * |
| 351 | * @hide |
| 352 | */ |
Hall Liu | 2ef0411 | 2020-09-14 18:34:10 -0700 | [diff] [blame] | 353 | @SystemApi |
Brad Ebinger | 3636d74 | 2019-05-21 15:28:19 -0700 | [diff] [blame] | 354 | public static final int CAPABILITY_EMERGENCY_PREFERRED = 0x2000; |
| 355 | |
Ravi Paluri | 80aa214 | 2019-12-02 11:57:37 +0530 | [diff] [blame] | 356 | /** |
| 357 | * An adhoc conference call is established by providing a list of addresses to |
| 358 | * {@code TelecomManager#startConference(List<Uri>, int videoState)} where the |
| 359 | * {@link ConnectionService} is responsible for connecting all indicated participants |
| 360 | * to a conference simultaneously. |
| 361 | * This is in contrast to conferences formed by merging calls together (e.g. using |
| 362 | * {@link android.telecom.Call#mergeConference()}). |
| 363 | */ |
| 364 | public static final int CAPABILITY_ADHOC_CONFERENCE_CALLING = 0x4000; |
| 365 | |
| 366 | /* NEXT CAPABILITY: 0x8000 */ |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 367 | |
| 368 | /** |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 369 | * URI scheme for telephone number URIs. |
| 370 | */ |
| 371 | public static final String SCHEME_TEL = "tel"; |
| 372 | |
| 373 | /** |
| 374 | * URI scheme for voicemail URIs. |
| 375 | */ |
| 376 | public static final String SCHEME_VOICEMAIL = "voicemail"; |
| 377 | |
| 378 | /** |
| 379 | * URI scheme for SIP URIs. |
| 380 | */ |
| 381 | public static final String SCHEME_SIP = "sip"; |
| 382 | |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 383 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 384 | * Indicating no icon tint is set. |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 385 | * @hide |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 386 | */ |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 387 | public static final int NO_ICON_TINT = 0; |
| 388 | |
| 389 | /** |
| 390 | * Indicating no hightlight color is set. |
| 391 | */ |
| 392 | public static final int NO_HIGHLIGHT_COLOR = 0; |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 393 | |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 394 | /** |
| 395 | * Indicating no resource ID is set. |
| 396 | */ |
| 397 | public static final int NO_RESOURCE_ID = -1; |
| 398 | |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 399 | private final PhoneAccountHandle mAccountHandle; |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 400 | private final Uri mAddress; |
| 401 | private final Uri mSubscriptionAddress; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 402 | private final int mCapabilities; |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 403 | private final int mHighlightColor; |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 404 | private final CharSequence mLabel; |
| 405 | private final CharSequence mShortDescription; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 406 | private final List<String> mSupportedUriSchemes; |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 407 | private final int mSupportedAudioRoutes; |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 408 | private final Icon mIcon; |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 409 | private final Bundle mExtras; |
Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 410 | private boolean mIsEnabled; |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 411 | private String mGroupId; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 412 | |
Tyler Gunn | 3b34781 | 2018-08-24 14:17:05 -0700 | [diff] [blame] | 413 | @Override |
| 414 | public boolean equals(Object o) { |
| 415 | if (this == o) return true; |
| 416 | if (o == null || getClass() != o.getClass()) return false; |
| 417 | PhoneAccount that = (PhoneAccount) o; |
| 418 | return mCapabilities == that.mCapabilities && |
| 419 | mHighlightColor == that.mHighlightColor && |
| 420 | mSupportedAudioRoutes == that.mSupportedAudioRoutes && |
| 421 | mIsEnabled == that.mIsEnabled && |
| 422 | Objects.equals(mAccountHandle, that.mAccountHandle) && |
| 423 | Objects.equals(mAddress, that.mAddress) && |
| 424 | Objects.equals(mSubscriptionAddress, that.mSubscriptionAddress) && |
| 425 | Objects.equals(mLabel, that.mLabel) && |
| 426 | Objects.equals(mShortDescription, that.mShortDescription) && |
| 427 | Objects.equals(mSupportedUriSchemes, that.mSupportedUriSchemes) && |
| 428 | areBundlesEqual(mExtras, that.mExtras) && |
| 429 | Objects.equals(mGroupId, that.mGroupId); |
| 430 | } |
| 431 | |
| 432 | @Override |
| 433 | public int hashCode() { |
| 434 | return Objects.hash(mAccountHandle, mAddress, mSubscriptionAddress, mCapabilities, |
| 435 | mHighlightColor, mLabel, mShortDescription, mSupportedUriSchemes, |
| 436 | mSupportedAudioRoutes, |
| 437 | mExtras, mIsEnabled, mGroupId); |
| 438 | } |
| 439 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 440 | /** |
| 441 | * Helper class for creating a {@link PhoneAccount}. |
| 442 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 443 | public static class Builder { |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 444 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 445 | private PhoneAccountHandle mAccountHandle; |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 446 | private Uri mAddress; |
| 447 | private Uri mSubscriptionAddress; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 448 | private int mCapabilities; |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 449 | private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 450 | private int mHighlightColor = NO_HIGHLIGHT_COLOR; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 451 | private CharSequence mLabel; |
| 452 | private CharSequence mShortDescription; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 453 | private List<String> mSupportedUriSchemes = new ArrayList<String>(); |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 454 | private Icon mIcon; |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 455 | private Bundle mExtras; |
Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 456 | private boolean mIsEnabled = false; |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 457 | private String mGroupId = ""; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 458 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 459 | /** |
| 460 | * Creates a builder with the specified {@link PhoneAccountHandle} and label. |
| 461 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 462 | public Builder(PhoneAccountHandle accountHandle, CharSequence label) { |
| 463 | this.mAccountHandle = accountHandle; |
| 464 | this.mLabel = label; |
| 465 | } |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 466 | |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 467 | /** |
| 468 | * Creates an instance of the {@link PhoneAccount.Builder} from an existing |
| 469 | * {@link PhoneAccount}. |
| 470 | * |
| 471 | * @param phoneAccount The {@link PhoneAccount} used to initialize the builder. |
| 472 | */ |
| 473 | public Builder(PhoneAccount phoneAccount) { |
| 474 | mAccountHandle = phoneAccount.getAccountHandle(); |
| 475 | mAddress = phoneAccount.getAddress(); |
| 476 | mSubscriptionAddress = phoneAccount.getSubscriptionAddress(); |
| 477 | mCapabilities = phoneAccount.getCapabilities(); |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 478 | mHighlightColor = phoneAccount.getHighlightColor(); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 479 | mLabel = phoneAccount.getLabel(); |
| 480 | mShortDescription = phoneAccount.getShortDescription(); |
| 481 | mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes()); |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 482 | mIcon = phoneAccount.getIcon(); |
Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 483 | mIsEnabled = phoneAccount.isEnabled(); |
Tyler Gunn | d426b20 | 2015-10-13 13:33:53 -0700 | [diff] [blame] | 484 | mExtras = phoneAccount.getExtras(); |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 485 | mGroupId = phoneAccount.getGroupId(); |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 486 | mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes(); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 487 | } |
| 488 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 489 | /** |
Tyler Gunn | 3765356 | 2017-03-13 18:15:15 -0700 | [diff] [blame] | 490 | * Sets the label. See {@link PhoneAccount#getLabel()}. |
| 491 | * |
| 492 | * @param label The label of the phone account. |
| 493 | * @return The builder. |
| 494 | * @hide |
| 495 | */ |
| 496 | public Builder setLabel(CharSequence label) { |
| 497 | this.mLabel = label; |
| 498 | return this; |
| 499 | } |
| 500 | |
| 501 | /** |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 502 | * Sets the address. See {@link PhoneAccount#getAddress}. |
| 503 | * |
| 504 | * @param value The address of the phone account. |
| 505 | * @return The builder. |
| 506 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 507 | public Builder setAddress(Uri value) { |
| 508 | this.mAddress = value; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 509 | return this; |
| 510 | } |
| 511 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 512 | /** |
| 513 | * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}. |
| 514 | * |
| 515 | * @param value The subscription address. |
| 516 | * @return The builder. |
| 517 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 518 | public Builder setSubscriptionAddress(Uri value) { |
| 519 | this.mSubscriptionAddress = value; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 520 | return this; |
| 521 | } |
| 522 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 523 | /** |
| 524 | * Sets the capabilities. See {@link PhoneAccount#getCapabilities}. |
| 525 | * |
| 526 | * @param value The capabilities to set. |
| 527 | * @return The builder. |
| 528 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 529 | public Builder setCapabilities(int value) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 530 | this.mCapabilities = value; |
| 531 | return this; |
| 532 | } |
| 533 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 534 | /** |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 535 | * Sets the icon. See {@link PhoneAccount#getIcon}. |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 536 | * |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 537 | * @param icon The icon to set. |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 538 | */ |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 539 | public Builder setIcon(Icon icon) { |
| 540 | mIcon = icon; |
Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 541 | return this; |
| 542 | } |
| 543 | |
| 544 | /** |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 545 | * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}. |
Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 546 | * |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 547 | * @param value The highlight color. |
Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 548 | * @return The builder. |
| 549 | */ |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 550 | public Builder setHighlightColor(int value) { |
| 551 | this.mHighlightColor = value; |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 552 | return this; |
| 553 | } |
| 554 | |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 555 | /** |
| 556 | * Sets the short description. See {@link PhoneAccount#getShortDescription}. |
| 557 | * |
| 558 | * @param value The short description. |
| 559 | * @return The builder. |
| 560 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 561 | public Builder setShortDescription(CharSequence value) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 562 | this.mShortDescription = value; |
| 563 | return this; |
| 564 | } |
| 565 | |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 566 | /** |
| 567 | * Specifies an additional URI scheme supported by the {@link PhoneAccount}. |
| 568 | * |
| 569 | * @param uriScheme The URI scheme. |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 570 | * @return The builder. |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 571 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 572 | public Builder addSupportedUriScheme(String uriScheme) { |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 573 | if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) { |
| 574 | this.mSupportedUriSchemes.add(uriScheme); |
| 575 | } |
| 576 | return this; |
| 577 | } |
| 578 | |
| 579 | /** |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 580 | * Specifies the URI schemes supported by the {@link PhoneAccount}. |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 581 | * |
| 582 | * @param uriSchemes The URI schemes. |
Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 583 | * @return The builder. |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 584 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 585 | public Builder setSupportedUriSchemes(List<String> uriSchemes) { |
| 586 | mSupportedUriSchemes.clear(); |
| 587 | |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 588 | if (uriSchemes != null && !uriSchemes.isEmpty()) { |
| 589 | for (String uriScheme : uriSchemes) { |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 590 | addSupportedUriScheme(uriScheme); |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | return this; |
| 594 | } |
| 595 | |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 596 | /** |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 597 | * Specifies the extras associated with the {@link PhoneAccount}. |
| 598 | * <p> |
| 599 | * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer}, |
| 600 | * and {@link Boolean}. Extras which are not of these types are ignored. |
| 601 | * |
| 602 | * @param extras |
| 603 | * @return |
| 604 | */ |
| 605 | public Builder setExtras(Bundle extras) { |
| 606 | mExtras = extras; |
| 607 | return this; |
| 608 | } |
| 609 | |
| 610 | /** |
Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 611 | * Sets the enabled state of the phone account. |
| 612 | * |
| 613 | * @param isEnabled The enabled state. |
| 614 | * @return The builder. |
| 615 | * @hide |
| 616 | */ |
| 617 | public Builder setIsEnabled(boolean isEnabled) { |
| 618 | mIsEnabled = isEnabled; |
| 619 | return this; |
| 620 | } |
| 621 | |
| 622 | /** |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 623 | * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is |
| 624 | * registered to Telecom, it will replace another {@link PhoneAccount} that is already |
| 625 | * registered in Telecom and take on the current user defaults and enabled status. There can |
| 626 | * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a |
| 627 | * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only |
| 628 | * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced. |
Tyler Gunn | 5567d74 | 2019-10-31 13:04:37 -0700 | [diff] [blame] | 629 | * <p> |
Tyler Gunn | c9503d6 | 2020-01-27 10:30:51 -0800 | [diff] [blame] | 630 | * Note: This is an API specific to the Telephony stack; the group Id will be ignored for |
| 631 | * callers not holding the correct permission. |
Tyler Gunn | 5567d74 | 2019-10-31 13:04:37 -0700 | [diff] [blame] | 632 | * |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 633 | * @param groupId The group Id of the {@link PhoneAccount} that will replace any other |
| 634 | * registered {@link PhoneAccount} in Telecom with the same Group Id. |
| 635 | * @return The builder |
| 636 | * @hide |
| 637 | */ |
Tyler Gunn | 5567d74 | 2019-10-31 13:04:37 -0700 | [diff] [blame] | 638 | @SystemApi |
| 639 | @TestApi |
Tyler Gunn | c9503d6 | 2020-01-27 10:30:51 -0800 | [diff] [blame] | 640 | @RequiresPermission(MODIFY_PHONE_STATE) |
Tyler Gunn | 5567d74 | 2019-10-31 13:04:37 -0700 | [diff] [blame] | 641 | public @NonNull Builder setGroupId(@NonNull String groupId) { |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 642 | if (groupId != null) { |
| 643 | mGroupId = groupId; |
| 644 | } else { |
| 645 | mGroupId = ""; |
| 646 | } |
| 647 | return this; |
| 648 | } |
| 649 | |
| 650 | /** |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 651 | * Sets the audio routes supported by this {@link PhoneAccount}. |
| 652 | * |
| 653 | * @param routes bit mask of available routes. |
| 654 | * @return The builder. |
| 655 | * @hide |
| 656 | */ |
| 657 | public Builder setSupportedAudioRoutes(int routes) { |
| 658 | mSupportedAudioRoutes = routes; |
| 659 | return this; |
| 660 | } |
| 661 | |
| 662 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 663 | * Creates an instance of a {@link PhoneAccount} based on the current builder settings. |
| 664 | * |
| 665 | * @return The {@link PhoneAccount}. |
| 666 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 667 | public PhoneAccount build() { |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 668 | // If no supported URI schemes were defined, assume "tel" is supported. |
| 669 | if (mSupportedUriSchemes.isEmpty()) { |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 670 | addSupportedUriScheme(SCHEME_TEL); |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 673 | return new PhoneAccount( |
| 674 | mAccountHandle, |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 675 | mAddress, |
| 676 | mSubscriptionAddress, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 677 | mCapabilities, |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 678 | mIcon, |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 679 | mHighlightColor, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 680 | mLabel, |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 681 | mShortDescription, |
Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 682 | mSupportedUriSchemes, |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 683 | mExtras, |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 684 | mSupportedAudioRoutes, |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 685 | mIsEnabled, |
| 686 | mGroupId); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 687 | } |
| 688 | } |
| 689 | |
| 690 | private PhoneAccount( |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 691 | PhoneAccountHandle account, |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 692 | Uri address, |
| 693 | Uri subscriptionAddress, |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 694 | int capabilities, |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 695 | Icon icon, |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 696 | int highlightColor, |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 697 | CharSequence label, |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 698 | CharSequence shortDescription, |
Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 699 | List<String> supportedUriSchemes, |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 700 | Bundle extras, |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 701 | int supportedAudioRoutes, |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 702 | boolean isEnabled, |
| 703 | String groupId) { |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 704 | mAccountHandle = account; |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 705 | mAddress = address; |
| 706 | mSubscriptionAddress = subscriptionAddress; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 707 | mCapabilities = capabilities; |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 708 | mIcon = icon; |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 709 | mHighlightColor = highlightColor; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 710 | mLabel = label; |
| 711 | mShortDescription = shortDescription; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 712 | mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes); |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 713 | mExtras = extras; |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 714 | mSupportedAudioRoutes = supportedAudioRoutes; |
Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 715 | mIsEnabled = isEnabled; |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 716 | mGroupId = groupId; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 719 | public static Builder builder( |
| 720 | PhoneAccountHandle accountHandle, |
| 721 | CharSequence label) { |
| 722 | return new Builder(accountHandle, label); |
| 723 | } |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 724 | |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 725 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 726 | * Returns a builder initialized with the current {@link PhoneAccount} instance. |
| 727 | * |
| 728 | * @return The builder. |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 729 | */ |
| 730 | public Builder toBuilder() { return new Builder(this); } |
| 731 | |
| 732 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 733 | * The unique identifier of this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 734 | * |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 735 | * @return A {@code PhoneAccountHandle}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 736 | */ |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 737 | public PhoneAccountHandle getAccountHandle() { |
| 738 | return mAccountHandle; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | /** |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 742 | * 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] | 743 | * represents the destination from which outgoing calls using this {@code PhoneAccount} |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 744 | * 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] | 745 | * {@code PhoneAccount} may be addressed. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 746 | * |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 747 | * @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] | 748 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 749 | public Uri getAddress() { |
| 750 | return mAddress; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 754 | * The raw callback number used for this {@code PhoneAccount}, as distinct from |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 755 | * {@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] | 756 | * 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] | 757 | * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)} |
| 758 | * has been used to alter the callback number. |
| 759 | * <p> |
Evan Charlton | 222db525 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 760 | * |
| 761 | * @return The subscription number, suitable for display to the user. |
| 762 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 763 | public Uri getSubscriptionAddress() { |
| 764 | return mSubscriptionAddress; |
Evan Charlton | 222db525 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 768 | * The capabilities of this {@code PhoneAccount}. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 769 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 770 | * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 771 | */ |
| 772 | public int getCapabilities() { |
| 773 | return mCapabilities; |
| 774 | } |
| 775 | |
| 776 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 777 | * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in |
| 778 | * bit mask. |
| 779 | * |
| 780 | * @param capability The capabilities to check. |
Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 781 | * @return {@code true} if the phone account has the capability. |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 782 | */ |
| 783 | public boolean hasCapabilities(int capability) { |
| 784 | return (mCapabilities & capability) == capability; |
| 785 | } |
| 786 | |
| 787 | /** |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 788 | * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask. |
| 789 | * |
| 790 | * @param route The routes to check. |
| 791 | * @return {@code true} if the phone account has the routes. |
| 792 | * @hide |
| 793 | */ |
| 794 | public boolean hasAudioRoutes(int routes) { |
| 795 | return (mSupportedAudioRoutes & routes) == routes; |
| 796 | } |
| 797 | |
| 798 | /** |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 799 | * A short label describing a {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 800 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 801 | * @return A label for this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 802 | */ |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 803 | public CharSequence getLabel() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 804 | return mLabel; |
| 805 | } |
| 806 | |
| 807 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 808 | * A short paragraph describing this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 809 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 810 | * @return A description for this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 811 | */ |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 812 | public CharSequence getShortDescription() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 813 | return mShortDescription; |
| 814 | } |
| 815 | |
| 816 | /** |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 817 | * The URI schemes supported by this {@code PhoneAccount}. |
| 818 | * |
| 819 | * @return The URI schemes. |
| 820 | */ |
| 821 | public List<String> getSupportedUriSchemes() { |
| 822 | return mSupportedUriSchemes; |
| 823 | } |
| 824 | |
| 825 | /** |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 826 | * The extras associated with this {@code PhoneAccount}. |
| 827 | * <p> |
| 828 | * A {@link ConnectionService} may provide implementation specific information about the |
| 829 | * {@link PhoneAccount} via the extras. |
| 830 | * |
| 831 | * @return The extras. |
| 832 | */ |
| 833 | public Bundle getExtras() { |
| 834 | return mExtras; |
| 835 | } |
| 836 | |
| 837 | /** |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 838 | * The audio routes supported by this {@code PhoneAccount}. |
| 839 | * |
| 840 | * @hide |
| 841 | */ |
| 842 | public int getSupportedAudioRoutes() { |
| 843 | return mSupportedAudioRoutes; |
| 844 | } |
| 845 | |
| 846 | /** |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 847 | * The icon to represent this {@code PhoneAccount}. |
| 848 | * |
| 849 | * @return The icon. |
| 850 | */ |
| 851 | public Icon getIcon() { |
| 852 | return mIcon; |
| 853 | } |
| 854 | |
| 855 | /** |
Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 856 | * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only |
| 857 | * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}. |
Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 858 | * |
Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 859 | * @return {@code true} if the account is enabled by the user, {@code false} otherwise. |
Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 860 | */ |
| 861 | public boolean isEnabled() { |
| 862 | return mIsEnabled; |
| 863 | } |
| 864 | |
| 865 | /** |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 866 | * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an |
| 867 | * empty {@link String} if the {@link PhoneAccount} is not in a group. If this |
| 868 | * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered |
| 869 | * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced, |
| 870 | * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}. |
| 871 | * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced. |
| 872 | * |
| 873 | * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group. |
| 874 | * @hide |
| 875 | */ |
| 876 | public String getGroupId() { |
| 877 | return mGroupId; |
| 878 | } |
| 879 | |
| 880 | /** |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 881 | * 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] | 882 | * scheme. |
| 883 | * |
| 884 | * @param uriScheme The URI scheme to check. |
Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 885 | * @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] | 886 | * specified URI scheme. |
| 887 | */ |
| 888 | public boolean supportsUriScheme(String uriScheme) { |
| 889 | if (mSupportedUriSchemes == null || uriScheme == null) { |
| 890 | return false; |
| 891 | } |
| 892 | |
| 893 | for (String scheme : mSupportedUriSchemes) { |
| 894 | if (scheme != null && scheme.equals(uriScheme)) { |
| 895 | return true; |
| 896 | } |
| 897 | } |
| 898 | return false; |
| 899 | } |
| 900 | |
| 901 | /** |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 902 | * A highlight color to use in displaying information about this {@code PhoneAccount}. |
| 903 | * |
| 904 | * @return A hexadecimal color value. |
| 905 | */ |
| 906 | public int getHighlightColor() { |
| 907 | return mHighlightColor; |
| 908 | } |
| 909 | |
Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 910 | /** |
| 911 | * Sets the enabled state of the phone account. |
| 912 | * @hide |
| 913 | */ |
| 914 | public void setIsEnabled(boolean isEnabled) { |
| 915 | mIsEnabled = isEnabled; |
| 916 | } |
| 917 | |
Tyler Gunn | f503543 | 2017-01-09 09:43:12 -0800 | [diff] [blame] | 918 | /** |
| 919 | * @return {@code true} if the {@link PhoneAccount} is self-managed, {@code false} otherwise. |
| 920 | * @hide |
| 921 | */ |
| 922 | public boolean isSelfManaged() { |
| 923 | return (mCapabilities & CAPABILITY_SELF_MANAGED) == CAPABILITY_SELF_MANAGED; |
| 924 | } |
| 925 | |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 926 | // |
| 927 | // Parcelable implementation |
| 928 | // |
| 929 | |
| 930 | @Override |
| 931 | public int describeContents() { |
| 932 | return 0; |
| 933 | } |
| 934 | |
| 935 | @Override |
| 936 | public void writeToParcel(Parcel out, int flags) { |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 937 | if (mAccountHandle == null) { |
| 938 | out.writeInt(0); |
| 939 | } else { |
| 940 | out.writeInt(1); |
| 941 | mAccountHandle.writeToParcel(out, flags); |
| 942 | } |
| 943 | if (mAddress == null) { |
| 944 | out.writeInt(0); |
| 945 | } else { |
| 946 | out.writeInt(1); |
| 947 | mAddress.writeToParcel(out, flags); |
| 948 | } |
| 949 | if (mSubscriptionAddress == null) { |
| 950 | out.writeInt(0); |
| 951 | } else { |
| 952 | out.writeInt(1); |
| 953 | mSubscriptionAddress.writeToParcel(out, flags); |
| 954 | } |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 955 | out.writeInt(mCapabilities); |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 956 | out.writeInt(mHighlightColor); |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 957 | out.writeCharSequence(mLabel); |
| 958 | out.writeCharSequence(mShortDescription); |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 959 | out.writeStringList(mSupportedUriSchemes); |
Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 960 | |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 961 | if (mIcon == null) { |
| 962 | out.writeInt(0); |
| 963 | } else { |
| 964 | out.writeInt(1); |
| 965 | mIcon.writeToParcel(out, flags); |
| 966 | } |
Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 967 | out.writeByte((byte) (mIsEnabled ? 1 : 0)); |
Tyler Gunn | ef829ec | 2015-10-08 09:46:23 -0700 | [diff] [blame] | 968 | out.writeBundle(mExtras); |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 969 | out.writeString(mGroupId); |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 970 | out.writeInt(mSupportedAudioRoutes); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 971 | } |
| 972 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 973 | public static final @android.annotation.NonNull Creator<PhoneAccount> CREATOR |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 974 | = new Creator<PhoneAccount>() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 975 | @Override |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 976 | public PhoneAccount createFromParcel(Parcel in) { |
| 977 | return new PhoneAccount(in); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | @Override |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 981 | public PhoneAccount[] newArray(int size) { |
| 982 | return new PhoneAccount[size]; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 983 | } |
| 984 | }; |
| 985 | |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 986 | private PhoneAccount(Parcel in) { |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 987 | if (in.readInt() > 0) { |
| 988 | mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in); |
| 989 | } else { |
| 990 | mAccountHandle = null; |
| 991 | } |
| 992 | if (in.readInt() > 0) { |
| 993 | mAddress = Uri.CREATOR.createFromParcel(in); |
| 994 | } else { |
| 995 | mAddress = null; |
| 996 | } |
| 997 | if (in.readInt() > 0) { |
| 998 | mSubscriptionAddress = Uri.CREATOR.createFromParcel(in); |
| 999 | } else { |
| 1000 | mSubscriptionAddress = null; |
| 1001 | } |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 1002 | mCapabilities = in.readInt(); |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 1003 | mHighlightColor = in.readInt(); |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 1004 | mLabel = in.readCharSequence(); |
| 1005 | mShortDescription = in.readCharSequence(); |
Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 1006 | mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList()); |
Santos Cordon | cad84a2 | 2015-05-13 11:17:25 -0700 | [diff] [blame] | 1007 | if (in.readInt() > 0) { |
| 1008 | mIcon = Icon.CREATOR.createFromParcel(in); |
| 1009 | } else { |
| 1010 | mIcon = null; |
| 1011 | } |
Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 1012 | mIsEnabled = in.readByte() == 1; |
Tyler Gunn | ef829ec | 2015-10-08 09:46:23 -0700 | [diff] [blame] | 1013 | mExtras = in.readBundle(); |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 1014 | mGroupId = in.readString(); |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 1015 | mSupportedAudioRoutes = in.readInt(); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 1016 | } |
Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 1017 | |
| 1018 | @Override |
| 1019 | public String toString() { |
Santos Cordon | 91371dc0 | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 1020 | StringBuilder sb = new StringBuilder().append("[[") |
| 1021 | .append(mIsEnabled ? 'X' : ' ') |
| 1022 | .append("] PhoneAccount: ") |
Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 1023 | .append(mAccountHandle) |
| 1024 | .append(" Capabilities: ") |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 1025 | .append(capabilitiesToString()) |
| 1026 | .append(" Audio Routes: ") |
| 1027 | .append(audioRoutesToString()) |
Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 1028 | .append(" Schemes: "); |
| 1029 | for (String scheme : mSupportedUriSchemes) { |
| 1030 | sb.append(scheme) |
| 1031 | .append(" "); |
| 1032 | } |
Tyler Gunn | ef829ec | 2015-10-08 09:46:23 -0700 | [diff] [blame] | 1033 | sb.append(" Extras: "); |
Tyler Gunn | 25ed2d7 | 2015-10-05 14:14:38 -0700 | [diff] [blame] | 1034 | sb.append(mExtras); |
Brad Ebinger | 7298f3b | 2016-06-10 17:19:42 -0700 | [diff] [blame] | 1035 | sb.append(" GroupId: "); |
| 1036 | sb.append(Log.pii(mGroupId)); |
Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 1037 | sb.append("]"); |
| 1038 | return sb.toString(); |
| 1039 | } |
Tyler Gunn | 3e122f7 | 2016-01-11 19:25:00 -0800 | [diff] [blame] | 1040 | |
| 1041 | /** |
| 1042 | * Generates a string representation of a capabilities bitmask. |
| 1043 | * |
Tyler Gunn | 3e122f7 | 2016-01-11 19:25:00 -0800 | [diff] [blame] | 1044 | * @return String representation of the capabilities bitmask. |
Tyler Gunn | 1847b4e | 2018-11-09 08:43:02 -0800 | [diff] [blame] | 1045 | * @hide |
Tyler Gunn | 3e122f7 | 2016-01-11 19:25:00 -0800 | [diff] [blame] | 1046 | */ |
Tyler Gunn | 1847b4e | 2018-11-09 08:43:02 -0800 | [diff] [blame] | 1047 | public String capabilitiesToString() { |
Tyler Gunn | 3e122f7 | 2016-01-11 19:25:00 -0800 | [diff] [blame] | 1048 | StringBuilder sb = new StringBuilder(); |
Tyler Gunn | f503543 | 2017-01-09 09:43:12 -0800 | [diff] [blame] | 1049 | if (hasCapabilities(CAPABILITY_SELF_MANAGED)) { |
| 1050 | sb.append("SelfManaged "); |
| 1051 | } |
Tyler Gunn | 58cbd7a | 2016-11-11 11:31:28 -0800 | [diff] [blame] | 1052 | if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) { |
| 1053 | sb.append("SuppVideo "); |
| 1054 | } |
Tyler Gunn | 3e122f7 | 2016-01-11 19:25:00 -0800 | [diff] [blame] | 1055 | if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) { |
| 1056 | sb.append("Video "); |
| 1057 | } |
| 1058 | if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) { |
| 1059 | sb.append("Presence "); |
| 1060 | } |
| 1061 | if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) { |
| 1062 | sb.append("CallProvider "); |
| 1063 | } |
| 1064 | if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) { |
| 1065 | sb.append("CallSubject "); |
| 1066 | } |
| 1067 | if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) { |
| 1068 | sb.append("ConnectionMgr "); |
| 1069 | } |
| 1070 | if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) { |
| 1071 | sb.append("EmergOnly "); |
| 1072 | } |
| 1073 | if (hasCapabilities(CAPABILITY_MULTI_USER)) { |
| 1074 | sb.append("MultiUser "); |
| 1075 | } |
| 1076 | if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) { |
| 1077 | sb.append("PlaceEmerg "); |
| 1078 | } |
Brad Ebinger | 3636d74 | 2019-05-21 15:28:19 -0700 | [diff] [blame] | 1079 | if (hasCapabilities(CAPABILITY_EMERGENCY_PREFERRED)) { |
| 1080 | sb.append("EmerPrefer "); |
| 1081 | } |
Tyler Gunn | cee9ea6 | 2016-03-24 11:45:43 -0700 | [diff] [blame] | 1082 | if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) { |
| 1083 | sb.append("EmergVideo "); |
| 1084 | } |
Tyler Gunn | 3e122f7 | 2016-01-11 19:25:00 -0800 | [diff] [blame] | 1085 | if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) { |
| 1086 | sb.append("SimSub "); |
| 1087 | } |
Hall Liu | 47ed620 | 2017-11-20 16:25:39 -0800 | [diff] [blame] | 1088 | if (hasCapabilities(CAPABILITY_RTT)) { |
| 1089 | sb.append("Rtt"); |
| 1090 | } |
Ravi Paluri | 80aa214 | 2019-12-02 11:57:37 +0530 | [diff] [blame] | 1091 | if (hasCapabilities(CAPABILITY_ADHOC_CONFERENCE_CALLING)) { |
| 1092 | sb.append("AdhocConf"); |
| 1093 | } |
Tyler Gunn | 3e122f7 | 2016-01-11 19:25:00 -0800 | [diff] [blame] | 1094 | return sb.toString(); |
| 1095 | } |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 1096 | |
| 1097 | private String audioRoutesToString() { |
| 1098 | StringBuilder sb = new StringBuilder(); |
| 1099 | |
| 1100 | if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) { |
| 1101 | sb.append("B"); |
| 1102 | } |
| 1103 | if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) { |
| 1104 | sb.append("E"); |
| 1105 | } |
| 1106 | if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) { |
| 1107 | sb.append("S"); |
| 1108 | } |
| 1109 | if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) { |
| 1110 | sb.append("W"); |
| 1111 | } |
| 1112 | |
| 1113 | return sb.toString(); |
| 1114 | } |
Tyler Gunn | 3b34781 | 2018-08-24 14:17:05 -0700 | [diff] [blame] | 1115 | |
| 1116 | /** |
| 1117 | * Determines if two {@link Bundle}s are equal. |
| 1118 | * @param extras First {@link Bundle} to check. |
| 1119 | * @param newExtras {@link Bundle} to compare against. |
| 1120 | * @return {@code true} if the {@link Bundle}s are equal, {@code false} otherwise. |
| 1121 | */ |
| 1122 | private static boolean areBundlesEqual(Bundle extras, Bundle newExtras) { |
| 1123 | if (extras == null || newExtras == null) { |
| 1124 | return extras == newExtras; |
| 1125 | } |
| 1126 | |
| 1127 | if (extras.size() != newExtras.size()) { |
| 1128 | return false; |
| 1129 | } |
| 1130 | |
| 1131 | for(String key : extras.keySet()) { |
| 1132 | if (key != null) { |
| 1133 | final Object value = extras.get(key); |
| 1134 | final Object newValue = newExtras.get(key); |
| 1135 | if (!Objects.equals(value, newValue)) { |
| 1136 | return false; |
| 1137 | } |
| 1138 | } |
| 1139 | } |
| 1140 | return true; |
| 1141 | } |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 1142 | } |