blob: 768c8eebf0674ab6d75d4b227a7611a876bf4a0e [file] [log] [blame]
Ihab Awad807fe0a2014-07-09 12:30:52 -07001/*
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 Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad807fe0a2014-07-09 12:30:52 -070018
Tyler Gunn754493b2020-01-27 10:30:51 -080019import static android.Manifest.permission.MODIFY_PHONE_STATE;
20
Tyler Gunn5567d742019-10-31 13:04:37 -070021import android.annotation.NonNull;
Tyler Gunn754493b2020-01-27 10:30:51 -080022import android.annotation.RequiresPermission;
Evan Charlton0e094d92014-11-08 15:49:16 -080023import android.annotation.SystemApi;
Tyler Gunn5567d742019-10-31 13:04:37 -070024import android.annotation.TestApi;
Brad Ebinger3636d742019-05-21 15:28:19 -070025import android.content.Intent;
Santos Cordoncad84a22015-05-13 11:17:25 -070026import android.graphics.drawable.Icon;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070027import android.net.Uri;
Tyler Gunn25ed2d72015-10-05 14:14:38 -070028import android.os.Bundle;
Ihab Awad807fe0a2014-07-09 12:30:52 -070029import android.os.Parcel;
30import android.os.Parcelable;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070031import android.text.TextUtils;
Ihab Awad807fe0a2014-07-09 12:30:52 -070032
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070033import java.util.ArrayList;
34import java.util.Collections;
35import java.util.List;
Tyler Gunn3b347812018-08-24 14:17:05 -070036import java.util.Objects;
Ihab Awad807fe0a2014-07-09 12:30:52 -070037
38/**
Santos Cordon32c65a52014-10-27 14:57:49 -070039 * Represents a distinct method to place or receive a phone call. Apps which can place calls and
40 * want those calls to be integrated into the dialer and in-call UI should build an instance of
Brian Attwellad147f42014-12-19 11:37:16 -080041 * this class and register it with the system using {@link TelecomManager}.
Santos Cordon32c65a52014-10-27 14:57:49 -070042 * <p>
43 * {@link TelecomManager} uses registered {@link PhoneAccount}s to present the user with
44 * alternative options when placing a phone call. When building a {@link PhoneAccount}, the app
Brian Attwellad147f42014-12-19 11:37:16 -080045 * should supply a valid {@link PhoneAccountHandle} that references the connection service
Santos Cordon32c65a52014-10-27 14:57:49 -070046 * implementation Telecom will use to interact with the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -070047 */
Yorke Lee400470f2015-05-12 13:31:25 -070048public final class PhoneAccount implements Parcelable {
Ihab Awad94cf4bf2014-07-17 11:21:19 -070049
50 /**
Tyler Gunnd426b202015-10-13 13:33:53 -070051 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
Srikanth Chintala62428402017-03-27 19:27:52 +053052 * sort order for {@link PhoneAccount}s from the same
53 * {@link android.telecom.ConnectionService}.
54 * @hide
55 */
56 public static final String EXTRA_SORT_ORDER =
57 "android.telecom.extra.SORT_ORDER";
58
59 /**
60 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
Tyler Gunnd426b202015-10-13 13:33:53 -070061 * maximum permitted length of a call subject specified via the
62 * {@link TelecomManager#EXTRA_CALL_SUBJECT} extra on an
63 * {@link android.content.Intent#ACTION_CALL} intent. Ultimately a {@link ConnectionService} is
64 * responsible for enforcing the maximum call subject length when sending the message, however
65 * this extra is provided so that the user interface can proactively limit the length of the
66 * call subject as the user types it.
67 */
68 public static final String EXTRA_CALL_SUBJECT_MAX_LENGTH =
69 "android.telecom.extra.CALL_SUBJECT_MAX_LENGTH";
70
71 /**
72 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
73 * character encoding to be used when determining the length of messages.
74 * The user interface can use this when determining the number of characters the user may type
75 * in a call subject. If empty-string, the call subject message size limit will be enforced on
76 * a 1:1 basis. That is, each character will count towards the messages size limit as a single
77 * character. If a character encoding is specified, the message size limit will be based on the
78 * number of bytes in the message per the specified encoding. See
79 * {@link #EXTRA_CALL_SUBJECT_MAX_LENGTH} for more information on the call subject maximum
80 * length.
81 */
82 public static final String EXTRA_CALL_SUBJECT_CHARACTER_ENCODING =
83 "android.telecom.extra.CALL_SUBJECT_CHARACTER_ENCODING";
84
Hall Liuba820bd2020-01-22 17:17:13 -080085 /**
86 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
87 * indicates that all calls from this {@link PhoneAccount} should be treated as VoIP calls
88 * rather than cellular calls.
Srikanth Chintalaf77d4a12017-04-03 18:08:14 +053089 * @hide
90 */
91 public static final String EXTRA_ALWAYS_USE_VOIP_AUDIO_MODE =
92 "android.telecom.extra.ALWAYS_USE_VOIP_AUDIO_MODE";
93
Tyler Gunnd426b202015-10-13 13:33:53 -070094 /**
Tyler Gunn8bf76572017-04-06 15:30:08 -070095 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
96 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
Sanket Padawea8eddd42017-11-03 11:07:35 -070097 * connection (see {@code android.telecom.Call#handoverTo()}) to this {@link PhoneAccount} from
98 * a {@link PhoneAccount} specifying {@link #EXTRA_SUPPORTS_HANDOVER_FROM}.
Tyler Gunn8bf76572017-04-06 15:30:08 -070099 * <p>
100 * A handover request is initiated by the user from the default dialer app to indicate a desire
101 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700102 */
103 public static final String EXTRA_SUPPORTS_HANDOVER_TO =
104 "android.telecom.extra.SUPPORTS_HANDOVER_TO";
105
106 /**
107 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Ta-wei Yen9d20d982017-06-02 11:07:07 -0700108 * indicates whether this {@link PhoneAccount} supports using a fallback if video calling is
109 * not available. This extra is for device level support, {@link
110 * android.telephony.CarrierConfigManager#KEY_ALLOW_VIDEO_CALLING_FALLBACK_BOOL} should also
111 * be checked to ensure it is not disabled by individual carrier.
112 *
113 * @hide
114 */
115 public static final String EXTRA_SUPPORTS_VIDEO_CALLING_FALLBACK =
116 "android.telecom.extra.SUPPORTS_VIDEO_CALLING_FALLBACK";
117
118 /**
119 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Tyler Gunn8bf76572017-04-06 15:30:08 -0700120 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
121 * connection from this {@link PhoneAccount} to another {@link PhoneAccount}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700122 * (see {@code android.telecom.Call#handoverTo()}) which specifies
Tyler Gunn8bf76572017-04-06 15:30:08 -0700123 * {@link #EXTRA_SUPPORTS_HANDOVER_TO}.
124 * <p>
125 * A handover request is initiated by the user from the default dialer app to indicate a desire
126 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700127 */
128 public static final String EXTRA_SUPPORTS_HANDOVER_FROM =
129 "android.telecom.extra.SUPPORTS_HANDOVER_FROM";
130
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700131
132 /**
133 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
134 * indicates whether a Self-Managed {@link PhoneAccount} should log its calls to the call log.
Brad Ebingerbb1a55f2017-06-26 13:26:14 -0700135 * Self-Managed {@link PhoneAccount}s are responsible for their own notifications, so the system
136 * will not create a notification when a missed call is logged.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700137 * <p>
138 * By default, Self-Managed {@link PhoneAccount}s do not log their calls to the call log.
139 * Setting this extra to {@code true} provides a means for them to log their calls.
Tyler Gunn2155c4c2018-04-05 09:43:41 -0700140 * <p>
141 * Note: Only calls where the {@link Call.Details#getHandle()} {@link Uri#getScheme()} is
142 * {@link #SCHEME_SIP} or {@link #SCHEME_TEL} will be logged at the current time.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700143 */
144 public static final String EXTRA_LOG_SELF_MANAGED_CALLS =
145 "android.telecom.extra.LOG_SELF_MANAGED_CALLS";
146
Tyler Gunn8bf76572017-04-06 15:30:08 -0700147 /**
Tyler Gunnacdb6862018-01-29 14:30:52 -0800148 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
149 * indicates whether calls for a {@link PhoneAccount} should generate a "call recording tone"
150 * when the user is recording audio on the device.
151 * <p>
152 * The call recording tone is played over the telephony audio stream so that the remote party
153 * has an audible indication that it is possible their call is being recorded using a call
154 * recording app on the device.
155 * <p>
156 * This extra only has an effect for calls placed via Telephony (e.g.
157 * {@link #CAPABILITY_SIM_SUBSCRIPTION}).
158 * <p>
159 * The call recording tone is a 1400 hz tone which repeats every 15 seconds while recording is
160 * in progress.
161 * @hide
162 */
163 public static final String EXTRA_PLAY_CALL_RECORDING_TONE =
164 "android.telecom.extra.PLAY_CALL_RECORDING_TONE";
165
166 /**
Sean Kelley4d3c1782018-05-22 14:35:27 -0700167 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()} which
168 * indicates whether calls for a {@link PhoneAccount} should skip call filtering.
169 * <p>
170 * If not specified, this will default to false; all calls will undergo call filtering unless
171 * specifically exempted (e.g. {@link Connection#PROPERTY_EMERGENCY_CALLBACK_MODE}.) However,
172 * this may be used to skip call filtering when it has already been performed on another device.
173 * @hide
174 */
175 public static final String EXTRA_SKIP_CALL_FILTERING =
176 "android.telecom.extra.SKIP_CALL_FILTERING";
177
178 /**
Ihab Awadf8b69882014-07-25 15:14:01 -0700179 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
180 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
181 * will be allowed to manage phone calls including using its own proprietary phone-call
182 * implementation (like VoIP calling) to make calls instead of the telephony stack.
183 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700184 * When a user opts to place a call using the SIM-based telephony stack, the
185 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
186 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700187 * <p>
188 * See {@link #getCapabilities}
189 */
Ihab Awadf8b69882014-07-25 15:14:01 -0700190 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700191
192 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700193 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -0700194 * traditional SIM-based telephony calls. This account will be treated as a distinct method
195 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -0700196 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -0700197 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700198 * <p>
199 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700200 * <p>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700201 */
202 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
203
Ihab Awad7522bbd62014-07-18 15:53:17 -0700204 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700205 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -0700206 * subscription.
Ihab Awad7522bbd62014-07-18 15:53:17 -0700207 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700208 * Only the Android framework can register a {@code PhoneAccount} having this capability.
209 * <p>
210 * See {@link #getCapabilities}
Ihab Awad7522bbd62014-07-18 15:53:17 -0700211 */
212 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
213
Ihab Awadf8b69882014-07-25 15:14:01 -0700214 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800215 * Flag indicating that this {@code PhoneAccount} is currently able to place video calls.
216 * <p>
217 * See also {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING} which indicates whether the
218 * {@code PhoneAccount} supports placing video calls.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700219 * <p>
220 * See {@link #getCapabilities}
Ihab Awadf8b69882014-07-25 15:14:01 -0700221 */
222 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
223
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700224 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700225 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
226 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
227 * <p>
228 * See {@link #getCapabilities}
229 */
230 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
231
232 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800233 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
234 * should only be used by system apps (and will be ignored for all other apps trying to use it).
235 * <p>
236 * See {@link #getCapabilities}
237 * @hide
238 */
Brian Attwellad147f42014-12-19 11:37:16 -0800239 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800240 public static final int CAPABILITY_MULTI_USER = 0x20;
241
242 /**
Tyler Gunn65a3d342015-07-27 16:06:16 -0700243 * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a
244 * caller is able to specify a short subject line for an outgoing call. A capable receiving
245 * device displays the call subject on the incoming call screen.
246 * <p>
247 * See {@link #getCapabilities}
248 */
249 public static final int CAPABILITY_CALL_SUBJECT = 0x40;
250
251 /**
Bryce Leeb96d89c2015-10-14 16:48:40 -0700252 * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls.
253 * <p>
254 * See {@link #getCapabilities}
255 * @hide
256 */
257 public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80;
258
259 /**
Tyler Gunn9a365752015-12-09 15:00:18 -0800260 * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a
261 * number relies on presence. Should only be set if the {@code PhoneAccount} also has
262 * {@link #CAPABILITY_VIDEO_CALLING}.
263 * <p>
264 * When set, the {@link ConnectionService} is responsible for toggling the
265 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the
266 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether
267 * a contact's phone number supports video calling.
268 * <p>
269 * See {@link #getCapabilities}
270 */
271 public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100;
272
273 /**
Tyler Gunncee9ea62016-03-24 11:45:43 -0700274 * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed.
275 * <p>
276 * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will
277 * convert all outgoing video calls to emergency numbers to audio-only.
278 * @hide
279 */
280 public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200;
281
282 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800283 * Flag indicating that this {@link PhoneAccount} supports video calling.
284 * This is not an indication that the {@link PhoneAccount} is currently able to make a video
285 * call, but rather that it has the ability to make video calls (but not necessarily at this
286 * time).
287 * <p>
288 * Whether a {@link PhoneAccount} can make a video call is ultimately controlled by
289 * {@link #CAPABILITY_VIDEO_CALLING}, which indicates whether the {@link PhoneAccount} is
290 * currently capable of making a video call. Consider a case where, for example, a
291 * {@link PhoneAccount} supports making video calls (e.g.
292 * {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING}), but a current lack of network connectivity
293 * prevents video calls from being made (e.g. {@link #CAPABILITY_VIDEO_CALLING}).
294 * <p>
295 * See {@link #getCapabilities}
296 */
297 public static final int CAPABILITY_SUPPORTS_VIDEO_CALLING = 0x400;
298
299 /**
Tyler Gunnf5035432017-01-09 09:43:12 -0800300 * Flag indicating that this {@link PhoneAccount} is responsible for managing its own
301 * {@link Connection}s. This type of {@link PhoneAccount} is ideal for use with standalone
302 * calling apps which do not wish to use the default phone app for {@link Connection} UX,
303 * but which want to leverage the call and audio routing capabilities of the Telecom framework.
304 * <p>
305 * When set, {@link Connection}s created by the self-managed {@link ConnectionService} will not
306 * be surfaced to implementations of the {@link InCallService} API. Thus it is the
307 * responsibility of a self-managed {@link ConnectionService} to provide a user interface for
308 * its {@link Connection}s.
309 * <p>
310 * Self-managed {@link Connection}s will, however, be displayed on connected Bluetooth devices.
311 */
312 public static final int CAPABILITY_SELF_MANAGED = 0x800;
313
314 /**
Hall Liu95d55872017-01-25 17:12:49 -0800315 * Flag indicating that this {@link PhoneAccount} is capable of making a call with an
316 * RTT (Real-time text) session.
317 * When set, Telecom will attempt to open an RTT session on outgoing calls that specify
318 * that they should be placed with an RTT session , and the in-call app will be displayed
319 * with text entry fields for RTT. Likewise, the in-call app can request that an RTT
320 * session be opened during a call if this bit is set.
321 */
322 public static final int CAPABILITY_RTT = 0x1000;
323
Brad Ebinger3636d742019-05-21 15:28:19 -0700324 /**
325 * Flag indicating that this {@link PhoneAccount} is the preferred SIM subscription for
326 * emergency calls. A {@link PhoneAccount} that sets this capabilitiy must also
327 * set the {@link #CAPABILITY_SIM_SUBSCRIPTION} and {@link #CAPABILITY_PLACE_EMERGENCY_CALLS}
328 * capabilities. There should only be one emergency preferred {@link PhoneAccount}.
329 * <p>
330 * When set, Telecom will prefer this {@link PhoneAccount} over others for emergency calling,
331 * even if the emergency call was placed with a specific {@link PhoneAccount} set using the
332 * extra{@link TelecomManager#EXTRA_PHONE_ACCOUNT_HANDLE} in
333 * {@link Intent#ACTION_CALL_EMERGENCY} or {@link TelecomManager#placeCall(Uri, Bundle)}.
334 *
335 * @hide
336 */
337 public static final int CAPABILITY_EMERGENCY_PREFERRED = 0x2000;
338
Ravi Paluri80aa2142019-12-02 11:57:37 +0530339 /**
340 * An adhoc conference call is established by providing a list of addresses to
341 * {@code TelecomManager#startConference(List<Uri>, int videoState)} where the
342 * {@link ConnectionService} is responsible for connecting all indicated participants
343 * to a conference simultaneously.
344 * This is in contrast to conferences formed by merging calls together (e.g. using
345 * {@link android.telecom.Call#mergeConference()}).
346 */
347 public static final int CAPABILITY_ADHOC_CONFERENCE_CALLING = 0x4000;
348
349 /* NEXT CAPABILITY: 0x8000 */
Hall Liu95d55872017-01-25 17:12:49 -0800350
351 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700352 * URI scheme for telephone number URIs.
353 */
354 public static final String SCHEME_TEL = "tel";
355
356 /**
357 * URI scheme for voicemail URIs.
358 */
359 public static final String SCHEME_VOICEMAIL = "voicemail";
360
361 /**
362 * URI scheme for SIP URIs.
363 */
364 public static final String SCHEME_SIP = "sip";
365
Nancy Chen3ace54b2014-10-22 17:45:26 -0700366 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800367 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700368 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700369 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800370 public static final int NO_ICON_TINT = 0;
371
372 /**
373 * Indicating no hightlight color is set.
374 */
375 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700376
Ihab Awad476cc832014-11-03 09:47:51 -0800377 /**
378 * Indicating no resource ID is set.
379 */
380 public static final int NO_RESOURCE_ID = -1;
381
Evan Charlton8c8a0622014-07-20 12:31:00 -0700382 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700383 private final Uri mAddress;
384 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700385 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800386 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700387 private final CharSequence mLabel;
388 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700389 private final List<String> mSupportedUriSchemes;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800390 private final int mSupportedAudioRoutes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700391 private final Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700392 private final Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700393 private boolean mIsEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700394 private String mGroupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700395
Tyler Gunn3b347812018-08-24 14:17:05 -0700396 @Override
397 public boolean equals(Object o) {
398 if (this == o) return true;
399 if (o == null || getClass() != o.getClass()) return false;
400 PhoneAccount that = (PhoneAccount) o;
401 return mCapabilities == that.mCapabilities &&
402 mHighlightColor == that.mHighlightColor &&
403 mSupportedAudioRoutes == that.mSupportedAudioRoutes &&
404 mIsEnabled == that.mIsEnabled &&
405 Objects.equals(mAccountHandle, that.mAccountHandle) &&
406 Objects.equals(mAddress, that.mAddress) &&
407 Objects.equals(mSubscriptionAddress, that.mSubscriptionAddress) &&
408 Objects.equals(mLabel, that.mLabel) &&
409 Objects.equals(mShortDescription, that.mShortDescription) &&
410 Objects.equals(mSupportedUriSchemes, that.mSupportedUriSchemes) &&
411 areBundlesEqual(mExtras, that.mExtras) &&
412 Objects.equals(mGroupId, that.mGroupId);
413 }
414
415 @Override
416 public int hashCode() {
417 return Objects.hash(mAccountHandle, mAddress, mSubscriptionAddress, mCapabilities,
418 mHighlightColor, mLabel, mShortDescription, mSupportedUriSchemes,
419 mSupportedAudioRoutes,
420 mExtras, mIsEnabled, mGroupId);
421 }
422
Santos Cordon32c65a52014-10-27 14:57:49 -0700423 /**
424 * Helper class for creating a {@link PhoneAccount}.
425 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700426 public static class Builder {
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800427
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700428 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700429 private Uri mAddress;
430 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700431 private int mCapabilities;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800432 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800433 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700434 private CharSequence mLabel;
435 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700436 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700437 private Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700438 private Bundle mExtras;
Santos Cordon91371dc02015-05-08 13:52:09 -0700439 private boolean mIsEnabled = false;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700440 private String mGroupId = "";
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700441
Santos Cordon32c65a52014-10-27 14:57:49 -0700442 /**
443 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
444 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700445 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
446 this.mAccountHandle = accountHandle;
447 this.mLabel = label;
448 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700449
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700450 /**
451 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
452 * {@link PhoneAccount}.
453 *
454 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
455 */
456 public Builder(PhoneAccount phoneAccount) {
457 mAccountHandle = phoneAccount.getAccountHandle();
458 mAddress = phoneAccount.getAddress();
459 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
460 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800461 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700462 mLabel = phoneAccount.getLabel();
463 mShortDescription = phoneAccount.getShortDescription();
464 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700465 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc02015-05-08 13:52:09 -0700466 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunnd426b202015-10-13 13:33:53 -0700467 mExtras = phoneAccount.getExtras();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700468 mGroupId = phoneAccount.getGroupId();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800469 mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700470 }
471
Santos Cordon32c65a52014-10-27 14:57:49 -0700472 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700473 * Sets the label. See {@link PhoneAccount#getLabel()}.
474 *
475 * @param label The label of the phone account.
476 * @return The builder.
477 * @hide
478 */
479 public Builder setLabel(CharSequence label) {
480 this.mLabel = label;
481 return this;
482 }
483
484 /**
Santos Cordon32c65a52014-10-27 14:57:49 -0700485 * Sets the address. See {@link PhoneAccount#getAddress}.
486 *
487 * @param value The address of the phone account.
488 * @return The builder.
489 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700490 public Builder setAddress(Uri value) {
491 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700492 return this;
493 }
494
Santos Cordon32c65a52014-10-27 14:57:49 -0700495 /**
496 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
497 *
498 * @param value The subscription address.
499 * @return The builder.
500 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700501 public Builder setSubscriptionAddress(Uri value) {
502 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700503 return this;
504 }
505
Santos Cordon32c65a52014-10-27 14:57:49 -0700506 /**
507 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
508 *
509 * @param value The capabilities to set.
510 * @return The builder.
511 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700512 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700513 this.mCapabilities = value;
514 return this;
515 }
516
Santos Cordon32c65a52014-10-27 14:57:49 -0700517 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700518 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700519 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700520 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700521 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700522 public Builder setIcon(Icon icon) {
523 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700524 return this;
525 }
526
527 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800528 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700529 *
Ihab Awad476cc832014-11-03 09:47:51 -0800530 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700531 * @return The builder.
532 */
Ihab Awad476cc832014-11-03 09:47:51 -0800533 public Builder setHighlightColor(int value) {
534 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700535 return this;
536 }
537
Santos Cordon32c65a52014-10-27 14:57:49 -0700538 /**
539 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
540 *
541 * @param value The short description.
542 * @return The builder.
543 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700544 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700545 this.mShortDescription = value;
546 return this;
547 }
548
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700549 /**
550 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
551 *
552 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700553 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700554 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700555 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700556 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
557 this.mSupportedUriSchemes.add(uriScheme);
558 }
559 return this;
560 }
561
562 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700563 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700564 *
565 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700566 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700567 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700568 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
569 mSupportedUriSchemes.clear();
570
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700571 if (uriSchemes != null && !uriSchemes.isEmpty()) {
572 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700573 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700574 }
575 }
576 return this;
577 }
578
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700579 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700580 * Specifies the extras associated with the {@link PhoneAccount}.
581 * <p>
582 * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer},
583 * and {@link Boolean}. Extras which are not of these types are ignored.
584 *
585 * @param extras
586 * @return
587 */
588 public Builder setExtras(Bundle extras) {
589 mExtras = extras;
590 return this;
591 }
592
593 /**
Santos Cordon91371dc02015-05-08 13:52:09 -0700594 * Sets the enabled state of the phone account.
595 *
596 * @param isEnabled The enabled state.
597 * @return The builder.
598 * @hide
599 */
600 public Builder setIsEnabled(boolean isEnabled) {
601 mIsEnabled = isEnabled;
602 return this;
603 }
604
605 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700606 * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is
607 * registered to Telecom, it will replace another {@link PhoneAccount} that is already
608 * registered in Telecom and take on the current user defaults and enabled status. There can
609 * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a
610 * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only
611 * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced.
Tyler Gunn5567d742019-10-31 13:04:37 -0700612 * <p>
Tyler Gunn754493b2020-01-27 10:30:51 -0800613 * Note: This is an API specific to the Telephony stack; the group Id will be ignored for
614 * callers not holding the correct permission.
Tyler Gunn5567d742019-10-31 13:04:37 -0700615 *
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700616 * @param groupId The group Id of the {@link PhoneAccount} that will replace any other
617 * registered {@link PhoneAccount} in Telecom with the same Group Id.
618 * @return The builder
619 * @hide
620 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700621 @SystemApi
622 @TestApi
Tyler Gunn754493b2020-01-27 10:30:51 -0800623 @RequiresPermission(MODIFY_PHONE_STATE)
Tyler Gunn5567d742019-10-31 13:04:37 -0700624 public @NonNull Builder setGroupId(@NonNull String groupId) {
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700625 if (groupId != null) {
626 mGroupId = groupId;
627 } else {
628 mGroupId = "";
629 }
630 return this;
631 }
632
633 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800634 * Sets the audio routes supported by this {@link PhoneAccount}.
635 *
636 * @param routes bit mask of available routes.
637 * @return The builder.
638 * @hide
639 */
640 public Builder setSupportedAudioRoutes(int routes) {
641 mSupportedAudioRoutes = routes;
642 return this;
643 }
644
645 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700646 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
647 *
648 * @return The {@link PhoneAccount}.
649 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700650 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700651 // If no supported URI schemes were defined, assume "tel" is supported.
652 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700653 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700654 }
655
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700656 return new PhoneAccount(
657 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700658 mAddress,
659 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700660 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700661 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800662 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700663 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700664 mShortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700665 mSupportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700666 mExtras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800667 mSupportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700668 mIsEnabled,
669 mGroupId);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700670 }
671 }
672
673 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700674 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700675 Uri address,
676 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700677 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700678 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800679 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700680 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700681 CharSequence shortDescription,
Santos Cordon91371dc02015-05-08 13:52:09 -0700682 List<String> supportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700683 Bundle extras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800684 int supportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700685 boolean isEnabled,
686 String groupId) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700687 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700688 mAddress = address;
689 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700690 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700691 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800692 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700693 mLabel = label;
694 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700695 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700696 mExtras = extras;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800697 mSupportedAudioRoutes = supportedAudioRoutes;
Santos Cordon91371dc02015-05-08 13:52:09 -0700698 mIsEnabled = isEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700699 mGroupId = groupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700700 }
701
Andrew Lee3085a6c2014-09-04 10:59:13 -0700702 public static Builder builder(
703 PhoneAccountHandle accountHandle,
704 CharSequence label) {
705 return new Builder(accountHandle, label);
706 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700707
Ihab Awad807fe0a2014-07-09 12:30:52 -0700708 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700709 * Returns a builder initialized with the current {@link PhoneAccount} instance.
710 *
711 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700712 */
713 public Builder toBuilder() { return new Builder(this); }
714
715 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700716 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700717 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700718 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700719 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700720 public PhoneAccountHandle getAccountHandle() {
721 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700722 }
723
724 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700725 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700726 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700727 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700728 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700729 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700730 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700731 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700732 public Uri getAddress() {
733 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700734 }
735
736 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700737 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700738 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700739 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000740 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
741 * has been used to alter the callback number.
742 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700743 *
744 * @return The subscription number, suitable for display to the user.
745 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700746 public Uri getSubscriptionAddress() {
747 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700748 }
749
750 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700751 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700752 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700753 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700754 */
755 public int getCapabilities() {
756 return mCapabilities;
757 }
758
759 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700760 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
761 * bit mask.
762 *
763 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700764 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700765 */
766 public boolean hasCapabilities(int capability) {
767 return (mCapabilities & capability) == capability;
768 }
769
770 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800771 * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask.
772 *
773 * @param route The routes to check.
774 * @return {@code true} if the phone account has the routes.
775 * @hide
776 */
777 public boolean hasAudioRoutes(int routes) {
778 return (mSupportedAudioRoutes & routes) == routes;
779 }
780
781 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700782 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700783 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700784 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700785 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700786 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700787 return mLabel;
788 }
789
790 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700791 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700792 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700793 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700794 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700795 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700796 return mShortDescription;
797 }
798
799 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700800 * The URI schemes supported by this {@code PhoneAccount}.
801 *
802 * @return The URI schemes.
803 */
804 public List<String> getSupportedUriSchemes() {
805 return mSupportedUriSchemes;
806 }
807
808 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700809 * The extras associated with this {@code PhoneAccount}.
810 * <p>
811 * A {@link ConnectionService} may provide implementation specific information about the
812 * {@link PhoneAccount} via the extras.
813 *
814 * @return The extras.
815 */
816 public Bundle getExtras() {
817 return mExtras;
818 }
819
820 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800821 * The audio routes supported by this {@code PhoneAccount}.
822 *
823 * @hide
824 */
825 public int getSupportedAudioRoutes() {
826 return mSupportedAudioRoutes;
827 }
828
829 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700830 * The icon to represent this {@code PhoneAccount}.
831 *
832 * @return The icon.
833 */
834 public Icon getIcon() {
835 return mIcon;
836 }
837
838 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700839 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
840 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc02015-05-08 13:52:09 -0700841 *
Santos Cordon895d4b82015-06-25 16:41:48 -0700842 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc02015-05-08 13:52:09 -0700843 */
844 public boolean isEnabled() {
845 return mIsEnabled;
846 }
847
848 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700849 * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an
850 * empty {@link String} if the {@link PhoneAccount} is not in a group. If this
851 * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered
852 * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced,
853 * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}.
854 * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced.
855 *
856 * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group.
857 * @hide
858 */
859 public String getGroupId() {
860 return mGroupId;
861 }
862
863 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700864 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700865 * scheme.
866 *
867 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700868 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700869 * specified URI scheme.
870 */
871 public boolean supportsUriScheme(String uriScheme) {
872 if (mSupportedUriSchemes == null || uriScheme == null) {
873 return false;
874 }
875
876 for (String scheme : mSupportedUriSchemes) {
877 if (scheme != null && scheme.equals(uriScheme)) {
878 return true;
879 }
880 }
881 return false;
882 }
883
884 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800885 * A highlight color to use in displaying information about this {@code PhoneAccount}.
886 *
887 * @return A hexadecimal color value.
888 */
889 public int getHighlightColor() {
890 return mHighlightColor;
891 }
892
Santos Cordon91371dc02015-05-08 13:52:09 -0700893 /**
894 * Sets the enabled state of the phone account.
895 * @hide
896 */
897 public void setIsEnabled(boolean isEnabled) {
898 mIsEnabled = isEnabled;
899 }
900
Tyler Gunnf5035432017-01-09 09:43:12 -0800901 /**
902 * @return {@code true} if the {@link PhoneAccount} is self-managed, {@code false} otherwise.
903 * @hide
904 */
905 public boolean isSelfManaged() {
906 return (mCapabilities & CAPABILITY_SELF_MANAGED) == CAPABILITY_SELF_MANAGED;
907 }
908
Ihab Awad807fe0a2014-07-09 12:30:52 -0700909 //
910 // Parcelable implementation
911 //
912
913 @Override
914 public int describeContents() {
915 return 0;
916 }
917
918 @Override
919 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800920 if (mAccountHandle == null) {
921 out.writeInt(0);
922 } else {
923 out.writeInt(1);
924 mAccountHandle.writeToParcel(out, flags);
925 }
926 if (mAddress == null) {
927 out.writeInt(0);
928 } else {
929 out.writeInt(1);
930 mAddress.writeToParcel(out, flags);
931 }
932 if (mSubscriptionAddress == null) {
933 out.writeInt(0);
934 } else {
935 out.writeInt(1);
936 mSubscriptionAddress.writeToParcel(out, flags);
937 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700938 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800939 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700940 out.writeCharSequence(mLabel);
941 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800942 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc02015-05-08 13:52:09 -0700943
Santos Cordoncad84a22015-05-13 11:17:25 -0700944 if (mIcon == null) {
945 out.writeInt(0);
946 } else {
947 out.writeInt(1);
948 mIcon.writeToParcel(out, flags);
949 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700950 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Tyler Gunnef829ec2015-10-08 09:46:23 -0700951 out.writeBundle(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700952 out.writeString(mGroupId);
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800953 out.writeInt(mSupportedAudioRoutes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700954 }
955
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700956 public static final @android.annotation.NonNull Creator<PhoneAccount> CREATOR
Evan Charlton8c8a0622014-07-20 12:31:00 -0700957 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700958 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700959 public PhoneAccount createFromParcel(Parcel in) {
960 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700961 }
962
963 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700964 public PhoneAccount[] newArray(int size) {
965 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700966 }
967 };
968
Evan Charlton8c8a0622014-07-20 12:31:00 -0700969 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800970 if (in.readInt() > 0) {
971 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
972 } else {
973 mAccountHandle = null;
974 }
975 if (in.readInt() > 0) {
976 mAddress = Uri.CREATOR.createFromParcel(in);
977 } else {
978 mAddress = null;
979 }
980 if (in.readInt() > 0) {
981 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
982 } else {
983 mSubscriptionAddress = null;
984 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700985 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -0800986 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700987 mLabel = in.readCharSequence();
988 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800989 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -0700990 if (in.readInt() > 0) {
991 mIcon = Icon.CREATOR.createFromParcel(in);
992 } else {
993 mIcon = null;
994 }
Santos Cordon91371dc02015-05-08 13:52:09 -0700995 mIsEnabled = in.readByte() == 1;
Tyler Gunnef829ec2015-10-08 09:46:23 -0700996 mExtras = in.readBundle();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700997 mGroupId = in.readString();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800998 mSupportedAudioRoutes = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700999 }
Tyler Gunn76c01a52014-09-30 14:47:51 -07001000
1001 @Override
1002 public String toString() {
Santos Cordon91371dc02015-05-08 13:52:09 -07001003 StringBuilder sb = new StringBuilder().append("[[")
1004 .append(mIsEnabled ? 'X' : ' ')
1005 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -07001006 .append(mAccountHandle)
1007 .append(" Capabilities: ")
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001008 .append(capabilitiesToString())
1009 .append(" Audio Routes: ")
1010 .append(audioRoutesToString())
Tyler Gunn76c01a52014-09-30 14:47:51 -07001011 .append(" Schemes: ");
1012 for (String scheme : mSupportedUriSchemes) {
1013 sb.append(scheme)
1014 .append(" ");
1015 }
Tyler Gunnef829ec2015-10-08 09:46:23 -07001016 sb.append(" Extras: ");
Tyler Gunn25ed2d72015-10-05 14:14:38 -07001017 sb.append(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -07001018 sb.append(" GroupId: ");
1019 sb.append(Log.pii(mGroupId));
Tyler Gunn76c01a52014-09-30 14:47:51 -07001020 sb.append("]");
1021 return sb.toString();
1022 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001023
1024 /**
1025 * Generates a string representation of a capabilities bitmask.
1026 *
Tyler Gunn3e122f72016-01-11 19:25:00 -08001027 * @return String representation of the capabilities bitmask.
Tyler Gunn1847b4e2018-11-09 08:43:02 -08001028 * @hide
Tyler Gunn3e122f72016-01-11 19:25:00 -08001029 */
Tyler Gunn1847b4e2018-11-09 08:43:02 -08001030 public String capabilitiesToString() {
Tyler Gunn3e122f72016-01-11 19:25:00 -08001031 StringBuilder sb = new StringBuilder();
Tyler Gunnf5035432017-01-09 09:43:12 -08001032 if (hasCapabilities(CAPABILITY_SELF_MANAGED)) {
1033 sb.append("SelfManaged ");
1034 }
Tyler Gunn58cbd7a2016-11-11 11:31:28 -08001035 if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) {
1036 sb.append("SuppVideo ");
1037 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001038 if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) {
1039 sb.append("Video ");
1040 }
1041 if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
1042 sb.append("Presence ");
1043 }
1044 if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) {
1045 sb.append("CallProvider ");
1046 }
1047 if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) {
1048 sb.append("CallSubject ");
1049 }
1050 if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) {
1051 sb.append("ConnectionMgr ");
1052 }
1053 if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) {
1054 sb.append("EmergOnly ");
1055 }
1056 if (hasCapabilities(CAPABILITY_MULTI_USER)) {
1057 sb.append("MultiUser ");
1058 }
1059 if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) {
1060 sb.append("PlaceEmerg ");
1061 }
Brad Ebinger3636d742019-05-21 15:28:19 -07001062 if (hasCapabilities(CAPABILITY_EMERGENCY_PREFERRED)) {
1063 sb.append("EmerPrefer ");
1064 }
Tyler Gunncee9ea62016-03-24 11:45:43 -07001065 if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
1066 sb.append("EmergVideo ");
1067 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001068 if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) {
1069 sb.append("SimSub ");
1070 }
Hall Liu47ed6202017-11-20 16:25:39 -08001071 if (hasCapabilities(CAPABILITY_RTT)) {
1072 sb.append("Rtt");
1073 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05301074 if (hasCapabilities(CAPABILITY_ADHOC_CONFERENCE_CALLING)) {
1075 sb.append("AdhocConf");
1076 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001077 return sb.toString();
1078 }
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001079
1080 private String audioRoutesToString() {
1081 StringBuilder sb = new StringBuilder();
1082
1083 if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) {
1084 sb.append("B");
1085 }
1086 if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) {
1087 sb.append("E");
1088 }
1089 if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) {
1090 sb.append("S");
1091 }
1092 if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) {
1093 sb.append("W");
1094 }
1095
1096 return sb.toString();
1097 }
Tyler Gunn3b347812018-08-24 14:17:05 -07001098
1099 /**
1100 * Determines if two {@link Bundle}s are equal.
1101 * @param extras First {@link Bundle} to check.
1102 * @param newExtras {@link Bundle} to compare against.
1103 * @return {@code true} if the {@link Bundle}s are equal, {@code false} otherwise.
1104 */
1105 private static boolean areBundlesEqual(Bundle extras, Bundle newExtras) {
1106 if (extras == null || newExtras == null) {
1107 return extras == newExtras;
1108 }
1109
1110 if (extras.size() != newExtras.size()) {
1111 return false;
1112 }
1113
1114 for(String key : extras.keySet()) {
1115 if (key != null) {
1116 final Object value = extras.get(key);
1117 final Object newValue = newExtras.get(key);
1118 if (!Objects.equals(value, newValue)) {
1119 return false;
1120 }
1121 }
1122 }
1123 return true;
1124 }
Ihab Awad807fe0a2014-07-09 12:30:52 -07001125}