1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.telecom;
18 
19 import android.annotation.FlaggedApi;
20 import android.annotation.IntDef;
21 import android.annotation.NonNull;
22 import android.annotation.Nullable;
23 import android.annotation.SystemApi;
24 import android.annotation.TestApi;
25 import android.compat.annotation.UnsupportedAppUsage;
26 import android.content.pm.ServiceInfo;
27 import android.net.Uri;
28 import android.os.BadParcelableException;
29 import android.os.Build;
30 import android.os.Bundle;
31 import android.os.Handler;
32 import android.os.ParcelFileDescriptor;
33 
34 import com.android.internal.telecom.IVideoProvider;
35 import com.android.server.telecom.flags.Flags;
36 
37 import java.io.IOException;
38 import java.io.InputStreamReader;
39 import java.io.OutputStreamWriter;
40 import java.lang.annotation.Retention;
41 import java.lang.annotation.RetentionPolicy;
42 import java.nio.charset.StandardCharsets;
43 import java.util.ArrayList;
44 import java.util.Arrays;
45 import java.util.Collections;
46 import java.util.List;
47 import java.util.Map;
48 import java.util.Objects;
49 import java.util.concurrent.CopyOnWriteArrayList;
50 
51 /**
52  * Represents an ongoing phone call that the in-call app should present to the user.
53  */
54 public final class Call {
55     /**
56      * The state of a {@code Call} when newly created.
57      */
58     public static final int STATE_NEW = 0;
59 
60     /**
61      * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected.
62      */
63     public static final int STATE_DIALING = 1;
64 
65     /**
66      * The state of an incoming {@code Call} when ringing locally, but not yet connected.
67      */
68     public static final int STATE_RINGING = 2;
69 
70     /**
71      * The state of a {@code Call} when in a holding state.
72      */
73     public static final int STATE_HOLDING = 3;
74 
75     /**
76      * The state of a {@code Call} when actively supporting conversation.
77      */
78     public static final int STATE_ACTIVE = 4;
79 
80     /**
81      * The state of a {@code Call} when no further voice or other communication is being
82      * transmitted, the remote side has been or will inevitably be informed that the {@code Call}
83      * is no longer active, and the local data transport has or inevitably will release resources
84      * associated with this {@code Call}.
85      */
86     public static final int STATE_DISCONNECTED = 7;
87 
88     /**
89      * The state of an outgoing {@code Call} when waiting on user to select a
90      * {@link PhoneAccount} through which to place the call.
91      */
92     public static final int STATE_SELECT_PHONE_ACCOUNT = 8;
93 
94     /**
95      * @hide
96      * @deprecated use STATE_SELECT_PHONE_ACCOUNT.
97      */
98     @Deprecated
99     @SystemApi
100     public static final int STATE_PRE_DIAL_WAIT = STATE_SELECT_PHONE_ACCOUNT;
101 
102     /**
103      * The initial state of an outgoing {@code Call}.
104      * Common transitions are to {@link #STATE_DIALING} state for a successful call or
105      * {@link #STATE_DISCONNECTED} if it failed.
106      */
107     public static final int STATE_CONNECTING = 9;
108 
109     /**
110      * The state of a {@code Call} when the user has initiated a disconnection of the call, but the
111      * call has not yet been disconnected by the underlying {@code ConnectionService}.  The next
112      * state of the call is (potentially) {@link #STATE_DISCONNECTED}.
113      */
114     public static final int STATE_DISCONNECTING = 10;
115 
116     /**
117      * The state of an external call which is in the process of being pulled from a remote device to
118      * the local device.
119      * <p>
120      * A call can only be in this state if the {@link Details#PROPERTY_IS_EXTERNAL_CALL} property
121      * and {@link Details#CAPABILITY_CAN_PULL_CALL} capability are set on the call.
122      * <p>
123      * An {@link InCallService} will only see this state if it has the
124      * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
125      * manifest.
126      */
127     public static final int STATE_PULLING_CALL = 11;
128 
129     /**
130      * The state of a call that is active with the network, but the audio from the call is
131      * being intercepted by an app on the local device. Telecom does not hold audio focus in this
132      * state, and the call will be invisible to the user except for a persistent notification.
133      */
134     public static final int STATE_AUDIO_PROCESSING = 12;
135 
136     /**
137      * The state of a call that is being presented to the user after being in
138      * {@link #STATE_AUDIO_PROCESSING}. The call is still active with the network in this case, and
139      * Telecom will hold audio focus and play a ringtone if appropriate.
140      */
141     public static final int STATE_SIMULATED_RINGING = 13;
142 
143     /**
144      * @hide
145      */
146     @IntDef(prefix = { "STATE_" },
147             value = {
148                     STATE_NEW,
149                     STATE_DIALING,
150                     STATE_RINGING,
151                     STATE_HOLDING,
152                     STATE_ACTIVE,
153                     STATE_DISCONNECTED,
154                     STATE_SELECT_PHONE_ACCOUNT,
155                     STATE_CONNECTING,
156                     STATE_DISCONNECTING,
157                     STATE_PULLING_CALL,
158                     STATE_AUDIO_PROCESSING,
159                     STATE_SIMULATED_RINGING
160             })
161     @Retention(RetentionPolicy.SOURCE)
162     public @interface CallState {};
163 
164     /**
165      * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
166      * extras. Used to pass the phone accounts to display on the front end to the user in order to
167      * select phone accounts to (for example) place a call.
168      * @deprecated Use the list from {@link #EXTRA_SUGGESTED_PHONE_ACCOUNTS} instead.
169      */
170     @Deprecated
171     public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
172 
173     /**
174      * Extra key intended for {@link InCallService}s that notify the user of an incoming call. When
175      * EXTRA_IS_SUPPRESSED_BY_DO_NOT_DISTURB returns true, the {@link InCallService} should not
176      * interrupt the user of the incoming call because the call is being suppressed by Do Not
177      * Disturb settings.
178      *
179      * This extra will be removed from the {@link Call} object for {@link InCallService}s that do
180      * not hold the {@link android.Manifest.permission#READ_CONTACTS} permission.
181      */
182     public static final String EXTRA_IS_SUPPRESSED_BY_DO_NOT_DISTURB =
183             "android.telecom.extra.IS_SUPPRESSED_BY_DO_NOT_DISTURB";
184 
185     /**
186      * Key for extra used to pass along a list of {@link PhoneAccountSuggestion}s to the in-call
187      * UI when a call enters the {@link #STATE_SELECT_PHONE_ACCOUNT} state. The list included here
188      * will have the same length and be in the same order as the list passed with
189      * {@link #AVAILABLE_PHONE_ACCOUNTS}.
190      */
191     public static final String EXTRA_SUGGESTED_PHONE_ACCOUNTS =
192             "android.telecom.extra.SUGGESTED_PHONE_ACCOUNTS";
193 
194     /**
195      * Extra key used to indicate the time (in milliseconds since midnight, January 1, 1970 UTC)
196      * when the last outgoing emergency call was made.  This is used to identify potential emergency
197      * callbacks.
198      */
199     public static final String EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS =
200             "android.telecom.extra.LAST_EMERGENCY_CALLBACK_TIME_MILLIS";
201 
202 
203     /**
204      * Extra key used to indicate whether a {@link CallScreeningService} has requested to silence
205      * the ringtone for a call.  If the {@link InCallService} declares
206      * {@link TelecomManager#METADATA_IN_CALL_SERVICE_RINGING} in its manifest, it should not
207      * play a ringtone for an incoming call with this extra key set.
208      */
209     public static final String EXTRA_SILENT_RINGING_REQUESTED =
210             "android.telecom.extra.SILENT_RINGING_REQUESTED";
211 
212     /**
213      * Event reported from the Telecom stack to report an in-call diagnostic message which the
214      * dialer app may opt to display to the user.  A diagnostic message is used to communicate
215      * scenarios the device has detected which may impact the quality of the ongoing call.
216      * <p>
217      * For example a problem with a bluetooth headset may generate a recommendation for the user to
218      * try using the speakerphone instead, or if the device detects it has entered a poor service
219      * area, the user might be warned so that they can finish their call prior to it dropping.
220      * <p>
221      * A diagnostic message is considered persistent in nature.  When the user enters a poor service
222      * area, for example, the accompanying diagnostic message persists until they leave the area
223      * of poor service.  Each message is accompanied with a {@link #EXTRA_DIAGNOSTIC_MESSAGE_ID}
224      * which uniquely identifies the diagnostic condition being reported.  The framework raises a
225      * call event of type {@link #EVENT_CLEAR_DIAGNOSTIC_MESSAGE} when the condition reported has
226      * been cleared.  The dialer app should display the diagnostic message until it is cleared.
227      * If multiple diagnostic messages are sent with different IDs (which have not yet been cleared)
228      * the dialer app should prioritize the most recently received message, but still provide the
229      * user with a means to review past messages.
230      * <p>
231      * The text of the message is found in {@link #EXTRA_DIAGNOSTIC_MESSAGE} in the form of a human
232      * readable {@link CharSequence} which is intended for display in the call UX.
233      * <p>
234      * The telecom framework audibly notifies the user of the presence of a diagnostic message, so
235      * the dialer app needs only to concern itself with visually displaying the message.
236      * <p>
237      * The dialer app receives this event via
238      * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
239      */
240     public static final String EVENT_DISPLAY_DIAGNOSTIC_MESSAGE =
241             "android.telecom.event.DISPLAY_DIAGNOSTIC_MESSAGE";
242 
243     /**
244      * Event reported from the telecom framework when a diagnostic message previously raised with
245      * {@link #EVENT_DISPLAY_DIAGNOSTIC_MESSAGE} has cleared and is no longer pertinent.
246      * <p>
247      * The {@link #EXTRA_DIAGNOSTIC_MESSAGE_ID} indicates the diagnostic message which has been
248      * cleared.
249      * <p>
250      * The dialer app receives this event via
251      * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
252      */
253     public static final String EVENT_CLEAR_DIAGNOSTIC_MESSAGE =
254             "android.telecom.event.CLEAR_DIAGNOSTIC_MESSAGE";
255 
256     /**
257      * Integer extra representing a message ID for a message posted via
258      * {@link #EVENT_DISPLAY_DIAGNOSTIC_MESSAGE}.  Used to ensure that the dialer app knows when
259      * the message in question has cleared via {@link #EVENT_CLEAR_DIAGNOSTIC_MESSAGE}.
260      */
261     public static final String EXTRA_DIAGNOSTIC_MESSAGE_ID =
262             "android.telecom.extra.DIAGNOSTIC_MESSAGE_ID";
263 
264     /**
265      * {@link CharSequence} extra used with {@link #EVENT_DISPLAY_DIAGNOSTIC_MESSAGE}.  This is the
266      * diagnostic message the dialer app should display.
267      */
268     public static final String EXTRA_DIAGNOSTIC_MESSAGE =
269             "android.telecom.extra.DIAGNOSTIC_MESSAGE";
270 
271     /**
272      * Boolean indicating that the call is a verified business call.
273      *
274      * {@link Connection#setExtras(Bundle)} or {@link Connection#putExtras(Bundle)}
275      * should be used to notify Telecom this extra has been set.
276      */
277     @FlaggedApi(Flags.FLAG_BUSINESS_CALL_COMPOSER)
278     public static final String EXTRA_IS_BUSINESS_CALL =
279             "android.telecom.extra.IS_BUSINESS_CALL";
280 
281     /**
282      * String value indicating the asserted display name reported via
283      * ImsCallProfile#EXTRA_ASSERTED_DISPLAY_NAME.
284      *
285      * {@link Connection#setExtras(Bundle)} or {@link Connection#putExtras(Bundle)}
286      * should be used to notify Telecom this extra has been set.
287      */
288     @FlaggedApi(Flags.FLAG_BUSINESS_CALL_COMPOSER)
289     public static final String EXTRA_ASSERTED_DISPLAY_NAME =
290             "android.telecom.extra.ASSERTED_DISPLAY_NAME";
291 
292     /**
293      * Reject reason used with {@link #reject(int)} to indicate that the user is rejecting this
294      * call because they have declined to answer it.  This typically means that they are unable
295      * to answer the call at this time and would prefer it be sent to voicemail.
296      */
297     public static final int REJECT_REASON_DECLINED = 1;
298 
299     /**
300      * Reject reason used with {@link #reject(int)} to indicate that the user is rejecting this
301      * call because it is an unwanted call.  This allows the user to indicate that they are
302      * rejecting a call because it is likely a nuisance call.
303      */
304     public static final int REJECT_REASON_UNWANTED = 2;
305 
306     /**
307      * @hide
308      */
309     @IntDef(prefix = { "REJECT_REASON_" },
310             value = {REJECT_REASON_DECLINED, REJECT_REASON_UNWANTED})
311     @Retention(RetentionPolicy.SOURCE)
312     public @interface RejectReason {};
313 
314     public static class Details {
315         /** @hide */
316         @Retention(RetentionPolicy.SOURCE)
317         @IntDef(
318                 prefix = { "DIRECTION_" },
319                 value = {DIRECTION_UNKNOWN, DIRECTION_INCOMING, DIRECTION_OUTGOING})
320         public @interface CallDirection {}
321 
322         /**
323          * Indicates that the call is neither and incoming nor an outgoing call.  This can be the
324          * case for calls reported directly by a {@link ConnectionService} in special cases such as
325          * call handovers.
326          */
327         public static final int DIRECTION_UNKNOWN = -1;
328 
329         /**
330          * Indicates that the call is an incoming call.
331          */
332         public static final int DIRECTION_INCOMING = 0;
333 
334         /**
335          * Indicates that the call is an outgoing call.
336          */
337         public static final int DIRECTION_OUTGOING = 1;
338 
339         /** Call can currently be put on hold or unheld. */
340         public static final int CAPABILITY_HOLD = 0x00000001;
341 
342         /** Call supports the hold feature. */
343         public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
344 
345         /**
346          * Calls within a conference can be merged. A {@link ConnectionService} has the option to
347          * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
348          * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
349          * capability allows a merge button to be shown while the conference call is in the foreground
350          * of the in-call UI.
351          * <p>
352          * This is only intended for use by a {@link Conference}.
353          */
354         public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
355 
356         /**
357          * Calls within a conference can be swapped between foreground and background.
358          * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
359          * <p>
360          * This is only intended for use by a {@link Conference}.
361          */
362         public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
363 
364         /**
365          * @hide
366          */
367         public static final int CAPABILITY_UNUSED_1 = 0x00000010;
368 
369         /** Call supports responding via text option. */
370         public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
371 
372         /** Call can be muted. */
373         public static final int CAPABILITY_MUTE = 0x00000040;
374 
375         /**
376          * Call supports conference call management. This capability only applies to {@link Conference}
377          * calls which can have {@link Connection}s as children.
378          */
379         public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
380 
381         /**
382          * Local device supports receiving video.
383          */
384         public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
385 
386         /**
387          * Local device supports transmitting video.
388          */
389         public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
390 
391         /**
392          * Local device supports bidirectional video calling.
393          */
394         public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
395                 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
396 
397         /**
398          * Remote device supports receiving video.
399          */
400         public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
401 
402         /**
403          * Remote device supports transmitting video.
404          */
405         public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
406 
407         /**
408          * Remote device supports bidirectional video calling.
409          */
410         public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
411                 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
412 
413         /**
414          * Call is able to be separated from its parent {@code Conference}, if any.
415          */
416         public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
417 
418         /**
419          * Call is able to be individually disconnected when in a {@code Conference}.
420          */
421         public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
422 
423         /**
424          * Speed up audio setup for MT call.
425          * @hide
426          */
427         public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
428 
429         /**
430          * Call can be upgraded to a video call.
431          * @hide
432          * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
433          * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call
434          * whether or not video calling is supported.
435          */
436         @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 119305590)
437         public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
438 
439         /**
440          * For video calls, indicates whether the outgoing video for the call can be paused using
441          * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
442          */
443         public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
444 
445         /**
446          * Call sends responses through connection.
447          * @hide
448          */
449         public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
450 
451         /**
452          * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
453          * <p>
454          * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
455          * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
456          * downgraded from a video call back to a VideoState of
457          * {@link VideoProfile#STATE_AUDIO_ONLY}.
458          * <p>
459          * Intuitively, a call which can be downgraded to audio should also have local and remote
460          * video
461          * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
462          * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
463          */
464         public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
465 
466         /**
467          * When set for an external call, indicates that this {@code Call} can be pulled from a
468          * remote device to the current device.
469          * <p>
470          * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
471          * <p>
472          * An {@link InCallService} will only see calls with this capability if it has the
473          * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
474          * in its manifest.
475          * <p>
476          * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
477          * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
478          */
479         public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
480 
481         /** Call supports the deflect feature. */
482         public static final int CAPABILITY_SUPPORT_DEFLECT = 0x01000000;
483 
484         /**
485          * Call supports adding participants to the call via
486          * {@link #addConferenceParticipants(List)}. Once participants are added, the call becomes
487          * an adhoc conference call ({@link #PROPERTY_IS_ADHOC_CONFERENCE}).
488          */
489         public static final int CAPABILITY_ADD_PARTICIPANT = 0x02000000;
490 
491         /**
492          * When set for a call, indicates that this {@code Call} can be transferred to another
493          * number.
494          * Call supports the confirmed and unconfirmed call transfer feature.
495          *
496          * @hide
497          */
498         public static final int CAPABILITY_TRANSFER = 0x04000000;
499 
500         /**
501          * When set for a call, indicates that this {@code Call} can be transferred to another
502          * ongoing call.
503          * Call supports the consultative call transfer feature.
504          *
505          * @hide
506          */
507         public static final int CAPABILITY_TRANSFER_CONSULTATIVE = 0x08000000;
508 
509         /**
510          * Indicates whether the remote party supports RTT or not to the UI.
511          */
512 
513         public static final int CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT = 0x10000000;
514 
515         //******************************************************************************************
516         // Next CAPABILITY value: 0x20000000
517         //******************************************************************************************
518 
519         /**
520          * Whether the call is currently a conference.
521          */
522         public static final int PROPERTY_CONFERENCE = 0x00000001;
523 
524         /**
525          * Whether the call is a generic conference, where we do not know the precise state of
526          * participants in the conference (eg. on CDMA).
527          */
528         public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
529 
530         /**
531          * Whether the call is made while the device is in emergency callback mode.
532          */
533         public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
534 
535         /**
536          * Connection is using WIFI.
537          */
538         public static final int PROPERTY_WIFI = 0x00000008;
539 
540         /**
541          * When set, the UI should indicate to the user that a call is using high definition
542          * audio.
543          * <p>
544          * The underlying {@link ConnectionService} is responsible for reporting this
545          * property.  It is important to note that this property is not intended to report the
546          * actual audio codec being used for a Call, but whether the call should be indicated
547          * to the user as high definition.
548          * <p>
549          * The Android Telephony stack reports this property for calls based on a number
550          * of factors, including which audio codec is used and whether a call is using an HD
551          * codec end-to-end.  Some mobile operators choose to suppress display of an HD indication,
552          * and in these cases this property will not be set for a call even if the underlying audio
553          * codec is in fact "high definition".
554          */
555         public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
556 
557         /**
558          * Whether the call is associated with the work profile.
559          */
560         public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
561 
562         /**
563          * When set, indicates that this {@code Call} does not actually exist locally for the
564          * {@link ConnectionService}.
565          * <p>
566          * Consider, for example, a scenario where a user has two phones with the same phone number.
567          * When a user places a call on one device, the telephony stack can represent that call on
568          * the other device by adding it to the {@link ConnectionService} with the
569          * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
570          * <p>
571          * An {@link InCallService} will only see calls with this property if it has the
572          * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
573          * in its manifest.
574          * <p>
575          * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
576          */
577         public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
578 
579         /**
580          * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
581          */
582         public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
583 
584         /**
585          * Indicates that the call is from a self-managed {@link ConnectionService}.
586          * <p>
587          * See also {@link Connection#PROPERTY_SELF_MANAGED}
588          */
589         public static final int PROPERTY_SELF_MANAGED = 0x00000100;
590 
591         /**
592          * Indicates the call used Assisted Dialing.
593          *
594          * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
595          */
596         public static final int PROPERTY_ASSISTED_DIALING = 0x00000200;
597 
598         /**
599          * Indicates that the call is an RTT call. Use {@link #getRttCall()} to get the
600          * {@link RttCall} object that is used to send and receive text.
601          */
602         public static final int PROPERTY_RTT = 0x00000400;
603 
604         /**
605          * Indicates that the call has been identified as the network as an emergency call. This
606          * property may be set for both incoming and outgoing calls which the network identifies as
607          * emergency calls.
608          */
609         public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 0x00000800;
610 
611         /**
612          * Indicates that the call is using VoIP audio mode.
613          * <p>
614          * When this property is set, the {@link android.media.AudioManager} audio mode for this
615          * call will be {@link android.media.AudioManager#MODE_IN_COMMUNICATION}.  When this
616          * property is not set, the audio mode for this call will be
617          * {@link android.media.AudioManager#MODE_IN_CALL}.
618          * <p>
619          * This property reflects changes made using {@link Connection#setAudioModeIsVoip(boolean)}.
620          * <p>
621          * You can use this property to determine whether an un-answered incoming call or a held
622          * call will use VoIP audio mode (if the call does not currently have focus, the system
623          * audio mode may not reflect the mode the call will use).
624          */
625         public static final int PROPERTY_VOIP_AUDIO_MODE = 0x00001000;
626 
627         /**
628          * Indicates that the call is an adhoc conference call. This property can be set for both
629          * incoming and outgoing calls. An adhoc conference call is formed using
630          * {@link #addConferenceParticipants(List)},
631          * {@link TelecomManager#addNewIncomingConference(PhoneAccountHandle, Bundle)}, or
632          * {@link TelecomManager#startConference(List, Bundle)}, rather than by merging existing
633          * call using {@link #conference(Call)}.
634          */
635         public static final int PROPERTY_IS_ADHOC_CONFERENCE = 0x00002000;
636 
637         /**
638          * Connection is using cross sim technology.
639          * <p>
640          * Indicates that the {@link Connection} is using a cross sim technology which would
641          * register IMS over internet APN of default data subscription.
642          * <p>
643          */
644         public static final int PROPERTY_CROSS_SIM = 0x00004000;
645 
646         /**
647          * The connection is using transactional call APIs.
648          * <p>
649          * The underlying connection was added as a transactional call via the
650          * {@link TelecomManager#addCall} API.
651          */
652         @FlaggedApi(Flags.FLAG_VOIP_APP_ACTIONS_SUPPORT)
653         public static final int PROPERTY_IS_TRANSACTIONAL = 0x00008000;
654 
655         //******************************************************************************************
656         // Next PROPERTY value: 0x00010000
657         //******************************************************************************************
658 
659         private final @CallState int mState;
660         private final String mTelecomCallId;
661         private final Uri mHandle;
662         private final int mHandlePresentation;
663         private final String mCallerDisplayName;
664         private final int mCallerDisplayNamePresentation;
665         private final PhoneAccountHandle mAccountHandle;
666         private final int mCallCapabilities;
667         private final int mCallProperties;
668         private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
669         private final DisconnectCause mDisconnectCause;
670         private final long mConnectTimeMillis;
671         private final GatewayInfo mGatewayInfo;
672         private final int mVideoState;
673         private final StatusHints mStatusHints;
674         private final Bundle mExtras;
675         private final Bundle mIntentExtras;
676         private final long mCreationTimeMillis;
677         private final String mContactDisplayName;
678         private final @CallDirection int mCallDirection;
679         private final @Connection.VerificationStatus int mCallerNumberVerificationStatus;
680         private final Uri mContactPhotoUri;
681 
682         /**
683          * Whether the supplied capabilities  supports the specified capability.
684          *
685          * @param capabilities A bit field of capabilities.
686          * @param capability The capability to check capabilities for.
687          * @return Whether the specified capability is supported.
688          */
can(int capabilities, int capability)689         public static boolean can(int capabilities, int capability) {
690             return (capabilities & capability) == capability;
691         }
692 
693         /**
694          * Whether the capabilities of this {@code Details} supports the specified capability.
695          *
696          * @param capability The capability to check capabilities for.
697          * @return Whether the specified capability is supported.
698          */
can(int capability)699         public boolean can(int capability) {
700             return can(mCallCapabilities, capability);
701         }
702 
703         /**
704          * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
705          *
706          * @param capabilities A capability bit field.
707          * @return A human readable string representation.
708          */
capabilitiesToString(int capabilities)709         public static String capabilitiesToString(int capabilities) {
710             StringBuilder builder = new StringBuilder();
711             builder.append("[Capabilities:");
712             if (can(capabilities, CAPABILITY_HOLD)) {
713                 builder.append(" CAPABILITY_HOLD");
714             }
715             if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
716                 builder.append(" CAPABILITY_SUPPORT_HOLD");
717             }
718             if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
719                 builder.append(" CAPABILITY_MERGE_CONFERENCE");
720             }
721             if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
722                 builder.append(" CAPABILITY_SWAP_CONFERENCE");
723             }
724             if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
725                 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
726             }
727             if (can(capabilities, CAPABILITY_MUTE)) {
728                 builder.append(" CAPABILITY_MUTE");
729             }
730             if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
731                 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
732             }
733             if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
734                 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
735             }
736             if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
737                 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
738             }
739             if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
740                 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
741             }
742             if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
743                 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
744             }
745             if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
746                 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
747             }
748             if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
749                 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
750             }
751             if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
752                 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
753             }
754             if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
755                 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
756             }
757             if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
758                 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
759             }
760             if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
761                 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
762             }
763             if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
764                 builder.append(" CAPABILITY_CAN_PULL_CALL");
765             }
766             if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
767                 builder.append(" CAPABILITY_SUPPORT_DEFLECT");
768             }
769             if (can(capabilities, CAPABILITY_ADD_PARTICIPANT)) {
770                 builder.append(" CAPABILITY_ADD_PARTICIPANT");
771             }
772             if (can(capabilities, CAPABILITY_TRANSFER)) {
773                 builder.append(" CAPABILITY_TRANSFER");
774             }
775             if (can(capabilities, CAPABILITY_TRANSFER_CONSULTATIVE)) {
776                 builder.append(" CAPABILITY_TRANSFER_CONSULTATIVE");
777             }
778             if (can(capabilities, CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT)) {
779                 builder.append(" CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT");
780             }
781             builder.append("]");
782             return builder.toString();
783         }
784 
785         /**
786          * Whether the supplied properties includes the specified property.
787          *
788          * @param properties A bit field of properties.
789          * @param property The property to check properties for.
790          * @return Whether the specified property is supported.
791          */
hasProperty(int properties, int property)792         public static boolean hasProperty(int properties, int property) {
793             return (properties & property) == property;
794         }
795 
796         /**
797          * Whether the properties of this {@code Details} includes the specified property.
798          *
799          * @param property The property to check properties for.
800          * @return Whether the specified property is supported.
801          */
hasProperty(int property)802         public boolean hasProperty(int property) {
803             return hasProperty(mCallProperties, property);
804         }
805 
806         /**
807          * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
808          *
809          * @param properties A property bit field.
810          * @return A human readable string representation.
811          */
propertiesToString(int properties)812         public static String propertiesToString(int properties) {
813             StringBuilder builder = new StringBuilder();
814             builder.append("[Properties:");
815             if (hasProperty(properties, PROPERTY_CONFERENCE)) {
816                 builder.append(" PROPERTY_CONFERENCE");
817             }
818             if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
819                 builder.append(" PROPERTY_GENERIC_CONFERENCE");
820             }
821             if (hasProperty(properties, PROPERTY_WIFI)) {
822                 builder.append(" PROPERTY_WIFI");
823             }
824             if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
825                 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
826             }
827             if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
828                 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
829             }
830             if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
831                 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
832             }
833             if (hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
834                 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
835             }
836             if (hasProperty(properties, PROPERTY_ASSISTED_DIALING)) {
837                 builder.append(" PROPERTY_ASSISTED_DIALING_USED");
838             }
839             if (hasProperty(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
840                 builder.append(" PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL");
841             }
842             if (hasProperty(properties, PROPERTY_RTT)) {
843                 builder.append(" PROPERTY_RTT");
844             }
845             if (hasProperty(properties, PROPERTY_VOIP_AUDIO_MODE)) {
846                 builder.append(" PROPERTY_VOIP_AUDIO_MODE");
847             }
848             if (hasProperty(properties, PROPERTY_IS_ADHOC_CONFERENCE)) {
849                 builder.append(" PROPERTY_IS_ADHOC_CONFERENCE");
850             }
851             if (hasProperty(properties, PROPERTY_CROSS_SIM)) {
852                 builder.append(" PROPERTY_CROSS_SIM");
853             }
854             if (hasProperty(properties, PROPERTY_IS_TRANSACTIONAL)) {
855                 builder.append(" PROPERTY_IS_TRANSACTIONAL");
856             }
857             builder.append("]");
858             return builder.toString();
859         }
860 
861         /**
862          * @return the state of the {@link Call} represented by this {@link Call.Details}.
863          */
getState()864         public final @CallState int getState() {
865             return mState;
866         }
867 
868         /**
869          * @return the Telecom identifier associated with this {@link Call} . This is not a stable
870          * identifier and is not guaranteed to be unique across device reboots.
871          */
872         @FlaggedApi(Flags.FLAG_CALL_DETAILS_ID_CHANGES)
getId()873         public @NonNull String getId() { return mTelecomCallId; }
874 
875         /** {@hide} */
876         @TestApi
getTelecomCallId()877         public String getTelecomCallId() {
878             return mTelecomCallId;
879         }
880 
881         /**
882          * @return The handle (e.g., phone number) to which the {@code Call} is currently
883          * connected.
884          */
getHandle()885         public Uri getHandle() {
886             return mHandle;
887         }
888 
889         /**
890          * @return The presentation requirements for the handle. See
891          * {@link TelecomManager} for valid values.
892          */
getHandlePresentation()893         public int getHandlePresentation() {
894             return mHandlePresentation;
895         }
896 
897         /**
898          * @return The contact photo URI which corresponds to
899          * {@link android.provider.ContactsContract.PhoneLookup#PHOTO_URI}, or {@code null} if the
900          * lookup is not yet complete, if there's no contacts entry for the caller,
901          * or if the {@link InCallService} does not hold the
902          * {@link android.Manifest.permission#READ_CONTACTS} permission.
903          */
getContactPhotoUri()904         public @Nullable Uri getContactPhotoUri() {
905             return mContactPhotoUri;
906         }
907 
908         /**
909          * The display name for the caller.
910          * <p>
911          * This is the name as reported by the {@link ConnectionService} associated with this call.
912          *
913          * @return The display name for the caller.
914          */
getCallerDisplayName()915         public String getCallerDisplayName() {
916             return mCallerDisplayName;
917         }
918 
919         /**
920          * @return The presentation requirements for the caller display name. See
921          * {@link TelecomManager} for valid values.
922          */
getCallerDisplayNamePresentation()923         public int getCallerDisplayNamePresentation() {
924             return mCallerDisplayNamePresentation;
925         }
926 
927         /**
928          * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
929          * routed.
930          */
getAccountHandle()931         public PhoneAccountHandle getAccountHandle() {
932             return mAccountHandle;
933         }
934 
935         /**
936          * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
937          *         {@code CAPABILITY_*} constants in this class.
938          */
getCallCapabilities()939         public int getCallCapabilities() {
940             return mCallCapabilities;
941         }
942 
943         /**
944          * @return A bitmask of the properties of the {@code Call}, as defined by the various
945          *         {@code PROPERTY_*} constants in this class.
946          */
getCallProperties()947         public int getCallProperties() {
948             return mCallProperties;
949         }
950 
951         /**
952          * @return a bitmask of the audio routes available for the call.
953          *
954          * @hide
955          */
getSupportedAudioRoutes()956         public int getSupportedAudioRoutes() {
957             return mSupportedAudioRoutes;
958         }
959 
960         /**
961          * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
962          * by {@link android.telecom.DisconnectCause}.
963          */
getDisconnectCause()964         public DisconnectCause getDisconnectCause() {
965             return mDisconnectCause;
966         }
967 
968         /**
969          * Returns the time the {@link Call} connected (i.e. became active).  This information is
970          * updated periodically, but user interfaces should not rely on this to display the "call
971          * time clock".  For the time when the call was first added to Telecom, see
972          * {@link #getCreationTimeMillis()}.
973          *
974          * @return The time the {@link Call} connected in milliseconds since the epoch.
975          */
getConnectTimeMillis()976         public final long getConnectTimeMillis() {
977             return mConnectTimeMillis;
978         }
979 
980         /**
981          * @return Information about any calling gateway the {@code Call} may be using.
982          */
getGatewayInfo()983         public GatewayInfo getGatewayInfo() {
984             return mGatewayInfo;
985         }
986 
987         /**
988          * @return The video state of the {@code Call}.
989          */
getVideoState()990         public int getVideoState() {
991             return mVideoState;
992         }
993 
994         /**
995          * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
996          * have been set.
997          */
getStatusHints()998         public StatusHints getStatusHints() {
999             return mStatusHints;
1000         }
1001 
1002         /**
1003          * @return The extras associated with this call.
1004          */
getExtras()1005         public Bundle getExtras() {
1006             return mExtras;
1007         }
1008 
1009         /**
1010          * @return The extras used with the original intent to place this call.
1011          */
getIntentExtras()1012         public Bundle getIntentExtras() {
1013             return mIntentExtras;
1014         }
1015 
1016         /**
1017          * Returns the time when the call was first created and added to Telecom.  This is the same
1018          * time that is logged as the start time in the Call Log (see
1019          * {@link android.provider.CallLog.Calls#DATE}).  To determine when the call was connected
1020          * (became active), see {@link #getConnectTimeMillis()}.
1021          *
1022          * @return The creation time of the call, in millis since the epoch.
1023          */
getCreationTimeMillis()1024         public long getCreationTimeMillis() {
1025             return mCreationTimeMillis;
1026         }
1027 
1028         /**
1029          * Returns the name of the caller on the remote end, as derived from a
1030          * {@link android.provider.ContactsContract} lookup of the call's handle.
1031          * @return The name of the caller, or {@code null} if the lookup is not yet complete, if
1032          *         there's no contacts entry for the caller, or if the {@link InCallService} does
1033          *         not hold the {@link android.Manifest.permission#READ_CONTACTS} permission.
1034          */
getContactDisplayName()1035         public @Nullable String getContactDisplayName() {
1036             return mContactDisplayName;
1037         }
1038 
1039         /**
1040          * Indicates whether the call is an incoming or outgoing call.
1041          * @return The call's direction.
1042          */
getCallDirection()1043         public @CallDirection int getCallDirection() {
1044             return mCallDirection;
1045         }
1046 
1047         /**
1048          * Gets the verification status for the phone number of an incoming call as identified in
1049          * ATIS-1000082.
1050          * <p>
1051          * For incoming calls, the number verification status indicates whether the device was
1052          * able to verify the authenticity of the calling number using the STIR process outlined
1053          * in ATIS-1000082.  {@link Connection#VERIFICATION_STATUS_NOT_VERIFIED} indicates that
1054          * the network was not able to use STIR to verify the caller's number (i.e. nothing is
1055          * known regarding the authenticity of the number.
1056          * {@link Connection#VERIFICATION_STATUS_PASSED} indicates that the network was able to
1057          * use STIR to verify the caller's number.  This indicates that the network has a high
1058          * degree of confidence that the incoming call actually originated from the indicated
1059          * number.  {@link Connection#VERIFICATION_STATUS_FAILED} indicates that the network's
1060          * STIR verification did not pass.  This indicates that the incoming call may not
1061          * actually be from the indicated number.  This could occur if, for example, the caller
1062          * is using an impersonated phone number.
1063          * <p>
1064          * A {@link CallScreeningService} can use this information to help determine if an
1065          * incoming call is potentially an unwanted call.  A verification status of
1066          * {@link Connection#VERIFICATION_STATUS_FAILED} indicates that an incoming call may not
1067          * actually be from the number indicated on the call (i.e. impersonated number) and that it
1068          * should potentially be blocked.  Likewise,
1069          * {@link Connection#VERIFICATION_STATUS_PASSED} can be used as a positive signal to
1070          * help clarify that the incoming call is originating from the indicated number and it
1071          * is less likely to be an undesirable call.
1072          * <p>
1073          * An {@link InCallService} can use this information to provide a visual indicator to the
1074          * user regarding the verification status of a call and to help identify calls from
1075          * potentially impersonated numbers.
1076          * @return the verification status.
1077          */
getCallerNumberVerificationStatus()1078         public @Connection.VerificationStatus int getCallerNumberVerificationStatus() {
1079             return mCallerNumberVerificationStatus;
1080         }
1081 
1082         @Override
equals(Object o)1083         public boolean equals(Object o) {
1084             if (o instanceof Details) {
1085                 Details d = (Details) o;
1086                 return
1087                         Objects.equals(mState, d.mState) &&
1088                         Objects.equals(mHandle, d.mHandle) &&
1089                         Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
1090                         Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
1091                         Objects.equals(mCallerDisplayNamePresentation,
1092                                 d.mCallerDisplayNamePresentation) &&
1093                         Objects.equals(mAccountHandle, d.mAccountHandle) &&
1094                         Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
1095                         Objects.equals(mCallProperties, d.mCallProperties) &&
1096                         Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
1097                         Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
1098                         Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
1099                         Objects.equals(mVideoState, d.mVideoState) &&
1100                         Objects.equals(mStatusHints, d.mStatusHints) &&
1101                         areBundlesEqual(mExtras, d.mExtras) &&
1102                         areBundlesEqual(mIntentExtras, d.mIntentExtras) &&
1103                         Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis) &&
1104                         Objects.equals(mContactDisplayName, d.mContactDisplayName) &&
1105                         Objects.equals(mCallDirection, d.mCallDirection) &&
1106                         Objects.equals(mCallerNumberVerificationStatus,
1107                                 d.mCallerNumberVerificationStatus) &&
1108                         Objects.equals(mContactPhotoUri, d.mContactPhotoUri);
1109             }
1110             return false;
1111         }
1112 
1113         @Override
hashCode()1114         public int hashCode() {
1115             return Objects.hash(mState,
1116                             mHandle,
1117                             mHandlePresentation,
1118                             mCallerDisplayName,
1119                             mCallerDisplayNamePresentation,
1120                             mAccountHandle,
1121                             mCallCapabilities,
1122                             mCallProperties,
1123                             mDisconnectCause,
1124                             mConnectTimeMillis,
1125                             mGatewayInfo,
1126                             mVideoState,
1127                             mStatusHints,
1128                             mExtras,
1129                             mIntentExtras,
1130                             mCreationTimeMillis,
1131                             mContactDisplayName,
1132                             mCallDirection,
1133                             mCallerNumberVerificationStatus,
1134                     mContactPhotoUri);
1135         }
1136 
1137         /** {@hide} */
Details( @allState int state, String telecomCallId, Uri handle, int handlePresentation, String callerDisplayName, int callerDisplayNamePresentation, PhoneAccountHandle accountHandle, int capabilities, int properties, DisconnectCause disconnectCause, long connectTimeMillis, GatewayInfo gatewayInfo, int videoState, StatusHints statusHints, Bundle extras, Bundle intentExtras, long creationTimeMillis, String contactDisplayName, int callDirection, int callerNumberVerificationStatus, Uri contactPhotoUri)1138         public Details(
1139                 @CallState int state,
1140                 String telecomCallId,
1141                 Uri handle,
1142                 int handlePresentation,
1143                 String callerDisplayName,
1144                 int callerDisplayNamePresentation,
1145                 PhoneAccountHandle accountHandle,
1146                 int capabilities,
1147                 int properties,
1148                 DisconnectCause disconnectCause,
1149                 long connectTimeMillis,
1150                 GatewayInfo gatewayInfo,
1151                 int videoState,
1152                 StatusHints statusHints,
1153                 Bundle extras,
1154                 Bundle intentExtras,
1155                 long creationTimeMillis,
1156                 String contactDisplayName,
1157                 int callDirection,
1158                 int callerNumberVerificationStatus,
1159                 Uri contactPhotoUri) {
1160             mState = state;
1161             mTelecomCallId = telecomCallId;
1162             mHandle = handle;
1163             mHandlePresentation = handlePresentation;
1164             mCallerDisplayName = callerDisplayName;
1165             mCallerDisplayNamePresentation = callerDisplayNamePresentation;
1166             mAccountHandle = accountHandle;
1167             mCallCapabilities = capabilities;
1168             mCallProperties = properties;
1169             mDisconnectCause = disconnectCause;
1170             mConnectTimeMillis = connectTimeMillis;
1171             mGatewayInfo = gatewayInfo;
1172             mVideoState = videoState;
1173             mStatusHints = statusHints;
1174             mExtras = extras;
1175             mIntentExtras = intentExtras;
1176             mCreationTimeMillis = creationTimeMillis;
1177             mContactDisplayName = contactDisplayName;
1178             mCallDirection = callDirection;
1179             mCallerNumberVerificationStatus = callerNumberVerificationStatus;
1180             mContactPhotoUri = contactPhotoUri;
1181         }
1182 
1183         /** {@hide} */
createFromParcelableCall(ParcelableCall parcelableCall)1184         public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
1185             return new Details(
1186                     parcelableCall.getState(),
1187                     parcelableCall.getId(),
1188                     parcelableCall.getHandle(),
1189                     parcelableCall.getHandlePresentation(),
1190                     parcelableCall.getCallerDisplayName(),
1191                     parcelableCall.getCallerDisplayNamePresentation(),
1192                     parcelableCall.getAccountHandle(),
1193                     parcelableCall.getCapabilities(),
1194                     parcelableCall.getProperties(),
1195                     parcelableCall.getDisconnectCause(),
1196                     parcelableCall.getConnectTimeMillis(),
1197                     parcelableCall.getGatewayInfo(),
1198                     parcelableCall.getVideoState(),
1199                     parcelableCall.getStatusHints(),
1200                     parcelableCall.getExtras(),
1201                     parcelableCall.getIntentExtras(),
1202                     parcelableCall.getCreationTimeMillis(),
1203                     parcelableCall.getContactDisplayName(),
1204                     parcelableCall.getCallDirection(),
1205                     parcelableCall.getCallerNumberVerificationStatus(),
1206                     parcelableCall.getContactPhotoUri()
1207             );
1208         }
1209 
1210         @Override
toString()1211         public String toString() {
1212             StringBuilder sb = new StringBuilder();
1213             sb.append("[id: ");
1214             sb.append(mTelecomCallId);
1215             sb.append(", state: ");
1216             sb.append(Call.stateToString(mState));
1217             sb.append(", pa: ");
1218             sb.append(mAccountHandle);
1219             sb.append(", hdl: ");
1220             sb.append(Log.piiHandle(mHandle));
1221             sb.append(", hdlPres: ");
1222             sb.append(mHandlePresentation);
1223             sb.append(", videoState: ");
1224             sb.append(VideoProfile.videoStateToString(mVideoState));
1225             sb.append(", caps: ");
1226             sb.append(capabilitiesToString(mCallCapabilities));
1227             sb.append(", props: ");
1228             sb.append(propertiesToString(mCallProperties));
1229             sb.append("]");
1230             return sb.toString();
1231         }
1232     }
1233 
1234     /**
1235      * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
1236      * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
1237      * implementation.
1238      * <p>
1239      * You can handle these callbacks by extending the {@link Callback} class and overriding the
1240      * callbacks that your {@link InCallService} is interested in.  The callback methods include the
1241      * {@link Call} for which the callback applies, allowing reuse of a single instance of your
1242      * {@link Callback} implementation, if desired.
1243      * <p>
1244      * Use {@link Call#registerCallback(Callback)} to register your callback(s).  Ensure
1245      * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
1246      * (typically in {@link InCallService#onCallRemoved(Call)}).
1247      * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
1248      * reach your implementation of {@link Callback}, so it is important to register your callback
1249      * as soon as your {@link InCallService} is notified of a new call via
1250      * {@link InCallService#onCallAdded(Call)}.
1251      */
1252     public static abstract class Callback {
1253         /**
1254          * @hide
1255          */
1256         @IntDef(prefix = { "HANDOVER_" },
1257                 value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED,
1258                 HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL,
1259                 HANDOVER_FAILURE_UNKNOWN})
1260         @Retention(RetentionPolicy.SOURCE)
1261         public @interface HandoverFailureErrors {}
1262 
1263         /**
1264          * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app
1265          * to handover the call to rejects the handover request.
1266          * <p>
1267          * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called
1268          * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a
1269          * {@code null} {@link Connection} from
1270          * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
1271          * ConnectionRequest)}.
1272          * <p>
1273          * For more information on call handovers, see
1274          * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
1275          */
1276         public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1;
1277 
1278         /**
1279          * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1280          * is initiated but the source or destination app does not support handover.
1281          * <p>
1282          * Will be returned when a handover is requested via
1283          * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination
1284          * {@link PhoneAccountHandle} does not declare
1285          * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.  May also be returned when a handover is
1286          * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's
1287          * {@link Details#getAccountHandle()}) does not declare
1288          * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
1289          * <p>
1290          * For more information on call handovers, see
1291          * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
1292          */
1293         public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2;
1294 
1295         /**
1296          * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote
1297          * user rejects the handover request.
1298          * <p>
1299          * For more information on call handovers, see
1300          * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
1301          */
1302         public static final int HANDOVER_FAILURE_USER_REJECTED = 3;
1303 
1304         /**
1305          * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there
1306          * is ongoing emergency call.
1307          * <p>
1308          * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is
1309          * called on an emergency call, or if any other call is an emergency call.
1310          * <p>
1311          * Handovers are not permitted while there are ongoing emergency calls.
1312          * <p>
1313          * For more information on call handovers, see
1314          * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
1315          */
1316         public static final int HANDOVER_FAILURE_ONGOING_EMERGENCY_CALL = 4;
1317 
1318         /**
1319          * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover
1320          * fails for an unknown reason.
1321          * <p>
1322          * For more information on call handovers, see
1323          * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}.
1324          */
1325         public static final int HANDOVER_FAILURE_UNKNOWN = 5;
1326 
1327         /**
1328          * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
1329          *
1330          * @param call The {@code Call} invoking this method.
1331          * @param state The new state of the {@code Call}.
1332          */
onStateChanged(Call call, @CallState int state)1333         public void onStateChanged(Call call, @CallState int state) {}
1334 
1335         /**
1336          * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
1337          *
1338          * @param call The {@code Call} invoking this method.
1339          * @param parent The new parent of the {@code Call}.
1340          */
onParentChanged(Call call, Call parent)1341         public void onParentChanged(Call call, Call parent) {}
1342 
1343         /**
1344          * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
1345          *
1346          * @param call The {@code Call} invoking this method.
1347          * @param children The new children of the {@code Call}.
1348          */
onChildrenChanged(Call call, List<Call> children)1349         public void onChildrenChanged(Call call, List<Call> children) {}
1350 
1351         /**
1352          * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
1353          *
1354          * @param call The {@code Call} invoking this method.
1355          * @param details A {@code Details} object describing the {@code Call}.
1356          */
onDetailsChanged(Call call, Details details)1357         public void onDetailsChanged(Call call, Details details) {}
1358 
1359         /**
1360          * Invoked when the text messages that can be used as responses to the incoming
1361          * {@code Call} are loaded from the relevant database.
1362          * See {@link #getCannedTextResponses()}.
1363          *
1364          * @param call The {@code Call} invoking this method.
1365          * @param cannedTextResponses The text messages useable as responses.
1366          */
onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses)1367         public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
1368 
1369         /**
1370          * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
1371          * character. This causes the post-dial signals to stop pending user confirmation. An
1372          * implementation should present this choice to the user and invoke
1373          * {@link #postDialContinue(boolean)} when the user makes the choice.
1374          *
1375          * @param call The {@code Call} invoking this method.
1376          * @param remainingPostDialSequence The post-dial characters that remain to be sent.
1377          */
onPostDialWait(Call call, String remainingPostDialSequence)1378         public void onPostDialWait(Call call, String remainingPostDialSequence) {}
1379 
1380         /**
1381          * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
1382          *
1383          * @param call The {@code Call} invoking this method.
1384          * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
1385          */
onVideoCallChanged(Call call, InCallService.VideoCall videoCall)1386         public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
1387 
1388         /**
1389          * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
1390          * up their UI for the {@code Call} in response to state transitions. Specifically,
1391          * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
1392          * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
1393          * clients should wait for this method to be invoked.
1394          *
1395          * @param call The {@code Call} being destroyed.
1396          */
onCallDestroyed(Call call)1397         public void onCallDestroyed(Call call) {}
1398 
1399         /**
1400          * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
1401          * conferenced.
1402          *
1403          * @param call The {@code Call} being updated.
1404          * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
1405          *          conferenced.
1406          */
onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls)1407         public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
1408 
1409         /**
1410          * Invoked when a {@link Call} receives an event from its associated {@link Connection} or
1411          * {@link Conference}.
1412          * <p>
1413          * Where possible, the Call should make an attempt to handle {@link Connection} events which
1414          * are part of the {@code android.telecom.*} namespace.  The Call should ignore any events
1415          * it does not wish to handle.  Unexpected events should be handled gracefully, as it is
1416          * possible that a {@link ConnectionService} has defined its own Connection events which a
1417          * Call is not aware of.
1418          * <p>
1419          * See {@link Connection#sendConnectionEvent(String, Bundle)},
1420          * {@link Conference#sendConferenceEvent(String, Bundle)}.
1421          *
1422          * @param call The {@code Call} receiving the event.
1423          * @param event The event.
1424          * @param extras Extras associated with the connection event.
1425          */
onConnectionEvent(Call call, String event, Bundle extras)1426         public void onConnectionEvent(Call call, String event, Bundle extras) {}
1427 
1428         /**
1429          * Invoked when the RTT mode changes for this call.
1430          * @param call The call whose RTT mode has changed.
1431          * @param mode the new RTT mode, one of
1432          * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
1433          *             or {@link RttCall#RTT_MODE_VCO}
1434          */
onRttModeChanged(Call call, int mode)1435         public void onRttModeChanged(Call call, int mode) {}
1436 
1437         /**
1438          * Invoked when the call's RTT status changes, either from off to on or from on to off.
1439          * @param call The call whose RTT status has changed.
1440          * @param enabled whether RTT is now enabled or disabled
1441          * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
1442          *                on, null otherwise.
1443          */
onRttStatusChanged(Call call, boolean enabled, RttCall rttCall)1444         public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
1445 
1446         /**
1447          * Invoked when the remote end of the connection has requested that an RTT communication
1448          * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
1449          * with the same ID that this method is invoked with.
1450          * @param call The call which the RTT request was placed on
1451          * @param id The ID of the request.
1452          */
onRttRequest(Call call, int id)1453         public void onRttRequest(Call call, int id) {}
1454 
1455         /**
1456          * Invoked when the RTT session failed to initiate for some reason, including rejection
1457          * by the remote party.
1458          * <p>
1459          * This callback will ONLY be invoked to report a failure related to a user initiated
1460          * session modification request (i.e. {@link Call#sendRttRequest()}).
1461          * <p>
1462          * If a call is initiated with {@link TelecomManager#EXTRA_START_CALL_WITH_RTT} specified,
1463          * the availability of RTT can be determined by checking {@link Details#PROPERTY_RTT}
1464          * once the call enters state {@link Details#STATE_ACTIVE}.
1465          *
1466          * @param call The call which the RTT initiation failure occurred on.
1467          * @param reason One of the status codes defined in
1468          *      {@link android.telecom.Connection.RttModifyStatus}, with the exception of
1469          *      {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
1470          */
onRttInitiationFailure(Call call, @android.telecom.Connection.RttModifyStatus.RttSessionModifyStatus int reason)1471         public void onRttInitiationFailure(Call call,
1472                 @android.telecom.Connection.RttModifyStatus.RttSessionModifyStatus int reason) {}
1473 
1474         /**
1475          * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1476          * has completed successfully.
1477          * <p>
1478          * For a full discussion of the handover process and the APIs involved, see
1479          * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1480          *
1481          * @param call The call which had initiated handover.
1482          */
onHandoverComplete(Call call)1483         public void onHandoverComplete(Call call) {}
1484 
1485         /**
1486          * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount}
1487          * has failed.
1488          * <p>
1489          * For a full discussion of the handover process and the APIs involved, see
1490          * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
1491          *
1492          * @param call The call which had initiated handover.
1493          * @param failureReason Error reason for failure.
1494          */
onHandoverFailed(Call call, @HandoverFailureErrors int failureReason)1495         public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {}
1496     }
1497 
1498     /**
1499      * A class that holds the state that describes the state of the RTT channel to the remote
1500      * party, if it is active.
1501      */
1502     public static final class RttCall {
1503         /** @hide */
1504         @Retention(RetentionPolicy.SOURCE)
1505         @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
1506         public @interface RttAudioMode {}
1507 
1508         /**
1509          * For metrics use. Default value in the proto.
1510          * @hide
1511          */
1512         public static final int RTT_MODE_INVALID = 0;
1513 
1514         /**
1515          * Indicates that there should be a bidirectional audio stream between the two parties
1516          * on the call.
1517          */
1518         public static final int RTT_MODE_FULL = 1;
1519 
1520         /**
1521          * Indicates that the local user should be able to hear the audio stream from the remote
1522          * user, but not vice versa. Equivalent to muting the microphone.
1523          */
1524         public static final int RTT_MODE_HCO = 2;
1525 
1526         /**
1527          * Indicates that the remote user should be able to hear the audio stream from the local
1528          * user, but not vice versa. Equivalent to setting the volume to zero.
1529          */
1530         public static final int RTT_MODE_VCO = 3;
1531 
1532         private static final int READ_BUFFER_SIZE = 1000;
1533 
1534         private InputStreamReader mReceiveStream;
1535         private OutputStreamWriter mTransmitStream;
1536         private int mRttMode;
1537         private final InCallAdapter mInCallAdapter;
1538         private final String mTelecomCallId;
1539         private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1540 
1541         /**
1542          * @hide
1543          */
RttCall(String telecomCallId, InputStreamReader receiveStream, OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter)1544         public RttCall(String telecomCallId, InputStreamReader receiveStream,
1545                 OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) {
1546             mTelecomCallId = telecomCallId;
1547             mReceiveStream = receiveStream;
1548             mTransmitStream = transmitStream;
1549             mRttMode = mode;
1550             mInCallAdapter = inCallAdapter;
1551         }
1552 
1553         /**
1554          * Returns the current RTT audio mode.
1555          * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
1556          * {@link #RTT_MODE_HCO}.
1557          */
getRttAudioMode()1558         public int getRttAudioMode() {
1559             return mRttMode;
1560         }
1561 
1562         /**
1563          * Sets the RTT audio mode. The requested mode change will be communicated through
1564          * {@link Callback#onRttModeChanged(Call, int)}.
1565          * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
1566          * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
1567          */
setRttMode(@ttAudioMode int mode)1568         public void setRttMode(@RttAudioMode int mode) {
1569             mInCallAdapter.setRttMode(mTelecomCallId, mode);
1570         }
1571 
1572         /**
1573          * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
1574          * RTT transmits text in real-time, this method should be called once for each user action.
1575          * For example, when the user enters text as discrete characters using the keyboard, this
1576          * method should be called once for each character. However, if the user enters text by
1577          * pasting or autocomplete, the entire contents of the pasted or autocompleted text should
1578          * be sent in one call to this method.
1579          *
1580          * This method is not thread-safe -- calling it from multiple threads simultaneously may
1581          * lead to interleaved text.
1582          * @param input The message to send to the remote user.
1583          */
write(String input)1584         public void write(String input) throws IOException {
1585             mTransmitStream.write(input);
1586             mTransmitStream.flush();
1587         }
1588 
1589         /**
1590          * Reads a string from the remote user, blocking if there is no data available. Returns
1591          * {@code null} if the RTT conversation has been terminated and there is no further data
1592          * to read.
1593          *
1594          * This method is not thread-safe -- calling it from multiple threads simultaneously may
1595          * lead to interleaved text.
1596          * @return A string containing text sent by the remote user, or {@code null} if the
1597          * conversation has been terminated or if there was an error while reading.
1598          */
read()1599         public String read() {
1600             try {
1601                 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1602                 if (numRead < 0) {
1603                     return null;
1604                 }
1605                 return new String(mReadBuffer, 0, numRead);
1606             } catch (IOException e) {
1607                 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
1608                 return null;
1609             }
1610         }
1611 
1612         /**
1613          * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1614          * be read.
1615          * @return A string containing text entered by the user, or {@code null} if the user has
1616          * not entered any new text yet.
1617          */
readImmediately()1618         public String readImmediately() throws IOException {
1619             if (mReceiveStream.ready()) {
1620                 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1621                 if (numRead < 0) {
1622                     return null;
1623                 }
1624                 return new String(mReadBuffer, 0, numRead);
1625             } else {
1626                 return null;
1627             }
1628         }
1629 
1630         /**
1631          * Closes the underlying file descriptors
1632          * @hide
1633          */
close()1634         public void close() {
1635             try {
1636                 mReceiveStream.close();
1637             } catch (IOException e) {
1638                 // ignore
1639             }
1640             try {
1641                 mTransmitStream.close();
1642             } catch (IOException e) {
1643                 // ignore
1644             }
1645         }
1646     }
1647 
1648     /**
1649      * @deprecated Use {@code Call.Callback} instead.
1650      * @hide
1651      */
1652     @Deprecated
1653     @SystemApi
1654     public static abstract class Listener extends Callback { }
1655 
1656     private final Phone mPhone;
1657     private final String mTelecomCallId;
1658     private final InCallAdapter mInCallAdapter;
1659     private final List<String> mChildrenIds = new ArrayList<>();
1660     private final List<Call> mChildren = new ArrayList<>();
1661     private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
1662     private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
1663     private final List<Call> mConferenceableCalls = new ArrayList<>();
1664     private final List<Call> mUnmodifiableConferenceableCalls =
1665             Collections.unmodifiableList(mConferenceableCalls);
1666 
1667     private boolean mChildrenCached;
1668     private String mParentId = null;
1669     private String mActiveGenericConferenceChild = null;
1670     private int mState;
1671     private List<String> mCannedTextResponses = null;
1672     private String mCallingPackage;
1673     private int mTargetSdkVersion;
1674     private String mRemainingPostDialSequence;
1675     private VideoCallImpl mVideoCallImpl;
1676     private RttCall mRttCall;
1677     private Details mDetails;
1678     private Bundle mExtras;
1679 
1680     /**
1681      * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1682      *
1683      * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1684      * remaining or this {@code Call} is not in a post-dial state.
1685      */
getRemainingPostDialSequence()1686     public String getRemainingPostDialSequence() {
1687         return mRemainingPostDialSequence;
1688     }
1689 
1690     /**
1691      * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
1692      * @param videoState The video state in which to answer the call.
1693      */
answer(@ideoProfile.VideoState int videoState)1694     public void answer(@VideoProfile.VideoState int videoState) {
1695         mInCallAdapter.answerCall(mTelecomCallId, videoState);
1696     }
1697 
1698     /**
1699      * Instructs this {@link #STATE_RINGING} {@code Call} to deflect.
1700      *
1701      * @param address The address to which the call will be deflected.
1702      */
deflect(Uri address)1703     public void deflect(Uri address) {
1704         mInCallAdapter.deflectCall(mTelecomCallId, address);
1705     }
1706 
1707     /**
1708      * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1709      *
1710      * @param rejectWithMessage Whether to reject with a text message.
1711      * @param textMessage An optional text message with which to respond.
1712      */
reject(boolean rejectWithMessage, String textMessage)1713     public void reject(boolean rejectWithMessage, String textMessage) {
1714         mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
1715     }
1716 
1717     /**
1718      * Instructs the {@link ConnectionService} providing this {@link #STATE_RINGING} call that the
1719      * user has chosen to reject the call and has indicated a reason why the call is being rejected.
1720      *
1721      * @param rejectReason the reason the call is being rejected.
1722      */
reject(@ejectReason int rejectReason)1723     public void reject(@RejectReason int rejectReason) {
1724         mInCallAdapter.rejectCall(mTelecomCallId, rejectReason);
1725     }
1726 
1727     /**
1728      * Instructs this {@code Call} to be transferred to another number.
1729      *
1730      * @param targetNumber The address to which the call will be transferred.
1731      * @param isConfirmationRequired if {@code true} it will initiate a confirmed transfer,
1732      * if {@code false}, it will initiate an unconfirmed transfer.
1733      *
1734      * @hide
1735      */
transfer(@onNull Uri targetNumber, boolean isConfirmationRequired)1736     public void transfer(@NonNull Uri targetNumber, boolean isConfirmationRequired) {
1737         mInCallAdapter.transferCall(mTelecomCallId, targetNumber, isConfirmationRequired);
1738     }
1739 
1740     /**
1741      * Instructs this {@code Call} to be transferred to another ongoing call.
1742      * This will initiate CONSULTATIVE transfer.
1743      * @param toCall The other ongoing {@code Call} to which this call will be transferred.
1744      *
1745      * @hide
1746      */
transfer(@onNull android.telecom.Call toCall)1747     public void transfer(@NonNull android.telecom.Call toCall) {
1748         mInCallAdapter.transferCall(mTelecomCallId, toCall.mTelecomCallId);
1749     }
1750 
1751     /**
1752      * Instructs this {@code Call} to disconnect.
1753      */
disconnect()1754     public void disconnect() {
1755         mInCallAdapter.disconnectCall(mTelecomCallId);
1756     }
1757 
1758     /**
1759      * Instructs this {@code Call} to go on hold.
1760      */
hold()1761     public void hold() {
1762         mInCallAdapter.holdCall(mTelecomCallId);
1763     }
1764 
1765     /**
1766      * Instructs this {@link #STATE_HOLDING} call to release from hold.
1767      */
unhold()1768     public void unhold() {
1769         mInCallAdapter.unholdCall(mTelecomCallId);
1770     }
1771 
1772     /**
1773      * Instructs Telecom to put the call into the background audio processing state.
1774      * <p>
1775      * This method can be called either when the call is in {@link #STATE_RINGING} or
1776      * {@link #STATE_ACTIVE}. After Telecom acknowledges the request by setting the call's state to
1777      * {@link #STATE_AUDIO_PROCESSING}, your app may setup the audio paths with the audio stack in
1778      * order to capture and play audio on the call stream.
1779      * <p>
1780      * This method can only be called by the default dialer app.
1781      * <p>
1782      * Apps built with SDK version {@link android.os.Build.VERSION_CODES#R} or later which are using
1783      * the microphone as part of audio processing should specify the foreground service type using
1784      * the attribute {@link android.R.attr#foregroundServiceType} in the {@link InCallService}
1785      * service element of the app's manifest file.
1786      * The {@link ServiceInfo#FOREGROUND_SERVICE_TYPE_MICROPHONE} attribute should be specified.
1787      * @see <a href="https://developer.android.com/preview/privacy/foreground-service-types">
1788      * the Android Developer Site</a> for more information.
1789      * @hide
1790      */
1791     @SystemApi
enterBackgroundAudioProcessing()1792     public void enterBackgroundAudioProcessing() {
1793         if (mState != STATE_ACTIVE && mState != STATE_RINGING) {
1794             throw new IllegalStateException("Call must be active or ringing");
1795         }
1796         mInCallAdapter.enterBackgroundAudioProcessing(mTelecomCallId);
1797     }
1798 
1799     /**
1800      * Instructs Telecom to come out of the background audio processing state requested by
1801      * {@link #enterBackgroundAudioProcessing()} or from the call screening service.
1802      *
1803      * This method can only be called when the call is in {@link #STATE_AUDIO_PROCESSING}.
1804      *
1805      * @param shouldRing If true, Telecom will put the call into the
1806      *                   {@link #STATE_SIMULATED_RINGING} state and notify other apps that there is
1807      *                   a ringing call. Otherwise, the call will go into {@link #STATE_ACTIVE}
1808      *                   immediately.
1809      * @hide
1810      */
1811     @SystemApi
exitBackgroundAudioProcessing(boolean shouldRing)1812     public void exitBackgroundAudioProcessing(boolean shouldRing) {
1813         if (mState != STATE_AUDIO_PROCESSING) {
1814             throw new IllegalStateException("Call must in the audio processing state");
1815         }
1816         mInCallAdapter.exitBackgroundAudioProcessing(mTelecomCallId, shouldRing);
1817     }
1818 
1819     /**
1820      * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1821      * <p>
1822      * Tones are both played locally for the user to hear and sent to the network to be relayed
1823      * to the remote device.
1824      * <p>
1825      * You must ensure that any call to {@link #playDtmfTone(char)} is followed by a matching
1826      * call to {@link #stopDtmfTone()} and that each tone is stopped before a new one is started.
1827      * The play and stop commands are relayed to the underlying
1828      * {@link android.telecom.ConnectionService} as executed; implementations may not correctly
1829      * handle out of order commands.
1830      *
1831      * @param digit A character representing the DTMF digit for which to play the tone. This
1832      *         value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1833      */
playDtmfTone(char digit)1834     public void playDtmfTone(char digit) {
1835         mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
1836     }
1837 
1838     /**
1839      * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1840      * currently playing.
1841      *
1842      * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1843      * currently playing, this method will do nothing.
1844      */
stopDtmfTone()1845     public void stopDtmfTone() {
1846         mInCallAdapter.stopDtmfTone(mTelecomCallId);
1847     }
1848 
1849     /**
1850      * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1851      *
1852      * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1853      * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
1854      *
1855      * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
1856      * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1857      *
1858      * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
1859      * {@code Call} will pause playing the tones and notify callbacks via
1860      * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
1861      * should display to the user an indication of this state and an affordance to continue
1862      * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1863      * app should invoke the {@link #postDialContinue(boolean)} method.
1864      *
1865      * @param proceed Whether or not to continue with the post-dial sequence.
1866      */
postDialContinue(boolean proceed)1867     public void postDialContinue(boolean proceed) {
1868         mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
1869     }
1870 
1871     /**
1872      * Notifies this {@code Call} that an account has been selected and to proceed with placing
1873      * an outgoing call. Optionally sets this account as the default account.
1874      */
phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault)1875     public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1876         mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
1877 
1878     }
1879 
1880     /**
1881      * Instructs this {@code Call} to enter a conference.
1882      *
1883      * @param callToConferenceWith The other call with which to conference.
1884      */
conference(Call callToConferenceWith)1885     public void conference(Call callToConferenceWith) {
1886         if (callToConferenceWith != null) {
1887             mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
1888         }
1889     }
1890 
1891     /**
1892      * Instructs this {@code Call} to split from any conference call with which it may be
1893      * connected.
1894      */
splitFromConference()1895     public void splitFromConference() {
1896         mInCallAdapter.splitFromConference(mTelecomCallId);
1897     }
1898 
1899     /**
1900      * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
1901      */
mergeConference()1902     public void mergeConference() {
1903         mInCallAdapter.mergeConference(mTelecomCallId);
1904     }
1905 
1906     /**
1907      * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
1908      */
swapConference()1909     public void swapConference() {
1910         mInCallAdapter.swapConference(mTelecomCallId);
1911     }
1912 
1913     /**
1914      * Pulls participants to existing call by forming a conference call.
1915      * See {@link Details#CAPABILITY_ADD_PARTICIPANT}.
1916      *
1917      * @param participants participants to be pulled to existing call.
1918      */
addConferenceParticipants(@onNull List<Uri> participants)1919     public void addConferenceParticipants(@NonNull List<Uri> participants) {
1920         mInCallAdapter.addConferenceParticipants(mTelecomCallId, participants);
1921     }
1922 
1923     /**
1924      * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1925      * device.
1926      * <p>
1927      * Calls to this method are ignored if the call does not have the
1928      * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1929      * <p>
1930      * An {@link InCallService} will only see calls which support this method if it has the
1931      * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1932      * in its manifest.
1933      */
pullExternalCall()1934     public void pullExternalCall() {
1935         // If this isn't an external call, ignore the request.
1936         if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1937             return;
1938         }
1939 
1940         mInCallAdapter.pullExternalCall(mTelecomCallId);
1941     }
1942 
1943     /**
1944      * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1945      * the {@link ConnectionService}.
1946      * <p>
1947      * Call events are used to communicate point in time information from an {@link InCallService}
1948      * to a {@link ConnectionService}.  A {@link ConnectionService} implementation could define
1949      * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1950      * {@link ConnectionService}.
1951      * <p>
1952      * A {@link ConnectionService} can communicate to the {@link InCallService} using
1953      * {@link Connection#sendConnectionEvent(String, Bundle)}.
1954      * <p>
1955      * Events are exposed to {@link ConnectionService} implementations via
1956      * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1957      * <p>
1958      * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
1959      * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1960      * ignore some events altogether.
1961      * <p>
1962      * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1963      * conflicts between {@link InCallService} implementations.  Further, {@link InCallService}
1964      * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1965      * they define their own event types in this namespace.  When defining a custom event type,
1966      * ensure the contents of the extras {@link Bundle} is clearly defined.  Extra keys for this
1967      * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1968      * <p>
1969      * When defining events and the associated extras, it is important to keep their behavior
1970      * consistent when the associated {@link InCallService} is updated.  Support for deprecated
1971      * events/extras should me maintained to ensure backwards compatibility with older
1972      * {@link ConnectionService} implementations which were built to support the older behavior.
1973      *
1974      * @param event The connection event.
1975      * @param extras Bundle containing extra information associated with the event.
1976      */
sendCallEvent(String event, Bundle extras)1977     public void sendCallEvent(String event, Bundle extras) {
1978         mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras);
1979     }
1980 
1981     /**
1982      * Sends an RTT upgrade request to the remote end of the connection. Success is not
1983      * guaranteed, and notification of success will be via the
1984      * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1985      */
sendRttRequest()1986     public void sendRttRequest() {
1987         mInCallAdapter.sendRttRequest(mTelecomCallId);
1988     }
1989 
1990     /**
1991      * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1992      * callback.
1993      * The ID used here should be the same as the ID that was received via the callback.
1994      * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1995      * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1996      */
respondToRttRequest(int id, boolean accept)1997     public void respondToRttRequest(int id, boolean accept) {
1998         mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept);
1999     }
2000 
2001     /**
2002      * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified
2003      * by {@code toHandle}.  The videoState specified indicates the desired video state after the
2004      * handover.
2005      * <p>
2006      * A call handover is the process where an ongoing call is transferred from one app (i.e.
2007      * {@link ConnectionService} to another app.  The user could, for example, choose to continue a
2008      * mobile network call in a video calling app.  The mobile network call via the Telephony stack
2009      * is referred to as the source of the handover, and the video calling app is referred to as the
2010      * destination.
2011      * <p>
2012      * When considering a handover scenario the device this method is called on is considered the
2013      * <em>initiating</em> device (since the user initiates the handover from this device), and the
2014      * other device is considered the <em>receiving</em> device.
2015      * <p>
2016      * When this method is called on the <em>initiating</em> device, the Telecom framework will bind
2017      * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle}
2018      * and invoke
2019      * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle,
2020      * ConnectionRequest)} to inform the destination app that a request has been made to handover a
2021      * call to it.  The app returns an instance of {@link Connection} to represent the handover call
2022      * At this point the app should display UI to indicate to the user that a call
2023      * handover is in process.
2024      * <p>
2025      * The destination app is responsible for communicating the handover request from the
2026      * <em>initiating</em> device to the <em>receiving</em> device.
2027      * <p>
2028      * When the app on the <em>receiving</em> device receives the handover request, it calls
2029      * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover
2030      * process from the <em>initiating</em> device to the <em>receiving</em> device.  At this point
2031      * the destination app on the <em>receiving</em> device should show UI to allow the user to
2032      * choose whether they want to continue their call in the destination app.
2033      * <p>
2034      * When the destination app on the <em>receiving</em> device calls
2035      * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its
2036      * {@link ConnectionService} and call
2037      * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle,
2038      * ConnectionRequest)} to inform it of the handover request.  The app returns an instance of
2039      * {@link Connection} to represent the handover call.
2040      * <p>
2041      * If the user of the <em>receiving</em> device accepts the handover, the app calls
2042      * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the
2043      * original call.  If the user rejects the handover, the app calls
2044      * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause}
2045      * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled.
2046      * <p>
2047      * Telecom will only allow handovers from {@link PhoneAccount}s which declare
2048      * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.  Similarly, the {@link PhoneAccount}
2049      * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}.
2050      * <p>
2051      * Errors in the handover process are reported to the {@link InCallService} via
2052      * {@link Callback#onHandoverFailed(Call, int)}.  Errors in the handover process are reported to
2053      * the involved {@link ConnectionService}s via
2054      * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}.
2055      *
2056      * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover
2057      *                 this call to.
2058      * @param videoState Indicates the video state desired after the handover (see the
2059      *               {@code STATE_*} constants defined in {@link VideoProfile}).
2060      * @param extras Bundle containing extra information to be passed to the
2061      *               {@link ConnectionService}
2062      */
handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState, Bundle extras)2063     public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState,
2064             Bundle extras) {
2065         mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras);
2066     }
2067 
2068     /**
2069      * Terminate the RTT session on this call. The resulting state change will be notified via
2070      * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
2071      */
stopRtt()2072     public void stopRtt() {
2073         mInCallAdapter.stopRtt(mTelecomCallId);
2074     }
2075 
2076     /**
2077      * Adds some extras to this {@link Call}.  Existing keys are replaced and new ones are
2078      * added.
2079      * <p>
2080      * No assumptions should be made as to how an In-Call UI or service will handle these
2081      * extras.  Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2082      * <p>
2083      * Extras added using this method will be made available to the {@link ConnectionService}
2084      * associated with this {@link Call} and notified via
2085      * {@link Connection#onExtrasChanged(Bundle)}.
2086      * <p>
2087      * Extras added using this method will also be available to other running {@link InCallService}s
2088      * and notified via {@link Call.Callback#onDetailsChanged(Call, Details)}.  The extras can be
2089      * accessed via {@link Details#getExtras()}.
2090      *
2091      * @param extras The extras to add.
2092      */
putExtras(Bundle extras)2093     public final void putExtras(Bundle extras) {
2094         if (extras == null) {
2095             return;
2096         }
2097 
2098         if (mExtras == null) {
2099             mExtras = new Bundle();
2100         }
2101         mExtras.putAll(extras);
2102         mInCallAdapter.putExtras(mTelecomCallId, extras);
2103     }
2104 
2105     /**
2106      * Adds a boolean extra to this {@link Call}.
2107      *
2108      * @param key The extra key.
2109      * @param value The value.
2110      * @hide
2111      */
putExtra(String key, boolean value)2112     public final void putExtra(String key, boolean value) {
2113         if (mExtras == null) {
2114             mExtras = new Bundle();
2115         }
2116         mExtras.putBoolean(key, value);
2117         mInCallAdapter.putExtra(mTelecomCallId, key, value);
2118     }
2119 
2120     /**
2121      * Adds an integer extra to this {@link Call}.
2122      *
2123      * @param key The extra key.
2124      * @param value The value.
2125      * @hide
2126      */
putExtra(String key, int value)2127     public final void putExtra(String key, int value) {
2128         if (mExtras == null) {
2129             mExtras = new Bundle();
2130         }
2131         mExtras.putInt(key, value);
2132         mInCallAdapter.putExtra(mTelecomCallId, key, value);
2133     }
2134 
2135     /**
2136      * Adds a string extra to this {@link Call}.
2137      *
2138      * @param key The extra key.
2139      * @param value The value.
2140      * @hide
2141      */
putExtra(String key, String value)2142     public final void putExtra(String key, String value) {
2143         if (mExtras == null) {
2144             mExtras = new Bundle();
2145         }
2146         mExtras.putString(key, value);
2147         mInCallAdapter.putExtra(mTelecomCallId, key, value);
2148     }
2149 
2150     /**
2151      * Removes extras from this {@link Call}.
2152      *
2153      * @param keys The keys of the extras to remove.
2154      */
removeExtras(List<String> keys)2155     public final void removeExtras(List<String> keys) {
2156         if (mExtras != null) {
2157             for (String key : keys) {
2158                 mExtras.remove(key);
2159             }
2160             if (mExtras.size() == 0) {
2161                 mExtras = null;
2162             }
2163         }
2164         mInCallAdapter.removeExtras(mTelecomCallId, keys);
2165     }
2166 
2167     /**
2168      * Removes extras from this {@link Call}.
2169      *
2170      * @param keys The keys of the extras to remove.
2171      */
removeExtras(String .... keys)2172     public final void removeExtras(String ... keys) {
2173         removeExtras(Arrays.asList(keys));
2174     }
2175 
2176     /**
2177      * Obtains the parent of this {@code Call} in a conference, if any.
2178      *
2179      * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
2180      * child of any conference {@code Call}s.
2181      */
getParent()2182     public Call getParent() {
2183         if (mParentId != null) {
2184             return mPhone.internalGetCallByTelecomId(mParentId);
2185         }
2186         return null;
2187     }
2188 
2189     /**
2190      * Obtains the children of this conference {@code Call}, if any.
2191      *
2192      * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
2193      * {@code List} otherwise.
2194      */
getChildren()2195     public List<Call> getChildren() {
2196         if (!mChildrenCached) {
2197             mChildrenCached = true;
2198             mChildren.clear();
2199 
2200             for(String id : mChildrenIds) {
2201                 Call call = mPhone.internalGetCallByTelecomId(id);
2202                 if (call == null) {
2203                     // At least one child was still not found, so do not save true for "cached"
2204                     mChildrenCached = false;
2205                 } else {
2206                     mChildren.add(call);
2207                 }
2208             }
2209         }
2210 
2211         return mUnmodifiableChildren;
2212     }
2213 
2214     /**
2215      * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
2216      *
2217      * @return The list of conferenceable {@code Call}s.
2218      */
getConferenceableCalls()2219     public List<Call> getConferenceableCalls() {
2220         return mUnmodifiableConferenceableCalls;
2221     }
2222 
2223     /**
2224      * Obtains the state of this {@code Call}.
2225      *
2226      * @return The call state.
2227      * @deprecated The call state is available via {@link Call.Details#getState()}.
2228      */
2229     @Deprecated
getState()2230     public @CallState int getState() {
2231         return mState;
2232     }
2233 
2234     /**
2235      * Returns the child {@link Call} in a generic conference that is currently active.
2236      *
2237      * A "generic conference" is the mechanism used to support two simultaneous calls on a device
2238      * in CDMA networks. It is effectively equivalent to having one call active and one call on hold
2239      * in GSM or IMS calls. This method returns the currently active call.
2240      *
2241      * In a generic conference, the network exposes the conference to us as a single call, and we
2242      * switch between talking to the two participants using a CDMA flash command. Since the network
2243      * exposes no additional information about the call, the only way we know which caller we're
2244      * currently talking to is by keeping track of the flash commands that we've sent to the
2245      * network.
2246      *
2247      * For calls that are not generic conferences, or when the generic conference has more than
2248      * 2 children, returns {@code null}.
2249      * @see Details#PROPERTY_GENERIC_CONFERENCE
2250      * @return The active child call.
2251      */
getGenericConferenceActiveChildCall()2252     public @Nullable Call getGenericConferenceActiveChildCall() {
2253         if (mActiveGenericConferenceChild != null) {
2254             return mPhone.internalGetCallByTelecomId(mActiveGenericConferenceChild);
2255         }
2256         return null;
2257     }
2258 
2259     /**
2260      * Obtains a list of canned, pre-configured message responses to present to the user as
2261      * ways of rejecting an incoming {@code Call} using via a text message.
2262      * <p>
2263      * <em>Note:</em> Since canned responses may be loaded from the file system, they are not
2264      * guaranteed to be present when this {@link Call} is first added to the {@link InCallService}
2265      * via {@link InCallService#onCallAdded(Call)}.  The callback
2266      * {@link Call.Callback#onCannedTextResponsesLoaded(Call, List)} will be called when/if canned
2267      * responses for the call become available.
2268      *
2269      * @see #reject(boolean, String)
2270      *
2271      * @return A list of canned text message responses.
2272      */
getCannedTextResponses()2273     public List<String> getCannedTextResponses() {
2274         return mCannedTextResponses;
2275     }
2276 
2277     /**
2278      * Obtains an object that can be used to display video from this {@code Call}.
2279      *
2280      * @return An {@code Call.VideoCall}.
2281      */
getVideoCall()2282     public InCallService.VideoCall getVideoCall() {
2283         return mVideoCallImpl;
2284     }
2285 
2286     /**
2287      * Obtains an object containing call details.
2288      *
2289      * @return A {@link Details} object. Depending on the state of the {@code Call}, the
2290      * result may be {@code null}.
2291      */
getDetails()2292     public Details getDetails() {
2293         return mDetails;
2294     }
2295 
2296     /**
2297      * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
2298      * receive RTT text data, as well as to change the RTT mode.
2299      * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
2300      */
getRttCall()2301     public @Nullable RttCall getRttCall() {
2302         return mRttCall;
2303     }
2304 
2305     /**
2306      * Returns whether this call has an active RTT connection.
2307      * @return true if there is a connection, false otherwise.
2308      */
isRttActive()2309     public boolean isRttActive() {
2310         return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT);
2311     }
2312 
2313     /**
2314      * Registers a callback to this {@code Call}.
2315      *
2316      * @param callback A {@code Callback}.
2317      */
registerCallback(Callback callback)2318     public void registerCallback(Callback callback) {
2319         registerCallback(callback, new Handler());
2320     }
2321 
2322     /**
2323      * Registers a callback to this {@code Call}.
2324      *
2325      * @param callback A {@code Callback}.
2326      * @param handler A handler which command and status changes will be delivered to.
2327      */
registerCallback(Callback callback, Handler handler)2328     public void registerCallback(Callback callback, Handler handler) {
2329         unregisterCallback(callback);
2330         // Don't allow new callback registration if the call is already being destroyed.
2331         if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
2332             mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
2333         }
2334     }
2335 
2336     /**
2337      * Unregisters a callback from this {@code Call}.
2338      *
2339      * @param callback A {@code Callback}.
2340      */
unregisterCallback(Callback callback)2341     public void unregisterCallback(Callback callback) {
2342         // Don't allow callback deregistration if the call is already being destroyed.
2343         if (callback != null && mState != STATE_DISCONNECTED) {
2344             for (CallbackRecord<Callback> record : mCallbackRecords) {
2345                 if (record.getCallback() == callback) {
2346                     mCallbackRecords.remove(record);
2347                     break;
2348                 }
2349             }
2350         }
2351     }
2352 
2353     @Override
toString()2354     public String toString() {
2355         return new StringBuilder().
2356                 append("Call [id: ").
2357                 append(mTelecomCallId).
2358                 append(", state: ").
2359                 append(stateToString(mState)).
2360                 append(", details: ").
2361                 append(mDetails).
2362                 append("]").toString();
2363     }
2364 
2365     /**
2366      * @param state An integer value of a {@code STATE_*} constant.
2367      * @return A string representation of the value.
2368      */
stateToString(int state)2369     private static String stateToString(int state) {
2370         switch (state) {
2371             case STATE_NEW:
2372                 return "NEW";
2373             case STATE_RINGING:
2374                 return "RINGING";
2375             case STATE_DIALING:
2376                 return "DIALING";
2377             case STATE_ACTIVE:
2378                 return "ACTIVE";
2379             case STATE_HOLDING:
2380                 return "HOLDING";
2381             case STATE_DISCONNECTED:
2382                 return "DISCONNECTED";
2383             case STATE_CONNECTING:
2384                 return "CONNECTING";
2385             case STATE_DISCONNECTING:
2386                 return "DISCONNECTING";
2387             case STATE_SELECT_PHONE_ACCOUNT:
2388                 return "SELECT_PHONE_ACCOUNT";
2389             case STATE_SIMULATED_RINGING:
2390                 return "SIMULATED_RINGING";
2391             case STATE_AUDIO_PROCESSING:
2392                 return "AUDIO_PROCESSING";
2393             default:
2394                 Log.w(Call.class, "Unknown state %d", state);
2395                 return "UNKNOWN";
2396         }
2397     }
2398 
2399     /**
2400      * Adds a listener to this {@code Call}.
2401      *
2402      * @param listener A {@code Listener}.
2403      * @deprecated Use {@link #registerCallback} instead.
2404      * @hide
2405      */
2406     @Deprecated
2407     @SystemApi
addListener(Listener listener)2408     public void addListener(Listener listener) {
2409         registerCallback(listener);
2410     }
2411 
2412     /**
2413      * Removes a listener from this {@code Call}.
2414      *
2415      * @param listener A {@code Listener}.
2416      * @deprecated Use {@link #unregisterCallback} instead.
2417      * @hide
2418      */
2419     @Deprecated
2420     @SystemApi
removeListener(Listener listener)2421     public void removeListener(Listener listener) {
2422         unregisterCallback(listener);
2423     }
2424 
2425     /** {@hide} */
Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage, int targetSdkVersion)2426     Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage,
2427          int targetSdkVersion) {
2428         mPhone = phone;
2429         mTelecomCallId = telecomCallId;
2430         mInCallAdapter = inCallAdapter;
2431         mState = STATE_NEW;
2432         mCallingPackage = callingPackage;
2433         mTargetSdkVersion = targetSdkVersion;
2434     }
2435 
2436     /** {@hide} */
Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state, String callingPackage, int targetSdkVersion)2437     Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
2438             String callingPackage, int targetSdkVersion) {
2439         mPhone = phone;
2440         mTelecomCallId = telecomCallId;
2441         mInCallAdapter = inCallAdapter;
2442         mState = state;
2443         mCallingPackage = callingPackage;
2444         mTargetSdkVersion = targetSdkVersion;
2445     }
2446 
2447     /** {@hide} */
internalGetCallId()2448     final String internalGetCallId() {
2449         return mTelecomCallId;
2450     }
2451 
2452     /** {@hide} */
internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap)2453     final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
2454 
2455         // First, we update the internal state as far as possible before firing any updates.
2456         Details details = Details.createFromParcelableCall(parcelableCall);
2457         boolean detailsChanged = !Objects.equals(mDetails, details);
2458         if (detailsChanged) {
2459             mDetails = details;
2460         }
2461 
2462         boolean cannedTextResponsesChanged = false;
2463         if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
2464                 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
2465             mCannedTextResponses =
2466                     Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
2467             cannedTextResponsesChanged = true;
2468         }
2469 
2470         IVideoProvider previousVideoProvider = mVideoCallImpl == null ? null :
2471                 mVideoCallImpl.getVideoProvider();
2472         IVideoProvider newVideoProvider = parcelableCall.getVideoProvider();
2473 
2474         // parcelableCall.isVideoCallProviderChanged is only true when we have a video provider
2475         // specified; so we should check if the actual IVideoProvider changes as well.
2476         boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged()
2477                 && !Objects.equals(previousVideoProvider, newVideoProvider);
2478         if (videoCallChanged) {
2479             if (mVideoCallImpl != null) {
2480                 mVideoCallImpl.destroy();
2481             }
2482             mVideoCallImpl = parcelableCall.isVideoCallProviderChanged() ?
2483                     parcelableCall.getVideoCallImpl(mCallingPackage, mTargetSdkVersion) : null;
2484         }
2485 
2486         if (mVideoCallImpl != null) {
2487             mVideoCallImpl.setVideoState(getDetails().getVideoState());
2488         }
2489 
2490         int state = parcelableCall.getState();
2491         if (mTargetSdkVersion < Phone.SDK_VERSION_R && state == Call.STATE_SIMULATED_RINGING) {
2492             state = Call.STATE_RINGING;
2493         }
2494         boolean stateChanged = mState != state;
2495         if (stateChanged) {
2496             mState = state;
2497         }
2498 
2499         String parentId = parcelableCall.getParentCallId();
2500         boolean parentChanged = !Objects.equals(mParentId, parentId);
2501         if (parentChanged) {
2502             mParentId = parentId;
2503         }
2504 
2505         List<String> childCallIds = parcelableCall.getChildCallIds();
2506         boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
2507         if (childrenChanged) {
2508             mChildrenIds.clear();
2509             mChildrenIds.addAll(parcelableCall.getChildCallIds());
2510             mChildrenCached = false;
2511         }
2512 
2513         String activeChildCallId = parcelableCall.getActiveChildCallId();
2514         boolean activeChildChanged = !Objects.equals(activeChildCallId,
2515                 mActiveGenericConferenceChild);
2516         if (activeChildChanged) {
2517             mActiveGenericConferenceChild = activeChildCallId;
2518         }
2519 
2520         List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
2521         List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
2522         for (String otherId : conferenceableCallIds) {
2523             if (callIdMap.containsKey(otherId)) {
2524                 conferenceableCalls.add(callIdMap.get(otherId));
2525             }
2526         }
2527 
2528         if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
2529             mConferenceableCalls.clear();
2530             mConferenceableCalls.addAll(conferenceableCalls);
2531             fireConferenceableCallsChanged();
2532         }
2533 
2534         boolean isRttChanged = false;
2535         boolean rttModeChanged = false;
2536         if (parcelableCall.getIsRttCallChanged()
2537                 && mDetails.hasProperty(Details.PROPERTY_RTT)) {
2538             ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
2539             InputStreamReader receiveStream = new InputStreamReader(
2540                     new ParcelFileDescriptor.AutoCloseInputStream(
2541                             parcelableRttCall.getReceiveStream()),
2542                     StandardCharsets.UTF_8);
2543             OutputStreamWriter transmitStream = new OutputStreamWriter(
2544                     new ParcelFileDescriptor.AutoCloseOutputStream(
2545                             parcelableRttCall.getTransmitStream()),
2546                     StandardCharsets.UTF_8);
2547             RttCall newRttCall = new Call.RttCall(mTelecomCallId,
2548                     receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
2549             if (mRttCall == null) {
2550                 isRttChanged = true;
2551             } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
2552                 rttModeChanged = true;
2553             }
2554             mRttCall = newRttCall;
2555         } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
2556                 && parcelableCall.getIsRttCallChanged()) {
2557             isRttChanged = true;
2558             mRttCall.close();
2559             mRttCall = null;
2560         }
2561 
2562         // Now we fire updates, ensuring that any client who listens to any of these notifications
2563         // gets the most up-to-date state.
2564 
2565         if (stateChanged) {
2566             fireStateChanged(mState);
2567         }
2568         if (detailsChanged) {
2569             fireDetailsChanged(mDetails);
2570         }
2571         if (cannedTextResponsesChanged) {
2572             fireCannedTextResponsesLoaded(mCannedTextResponses);
2573         }
2574         if (videoCallChanged) {
2575             fireVideoCallChanged(mVideoCallImpl);
2576         }
2577         if (parentChanged) {
2578             fireParentChanged(getParent());
2579         }
2580         if (childrenChanged || activeChildChanged) {
2581             fireChildrenChanged(getChildren());
2582         }
2583         if (isRttChanged) {
2584             fireOnIsRttChanged(mRttCall != null, mRttCall);
2585         }
2586         if (rttModeChanged) {
2587             fireOnRttModeChanged(mRttCall.getRttAudioMode());
2588         }
2589 
2590         // If we have transitioned to DISCONNECTED, that means we need to notify clients and
2591         // remove ourselves from the Phone. Note that we do this after completing all state updates
2592         // so a client can cleanly transition all their UI to the state appropriate for a
2593         // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
2594         // Check if the original state is already disconnected, otherwise onCallRemoved will be
2595         // triggered before onCallAdded.
2596         if (mState == STATE_DISCONNECTED && stateChanged) {
2597             fireCallDestroyed();
2598         }
2599     }
2600 
2601     /** {@hide} */
internalSetPostDialWait(String remaining)2602     final void internalSetPostDialWait(String remaining) {
2603         mRemainingPostDialSequence = remaining;
2604         firePostDialWait(mRemainingPostDialSequence);
2605     }
2606 
2607     /** {@hide} */
internalSetDisconnected()2608     final void internalSetDisconnected() {
2609         if (mState != Call.STATE_DISCONNECTED) {
2610             mState = Call.STATE_DISCONNECTED;
2611             if (mDetails != null) {
2612                 mDetails = new Details(mState,
2613                         mDetails.getTelecomCallId(),
2614                         mDetails.getHandle(),
2615                         mDetails.getHandlePresentation(),
2616                         mDetails.getCallerDisplayName(),
2617                         mDetails.getCallerDisplayNamePresentation(),
2618                         mDetails.getAccountHandle(),
2619                         mDetails.getCallCapabilities(),
2620                         mDetails.getCallProperties(),
2621                         mDetails.getDisconnectCause(),
2622                         mDetails.getConnectTimeMillis(),
2623                         mDetails.getGatewayInfo(),
2624                         mDetails.getVideoState(),
2625                         mDetails.getStatusHints(),
2626                         mDetails.getExtras(),
2627                         mDetails.getIntentExtras(),
2628                         mDetails.getCreationTimeMillis(),
2629                         mDetails.getContactDisplayName(),
2630                         mDetails.getCallDirection(),
2631                         mDetails.getCallerNumberVerificationStatus(),
2632                         mDetails.getContactPhotoUri()
2633                         );
2634                 fireDetailsChanged(mDetails);
2635             }
2636             fireStateChanged(mState);
2637             fireCallDestroyed();
2638         }
2639     }
2640 
2641     /** {@hide} */
internalOnConnectionEvent(String event, Bundle extras)2642     final void internalOnConnectionEvent(String event, Bundle extras) {
2643         fireOnConnectionEvent(event, extras);
2644     }
2645 
2646     /** {@hide} */
internalOnRttUpgradeRequest(final int requestId)2647     final void internalOnRttUpgradeRequest(final int requestId) {
2648         for (CallbackRecord<Callback> record : mCallbackRecords) {
2649             final Call call = this;
2650             final Callback callback = record.getCallback();
2651             record.getHandler().post(() -> callback.onRttRequest(call, requestId));
2652         }
2653     }
2654 
2655     /** @hide */
internalOnRttInitiationFailure(int reason)2656     final void internalOnRttInitiationFailure(int reason) {
2657         for (CallbackRecord<Callback> record : mCallbackRecords) {
2658             final Call call = this;
2659             final Callback callback = record.getCallback();
2660             record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason));
2661         }
2662     }
2663 
2664     /** {@hide} */
internalOnHandoverFailed(int error)2665     final void internalOnHandoverFailed(int error) {
2666         for (CallbackRecord<Callback> record : mCallbackRecords) {
2667             final Call call = this;
2668             final Callback callback = record.getCallback();
2669             record.getHandler().post(() -> callback.onHandoverFailed(call, error));
2670         }
2671     }
2672 
2673     /** {@hide} */
internalOnHandoverComplete()2674     final void internalOnHandoverComplete() {
2675         for (CallbackRecord<Callback> record : mCallbackRecords) {
2676             final Call call = this;
2677             final Callback callback = record.getCallback();
2678             record.getHandler().post(() -> callback.onHandoverComplete(call));
2679         }
2680     }
2681 
fireStateChanged(final int newState)2682     private void fireStateChanged(final int newState) {
2683         for (CallbackRecord<Callback> record : mCallbackRecords) {
2684             final Call call = this;
2685             final Callback callback = record.getCallback();
2686             record.getHandler().post(new Runnable() {
2687                 @Override
2688                 public void run() {
2689                     callback.onStateChanged(call, newState);
2690                 }
2691             });
2692         }
2693     }
2694 
fireParentChanged(final Call newParent)2695     private void fireParentChanged(final Call newParent) {
2696         for (CallbackRecord<Callback> record : mCallbackRecords) {
2697             final Call call = this;
2698             final Callback callback = record.getCallback();
2699             record.getHandler().post(new Runnable() {
2700                 @Override
2701                 public void run() {
2702                     callback.onParentChanged(call, newParent);
2703                 }
2704             });
2705         }
2706     }
2707 
fireChildrenChanged(final List<Call> children)2708     private void fireChildrenChanged(final List<Call> children) {
2709         for (CallbackRecord<Callback> record : mCallbackRecords) {
2710             final Call call = this;
2711             final Callback callback = record.getCallback();
2712             record.getHandler().post(new Runnable() {
2713                 @Override
2714                 public void run() {
2715                     callback.onChildrenChanged(call, children);
2716                 }
2717             });
2718         }
2719     }
2720 
fireDetailsChanged(final Details details)2721     private void fireDetailsChanged(final Details details) {
2722         for (CallbackRecord<Callback> record : mCallbackRecords) {
2723             final Call call = this;
2724             final Callback callback = record.getCallback();
2725             record.getHandler().post(new Runnable() {
2726                 @Override
2727                 public void run() {
2728                     callback.onDetailsChanged(call, details);
2729                 }
2730             });
2731         }
2732     }
2733 
fireCannedTextResponsesLoaded(final List<String> cannedTextResponses)2734     private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
2735         for (CallbackRecord<Callback> record : mCallbackRecords) {
2736             final Call call = this;
2737             final Callback callback = record.getCallback();
2738             record.getHandler().post(new Runnable() {
2739                 @Override
2740                 public void run() {
2741                     callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
2742                 }
2743             });
2744         }
2745     }
2746 
fireVideoCallChanged(final InCallService.VideoCall videoCall)2747     private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
2748         for (CallbackRecord<Callback> record : mCallbackRecords) {
2749             final Call call = this;
2750             final Callback callback = record.getCallback();
2751             record.getHandler().post(new Runnable() {
2752                 @Override
2753                 public void run() {
2754                     callback.onVideoCallChanged(call, videoCall);
2755                 }
2756             });
2757         }
2758     }
2759 
firePostDialWait(final String remainingPostDialSequence)2760     private void firePostDialWait(final String remainingPostDialSequence) {
2761         for (CallbackRecord<Callback> record : mCallbackRecords) {
2762             final Call call = this;
2763             final Callback callback = record.getCallback();
2764             record.getHandler().post(new Runnable() {
2765                 @Override
2766                 public void run() {
2767                     callback.onPostDialWait(call, remainingPostDialSequence);
2768                 }
2769             });
2770         }
2771     }
2772 
fireCallDestroyed()2773     private void fireCallDestroyed() {
2774         /**
2775          * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
2776          * onCallRemoved callback, we remove this call from the Phone's record
2777          * only once all of the registered onCallDestroyed callbacks are executed.
2778          * All the callbacks get removed from our records as a part of this operation
2779          * since onCallDestroyed is the final callback.
2780          */
2781         final Call call = this;
2782         if (mCallbackRecords.isEmpty()) {
2783             // No callbacks registered, remove the call from Phone's record.
2784             mPhone.internalRemoveCall(call);
2785         }
2786         for (final CallbackRecord<Callback> record : mCallbackRecords) {
2787             final Callback callback = record.getCallback();
2788             record.getHandler().post(new Runnable() {
2789                 @Override
2790                 public void run() {
2791                     boolean isFinalRemoval = false;
2792                     RuntimeException toThrow = null;
2793                     try {
2794                         callback.onCallDestroyed(call);
2795                     } catch (RuntimeException e) {
2796                             toThrow = e;
2797                     }
2798                     synchronized(Call.this) {
2799                         mCallbackRecords.remove(record);
2800                         if (mCallbackRecords.isEmpty()) {
2801                             isFinalRemoval = true;
2802                         }
2803                     }
2804                     if (isFinalRemoval) {
2805                         mPhone.internalRemoveCall(call);
2806                     }
2807                     if (toThrow != null) {
2808                         throw toThrow;
2809                     }
2810                 }
2811             });
2812         }
2813     }
2814 
fireConferenceableCallsChanged()2815     private void fireConferenceableCallsChanged() {
2816         for (CallbackRecord<Callback> record : mCallbackRecords) {
2817             final Call call = this;
2818             final Callback callback = record.getCallback();
2819             record.getHandler().post(new Runnable() {
2820                 @Override
2821                 public void run() {
2822                     callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
2823                 }
2824             });
2825         }
2826     }
2827 
2828     /**
2829      * Notifies listeners of an incoming connection event.
2830      * <p>
2831      * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
2832      *
2833      * @param event
2834      * @param extras
2835      */
fireOnConnectionEvent(final String event, final Bundle extras)2836     private void fireOnConnectionEvent(final String event, final Bundle extras) {
2837         for (CallbackRecord<Callback> record : mCallbackRecords) {
2838             final Call call = this;
2839             final Callback callback = record.getCallback();
2840             record.getHandler().post(new Runnable() {
2841                 @Override
2842                 public void run() {
2843                     callback.onConnectionEvent(call, event, extras);
2844                 }
2845             });
2846         }
2847     }
2848 
2849     /**
2850      * Notifies listeners of an RTT on/off change
2851      *
2852      * @param enabled True if RTT is now enabled, false otherwise
2853      */
fireOnIsRttChanged(final boolean enabled, final RttCall rttCall)2854     private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
2855         for (CallbackRecord<Callback> record : mCallbackRecords) {
2856             final Call call = this;
2857             final Callback callback = record.getCallback();
2858             record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
2859         }
2860     }
2861 
2862     /**
2863      * Notifies listeners of a RTT mode change
2864      *
2865      * @param mode The new RTT mode
2866      */
fireOnRttModeChanged(final int mode)2867     private void fireOnRttModeChanged(final int mode) {
2868         for (CallbackRecord<Callback> record : mCallbackRecords) {
2869             final Call call = this;
2870             final Callback callback = record.getCallback();
2871             record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
2872         }
2873     }
2874 
2875     /**
2876      * Determines if two bundles are equal.
2877      *
2878      * @param bundle The original bundle.
2879      * @param newBundle The bundle to compare with.
2880      * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
2881      */
areBundlesEqual(Bundle bundle, Bundle newBundle)2882     private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
2883         if (bundle == null || newBundle == null) {
2884             return bundle == newBundle;
2885         }
2886 
2887         if (bundle.size() != newBundle.size()) {
2888             return false;
2889         }
2890 
2891         for(String key : bundle.keySet()) {
2892             if (key != null) {
2893                 if (!newBundle.containsKey(key)) {
2894                     return false;
2895                 }
2896                 // In case new call extra contains non-framework class objects, return false to
2897                 // force update the call extra
2898                 try {
2899                     final Object value = bundle.get(key);
2900                     final Object newValue = newBundle.get(key);
2901                     if (value instanceof Bundle && newValue instanceof Bundle) {
2902                         if (!areBundlesEqual((Bundle) value, (Bundle) newValue)) {
2903                             return false;
2904                         }
2905                     }
2906                     if (value instanceof byte[] && newValue instanceof byte[]) {
2907                         if (!Arrays.equals((byte[]) value, (byte[]) newValue)) {
2908                             return false;
2909                         }
2910                     } else if (!Objects.equals(value, newValue)) {
2911                         return false;
2912                     }
2913                 } catch (BadParcelableException e) {
2914                     return false;
2915                 }
2916             }
2917         }
2918         return true;
2919     }
2920 }
2921