TelephonyManager.java revision 65d62c774e42d8bf9a55ef50e153ffc9e277ef37
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 17package android.telephony; 18 19import android.annotation.SdkConstant; 20import android.annotation.SdkConstant.SdkConstantType; 21import android.content.Context; 22import android.os.Bundle; 23import android.os.RemoteException; 24import android.os.ServiceManager; 25import android.os.SystemProperties; 26 27import com.android.internal.telephony.IPhoneSubInfo; 28import com.android.internal.telephony.ITelephony; 29import com.android.internal.telephony.ITelephonyRegistry; 30import com.android.internal.telephony.Phone; 31import com.android.internal.telephony.PhoneFactory; 32import com.android.internal.telephony.RILConstants; 33import com.android.internal.telephony.TelephonyProperties; 34 35import java.util.List; 36 37/** 38 * Provides access to information about the telephony services on 39 * the device. Applications can use the methods in this class to 40 * determine telephony services and states, as well as to access some 41 * types of subscriber information. Applications can also register 42 * a listener to receive notification of telephony state changes. 43 * <p> 44 * You do not instantiate this class directly; instead, you retrieve 45 * a reference to an instance through 46 * {@link android.content.Context#getSystemService 47 * Context.getSystemService(Context.TELEPHONY_SERVICE)}. 48 * <p> 49 * Note that acess to some telephony information is 50 * permission-protected. Your application cannot access the protected 51 * information unless it has the appropriate permissions declared in 52 * its manifest file. Where permissions apply, they are noted in the 53 * the methods through which you access the protected information. 54 */ 55public class TelephonyManager { 56 private static final String TAG = "TelephonyManager"; 57 58 private Context mContext; 59 private ITelephonyRegistry mRegistry; 60 61 /** @hide */ 62 public TelephonyManager(Context context) { 63 mContext = context; 64 mRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService( 65 "telephony.registry")); 66 } 67 68 /** @hide */ 69 private TelephonyManager() { 70 } 71 72 private static TelephonyManager sInstance = new TelephonyManager(); 73 74 /** @hide */ 75 public static TelephonyManager getDefault() { 76 return sInstance; 77 } 78 79 80 // 81 // Broadcast Intent actions 82 // 83 84 /** 85 * Broadcast intent action indicating that the call state (cellular) 86 * on the device has changed. 87 * 88 * <p> 89 * The {@link #EXTRA_STATE} extra indicates the new call state. 90 * If the new state is RINGING, a second extra 91 * {@link #EXTRA_INCOMING_NUMBER} provides the incoming phone number as 92 * a String. 93 * 94 * <p class="note"> 95 * Requires the READ_PHONE_STATE permission. 96 * 97 * <p class="note"> 98 * This was a {@link android.content.Context#sendStickyBroadcast sticky} 99 * broadcast in version 1.0, but it is no longer sticky. 100 * Instead, use {@link #getCallState} to synchronously query the current call state. 101 * 102 * @see #EXTRA_STATE 103 * @see #EXTRA_INCOMING_NUMBER 104 * @see #getCallState 105 */ 106 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 107 public static final String ACTION_PHONE_STATE_CHANGED = 108 "android.intent.action.PHONE_STATE"; 109 110 /** 111 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 112 * for a String containing the new call state. 113 * 114 * @see #EXTRA_STATE_IDLE 115 * @see #EXTRA_STATE_RINGING 116 * @see #EXTRA_STATE_OFFHOOK 117 * 118 * <p class="note"> 119 * Retrieve with 120 * {@link android.content.Intent#getStringExtra(String)}. 121 */ 122 public static final String EXTRA_STATE = Phone.STATE_KEY; 123 124 /** 125 * Value used with {@link #EXTRA_STATE} corresponding to 126 * {@link #CALL_STATE_IDLE}. 127 */ 128 public static final String EXTRA_STATE_IDLE = Phone.State.IDLE.toString(); 129 130 /** 131 * Value used with {@link #EXTRA_STATE} corresponding to 132 * {@link #CALL_STATE_RINGING}. 133 */ 134 public static final String EXTRA_STATE_RINGING = Phone.State.RINGING.toString(); 135 136 /** 137 * Value used with {@link #EXTRA_STATE} corresponding to 138 * {@link #CALL_STATE_OFFHOOK}. 139 */ 140 public static final String EXTRA_STATE_OFFHOOK = Phone.State.OFFHOOK.toString(); 141 142 /** 143 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 144 * for a String containing the incoming phone number. 145 * Only valid when the new call state is RINGING. 146 * 147 * <p class="note"> 148 * Retrieve with 149 * {@link android.content.Intent#getStringExtra(String)}. 150 */ 151 public static final String EXTRA_INCOMING_NUMBER = "incoming_number"; 152 153 154 // 155 // 156 // Device Info 157 // 158 // 159 160 /** 161 * Returns the software version number for the device, for example, 162 * the IMEI/SV for GSM phones. 163 * 164 * <p>Requires Permission: 165 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 166 */ 167 public String getDeviceSoftwareVersion() { 168 try { 169 return getSubscriberInfo().getDeviceSvn(); 170 } catch (RemoteException ex) { 171 } 172 return null; 173 } 174 175 /** 176 * Returns the unique device ID, for example, the IMEI for GSM and the MEID for CDMA 177 * phones. 178 * 179 * <p>Requires Permission: 180 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 181 */ 182 public String getDeviceId() { 183 try { 184 return getSubscriberInfo().getDeviceId(); 185 } catch (RemoteException ex) { 186 } 187 return null; 188 } 189 190 /** 191 * Returns the current location of the device. 192 * 193 * <p>Requires Permission: 194 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or 195 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION}. 196 */ 197 public CellLocation getCellLocation() { 198 try { 199 Bundle bundle = getITelephony().getCellLocation(); 200 return CellLocation.newFromBundle(bundle); 201 } catch (RemoteException ex) { 202 } 203 return null; 204 } 205 206 /** 207 * Enables location update notifications. {@link PhoneStateListener#onCellLocationChanged 208 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 209 * 210 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 211 * CONTROL_LOCATION_UPDATES} 212 * 213 * @hide 214 */ 215 public void enableLocationUpdates() { 216 try { 217 getITelephony().enableLocationUpdates(); 218 } catch (RemoteException ex) { 219 } 220 } 221 222 /** 223 * Disables location update notifications. {@link PhoneStateListener#onCellLocationChanged 224 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 225 * 226 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 227 * CONTROL_LOCATION_UPDATES} 228 * 229 * @hide 230 */ 231 public void disableLocationUpdates() { 232 try { 233 getITelephony().disableLocationUpdates(); 234 } catch (RemoteException ex) { 235 } 236 } 237 238 /** 239 * Returns the neighboring cell information of the device. 240 * 241 * @return List of NeighboringCellInfo or null if info unavailable. 242 * 243 * <p>Requires Permission: 244 * (@link android.Manifest.permission#ACCESS_COARSE_UPDATES} 245 */ 246 public List<NeighboringCellInfo> getNeighboringCellInfo() { 247 try { 248 return getITelephony().getNeighboringCellInfo(); 249 } catch (RemoteException ex) { 250 } 251 return null; 252 253 } 254 255 /** 256 * No phone module 257 * 258 */ 259 public static final int PHONE_TYPE_NONE = RILConstants.NO_PHONE; 260 261 /** 262 * GSM phone 263 */ 264 public static final int PHONE_TYPE_GSM = RILConstants.GSM_PHONE; 265 266 /** 267 * CDMA phone 268 * @hide 269 */ 270 public static final int PHONE_TYPE_CDMA = RILConstants.CDMA_PHONE; 271 272 /** 273 * Returns a constant indicating the device phone type. 274 * 275 * @see #PHONE_TYPE_NONE 276 * @see #PHONE_TYPE_GSM 277 * @see #PHONE_TYPE_CDMA 278 */ 279 public int getPhoneType() { 280 try{ 281 ITelephony telephony = getITelephony(); 282 if (telephony != null) { 283 if(telephony.getActivePhoneType() == RILConstants.CDMA_PHONE) { 284 return PHONE_TYPE_CDMA; 285 } else { 286 return PHONE_TYPE_GSM; 287 } 288 } else { 289 // This can happen when the ITelephony interface is not up yet. 290 return getPhoneTypeFromProperty(); 291 } 292 } catch(RemoteException ex){ 293 // This shouldn't happen in the normal case, as a backup we 294 // read from the system property. 295 return getPhoneTypeFromProperty(); 296 } 297 } 298 299 300 private int getPhoneTypeFromProperty() { 301 int type = 302 SystemProperties.getInt(TelephonyProperties.CURRENT_ACTIVE_PHONE, 303 getPhoneTypeFromNetworkType()); 304 return type; 305 } 306 307 private int getPhoneTypeFromNetworkType() { 308 // When the system property CURRENT_ACTIVE_PHONE, has not been set, 309 // use the system property for default network type. 310 // This is a fail safe, and can only happen at first boot. 311 int mode = SystemProperties.getInt("ro.telephony.default_network", -1); 312 if (mode == -1) 313 return PHONE_TYPE_NONE; 314 return PhoneFactory.getPhoneType(mode); 315 } 316 // 317 // 318 // Current Network 319 // 320 // 321 322 /** 323 * Returns the alphabetic name of current registered operator. 324 * <p> 325 * Availability: Only when user is registered to a network. Result may be 326 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 327 * on a CDMA network). 328 */ 329 public String getNetworkOperatorName() { 330 return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ALPHA); 331 } 332 333 /** 334 * Returns the numeric name (MCC+MNC) of current registered operator. 335 * <p> 336 * Availability: Only when user is registered to a network. Result may be 337 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 338 * on a CDMA network). 339 */ 340 public String getNetworkOperator() { 341 return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC); 342 } 343 344 /** 345 * Returns true if the device is considered roaming on the current 346 * network, for GSM purposes. 347 * <p> 348 * Availability: Only when user registered to a network. 349 */ 350 public boolean isNetworkRoaming() { 351 return "true".equals(SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ISROAMING)); 352 } 353 354 /** 355 * Returns the ISO country code equivilent of the current registered 356 * operator's MCC (Mobile Country Code). 357 * <p> 358 * Availability: Only when user is registered to a network. Result may be 359 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 360 * on a CDMA network). 361 */ 362 public String getNetworkCountryIso() { 363 return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY); 364 } 365 366 /** Network type is unknown */ 367 public static final int NETWORK_TYPE_UNKNOWN = 0; 368 /** Current network is GPRS */ 369 public static final int NETWORK_TYPE_GPRS = 1; 370 /** Current network is EDGE */ 371 public static final int NETWORK_TYPE_EDGE = 2; 372 /** Current network is UMTS */ 373 public static final int NETWORK_TYPE_UMTS = 3; 374 /** Current network is CDMA: Either IS95A or IS95B*/ 375 /** @hide */ 376 public static final int NETWORK_TYPE_CDMA = 4; 377 /** Current network is EVDO revision 0 or revision A*/ 378 /** @hide */ 379 public static final int NETWORK_TYPE_EVDO_0 = 5; 380 /** @hide */ 381 public static final int NETWORK_TYPE_EVDO_A = 6; 382 /** Current network is 1xRTT*/ 383 /** @hide */ 384 public static final int NETWORK_TYPE_1xRTT = 7; 385 /** Current network is HSDPA */ 386 /** @hide */ 387 public static final int NETWORK_TYPE_HSDPA = 8; 388 /** Current network is HSUPA */ 389 /** @hide */ 390 public static final int NETWORK_TYPE_HSUPA = 9; 391 /** Current network is HSPA */ 392 /** @hide */ 393 public static final int NETWORK_TYPE_HSPA = 10; 394 395 /** 396 * Returns a constant indicating the radio technology (network type) 397 * currently in use on the device. 398 * @return the network type 399 * 400 * @see #NETWORK_TYPE_UNKNOWN 401 * @see #NETWORK_TYPE_GPRS 402 * @see #NETWORK_TYPE_EDGE 403 * @see #NETWORK_TYPE_UMTS 404 * @see #NETWORK_TYPE_HSDPA 405 * @see #NETWORK_TYPE_HSUPA 406 * @see #NETWORK_TYPE_HSPA 407 * @see #NETWORK_TYPE_CDMA 408 * @see #NETWORK_TYPE_EVDO_0 409 * @see #NETWORK_TYPE_EVDO_A 410 * @see #NETWORK_TYPE_1xRTT 411 */ 412 public int getNetworkType() { 413 try{ 414 ITelephony telephony = getITelephony(); 415 if (telephony != null) { 416 return telephony.getNetworkType(); 417 } else { 418 // This can happen when the ITelephony interface is not up yet. 419 return NETWORK_TYPE_UNKNOWN; 420 } 421 } catch(RemoteException ex){ 422 // This shouldn't happen in the normal case 423 return NETWORK_TYPE_UNKNOWN; 424 } 425 } 426 427 /** 428 * Returns a string representation of the radio technology (network type) 429 * currently in use on the device. 430 * @return the name of the radio technology 431 * 432 * @hide pending API council review 433 */ 434 public String getNetworkTypeName() { 435 switch (getNetworkType()) { 436 case NETWORK_TYPE_GPRS: 437 return "GPRS"; 438 case NETWORK_TYPE_EDGE: 439 return "EDGE"; 440 case NETWORK_TYPE_UMTS: 441 return "UMTS"; 442 case NETWORK_TYPE_HSDPA: 443 return "HSDPA"; 444 case NETWORK_TYPE_HSUPA: 445 return "HSUPA"; 446 case NETWORK_TYPE_HSPA: 447 return "HSPA"; 448 case NETWORK_TYPE_CDMA: 449 return "CDMA"; 450 case NETWORK_TYPE_EVDO_0: 451 return "CDMA - EvDo rev. 0"; 452 case NETWORK_TYPE_EVDO_A: 453 return "CDMA - EvDo rev. A"; 454 case NETWORK_TYPE_1xRTT: 455 return "CDMA - 1xRTT"; 456 default: 457 return "UNKNOWN"; 458 } 459 } 460 461 // 462 // 463 // SIM Card 464 // 465 // 466 467 /** SIM card state: Unknown. Signifies that the SIM is in transition 468 * between states. For example, when the user inputs the SIM pin 469 * under PIN_REQUIRED state, a query for sim status returns 470 * this state before turning to SIM_STATE_READY. */ 471 public static final int SIM_STATE_UNKNOWN = 0; 472 /** SIM card state: no SIM card is available in the device */ 473 public static final int SIM_STATE_ABSENT = 1; 474 /** SIM card state: Locked: requires the user's SIM PIN to unlock */ 475 public static final int SIM_STATE_PIN_REQUIRED = 2; 476 /** SIM card state: Locked: requires the user's SIM PUK to unlock */ 477 public static final int SIM_STATE_PUK_REQUIRED = 3; 478 /** SIM card state: Locked: requries a network PIN to unlock */ 479 public static final int SIM_STATE_NETWORK_LOCKED = 4; 480 /** SIM card state: Ready */ 481 public static final int SIM_STATE_READY = 5; 482 483 /** 484 * @return true if a ICC card is present 485 */ 486 public boolean hasIccCard() { 487 return PhoneFactory.getDefaultPhone().getIccCard().hasIccCard(); 488 } 489 490 /** 491 * Returns a constant indicating the state of the 492 * device SIM card. 493 * 494 * @see #SIM_STATE_UNKNOWN 495 * @see #SIM_STATE_ABSENT 496 * @see #SIM_STATE_PIN_REQUIRED 497 * @see #SIM_STATE_PUK_REQUIRED 498 * @see #SIM_STATE_NETWORK_LOCKED 499 * @see #SIM_STATE_READY 500 */ 501 public int getSimState() { 502 String prop = SystemProperties.get(TelephonyProperties.PROPERTY_SIM_STATE); 503 if ("ABSENT".equals(prop)) { 504 return SIM_STATE_ABSENT; 505 } 506 else if ("PIN_REQUIRED".equals(prop)) { 507 return SIM_STATE_PIN_REQUIRED; 508 } 509 else if ("PUK_REQUIRED".equals(prop)) { 510 return SIM_STATE_PUK_REQUIRED; 511 } 512 else if ("NETWORK_LOCKED".equals(prop)) { 513 return SIM_STATE_NETWORK_LOCKED; 514 } 515 else if ("READY".equals(prop)) { 516 return SIM_STATE_READY; 517 } 518 else { 519 return SIM_STATE_UNKNOWN; 520 } 521 } 522 523 /** 524 * Returns the MCC+MNC (mobile country code + mobile network code) of the 525 * provider of the SIM. 5 or 6 decimal digits. 526 * <p> 527 * Availability: SIM state must be {@link #SIM_STATE_READY} 528 * 529 * @see #getSimState 530 */ 531 public String getSimOperator() { 532 return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC); 533 } 534 535 /** 536 * Returns the Service Provider Name (SPN). 537 * <p> 538 * Availability: SIM state must be {@link #SIM_STATE_READY} 539 * 540 * @see #getSimState 541 */ 542 public String getSimOperatorName() { 543 return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA); 544 } 545 546 /** 547 * Returns the ISO country code equivalent for the SIM provider's country code. 548 */ 549 public String getSimCountryIso() { 550 return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY); 551 } 552 553 /** 554 * Returns the serial number of the SIM, if applicable. 555 * <p> 556 * Requires Permission: 557 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 558 */ 559 public String getSimSerialNumber() { 560 try { 561 return getSubscriberInfo().getIccSerialNumber(); 562 } catch (RemoteException ex) { 563 } 564 return null; 565 } 566 567 // 568 // 569 // Subscriber Info 570 // 571 // 572 573 /** 574 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone. 575 * <p> 576 * Requires Permission: 577 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 578 */ 579 public String getSubscriberId() { 580 try { 581 return getSubscriberInfo().getSubscriberId(); 582 } catch (RemoteException ex) { 583 } 584 return null; 585 } 586 587 /** 588 * Returns the phone number string for line 1, for example, the MSISDN 589 * for a GSM phone. 590 * <p> 591 * Requires Permission: 592 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 593 */ 594 public String getLine1Number() { 595 try { 596 return getSubscriberInfo().getLine1Number(); 597 } catch (RemoteException ex) { 598 } 599 return null; 600 } 601 602 /** 603 * Returns the alphabetic identifier associated with the line 1 number. 604 * <p> 605 * Requires Permission: 606 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 607 * @hide 608 * nobody seems to call this. 609 */ 610 public String getLine1AlphaTag() { 611 try { 612 return getSubscriberInfo().getLine1AlphaTag(); 613 } catch (RemoteException ex) { 614 } 615 return null; 616 } 617 618 /** 619 * Returns the voice mail number. 620 * <p> 621 * Requires Permission: 622 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 623 */ 624 public String getVoiceMailNumber() { 625 try { 626 return getSubscriberInfo().getVoiceMailNumber(); 627 } catch (RemoteException ex) { 628 } 629 return null; 630 } 631 632 /** 633 * Returns the voice mail count. 634 * <p> 635 * Requires Permission: 636 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 637 * @hide 638 */ 639 public int getVoiceMessageCount() { 640 try { 641 return getITelephony().getVoiceMessageCount(); 642 } catch (RemoteException ex) { 643 } 644 return 0; 645 } 646 647 /** 648 * Retrieves the alphabetic identifier associated with the voice 649 * mail number. 650 * <p> 651 * Requires Permission: 652 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 653 */ 654 public String getVoiceMailAlphaTag() { 655 try { 656 return getSubscriberInfo().getVoiceMailAlphaTag(); 657 } catch (RemoteException ex) { 658 } 659 return null; 660 } 661 662 private IPhoneSubInfo getSubscriberInfo() { 663 // get it each time because that process crashes a lot 664 return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo")); 665 } 666 667 668 /** Device call state: No activity. */ 669 public static final int CALL_STATE_IDLE = 0; 670 /** Device call state: Ringing. A new call arrived and is 671 * ringing or waiting. In the latter case, another call is 672 * already active. */ 673 public static final int CALL_STATE_RINGING = 1; 674 /** Device call state: Off-hook. At least one call exists 675 * that is dialing, active, or on hold, and no calls are ringing 676 * or waiting. */ 677 public static final int CALL_STATE_OFFHOOK = 2; 678 679 /** 680 * Returns a constant indicating the call state (cellular) on the device. 681 */ 682 public int getCallState() { 683 try { 684 return getITelephony().getCallState(); 685 } catch (RemoteException ex) { 686 // the phone process is restarting. 687 return CALL_STATE_IDLE; 688 } catch (NullPointerException ex) { 689 // the phone process is restarting. 690 return CALL_STATE_IDLE; 691 } 692 } 693 694 /** Data connection activity: No traffic. */ 695 public static final int DATA_ACTIVITY_NONE = 0x00000000; 696 /** Data connection activity: Currently receiving IP PPP traffic. */ 697 public static final int DATA_ACTIVITY_IN = 0x00000001; 698 /** Data connection activity: Currently sending IP PPP traffic. */ 699 public static final int DATA_ACTIVITY_OUT = 0x00000002; 700 /** Data connection activity: Currently both sending and receiving 701 * IP PPP traffic. */ 702 public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT; 703 /** 704 * Data connection is active, but physical link is down 705 * @hide 706 */ 707 public static final int DATA_ACTIVITY_DORMANT = 0x00000004; 708 709 /** 710 * Returns a constant indicating the type of activity on a data connection 711 * (cellular). 712 * 713 * @see #DATA_ACTIVITY_NONE 714 * @see #DATA_ACTIVITY_IN 715 * @see #DATA_ACTIVITY_OUT 716 * @see #DATA_ACTIVITY_INOUT 717 * @see #DATA_ACTIVITY_DORMANT 718 */ 719 public int getDataActivity() { 720 try { 721 return getITelephony().getDataActivity(); 722 } catch (RemoteException ex) { 723 // the phone process is restarting. 724 return DATA_ACTIVITY_NONE; 725 } catch (NullPointerException ex) { 726 // the phone process is restarting. 727 return DATA_ACTIVITY_NONE; 728 } 729 } 730 731 /** Data connection state: Disconnected. IP traffic not available. */ 732 public static final int DATA_DISCONNECTED = 0; 733 /** Data connection state: Currently setting up a data connection. */ 734 public static final int DATA_CONNECTING = 1; 735 /** Data connection state: Connected. IP traffic should be available. */ 736 public static final int DATA_CONNECTED = 2; 737 /** Data connection state: Suspended. The connection is up, but IP 738 * traffic is temporarily unavailable. For example, in a 2G network, 739 * data activity may be suspended when a voice call arrives. */ 740 public static final int DATA_SUSPENDED = 3; 741 742 /** 743 * Returns a constant indicating the current data connection state 744 * (cellular). 745 * 746 * @see #DATA_DISCONNECTED 747 * @see #DATA_CONNECTING 748 * @see #DATA_CONNECTED 749 * @see #DATA_SUSPENDED 750 */ 751 public int getDataState() { 752 try { 753 return getITelephony().getDataState(); 754 } catch (RemoteException ex) { 755 // the phone process is restarting. 756 return DATA_DISCONNECTED; 757 } 758 } 759 760 private ITelephony getITelephony() { 761 return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); 762 } 763 764 // 765 // 766 // PhoneStateListener 767 // 768 // 769 770 /** 771 * Registers a listener object to receive notification of changes 772 * in specified telephony states. 773 * <p> 774 * To register a listener, pass a {@link PhoneStateListener} 775 * and specify at least one telephony state of interest in 776 * the events argument. 777 * 778 * At registration, and when a specified telephony state 779 * changes, the telephony manager invokes the appropriate 780 * callback method on the listener object and passes the 781 * current (udpated) values. 782 * <p> 783 * To unregister a listener, pass the listener object and set the 784 * events argument to 785 * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0). 786 * 787 * @param listener The {@link PhoneStateListener} object to register 788 * (or unregister) 789 * @param events The telephony state(s) of interest to the listener, 790 * as a bitwise-OR combination of {@link PhoneStateListener} 791 * LISTEN_ flags. 792 */ 793 public void listen(PhoneStateListener listener, int events) { 794 String pkgForDebug = mContext != null ? mContext.getPackageName() : "<unknown>"; 795 try { 796 Boolean notifyNow = (getITelephony() != null); 797 mRegistry.listen(pkgForDebug, listener.callback, events, notifyNow); 798 } catch (RemoteException ex) { 799 // system process dead 800 } 801 } 802 803 /** 804 * Returns the CDMA ERI icon index to display 805 * 806 * @hide 807 */ 808 public int getCdmaEriIconIndex() { 809 try { 810 return getITelephony().getCdmaEriIconIndex(); 811 } catch (RemoteException ex) { 812 // the phone process is restarting. 813 return -1; 814 } 815 } 816 817 /** 818 * Returns the CDMA ERI icon mode, 819 * 0 - ON 820 * 1 - FLASHING 821 * 822 * @hide 823 */ 824 public int getCdmaEriIconMode() { 825 try { 826 return getITelephony().getCdmaEriIconMode(); 827 } catch (RemoteException ex) { 828 // the phone process is restarting. 829 return -1; 830 } 831 } 832 833 /** 834 * Returns the CDMA ERI text, 835 * 836 * @hide 837 */ 838 public String getCdmaEriText() { 839 try { 840 return getITelephony().getCdmaEriText(); 841 } catch (RemoteException ex) { 842 // the phone process is restarting. 843 return null; 844 } 845 } 846} 847