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