• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.telephony;
18 
19 import android.Manifest;
20 import android.annotation.CallbackExecutor;
21 import android.annotation.FlaggedApi;
22 import android.annotation.IntDef;
23 import android.annotation.NonNull;
24 import android.annotation.RequiresPermission;
25 import android.annotation.SystemApi;
26 import android.compat.annotation.ChangeId;
27 import android.os.Binder;
28 import android.os.Build;
29 import android.telephony.emergency.EmergencyNumber;
30 import android.telephony.ims.ImsReasonInfo;
31 import android.telephony.ims.MediaQualityStatus;
32 import android.telephony.ims.MediaThreshold;
33 import android.telephony.satellite.NtnSignalStrength;
34 import android.util.Log;
35 
36 import com.android.internal.annotations.VisibleForTesting;
37 import com.android.internal.annotations.WeaklyReferencedCallback;
38 import com.android.internal.telephony.IPhoneStateListener;
39 import com.android.internal.telephony.flags.Flags;
40 
41 import dalvik.system.VMRuntime;
42 
43 import java.lang.annotation.Retention;
44 import java.lang.annotation.RetentionPolicy;
45 import java.lang.ref.WeakReference;
46 import java.time.Duration;
47 import java.util.Arrays;
48 import java.util.List;
49 import java.util.Map;
50 import java.util.Set;
51 import java.util.concurrent.Executor;
52 import java.util.stream.Collectors;
53 
54 /**
55  * A callback class for monitoring changes in specific telephony states
56  * on the device, including service state, signal strength, message
57  * waiting indicator (voicemail), and others.
58  * <p>
59  * To register a callback, use a {@link TelephonyCallback} which implements interfaces regarding
60  * EVENT_*. For example,
61  * FakeServiceStateCallback extends {@link TelephonyCallback} implements
62  * {@link TelephonyCallback.ServiceStateListener}.
63  * <p>
64  * Then override the methods for the state that you wish to receive updates for, and
65  * pass the executor and your TelephonyCallback object to
66  * {@link TelephonyManager#registerTelephonyCallback}.
67  * Methods are called when the state changes, as well as once on initial registration.
68  * <p>
69  * Note that access to some telephony information is
70  * permission-protected. Your application won't receive updates for protected
71  * information unless it has the appropriate permissions declared in
72  * its manifest file. Where permissions apply, they are noted in the
73  * appropriate sub-interfaces.
74  */
75 @WeaklyReferencedCallback
76 public class TelephonyCallback {
77     private static final String LOG_TAG = "TelephonyCallback";
78     /**
79      * Experiment flag to set the per-pid registration limit for TelephonyCallback
80      *
81      * Limit on registrations of {@link TelephonyCallback}s on a per-pid basis. When this limit is
82      * exceeded, any calls to {@link TelephonyManager#registerTelephonyCallback} will fail with an
83      * {@link IllegalStateException}.
84      *
85      * {@link android.os.Process#PHONE_UID}, {@link android.os.Process#SYSTEM_UID}, and the uid that
86      * TelephonyRegistry runs under are exempt from this limit.
87      *
88      * If the value of the flag is less than 1, enforcement of the limit will be disabled.
89      * @hide
90      */
91     public static final String FLAG_PER_PID_REGISTRATION_LIMIT =
92             "phone_state_listener_per_pid_registration_limit";
93 
94     /**
95      * Default value for the per-pid registration limit.
96      * See {@link #FLAG_PER_PID_REGISTRATION_LIMIT}.
97      * @hide
98      */
99     public static final int DEFAULT_PER_PID_REGISTRATION_LIMIT = 50;
100 
101     /**
102      * This change enables a limit on the number of {@link TelephonyCallback} objects any process
103      * may register via {@link TelephonyManager#registerTelephonyCallback}. The default limit is 50,
104      * which may change via remote device config updates.
105      *
106      * This limit is enforced via an {@link IllegalStateException} thrown from
107      * {@link TelephonyManager#registerTelephonyCallback} when the offending process attempts to
108      * register one too many callbacks.
109      *
110      * @hide
111      */
112     @ChangeId
113     public static final long PHONE_STATE_LISTENER_LIMIT_CHANGE_ID = 150880553L;
114 
115     /**
116      * Event for changes to the network service state (cellular).
117      *
118      * <p>Requires {@link Manifest.permission#ACCESS_FINE_LOCATION} or {@link
119      * Manifest.permission#ACCESS_COARSE_LOCATION} depending on the accuracy of the location info
120      * listeners want to get.
121      *
122      * @hide
123      * @see ServiceStateListener#onServiceStateChanged
124      * @see ServiceState
125      */
126     @SystemApi
127     public static final int EVENT_SERVICE_STATE_CHANGED = 1;
128 
129     /**
130      * Event for changes to the network signal strength (cellular).
131      *
132      * @hide
133      * @see SignalStrengthsListener#onSignalStrengthsChanged
134      */
135     @SystemApi
136     public static final int EVENT_SIGNAL_STRENGTH_CHANGED = 2;
137 
138     /**
139      * Event for changes to the message-waiting indicator.
140      * <p>
141      * Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE} or that
142      * the calling app has carrier privileges (see
143      * {@link TelephonyManager#hasCarrierPrivileges}).
144      * <p>
145      * Example: The status bar uses this to determine when to display the
146      * voicemail icon.
147      *
148      * @hide
149      * @see MessageWaitingIndicatorListener#onMessageWaitingIndicatorChanged
150      */
151     @SystemApi
152     @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
153     public static final int EVENT_MESSAGE_WAITING_INDICATOR_CHANGED = 3;
154 
155     /**
156      * Event for changes to the call-forwarding indicator.
157      * <p>
158      * Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE} or that
159      * the calling app has carrier privileges (see
160      * {@link TelephonyManager#hasCarrierPrivileges}).
161      *
162      * @hide
163      * @see CallForwardingIndicatorListener#onCallForwardingIndicatorChanged
164      */
165     @SystemApi
166     @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
167     public static final int EVENT_CALL_FORWARDING_INDICATOR_CHANGED = 4;
168 
169     /**
170      * Event for changes to the device's cell location. Note that
171      * this will result in frequent listeners to the listener.
172      * <p>
173      * If you need regular location updates but want more control over
174      * the update interval or location precision, you can set up a callback
175      * through the {@link android.location.LocationManager location manager}
176      * instead.
177      *
178      * @hide
179      * @see CellLocationListener#onCellLocationChanged
180      */
181     @SystemApi
182     @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION)
183     public static final int EVENT_CELL_LOCATION_CHANGED = 5;
184 
185     /**
186      * Event for changes to the device call state.
187      * <p>
188      * Handles callbacks to {@link CallStateListener#onCallStateChanged(int)}.
189      * <p>
190      * Note: This is different from the legacy {@link #EVENT_LEGACY_CALL_STATE_CHANGED} listener
191      * which can include the phone number of the caller.  We purposely do not include the phone
192      * number as that information is not required for call state listeners going forward.
193      * @hide
194      */
195     @SystemApi
196     public static final int EVENT_CALL_STATE_CHANGED = 6;
197 
198     /**
199      * Event for changes to the data connection state (cellular).
200      *
201      * @hide
202      * @see DataConnectionStateListener#onDataConnectionStateChanged
203      */
204     @SystemApi
205     public static final int EVENT_DATA_CONNECTION_STATE_CHANGED = 7;
206 
207     /**
208      * Event for changes to the direction of data traffic on the data
209      * connection (cellular).
210      * <p>
211      * Example: The status bar uses this to display the appropriate
212      * data-traffic icon.
213      *
214      * @hide
215      * @see DataActivityListener#onDataActivity
216      */
217     @SystemApi
218     public static final int EVENT_DATA_ACTIVITY_CHANGED = 8;
219 
220     /**
221      * Event for changes to the network signal strengths (cellular).
222      * <p>
223      * Example: The status bar uses this to control the signal-strength
224      * icon.
225      *
226      * @hide
227      * @see SignalStrengthsListener#onSignalStrengthsChanged
228      */
229     @SystemApi
230     public static final int EVENT_SIGNAL_STRENGTHS_CHANGED = 9;
231 
232     /**
233      * Event for changes of the network signal strengths (cellular) always reported from modem,
234      * even in some situations such as the screen of the device is off.
235      *
236      * @hide
237      * @see TelephonyManager#setSignalStrengthUpdateRequest
238      */
239     @SystemApi
240     public static final int EVENT_ALWAYS_REPORTED_SIGNAL_STRENGTH_CHANGED = 10;
241 
242     /**
243      * Event for changes to observed cell info.
244      *
245      * @hide
246      * @see CellInfoListener#onCellInfoChanged
247      */
248     @SystemApi
249     @RequiresPermission(allOf = {
250             Manifest.permission.READ_PHONE_STATE,
251             Manifest.permission.ACCESS_FINE_LOCATION
252     })    public static final int EVENT_CELL_INFO_CHANGED = 11;
253 
254     /**
255      * Event for {@link android.telephony.Annotation.PreciseCallStates} of ringing,
256      * background and foreground calls.
257      *
258      * <p>Requires permission {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE}
259      * or the calling app has carrier privileges
260      * (see {@link TelephonyManager#hasCarrierPrivileges}).
261      *
262      * @hide
263      * @see PreciseCallStateListener#onPreciseCallStateChanged
264      */
265     @SystemApi
266     @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE)
267     public static final int EVENT_PRECISE_CALL_STATE_CHANGED = 12;
268 
269     /**
270      * Event for {@link PreciseDataConnectionState} on the data connection (cellular).
271      *
272      * <p>Requires permission {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE}
273      * or the calling app has carrier privileges
274      * (see {@link TelephonyManager#hasCarrierPrivileges}).
275      *
276      * @hide
277      * @see PreciseDataConnectionStateListener#onPreciseDataConnectionStateChanged
278      */
279     @SystemApi
280     @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE)
281     public static final int EVENT_PRECISE_DATA_CONNECTION_STATE_CHANGED = 13;
282 
283     /**
284      * Event for real time info for all data connections (cellular)).
285      *
286      * @hide
287      * @see PhoneStateListener#onDataConnectionRealTimeInfoChanged(DataConnectionRealTimeInfo)
288      * @deprecated Use {@link TelephonyManager#requestModemActivityInfo}
289      */
290     @Deprecated
291     @SystemApi
292     @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE)
293     public static final int EVENT_DATA_CONNECTION_REAL_TIME_INFO_CHANGED = 14;
294 
295     /**
296      * Event for OEM hook raw event
297      *
298      * @hide
299      * @see PhoneStateListener#onOemHookRawEvent
300      */
301     @SystemApi
302     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
303     public static final int EVENT_OEM_HOOK_RAW = 15;
304 
305     /**
306      * Event for changes to the SRVCC state of the active call.
307      *
308      * @hide
309      * @see SrvccStateListener#onSrvccStateChanged
310      */
311     @SystemApi
312     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
313     public static final int EVENT_SRVCC_STATE_CHANGED = 16;
314 
315     /**
316      * Event for carrier network changes indicated by a carrier app.
317      *
318      * @hide
319      * @see android.service.carrier.CarrierService#notifyCarrierNetworkChange(boolean)
320      * @see CarrierNetworkListener#onCarrierNetworkChange
321      */
322     @SystemApi
323     public static final int EVENT_CARRIER_NETWORK_CHANGED = 17;
324 
325     /**
326      * Event for changes to the sim voice activation state
327      *
328      * @hide
329      * @see TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATING
330      * @see TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATED
331      * @see TelephonyManager#SIM_ACTIVATION_STATE_DEACTIVATED
332      * @see TelephonyManager#SIM_ACTIVATION_STATE_RESTRICTED
333      * @see TelephonyManager#SIM_ACTIVATION_STATE_UNKNOWN
334      * <p>
335      * Example: TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATED indicates voice service has been
336      * fully activated
337      * @see VoiceActivationStateListener#onVoiceActivationStateChanged
338      */
339     @SystemApi
340     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
341     public static final int EVENT_VOICE_ACTIVATION_STATE_CHANGED = 18;
342 
343     /**
344      * Event for changes to the sim data activation state
345      *
346      * @hide
347      * @see TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATING
348      * @see TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATED
349      * @see TelephonyManager#SIM_ACTIVATION_STATE_DEACTIVATED
350      * @see TelephonyManager#SIM_ACTIVATION_STATE_RESTRICTED
351      * @see TelephonyManager#SIM_ACTIVATION_STATE_UNKNOWN
352      * <p>
353      * Example: TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATED indicates data service has been
354      * fully activated
355      * @see DataActivationStateListener#onDataActivationStateChanged
356      */
357     @SystemApi
358     public static final int EVENT_DATA_ACTIVATION_STATE_CHANGED = 19;
359 
360     /**
361      * Event for changes to the user mobile data state
362      *
363      * @hide
364      * @see UserMobileDataStateListener#onUserMobileDataStateChanged
365      */
366     @SystemApi
367     public static final int EVENT_USER_MOBILE_DATA_STATE_CHANGED = 20;
368 
369     /**
370      * Event for display info changed event.
371      *
372      * @hide
373      * @see DisplayInfoListener#onDisplayInfoChanged
374      */
375     @SystemApi
376     public static final int EVENT_DISPLAY_INFO_CHANGED = 21;
377 
378     /**
379      * Event for changes to the phone capability.
380      *
381      * @hide
382      * @see PhoneCapabilityListener#onPhoneCapabilityChanged
383      */
384     @SystemApi
385     public static final int EVENT_PHONE_CAPABILITY_CHANGED = 22;
386 
387     /**
388      * Event for changes to active data subscription ID. Active data subscription is
389      * the current subscription used to setup Cellular Internet data. The data is only active on the
390      * subscription at a time, even it is multi-SIM mode. For example, it could be the current
391      * active opportunistic subscription in use, or the subscription user selected as default data
392      * subscription in DSDS mode.
393      *
394      * <p>Requires permission {@link android.Manifest.permission#READ_PHONE_STATE} or the calling
395      * app has carrier privileges (see {@link TelephonyManager#hasCarrierPrivileges}).
396      *
397      * @hide
398      * @see ActiveDataSubscriptionIdListener#onActiveDataSubscriptionIdChanged
399      */
400     @SystemApi
401     @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
402     public static final int EVENT_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGED = 23;
403 
404     /**
405      * Event for changes to the radio power state.
406      *
407      * @hide
408      * @see RadioPowerStateListener#onRadioPowerStateChanged
409      */
410     @SystemApi
411     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
412     public static final int EVENT_RADIO_POWER_STATE_CHANGED = 24;
413 
414     /**
415      * Event for changes to emergency number list based on all active subscriptions.
416      *
417      * <p>Requires permission {@link android.Manifest.permission#READ_PHONE_STATE} or the calling
418      * app has carrier privileges (see {@link TelephonyManager#hasCarrierPrivileges}).
419      *
420      * @hide
421      * @see EmergencyNumberListListener#onEmergencyNumberListChanged
422      */
423     @SystemApi
424     @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
425     public static final int EVENT_EMERGENCY_NUMBER_LIST_CHANGED = 25;
426 
427     /**
428      * Event for call disconnect causes which contains {@link DisconnectCause} and
429      * {@link PreciseDisconnectCause}.
430      *
431      * <p>Requires permission {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE}
432      * or the calling app has carrier privileges
433      * (see {@link TelephonyManager#hasCarrierPrivileges}).
434      *
435      * @hide
436      * @see CallDisconnectCauseListener#onCallDisconnectCauseChanged
437      */
438     @SystemApi
439     @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE)
440     public static final int EVENT_CALL_DISCONNECT_CAUSE_CHANGED = 26;
441 
442     /**
443      * Event for changes to the call attributes of a currently active call.
444      *
445      * <p>Requires permission {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE}
446      * or the calling app has carrier privileges
447      * (see {@link TelephonyManager#hasCarrierPrivileges}).
448      *
449      * @hide
450      * @see CallAttributesListener#onCallAttributesChanged
451      */
452     @SystemApi
453     @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE)
454     public static final int EVENT_CALL_ATTRIBUTES_CHANGED = 27;
455 
456     /**
457      * Event for IMS call disconnect causes which contains
458      * {@link android.telephony.ims.ImsReasonInfo}
459      *
460      * <p>Requires permission {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE}
461      * or the calling app has carrier privileges
462      * (see {@link TelephonyManager#hasCarrierPrivileges}).
463      *
464      * @hide
465      * @see ImsCallDisconnectCauseListener#onImsCallDisconnectCauseChanged(ImsReasonInfo)
466      */
467     @SystemApi
468     @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE)
469     public static final int EVENT_IMS_CALL_DISCONNECT_CAUSE_CHANGED = 28;
470 
471     /**
472      * Event for the emergency number placed from an outgoing call.
473      *
474      * @hide
475      * @see OutgoingEmergencyCallListener#onOutgoingEmergencyCall
476      */
477     @SystemApi
478     @RequiresPermission(Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION)
479     public static final int EVENT_OUTGOING_EMERGENCY_CALL = 29;
480 
481     /**
482      * Event for the emergency number placed from an outgoing SMS.
483      *
484      * @hide
485      * @see OutgoingEmergencySmsListener#onOutgoingEmergencySms
486      */
487     @SystemApi
488     @RequiresPermission(Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION)
489     public static final int EVENT_OUTGOING_EMERGENCY_SMS = 30;
490 
491     /**
492      * Event for registration failures.
493      * <p>
494      * Event for indications that a registration procedure has failed in either the CS or PS
495      * domain. This indication does not necessarily indicate a change of service state, which should
496      * be tracked via {@link #EVENT_SERVICE_STATE_CHANGED}.
497      *
498      * <p>Requires permission {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE} or
499      * the calling app has carrier privileges (see {@link TelephonyManager#hasCarrierPrivileges}).
500      *
501      * <p>Requires the {@link Manifest.permission#ACCESS_FINE_LOCATION} permission in case that
502      * listener want to get location info in {@link CellIdentity} regardless of whether the calling
503      * app has carrier privileges.
504      *
505      * @hide
506      * @see RegistrationFailedListener#onRegistrationFailed
507      */
508     @SystemApi
509     @RequiresPermission(allOf = {
510             Manifest.permission.READ_PRECISE_PHONE_STATE,
511             Manifest.permission.ACCESS_FINE_LOCATION
512     })
513     public static final int EVENT_REGISTRATION_FAILURE = 31;
514 
515     /**
516      * Event for Barring Information for the current registered / camped cell.
517      *
518      * <p>Requires permission {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE} or
519      * the calling app has carrier privileges (see {@link TelephonyManager#hasCarrierPrivileges}).
520      *
521      * <p>Requires the {@link Manifest.permission#ACCESS_FINE_LOCATION} permission in case that
522      * listener want to get {@link BarringInfo} which includes location info in {@link CellIdentity}
523      * regardless of whether the calling app has carrier privileges.
524      *
525      * @hide
526      * @see BarringInfoListener#onBarringInfoChanged
527      */
528     @SystemApi
529     @RequiresPermission(allOf = {
530             Manifest.permission.READ_PRECISE_PHONE_STATE,
531             Manifest.permission.ACCESS_FINE_LOCATION
532     })
533     public static final int EVENT_BARRING_INFO_CHANGED = 32;
534 
535     /**
536      * Event for changes to the physical channel configuration.
537      *
538      * <p>Requires permission {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE}
539      * or the calling app has carrier privileges
540      * (see {@link TelephonyManager#hasCarrierPrivileges}).
541      *
542      * @hide
543      * @see PhysicalChannelConfigListener#onPhysicalChannelConfigChanged
544      */
545     @SystemApi
546     @RequiresPermission(Manifest.permission.READ_PRECISE_PHONE_STATE)
547     public static final int EVENT_PHYSICAL_CHANNEL_CONFIG_CHANGED = 33;
548 
549 
550     /**
551      * Event for changes to the data enabled.
552      * <p>
553      * Event for indications that the enabled status of current data has changed.
554      *
555      * <p>Requires permission {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE}
556      * or the calling app has carrier privileges
557      * (see {@link TelephonyManager#hasCarrierPrivileges}).
558      *
559      * @hide
560      * @see DataEnabledListener#onDataEnabledChanged
561      */
562     @SystemApi
563     @RequiresPermission(Manifest.permission.READ_PRECISE_PHONE_STATE)
564     public static final int EVENT_DATA_ENABLED_CHANGED = 34;
565 
566     /**
567      * Event for changes to allowed network list based on all active subscriptions.
568      *
569      * @hide
570      * @see AllowedNetworkTypesListener#onAllowedNetworkTypesChanged
571      */
572     @SystemApi
573     @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
574     public static final int EVENT_ALLOWED_NETWORK_TYPE_LIST_CHANGED = 35;
575 
576     /**
577      * Event for changes to the legacy call state changed listener implemented by
578      * {@link PhoneStateListener#onCallStateChanged(int, String)}.  This listener variant is similar
579      * to the new {@link CallStateListener#onCallStateChanged(int)} with the important distinction
580      * that it CAN provide the phone number associated with a call.
581      *
582      * @hide
583      */
584     @SystemApi
585     @RequiresPermission(android.Manifest.permission.READ_CALL_LOG)
586     public static final int EVENT_LEGACY_CALL_STATE_CHANGED = 36;
587 
588 
589     /**
590      * Event for changes to the link capacity estimate (LCE)
591      *
592      * <p>Requires permission {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE}
593      *
594      * @see LinkCapacityEstimateChangedListener#onLinkCapacityEstimateChanged
595      *
596      * @hide
597      */
598     @SystemApi
599     @RequiresPermission(Manifest.permission.READ_PRECISE_PHONE_STATE)
600     public static final int EVENT_LINK_CAPACITY_ESTIMATE_CHANGED = 37;
601 
602     /**
603      * Event to norify the Anbr information from Radio to Ims.
604      *
605      * @see ImsCallSessionImplBase#callSessionNotifyAnbr.
606      *
607      * @hide
608      */
609     public static final int EVENT_TRIGGER_NOTIFY_ANBR = 38;
610 
611     /**
612      * Event for changes to the media quality status
613      *
614      * <p>Requires permission {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE}
615      *
616      * @see MediaQualityStatusChangedListener#onMediaQualityStatusChanged
617      *
618      * @hide
619      */
620     @SystemApi
621     @RequiresPermission(Manifest.permission.READ_PRECISE_PHONE_STATE)
622     public static final int EVENT_MEDIA_QUALITY_STATUS_CHANGED = 39;
623 
624 
625     /**
626      * Event for changes to the emergency callback mode
627      *
628      * <p>Requires permission {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE}
629      *
630      * @see EmergencyCallbackModeListener#onCallbackModeStarted(int, Duration, int)
631      * @see EmergencyCallbackModeListener#onCallbackModeRestarted(int, Duration, int)
632      * @see EmergencyCallbackModeListener#onCallbackModeStopped(int, int, int)
633      *
634      * @hide
635      */
636 
637     @FlaggedApi(Flags.FLAG_EMERGENCY_CALLBACK_MODE_NOTIFICATION)
638     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
639     @SystemApi
640     public static final int EVENT_EMERGENCY_CALLBACK_MODE_CHANGED = 40;
641 
642     /**
643      * Event for listening to changes in simultaneous cellular calling subscriptions.
644      *
645      * @see SimultaneousCellularCallingSupportListener
646      *
647      * @hide
648      */
649     @FlaggedApi(Flags.FLAG_SIMULTANEOUS_CALLING_INDICATIONS)
650     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
651     @SystemApi
652     public static final int EVENT_SIMULTANEOUS_CELLULAR_CALLING_SUBSCRIPTIONS_CHANGED = 41;
653 
654     /**
655      * Event for listening to changes in carrier roaming non-terrestrial network mode.
656      *
657      * @see CarrierRoamingNtnModeListener
658      *
659      * @hide
660      */
661     @SystemApi
662     @FlaggedApi(Flags.FLAG_SATELLITE_SYSTEM_APIS)
663     @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
664     public static final int EVENT_CARRIER_ROAMING_NTN_MODE_CHANGED = 42;
665 
666     /**
667      * Event for listening to changes in carrier roaming non-terrestrial network eligibility.
668      *
669      * @see CarrierRoamingNtnModeListener#onCarrierRoamingNtnEligibleStateChanged(boolean)
670      *
671      * Device is eligible for satellite communication if all the following conditions are met:
672      * <ul>
673      * <li>Any subscription on the device supports P2P satellite messaging which is defined by
674      * {@link CarrierConfigManager#KEY_SATELLITE_ATTACH_SUPPORTED_BOOL} </li>
675      * <li>{@link CarrierConfigManager#KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT} set to
676      * {@link CarrierConfigManager#CARRIER_ROAMING_NTN_CONNECT_MANUAL} </li>
677      * <li>The device is in {@link ServiceState#STATE_OUT_OF_SERVICE}, not connected to Wi-Fi,
678      * and the hysteresis timer defined by {@link CarrierConfigManager
679      * #KEY_CARRIER_SUPPORTED_SATELLITE_NOTIFICATION_HYSTERESIS_SEC_INT} is expired.
680      * </li>
681      * </ul>
682      *
683      * @hide
684      */
685     @SystemApi
686     @FlaggedApi(Flags.FLAG_SATELLITE_SYSTEM_APIS)
687     @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
688     public static final int EVENT_CARRIER_ROAMING_NTN_ELIGIBLE_STATE_CHANGED = 43;
689 
690     /**
691      * Event for listening to changes in carrier roaming non-terrestrial network available services
692      * via callback {@link
693      * CarrierRoamingNtnModeListener#onCarrierRoamingNtnAvailableServicesChanged(List)}
694      * This callback is triggered when the available services provided by the carrier roaming
695      * satellite changes. The carrier roaming satellite is defined by the following conditions.
696      * <ul>
697      * <li>Subscription supports attaching to satellite which is defined by
698      * {@link CarrierConfigManager#KEY_SATELLITE_ATTACH_SUPPORTED_BOOL} </li>
699      * </ul>
700      *
701      * @hide
702      */
703     @SystemApi
704     @FlaggedApi(Flags.FLAG_SATELLITE_SYSTEM_APIS)
705     @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
706     public static final int EVENT_CARRIER_ROAMING_NTN_AVAILABLE_SERVICES_CHANGED = 44;
707 
708     /**
709      * Event for listening to carrier roaming non-terrestrial network signal strength changes.
710      *
711      * @see CarrierRoamingNtnModeListener#onCarrierRoamingNtnSignalStrengthChanged(
712      * NtnSignalStrength)
713      *
714      * @hide
715      */
716     @SystemApi
717     @FlaggedApi(Flags.FLAG_SATELLITE_SYSTEM_APIS)
718     @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
719     public static final int EVENT_CARRIER_ROAMING_NTN_SIGNAL_STRENGTH_CHANGED = 45;
720 
721     /**
722      * Event for changes to mobile network ciphering algorithms.
723      * See {@link SecurityAlgorithmsListener#onSecurityAlgorithmsChanged}
724      *
725      * @hide
726      */
727     @FlaggedApi(Flags.FLAG_CELLULAR_IDENTIFIER_DISCLOSURE_INDICATIONS)
728     @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
729     @SystemApi
730     public static final int EVENT_SECURITY_ALGORITHMS_CHANGED = 46;
731 
732      /**
733       * Event for updates to sensitive device identifier disclosures (IMSI, IMEI, unciphered SUCI).
734       * See {@link CellularIdentifierDisclosedListener#onCellularIdentifierDisclosedChanged}
735       *
736       * @hide
737       */
738     @FlaggedApi(Flags.FLAG_CELLULAR_IDENTIFIER_DISCLOSURE_INDICATIONS)
739     @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
740     @SystemApi
741     public static final int EVENT_CELLULAR_IDENTIFIER_DISCLOSED_CHANGED = 47;
742 
743     /**
744      * @hide
745      */
746     @IntDef(prefix = {"EVENT_"}, value = {
747             EVENT_SERVICE_STATE_CHANGED,
748             EVENT_SIGNAL_STRENGTH_CHANGED,
749             EVENT_MESSAGE_WAITING_INDICATOR_CHANGED,
750             EVENT_CALL_FORWARDING_INDICATOR_CHANGED,
751             EVENT_CELL_LOCATION_CHANGED,
752             EVENT_CALL_STATE_CHANGED,
753             EVENT_DATA_CONNECTION_STATE_CHANGED,
754             EVENT_DATA_ACTIVITY_CHANGED,
755             EVENT_SIGNAL_STRENGTHS_CHANGED,
756             EVENT_ALWAYS_REPORTED_SIGNAL_STRENGTH_CHANGED,
757             EVENT_CELL_INFO_CHANGED,
758             EVENT_PRECISE_CALL_STATE_CHANGED,
759             EVENT_PRECISE_DATA_CONNECTION_STATE_CHANGED,
760             EVENT_DATA_CONNECTION_REAL_TIME_INFO_CHANGED,
761             EVENT_OEM_HOOK_RAW,
762             EVENT_SRVCC_STATE_CHANGED,
763             EVENT_CARRIER_NETWORK_CHANGED,
764             EVENT_VOICE_ACTIVATION_STATE_CHANGED,
765             EVENT_DATA_ACTIVATION_STATE_CHANGED,
766             EVENT_USER_MOBILE_DATA_STATE_CHANGED,
767             EVENT_DISPLAY_INFO_CHANGED,
768             EVENT_PHONE_CAPABILITY_CHANGED,
769             EVENT_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGED,
770             EVENT_RADIO_POWER_STATE_CHANGED,
771             EVENT_EMERGENCY_NUMBER_LIST_CHANGED,
772             EVENT_CALL_DISCONNECT_CAUSE_CHANGED,
773             EVENT_CALL_ATTRIBUTES_CHANGED,
774             EVENT_IMS_CALL_DISCONNECT_CAUSE_CHANGED,
775             EVENT_OUTGOING_EMERGENCY_CALL,
776             EVENT_OUTGOING_EMERGENCY_SMS,
777             EVENT_REGISTRATION_FAILURE,
778             EVENT_BARRING_INFO_CHANGED,
779             EVENT_PHYSICAL_CHANNEL_CONFIG_CHANGED,
780             EVENT_DATA_ENABLED_CHANGED,
781             EVENT_ALLOWED_NETWORK_TYPE_LIST_CHANGED,
782             EVENT_LEGACY_CALL_STATE_CHANGED,
783             EVENT_LINK_CAPACITY_ESTIMATE_CHANGED,
784             EVENT_TRIGGER_NOTIFY_ANBR,
785             EVENT_MEDIA_QUALITY_STATUS_CHANGED,
786             EVENT_EMERGENCY_CALLBACK_MODE_CHANGED,
787             EVENT_SIMULTANEOUS_CELLULAR_CALLING_SUBSCRIPTIONS_CHANGED,
788             EVENT_CARRIER_ROAMING_NTN_MODE_CHANGED,
789             EVENT_CARRIER_ROAMING_NTN_ELIGIBLE_STATE_CHANGED,
790             EVENT_CARRIER_ROAMING_NTN_AVAILABLE_SERVICES_CHANGED,
791             EVENT_CARRIER_ROAMING_NTN_SIGNAL_STRENGTH_CHANGED,
792             EVENT_SECURITY_ALGORITHMS_CHANGED,
793             EVENT_CELLULAR_IDENTIFIER_DISCLOSED_CHANGED
794     })
795     @Retention(RetentionPolicy.SOURCE)
796     public @interface TelephonyEvent {
797     }
798 
799     /**
800      * @hide
801      */
802     //TODO: The maxTargetSdk should be S if the build time tool updates it.
803     @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
804     public IPhoneStateListener callback;
805 
806     /**
807      * @hide
808      */
init(@onNull @allbackExecutor Executor executor)809     public void init(@NonNull @CallbackExecutor Executor executor) {
810         if (executor == null) {
811             throw new IllegalArgumentException("TelephonyCallback Executor must be non-null");
812         }
813         callback = new IPhoneStateListenerStub(this, executor);
814     }
815 
816     /**
817      * Interface for service state listener.
818      */
819     public interface ServiceStateListener {
820         /**
821          * Callback invoked when device service state changes on the registered subscription.
822          * Note, the registration subscription ID comes from {@link TelephonyManager} object
823          * which registers TelephonyCallback by
824          * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}.
825          * If this TelephonyManager object was created with
826          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
827          * subscription ID. Otherwise, this callback applies to
828          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
829          * <p>
830          * The instance of {@link ServiceState} passed as an argument here will have various
831          * levels of location information stripped from it depending on the location permissions
832          * that your app holds.
833          * Only apps holding the {@link Manifest.permission#ACCESS_FINE_LOCATION} permission will
834          * receive all the information in {@link ServiceState}, otherwise the cellIdentity
835          * will be null if apps only holding the {@link Manifest.permission#ACCESS_COARSE_LOCATION}
836          * permission. Network operator name in long/short alphanumeric format and numeric id will
837          * be null if apps holding neither {@link android.Manifest.permission#ACCESS_FINE_LOCATION}
838          *
839          * @see ServiceState#STATE_EMERGENCY_ONLY
840          * @see ServiceState#STATE_IN_SERVICE
841          * @see ServiceState#STATE_OUT_OF_SERVICE
842          * @see ServiceState#STATE_POWER_OFF
843          */
onServiceStateChanged(@onNull ServiceState serviceState)844         void onServiceStateChanged(@NonNull ServiceState serviceState);
845     }
846 
847     /**
848      * Interface for message waiting indicator listener.
849      */
850     public interface MessageWaitingIndicatorListener {
851         /**
852          * Callback invoked when the message-waiting indicator changes on the registered
853          * subscription.
854          * Note, the registration subscription ID comes from {@link TelephonyManager} object by
855          * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}.
856          * If this TelephonyManager object was created with
857          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
858          * subscription ID. Otherwise, this callback applies to
859          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
860          *
861          * The calling app should have carrier privileges
862          * (see {@link TelephonyManager#hasCarrierPrivileges}) if it does not have the
863          * {@link android.Manifest.permission#READ_PHONE_STATE}.
864          *
865          */
866         @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
onMessageWaitingIndicatorChanged(boolean mwi)867         void onMessageWaitingIndicatorChanged(boolean mwi);
868     }
869 
870     /**
871      * Interface for call-forwarding indicator listener.
872      */
873     public interface CallForwardingIndicatorListener {
874         /**
875          * Callback invoked when the call-forwarding indicator changes on the registered
876          * subscription.
877          * Note, the registration subscription ID comes from {@link TelephonyManager} object
878          * which registers TelephonyCallback by
879          * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}.
880          * If this TelephonyManager object was created with
881          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
882          * subscription ID. Otherwise, this callback applies to
883          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
884          *
885          * The calling app should have carrier privileges
886          * (see {@link TelephonyManager#hasCarrierPrivileges}) if it does not have the
887          * {@link android.Manifest.permission#READ_PHONE_STATE}.
888          *
889          */
890         @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
onCallForwardingIndicatorChanged(boolean cfi)891         void onCallForwardingIndicatorChanged(boolean cfi);
892     }
893 
894     /**
895      * Interface for device cell location listener.
896      */
897     public interface CellLocationListener {
898         /**
899          * Callback invoked when device cell location changes on the registered subscription.
900          * Note, the registration subscription ID comes from {@link TelephonyManager} object
901          * which registers TelephonyCallback by
902          * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}.
903          * If this TelephonyManager object was created with
904          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
905          * subscription ID. Otherwise, this callback applies to
906          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
907          */
908         @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION)
onCellLocationChanged(@onNull CellLocation location)909         void onCellLocationChanged(@NonNull CellLocation location);
910     }
911 
912     /**
913      * Interface for call state listener.
914      */
915     public interface CallStateListener {
916         /**
917          * Callback invoked when device call state changes.
918          * <p>
919          * Reports the state of Telephony (mobile) calls on the device for the registered
920          * subscription.
921          * <p>
922          * Note: the registration subscription ID comes from {@link TelephonyManager} object
923          * which registers TelephonyCallback by
924          * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}.
925          * If this TelephonyManager object was created with
926          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
927          * subscription ID. Otherwise, this callback applies to
928          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
929          * <p>
930          * Note: The state returned here may differ from that returned by
931          * {@link TelephonyManager#getCallState()}. Receivers of this callback should be aware that
932          * calling {@link TelephonyManager#getCallState()} from within this callback may return a
933          * different state than the callback reports.
934          *
935          * @param state the current call state
936          */
937         @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
onCallStateChanged(@nnotation.CallState int state)938         void onCallStateChanged(@Annotation.CallState int state);
939     }
940 
941     /**
942      * Interface for data connection state listener.
943      */
944     public interface DataConnectionStateListener {
945         /**
946          * Callback invoked when connection state changes on the registered subscription.
947          * Note, the registration subscription ID comes from {@link TelephonyManager} object
948          * which registers TelephonyCallback by
949          * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}.
950          * If this TelephonyManager object was created with
951          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
952          * subscription ID. Otherwise, this callback applies to
953          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
954          *
955          * @param state       is the current state of data connection.
956          * @param networkType is the current network type of data connection.
957          * @see TelephonyManager#DATA_DISCONNECTED
958          * @see TelephonyManager#DATA_CONNECTING
959          * @see TelephonyManager#DATA_CONNECTED
960          * @see TelephonyManager#DATA_SUSPENDED
961          * @see TelephonyManager#DATA_HANDOVER_IN_PROGRESS
962          */
onDataConnectionStateChanged(@elephonyManager.DataState int state, @Annotation.NetworkType int networkType)963         void onDataConnectionStateChanged(@TelephonyManager.DataState int state,
964                 @Annotation.NetworkType int networkType);
965     }
966 
967     /**
968      * Interface for data activity state listener.
969      */
970     public interface DataActivityListener {
971         /**
972          * Callback invoked when data activity state changes on the registered subscription.
973          * Note, the registration subscription ID comes from {@link TelephonyManager} object
974          * which registers TelephonyCallback by
975          * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}.
976          * If this TelephonyManager object was created with
977          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
978          * subscription ID. Otherwise, this callback applies to
979          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
980          *
981          * @see TelephonyManager#DATA_ACTIVITY_NONE
982          * @see TelephonyManager#DATA_ACTIVITY_IN
983          * @see TelephonyManager#DATA_ACTIVITY_OUT
984          * @see TelephonyManager#DATA_ACTIVITY_INOUT
985          * @see TelephonyManager#DATA_ACTIVITY_DORMANT
986          */
onDataActivity(@nnotation.DataActivityType int direction)987         void onDataActivity(@Annotation.DataActivityType int direction);
988     }
989 
990     /**
991      * Interface for network signal strengths listener.
992      */
993     public interface SignalStrengthsListener {
994         /**
995          * Callback invoked when network signal strengths changes on the registered subscription.
996          * Note, the registration subscription ID comes from {@link TelephonyManager} object
997          * which registers TelephonyCallback by
998          * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}.
999          * If this TelephonyManager object was created with
1000          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
1001          * subscription ID. Otherwise, this callback applies to
1002          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
1003          */
onSignalStrengthsChanged(@onNull SignalStrength signalStrength)1004         void onSignalStrengthsChanged(@NonNull SignalStrength signalStrength);
1005     }
1006 
1007     /**
1008      * Interface for cell info listener.
1009      */
1010     public interface CellInfoListener {
1011         /**
1012          * Callback invoked when an observed cell info has changed or new cells have been added
1013          * or removed on the registered subscription.
1014          * Note, the registration subscription ID s from {@link TelephonyManager} object
1015          * which registers TelephonyCallback by
1016          * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}.
1017          * If this TelephonyManager object was created with
1018          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
1019          * subscription ID. Otherwise, this callback applies to
1020          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
1021          *
1022          * @param cellInfo is the list of currently visible cells.
1023          */
1024         @RequiresPermission(allOf = {
1025                 Manifest.permission.READ_PHONE_STATE,
1026                 Manifest.permission.ACCESS_FINE_LOCATION
1027         })
onCellInfoChanged(@onNull List<CellInfo> cellInfo)1028         void onCellInfoChanged(@NonNull List<CellInfo> cellInfo);
1029     }
1030 
1031     /**
1032      * Interface for precise device call state listener.
1033      *
1034      * @hide
1035      */
1036     @SystemApi
1037     public interface PreciseCallStateListener {
1038         /**
1039          * Callback invoked when precise device call state changes on the registered subscription.
1040          * Note, the registration subscription ID comes from {@link TelephonyManager} object
1041          * which registers TelephonyCallback by
1042          * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}.
1043          * If this TelephonyManager object was created with
1044          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
1045          * subscription ID. Otherwise, this callback applies to
1046          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
1047          *
1048          * The calling app should have carrier privileges
1049          * (see {@link TelephonyManager#hasCarrierPrivileges}) if it does not have the
1050          * {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE}.
1051          *
1052          * @param callState {@link PreciseCallState}
1053          */
1054         @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE)
onPreciseCallStateChanged(@onNull PreciseCallState callState)1055         void onPreciseCallStateChanged(@NonNull PreciseCallState callState);
1056     }
1057 
1058     /**
1059      * Interface for call disconnect cause listener.
1060      */
1061     public interface CallDisconnectCauseListener {
1062         /**
1063          * Callback invoked when call disconnect cause changes on the registered subscription.
1064          * Note, the registration subscription ID comes from {@link TelephonyManager} object
1065          * which registers TelephonyCallback by
1066          * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}.
1067          * If this TelephonyManager object was created with
1068          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
1069          * subscription ID. Otherwise, this callback applies to
1070          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
1071          *
1072          * @param disconnectCause        the disconnect cause
1073          * @param preciseDisconnectCause the precise disconnect cause
1074          */
1075         @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE)
onCallDisconnectCauseChanged(@nnotation.DisconnectCauses int disconnectCause, @Annotation.PreciseDisconnectCauses int preciseDisconnectCause)1076         void onCallDisconnectCauseChanged(@Annotation.DisconnectCauses int disconnectCause,
1077                 @Annotation.PreciseDisconnectCauses int preciseDisconnectCause);
1078     }
1079 
1080     /**
1081      * Interface for IMS call disconnect cause listener.
1082      */
1083     public interface ImsCallDisconnectCauseListener {
1084         /**
1085          * Callback invoked when IMS call disconnect cause changes on the registered subscription.
1086          * Note, the registration subscription ID comes from {@link TelephonyManager} object
1087          * which registers TelephonyCallback by
1088          * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}.
1089          * If this TelephonyManager object was created with
1090          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
1091          * subscription ID. Otherwise, this callback applies to
1092          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
1093          *
1094          * The calling app should have carrier privileges
1095          * (see {@link TelephonyManager#hasCarrierPrivileges}) if it does not have the
1096          * {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE}.
1097          *
1098          * @param imsReasonInfo {@link ImsReasonInfo} contains details on why IMS call failed.
1099          */
1100         @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE)
onImsCallDisconnectCauseChanged(@onNull ImsReasonInfo imsReasonInfo)1101         void onImsCallDisconnectCauseChanged(@NonNull ImsReasonInfo imsReasonInfo);
1102     }
1103 
1104     /**
1105      * Interface for precise data connection state listener.
1106      */
1107     public interface PreciseDataConnectionStateListener {
1108         /**
1109          * Callback providing update about the default/internet data connection on the registered
1110          * subscription.
1111          * <p>
1112          * Note, the registration subscription ID comes from {@link TelephonyManager} object
1113          * which registers TelephonyCallback by
1114          * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}.
1115          * If this TelephonyManager object was created with
1116          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
1117          * subscription ID. Otherwise, this callback applies to
1118          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
1119          *
1120          * The calling app should have carrier privileges
1121          * (see {@link TelephonyManager#hasCarrierPrivileges}) if it does not have the
1122          * {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE}.
1123          *
1124          * @param dataConnectionState {@link PreciseDataConnectionState}
1125          */
1126         @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE)
onPreciseDataConnectionStateChanged( @onNull PreciseDataConnectionState dataConnectionState)1127         void onPreciseDataConnectionStateChanged(
1128             @NonNull PreciseDataConnectionState dataConnectionState);
1129     }
1130 
1131     /**
1132      * Interface for Single Radio Voice Call Continuity listener.
1133      *
1134      * @hide
1135      */
1136     @SystemApi
1137     public interface SrvccStateListener {
1138         /**
1139          * Callback invoked when there has been a change in the Single Radio Voice Call Continuity
1140          * (SRVCC) state for the currently active call on the registered subscription.
1141          * <p>
1142          * Note, the registration subscription ID comes from {@link TelephonyManager} object
1143          * which registers TelephonyCallback by
1144          * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}.
1145          * If this TelephonyManager object was created with
1146          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
1147          * subscription ID. Otherwise, this callback applies to
1148          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
1149          */
1150         @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
onSrvccStateChanged(@nnotation.SrvccState int srvccState)1151         void onSrvccStateChanged(@Annotation.SrvccState int srvccState);
1152     }
1153 
1154     /**
1155      * Interface for SIM voice activation state listener.
1156      *
1157      * @hide
1158      */
1159     @SystemApi
1160     public interface VoiceActivationStateListener {
1161         /**
1162          * Callback invoked when the SIM voice activation state has changed on the registered
1163          * subscription.
1164          * Note, the registration subscription ID comes from {@link TelephonyManager} object
1165          * which registers TelephonyCallback by
1166          * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}.
1167          * If this TelephonyManager object was created with
1168          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
1169          * subscription ID. Otherwise, this callback applies to
1170          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
1171          *
1172          * @param state is the current SIM voice activation state
1173          */
1174         @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
onVoiceActivationStateChanged(@nnotation.SimActivationState int state)1175         void onVoiceActivationStateChanged(@Annotation.SimActivationState int state);
1176 
1177     }
1178 
1179     /**
1180      * Interface for SIM data activation state listener.
1181      */
1182     public interface DataActivationStateListener {
1183         /**
1184          * Callback invoked when the SIM data activation state has changed on the registered
1185          * subscription.
1186          * Note, the registration subscription ID comes from {@link TelephonyManager} object
1187          * which registers TelephonyCallback by
1188          * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}.
1189          * If this TelephonyManager object was created with
1190          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
1191          * subscription ID. Otherwise, this callback applies to
1192          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
1193          *
1194          * @param state is the current SIM data activation state
1195          */
onDataActivationStateChanged(@nnotation.SimActivationState int state)1196         void onDataActivationStateChanged(@Annotation.SimActivationState int state);
1197     }
1198 
1199     /**
1200      * Interface for user mobile data state listener.
1201      */
1202     public interface UserMobileDataStateListener {
1203         /**
1204          * Callback invoked when the user mobile data state has changed on the registered
1205          * subscription.
1206          * Note, the registration subscription ID comes from {@link TelephonyManager} object
1207          * which registers TelephonyCallback by
1208          * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}.
1209          * If this TelephonyManager object was created with
1210          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
1211          * subscription ID. Otherwise, this callback applies to
1212          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
1213          *
1214          * @param enabled indicates whether the current user mobile data state is enabled or
1215          *                disabled.
1216          */
onUserMobileDataStateChanged(boolean enabled)1217         void onUserMobileDataStateChanged(boolean enabled);
1218     }
1219 
1220     /**
1221      * Interface for display info listener.
1222      */
1223     public interface DisplayInfoListener {
1224         /**
1225          * Callback invoked when the display info has changed on the registered subscription.
1226          * <p> The {@link TelephonyDisplayInfo} contains status information shown to the user
1227          * based on carrier policy.
1228          *
1229          * @param telephonyDisplayInfo The display information.
1230          */
onDisplayInfoChanged(@onNull TelephonyDisplayInfo telephonyDisplayInfo)1231         void onDisplayInfoChanged(@NonNull TelephonyDisplayInfo telephonyDisplayInfo);
1232     }
1233 
1234     /**
1235      * Interface for the current emergency number list listener.
1236      */
1237     public interface EmergencyNumberListListener {
1238         /**
1239          * Callback invoked when the current emergency number list has changed on the registered
1240          * subscription.
1241          * <p>
1242          * Note, the registered subscription is associated with {@link TelephonyManager} object
1243          * on which
1244          * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}
1245          * was called.
1246          * If this TelephonyManager object was created with
1247          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
1248          * given subscription ID. Otherwise, this callback applies to
1249          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
1250          *
1251          * The calling app should have carrier privileges
1252          * (see {@link TelephonyManager#hasCarrierPrivileges}) if it does not have the
1253          * {@link android.Manifest.permission#READ_PHONE_STATE}.
1254          *
1255          * @param emergencyNumberList Map associating all active subscriptions on the device with
1256          *                            the list of emergency numbers originating from that
1257          *                            subscription.
1258          *                            If there are no active subscriptions, the map will contain a
1259          *                            single entry with
1260          *                            {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} as
1261          *                            the key and a list of emergency numbers as the value. If no
1262          *                            emergency number information is available, the value will be
1263          *                            empty.
1264          */
1265         @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
onEmergencyNumberListChanged(@onNull Map<Integer, List<EmergencyNumber>> emergencyNumberList)1266         void onEmergencyNumberListChanged(@NonNull Map<Integer,
1267                 List<EmergencyNumber>> emergencyNumberList);
1268     }
1269 
1270     /**
1271      * Interface for outgoing emergency call listener.
1272      *
1273      * @hide
1274      */
1275     @SystemApi
1276     public interface OutgoingEmergencyCallListener {
1277         /**
1278          * Callback invoked when an outgoing call is placed to an emergency number.
1279          * <p>
1280          * This method will be called when an emergency call is placed on any subscription
1281          * (including the no-SIM case), regardless of which subscription this callback was
1282          * registered on.
1283          * <p>
1284          *
1285          * @param placedEmergencyNumber The {@link EmergencyNumber} the emergency call was
1286          *                              placed to.
1287          * @param subscriptionId        The subscription ID used to place the emergency call. If the
1288          *                              emergency call was placed without a valid subscription
1289          *                              (e.g. when there are no SIM cards in the device), this
1290          *                              will be
1291          *                              equal to
1292          *                              {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID}.
1293          */
1294         @RequiresPermission(Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION)
onOutgoingEmergencyCall(@onNull EmergencyNumber placedEmergencyNumber, int subscriptionId)1295         void onOutgoingEmergencyCall(@NonNull EmergencyNumber placedEmergencyNumber,
1296                 int subscriptionId);
1297     }
1298 
1299     /**
1300      * Interface for outgoing emergency sms listener.
1301      *
1302      * @hide
1303      */
1304     @SystemApi
1305     public interface OutgoingEmergencySmsListener {
1306         /**
1307          * Smsback invoked when an outgoing sms is sent to an emergency number.
1308          * <p>
1309          * This method will be called when an emergency sms is sent on any subscription,
1310          * regardless of which subscription this callback was registered on.
1311          *
1312          * @param sentEmergencyNumber The {@link EmergencyNumber} the emergency sms was sent to.
1313          * @param subscriptionId      The subscription ID used to send the emergency sms.
1314          */
1315         @RequiresPermission(Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION)
onOutgoingEmergencySms(@onNull EmergencyNumber sentEmergencyNumber, int subscriptionId)1316         void onOutgoingEmergencySms(@NonNull EmergencyNumber sentEmergencyNumber,
1317                 int subscriptionId);
1318     }
1319 
1320     /**
1321      * Interface for phone capability listener.
1322      *
1323      * @hide
1324      */
1325     @SystemApi
1326     public interface PhoneCapabilityListener {
1327         /**
1328          * Callback invoked when phone capability changes.
1329          * Note, this callback triggers regardless of registered subscription.
1330          *
1331          * @param capability the new phone capability
1332          */
onPhoneCapabilityChanged(@onNull PhoneCapability capability)1333         void onPhoneCapabilityChanged(@NonNull PhoneCapability capability);
1334     }
1335 
1336     /**
1337      * Interface for active data subscription ID listener.
1338      */
1339     public interface ActiveDataSubscriptionIdListener {
1340         /**
1341          * Callback invoked when active data subscription ID changes.
1342          * Note, this callback triggers regardless of registered subscription.
1343          *
1344          * @param subId current subscription used to setup Cellular Internet data. The data is
1345          *              only active on the subscription at a time, even it is multi-SIM mode.
1346          *              For example, it could be the current active opportunistic subscription
1347          *              in use, or the subscription user selected as default data subscription in
1348          *              DSDS mode.
1349          *
1350          * The calling app should have carrier privileges
1351          * (see {@link TelephonyManager#hasCarrierPrivileges}) if it does not have the
1352          * {@link android.Manifest.permission#READ_PHONE_STATE}.
1353          *
1354          */
1355         @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
onActiveDataSubscriptionIdChanged(int subId)1356         void onActiveDataSubscriptionIdChanged(int subId);
1357     }
1358 
1359     /**
1360      * Interface for modem radio power state listener.
1361      *
1362      * @hide
1363      */
1364     @SystemApi
1365     public interface RadioPowerStateListener {
1366         /**
1367          * Callback invoked when modem radio power state changes on the registered subscription.
1368          * Note, the registration subscription ID comes from {@link TelephonyManager} object
1369          * which registers TelephonyCallback by
1370          * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}.
1371          * If this TelephonyManager object was created with
1372          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
1373          * subscription ID. Otherwise, this callback applies to
1374          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
1375          *
1376          * @param state the modem radio power state
1377          */
1378         @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
onRadioPowerStateChanged(@nnotation.RadioPowerState int state)1379         void onRadioPowerStateChanged(@Annotation.RadioPowerState int state);
1380     }
1381 
1382     /**
1383      * Interface for carrier network listener.
1384      */
1385     public interface CarrierNetworkListener {
1386         /**
1387          * Callback invoked when telephony has received notice from a carrier
1388          * app that a network action that could result in connectivity loss
1389          * has been requested by an app using
1390          * {@link android.service.carrier.CarrierService#notifyCarrierNetworkChange(boolean)}
1391          * <p>
1392          * This is optional and is only used to allow the system to provide alternative UI while
1393          * telephony is performing an action that may result in intentional, temporary network
1394          * lack of connectivity.
1395          * <p>
1396          * Note, this callback is pinned to the registered subscription and will be invoked when
1397          * the notifying carrier app has carrier privilege rule on the registered
1398          * subscription. {@link android.telephony.TelephonyManager#hasCarrierPrivileges}
1399          *
1400          * @param active If the carrier network change is or shortly will be active,
1401          *               {@code true} indicate that showing alternative UI, {@code false} otherwise.
1402          */
onCarrierNetworkChange(boolean active)1403         void onCarrierNetworkChange(boolean active);
1404     }
1405 
1406     /**
1407      * Interface for registration failures listener.
1408      */
1409     public interface RegistrationFailedListener {
1410         /**
1411          * Report that Registration or a Location/Routing/Tracking Area update has failed.
1412          *
1413          * <p>Indicate whenever a registration procedure, including a location, routing, or tracking
1414          * area update fails. This includes procedures that do not necessarily result in a change of
1415          * the modem's registration status. If the modem's registration status changes, that is
1416          * reflected in the onNetworkStateChanged() and subsequent
1417          * get{Voice/Data}RegistrationState().
1418          *
1419          * <p>Because registration failures are ephemeral, this callback is not sticky.
1420          * Registrants will not receive the most recent past value when registering.
1421          *
1422          * The calling app should have carrier privileges
1423          * (see {@link TelephonyManager#hasCarrierPrivileges}) if it does not have the
1424          * {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE} and
1425          * {@link android.Manifest.permission#ACCESS_FINE_LOCATION}.
1426          *
1427          * If the calling app doesn't have {@link android.Manifest.permission#ACCESS_FINE_LOCATION},
1428          * it will receive {@link CellIdentity} without location-sensitive information included.
1429          *
1430          * @param cellIdentity        the CellIdentity, which must include the globally unique
1431          *                            identifier
1432          *                            for the cell (for example, all components of the CGI or ECGI).
1433          * @param chosenPlmn          a 5 or 6 digit alphanumeric PLMN (MCC|MNC) among those
1434          *                            broadcast by the
1435          *                            cell that was chosen for the failed registration attempt.
1436          * @param domain              DOMAIN_CS, DOMAIN_PS or both in case of a combined procedure.
1437          * @param causeCode           the primary failure cause code of the procedure.
1438          *                            For GSM/UMTS (MM), values are in TS 24.008 Sec 10.5.95
1439          *                            For GSM/UMTS (GMM), values are in TS 24.008 Sec 10.5.147
1440          *                            For LTE (EMM), cause codes are TS 24.301 Sec 9.9.3.9
1441          *                            For NR (5GMM), cause codes are TS 24.501 Sec 9.11.3.2
1442          *                            Integer.MAX_VALUE if this value is unused.
1443          * @param additionalCauseCode the cause code of any secondary/combined procedure
1444          *                            if appropriate. For UMTS, if a combined attach succeeds for
1445          *                            PS only, then the GMM cause code shall be included as an
1446          *                            additionalCauseCode. For LTE (ESM), cause codes are in
1447          *                            TS 24.301 9.9.4.4. Integer.MAX_VALUE if this value is unused.
1448          */
1449         @RequiresPermission(allOf = {
1450                 Manifest.permission.READ_PRECISE_PHONE_STATE,
1451                 Manifest.permission.ACCESS_FINE_LOCATION
1452         })
onRegistrationFailed(@onNull CellIdentity cellIdentity, @NonNull String chosenPlmn, @NetworkRegistrationInfo.Domain int domain, int causeCode, int additionalCauseCode)1453         void onRegistrationFailed(@NonNull CellIdentity cellIdentity, @NonNull String chosenPlmn,
1454                 @NetworkRegistrationInfo.Domain int domain, int causeCode, int additionalCauseCode);
1455     }
1456 
1457     /**
1458      * Interface for the current allowed network type list listener. This list involves values of
1459      * allowed network type for each of reasons.
1460      *
1461      * @hide
1462      */
1463     @SystemApi
1464     public interface AllowedNetworkTypesListener {
1465         /**
1466          * Callback invoked when the current allowed network type list has changed on the
1467          * registered subscription for a specified reason.
1468          * Note, the registered subscription is associated with {@link TelephonyManager} object
1469          * on which {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}
1470          * was called.
1471          * If this TelephonyManager object was created with
1472          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
1473          * given subscription ID. Otherwise, this callback applies to
1474          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
1475          *
1476          * @param reason an allowed network type reasons.
1477          * @see TelephonyManager#ALLOWED_NETWORK_TYPES_REASON_USER
1478          * @see TelephonyManager#ALLOWED_NETWORK_TYPES_REASON_POWER
1479          * @see TelephonyManager#ALLOWED_NETWORK_TYPES_REASON_CARRIER
1480          * @see TelephonyManager#ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
1481          *
1482          * @param allowedNetworkType an allowed network type bitmask value. (for example,
1483          * the long bitmask value is {{@link TelephonyManager#NETWORK_TYPE_BITMASK_NR}|
1484          * {@link TelephonyManager#NETWORK_TYPE_BITMASK_LTE}})
1485          *
1486          * For example:
1487          * If the latest allowed network type is changed by user, then the system
1488          * notifies the {@link TelephonyManager#ALLOWED_NETWORK_TYPES_REASON_USER} and
1489          * long type value}.
1490          */
1491         @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
onAllowedNetworkTypesChanged(@elephonyManager.AllowedNetworkTypesReason int reason, @TelephonyManager.NetworkTypeBitMask long allowedNetworkType)1492         void onAllowedNetworkTypesChanged(@TelephonyManager.AllowedNetworkTypesReason int reason,
1493                 @TelephonyManager.NetworkTypeBitMask long allowedNetworkType);
1494     }
1495 
1496     /**
1497      * Interface for listening to changes in the simultaneous cellular calling state for active
1498      * cellular subscriptions.
1499      *
1500      * @hide
1501      */
1502     @FlaggedApi(Flags.FLAG_SIMULTANEOUS_CALLING_INDICATIONS)
1503     @SystemApi
1504     public interface SimultaneousCellularCallingSupportListener {
1505         /**
1506          * Notify the Listener that the subscriptions available for simultaneous <b>cellular</b>
1507          * calling have changed.
1508          * <p>
1509          * If we have an ongoing <b>cellular</b> call on one subscription in this Set, a
1510          * simultaneous incoming or outgoing <b>cellular</b> call is possible on any of the
1511          * subscriptions in this Set. On a traditional Dual Sim Dual Standby device, simultaneous
1512          * calling is not possible between subscriptions, where on a Dual Sim Dual Active device,
1513          * simultaneous calling may be possible between subscriptions in certain network conditions.
1514          * <p>
1515          * Note: This listener only tracks the capability of the modem to perform simultaneous
1516          * cellular calls and does not track the simultaneous calling state of scenarios based on
1517          * multiple IMS registration over multiple transports (WiFi/Internet calling).
1518          * <p>
1519          * Note: This listener fires for all changes to cellular calling subscriptions independent
1520          * of which subscription it is registered on.
1521          *
1522          * @param simultaneousCallingSubscriptionIds The Set of subscription IDs that support
1523          * simultaneous calling. If there is an ongoing call on a subscription in this Set, then a
1524          * simultaneous incoming or outgoing call is only possible for other subscriptions in this
1525          * Set. If there is an ongoing call on a subscription that is not in this Set, then
1526          * simultaneous calling is not possible at the current time.
1527          *
1528          */
1529         @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
onSimultaneousCellularCallingSubscriptionsChanged( @onNull Set<Integer> simultaneousCallingSubscriptionIds)1530         void onSimultaneousCellularCallingSubscriptionsChanged(
1531                 @NonNull Set<Integer> simultaneousCallingSubscriptionIds);
1532     }
1533 
1534     /**
1535      * Interface for call attributes listener.
1536      *
1537      * @hide
1538      */
1539     @SystemApi
1540     public interface CallAttributesListener {
1541         /**
1542          * Callback invoked when the call attributes changes on the active call on the registered
1543          * subscription. If the user swaps between a foreground and background call the call
1544          * attributes will be reported for the active call only.
1545          * Note, the registration subscription ID comes from {@link TelephonyManager} object
1546          * which registers TelephonyCallback by
1547          * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}.
1548          * If this TelephonyManager object was created with
1549          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
1550          * subscription ID. Otherwise, this callback applies to
1551          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
1552          *
1553          * The calling app should have carrier privileges
1554          * (see {@link TelephonyManager#hasCarrierPrivileges}) if it does not have the
1555          * {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE}.
1556          *
1557          * @param callAttributes the call attributes
1558          * @deprecated Use onCallStatesChanged({@link List<CallState>}) to get each of call
1559          *          state for all ongoing calls on the subscription.
1560          */
1561         @RequiresPermission(Manifest.permission.READ_PRECISE_PHONE_STATE)
1562         @Deprecated
onCallAttributesChanged(@onNull CallAttributes callAttributes)1563         default void onCallAttributesChanged(@NonNull CallAttributes callAttributes) {
1564             Log.w(LOG_TAG, "onCallAttributesChanged(List<CallState>) should be "
1565                     + "overridden.");
1566         }
1567 
1568         /**
1569          * Callback invoked when the call attributes changes on the ongoing calls on the registered
1570          * subscription. If there are 1 foreground and 1 background call, Two {@link CallState}
1571          * will be passed.
1572          * Note, the registration subscription ID comes from {@link TelephonyManager} object
1573          * which registers TelephonyCallback by
1574          * {@link TelephonyManager#registerTelephonyCallback(Executor, TelephonyCallback)}.
1575          * If this TelephonyManager object was created with
1576          * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
1577          * subscription ID. Otherwise, this callback applies to
1578          * {@link SubscriptionManager#getDefaultSubscriptionId()}.
1579          * In the event that there are no active(state is not
1580          * {@link PreciseCallState#PRECISE_CALL_STATE_IDLE}) calls, this API will report empty list.
1581          *
1582          * The calling app should have carrier privileges
1583          * (see {@link TelephonyManager#hasCarrierPrivileges}) if it does not have the
1584          * {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE}.
1585          *
1586          * @param callStateList the list of call states for each ongoing call. If there are
1587          *                           a active call and a holding call, 1 call attributes for
1588          *                           {@link PreciseCallState#PRECISE_CALL_STATE_ACTIVE}  and another
1589          *                           for {@link PreciseCallState#PRECISE_CALL_STATE_HOLDING}
1590          *                           will be in this list.
1591          */
1592         // Added as default for backward compatibility
1593         @RequiresPermission(Manifest.permission.READ_PRECISE_PHONE_STATE)
onCallStatesChanged(@onNull List<CallState> callStateList)1594         default void onCallStatesChanged(@NonNull List<CallState> callStateList) {
1595             if (callStateList.size() > 0) {
1596                 int foregroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
1597                 int backgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
1598                 int ringingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE;
1599                 for (CallState cs : callStateList) {
1600                     switch (cs.getCallClassification()) {
1601                         case CallState.CALL_CLASSIFICATION_FOREGROUND:
1602                             foregroundCallState = cs.getCallState();
1603                             break;
1604                         case CallState.CALL_CLASSIFICATION_BACKGROUND:
1605                             backgroundCallState = cs.getCallState();
1606                             break;
1607                         case CallState.CALL_CLASSIFICATION_RINGING:
1608                             ringingCallState = cs.getCallState();
1609                             break;
1610                         default:
1611                             break;
1612                     }
1613                 }
1614                 onCallAttributesChanged(new CallAttributes(
1615                         new PreciseCallState(
1616                                 ringingCallState, foregroundCallState, backgroundCallState,
1617                                 DisconnectCause.NOT_VALID, PreciseDisconnectCause.NOT_VALID),
1618                         callStateList.get(0).getNetworkType(),
1619                         callStateList.get(0).getCallQuality()));
1620             } else {
1621                 onCallAttributesChanged(new CallAttributes(
1622                         new PreciseCallState(PreciseCallState.PRECISE_CALL_STATE_IDLE,
1623                                 PreciseCallState.PRECISE_CALL_STATE_IDLE,
1624                                 PreciseCallState.PRECISE_CALL_STATE_IDLE,
1625                                 DisconnectCause.NOT_VALID, PreciseDisconnectCause.NOT_VALID),
1626                         TelephonyManager.NETWORK_TYPE_UNKNOWN, new CallQuality()));
1627             }
1628         }
1629     }
1630 
1631     /**
1632      * Interface for barring information listener.
1633      */
1634     public interface BarringInfoListener {
1635         /**
1636          * Report updated barring information for the current camped/registered cell.
1637          *
1638          * <p>Barring info is provided for all services applicable to the current camped/registered
1639          * cell, for the registered PLMN and current access class/access category.
1640          *
1641          * The calling app should have carrier privileges
1642          * (see {@link TelephonyManager#hasCarrierPrivileges}) if it does not have the
1643          * {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE} and
1644          * {@link android.Manifest.permission#ACCESS_FINE_LOCATION}.
1645          *
1646          * If the calling app doesn't have {@link android.Manifest.permission#ACCESS_FINE_LOCATION},
1647          * it will receive {@link BarringInfo} including {@link CellIdentity} without
1648          * location-sensitive information included.
1649          *
1650          * @param barringInfo for all services on the current cell.
1651          * @see android.telephony.BarringInfo
1652          */
1653         @RequiresPermission(allOf = {
1654                 Manifest.permission.READ_PRECISE_PHONE_STATE,
1655                 Manifest.permission.ACCESS_FINE_LOCATION
1656         })
onBarringInfoChanged(@onNull BarringInfo barringInfo)1657         void onBarringInfoChanged(@NonNull BarringInfo barringInfo);
1658     }
1659 
1660     /**
1661      * Interface for current physical channel configuration listener.
1662      */
1663     public interface PhysicalChannelConfigListener {
1664         /**
1665          * Callback invoked when the current physical channel configuration has changed
1666          *
1667          * The calling app should have carrier privileges
1668          * (see {@link TelephonyManager#hasCarrierPrivileges}) if it does not have the
1669          * {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE}.
1670          *
1671          * @param configs List of the current {@link PhysicalChannelConfig}s
1672          */
1673         @RequiresPermission(Manifest.permission.READ_PRECISE_PHONE_STATE)
onPhysicalChannelConfigChanged(@onNull List<PhysicalChannelConfig> configs)1674         void onPhysicalChannelConfigChanged(@NonNull List<PhysicalChannelConfig> configs);
1675     }
1676 
1677     /**
1678      * Interface for data enabled listener.
1679      *
1680      * @hide
1681      */
1682     @SystemApi
1683     public interface DataEnabledListener {
1684         /**
1685          * Callback invoked when the data enabled changes.
1686          *
1687          * The calling app should have carrier privileges
1688          * (see {@link TelephonyManager#hasCarrierPrivileges}) if it does not have the
1689          * {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE}.
1690          *
1691          * @param enabled {@code true} if data is enabled, otherwise disabled.
1692          * @param reason  Reason for data enabled/disabled.
1693          *                See {@link TelephonyManager.DataEnabledChangedReason}.
1694          */
1695         @RequiresPermission(Manifest.permission.READ_PRECISE_PHONE_STATE)
onDataEnabledChanged(boolean enabled, @TelephonyManager.DataEnabledChangedReason int reason)1696         void onDataEnabledChanged(boolean enabled,
1697                 @TelephonyManager.DataEnabledChangedReason int reason);
1698     }
1699 
1700     /**
1701      * Interface for link capacity estimate changed listener.
1702      *
1703      * @hide
1704      */
1705     @SystemApi
1706     public interface LinkCapacityEstimateChangedListener {
1707         /**
1708          * Callback invoked when the link capacity estimate (LCE) changes
1709          *
1710          * @param linkCapacityEstimateList a list of {@link LinkCapacityEstimate}
1711          * The list size is at least 1.
1712          * In case of a dual connected network, the list size could be 2.
1713          * Use {@link LinkCapacityEstimate#getType()} to get the type of each element.
1714          */
1715         @RequiresPermission(Manifest.permission.READ_PRECISE_PHONE_STATE)
onLinkCapacityEstimateChanged( @onNull List<LinkCapacityEstimate> linkCapacityEstimateList)1716         void onLinkCapacityEstimateChanged(
1717                 @NonNull List<LinkCapacityEstimate> linkCapacityEstimateList);
1718     }
1719 
1720     /**
1721      * Interface for media quality status changed listener.
1722      *
1723      * @hide
1724      */
1725     @SystemApi
1726     public interface MediaQualityStatusChangedListener {
1727         /**
1728          * Callback invoked when the media quality status of IMS call changes. This call back
1729          * means current media quality status crosses at least one of threshold values in {@link
1730          * MediaThreshold}. Listener needs to get quality information & check whether it crossed
1731          * listener's threshold.
1732          *
1733          * <p/> Currently thresholds for this indication can be configurable by CARRIER_CONFIG
1734          * {@link CarrierConfigManager#KEY_VOICE_RTP_THRESHOLDS_PACKET_LOSS_RATE_INT}
1735          * {@link CarrierConfigManager#KEY_VOICE_RTP_THRESHOLDS_INACTIVITY_TIME_IN_MILLIS_INT}
1736          * {@link CarrierConfigManager#KEY_VOICE_RTP_THRESHOLDS_JITTER_INT}
1737          *
1738          * @param mediaQualityStatus The media quality status currently measured.
1739          */
1740         @RequiresPermission(Manifest.permission.READ_PRECISE_PHONE_STATE)
onMediaQualityStatusChanged(@onNull MediaQualityStatus mediaQualityStatus)1741         void onMediaQualityStatusChanged(@NonNull MediaQualityStatus mediaQualityStatus);
1742     }
1743 
1744     /**
1745      * Interface for the emergency callback mode listener.
1746      *
1747      * @hide
1748      */
1749     @FlaggedApi(Flags.FLAG_EMERGENCY_CALLBACK_MODE_NOTIFICATION)
1750     @SystemApi
1751     public interface EmergencyCallbackModeListener {
1752         /**
1753          * Indicates that emergency callback mode has been started.
1754          * <p>
1755          * This method will be called when an emergency SMS or emergency call is ended and
1756          * the emergency callback mode is supported by the carrier.
1757          * If the emergency callback mode was started for an emergency call and an emergency SMS is
1758          * transmitted during callback mode for SMS then this API will be called once again with
1759          * TelephonyManager#EMERGENCY_CALLBACK_MODE_SMS.
1760          *
1761          * @param type for the emergency callback mode entry
1762          *             See {@link TelephonyManager.EmergencyCallbackModeType}.
1763          * @see TelephonyManager#EMERGENCY_CALLBACK_MODE_CALL
1764          * @see TelephonyManager#EMERGENCY_CALLBACK_MODE_SMS
1765          *
1766          * @param timerDuration is the time remaining in the emergency callback mode.
1767          * @param subscriptionId The subscription ID used to start the emergency callback mode.
1768          */
onCallbackModeStarted(@elephonyManager.EmergencyCallbackModeType int type, @NonNull Duration timerDuration, int subscriptionId)1769         void onCallbackModeStarted(@TelephonyManager.EmergencyCallbackModeType int type,
1770                 @NonNull Duration timerDuration, int subscriptionId);
1771 
1772         /**
1773          * Indicates that emergency callback mode has been re-started.
1774          * <p>
1775          * This method will be called when an emergency SMS or emergency call is ended
1776          * in the emergency callback mode.
1777          * This is used to restart the emergency callback mode when it is already in progress.
1778          *
1779          * @param type for the emergency callback mode entry
1780          *             See {@link TelephonyManager.EmergencyCallbackModeType}.
1781          * @see TelephonyManager#EMERGENCY_CALLBACK_MODE_CALL
1782          * @see TelephonyManager#EMERGENCY_CALLBACK_MODE_SMS
1783          *
1784          * @param timerDuration is the time remaining in the emergency callback mode.
1785          * @param subscriptionId The subscription ID used to restart the emergency callback mode.
1786          */
onCallbackModeRestarted(@elephonyManager.EmergencyCallbackModeType int type, @NonNull Duration timerDuration, int subscriptionId)1787         void onCallbackModeRestarted(@TelephonyManager.EmergencyCallbackModeType int type,
1788                 @NonNull Duration timerDuration, int subscriptionId);
1789 
1790         /**
1791          * Indicates that emergency callback mode has been stopped.
1792          * <p>
1793          * This method will be called when the emergency callback mode timer expires or when
1794          * a normal call/SMS is sent
1795          *
1796          * @param type for the emergency callback mode entry
1797          * @see TelephonyManager#EMERGENCY_CALLBACK_MODE_CALL
1798          * @see TelephonyManager#EMERGENCY_CALLBACK_MODE_SMS
1799          *
1800          * @param reason for changing emergency callback mode
1801          * @see TelephonyManager#STOP_REASON_UNKNOWN
1802          * @see TelephonyManager#STOP_REASON_OUTGOING_NORMAL_CALL_INITIATED
1803          * @see TelephonyManager#STOP_REASON_NORMAL_SMS_SENT
1804          * @see TelephonyManager#STOP_REASON_OUTGOING_EMERGENCY_CALL_INITIATED
1805          * @see TelephonyManager#STOP_REASON_EMERGENCY_SMS_SENT
1806          * @see TelephonyManager#STOP_REASON_TIMER_EXPIRED
1807          * @see TelephonyManager#STOP_REASON_USER_ACTION
1808          *
1809          * @param subscriptionId is the current subscription used the emergency callback mode.
1810          */
onCallbackModeStopped(@elephonyManager.EmergencyCallbackModeType int type, @TelephonyManager.EmergencyCallbackModeStopReason int reason, int subscriptionId)1811         void onCallbackModeStopped(@TelephonyManager.EmergencyCallbackModeType int type,
1812                 @TelephonyManager.EmergencyCallbackModeStopReason int reason, int subscriptionId);
1813     }
1814 
1815     /**
1816      * Interface for carrier roaming non-terrestrial network listener.
1817      *
1818      * @hide
1819      */
1820     @SystemApi
1821     @FlaggedApi(Flags.FLAG_SATELLITE_SYSTEM_APIS)
1822     public interface CarrierRoamingNtnListener {
1823         /**
1824          * Callback invoked when carrier roaming non-terrestrial network mode changes.
1825          *
1826          * @param active {@code true} If the device is connected to carrier roaming
1827          *                           non-terrestrial network or was connected within the
1828          *                           {CarrierConfigManager
1829          *                           #KEY_SATELLITE_CONNECTION_HYSTERESIS_SEC_INT} duration,
1830          *                           {code false} otherwise.
1831          */
onCarrierRoamingNtnModeChanged(boolean active)1832         void onCarrierRoamingNtnModeChanged(boolean active);
1833 
1834         /**
1835          * Callback invoked when carrier roaming non-terrestrial network eligibility changes.
1836          *
1837          * @param eligible {@code true} when the device is eligible for satellite
1838          * communication if all the following conditions are met:
1839          * <ul>
1840          * <li>Any subscription on the device supports P2P satellite messaging which is defined by
1841          * {@link CarrierConfigManager#KEY_SATELLITE_ATTACH_SUPPORTED_BOOL} </li>
1842          * <li>{@link CarrierConfigManager#KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT} set to
1843          * {@link CarrierConfigManager#CARRIER_ROAMING_NTN_CONNECT_MANUAL} </li>
1844          * <li>The device is in {@link ServiceState#STATE_OUT_OF_SERVICE}, not connected to Wi-Fi,
1845          * and the hysteresis timer defined by {@link CarrierConfigManager
1846          * #KEY_CARRIER_SUPPORTED_SATELLITE_NOTIFICATION_HYSTERESIS_SEC_INT} is expired. </li>
1847          * </ul>
1848          */
onCarrierRoamingNtnEligibleStateChanged(boolean eligible)1849         default void onCarrierRoamingNtnEligibleStateChanged(boolean eligible) {}
1850 
1851         /**
1852          * Callback invoked when carrier roaming non-terrestrial network available
1853          * service changes.
1854          *
1855          * @param availableServices array of supported services.
1856          */
onCarrierRoamingNtnAvailableServicesChanged( @onNull @etworkRegistrationInfo.ServiceType int[] availableServices)1857         default void onCarrierRoamingNtnAvailableServicesChanged(
1858                 @NonNull @NetworkRegistrationInfo.ServiceType int[] availableServices) {}
1859 
1860         /**
1861          * Callback invoked when carrier roaming non-terrestrial network signal strength changes.
1862          *
1863          * @param ntnSignalStrength non-terrestrial network signal strength.
1864          */
onCarrierRoamingNtnSignalStrengthChanged( @onNull NtnSignalStrength ntnSignalStrength)1865         default void onCarrierRoamingNtnSignalStrengthChanged(
1866                 @NonNull NtnSignalStrength ntnSignalStrength) {}
1867     }
1868 
1869     /**
1870      * Interface for CellularIdentifierDisclosedListener
1871      * @hide
1872      */
1873     @SystemApi
1874     @FlaggedApi(Flags.FLAG_CELLULAR_IDENTIFIER_DISCLOSURE_INDICATIONS)
1875     public interface CellularIdentifierDisclosedListener {
1876         /**
1877          * Callback invoked when a device identifier (IMSI, IMEI, or unciphered SUCI)
1878          * is disclosed over the network before a security context is established
1879          * ("pre-authentication").
1880          *
1881          * @param disclosure details of the identifier disclosure
1882          * See {@link CellularIdentifierDisclosure} for more details
1883          */
onCellularIdentifierDisclosedChanged(@onNull CellularIdentifierDisclosure disclosure)1884         void onCellularIdentifierDisclosedChanged(@NonNull CellularIdentifierDisclosure disclosure);
1885     }
1886 
1887     /**
1888      * Interface for SecurityAlgorithmsListener
1889      * @hide
1890      */
1891     @SystemApi
1892     @FlaggedApi(Flags.FLAG_SECURITY_ALGORITHMS_UPDATE_INDICATIONS)
1893     public interface SecurityAlgorithmsListener {
1894         /**
1895          * Callback invoked when the most recently reported security algorithms has changed,
1896          * per a specified connection event.
1897          *
1898          * @param securityAlgorithmUpdate details of the security algorithm update
1899          * See {@link SecurityAlgorithmUpdate} for more details
1900          */
onSecurityAlgorithmsChanged(@onNull SecurityAlgorithmUpdate securityAlgorithmUpdate)1901         void onSecurityAlgorithmsChanged(@NonNull SecurityAlgorithmUpdate securityAlgorithmUpdate);
1902     }
1903 
1904     /**
1905      * The callback methods need to be called on the handler thread where
1906      * this object was created.  If the binder did that for us it'd be nice.
1907      * <p>
1908      * Using a static class and weak reference here to avoid memory leak caused by the
1909      * IPhoneState.Stub callback retaining references to the outside TelephonyCallback:
1910      * even caller has been destroyed and "un-registered" the TelephonyCallback, it is still not
1911      * eligible for GC given the references coming from:
1912      * Native Stack --> TelephonyCallback --> Context (Activity).
1913      * memory of caller's context will be collected after GC from service side get triggered
1914      */
1915     private static class IPhoneStateListenerStub extends IPhoneStateListener.Stub {
1916         private WeakReference<TelephonyCallback> mTelephonyCallbackWeakRef;
1917         private Executor mExecutor;
1918 
IPhoneStateListenerStub(TelephonyCallback telephonyCallback, Executor executor)1919         IPhoneStateListenerStub(TelephonyCallback telephonyCallback, Executor executor) {
1920             mTelephonyCallbackWeakRef = new WeakReference<TelephonyCallback>(telephonyCallback);
1921             mExecutor = executor;
1922         }
1923 
onServiceStateChanged(ServiceState serviceState)1924         public void onServiceStateChanged(ServiceState serviceState) {
1925             ServiceStateListener listener = (ServiceStateListener) mTelephonyCallbackWeakRef.get();
1926             if (listener == null) return;
1927 
1928             Binder.withCleanCallingIdentity(
1929                     () -> mExecutor.execute(() -> listener.onServiceStateChanged(serviceState)));
1930         }
1931 
onSignalStrengthChanged(int asu)1932         public void onSignalStrengthChanged(int asu) {
1933             // default implementation empty
1934         }
1935 
onMessageWaitingIndicatorChanged(boolean mwi)1936         public void onMessageWaitingIndicatorChanged(boolean mwi) {
1937             MessageWaitingIndicatorListener listener =
1938                     (MessageWaitingIndicatorListener) mTelephonyCallbackWeakRef.get();
1939             if (listener == null) return;
1940 
1941             Binder.withCleanCallingIdentity(
1942                     () -> mExecutor.execute(() -> listener.onMessageWaitingIndicatorChanged(mwi)));
1943         }
1944 
onCallForwardingIndicatorChanged(boolean cfi)1945         public void onCallForwardingIndicatorChanged(boolean cfi) {
1946             CallForwardingIndicatorListener listener =
1947                     (CallForwardingIndicatorListener) mTelephonyCallbackWeakRef.get();
1948             if (listener == null) return;
1949 
1950             Binder.withCleanCallingIdentity(
1951                     () -> mExecutor.execute(() -> listener.onCallForwardingIndicatorChanged(cfi)));
1952         }
1953 
onCellLocationChanged(CellIdentity cellIdentity)1954         public void onCellLocationChanged(CellIdentity cellIdentity) {
1955             // There is no system/public API to create an CellIdentity in system server,
1956             // so the server pass a null to indicate an empty initial location.
1957             CellLocation location =
1958                     cellIdentity == null ? CellLocation.getEmpty() : cellIdentity.asCellLocation();
1959             CellLocationListener listener = (CellLocationListener) mTelephonyCallbackWeakRef.get();
1960             if (listener == null) return;
1961 
1962             Binder.withCleanCallingIdentity(
1963                     () -> mExecutor.execute(() -> listener.onCellLocationChanged(location)));
1964         }
1965 
onLegacyCallStateChanged(int state, String incomingNumber)1966         public void onLegacyCallStateChanged(int state, String incomingNumber) {
1967             // Not used for TelephonyCallback; part of the AIDL which is used by both the legacy
1968             // PhoneStateListener and TelephonyCallback.
1969         }
1970 
onCallStateChanged(int state)1971         public void onCallStateChanged(int state) {
1972             CallStateListener listener = (CallStateListener) mTelephonyCallbackWeakRef.get();
1973             if (listener == null) return;
1974 
1975             Binder.withCleanCallingIdentity(
1976                     () -> mExecutor.execute(() -> listener.onCallStateChanged(state)));
1977         }
1978 
onDataConnectionStateChanged(int state, int networkType)1979         public void onDataConnectionStateChanged(int state, int networkType) {
1980             DataConnectionStateListener listener =
1981                     (DataConnectionStateListener) mTelephonyCallbackWeakRef.get();
1982             if (listener == null) return;
1983 
1984             if (state == TelephonyManager.DATA_DISCONNECTING
1985                     && VMRuntime.getRuntime().getTargetSdkVersion() < Build.VERSION_CODES.R) {
1986                 Binder.withCleanCallingIdentity(
1987                         () -> mExecutor.execute(() ->
1988                                 listener.onDataConnectionStateChanged(
1989                                         TelephonyManager.DATA_CONNECTED, networkType)));
1990             } else {
1991                 Binder.withCleanCallingIdentity(
1992                         () -> mExecutor.execute(() ->
1993                                 listener.onDataConnectionStateChanged(state, networkType)));
1994             }
1995         }
1996 
onDataActivity(int direction)1997         public void onDataActivity(int direction) {
1998             DataActivityListener listener = (DataActivityListener) mTelephonyCallbackWeakRef.get();
1999             if (listener == null) return;
2000 
2001             Binder.withCleanCallingIdentity(
2002                     () -> mExecutor.execute(() -> listener.onDataActivity(direction)));
2003         }
2004 
onSignalStrengthsChanged(SignalStrength signalStrength)2005         public void onSignalStrengthsChanged(SignalStrength signalStrength) {
2006             SignalStrengthsListener listener =
2007                     (SignalStrengthsListener) mTelephonyCallbackWeakRef.get();
2008             if (listener == null) return;
2009 
2010             Binder.withCleanCallingIdentity(
2011                     () -> mExecutor.execute(() -> listener.onSignalStrengthsChanged(
2012                             signalStrength)));
2013         }
2014 
onCellInfoChanged(List<CellInfo> cellInfo)2015         public void onCellInfoChanged(List<CellInfo> cellInfo) {
2016             CellInfoListener listener = (CellInfoListener) mTelephonyCallbackWeakRef.get();
2017             if (listener == null) return;
2018 
2019             Binder.withCleanCallingIdentity(
2020                     () -> mExecutor.execute(() -> listener.onCellInfoChanged(cellInfo)));
2021         }
2022 
onPreciseCallStateChanged(PreciseCallState callState)2023         public void onPreciseCallStateChanged(PreciseCallState callState) {
2024             PreciseCallStateListener listener =
2025                     (PreciseCallStateListener) mTelephonyCallbackWeakRef.get();
2026             if (listener == null) return;
2027 
2028             Binder.withCleanCallingIdentity(
2029                     () -> mExecutor.execute(() -> listener.onPreciseCallStateChanged(callState)));
2030         }
2031 
onCallDisconnectCauseChanged(int disconnectCause, int preciseDisconnectCause)2032         public void onCallDisconnectCauseChanged(int disconnectCause, int preciseDisconnectCause) {
2033             CallDisconnectCauseListener listener =
2034                     (CallDisconnectCauseListener) mTelephonyCallbackWeakRef.get();
2035             if (listener == null) return;
2036 
2037             Binder.withCleanCallingIdentity(
2038                     () -> mExecutor.execute(() -> listener.onCallDisconnectCauseChanged(
2039                             disconnectCause, preciseDisconnectCause)));
2040         }
2041 
onPreciseDataConnectionStateChanged( PreciseDataConnectionState dataConnectionState)2042         public void onPreciseDataConnectionStateChanged(
2043                 PreciseDataConnectionState dataConnectionState) {
2044             PreciseDataConnectionStateListener listener =
2045                     (PreciseDataConnectionStateListener) mTelephonyCallbackWeakRef.get();
2046             if (listener == null) return;
2047 
2048             Binder.withCleanCallingIdentity(
2049                     () -> mExecutor.execute(
2050                             () -> listener.onPreciseDataConnectionStateChanged(
2051                                     dataConnectionState)));
2052         }
2053 
onDataConnectionRealTimeInfoChanged(DataConnectionRealTimeInfo dcRtInfo)2054         public void onDataConnectionRealTimeInfoChanged(DataConnectionRealTimeInfo dcRtInfo) {
2055             // default implementation empty
2056         }
2057 
onSrvccStateChanged(int state)2058         public void onSrvccStateChanged(int state) {
2059             SrvccStateListener listener = (SrvccStateListener) mTelephonyCallbackWeakRef.get();
2060             if (listener == null) return;
2061 
2062             Binder.withCleanCallingIdentity(
2063                     () -> mExecutor.execute(() -> listener.onSrvccStateChanged(state)));
2064         }
2065 
onVoiceActivationStateChanged(int activationState)2066         public void onVoiceActivationStateChanged(int activationState) {
2067             VoiceActivationStateListener listener =
2068                     (VoiceActivationStateListener) mTelephonyCallbackWeakRef.get();
2069             if (listener == null) return;
2070 
2071             Binder.withCleanCallingIdentity(
2072                     () -> mExecutor.execute(
2073                             () -> listener.onVoiceActivationStateChanged(activationState)));
2074         }
2075 
onDataActivationStateChanged(int activationState)2076         public void onDataActivationStateChanged(int activationState) {
2077             DataActivationStateListener listener =
2078                     (DataActivationStateListener) mTelephonyCallbackWeakRef.get();
2079             if (listener == null) return;
2080 
2081             Binder.withCleanCallingIdentity(
2082                     () -> mExecutor.execute(
2083                             () -> listener.onDataActivationStateChanged(activationState)));
2084         }
2085 
onUserMobileDataStateChanged(boolean enabled)2086         public void onUserMobileDataStateChanged(boolean enabled) {
2087             UserMobileDataStateListener listener =
2088                     (UserMobileDataStateListener) mTelephonyCallbackWeakRef.get();
2089             if (listener == null) return;
2090 
2091             Binder.withCleanCallingIdentity(
2092                     () -> mExecutor.execute(
2093                             () -> listener.onUserMobileDataStateChanged(enabled)));
2094         }
2095 
onDisplayInfoChanged(TelephonyDisplayInfo telephonyDisplayInfo)2096         public void onDisplayInfoChanged(TelephonyDisplayInfo telephonyDisplayInfo) {
2097             DisplayInfoListener listener = (DisplayInfoListener)mTelephonyCallbackWeakRef.get();
2098             if (listener == null) return;
2099 
2100             Binder.withCleanCallingIdentity(
2101                     () -> mExecutor.execute(
2102                             () -> listener.onDisplayInfoChanged(telephonyDisplayInfo)));
2103         }
2104 
onOemHookRawEvent(byte[] rawData)2105         public void onOemHookRawEvent(byte[] rawData) {
2106             // default implementation empty
2107         }
2108 
onCarrierNetworkChange(boolean active)2109         public void onCarrierNetworkChange(boolean active) {
2110             CarrierNetworkListener listener =
2111                     (CarrierNetworkListener) mTelephonyCallbackWeakRef.get();
2112             if (listener == null) return;
2113 
2114             Binder.withCleanCallingIdentity(
2115                     () -> mExecutor.execute(() -> listener.onCarrierNetworkChange(active)));
2116         }
2117 
onEmergencyNumberListChanged(Map emergencyNumberList)2118         public void onEmergencyNumberListChanged(Map emergencyNumberList) {
2119             EmergencyNumberListListener listener =
2120                     (EmergencyNumberListListener) mTelephonyCallbackWeakRef.get();
2121             if (listener == null) return;
2122 
2123             Binder.withCleanCallingIdentity(
2124                     () -> mExecutor.execute(
2125                             () -> listener.onEmergencyNumberListChanged(emergencyNumberList)));
2126         }
2127 
onOutgoingEmergencyCall(@onNull EmergencyNumber placedEmergencyNumber, int subscriptionId)2128         public void onOutgoingEmergencyCall(@NonNull EmergencyNumber placedEmergencyNumber,
2129             int subscriptionId) {
2130             OutgoingEmergencyCallListener listener =
2131                     (OutgoingEmergencyCallListener) mTelephonyCallbackWeakRef.get();
2132             if (listener == null) return;
2133 
2134             Binder.withCleanCallingIdentity(
2135                     () -> mExecutor.execute(
2136                             () -> listener.onOutgoingEmergencyCall(placedEmergencyNumber,
2137                                     subscriptionId)));
2138         }
2139 
onOutgoingEmergencySms(@onNull EmergencyNumber sentEmergencyNumber, int subscriptionId)2140         public void onOutgoingEmergencySms(@NonNull EmergencyNumber sentEmergencyNumber,
2141             int subscriptionId) {
2142             OutgoingEmergencySmsListener listener =
2143                     (OutgoingEmergencySmsListener) mTelephonyCallbackWeakRef.get();
2144             if (listener == null) return;
2145 
2146             Binder.withCleanCallingIdentity(
2147                     () -> mExecutor.execute(
2148                             () -> listener.onOutgoingEmergencySms(sentEmergencyNumber,
2149                                     subscriptionId)));
2150         }
2151 
onPhoneCapabilityChanged(PhoneCapability capability)2152         public void onPhoneCapabilityChanged(PhoneCapability capability) {
2153             PhoneCapabilityListener listener =
2154                     (PhoneCapabilityListener) mTelephonyCallbackWeakRef.get();
2155             if (listener == null) return;
2156 
2157             Binder.withCleanCallingIdentity(
2158                     () -> mExecutor.execute(() -> listener.onPhoneCapabilityChanged(capability)));
2159         }
2160 
onRadioPowerStateChanged(@nnotation.RadioPowerState int state)2161         public void onRadioPowerStateChanged(@Annotation.RadioPowerState int state) {
2162             RadioPowerStateListener listener =
2163                     (RadioPowerStateListener) mTelephonyCallbackWeakRef.get();
2164             if (listener == null) return;
2165 
2166             Binder.withCleanCallingIdentity(
2167                     () -> mExecutor.execute(() -> listener.onRadioPowerStateChanged(state)));
2168         }
2169 
onCallStatesChanged(List<CallState> callStateList)2170         public void onCallStatesChanged(List<CallState> callStateList) {
2171             CallAttributesListener listener =
2172                     (CallAttributesListener) mTelephonyCallbackWeakRef.get();
2173             if (listener == null) return;
2174 
2175             Binder.withCleanCallingIdentity(
2176                     () -> mExecutor.execute(() -> listener.onCallStatesChanged(callStateList)));
2177         }
2178 
onActiveDataSubIdChanged(int subId)2179         public void onActiveDataSubIdChanged(int subId) {
2180             ActiveDataSubscriptionIdListener listener =
2181                     (ActiveDataSubscriptionIdListener) mTelephonyCallbackWeakRef.get();
2182             if (listener == null) return;
2183 
2184             Binder.withCleanCallingIdentity(
2185                     () -> mExecutor.execute(() -> listener.onActiveDataSubscriptionIdChanged(
2186                             subId)));
2187         }
2188 
onImsCallDisconnectCauseChanged(ImsReasonInfo disconnectCause)2189         public void onImsCallDisconnectCauseChanged(ImsReasonInfo disconnectCause) {
2190             ImsCallDisconnectCauseListener listener =
2191                     (ImsCallDisconnectCauseListener) mTelephonyCallbackWeakRef.get();
2192             if (listener == null) return;
2193 
2194             Binder.withCleanCallingIdentity(
2195                     () -> mExecutor.execute(
2196                             () -> listener.onImsCallDisconnectCauseChanged(disconnectCause)));
2197         }
2198 
onRegistrationFailed(@onNull CellIdentity cellIdentity, @NonNull String chosenPlmn, int domain, int causeCode, int additionalCauseCode)2199         public void onRegistrationFailed(@NonNull CellIdentity cellIdentity,
2200             @NonNull String chosenPlmn, int domain, int causeCode, int additionalCauseCode) {
2201             RegistrationFailedListener listener =
2202                     (RegistrationFailedListener) mTelephonyCallbackWeakRef.get();
2203             if (listener == null) return;
2204 
2205             Binder.withCleanCallingIdentity(
2206                     () -> mExecutor.execute(() -> listener.onRegistrationFailed(
2207                             cellIdentity, chosenPlmn, domain, causeCode, additionalCauseCode)));
2208             // default implementation empty
2209         }
2210 
onBarringInfoChanged(BarringInfo barringInfo)2211         public void onBarringInfoChanged(BarringInfo barringInfo) {
2212             BarringInfoListener listener = (BarringInfoListener) mTelephonyCallbackWeakRef.get();
2213             if (listener == null) return;
2214 
2215             Binder.withCleanCallingIdentity(
2216                     () -> mExecutor.execute(() -> listener.onBarringInfoChanged(barringInfo)));
2217         }
2218 
onPhysicalChannelConfigChanged(List<PhysicalChannelConfig> configs)2219         public void onPhysicalChannelConfigChanged(List<PhysicalChannelConfig> configs) {
2220             PhysicalChannelConfigListener listener =
2221                     (PhysicalChannelConfigListener) mTelephonyCallbackWeakRef.get();
2222             if (listener == null) return;
2223 
2224             Binder.withCleanCallingIdentity(
2225                     () -> mExecutor.execute(() -> listener.onPhysicalChannelConfigChanged(
2226                             configs)));
2227         }
2228 
onDataEnabledChanged(boolean enabled, @TelephonyManager.DataEnabledReason int reason)2229         public void onDataEnabledChanged(boolean enabled,
2230             @TelephonyManager.DataEnabledReason int reason) {
2231             DataEnabledListener listener =
2232                     (DataEnabledListener) mTelephonyCallbackWeakRef.get();
2233             if (listener == null) return;
2234 
2235             Binder.withCleanCallingIdentity(
2236                     () -> mExecutor.execute(() -> listener.onDataEnabledChanged(
2237                             enabled, reason)));
2238         }
2239 
onAllowedNetworkTypesChanged(int reason, long allowedNetworkType)2240         public void onAllowedNetworkTypesChanged(int reason, long allowedNetworkType) {
2241             AllowedNetworkTypesListener listener =
2242                     (AllowedNetworkTypesListener) mTelephonyCallbackWeakRef.get();
2243             if (listener == null) return;
2244 
2245             Binder.withCleanCallingIdentity(
2246                     () -> mExecutor.execute(
2247                             () -> listener.onAllowedNetworkTypesChanged(reason,
2248                                     allowedNetworkType)));
2249         }
2250 
onSimultaneousCallingStateChanged(int[] subIds)2251         public void onSimultaneousCallingStateChanged(int[] subIds) {
2252             SimultaneousCellularCallingSupportListener listener =
2253                     (SimultaneousCellularCallingSupportListener) mTelephonyCallbackWeakRef.get();
2254             if (listener == null) return;
2255 
2256             Binder.withCleanCallingIdentity(
2257                     () -> mExecutor.execute(
2258                             () -> listener.onSimultaneousCellularCallingSubscriptionsChanged(
2259                                     Arrays.stream(subIds).boxed().collect(Collectors.toSet()))));
2260         }
2261 
onLinkCapacityEstimateChanged( List<LinkCapacityEstimate> linkCapacityEstimateList)2262         public void onLinkCapacityEstimateChanged(
2263                 List<LinkCapacityEstimate> linkCapacityEstimateList) {
2264             LinkCapacityEstimateChangedListener listener =
2265                     (LinkCapacityEstimateChangedListener) mTelephonyCallbackWeakRef.get();
2266             if (listener == null) return;
2267 
2268             Binder.withCleanCallingIdentity(
2269                     () -> mExecutor.execute(() -> listener.onLinkCapacityEstimateChanged(
2270                             linkCapacityEstimateList)));
2271         }
2272 
onMediaQualityStatusChanged( MediaQualityStatus mediaQualityStatus)2273         public void onMediaQualityStatusChanged(
2274                 MediaQualityStatus mediaQualityStatus) {
2275             MediaQualityStatusChangedListener listener =
2276                     (MediaQualityStatusChangedListener) mTelephonyCallbackWeakRef.get();
2277             if (listener == null) return;
2278 
2279             Binder.withCleanCallingIdentity(
2280                     () -> mExecutor.execute(() -> listener.onMediaQualityStatusChanged(
2281                             mediaQualityStatus)));
2282         }
2283 
2284         @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
onCallbackModeStarted(@elephonyManager.EmergencyCallbackModeType int type, long durationMillis, int subscriptionId)2285         public void onCallbackModeStarted(@TelephonyManager.EmergencyCallbackModeType int type,
2286                 long durationMillis, int subscriptionId) {
2287             if (!Flags.emergencyCallbackModeNotification()) return;
2288 
2289             EmergencyCallbackModeListener listener =
2290                     (EmergencyCallbackModeListener) mTelephonyCallbackWeakRef.get();
2291             Log.d(LOG_TAG, "onCallBackModeStarted:type=" + type + ", listener=" + listener);
2292             if (listener == null) return;
2293 
2294             final Duration timerDuration = Duration.ofMillis(durationMillis);
2295             Binder.withCleanCallingIdentity(
2296                     () -> mExecutor.execute(() -> listener.onCallbackModeStarted(type,
2297                             timerDuration, subscriptionId)));
2298         }
2299 
2300         @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
onCallbackModeRestarted(@elephonyManager.EmergencyCallbackModeType int type, long durationMillis, int subscriptionId)2301         public void onCallbackModeRestarted(@TelephonyManager.EmergencyCallbackModeType int type,
2302                 long durationMillis, int subscriptionId) {
2303             if (!Flags.emergencyCallbackModeNotification()) return;
2304 
2305             EmergencyCallbackModeListener listener =
2306                     (EmergencyCallbackModeListener) mTelephonyCallbackWeakRef.get();
2307             Log.d(LOG_TAG, "onCallbackModeRestarted:type=" + type + ", listener=" + listener);
2308             if (listener == null) return;
2309 
2310             final Duration timerDuration = Duration.ofMillis(durationMillis);
2311             Binder.withCleanCallingIdentity(
2312                     () -> mExecutor.execute(() -> listener.onCallbackModeRestarted(type,
2313                             timerDuration, subscriptionId)));
2314         }
2315 
2316         @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
onCallbackModeStopped(@elephonyManager.EmergencyCallbackModeType int type, @TelephonyManager.EmergencyCallbackModeStopReason int reason, int subscriptionId)2317         public void onCallbackModeStopped(@TelephonyManager.EmergencyCallbackModeType int type,
2318                 @TelephonyManager.EmergencyCallbackModeStopReason int reason, int subscriptionId) {
2319             if (!Flags.emergencyCallbackModeNotification()) return;
2320 
2321             EmergencyCallbackModeListener listener =
2322                     (EmergencyCallbackModeListener) mTelephonyCallbackWeakRef.get();
2323             Log.d(LOG_TAG, "onCallBackModeStopped:type=" + type
2324                     + ", reason=" + reason + ", listener=" + listener);
2325             if (listener == null) return;
2326 
2327             Binder.withCleanCallingIdentity(
2328                     () -> mExecutor.execute(() -> listener.onCallbackModeStopped(type, reason,
2329                             subscriptionId)));
2330         }
2331 
onCarrierRoamingNtnModeChanged(boolean active)2332         public void onCarrierRoamingNtnModeChanged(boolean active) {
2333             CarrierRoamingNtnListener listener =
2334                     (CarrierRoamingNtnListener) mTelephonyCallbackWeakRef.get();
2335             if (listener == null) return;
2336 
2337             Binder.withCleanCallingIdentity(
2338                     () -> mExecutor.execute(() -> listener.onCarrierRoamingNtnModeChanged(active)));
2339         }
2340 
onCarrierRoamingNtnEligibleStateChanged(boolean eligible)2341         public void onCarrierRoamingNtnEligibleStateChanged(boolean eligible) {
2342             if (!Flags.carrierRoamingNbIotNtn()) return;
2343 
2344             CarrierRoamingNtnListener listener =
2345                     (CarrierRoamingNtnListener) mTelephonyCallbackWeakRef.get();
2346             if (listener == null) return;
2347 
2348             Binder.withCleanCallingIdentity(() -> mExecutor.execute(
2349                     () -> listener.onCarrierRoamingNtnEligibleStateChanged(eligible)));
2350         }
2351 
onCarrierRoamingNtnAvailableServicesChanged( @etworkRegistrationInfo.ServiceType int[] availableServices)2352         public void onCarrierRoamingNtnAvailableServicesChanged(
2353                 @NetworkRegistrationInfo.ServiceType int[] availableServices) {
2354             if (!Flags.carrierRoamingNbIotNtn()) return;
2355 
2356             CarrierRoamingNtnListener listener =
2357                     (CarrierRoamingNtnListener) mTelephonyCallbackWeakRef.get();
2358             if (listener == null) return;
2359 
2360             Binder.withCleanCallingIdentity(() -> mExecutor.execute(
2361                     () -> listener.onCarrierRoamingNtnAvailableServicesChanged(availableServices)));
2362         }
2363 
onCarrierRoamingNtnSignalStrengthChanged( @onNull NtnSignalStrength ntnSignalStrength)2364         public void onCarrierRoamingNtnSignalStrengthChanged(
2365                 @NonNull NtnSignalStrength ntnSignalStrength) {
2366             if (!Flags.carrierRoamingNbIotNtn()) return;
2367 
2368             CarrierRoamingNtnListener listener =
2369                     (CarrierRoamingNtnListener) mTelephonyCallbackWeakRef.get();
2370             if (listener == null) return;
2371 
2372             Binder.withCleanCallingIdentity(() -> mExecutor.execute(
2373                     () -> listener.onCarrierRoamingNtnSignalStrengthChanged(ntnSignalStrength)));
2374 
2375         }
2376 
onSecurityAlgorithmsChanged(SecurityAlgorithmUpdate update)2377         public void onSecurityAlgorithmsChanged(SecurityAlgorithmUpdate update) {
2378             if (!Flags.securityAlgorithmsUpdateIndications()) return;
2379 
2380             SecurityAlgorithmsListener listener =
2381                     (SecurityAlgorithmsListener) mTelephonyCallbackWeakRef.get();
2382             if (listener == null) return;
2383 
2384             Binder.withCleanCallingIdentity(() -> mExecutor.execute(
2385                     () -> listener.onSecurityAlgorithmsChanged(update)));
2386         }
2387 
onCellularIdentifierDisclosedChanged(CellularIdentifierDisclosure disclosure)2388         public void onCellularIdentifierDisclosedChanged(CellularIdentifierDisclosure disclosure) {
2389             if (!Flags.cellularIdentifierDisclosureIndications()) return;
2390 
2391             CellularIdentifierDisclosedListener listener =
2392                     (CellularIdentifierDisclosedListener) mTelephonyCallbackWeakRef.get();
2393             if (listener == null) return;
2394 
2395             Binder.withCleanCallingIdentity(() -> mExecutor.execute(
2396                     () -> listener.onCellularIdentifierDisclosedChanged(disclosure)));
2397         }
2398     }
2399 }
2400