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