• 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.annotation.UnsupportedAppUsage;
24 import android.os.Binder;
25 import android.os.Build;
26 import android.os.Bundle;
27 import android.os.Handler;
28 import android.os.HandlerExecutor;
29 import android.os.Looper;
30 import android.telephony.emergency.EmergencyNumber;
31 import android.telephony.ims.ImsReasonInfo;
32 
33 import com.android.internal.annotations.VisibleForTesting;
34 import com.android.internal.telephony.IPhoneStateListener;
35 
36 import java.lang.ref.WeakReference;
37 import java.util.List;
38 import java.util.Map;
39 import java.util.concurrent.Executor;
40 
41 import dalvik.system.VMRuntime;
42 
43 /**
44  * A listener 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  * Override the methods for the state that you wish to receive updates for, and
49  * pass your PhoneStateListener object, along with bitwise-or of the LISTEN_
50  * flags to {@link TelephonyManager#listen TelephonyManager.listen()}. Methods are
51  * called when the state changes, as well as once on initial registration.
52  * <p>
53  * Note that access to some telephony information is
54  * permission-protected. Your application won't receive updates for protected
55  * information unless it has the appropriate permissions declared in
56  * its manifest file. Where permissions apply, they are noted in the
57  * appropriate LISTEN_ flags.
58  */
59 public class PhoneStateListener {
60     private static final String LOG_TAG = "PhoneStateListener";
61     private static final boolean DBG = false; // STOPSHIP if true
62 
63     /**
64      * Stop listening for updates.
65      *
66      * The PhoneStateListener is not tied to any subscription and unregistered for any update.
67      */
68     public static final int LISTEN_NONE = 0;
69 
70     /**
71      *  Listen for changes to the network service state (cellular).
72      *
73      *  @see #onServiceStateChanged
74      *  @see ServiceState
75      */
76     public static final int LISTEN_SERVICE_STATE                            = 0x00000001;
77 
78     /**
79      * Listen for changes to the network signal strength (cellular).
80      * {@more}
81      *
82      * @see #onSignalStrengthChanged
83      *
84      * @deprecated by {@link #LISTEN_SIGNAL_STRENGTHS}
85      */
86     @Deprecated
87     public static final int LISTEN_SIGNAL_STRENGTH                          = 0x00000002;
88 
89     /**
90      * Listen for changes to the message-waiting indicator.
91      * {@more}
92      * Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE
93      * READ_PHONE_STATE} or that the calling app has carrier privileges (see
94      * {@link TelephonyManager#hasCarrierPrivileges}).
95      * <p>
96      * Example: The status bar uses this to determine when to display the
97      * voicemail icon.
98      *
99      * @see #onMessageWaitingIndicatorChanged
100      */
101     public static final int LISTEN_MESSAGE_WAITING_INDICATOR                = 0x00000004;
102 
103     /**
104      * Listen for changes to the call-forwarding indicator.
105      * {@more}
106      * Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE
107      * READ_PHONE_STATE} or that the calling app has carrier privileges (see
108      * {@link TelephonyManager#hasCarrierPrivileges}).
109      *
110      * @see #onCallForwardingIndicatorChanged
111      */
112     public static final int LISTEN_CALL_FORWARDING_INDICATOR                = 0x00000008;
113 
114     /**
115      * Listen for changes to the device's cell location. Note that
116      * this will result in frequent callbacks to the listener.
117      * {@more}
118      * Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION
119      * ACCESS_COARSE_LOCATION}
120      * <p>
121      * If you need regular location updates but want more control over
122      * the update interval or location precision, you can set up a listener
123      * through the {@link android.location.LocationManager location manager}
124      * instead.
125      *
126      * @see #onCellLocationChanged
127      */
128     public static final int LISTEN_CELL_LOCATION                            = 0x00000010;
129 
130     /**
131      * Listen for changes to the device call state.
132      * {@more}
133      *
134      * @see #onCallStateChanged
135      */
136     public static final int LISTEN_CALL_STATE                               = 0x00000020;
137 
138     /**
139      * Listen for changes to the data connection state (cellular).
140      *
141      * @see #onDataConnectionStateChanged
142      */
143     public static final int LISTEN_DATA_CONNECTION_STATE                    = 0x00000040;
144 
145     /**
146      * Listen for changes to the direction of data traffic on the data
147      * connection (cellular).
148      * {@more}
149      * Example: The status bar uses this to display the appropriate
150      * data-traffic icon.
151      *
152      * @see #onDataActivity
153      */
154     public static final int LISTEN_DATA_ACTIVITY                            = 0x00000080;
155 
156     /**
157      * Listen for changes to the network signal strengths (cellular).
158      * <p>
159      * Example: The status bar uses this to control the signal-strength
160      * icon.
161      *
162      * @see #onSignalStrengthsChanged
163      */
164     public static final int LISTEN_SIGNAL_STRENGTHS                         = 0x00000100;
165 
166     /**
167      * Listen for changes to OTASP mode.
168      *
169      * @see #onOtaspChanged
170      * @hide
171      */
172     public static final int LISTEN_OTASP_CHANGED                            = 0x00000200;
173 
174     /**
175      * Listen for changes to observed cell info.
176      *
177      * @see #onCellInfoChanged
178      */
179     public static final int LISTEN_CELL_INFO = 0x00000400;
180 
181     /**
182      * Listen for {@link PreciseCallState.State} of ringing, background and foreground calls.
183      *
184      * @hide
185      */
186     @RequiresPermission((android.Manifest.permission.READ_PRECISE_PHONE_STATE))
187     @SystemApi
188     public static final int LISTEN_PRECISE_CALL_STATE                       = 0x00000800;
189 
190     /**
191      * Listen for {@link PreciseDataConnectionState} on the data connection (cellular).
192      *
193      * @see #onPreciseDataConnectionStateChanged
194      *
195      * @hide
196      */
197     @RequiresPermission((android.Manifest.permission.READ_PRECISE_PHONE_STATE))
198     @SystemApi
199     public static final int LISTEN_PRECISE_DATA_CONNECTION_STATE            = 0x00001000;
200 
201     /**
202      * Listen for real time info for all data connections (cellular)).
203      * {@more}
204      * Requires Permission: {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE
205      * READ_PRECISE_PHONE_STATE}
206      * @see #onDataConnectionRealTimeInfoChanged(DataConnectionRealTimeInfo)
207      *
208      * @deprecated Use {@link TelephonyManager#getModemActivityInfo()}
209      * @hide
210      */
211     @Deprecated
212     public static final int LISTEN_DATA_CONNECTION_REAL_TIME_INFO           = 0x00002000;
213 
214     /**
215      * Listen for changes to the SRVCC state of the active call.
216      * @see #onServiceStateChanged(ServiceState)
217      * @hide
218      */
219     @SystemApi
220     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
221     public static final int LISTEN_SRVCC_STATE_CHANGED                     = 0x00004000;
222 
223     /**
224      * Listen for OEM hook raw event
225      *
226      * @see #onOemHookRawEvent
227      * @hide
228      * @deprecated OEM needs a vendor-extension hal and their apps should use that instead
229      */
230     @Deprecated
231     public static final int LISTEN_OEM_HOOK_RAW_EVENT                       = 0x00008000;
232 
233     /**
234      * Listen for carrier network changes indicated by a carrier app.
235      *
236      * @see #onCarrierNetworkRequest
237      * @see TelephonyManager#notifyCarrierNetworkChange(boolean)
238      * @hide
239      */
240     public static final int LISTEN_CARRIER_NETWORK_CHANGE                   = 0x00010000;
241 
242     /**
243      * Listen for changes to the sim voice activation state
244      * @see TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATING
245      * @see TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATED
246      * @see TelephonyManager#SIM_ACTIVATION_STATE_DEACTIVATED
247      * @see TelephonyManager#SIM_ACTIVATION_STATE_RESTRICTED
248      * @see TelephonyManager#SIM_ACTIVATION_STATE_UNKNOWN
249      * {@more}
250      * Example: TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATED indicates voice service has been
251      * fully activated
252      *
253      * @see #onVoiceActivationStateChanged
254      * @hide
255      */
256     @SystemApi
257     public static final int LISTEN_VOICE_ACTIVATION_STATE                   = 0x00020000;
258 
259     /**
260      * Listen for changes to the sim data activation state
261      * @see TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATING
262      * @see TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATED
263      * @see TelephonyManager#SIM_ACTIVATION_STATE_DEACTIVATED
264      * @see TelephonyManager#SIM_ACTIVATION_STATE_RESTRICTED
265      * @see TelephonyManager#SIM_ACTIVATION_STATE_UNKNOWN
266      * {@more}
267      * Example: TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATED indicates data service has been
268      * fully activated
269      *
270      * @see #onDataActivationStateChanged
271      * @hide
272      */
273     public static final int LISTEN_DATA_ACTIVATION_STATE                   = 0x00040000;
274 
275     /**
276      *  Listen for changes to the user mobile data state
277      *
278      *  @see #onUserMobileDataStateChanged
279      */
280     public static final int LISTEN_USER_MOBILE_DATA_STATE                  = 0x00080000;
281 
282     /**
283      *  Listen for changes to the physical channel configuration.
284      *
285      *  @see #onPhysicalChannelConfigurationChanged
286      *  @hide
287      */
288     public static final int LISTEN_PHYSICAL_CHANNEL_CONFIGURATION          = 0x00100000;
289 
290     /**
291      *  Listen for changes to the phone capability.
292      *
293      *  @see #onPhoneCapabilityChanged
294      *  @hide
295      */
296     public static final int LISTEN_PHONE_CAPABILITY_CHANGE                 = 0x00200000;
297 
298     /**
299      *  Listen for changes to active data subId. Active data subscription is
300      *  the current subscription used to setup Cellular Internet data. For example,
301      *  it could be the current active opportunistic subscription in use, or the
302      *  subscription user selected as default data subscription in DSDS mode.
303      *
304      *  Requires Permission: No permission is required to listen, but notification requires
305      *  {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} or the calling
306      *  app has carrier privileges (see {@link TelephonyManager#hasCarrierPrivileges})
307      *  on any active subscription.
308      *
309      *  @see #onActiveDataSubscriptionIdChanged
310      */
311     public static final int LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE = 0x00400000;
312 
313     /**
314      *  Listen for changes to the radio power state.
315      *
316      *  @see #onRadioPowerStateChanged
317      *  @hide
318      */
319     @SystemApi
320     public static final int LISTEN_RADIO_POWER_STATE_CHANGED               = 0x00800000;
321 
322     /**
323      * Listen for changes to emergency number list based on all active subscriptions.
324      *
325      * <p>Requires permission {@link android.Manifest.permission#READ_PHONE_STATE} or the calling
326      * app has carrier privileges (see {@link TelephonyManager#hasCarrierPrivileges}).
327      *
328      * @see #onEmergencyNumberListChanged
329      */
330     public static final int LISTEN_EMERGENCY_NUMBER_LIST                   = 0x01000000;
331 
332     /**
333      * Listen for call disconnect causes which contains {@link DisconnectCause} and
334      * {@link PreciseDisconnectCause}.
335      *
336      * @hide
337      */
338     @RequiresPermission((android.Manifest.permission.READ_PRECISE_PHONE_STATE))
339     @SystemApi
340     public static final int LISTEN_CALL_DISCONNECT_CAUSES                  = 0x02000000;
341 
342     /**
343      * Listen for changes to the call attributes of a currently active call.
344      * {@more}
345      * Requires Permission: {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE
346      * READ_PRECISE_PHONE_STATE}
347      *
348      * @see #onCallAttributesChanged
349      * @hide
350      */
351     @SystemApi
352     public static final int LISTEN_CALL_ATTRIBUTES_CHANGED                 = 0x04000000;
353 
354     /**
355      * Listen for IMS call disconnect causes which contains
356      * {@link android.telephony.ims.ImsReasonInfo}
357      *
358      * @see #onImsCallDisconnectCauseChanged(ImsReasonInfo)
359      * @hide
360      */
361     @RequiresPermission((android.Manifest.permission.READ_PRECISE_PHONE_STATE))
362     @SystemApi
363     public static final int LISTEN_IMS_CALL_DISCONNECT_CAUSES              = 0x08000000;
364 
365     /*
366      * Subscription used to listen to the phone state changes
367      * @hide
368      */
369     /** @hide */
370     @UnsupportedAppUsage
371     protected Integer mSubId;
372 
373     /**
374      * @hide
375      */
376     @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
377     @UnsupportedAppUsage
378     public final IPhoneStateListener callback;
379 
380     /**
381      * Create a PhoneStateListener for the Phone with the default subscription.
382      * This class requires Looper.myLooper() not return null.
383      */
PhoneStateListener()384     public PhoneStateListener() {
385         this(null, Looper.myLooper());
386     }
387 
388     /**
389      * Create a PhoneStateListener for the Phone with the default subscription
390      * using a particular non-null Looper.
391      * @hide
392      */
393     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
PhoneStateListener(Looper looper)394     public PhoneStateListener(Looper looper) {
395         this(null, looper);
396     }
397 
398     /**
399      * Create a PhoneStateListener for the Phone using the specified subscription.
400      * This class requires Looper.myLooper() not return null. To supply your
401      * own non-null Looper use PhoneStateListener(int subId, Looper looper) below.
402      * @hide
403      */
404     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
PhoneStateListener(Integer subId)405     public PhoneStateListener(Integer subId) {
406         this(subId, Looper.myLooper());
407         if (subId != null && VMRuntime.getRuntime().getTargetSdkVersion()
408                 >= Build.VERSION_CODES.Q) {
409             throw new IllegalArgumentException("PhoneStateListener with subId: "
410                     + subId + " is not supported, use default constructor");
411         }
412     }
413     /**
414      * Create a PhoneStateListener for the Phone using the specified subscription
415      * and non-null Looper.
416      * @hide
417      */
418     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
PhoneStateListener(Integer subId, Looper looper)419     public PhoneStateListener(Integer subId, Looper looper) {
420         this(subId, new HandlerExecutor(new Handler(looper)));
421         if (subId != null && VMRuntime.getRuntime().getTargetSdkVersion()
422                 >= Build.VERSION_CODES.Q) {
423             throw new IllegalArgumentException("PhoneStateListener with subId: "
424                     + subId + " is not supported, use default constructor");
425         }
426     }
427 
428     /**
429      * Create a PhoneStateListener for the Phone using the specified Executor
430      *
431      * <p>Create a PhoneStateListener with a specified Executor for handling necessary callbacks.
432      * The Executor must not be null.
433      *
434      * @param executor a non-null Executor that will execute callbacks for the PhoneStateListener.
435      */
PhoneStateListener(@onNull Executor executor)436     public PhoneStateListener(@NonNull Executor executor) {
437         this(null, executor);
438     }
439 
PhoneStateListener(Integer subId, Executor e)440     private PhoneStateListener(Integer subId, Executor e) {
441         if (e == null) {
442             throw new IllegalArgumentException("PhoneStateListener Executor must be non-null");
443         }
444         mSubId = subId;
445         callback = new IPhoneStateListenerStub(this, e);
446     }
447 
448     /**
449      * Callback invoked when device service state changes on the registered subscription.
450      * Note, the registration subId comes from {@link TelephonyManager} object which registers
451      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
452      * If this TelephonyManager object was created with
453      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
454      * subId. Otherwise, this callback applies to
455      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
456      *
457      * @see ServiceState#STATE_EMERGENCY_ONLY
458      * @see ServiceState#STATE_IN_SERVICE
459      * @see ServiceState#STATE_OUT_OF_SERVICE
460      * @see ServiceState#STATE_POWER_OFF
461      */
onServiceStateChanged(ServiceState serviceState)462     public void onServiceStateChanged(ServiceState serviceState) {
463         // default implementation empty
464     }
465 
466     /**
467      * Callback invoked when network signal strength changes on the registered subscription.
468      * Note, the registration subId comes from {@link TelephonyManager} object which registers
469      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
470      * If this TelephonyManager object was created with
471      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
472      * subId. Otherwise, this callback applies to
473      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
474      *
475      * @see ServiceState#STATE_EMERGENCY_ONLY
476      * @see ServiceState#STATE_IN_SERVICE
477      * @see ServiceState#STATE_OUT_OF_SERVICE
478      * @see ServiceState#STATE_POWER_OFF
479      * @deprecated Use {@link #onSignalStrengthsChanged(SignalStrength)}
480      */
481     @Deprecated
onSignalStrengthChanged(int asu)482     public void onSignalStrengthChanged(int asu) {
483         // default implementation empty
484     }
485 
486     /**
487      * Callback invoked when the message-waiting indicator changes on the registered subscription.
488      * Note, the registration subId comes from {@link TelephonyManager} object which registers
489      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
490      * If this TelephonyManager object was created with
491      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
492      * subId. Otherwise, this callback applies to
493      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
494      */
onMessageWaitingIndicatorChanged(boolean mwi)495     public void onMessageWaitingIndicatorChanged(boolean mwi) {
496         // default implementation empty
497     }
498 
499     /**
500      * Callback invoked when the call-forwarding indicator changes on the registered subscription.
501      * Note, the registration subId comes from {@link TelephonyManager} object which registers
502      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
503      * If this TelephonyManager object was created with
504      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
505      * subId. Otherwise, this callback applies to
506      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
507      */
onCallForwardingIndicatorChanged(boolean cfi)508     public void onCallForwardingIndicatorChanged(boolean cfi) {
509         // default implementation empty
510     }
511 
512     /**
513      * Callback invoked when device cell location changes on the registered subscription.
514      * Note, the registration subId comes from {@link TelephonyManager} object which registers
515      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
516      * If this TelephonyManager object was created with
517      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
518      * subId. Otherwise, this callback applies to
519      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
520      */
onCellLocationChanged(CellLocation location)521     public void onCellLocationChanged(CellLocation location) {
522         // default implementation empty
523     }
524 
525     /**
526      * Callback invoked when device call state changes.
527      * <p>
528      * Reports the state of Telephony (mobile) calls on the device for the registered subscription.
529      * <p>
530      * Note: the registration subId comes from {@link TelephonyManager} object which registers
531      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
532      * If this TelephonyManager object was created with
533      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
534      * subId. Otherwise, this callback applies to
535      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
536      * <p>
537      * Note: The state returned here may differ from that returned by
538      * {@link TelephonyManager#getCallState()}. Receivers of this callback should be aware that
539      * calling {@link TelephonyManager#getCallState()} from within this callback may return a
540      * different state than the callback reports.
541      *
542      * @param state call state
543      * @param phoneNumber call phone number. If application does not have
544      * {@link android.Manifest.permission#READ_CALL_LOG READ_CALL_LOG} permission or carrier
545      * privileges (see {@link TelephonyManager#hasCarrierPrivileges}), an empty string will be
546      * passed as an argument.
547      */
onCallStateChanged(@elephonyManager.CallState int state, String phoneNumber)548     public void onCallStateChanged(@TelephonyManager.CallState int state, String phoneNumber) {
549         // default implementation empty
550     }
551 
552     /**
553      * Callback invoked when connection state changes on the registered subscription.
554      * Note, the registration subId comes from {@link TelephonyManager} object which registers
555      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
556      * If this TelephonyManager object was created with
557      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
558      * subId. Otherwise, this callback applies to
559      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
560      *
561      * @see TelephonyManager#DATA_DISCONNECTED
562      * @see TelephonyManager#DATA_CONNECTING
563      * @see TelephonyManager#DATA_CONNECTED
564      * @see TelephonyManager#DATA_SUSPENDED
565      */
onDataConnectionStateChanged(int state)566     public void onDataConnectionStateChanged(int state) {
567         // default implementation empty
568     }
569 
570     /**
571      * same as above, but with the network type.  Both called.
572      */
onDataConnectionStateChanged(int state, int networkType)573     public void onDataConnectionStateChanged(int state, int networkType) {
574     }
575 
576     /**
577      * Callback invoked when data activity state changes on the registered subscription.
578      * Note, the registration subId comes from {@link TelephonyManager} object which registers
579      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
580      * If this TelephonyManager object was created with
581      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
582      * subId. Otherwise, this callback applies to
583      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
584      *
585      * @see TelephonyManager#DATA_ACTIVITY_NONE
586      * @see TelephonyManager#DATA_ACTIVITY_IN
587      * @see TelephonyManager#DATA_ACTIVITY_OUT
588      * @see TelephonyManager#DATA_ACTIVITY_INOUT
589      * @see TelephonyManager#DATA_ACTIVITY_DORMANT
590      */
onDataActivity(int direction)591     public void onDataActivity(int direction) {
592         // default implementation empty
593     }
594 
595     /**
596      * Callback invoked when network signal strengths changes on the registered subscription.
597      * Note, the registration subId comes from {@link TelephonyManager} object which registers
598      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
599      * If this TelephonyManager object was created with
600      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
601      * subId. Otherwise, this callback applies to
602      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
603      */
onSignalStrengthsChanged(SignalStrength signalStrength)604     public void onSignalStrengthsChanged(SignalStrength signalStrength) {
605         // default implementation empty
606     }
607 
608 
609     /**
610      * The Over The Air Service Provisioning (OTASP) has changed on the registered subscription.
611      * Note, the registration subId comes from {@link TelephonyManager} object which registers
612      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
613      * If this TelephonyManager object was created with
614      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
615      * subId. Otherwise, this callback applies to
616      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
617      *
618      * Requires the READ_PHONE_STATE permission.
619      * @param otaspMode is integer <code>OTASP_UNKNOWN=1<code>
620      *   means the value is currently unknown and the system should wait until
621      *   <code>OTASP_NEEDED=2<code> or <code>OTASP_NOT_NEEDED=3<code> is received before
622      *   making the decision to perform OTASP or not.
623      *
624      * @hide
625      */
626     @UnsupportedAppUsage
onOtaspChanged(int otaspMode)627     public void onOtaspChanged(int otaspMode) {
628         // default implementation empty
629     }
630 
631     /**
632      * Callback invoked when a observed cell info has changed or new cells have been added
633      * or removed on the registered subscription.
634      * Note, the registration subId s from {@link TelephonyManager} object which registers
635      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
636      * If this TelephonyManager object was created with
637      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
638      * subId. Otherwise, this callback applies to
639      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
640      *
641      * @param cellInfo is the list of currently visible cells.
642      */
onCellInfoChanged(List<CellInfo> cellInfo)643     public void onCellInfoChanged(List<CellInfo> cellInfo) {
644     }
645 
646     /**
647      * Callback invoked when precise device call state changes on the registered subscription.
648      * Note, the registration subId comes from {@link TelephonyManager} object which registers
649      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
650      * If this TelephonyManager object was created with
651      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
652      * subId. Otherwise, this callback applies to
653      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
654      * @param callState {@link PreciseCallState}
655      * @hide
656      */
657     @RequiresPermission((android.Manifest.permission.READ_PRECISE_PHONE_STATE))
658     @SystemApi
onPreciseCallStateChanged(@onNull PreciseCallState callState)659     public void onPreciseCallStateChanged(@NonNull PreciseCallState callState) {
660         // default implementation empty
661     }
662 
663     /**
664      * Callback invoked when call disconnect cause changes on the registered subscription.
665      * Note, the registration subId comes from {@link TelephonyManager} object which registers
666      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
667      * If this TelephonyManager object was created with
668      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
669      * subId. Otherwise, this callback applies to
670      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
671      *
672      * @param disconnectCause {@link DisconnectCause}.
673      * @param preciseDisconnectCause {@link PreciseDisconnectCause}.
674      *
675      * @hide
676      */
677     @RequiresPermission((android.Manifest.permission.READ_PRECISE_PHONE_STATE))
678     @SystemApi
onCallDisconnectCauseChanged(int disconnectCause, int preciseDisconnectCause)679     public void onCallDisconnectCauseChanged(int disconnectCause, int preciseDisconnectCause) {
680         // default implementation empty
681     }
682 
683     /**
684      * Callback invoked when Ims call disconnect cause changes on the registered subscription.
685      * Note, the registration subId comes from {@link TelephonyManager} object which registers
686      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
687      * If this TelephonyManager object was created with
688      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
689      * subId. Otherwise, this callback applies to
690      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
691      *
692      * @param imsReasonInfo {@link ImsReasonInfo} contains details on why IMS call failed.
693      *
694      * @hide
695      */
696     @RequiresPermission((android.Manifest.permission.READ_PRECISE_PHONE_STATE))
697     @SystemApi
onImsCallDisconnectCauseChanged(@onNull ImsReasonInfo imsReasonInfo)698     public void onImsCallDisconnectCauseChanged(@NonNull ImsReasonInfo imsReasonInfo) {
699         // default implementation empty
700     }
701 
702     /**
703      * Callback invoked when data connection state changes with precise information
704      * on the registered subscription.
705      * Note, the registration subId comes from {@link TelephonyManager} object which registers
706      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
707      * If this TelephonyManager object was created with
708      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
709      * subId. Otherwise, this callback applies to
710      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
711      *
712      * @param dataConnectionState {@link PreciseDataConnectionState}
713      *
714      * @hide
715      */
716     @RequiresPermission((android.Manifest.permission.READ_PRECISE_PHONE_STATE))
717     @SystemApi
onPreciseDataConnectionStateChanged( @onNull PreciseDataConnectionState dataConnectionState)718     public void onPreciseDataConnectionStateChanged(
719             @NonNull PreciseDataConnectionState dataConnectionState) {
720         // default implementation empty
721     }
722 
723     /**
724      * Callback invoked when data connection real time info changes on the registered subscription.
725      * Note, the registration subId comes from {@link TelephonyManager} object which registers
726      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
727      * If this TelephonyManager object was created with
728      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
729      * subId. Otherwise, this callback applies to
730      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
731      *
732      * @hide
733      */
734     @UnsupportedAppUsage
onDataConnectionRealTimeInfoChanged( DataConnectionRealTimeInfo dcRtInfo)735     public void onDataConnectionRealTimeInfoChanged(
736             DataConnectionRealTimeInfo dcRtInfo) {
737         // default implementation empty
738     }
739 
740     /**
741      * Callback invoked when there has been a change in the Single Radio Voice Call Continuity
742      * (SRVCC) state for the currently active call on the registered subscription.
743      *
744      * Note, the registration subId comes from {@link TelephonyManager} object which registers
745      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
746      * If this TelephonyManager object was created with
747      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
748      * subId. Otherwise, this callback applies to
749      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
750      *
751      * @hide
752      */
753     @SystemApi
onSrvccStateChanged(@elephonyManager.SrvccState int srvccState)754     public void onSrvccStateChanged(@TelephonyManager.SrvccState int srvccState) {
755 
756     }
757 
758     /**
759      * Callback invoked when the SIM voice activation state has changed on the registered
760      * subscription.
761      * Note, the registration subId comes from {@link TelephonyManager} object which registers
762      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
763      * If this TelephonyManager object was created with
764      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
765      * subId. Otherwise, this callback applies to
766      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
767      *
768      * @param state is the current SIM voice activation state
769      * @hide
770      */
771     @SystemApi
onVoiceActivationStateChanged(@elephonyManager.SimActivationState int state)772     public void onVoiceActivationStateChanged(@TelephonyManager.SimActivationState int state) {
773     }
774 
775     /**
776      * Callback invoked when the SIM data activation state has changed on the registered
777      * subscription.
778      * Note, the registration subId comes from {@link TelephonyManager} object which registers
779      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
780      * If this TelephonyManager object was created with
781      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
782      * subId. Otherwise, this callback applies to
783      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
784      *
785      * @param state is the current SIM data activation state
786      * @hide
787      */
onDataActivationStateChanged(@elephonyManager.SimActivationState int state)788     public void onDataActivationStateChanged(@TelephonyManager.SimActivationState int state) {
789     }
790 
791     /**
792      * Callback invoked when the user mobile data state has changed on the registered subscription.
793      * Note, the registration subId comes from {@link TelephonyManager} object which registers
794      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
795      * If this TelephonyManager object was created with
796      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
797      * subId. Otherwise, this callback applies to
798      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
799      *
800      * @param enabled indicates whether the current user mobile data state is enabled or disabled.
801      */
onUserMobileDataStateChanged(boolean enabled)802     public void onUserMobileDataStateChanged(boolean enabled) {
803         // default implementation empty
804     }
805 
806     /**
807      * Callback invoked when the current physical channel configuration has changed on the
808      * registered subscription.
809      * Note, the registration subId comes from {@link TelephonyManager} object which registers
810      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
811      * If this TelephonyManager object was created with
812      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
813      * subId. Otherwise, this callback applies to
814      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
815      *
816      * @param configs List of the current {@link PhysicalChannelConfig}s
817      * @hide
818      */
onPhysicalChannelConfigurationChanged( @onNull List<PhysicalChannelConfig> configs)819     public void onPhysicalChannelConfigurationChanged(
820             @NonNull List<PhysicalChannelConfig> configs) {
821         // default implementation empty
822     }
823 
824     /**
825      * Callback invoked when the current emergency number list has changed on the registered
826      * subscription.
827      * Note, the registration subId comes from {@link TelephonyManager} object which registers
828      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
829      * If this TelephonyManager object was created with
830      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
831      * subId. Otherwise, this callback applies to
832      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
833      *
834      * @param emergencyNumberList Map including the key as the active subscription ID
835      *                           (Note: if there is no active subscription, the key is
836      *                           {@link SubscriptionManager#getDefaultSubscriptionId})
837      *                           and the value as the list of {@link EmergencyNumber};
838      *                           null if this information is not available.
839      * @hide
840      */
onEmergencyNumberListChanged( @onNull Map<Integer, List<EmergencyNumber>> emergencyNumberList)841     public void onEmergencyNumberListChanged(
842             @NonNull Map<Integer, List<EmergencyNumber>> emergencyNumberList) {
843         // default implementation empty
844     }
845 
846     /**
847      * Callback invoked when OEM hook raw event is received on the registered subscription.
848      * Note, the registration subId comes from {@link TelephonyManager} object which registers
849      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
850      * If this TelephonyManager object was created with
851      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
852      * subId. Otherwise, this callback applies to
853      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
854      *
855      * Requires the READ_PRIVILEGED_PHONE_STATE permission.
856      * @param rawData is the byte array of the OEM hook raw data.
857      * @hide
858      */
859     @UnsupportedAppUsage
onOemHookRawEvent(byte[] rawData)860     public void onOemHookRawEvent(byte[] rawData) {
861         // default implementation empty
862     }
863 
864     /**
865      * Callback invoked when phone capability changes.
866      * Note, this callback triggers regardless of registered subscription.
867      *
868      * Requires the READ_PRIVILEGED_PHONE_STATE permission.
869      * @param capability the new phone capability
870      * @hide
871      */
onPhoneCapabilityChanged(PhoneCapability capability)872     public void onPhoneCapabilityChanged(PhoneCapability capability) {
873         // default implementation empty
874     }
875 
876     /**
877      * Callback invoked when active data subId changes.
878      * Note, this callback triggers regardless of registered subscription.
879      *
880      * Requires the READ_PHONE_STATE permission.
881      * @param subId current subscription used to setup Cellular Internet data.
882      *              For example, it could be the current active opportunistic subscription in use,
883      *              or the subscription user selected as default data subscription in DSDS mode.
884      */
onActiveDataSubscriptionIdChanged(int subId)885     public void onActiveDataSubscriptionIdChanged(int subId) {
886         // default implementation empty
887     }
888 
889     /**
890      * Callback invoked when the call attributes changes on the registered subscription.
891      * Note, the registration subId comes from {@link TelephonyManager} object which registers
892      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
893      * If this TelephonyManager object was created with
894      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
895      * subId. Otherwise, this callback applies to
896      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
897      *
898      * Requires the READ_PRIVILEGED_PHONE_STATE permission.
899      * @param callAttributes the call attributes
900      * @hide
901      */
902     @SystemApi
onCallAttributesChanged(@onNull CallAttributes callAttributes)903     public void onCallAttributesChanged(@NonNull CallAttributes callAttributes) {
904         // default implementation empty
905     }
906 
907     /**
908      * Callback invoked when modem radio power state changes on the registered subscription.
909      * Note, the registration subId comes from {@link TelephonyManager} object which registers
910      * PhoneStateListener by {@link TelephonyManager#listen(PhoneStateListener, int)}.
911      * If this TelephonyManager object was created with
912      * {@link TelephonyManager#createForSubscriptionId(int)}, then the callback applies to the
913      * subId. Otherwise, this callback applies to
914      * {@link SubscriptionManager#getDefaultSubscriptionId()}.
915      *
916      * Requires
917      * the READ_PRIVILEGED_PHONE_STATE permission.
918      * @param state the modem radio power state
919      * @hide
920      */
921     @SystemApi
onRadioPowerStateChanged(@elephonyManager.RadioPowerState int state)922     public void onRadioPowerStateChanged(@TelephonyManager.RadioPowerState int state) {
923         // default implementation empty
924     }
925 
926     /**
927      * Callback invoked when telephony has received notice from a carrier
928      * app that a network action that could result in connectivity loss
929      * has been requested by an app using
930      * {@link android.telephony.TelephonyManager#notifyCarrierNetworkChange(boolean)}
931      *
932      * Note, this callback is pinned to the registered subscription and will be invoked when
933      * the notifying carrier app has carrier privilege rule on the registered
934      * subscription. {@link android.telephony.TelephonyManager#hasCarrierPrivileges}
935      *
936      * @param active Whether the carrier network change is or shortly
937      *               will be active. This value is true to indicate
938      *               showing alternative UI and false to stop.
939      *
940      * @hide
941      */
onCarrierNetworkChange(boolean active)942     public void onCarrierNetworkChange(boolean active) {
943         // default implementation empty
944     }
945 
946     /**
947      * The callback methods need to be called on the handler thread where
948      * this object was created.  If the binder did that for us it'd be nice.
949      *
950      * Using a static class and weak reference here to avoid memory leak caused by the
951      * IPhoneStateListener.Stub callback retaining references to the outside PhoneStateListeners:
952      * even caller has been destroyed and "un-registered" the PhoneStateListener, it is still not
953      * eligible for GC given the references coming from:
954      * Native Stack --> PhoneStateListener --> Context (Activity).
955      * memory of caller's context will be collected after GC from service side get triggered
956      */
957     private static class IPhoneStateListenerStub extends IPhoneStateListener.Stub {
958         private WeakReference<PhoneStateListener> mPhoneStateListenerWeakRef;
959         private Executor mExecutor;
960 
IPhoneStateListenerStub(PhoneStateListener phoneStateListener, Executor executor)961         IPhoneStateListenerStub(PhoneStateListener phoneStateListener, Executor executor) {
962             mPhoneStateListenerWeakRef = new WeakReference<PhoneStateListener>(phoneStateListener);
963             mExecutor = executor;
964         }
965 
onServiceStateChanged(ServiceState serviceState)966         public void onServiceStateChanged(ServiceState serviceState) {
967             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
968             if (psl == null) return;
969 
970             Binder.withCleanCallingIdentity(
971                     () -> mExecutor.execute(() -> psl.onServiceStateChanged(serviceState)));
972         }
973 
onSignalStrengthChanged(int asu)974         public void onSignalStrengthChanged(int asu) {
975             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
976             if (psl == null) return;
977 
978             Binder.withCleanCallingIdentity(
979                     () -> mExecutor.execute(() -> psl.onSignalStrengthChanged(asu)));
980         }
981 
onMessageWaitingIndicatorChanged(boolean mwi)982         public void onMessageWaitingIndicatorChanged(boolean mwi) {
983             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
984             if (psl == null) return;
985 
986             Binder.withCleanCallingIdentity(
987                     () -> mExecutor.execute(() -> psl.onMessageWaitingIndicatorChanged(mwi)));
988         }
989 
onCallForwardingIndicatorChanged(boolean cfi)990         public void onCallForwardingIndicatorChanged(boolean cfi) {
991             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
992             if (psl == null) return;
993 
994             Binder.withCleanCallingIdentity(
995                     () -> mExecutor.execute(() -> psl.onCallForwardingIndicatorChanged(cfi)));
996         }
997 
onCellLocationChanged(Bundle bundle)998         public void onCellLocationChanged(Bundle bundle) {
999             CellLocation location = CellLocation.newFromBundle(bundle);
1000             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1001             if (psl == null) return;
1002 
1003             Binder.withCleanCallingIdentity(
1004                     () -> mExecutor.execute(() -> psl.onCellLocationChanged(location)));
1005         }
1006 
onCallStateChanged(int state, String incomingNumber)1007         public void onCallStateChanged(int state, String incomingNumber) {
1008             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1009             if (psl == null) return;
1010 
1011             Binder.withCleanCallingIdentity(
1012                     () -> mExecutor.execute(() -> psl.onCallStateChanged(state, incomingNumber)));
1013         }
1014 
onDataConnectionStateChanged(int state, int networkType)1015         public void onDataConnectionStateChanged(int state, int networkType) {
1016             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1017             if (psl == null) return;
1018 
1019             Binder.withCleanCallingIdentity(() -> mExecutor.execute(
1020                     () -> {
1021                         psl.onDataConnectionStateChanged(state, networkType);
1022                         psl.onDataConnectionStateChanged(state);
1023                     }));
1024         }
1025 
onDataActivity(int direction)1026         public void onDataActivity(int direction) {
1027             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1028             if (psl == null) return;
1029 
1030             Binder.withCleanCallingIdentity(
1031                     () -> mExecutor.execute(() -> psl.onDataActivity(direction)));
1032         }
1033 
onSignalStrengthsChanged(SignalStrength signalStrength)1034         public void onSignalStrengthsChanged(SignalStrength signalStrength) {
1035             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1036             if (psl == null) return;
1037 
1038             Binder.withCleanCallingIdentity(
1039                     () -> mExecutor.execute(() -> psl.onSignalStrengthsChanged(signalStrength)));
1040         }
1041 
onOtaspChanged(int otaspMode)1042         public void onOtaspChanged(int otaspMode) {
1043             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1044             if (psl == null) return;
1045 
1046             Binder.withCleanCallingIdentity(
1047                     () -> mExecutor.execute(() -> psl.onOtaspChanged(otaspMode)));
1048         }
1049 
onCellInfoChanged(List<CellInfo> cellInfo)1050         public void onCellInfoChanged(List<CellInfo> cellInfo) {
1051             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1052             if (psl == null) return;
1053 
1054             Binder.withCleanCallingIdentity(
1055                     () -> mExecutor.execute(() -> psl.onCellInfoChanged(cellInfo)));
1056         }
1057 
onPreciseCallStateChanged(PreciseCallState callState)1058         public void onPreciseCallStateChanged(PreciseCallState callState) {
1059             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1060             if (psl == null) return;
1061 
1062             Binder.withCleanCallingIdentity(
1063                     () -> mExecutor.execute(() -> psl.onPreciseCallStateChanged(callState)));
1064         }
1065 
onCallDisconnectCauseChanged(int disconnectCause, int preciseDisconnectCause)1066         public void onCallDisconnectCauseChanged(int disconnectCause, int preciseDisconnectCause) {
1067             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1068             if (psl == null) return;
1069 
1070             Binder.withCleanCallingIdentity(
1071                     () -> mExecutor.execute(() -> psl.onCallDisconnectCauseChanged(
1072                             disconnectCause, preciseDisconnectCause)));
1073         }
1074 
onPreciseDataConnectionStateChanged( PreciseDataConnectionState dataConnectionState)1075         public void onPreciseDataConnectionStateChanged(
1076                 PreciseDataConnectionState dataConnectionState) {
1077             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1078             if (psl == null) return;
1079 
1080             Binder.withCleanCallingIdentity(
1081                     () -> mExecutor.execute(
1082                             () -> psl.onPreciseDataConnectionStateChanged(dataConnectionState)));
1083         }
1084 
onDataConnectionRealTimeInfoChanged(DataConnectionRealTimeInfo dcRtInfo)1085         public void onDataConnectionRealTimeInfoChanged(DataConnectionRealTimeInfo dcRtInfo) {
1086             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1087             if (psl == null) return;
1088 
1089             Binder.withCleanCallingIdentity(
1090                     () -> mExecutor.execute(
1091                             () -> psl.onDataConnectionRealTimeInfoChanged(dcRtInfo)));
1092         }
1093 
onSrvccStateChanged(int state)1094         public void onSrvccStateChanged(int state) {
1095             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1096             if (psl == null) return;
1097 
1098             Binder.withCleanCallingIdentity(
1099                     () -> mExecutor.execute(() -> psl.onSrvccStateChanged(state)));
1100         }
1101 
onVoiceActivationStateChanged(int activationState)1102         public void onVoiceActivationStateChanged(int activationState) {
1103             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1104             if (psl == null) return;
1105 
1106             Binder.withCleanCallingIdentity(
1107                     () -> mExecutor.execute(
1108                             () -> psl.onVoiceActivationStateChanged(activationState)));
1109         }
1110 
onDataActivationStateChanged(int activationState)1111         public void onDataActivationStateChanged(int activationState) {
1112             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1113             if (psl == null) return;
1114 
1115             Binder.withCleanCallingIdentity(
1116                     () -> mExecutor.execute(
1117                             () -> psl.onDataActivationStateChanged(activationState)));
1118         }
1119 
onUserMobileDataStateChanged(boolean enabled)1120         public void onUserMobileDataStateChanged(boolean enabled) {
1121             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1122             if (psl == null) return;
1123 
1124             Binder.withCleanCallingIdentity(
1125                     () -> mExecutor.execute(
1126                             () -> psl.onUserMobileDataStateChanged(enabled)));
1127         }
1128 
onOemHookRawEvent(byte[] rawData)1129         public void onOemHookRawEvent(byte[] rawData) {
1130             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1131             if (psl == null) return;
1132 
1133             Binder.withCleanCallingIdentity(
1134                     () -> mExecutor.execute(() -> psl.onOemHookRawEvent(rawData)));
1135         }
1136 
onCarrierNetworkChange(boolean active)1137         public void onCarrierNetworkChange(boolean active) {
1138             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1139             if (psl == null) return;
1140 
1141             Binder.withCleanCallingIdentity(
1142                     () -> mExecutor.execute(() -> psl.onCarrierNetworkChange(active)));
1143         }
1144 
onPhysicalChannelConfigurationChanged(List<PhysicalChannelConfig> configs)1145         public void onPhysicalChannelConfigurationChanged(List<PhysicalChannelConfig> configs) {
1146             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1147             if (psl == null) return;
1148 
1149             Binder.withCleanCallingIdentity(
1150                     () -> mExecutor.execute(
1151                             () -> psl.onPhysicalChannelConfigurationChanged(configs)));
1152         }
1153 
1154         @Override
onEmergencyNumberListChanged(Map emergencyNumberList)1155         public void onEmergencyNumberListChanged(Map emergencyNumberList) {
1156             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1157             if (psl == null) return;
1158 
1159             Binder.withCleanCallingIdentity(
1160                     () -> mExecutor.execute(
1161                             () -> psl.onEmergencyNumberListChanged(emergencyNumberList)));
1162         }
1163 
onPhoneCapabilityChanged(PhoneCapability capability)1164         public void onPhoneCapabilityChanged(PhoneCapability capability) {
1165             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1166             if (psl == null) return;
1167 
1168             Binder.withCleanCallingIdentity(
1169                     () -> mExecutor.execute(() -> psl.onPhoneCapabilityChanged(capability)));
1170         }
1171 
onRadioPowerStateChanged(@elephonyManager.RadioPowerState int state)1172         public void onRadioPowerStateChanged(@TelephonyManager.RadioPowerState int state) {
1173             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1174             if (psl == null) return;
1175 
1176             Binder.withCleanCallingIdentity(
1177                     () -> mExecutor.execute(() -> psl.onRadioPowerStateChanged(state)));
1178         }
1179 
onCallAttributesChanged(CallAttributes callAttributes)1180         public void onCallAttributesChanged(CallAttributes callAttributes) {
1181             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1182             if (psl == null) return;
1183 
1184             Binder.withCleanCallingIdentity(
1185                     () -> mExecutor.execute(() -> psl.onCallAttributesChanged(callAttributes)));
1186         }
1187 
onActiveDataSubIdChanged(int subId)1188         public void onActiveDataSubIdChanged(int subId) {
1189             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1190             if (psl == null) return;
1191 
1192             Binder.withCleanCallingIdentity(
1193                     () -> mExecutor.execute(() -> psl.onActiveDataSubscriptionIdChanged(subId)));
1194         }
1195 
onImsCallDisconnectCauseChanged(ImsReasonInfo disconnectCause)1196         public void onImsCallDisconnectCauseChanged(ImsReasonInfo disconnectCause) {
1197             PhoneStateListener psl = mPhoneStateListenerWeakRef.get();
1198             if (psl == null) return;
1199 
1200             Binder.withCleanCallingIdentity(
1201                     () -> mExecutor.execute(
1202                             () -> psl.onImsCallDisconnectCauseChanged(disconnectCause)));
1203 
1204         }
1205     }
1206 
1207 
log(String s)1208     private void log(String s) {
1209         Rlog.d(LOG_TAG, s);
1210     }
1211 }
1212