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