blob: 2ffad0345c64a36909b00296ebab71876e6652c9 [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
Evan Charlton0e094d92014-11-08 15:49:16 -080019import android.annotation.SystemApi;
Santos Cordoncad84a22015-05-13 11:17:25 -070020import android.graphics.drawable.Icon;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070021import android.net.Uri;
Tyler Gunn25ed2d72015-10-05 14:14:38 -070022import android.os.Bundle;
Ihab Awad807fe0a2014-07-09 12:30:52 -070023import android.os.Parcel;
24import android.os.Parcelable;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070025import android.text.TextUtils;
Ihab Awad807fe0a2014-07-09 12:30:52 -070026
Tyler Gunnf5b29dc2014-09-03 09:09:12 -070027import java.lang.String;
28import java.util.ArrayList;
29import java.util.Collections;
30import java.util.List;
Tyler Gunn3b347812018-08-24 14:17:05 -070031import java.util.Objects;
Ihab Awad807fe0a2014-07-09 12:30:52 -070032
33/**
Santos Cordon32c65a52014-10-27 14:57:49 -070034 * Represents a distinct method to place or receive a phone call. Apps which can place calls and
35 * 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 -080036 * this class and register it with the system using {@link TelecomManager}.
Santos Cordon32c65a52014-10-27 14:57:49 -070037 * <p>
38 * {@link TelecomManager} uses registered {@link PhoneAccount}s to present the user with
39 * alternative options when placing a phone call. When building a {@link PhoneAccount}, the app
Brian Attwellad147f42014-12-19 11:37:16 -080040 * should supply a valid {@link PhoneAccountHandle} that references the connection service
Santos Cordon32c65a52014-10-27 14:57:49 -070041 * implementation Telecom will use to interact with the app.
Ihab Awad807fe0a2014-07-09 12:30:52 -070042 */
Yorke Lee400470f2015-05-12 13:31:25 -070043public final class PhoneAccount implements Parcelable {
Ihab Awad94cf4bf2014-07-17 11:21:19 -070044
45 /**
Tyler Gunnd426b202015-10-13 13:33:53 -070046 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
Srikanth Chintala62428402017-03-27 19:27:52 +053047 * sort order for {@link PhoneAccount}s from the same
48 * {@link android.telecom.ConnectionService}.
49 * @hide
50 */
51 public static final String EXTRA_SORT_ORDER =
52 "android.telecom.extra.SORT_ORDER";
53
54 /**
55 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
Tyler Gunnd426b202015-10-13 13:33:53 -070056 * maximum permitted length of a call subject specified via the
57 * {@link TelecomManager#EXTRA_CALL_SUBJECT} extra on an
58 * {@link android.content.Intent#ACTION_CALL} intent. Ultimately a {@link ConnectionService} is
59 * responsible for enforcing the maximum call subject length when sending the message, however
60 * this extra is provided so that the user interface can proactively limit the length of the
61 * call subject as the user types it.
62 */
63 public static final String EXTRA_CALL_SUBJECT_MAX_LENGTH =
64 "android.telecom.extra.CALL_SUBJECT_MAX_LENGTH";
65
66 /**
67 * {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which determines the
68 * character encoding to be used when determining the length of messages.
69 * The user interface can use this when determining the number of characters the user may type
70 * in a call subject. If empty-string, the call subject message size limit will be enforced on
71 * a 1:1 basis. That is, each character will count towards the messages size limit as a single
72 * character. If a character encoding is specified, the message size limit will be based on the
73 * number of bytes in the message per the specified encoding. See
74 * {@link #EXTRA_CALL_SUBJECT_MAX_LENGTH} for more information on the call subject maximum
75 * length.
76 */
77 public static final String EXTRA_CALL_SUBJECT_CHARACTER_ENCODING =
78 "android.telecom.extra.CALL_SUBJECT_CHARACTER_ENCODING";
79
Srikanth Chintalaf77d4a12017-04-03 18:08:14 +053080 /**
81 * Indicating flag for phone account whether to use voip audio mode for voip calls
82 * @hide
83 */
84 public static final String EXTRA_ALWAYS_USE_VOIP_AUDIO_MODE =
85 "android.telecom.extra.ALWAYS_USE_VOIP_AUDIO_MODE";
86
Tyler Gunnd426b202015-10-13 13:33:53 -070087 /**
Tyler Gunn8bf76572017-04-06 15:30:08 -070088 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
89 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
Sanket Padawea8eddd42017-11-03 11:07:35 -070090 * connection (see {@code android.telecom.Call#handoverTo()}) to this {@link PhoneAccount} from
91 * a {@link PhoneAccount} specifying {@link #EXTRA_SUPPORTS_HANDOVER_FROM}.
Tyler Gunn8bf76572017-04-06 15:30:08 -070092 * <p>
93 * A handover request is initiated by the user from the default dialer app to indicate a desire
94 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
Tyler Gunn8bf76572017-04-06 15:30:08 -070095 */
96 public static final String EXTRA_SUPPORTS_HANDOVER_TO =
97 "android.telecom.extra.SUPPORTS_HANDOVER_TO";
98
99 /**
100 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Ta-wei Yen9d20d982017-06-02 11:07:07 -0700101 * indicates whether this {@link PhoneAccount} supports using a fallback if video calling is
102 * not available. This extra is for device level support, {@link
103 * android.telephony.CarrierConfigManager#KEY_ALLOW_VIDEO_CALLING_FALLBACK_BOOL} should also
104 * be checked to ensure it is not disabled by individual carrier.
105 *
106 * @hide
107 */
108 public static final String EXTRA_SUPPORTS_VIDEO_CALLING_FALLBACK =
109 "android.telecom.extra.SUPPORTS_VIDEO_CALLING_FALLBACK";
110
111 /**
112 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
Tyler Gunn8bf76572017-04-06 15:30:08 -0700113 * indicates whether this {@link PhoneAccount} is capable of supporting a request to handover a
114 * connection from this {@link PhoneAccount} to another {@link PhoneAccount}.
Sanket Padawea8eddd42017-11-03 11:07:35 -0700115 * (see {@code android.telecom.Call#handoverTo()}) which specifies
Tyler Gunn8bf76572017-04-06 15:30:08 -0700116 * {@link #EXTRA_SUPPORTS_HANDOVER_TO}.
117 * <p>
118 * A handover request is initiated by the user from the default dialer app to indicate a desire
119 * to handover a call from one {@link PhoneAccount}/{@link ConnectionService} to another.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700120 */
121 public static final String EXTRA_SUPPORTS_HANDOVER_FROM =
122 "android.telecom.extra.SUPPORTS_HANDOVER_FROM";
123
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700124
125 /**
126 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
127 * indicates whether a Self-Managed {@link PhoneAccount} should log its calls to the call log.
Brad Ebingerbb1a55f2017-06-26 13:26:14 -0700128 * Self-Managed {@link PhoneAccount}s are responsible for their own notifications, so the system
129 * will not create a notification when a missed call is logged.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700130 * <p>
131 * By default, Self-Managed {@link PhoneAccount}s do not log their calls to the call log.
132 * Setting this extra to {@code true} provides a means for them to log their calls.
Tyler Gunn2155c4c2018-04-05 09:43:41 -0700133 * <p>
134 * Note: Only calls where the {@link Call.Details#getHandle()} {@link Uri#getScheme()} is
135 * {@link #SCHEME_SIP} or {@link #SCHEME_TEL} will be logged at the current time.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700136 */
137 public static final String EXTRA_LOG_SELF_MANAGED_CALLS =
138 "android.telecom.extra.LOG_SELF_MANAGED_CALLS";
139
Tyler Gunn8bf76572017-04-06 15:30:08 -0700140 /**
Tyler Gunnacdb6862018-01-29 14:30:52 -0800141 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()}) which
142 * indicates whether calls for a {@link PhoneAccount} should generate a "call recording tone"
143 * when the user is recording audio on the device.
144 * <p>
145 * The call recording tone is played over the telephony audio stream so that the remote party
146 * has an audible indication that it is possible their call is being recorded using a call
147 * recording app on the device.
148 * <p>
149 * This extra only has an effect for calls placed via Telephony (e.g.
150 * {@link #CAPABILITY_SIM_SUBSCRIPTION}).
151 * <p>
152 * The call recording tone is a 1400 hz tone which repeats every 15 seconds while recording is
153 * in progress.
154 * @hide
155 */
156 public static final String EXTRA_PLAY_CALL_RECORDING_TONE =
157 "android.telecom.extra.PLAY_CALL_RECORDING_TONE";
158
159 /**
Sean Kelley4d3c1782018-05-22 14:35:27 -0700160 * Boolean {@link PhoneAccount} extras key (see {@link PhoneAccount#getExtras()} which
161 * indicates whether calls for a {@link PhoneAccount} should skip call filtering.
162 * <p>
163 * If not specified, this will default to false; all calls will undergo call filtering unless
164 * specifically exempted (e.g. {@link Connection#PROPERTY_EMERGENCY_CALLBACK_MODE}.) However,
165 * this may be used to skip call filtering when it has already been performed on another device.
166 * @hide
167 */
168 public static final String EXTRA_SKIP_CALL_FILTERING =
169 "android.telecom.extra.SKIP_CALL_FILTERING";
170
171 /**
Ihab Awadf8b69882014-07-25 15:14:01 -0700172 * Flag indicating that this {@code PhoneAccount} can act as a connection manager for
173 * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount}
174 * will be allowed to manage phone calls including using its own proprietary phone-call
175 * implementation (like VoIP calling) to make calls instead of the telephony stack.
176 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700177 * When a user opts to place a call using the SIM-based telephony stack, the
178 * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first
179 * if the user has explicitly selected it to be used as the default connection manager.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700180 * <p>
181 * See {@link #getCapabilities}
182 */
Ihab Awadf8b69882014-07-25 15:14:01 -0700183 public static final int CAPABILITY_CONNECTION_MANAGER = 0x1;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700184
185 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700186 * Flag indicating that this {@code PhoneAccount} can make phone calls in place of
Evan Charlton6eb262c2014-07-19 18:18:19 -0700187 * traditional SIM-based telephony calls. This account will be treated as a distinct method
188 * for placing calls alongside the traditional SIM-based telephony stack. This flag is
Ihab Awadf8b69882014-07-25 15:14:01 -0700189 * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
Santos Cordon32c65a52014-10-27 14:57:49 -0700190 * or place calls from the built-in telephony stack.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700191 * <p>
192 * See {@link #getCapabilities}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700193 * <p>
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700194 */
195 public static final int CAPABILITY_CALL_PROVIDER = 0x2;
196
Ihab Awad7522bbd2014-07-18 15:53:17 -0700197 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700198 * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM
Evan Charlton6eb262c2014-07-19 18:18:19 -0700199 * subscription.
Ihab Awad7522bbd2014-07-18 15:53:17 -0700200 * <p>
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700201 * Only the Android framework can register a {@code PhoneAccount} having this capability.
202 * <p>
203 * See {@link #getCapabilities}
Ihab Awad7522bbd2014-07-18 15:53:17 -0700204 */
205 public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
206
Ihab Awadf8b69882014-07-25 15:14:01 -0700207 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800208 * Flag indicating that this {@code PhoneAccount} is currently able to place video calls.
209 * <p>
210 * See also {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING} which indicates whether the
211 * {@code PhoneAccount} supports placing video calls.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700212 * <p>
213 * See {@link #getCapabilities}
Ihab Awadf8b69882014-07-25 15:14:01 -0700214 */
215 public static final int CAPABILITY_VIDEO_CALLING = 0x8;
216
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700217 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700218 * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls.
219 * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls.
220 * <p>
221 * See {@link #getCapabilities}
222 */
223 public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10;
224
225 /**
Evan Charlton134dd682014-11-25 14:12:57 -0800226 * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This
227 * should only be used by system apps (and will be ignored for all other apps trying to use it).
228 * <p>
229 * See {@link #getCapabilities}
230 * @hide
231 */
Brian Attwellad147f42014-12-19 11:37:16 -0800232 @SystemApi
Evan Charlton134dd682014-11-25 14:12:57 -0800233 public static final int CAPABILITY_MULTI_USER = 0x20;
234
235 /**
Tyler Gunn65a3d342015-07-27 16:06:16 -0700236 * Flag indicating that this {@code PhoneAccount} supports a subject for Calls. This means a
237 * caller is able to specify a short subject line for an outgoing call. A capable receiving
238 * device displays the call subject on the incoming call screen.
239 * <p>
240 * See {@link #getCapabilities}
241 */
242 public static final int CAPABILITY_CALL_SUBJECT = 0x40;
243
244 /**
Bryce Leeb96d89c2015-10-14 16:48:40 -0700245 * Flag indicating that this {@code PhoneAccount} should only be used for emergency calls.
246 * <p>
247 * See {@link #getCapabilities}
248 * @hide
249 */
250 public static final int CAPABILITY_EMERGENCY_CALLS_ONLY = 0x80;
251
252 /**
Tyler Gunn9a365752015-12-09 15:00:18 -0800253 * Flag indicating that for this {@code PhoneAccount}, the ability to make a video call to a
254 * number relies on presence. Should only be set if the {@code PhoneAccount} also has
255 * {@link #CAPABILITY_VIDEO_CALLING}.
256 * <p>
257 * When set, the {@link ConnectionService} is responsible for toggling the
258 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE_VT_CAPABLE} bit on the
259 * {@link android.provider.ContactsContract.Data#CARRIER_PRESENCE} column to indicate whether
260 * a contact's phone number supports video calling.
261 * <p>
262 * See {@link #getCapabilities}
263 */
264 public static final int CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE = 0x100;
265
266 /**
Tyler Gunncee9ea62016-03-24 11:45:43 -0700267 * Flag indicating that for this {@link PhoneAccount}, emergency video calling is allowed.
268 * <p>
269 * When set, Telecom will allow emergency video calls to be placed. When not set, Telecom will
270 * convert all outgoing video calls to emergency numbers to audio-only.
271 * @hide
272 */
273 public static final int CAPABILITY_EMERGENCY_VIDEO_CALLING = 0x200;
274
275 /**
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800276 * Flag indicating that this {@link PhoneAccount} supports video calling.
277 * This is not an indication that the {@link PhoneAccount} is currently able to make a video
278 * call, but rather that it has the ability to make video calls (but not necessarily at this
279 * time).
280 * <p>
281 * Whether a {@link PhoneAccount} can make a video call is ultimately controlled by
282 * {@link #CAPABILITY_VIDEO_CALLING}, which indicates whether the {@link PhoneAccount} is
283 * currently capable of making a video call. Consider a case where, for example, a
284 * {@link PhoneAccount} supports making video calls (e.g.
285 * {@link #CAPABILITY_SUPPORTS_VIDEO_CALLING}), but a current lack of network connectivity
286 * prevents video calls from being made (e.g. {@link #CAPABILITY_VIDEO_CALLING}).
287 * <p>
288 * See {@link #getCapabilities}
289 */
290 public static final int CAPABILITY_SUPPORTS_VIDEO_CALLING = 0x400;
291
292 /**
Tyler Gunnf5035432017-01-09 09:43:12 -0800293 * Flag indicating that this {@link PhoneAccount} is responsible for managing its own
294 * {@link Connection}s. This type of {@link PhoneAccount} is ideal for use with standalone
295 * calling apps which do not wish to use the default phone app for {@link Connection} UX,
296 * but which want to leverage the call and audio routing capabilities of the Telecom framework.
297 * <p>
298 * When set, {@link Connection}s created by the self-managed {@link ConnectionService} will not
299 * be surfaced to implementations of the {@link InCallService} API. Thus it is the
300 * responsibility of a self-managed {@link ConnectionService} to provide a user interface for
301 * its {@link Connection}s.
302 * <p>
303 * Self-managed {@link Connection}s will, however, be displayed on connected Bluetooth devices.
304 */
305 public static final int CAPABILITY_SELF_MANAGED = 0x800;
306
307 /**
Hall Liu95d55872017-01-25 17:12:49 -0800308 * Flag indicating that this {@link PhoneAccount} is capable of making a call with an
309 * RTT (Real-time text) session.
310 * When set, Telecom will attempt to open an RTT session on outgoing calls that specify
311 * that they should be placed with an RTT session , and the in-call app will be displayed
312 * with text entry fields for RTT. Likewise, the in-call app can request that an RTT
313 * session be opened during a call if this bit is set.
314 */
315 public static final int CAPABILITY_RTT = 0x1000;
316
317 /* NEXT CAPABILITY: 0x2000 */
318
319 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700320 * URI scheme for telephone number URIs.
321 */
322 public static final String SCHEME_TEL = "tel";
323
324 /**
325 * URI scheme for voicemail URIs.
326 */
327 public static final String SCHEME_VOICEMAIL = "voicemail";
328
329 /**
330 * URI scheme for SIP URIs.
331 */
332 public static final String SCHEME_SIP = "sip";
333
Nancy Chen3ace54b2014-10-22 17:45:26 -0700334 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800335 * Indicating no icon tint is set.
Santos Cordoncad84a22015-05-13 11:17:25 -0700336 * @hide
Nancy Chen3ace54b2014-10-22 17:45:26 -0700337 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800338 public static final int NO_ICON_TINT = 0;
339
340 /**
341 * Indicating no hightlight color is set.
342 */
343 public static final int NO_HIGHLIGHT_COLOR = 0;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700344
Ihab Awad476cc832014-11-03 09:47:51 -0800345 /**
346 * Indicating no resource ID is set.
347 */
348 public static final int NO_RESOURCE_ID = -1;
349
Evan Charlton8c8a0622014-07-20 12:31:00 -0700350 private final PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700351 private final Uri mAddress;
352 private final Uri mSubscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700353 private final int mCapabilities;
Ihab Awad476cc832014-11-03 09:47:51 -0800354 private final int mHighlightColor;
Santos Cordon146a3e32014-07-21 00:00:44 -0700355 private final CharSequence mLabel;
356 private final CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700357 private final List<String> mSupportedUriSchemes;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800358 private final int mSupportedAudioRoutes;
Santos Cordoncad84a22015-05-13 11:17:25 -0700359 private final Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700360 private final Bundle mExtras;
Santos Cordon91371dc2015-05-08 13:52:09 -0700361 private boolean mIsEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700362 private String mGroupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700363
Tyler Gunn3b347812018-08-24 14:17:05 -0700364 @Override
365 public boolean equals(Object o) {
366 if (this == o) return true;
367 if (o == null || getClass() != o.getClass()) return false;
368 PhoneAccount that = (PhoneAccount) o;
369 return mCapabilities == that.mCapabilities &&
370 mHighlightColor == that.mHighlightColor &&
371 mSupportedAudioRoutes == that.mSupportedAudioRoutes &&
372 mIsEnabled == that.mIsEnabled &&
373 Objects.equals(mAccountHandle, that.mAccountHandle) &&
374 Objects.equals(mAddress, that.mAddress) &&
375 Objects.equals(mSubscriptionAddress, that.mSubscriptionAddress) &&
376 Objects.equals(mLabel, that.mLabel) &&
377 Objects.equals(mShortDescription, that.mShortDescription) &&
378 Objects.equals(mSupportedUriSchemes, that.mSupportedUriSchemes) &&
379 areBundlesEqual(mExtras, that.mExtras) &&
380 Objects.equals(mGroupId, that.mGroupId);
381 }
382
383 @Override
384 public int hashCode() {
385 return Objects.hash(mAccountHandle, mAddress, mSubscriptionAddress, mCapabilities,
386 mHighlightColor, mLabel, mShortDescription, mSupportedUriSchemes,
387 mSupportedAudioRoutes,
388 mExtras, mIsEnabled, mGroupId);
389 }
390
Santos Cordon32c65a52014-10-27 14:57:49 -0700391 /**
392 * Helper class for creating a {@link PhoneAccount}.
393 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700394 public static class Builder {
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800395
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700396 private PhoneAccountHandle mAccountHandle;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700397 private Uri mAddress;
398 private Uri mSubscriptionAddress;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700399 private int mCapabilities;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800400 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800401 private int mHighlightColor = NO_HIGHLIGHT_COLOR;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700402 private CharSequence mLabel;
403 private CharSequence mShortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700404 private List<String> mSupportedUriSchemes = new ArrayList<String>();
Santos Cordoncad84a22015-05-13 11:17:25 -0700405 private Icon mIcon;
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700406 private Bundle mExtras;
Santos Cordon91371dc2015-05-08 13:52:09 -0700407 private boolean mIsEnabled = false;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700408 private String mGroupId = "";
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700409
Santos Cordon32c65a52014-10-27 14:57:49 -0700410 /**
411 * Creates a builder with the specified {@link PhoneAccountHandle} and label.
412 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700413 public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
414 this.mAccountHandle = accountHandle;
415 this.mLabel = label;
416 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700417
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700418 /**
419 * Creates an instance of the {@link PhoneAccount.Builder} from an existing
420 * {@link PhoneAccount}.
421 *
422 * @param phoneAccount The {@link PhoneAccount} used to initialize the builder.
423 */
424 public Builder(PhoneAccount phoneAccount) {
425 mAccountHandle = phoneAccount.getAccountHandle();
426 mAddress = phoneAccount.getAddress();
427 mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
428 mCapabilities = phoneAccount.getCapabilities();
Ihab Awad476cc832014-11-03 09:47:51 -0800429 mHighlightColor = phoneAccount.getHighlightColor();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700430 mLabel = phoneAccount.getLabel();
431 mShortDescription = phoneAccount.getShortDescription();
432 mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
Santos Cordoncad84a22015-05-13 11:17:25 -0700433 mIcon = phoneAccount.getIcon();
Santos Cordon91371dc2015-05-08 13:52:09 -0700434 mIsEnabled = phoneAccount.isEnabled();
Tyler Gunnd426b202015-10-13 13:33:53 -0700435 mExtras = phoneAccount.getExtras();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700436 mGroupId = phoneAccount.getGroupId();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800437 mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes();
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700438 }
439
Santos Cordon32c65a52014-10-27 14:57:49 -0700440 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700441 * Sets the label. See {@link PhoneAccount#getLabel()}.
442 *
443 * @param label The label of the phone account.
444 * @return The builder.
445 * @hide
446 */
447 public Builder setLabel(CharSequence label) {
448 this.mLabel = label;
449 return this;
450 }
451
452 /**
Santos Cordon32c65a52014-10-27 14:57:49 -0700453 * Sets the address. See {@link PhoneAccount#getAddress}.
454 *
455 * @param value The address of the phone account.
456 * @return The builder.
457 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700458 public Builder setAddress(Uri value) {
459 this.mAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700460 return this;
461 }
462
Santos Cordon32c65a52014-10-27 14:57:49 -0700463 /**
464 * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
465 *
466 * @param value The subscription address.
467 * @return The builder.
468 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700469 public Builder setSubscriptionAddress(Uri value) {
470 this.mSubscriptionAddress = value;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700471 return this;
472 }
473
Santos Cordon32c65a52014-10-27 14:57:49 -0700474 /**
475 * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
476 *
477 * @param value The capabilities to set.
478 * @return The builder.
479 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700480 public Builder setCapabilities(int value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700481 this.mCapabilities = value;
482 return this;
483 }
484
Santos Cordon32c65a52014-10-27 14:57:49 -0700485 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700486 * Sets the icon. See {@link PhoneAccount#getIcon}.
Santos Cordon32c65a52014-10-27 14:57:49 -0700487 *
Santos Cordoncad84a22015-05-13 11:17:25 -0700488 * @param icon The icon to set.
Santos Cordon32c65a52014-10-27 14:57:49 -0700489 */
Santos Cordoncad84a22015-05-13 11:17:25 -0700490 public Builder setIcon(Icon icon) {
491 mIcon = icon;
Ihab Awad074bf102014-10-24 11:42:32 -0700492 return this;
493 }
494
495 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800496 * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}.
Ihab Awad074bf102014-10-24 11:42:32 -0700497 *
Ihab Awad476cc832014-11-03 09:47:51 -0800498 * @param value The highlight color.
Ihab Awad074bf102014-10-24 11:42:32 -0700499 * @return The builder.
500 */
Ihab Awad476cc832014-11-03 09:47:51 -0800501 public Builder setHighlightColor(int value) {
502 this.mHighlightColor = value;
Nancy Chen3ace54b2014-10-22 17:45:26 -0700503 return this;
504 }
505
Santos Cordon32c65a52014-10-27 14:57:49 -0700506 /**
507 * Sets the short description. See {@link PhoneAccount#getShortDescription}.
508 *
509 * @param value The short description.
510 * @return The builder.
511 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700512 public Builder setShortDescription(CharSequence value) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700513 this.mShortDescription = value;
514 return this;
515 }
516
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700517 /**
518 * Specifies an additional URI scheme supported by the {@link PhoneAccount}.
519 *
520 * @param uriScheme The URI scheme.
Santos Cordon32c65a52014-10-27 14:57:49 -0700521 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700522 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700523 public Builder addSupportedUriScheme(String uriScheme) {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700524 if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) {
525 this.mSupportedUriSchemes.add(uriScheme);
526 }
527 return this;
528 }
529
530 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700531 * Specifies the URI schemes supported by the {@link PhoneAccount}.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700532 *
533 * @param uriSchemes The URI schemes.
Santos Cordon32c65a52014-10-27 14:57:49 -0700534 * @return The builder.
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700535 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700536 public Builder setSupportedUriSchemes(List<String> uriSchemes) {
537 mSupportedUriSchemes.clear();
538
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700539 if (uriSchemes != null && !uriSchemes.isEmpty()) {
540 for (String uriScheme : uriSchemes) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700541 addSupportedUriScheme(uriScheme);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700542 }
543 }
544 return this;
545 }
546
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700547 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700548 * Specifies the extras associated with the {@link PhoneAccount}.
549 * <p>
550 * {@code PhoneAccount}s only support extra values of type: {@link String}, {@link Integer},
551 * and {@link Boolean}. Extras which are not of these types are ignored.
552 *
553 * @param extras
554 * @return
555 */
556 public Builder setExtras(Bundle extras) {
557 mExtras = extras;
558 return this;
559 }
560
561 /**
Santos Cordon91371dc2015-05-08 13:52:09 -0700562 * Sets the enabled state of the phone account.
563 *
564 * @param isEnabled The enabled state.
565 * @return The builder.
566 * @hide
567 */
568 public Builder setIsEnabled(boolean isEnabled) {
569 mIsEnabled = isEnabled;
570 return this;
571 }
572
573 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700574 * Sets the group Id of the {@link PhoneAccount}. When a new {@link PhoneAccount} is
575 * registered to Telecom, it will replace another {@link PhoneAccount} that is already
576 * registered in Telecom and take on the current user defaults and enabled status. There can
577 * only be one {@link PhoneAccount} with a non-empty group number registered to Telecom at a
578 * time. By default, there is no group Id for a {@link PhoneAccount} (an empty String). Only
579 * grouped {@link PhoneAccount}s with the same {@link ConnectionService} can be replaced.
580 * @param groupId The group Id of the {@link PhoneAccount} that will replace any other
581 * registered {@link PhoneAccount} in Telecom with the same Group Id.
582 * @return The builder
583 * @hide
584 */
585 public Builder setGroupId(String groupId) {
586 if (groupId != null) {
587 mGroupId = groupId;
588 } else {
589 mGroupId = "";
590 }
591 return this;
592 }
593
594 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800595 * Sets the audio routes supported by this {@link PhoneAccount}.
596 *
597 * @param routes bit mask of available routes.
598 * @return The builder.
599 * @hide
600 */
601 public Builder setSupportedAudioRoutes(int routes) {
602 mSupportedAudioRoutes = routes;
603 return this;
604 }
605
606 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700607 * Creates an instance of a {@link PhoneAccount} based on the current builder settings.
608 *
609 * @return The {@link PhoneAccount}.
610 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700611 public PhoneAccount build() {
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700612 // If no supported URI schemes were defined, assume "tel" is supported.
613 if (mSupportedUriSchemes.isEmpty()) {
Andrew Lee3085a6c2014-09-04 10:59:13 -0700614 addSupportedUriScheme(SCHEME_TEL);
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700615 }
616
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700617 return new PhoneAccount(
618 mAccountHandle,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700619 mAddress,
620 mSubscriptionAddress,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700621 mCapabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700622 mIcon,
Ihab Awad476cc832014-11-03 09:47:51 -0800623 mHighlightColor,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700624 mLabel,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700625 mShortDescription,
Santos Cordon91371dc2015-05-08 13:52:09 -0700626 mSupportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700627 mExtras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800628 mSupportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700629 mIsEnabled,
630 mGroupId);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700631 }
632 }
633
634 private PhoneAccount(
Evan Charlton6eb262c2014-07-19 18:18:19 -0700635 PhoneAccountHandle account,
Andrew Lee3085a6c2014-09-04 10:59:13 -0700636 Uri address,
637 Uri subscriptionAddress,
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700638 int capabilities,
Santos Cordoncad84a22015-05-13 11:17:25 -0700639 Icon icon,
Ihab Awad476cc832014-11-03 09:47:51 -0800640 int highlightColor,
Santos Cordon146a3e32014-07-21 00:00:44 -0700641 CharSequence label,
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700642 CharSequence shortDescription,
Santos Cordon91371dc2015-05-08 13:52:09 -0700643 List<String> supportedUriSchemes,
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700644 Bundle extras,
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800645 int supportedAudioRoutes,
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700646 boolean isEnabled,
647 String groupId) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700648 mAccountHandle = account;
Andrew Lee3085a6c2014-09-04 10:59:13 -0700649 mAddress = address;
650 mSubscriptionAddress = subscriptionAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700651 mCapabilities = capabilities;
Santos Cordoncad84a22015-05-13 11:17:25 -0700652 mIcon = icon;
Ihab Awad476cc832014-11-03 09:47:51 -0800653 mHighlightColor = highlightColor;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700654 mLabel = label;
655 mShortDescription = shortDescription;
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700656 mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700657 mExtras = extras;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800658 mSupportedAudioRoutes = supportedAudioRoutes;
Santos Cordon91371dc2015-05-08 13:52:09 -0700659 mIsEnabled = isEnabled;
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700660 mGroupId = groupId;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700661 }
662
Andrew Lee3085a6c2014-09-04 10:59:13 -0700663 public static Builder builder(
664 PhoneAccountHandle accountHandle,
665 CharSequence label) {
666 return new Builder(accountHandle, label);
667 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700668
Ihab Awad807fe0a2014-07-09 12:30:52 -0700669 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700670 * Returns a builder initialized with the current {@link PhoneAccount} instance.
671 *
672 * @return The builder.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700673 */
674 public Builder toBuilder() { return new Builder(this); }
675
676 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700677 * The unique identifier of this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700678 *
Evan Charlton6eb262c2014-07-19 18:18:19 -0700679 * @return A {@code PhoneAccountHandle}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700680 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700681 public PhoneAccountHandle getAccountHandle() {
682 return mAccountHandle;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700683 }
684
685 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700686 * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This
Evan Charlton8c8a0622014-07-20 12:31:00 -0700687 * represents the destination from which outgoing calls using this {@code PhoneAccount}
Evan Charlton6eb262c2014-07-19 18:18:19 -0700688 * will appear to come, if applicable, and the destination to which incoming calls using this
Evan Charlton8c8a0622014-07-20 12:31:00 -0700689 * {@code PhoneAccount} may be addressed.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700690 *
Andrew Lee3085a6c2014-09-04 10:59:13 -0700691 * @return A address expressed as a {@code Uri}, for example, a phone number.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700692 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700693 public Uri getAddress() {
694 return mAddress;
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700695 }
696
697 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700698 * The raw callback number used for this {@code PhoneAccount}, as distinct from
Andrew Lee3085a6c2014-09-04 10:59:13 -0700699 * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700700 * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
Junda Liuf52ac902014-09-25 17:36:48 +0000701 * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
702 * has been used to alter the callback number.
703 * <p>
Evan Charlton222db5252014-07-17 16:59:18 -0700704 *
705 * @return The subscription number, suitable for display to the user.
706 */
Andrew Lee3085a6c2014-09-04 10:59:13 -0700707 public Uri getSubscriptionAddress() {
708 return mSubscriptionAddress;
Evan Charlton222db5252014-07-17 16:59:18 -0700709 }
710
711 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700712 * The capabilities of this {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700713 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700714 * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700715 */
716 public int getCapabilities() {
717 return mCapabilities;
718 }
719
720 /**
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700721 * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in
722 * bit mask.
723 *
724 * @param capability The capabilities to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700725 * @return {@code true} if the phone account has the capability.
Tyler Gunna1ed7d12014-09-08 09:52:22 -0700726 */
727 public boolean hasCapabilities(int capability) {
728 return (mCapabilities & capability) == capability;
729 }
730
731 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800732 * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask.
733 *
734 * @param route The routes to check.
735 * @return {@code true} if the phone account has the routes.
736 * @hide
737 */
738 public boolean hasAudioRoutes(int routes) {
739 return (mSupportedAudioRoutes & routes) == routes;
740 }
741
742 /**
Santos Cordon146a3e32014-07-21 00:00:44 -0700743 * A short label describing a {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700744 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700745 * @return A label for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700746 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700747 public CharSequence getLabel() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700748 return mLabel;
749 }
750
751 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700752 * A short paragraph describing this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700753 *
Evan Charlton8c8a0622014-07-20 12:31:00 -0700754 * @return A description for this {@code PhoneAccount}.
Ihab Awad807fe0a2014-07-09 12:30:52 -0700755 */
Santos Cordon146a3e32014-07-21 00:00:44 -0700756 public CharSequence getShortDescription() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700757 return mShortDescription;
758 }
759
760 /**
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700761 * The URI schemes supported by this {@code PhoneAccount}.
762 *
763 * @return The URI schemes.
764 */
765 public List<String> getSupportedUriSchemes() {
766 return mSupportedUriSchemes;
767 }
768
769 /**
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700770 * The extras associated with this {@code PhoneAccount}.
771 * <p>
772 * A {@link ConnectionService} may provide implementation specific information about the
773 * {@link PhoneAccount} via the extras.
774 *
775 * @return The extras.
776 */
777 public Bundle getExtras() {
778 return mExtras;
779 }
780
781 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800782 * The audio routes supported by this {@code PhoneAccount}.
783 *
784 * @hide
785 */
786 public int getSupportedAudioRoutes() {
787 return mSupportedAudioRoutes;
788 }
789
790 /**
Santos Cordoncad84a22015-05-13 11:17:25 -0700791 * The icon to represent this {@code PhoneAccount}.
792 *
793 * @return The icon.
794 */
795 public Icon getIcon() {
796 return mIcon;
797 }
798
799 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700800 * Indicates whether the user has enabled this {@code PhoneAccount} or not. This value is only
801 * populated for {@code PhoneAccount}s returned by {@link TelecomManager#getPhoneAccount}.
Santos Cordon91371dc2015-05-08 13:52:09 -0700802 *
Santos Cordon895d4b82015-06-25 16:41:48 -0700803 * @return {@code true} if the account is enabled by the user, {@code false} otherwise.
Santos Cordon91371dc2015-05-08 13:52:09 -0700804 */
805 public boolean isEnabled() {
806 return mIsEnabled;
807 }
808
809 /**
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700810 * A non-empty {@link String} representing the group that A {@link PhoneAccount} is in or an
811 * empty {@link String} if the {@link PhoneAccount} is not in a group. If this
812 * {@link PhoneAccount} is in a group, this new {@link PhoneAccount} will replace a registered
813 * {@link PhoneAccount} that is in the same group. When the {@link PhoneAccount} is replaced,
814 * its user defined defaults and enabled status will also pass to this new {@link PhoneAccount}.
815 * Only {@link PhoneAccount}s that share the same {@link ConnectionService} can be replaced.
816 *
817 * @return A non-empty String Id if this {@link PhoneAccount} belongs to a group.
818 * @hide
819 */
820 public String getGroupId() {
821 return mGroupId;
822 }
823
824 /**
Andrew Lee3085a6c2014-09-04 10:59:13 -0700825 * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700826 * scheme.
827 *
828 * @param uriScheme The URI scheme to check.
Santos Cordon895d4b82015-06-25 16:41:48 -0700829 * @return {@code true} if the {@code PhoneAccount} supports calls to/from addresses with the
Tyler Gunnf5b29dc2014-09-03 09:09:12 -0700830 * specified URI scheme.
831 */
832 public boolean supportsUriScheme(String uriScheme) {
833 if (mSupportedUriSchemes == null || uriScheme == null) {
834 return false;
835 }
836
837 for (String scheme : mSupportedUriSchemes) {
838 if (scheme != null && scheme.equals(uriScheme)) {
839 return true;
840 }
841 }
842 return false;
843 }
844
845 /**
Ihab Awad476cc832014-11-03 09:47:51 -0800846 * A highlight color to use in displaying information about this {@code PhoneAccount}.
847 *
848 * @return A hexadecimal color value.
849 */
850 public int getHighlightColor() {
851 return mHighlightColor;
852 }
853
Santos Cordon91371dc2015-05-08 13:52:09 -0700854 /**
855 * Sets the enabled state of the phone account.
856 * @hide
857 */
858 public void setIsEnabled(boolean isEnabled) {
859 mIsEnabled = isEnabled;
860 }
861
Tyler Gunnf5035432017-01-09 09:43:12 -0800862 /**
863 * @return {@code true} if the {@link PhoneAccount} is self-managed, {@code false} otherwise.
864 * @hide
865 */
866 public boolean isSelfManaged() {
867 return (mCapabilities & CAPABILITY_SELF_MANAGED) == CAPABILITY_SELF_MANAGED;
868 }
869
Ihab Awad807fe0a2014-07-09 12:30:52 -0700870 //
871 // Parcelable implementation
872 //
873
874 @Override
875 public int describeContents() {
876 return 0;
877 }
878
879 @Override
880 public void writeToParcel(Parcel out, int flags) {
Ihab Awad476cc832014-11-03 09:47:51 -0800881 if (mAccountHandle == null) {
882 out.writeInt(0);
883 } else {
884 out.writeInt(1);
885 mAccountHandle.writeToParcel(out, flags);
886 }
887 if (mAddress == null) {
888 out.writeInt(0);
889 } else {
890 out.writeInt(1);
891 mAddress.writeToParcel(out, flags);
892 }
893 if (mSubscriptionAddress == null) {
894 out.writeInt(0);
895 } else {
896 out.writeInt(1);
897 mSubscriptionAddress.writeToParcel(out, flags);
898 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700899 out.writeInt(mCapabilities);
Ihab Awad476cc832014-11-03 09:47:51 -0800900 out.writeInt(mHighlightColor);
Santos Cordon146a3e32014-07-21 00:00:44 -0700901 out.writeCharSequence(mLabel);
902 out.writeCharSequence(mShortDescription);
Ihab Awad476cc832014-11-03 09:47:51 -0800903 out.writeStringList(mSupportedUriSchemes);
Santos Cordon91371dc2015-05-08 13:52:09 -0700904
Santos Cordoncad84a22015-05-13 11:17:25 -0700905 if (mIcon == null) {
906 out.writeInt(0);
907 } else {
908 out.writeInt(1);
909 mIcon.writeToParcel(out, flags);
910 }
Santos Cordon91371dc2015-05-08 13:52:09 -0700911 out.writeByte((byte) (mIsEnabled ? 1 : 0));
Tyler Gunnef829ec2015-10-08 09:46:23 -0700912 out.writeBundle(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700913 out.writeString(mGroupId);
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800914 out.writeInt(mSupportedAudioRoutes);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700915 }
916
Evan Charlton8c8a0622014-07-20 12:31:00 -0700917 public static final Creator<PhoneAccount> CREATOR
918 = new Creator<PhoneAccount>() {
Ihab Awad807fe0a2014-07-09 12:30:52 -0700919 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700920 public PhoneAccount createFromParcel(Parcel in) {
921 return new PhoneAccount(in);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700922 }
923
924 @Override
Evan Charlton8c8a0622014-07-20 12:31:00 -0700925 public PhoneAccount[] newArray(int size) {
926 return new PhoneAccount[size];
Ihab Awad807fe0a2014-07-09 12:30:52 -0700927 }
928 };
929
Evan Charlton8c8a0622014-07-20 12:31:00 -0700930 private PhoneAccount(Parcel in) {
Ihab Awad476cc832014-11-03 09:47:51 -0800931 if (in.readInt() > 0) {
932 mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in);
933 } else {
934 mAccountHandle = null;
935 }
936 if (in.readInt() > 0) {
937 mAddress = Uri.CREATOR.createFromParcel(in);
938 } else {
939 mAddress = null;
940 }
941 if (in.readInt() > 0) {
942 mSubscriptionAddress = Uri.CREATOR.createFromParcel(in);
943 } else {
944 mSubscriptionAddress = null;
945 }
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700946 mCapabilities = in.readInt();
Ihab Awad476cc832014-11-03 09:47:51 -0800947 mHighlightColor = in.readInt();
Santos Cordon146a3e32014-07-21 00:00:44 -0700948 mLabel = in.readCharSequence();
949 mShortDescription = in.readCharSequence();
Ihab Awad476cc832014-11-03 09:47:51 -0800950 mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList());
Santos Cordoncad84a22015-05-13 11:17:25 -0700951 if (in.readInt() > 0) {
952 mIcon = Icon.CREATOR.createFromParcel(in);
953 } else {
954 mIcon = null;
955 }
Santos Cordon91371dc2015-05-08 13:52:09 -0700956 mIsEnabled = in.readByte() == 1;
Tyler Gunnef829ec2015-10-08 09:46:23 -0700957 mExtras = in.readBundle();
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700958 mGroupId = in.readString();
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800959 mSupportedAudioRoutes = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700960 }
Tyler Gunn76c01a52014-09-30 14:47:51 -0700961
962 @Override
963 public String toString() {
Santos Cordon91371dc2015-05-08 13:52:09 -0700964 StringBuilder sb = new StringBuilder().append("[[")
965 .append(mIsEnabled ? 'X' : ' ')
966 .append("] PhoneAccount: ")
Tyler Gunn76c01a52014-09-30 14:47:51 -0700967 .append(mAccountHandle)
968 .append(" Capabilities: ")
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800969 .append(capabilitiesToString())
970 .append(" Audio Routes: ")
971 .append(audioRoutesToString())
Tyler Gunn76c01a52014-09-30 14:47:51 -0700972 .append(" Schemes: ");
973 for (String scheme : mSupportedUriSchemes) {
974 sb.append(scheme)
975 .append(" ");
976 }
Tyler Gunnef829ec2015-10-08 09:46:23 -0700977 sb.append(" Extras: ");
Tyler Gunn25ed2d72015-10-05 14:14:38 -0700978 sb.append(mExtras);
Brad Ebinger7298f3b2016-06-10 17:19:42 -0700979 sb.append(" GroupId: ");
980 sb.append(Log.pii(mGroupId));
Tyler Gunn76c01a52014-09-30 14:47:51 -0700981 sb.append("]");
982 return sb.toString();
983 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800984
985 /**
986 * Generates a string representation of a capabilities bitmask.
987 *
Tyler Gunn3e122f72016-01-11 19:25:00 -0800988 * @return String representation of the capabilities bitmask.
Tyler Gunn1847b4e2018-11-09 08:43:02 -0800989 * @hide
Tyler Gunn3e122f72016-01-11 19:25:00 -0800990 */
Tyler Gunn1847b4e2018-11-09 08:43:02 -0800991 public String capabilitiesToString() {
Tyler Gunn3e122f72016-01-11 19:25:00 -0800992 StringBuilder sb = new StringBuilder();
Tyler Gunnf5035432017-01-09 09:43:12 -0800993 if (hasCapabilities(CAPABILITY_SELF_MANAGED)) {
994 sb.append("SelfManaged ");
995 }
Tyler Gunn58cbd7a2016-11-11 11:31:28 -0800996 if (hasCapabilities(CAPABILITY_SUPPORTS_VIDEO_CALLING)) {
997 sb.append("SuppVideo ");
998 }
Tyler Gunn3e122f72016-01-11 19:25:00 -0800999 if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) {
1000 sb.append("Video ");
1001 }
1002 if (hasCapabilities(CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
1003 sb.append("Presence ");
1004 }
1005 if (hasCapabilities(CAPABILITY_CALL_PROVIDER)) {
1006 sb.append("CallProvider ");
1007 }
1008 if (hasCapabilities(CAPABILITY_CALL_SUBJECT)) {
1009 sb.append("CallSubject ");
1010 }
1011 if (hasCapabilities(CAPABILITY_CONNECTION_MANAGER)) {
1012 sb.append("ConnectionMgr ");
1013 }
1014 if (hasCapabilities(CAPABILITY_EMERGENCY_CALLS_ONLY)) {
1015 sb.append("EmergOnly ");
1016 }
1017 if (hasCapabilities(CAPABILITY_MULTI_USER)) {
1018 sb.append("MultiUser ");
1019 }
1020 if (hasCapabilities(CAPABILITY_PLACE_EMERGENCY_CALLS)) {
1021 sb.append("PlaceEmerg ");
1022 }
Tyler Gunncee9ea62016-03-24 11:45:43 -07001023 if (hasCapabilities(CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
1024 sb.append("EmergVideo ");
1025 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001026 if (hasCapabilities(CAPABILITY_SIM_SUBSCRIPTION)) {
1027 sb.append("SimSub ");
1028 }
Hall Liu47ed6202017-11-20 16:25:39 -08001029 if (hasCapabilities(CAPABILITY_RTT)) {
1030 sb.append("Rtt");
1031 }
Tyler Gunn3e122f72016-01-11 19:25:00 -08001032 return sb.toString();
1033 }
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001034
1035 private String audioRoutesToString() {
1036 StringBuilder sb = new StringBuilder();
1037
1038 if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) {
1039 sb.append("B");
1040 }
1041 if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) {
1042 sb.append("E");
1043 }
1044 if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) {
1045 sb.append("S");
1046 }
1047 if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) {
1048 sb.append("W");
1049 }
1050
1051 return sb.toString();
1052 }
Tyler Gunn3b347812018-08-24 14:17:05 -07001053
1054 /**
1055 * Determines if two {@link Bundle}s are equal.
1056 * @param extras First {@link Bundle} to check.
1057 * @param newExtras {@link Bundle} to compare against.
1058 * @return {@code true} if the {@link Bundle}s are equal, {@code false} otherwise.
1059 */
1060 private static boolean areBundlesEqual(Bundle extras, Bundle newExtras) {
1061 if (extras == null || newExtras == null) {
1062 return extras == newExtras;
1063 }
1064
1065 if (extras.size() != newExtras.size()) {
1066 return false;
1067 }
1068
1069 for(String key : extras.keySet()) {
1070 if (key != null) {
1071 final Object value = extras.get(key);
1072 final Object newValue = newExtras.get(key);
1073 if (!Objects.equals(value, newValue)) {
1074 return false;
1075 }
1076 }
1077 }
1078 return true;
1079 }
Ihab Awad807fe0a2014-07-09 12:30:52 -07001080}