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