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