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