TelephonyManager.java revision f099a5f389a43a1a1f0abc6577e45c7dfca14c5c
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; 26import android.telephony.Rlog; 27 28import com.android.internal.telephony.IPhoneSubInfo; 29import com.android.internal.telephony.ITelephony; 30import com.android.internal.telephony.ITelephonyRegistry; 31import com.android.internal.telephony.PhoneConstants; 32import com.android.internal.telephony.RILConstants; 33import com.android.internal.telephony.TelephonyProperties; 34 35import java.io.FileInputStream; 36import java.io.IOException; 37import java.util.List; 38import java.util.regex.Matcher; 39import java.util.regex.Pattern; 40 41/** 42 * Provides access to information about the telephony services on 43 * the device. Applications can use the methods in this class to 44 * determine telephony services and states, as well as to access some 45 * types of subscriber information. Applications can also register 46 * a listener to receive notification of telephony state changes. 47 * <p> 48 * You do not instantiate this class directly; instead, you retrieve 49 * a reference to an instance through 50 * {@link android.content.Context#getSystemService 51 * Context.getSystemService(Context.TELEPHONY_SERVICE)}. 52 * <p> 53 * Note that access to some telephony information is 54 * permission-protected. Your application cannot access the protected 55 * information unless it has the appropriate permissions declared in 56 * its manifest file. Where permissions apply, they are noted in the 57 * the methods through which you access the protected information. 58 */ 59public class TelephonyManager { 60 private static final String TAG = "TelephonyManager"; 61 62 private static ITelephonyRegistry sRegistry; 63 private final Context mContext; 64 65 /** @hide */ 66 public TelephonyManager(Context context) { 67 Context appContext = context.getApplicationContext(); 68 if (appContext != null) { 69 mContext = appContext; 70 } else { 71 mContext = context; 72 } 73 74 if (sRegistry == null) { 75 sRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService( 76 "telephony.registry")); 77 } 78 } 79 80 /** @hide */ 81 private TelephonyManager() { 82 mContext = null; 83 } 84 85 private static TelephonyManager sInstance = new TelephonyManager(); 86 87 /** @hide 88 /* @deprecated - use getSystemService as described above */ 89 public static TelephonyManager getDefault() { 90 return sInstance; 91 } 92 93 /** {@hide} */ 94 public static TelephonyManager from(Context context) { 95 return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 96 } 97 98 // 99 // Broadcast Intent actions 100 // 101 102 /** 103 * Broadcast intent action indicating that the call state (cellular) 104 * on the device has changed. 105 * 106 * <p> 107 * The {@link #EXTRA_STATE} extra indicates the new call state. 108 * If the new state is RINGING, a second extra 109 * {@link #EXTRA_INCOMING_NUMBER} provides the incoming phone number as 110 * a String. 111 * 112 * <p class="note"> 113 * Requires the READ_PHONE_STATE permission. 114 * 115 * <p class="note"> 116 * This was a {@link android.content.Context#sendStickyBroadcast sticky} 117 * broadcast in version 1.0, but it is no longer sticky. 118 * Instead, use {@link #getCallState} to synchronously query the current call state. 119 * 120 * @see #EXTRA_STATE 121 * @see #EXTRA_INCOMING_NUMBER 122 * @see #getCallState 123 */ 124 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 125 public static final String ACTION_PHONE_STATE_CHANGED = 126 "android.intent.action.PHONE_STATE"; 127 128 /** 129 * The Phone app sends this intent when a user opts to respond-via-message during an incoming 130 * call. By default, the device's default SMS app consumes this message and sends a text message 131 * to the caller. A third party app can also provide this functionality by consuming this Intent 132 * with a {@link android.app.Service} and sending the message using its own messaging system. 133 * <p>The intent contains a URI (available from {@link android.content.Intent#getData}) 134 * describing the recipient, using either the {@code sms:}, {@code smsto:}, {@code mms:}, 135 * or {@code mmsto:} URI schema. Each of these URI schema carry the recipient information the 136 * same way: the path part of the URI contains the recipient's phone number or a comma-separated 137 * set of phone numbers if there are multiple recipients. For example, {@code 138 * smsto:2065551234}.</p> 139 * 140 * <p>The intent may also contain extras for the message text (in {@link 141 * android.content.Intent#EXTRA_TEXT}) and a message subject 142 * (in {@link android.content.Intent#EXTRA_SUBJECT}).</p> 143 * 144 * <p class="note"><strong>Note:</strong> 145 * The intent-filter that consumes this Intent needs to be in a {@link android.app.Service} 146 * that requires the 147 * permission {@link android.Manifest.permission#SEND_RESPOND_VIA_MESSAGE}.</p> 148 * <p>For example, the service that receives this intent can be declared in the manifest file 149 * with an intent filter like this:</p> 150 * <pre> 151 * <!-- Service that delivers SMS messages received from the phone "quick response" --> 152 * <service android:name=".HeadlessSmsSendService" 153 * android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE" 154 * android:exported="true" > 155 * <intent-filter> 156 * <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" /> 157 * <category android:name="android.intent.category.DEFAULT" /> 158 * <data android:scheme="sms" /> 159 * <data android:scheme="smsto" /> 160 * <data android:scheme="mms" /> 161 * <data android:scheme="mmsto" /> 162 * </intent-filter> 163 * </service></pre> 164 * <p> 165 * Output: nothing. 166 */ 167 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 168 public static final String ACTION_RESPOND_VIA_MESSAGE = 169 "android.intent.action.RESPOND_VIA_MESSAGE"; 170 171 /** 172 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 173 * for a String containing the new call state. 174 * 175 * @see #EXTRA_STATE_IDLE 176 * @see #EXTRA_STATE_RINGING 177 * @see #EXTRA_STATE_OFFHOOK 178 * 179 * <p class="note"> 180 * Retrieve with 181 * {@link android.content.Intent#getStringExtra(String)}. 182 */ 183 public static final String EXTRA_STATE = PhoneConstants.STATE_KEY; 184 185 /** 186 * Value used with {@link #EXTRA_STATE} corresponding to 187 * {@link #CALL_STATE_IDLE}. 188 */ 189 public static final String EXTRA_STATE_IDLE = PhoneConstants.State.IDLE.toString(); 190 191 /** 192 * Value used with {@link #EXTRA_STATE} corresponding to 193 * {@link #CALL_STATE_RINGING}. 194 */ 195 public static final String EXTRA_STATE_RINGING = PhoneConstants.State.RINGING.toString(); 196 197 /** 198 * Value used with {@link #EXTRA_STATE} corresponding to 199 * {@link #CALL_STATE_OFFHOOK}. 200 */ 201 public static final String EXTRA_STATE_OFFHOOK = PhoneConstants.State.OFFHOOK.toString(); 202 203 /** 204 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 205 * for a String containing the incoming phone number. 206 * Only valid when the new call state is RINGING. 207 * 208 * <p class="note"> 209 * Retrieve with 210 * {@link android.content.Intent#getStringExtra(String)}. 211 */ 212 public static final String EXTRA_INCOMING_NUMBER = "incoming_number"; 213 214 215 // 216 // 217 // Device Info 218 // 219 // 220 221 /** 222 * Returns the software version number for the device, for example, 223 * the IMEI/SV for GSM phones. Return null if the software version is 224 * not available. 225 * 226 * <p>Requires Permission: 227 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 228 */ 229 public String getDeviceSoftwareVersion() { 230 try { 231 return getSubscriberInfo().getDeviceSvn(); 232 } catch (RemoteException ex) { 233 return null; 234 } catch (NullPointerException ex) { 235 return null; 236 } 237 } 238 239 /** 240 * Returns the unique device ID, for example, the IMEI for GSM and the MEID 241 * or ESN for CDMA phones. Return null if device ID is not available. 242 * 243 * <p>Requires Permission: 244 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 245 */ 246 public String getDeviceId() { 247 try { 248 return getSubscriberInfo().getDeviceId(); 249 } catch (RemoteException ex) { 250 return null; 251 } catch (NullPointerException ex) { 252 return null; 253 } 254 } 255 256 /** 257 * Returns the current location of the device. 258 *<p> 259 * If there is only one radio in the device and that radio has an LTE connection, 260 * this method will return null. The implementation must not to try add LTE 261 * identifiers into the existing cdma/gsm classes. 262 *<p> 263 * In the future this call will be deprecated. 264 *<p> 265 * @return Current location of the device or null if not available. 266 * 267 * <p>Requires Permission: 268 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or 269 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION}. 270 */ 271 public CellLocation getCellLocation() { 272 try { 273 Bundle bundle = getITelephony().getCellLocation(); 274 if (bundle.isEmpty()) return null; 275 CellLocation cl = CellLocation.newFromBundle(bundle); 276 if (cl.isEmpty()) 277 return null; 278 return cl; 279 } catch (RemoteException ex) { 280 return null; 281 } catch (NullPointerException ex) { 282 return null; 283 } 284 } 285 286 /** 287 * Enables location update notifications. {@link PhoneStateListener#onCellLocationChanged 288 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 289 * 290 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 291 * CONTROL_LOCATION_UPDATES} 292 * 293 * @hide 294 */ 295 public void enableLocationUpdates() { 296 try { 297 getITelephony().enableLocationUpdates(); 298 } catch (RemoteException ex) { 299 } catch (NullPointerException ex) { 300 } 301 } 302 303 /** 304 * Disables location update notifications. {@link PhoneStateListener#onCellLocationChanged 305 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 306 * 307 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 308 * CONTROL_LOCATION_UPDATES} 309 * 310 * @hide 311 */ 312 public void disableLocationUpdates() { 313 try { 314 getITelephony().disableLocationUpdates(); 315 } catch (RemoteException ex) { 316 } catch (NullPointerException ex) { 317 } 318 } 319 320 /** 321 * Returns the neighboring cell information of the device. The getAllCellInfo is preferred 322 * and use this only if getAllCellInfo return nulls or an empty list. 323 *<p> 324 * In the future this call will be deprecated. 325 *<p> 326 * @return List of NeighboringCellInfo or null if info unavailable. 327 * 328 * <p>Requires Permission: 329 * (@link android.Manifest.permission#ACCESS_COARSE_UPDATES} 330 */ 331 public List<NeighboringCellInfo> getNeighboringCellInfo() { 332 try { 333 return getITelephony().getNeighboringCellInfo(mContext.getOpPackageName()); 334 } catch (RemoteException ex) { 335 return null; 336 } catch (NullPointerException ex) { 337 return null; 338 } 339 } 340 341 /** No phone radio. */ 342 public static final int PHONE_TYPE_NONE = PhoneConstants.PHONE_TYPE_NONE; 343 /** Phone radio is GSM. */ 344 public static final int PHONE_TYPE_GSM = PhoneConstants.PHONE_TYPE_GSM; 345 /** Phone radio is CDMA. */ 346 public static final int PHONE_TYPE_CDMA = PhoneConstants.PHONE_TYPE_CDMA; 347 /** Phone is via SIP. */ 348 public static final int PHONE_TYPE_SIP = PhoneConstants.PHONE_TYPE_SIP; 349 350 /** 351 * Returns the current phone type. 352 * TODO: This is a last minute change and hence hidden. 353 * 354 * @see #PHONE_TYPE_NONE 355 * @see #PHONE_TYPE_GSM 356 * @see #PHONE_TYPE_CDMA 357 * @see #PHONE_TYPE_SIP 358 * 359 * {@hide} 360 */ 361 public int getCurrentPhoneType() { 362 try{ 363 ITelephony telephony = getITelephony(); 364 if (telephony != null) { 365 return telephony.getActivePhoneType(); 366 } else { 367 // This can happen when the ITelephony interface is not up yet. 368 return getPhoneTypeFromProperty(); 369 } 370 } catch (RemoteException ex) { 371 // This shouldn't happen in the normal case, as a backup we 372 // read from the system property. 373 return getPhoneTypeFromProperty(); 374 } catch (NullPointerException ex) { 375 // This shouldn't happen in the normal case, as a backup we 376 // read from the system property. 377 return getPhoneTypeFromProperty(); 378 } 379 } 380 381 /** 382 * Returns a constant indicating the device phone type. This 383 * indicates the type of radio used to transmit voice calls. 384 * 385 * @see #PHONE_TYPE_NONE 386 * @see #PHONE_TYPE_GSM 387 * @see #PHONE_TYPE_CDMA 388 * @see #PHONE_TYPE_SIP 389 */ 390 public int getPhoneType() { 391 if (!isVoiceCapable()) { 392 return PHONE_TYPE_NONE; 393 } 394 return getCurrentPhoneType(); 395 } 396 397 private int getPhoneTypeFromProperty() { 398 int type = 399 SystemProperties.getInt(TelephonyProperties.CURRENT_ACTIVE_PHONE, 400 getPhoneTypeFromNetworkType()); 401 return type; 402 } 403 404 private int getPhoneTypeFromNetworkType() { 405 // When the system property CURRENT_ACTIVE_PHONE, has not been set, 406 // use the system property for default network type. 407 // This is a fail safe, and can only happen at first boot. 408 int mode = SystemProperties.getInt("ro.telephony.default_network", -1); 409 if (mode == -1) 410 return PHONE_TYPE_NONE; 411 return getPhoneType(mode); 412 } 413 414 /** 415 * This function returns the type of the phone, depending 416 * on the network mode. 417 * 418 * @param networkMode 419 * @return Phone Type 420 * 421 * @hide 422 */ 423 public static int getPhoneType(int networkMode) { 424 switch(networkMode) { 425 case RILConstants.NETWORK_MODE_CDMA: 426 case RILConstants.NETWORK_MODE_CDMA_NO_EVDO: 427 case RILConstants.NETWORK_MODE_EVDO_NO_CDMA: 428 return PhoneConstants.PHONE_TYPE_CDMA; 429 430 case RILConstants.NETWORK_MODE_WCDMA_PREF: 431 case RILConstants.NETWORK_MODE_GSM_ONLY: 432 case RILConstants.NETWORK_MODE_WCDMA_ONLY: 433 case RILConstants.NETWORK_MODE_GSM_UMTS: 434 case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA: 435 case RILConstants.NETWORK_MODE_LTE_WCDMA: 436 case RILConstants.NETWORK_MODE_LTE_CMDA_EVDO_GSM_WCDMA: 437 return PhoneConstants.PHONE_TYPE_GSM; 438 439 // Use CDMA Phone for the global mode including CDMA 440 case RILConstants.NETWORK_MODE_GLOBAL: 441 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO: 442 return PhoneConstants.PHONE_TYPE_CDMA; 443 444 case RILConstants.NETWORK_MODE_LTE_ONLY: 445 if (getLteOnCdmaModeStatic() == PhoneConstants.LTE_ON_CDMA_TRUE) { 446 return PhoneConstants.PHONE_TYPE_CDMA; 447 } else { 448 return PhoneConstants.PHONE_TYPE_GSM; 449 } 450 default: 451 return PhoneConstants.PHONE_TYPE_GSM; 452 } 453 } 454 455 /** 456 * The contents of the /proc/cmdline file 457 */ 458 private static String getProcCmdLine() 459 { 460 String cmdline = ""; 461 FileInputStream is = null; 462 try { 463 is = new FileInputStream("/proc/cmdline"); 464 byte [] buffer = new byte[2048]; 465 int count = is.read(buffer); 466 if (count > 0) { 467 cmdline = new String(buffer, 0, count); 468 } 469 } catch (IOException e) { 470 Rlog.d(TAG, "No /proc/cmdline exception=" + e); 471 } finally { 472 if (is != null) { 473 try { 474 is.close(); 475 } catch (IOException e) { 476 } 477 } 478 } 479 Rlog.d(TAG, "/proc/cmdline=" + cmdline); 480 return cmdline; 481 } 482 483 /** Kernel command line */ 484 private static final String sKernelCmdLine = getProcCmdLine(); 485 486 /** Pattern for selecting the product type from the kernel command line */ 487 private static final Pattern sProductTypePattern = 488 Pattern.compile("\\sproduct_type\\s*=\\s*(\\w+)"); 489 490 /** The ProductType used for LTE on CDMA devices */ 491 private static final String sLteOnCdmaProductType = 492 SystemProperties.get(TelephonyProperties.PROPERTY_LTE_ON_CDMA_PRODUCT_TYPE, ""); 493 494 /** 495 * Return if the current radio is LTE on CDMA. This 496 * is a tri-state return value as for a period of time 497 * the mode may be unknown. 498 * 499 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 500 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 501 * 502 * @hide 503 */ 504 public static int getLteOnCdmaModeStatic() { 505 int retVal; 506 int curVal; 507 String productType = ""; 508 509 curVal = SystemProperties.getInt(TelephonyProperties.PROPERTY_LTE_ON_CDMA_DEVICE, 510 PhoneConstants.LTE_ON_CDMA_UNKNOWN); 511 retVal = curVal; 512 if (retVal == PhoneConstants.LTE_ON_CDMA_UNKNOWN) { 513 Matcher matcher = sProductTypePattern.matcher(sKernelCmdLine); 514 if (matcher.find()) { 515 productType = matcher.group(1); 516 if (sLteOnCdmaProductType.equals(productType)) { 517 retVal = PhoneConstants.LTE_ON_CDMA_TRUE; 518 } else { 519 retVal = PhoneConstants.LTE_ON_CDMA_FALSE; 520 } 521 } else { 522 retVal = PhoneConstants.LTE_ON_CDMA_FALSE; 523 } 524 } 525 526 Rlog.d(TAG, "getLteOnCdmaMode=" + retVal + " curVal=" + curVal + 527 " product_type='" + productType + 528 "' lteOnCdmaProductType='" + sLteOnCdmaProductType + "'"); 529 return retVal; 530 } 531 532 // 533 // 534 // Current Network 535 // 536 // 537 538 /** 539 * Returns the alphabetic name of current registered operator. 540 * <p> 541 * Availability: Only when user is registered to a network. Result may be 542 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 543 * on a CDMA network). 544 */ 545 public String getNetworkOperatorName() { 546 return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ALPHA); 547 } 548 549 /** 550 * Returns the numeric name (MCC+MNC) of current registered operator. 551 * <p> 552 * Availability: Only when user is registered to a network. Result may be 553 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 554 * on a CDMA network). 555 */ 556 public String getNetworkOperator() { 557 return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC); 558 } 559 560 /** 561 * Returns true if the device is considered roaming on the current 562 * network, for GSM purposes. 563 * <p> 564 * Availability: Only when user registered to a network. 565 */ 566 public boolean isNetworkRoaming() { 567 return "true".equals(SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ISROAMING)); 568 } 569 570 /** 571 * Returns the ISO country code equivalent of the current registered 572 * operator's MCC (Mobile Country Code). 573 * <p> 574 * Availability: Only when user is registered to a network. Result may be 575 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 576 * on a CDMA network). 577 */ 578 public String getNetworkCountryIso() { 579 return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY); 580 } 581 582 /** Network type is unknown */ 583 public static final int NETWORK_TYPE_UNKNOWN = 0; 584 /** Current network is GPRS */ 585 public static final int NETWORK_TYPE_GPRS = 1; 586 /** Current network is EDGE */ 587 public static final int NETWORK_TYPE_EDGE = 2; 588 /** Current network is UMTS */ 589 public static final int NETWORK_TYPE_UMTS = 3; 590 /** Current network is CDMA: Either IS95A or IS95B*/ 591 public static final int NETWORK_TYPE_CDMA = 4; 592 /** Current network is EVDO revision 0*/ 593 public static final int NETWORK_TYPE_EVDO_0 = 5; 594 /** Current network is EVDO revision A*/ 595 public static final int NETWORK_TYPE_EVDO_A = 6; 596 /** Current network is 1xRTT*/ 597 public static final int NETWORK_TYPE_1xRTT = 7; 598 /** Current network is HSDPA */ 599 public static final int NETWORK_TYPE_HSDPA = 8; 600 /** Current network is HSUPA */ 601 public static final int NETWORK_TYPE_HSUPA = 9; 602 /** Current network is HSPA */ 603 public static final int NETWORK_TYPE_HSPA = 10; 604 /** Current network is iDen */ 605 public static final int NETWORK_TYPE_IDEN = 11; 606 /** Current network is EVDO revision B*/ 607 public static final int NETWORK_TYPE_EVDO_B = 12; 608 /** Current network is LTE */ 609 public static final int NETWORK_TYPE_LTE = 13; 610 /** Current network is eHRPD */ 611 public static final int NETWORK_TYPE_EHRPD = 14; 612 /** Current network is HSPA+ */ 613 public static final int NETWORK_TYPE_HSPAP = 15; 614 615 /** 616 * @return the NETWORK_TYPE_xxxx for current data connection. 617 */ 618 public int getNetworkType() { 619 return getDataNetworkType(); 620 } 621 622 /** 623 * Returns a constant indicating the radio technology (network type) 624 * currently in use on the device for data transmission. 625 * @return the network type 626 * 627 * @see #NETWORK_TYPE_UNKNOWN 628 * @see #NETWORK_TYPE_GPRS 629 * @see #NETWORK_TYPE_EDGE 630 * @see #NETWORK_TYPE_UMTS 631 * @see #NETWORK_TYPE_HSDPA 632 * @see #NETWORK_TYPE_HSUPA 633 * @see #NETWORK_TYPE_HSPA 634 * @see #NETWORK_TYPE_CDMA 635 * @see #NETWORK_TYPE_EVDO_0 636 * @see #NETWORK_TYPE_EVDO_A 637 * @see #NETWORK_TYPE_EVDO_B 638 * @see #NETWORK_TYPE_1xRTT 639 * @see #NETWORK_TYPE_IDEN 640 * @see #NETWORK_TYPE_LTE 641 * @see #NETWORK_TYPE_EHRPD 642 * @see #NETWORK_TYPE_HSPAP 643 * 644 * @hide 645 */ 646 public int getDataNetworkType() { 647 try{ 648 ITelephony telephony = getITelephony(); 649 if (telephony != null) { 650 return telephony.getDataNetworkType(); 651 } else { 652 // This can happen when the ITelephony interface is not up yet. 653 return NETWORK_TYPE_UNKNOWN; 654 } 655 } catch(RemoteException ex) { 656 // This shouldn't happen in the normal case 657 return NETWORK_TYPE_UNKNOWN; 658 } catch (NullPointerException ex) { 659 // This could happen before phone restarts due to crashing 660 return NETWORK_TYPE_UNKNOWN; 661 } 662 } 663 664 /** 665 * Returns the NETWORK_TYPE_xxxx for voice 666 * 667 * @hide 668 */ 669 public int getVoiceNetworkType() { 670 try{ 671 ITelephony telephony = getITelephony(); 672 if (telephony != null) { 673 return telephony.getVoiceNetworkType(); 674 } else { 675 // This can happen when the ITelephony interface is not up yet. 676 return NETWORK_TYPE_UNKNOWN; 677 } 678 } catch(RemoteException ex) { 679 // This shouldn't happen in the normal case 680 return NETWORK_TYPE_UNKNOWN; 681 } catch (NullPointerException ex) { 682 // This could happen before phone restarts due to crashing 683 return NETWORK_TYPE_UNKNOWN; 684 } 685 } 686 687 /** Unknown network class. {@hide} */ 688 public static final int NETWORK_CLASS_UNKNOWN = 0; 689 /** Class of broadly defined "2G" networks. {@hide} */ 690 public static final int NETWORK_CLASS_2_G = 1; 691 /** Class of broadly defined "3G" networks. {@hide} */ 692 public static final int NETWORK_CLASS_3_G = 2; 693 /** Class of broadly defined "4G" networks. {@hide} */ 694 public static final int NETWORK_CLASS_4_G = 3; 695 696 /** 697 * Return general class of network type, such as "3G" or "4G". In cases 698 * where classification is contentious, this method is conservative. 699 * 700 * @hide 701 */ 702 public static int getNetworkClass(int networkType) { 703 switch (networkType) { 704 case NETWORK_TYPE_GPRS: 705 case NETWORK_TYPE_EDGE: 706 case NETWORK_TYPE_CDMA: 707 case NETWORK_TYPE_1xRTT: 708 case NETWORK_TYPE_IDEN: 709 return NETWORK_CLASS_2_G; 710 case NETWORK_TYPE_UMTS: 711 case NETWORK_TYPE_EVDO_0: 712 case NETWORK_TYPE_EVDO_A: 713 case NETWORK_TYPE_HSDPA: 714 case NETWORK_TYPE_HSUPA: 715 case NETWORK_TYPE_HSPA: 716 case NETWORK_TYPE_EVDO_B: 717 case NETWORK_TYPE_EHRPD: 718 case NETWORK_TYPE_HSPAP: 719 return NETWORK_CLASS_3_G; 720 case NETWORK_TYPE_LTE: 721 return NETWORK_CLASS_4_G; 722 default: 723 return NETWORK_CLASS_UNKNOWN; 724 } 725 } 726 727 /** 728 * Returns a string representation of the radio technology (network type) 729 * currently in use on the device. 730 * @return the name of the radio technology 731 * 732 * @hide pending API council review 733 */ 734 public String getNetworkTypeName() { 735 return getNetworkTypeName(getNetworkType()); 736 } 737 738 /** {@hide} */ 739 public static String getNetworkTypeName(int type) { 740 switch (type) { 741 case NETWORK_TYPE_GPRS: 742 return "GPRS"; 743 case NETWORK_TYPE_EDGE: 744 return "EDGE"; 745 case NETWORK_TYPE_UMTS: 746 return "UMTS"; 747 case NETWORK_TYPE_HSDPA: 748 return "HSDPA"; 749 case NETWORK_TYPE_HSUPA: 750 return "HSUPA"; 751 case NETWORK_TYPE_HSPA: 752 return "HSPA"; 753 case NETWORK_TYPE_CDMA: 754 return "CDMA"; 755 case NETWORK_TYPE_EVDO_0: 756 return "CDMA - EvDo rev. 0"; 757 case NETWORK_TYPE_EVDO_A: 758 return "CDMA - EvDo rev. A"; 759 case NETWORK_TYPE_EVDO_B: 760 return "CDMA - EvDo rev. B"; 761 case NETWORK_TYPE_1xRTT: 762 return "CDMA - 1xRTT"; 763 case NETWORK_TYPE_LTE: 764 return "LTE"; 765 case NETWORK_TYPE_EHRPD: 766 return "CDMA - eHRPD"; 767 case NETWORK_TYPE_IDEN: 768 return "iDEN"; 769 case NETWORK_TYPE_HSPAP: 770 return "HSPA+"; 771 default: 772 return "UNKNOWN"; 773 } 774 } 775 776 // 777 // 778 // SIM Card 779 // 780 // 781 782 /** SIM card state: Unknown. Signifies that the SIM is in transition 783 * between states. For example, when the user inputs the SIM pin 784 * under PIN_REQUIRED state, a query for sim status returns 785 * this state before turning to SIM_STATE_READY. */ 786 public static final int SIM_STATE_UNKNOWN = 0; 787 /** SIM card state: no SIM card is available in the device */ 788 public static final int SIM_STATE_ABSENT = 1; 789 /** SIM card state: Locked: requires the user's SIM PIN to unlock */ 790 public static final int SIM_STATE_PIN_REQUIRED = 2; 791 /** SIM card state: Locked: requires the user's SIM PUK to unlock */ 792 public static final int SIM_STATE_PUK_REQUIRED = 3; 793 /** SIM card state: Locked: requries a network PIN to unlock */ 794 public static final int SIM_STATE_NETWORK_LOCKED = 4; 795 /** SIM card state: Ready */ 796 public static final int SIM_STATE_READY = 5; 797 /** SIM card state: SIM Card Error, Sim Card is present but faulty 798 *@hide 799 */ 800 public static final int SIM_STATE_CARD_IO_ERROR = 6; 801 802 /** 803 * @return true if a ICC card is present 804 */ 805 public boolean hasIccCard() { 806 try { 807 return getITelephony().hasIccCard(); 808 } catch (RemoteException ex) { 809 // Assume no ICC card if remote exception which shouldn't happen 810 return false; 811 } catch (NullPointerException ex) { 812 // This could happen before phone restarts due to crashing 813 return false; 814 } 815 } 816 817 /** 818 * Returns a constant indicating the state of the 819 * device SIM card. 820 * 821 * @see #SIM_STATE_UNKNOWN 822 * @see #SIM_STATE_ABSENT 823 * @see #SIM_STATE_PIN_REQUIRED 824 * @see #SIM_STATE_PUK_REQUIRED 825 * @see #SIM_STATE_NETWORK_LOCKED 826 * @see #SIM_STATE_READY 827 * @see #SIM_STATE_CARD_IO_ERROR 828 */ 829 public int getSimState() { 830 String prop = SystemProperties.get(TelephonyProperties.PROPERTY_SIM_STATE); 831 if ("ABSENT".equals(prop)) { 832 return SIM_STATE_ABSENT; 833 } 834 else if ("PIN_REQUIRED".equals(prop)) { 835 return SIM_STATE_PIN_REQUIRED; 836 } 837 else if ("PUK_REQUIRED".equals(prop)) { 838 return SIM_STATE_PUK_REQUIRED; 839 } 840 else if ("NETWORK_LOCKED".equals(prop)) { 841 return SIM_STATE_NETWORK_LOCKED; 842 } 843 else if ("READY".equals(prop)) { 844 return SIM_STATE_READY; 845 } 846 else if ("CARD_IO_ERROR".equals(prop)) { 847 return SIM_STATE_CARD_IO_ERROR; 848 } 849 else { 850 return SIM_STATE_UNKNOWN; 851 } 852 } 853 854 /** 855 * Returns the MCC+MNC (mobile country code + mobile network code) of the 856 * provider of the SIM. 5 or 6 decimal digits. 857 * <p> 858 * Availability: SIM state must be {@link #SIM_STATE_READY} 859 * 860 * @see #getSimState 861 */ 862 public String getSimOperator() { 863 return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC); 864 } 865 866 /** 867 * Returns the Service Provider Name (SPN). 868 * <p> 869 * Availability: SIM state must be {@link #SIM_STATE_READY} 870 * 871 * @see #getSimState 872 */ 873 public String getSimOperatorName() { 874 return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA); 875 } 876 877 /** 878 * Returns the ISO country code equivalent for the SIM provider's country code. 879 */ 880 public String getSimCountryIso() { 881 return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY); 882 } 883 884 /** 885 * Returns the serial number of the SIM, if applicable. Return null if it is 886 * unavailable. 887 * <p> 888 * Requires Permission: 889 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 890 */ 891 public String getSimSerialNumber() { 892 try { 893 return getSubscriberInfo().getIccSerialNumber(); 894 } catch (RemoteException ex) { 895 return null; 896 } catch (NullPointerException ex) { 897 // This could happen before phone restarts due to crashing 898 return null; 899 } 900 } 901 902 /** 903 * Return if the current radio is LTE on CDMA. This 904 * is a tri-state return value as for a period of time 905 * the mode may be unknown. 906 * 907 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 908 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 909 * 910 * @hide 911 */ 912 public int getLteOnCdmaMode() { 913 try { 914 return getITelephony().getLteOnCdmaMode(); 915 } catch (RemoteException ex) { 916 // Assume no ICC card if remote exception which shouldn't happen 917 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 918 } catch (NullPointerException ex) { 919 // This could happen before phone restarts due to crashing 920 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 921 } 922 } 923 924 // 925 // 926 // Subscriber Info 927 // 928 // 929 930 /** 931 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone. 932 * Return null if it is unavailable. 933 * <p> 934 * Requires Permission: 935 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 936 */ 937 public String getSubscriberId() { 938 try { 939 return getSubscriberInfo().getSubscriberId(); 940 } catch (RemoteException ex) { 941 return null; 942 } catch (NullPointerException ex) { 943 // This could happen before phone restarts due to crashing 944 return null; 945 } 946 } 947 948 /** 949 * Returns the Group Identifier Level1 for a GSM phone. 950 * Return null if it is unavailable. 951 * <p> 952 * Requires Permission: 953 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 954 */ 955 public String getGroupIdLevel1() { 956 try { 957 return getSubscriberInfo().getGroupIdLevel1(); 958 } catch (RemoteException ex) { 959 return null; 960 } catch (NullPointerException ex) { 961 // This could happen before phone restarts due to crashing 962 return null; 963 } 964 } 965 966 /** 967 * Returns the phone number string for line 1, for example, the MSISDN 968 * for a GSM phone. Return null if it is unavailable. 969 * <p> 970 * Requires Permission: 971 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 972 */ 973 public String getLine1Number() { 974 try { 975 return getSubscriberInfo().getLine1Number(); 976 } catch (RemoteException ex) { 977 return null; 978 } catch (NullPointerException ex) { 979 // This could happen before phone restarts due to crashing 980 return null; 981 } 982 } 983 984 /** 985 * Returns the alphabetic identifier associated with the line 1 number. 986 * Return null if it is unavailable. 987 * <p> 988 * Requires Permission: 989 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 990 * @hide 991 * nobody seems to call this. 992 */ 993 public String getLine1AlphaTag() { 994 try { 995 return getSubscriberInfo().getLine1AlphaTag(); 996 } catch (RemoteException ex) { 997 return null; 998 } catch (NullPointerException ex) { 999 // This could happen before phone restarts due to crashing 1000 return null; 1001 } 1002 } 1003 1004 /** 1005 * Returns the MSISDN string. 1006 * for a GSM phone. Return null if it is unavailable. 1007 * <p> 1008 * Requires Permission: 1009 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1010 * 1011 * @hide 1012 */ 1013 public String getMsisdn() { 1014 try { 1015 return getSubscriberInfo().getMsisdn(); 1016 } catch (RemoteException ex) { 1017 return null; 1018 } catch (NullPointerException ex) { 1019 // This could happen before phone restarts due to crashing 1020 return null; 1021 } 1022 } 1023 1024 /** 1025 * Returns the voice mail number. Return null if it is unavailable. 1026 * <p> 1027 * Requires Permission: 1028 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1029 */ 1030 public String getVoiceMailNumber() { 1031 try { 1032 return getSubscriberInfo().getVoiceMailNumber(); 1033 } catch (RemoteException ex) { 1034 return null; 1035 } catch (NullPointerException ex) { 1036 // This could happen before phone restarts due to crashing 1037 return null; 1038 } 1039 } 1040 1041 /** 1042 * Returns the complete voice mail number. Return null if it is unavailable. 1043 * <p> 1044 * Requires Permission: 1045 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 1046 * 1047 * @hide 1048 */ 1049 public String getCompleteVoiceMailNumber() { 1050 try { 1051 return getSubscriberInfo().getCompleteVoiceMailNumber(); 1052 } catch (RemoteException ex) { 1053 return null; 1054 } catch (NullPointerException ex) { 1055 // This could happen before phone restarts due to crashing 1056 return null; 1057 } 1058 } 1059 1060 /** 1061 * Returns the voice mail count. Return 0 if unavailable. 1062 * <p> 1063 * Requires Permission: 1064 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1065 * @hide 1066 */ 1067 public int getVoiceMessageCount() { 1068 try { 1069 return getITelephony().getVoiceMessageCount(); 1070 } catch (RemoteException ex) { 1071 return 0; 1072 } catch (NullPointerException ex) { 1073 // This could happen before phone restarts due to crashing 1074 return 0; 1075 } 1076 } 1077 1078 /** 1079 * Retrieves the alphabetic identifier associated with the voice 1080 * mail number. 1081 * <p> 1082 * Requires Permission: 1083 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1084 */ 1085 public String getVoiceMailAlphaTag() { 1086 try { 1087 return getSubscriberInfo().getVoiceMailAlphaTag(); 1088 } catch (RemoteException ex) { 1089 return null; 1090 } catch (NullPointerException ex) { 1091 // This could happen before phone restarts due to crashing 1092 return null; 1093 } 1094 } 1095 1096 /** 1097 * Returns the IMS private user identity (IMPI) that was loaded from the ISIM. 1098 * @return the IMPI, or null if not present or not loaded 1099 * @hide 1100 */ 1101 public String getIsimImpi() { 1102 try { 1103 return getSubscriberInfo().getIsimImpi(); 1104 } catch (RemoteException ex) { 1105 return null; 1106 } catch (NullPointerException ex) { 1107 // This could happen before phone restarts due to crashing 1108 return null; 1109 } 1110 } 1111 1112 /** 1113 * Returns the IMS home network domain name that was loaded from the ISIM. 1114 * @return the IMS domain name, or null if not present or not loaded 1115 * @hide 1116 */ 1117 public String getIsimDomain() { 1118 try { 1119 return getSubscriberInfo().getIsimDomain(); 1120 } catch (RemoteException ex) { 1121 return null; 1122 } catch (NullPointerException ex) { 1123 // This could happen before phone restarts due to crashing 1124 return null; 1125 } 1126 } 1127 1128 /** 1129 * Returns the IMS public user identities (IMPU) that were loaded from the ISIM. 1130 * @return an array of IMPU strings, with one IMPU per string, or null if 1131 * not present or not loaded 1132 * @hide 1133 */ 1134 public String[] getIsimImpu() { 1135 try { 1136 return getSubscriberInfo().getIsimImpu(); 1137 } catch (RemoteException ex) { 1138 return null; 1139 } catch (NullPointerException ex) { 1140 // This could happen before phone restarts due to crashing 1141 return null; 1142 } 1143 } 1144 1145 private IPhoneSubInfo getSubscriberInfo() { 1146 // get it each time because that process crashes a lot 1147 return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo")); 1148 } 1149 1150 1151 /** Device call state: No activity. */ 1152 public static final int CALL_STATE_IDLE = 0; 1153 /** Device call state: Ringing. A new call arrived and is 1154 * ringing or waiting. In the latter case, another call is 1155 * already active. */ 1156 public static final int CALL_STATE_RINGING = 1; 1157 /** Device call state: Off-hook. At least one call exists 1158 * that is dialing, active, or on hold, and no calls are ringing 1159 * or waiting. */ 1160 public static final int CALL_STATE_OFFHOOK = 2; 1161 1162 /** 1163 * Returns a constant indicating the call state (cellular) on the device. 1164 */ 1165 public int getCallState() { 1166 try { 1167 return getITelephony().getCallState(); 1168 } catch (RemoteException ex) { 1169 // the phone process is restarting. 1170 return CALL_STATE_IDLE; 1171 } catch (NullPointerException ex) { 1172 // the phone process is restarting. 1173 return CALL_STATE_IDLE; 1174 } 1175 } 1176 1177 /** Data connection activity: No traffic. */ 1178 public static final int DATA_ACTIVITY_NONE = 0x00000000; 1179 /** Data connection activity: Currently receiving IP PPP traffic. */ 1180 public static final int DATA_ACTIVITY_IN = 0x00000001; 1181 /** Data connection activity: Currently sending IP PPP traffic. */ 1182 public static final int DATA_ACTIVITY_OUT = 0x00000002; 1183 /** Data connection activity: Currently both sending and receiving 1184 * IP PPP traffic. */ 1185 public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT; 1186 /** 1187 * Data connection is active, but physical link is down 1188 */ 1189 public static final int DATA_ACTIVITY_DORMANT = 0x00000004; 1190 1191 /** 1192 * Returns a constant indicating the type of activity on a data connection 1193 * (cellular). 1194 * 1195 * @see #DATA_ACTIVITY_NONE 1196 * @see #DATA_ACTIVITY_IN 1197 * @see #DATA_ACTIVITY_OUT 1198 * @see #DATA_ACTIVITY_INOUT 1199 * @see #DATA_ACTIVITY_DORMANT 1200 */ 1201 public int getDataActivity() { 1202 try { 1203 return getITelephony().getDataActivity(); 1204 } catch (RemoteException ex) { 1205 // the phone process is restarting. 1206 return DATA_ACTIVITY_NONE; 1207 } catch (NullPointerException ex) { 1208 // the phone process is restarting. 1209 return DATA_ACTIVITY_NONE; 1210 } 1211 } 1212 1213 /** Data connection state: Unknown. Used before we know the state. 1214 * @hide 1215 */ 1216 public static final int DATA_UNKNOWN = -1; 1217 /** Data connection state: Disconnected. IP traffic not available. */ 1218 public static final int DATA_DISCONNECTED = 0; 1219 /** Data connection state: Currently setting up a data connection. */ 1220 public static final int DATA_CONNECTING = 1; 1221 /** Data connection state: Connected. IP traffic should be available. */ 1222 public static final int DATA_CONNECTED = 2; 1223 /** Data connection state: Suspended. The connection is up, but IP 1224 * traffic is temporarily unavailable. For example, in a 2G network, 1225 * data activity may be suspended when a voice call arrives. */ 1226 public static final int DATA_SUSPENDED = 3; 1227 1228 /** 1229 * Returns a constant indicating the current data connection state 1230 * (cellular). 1231 * 1232 * @see #DATA_DISCONNECTED 1233 * @see #DATA_CONNECTING 1234 * @see #DATA_CONNECTED 1235 * @see #DATA_SUSPENDED 1236 */ 1237 public int getDataState() { 1238 try { 1239 return getITelephony().getDataState(); 1240 } catch (RemoteException ex) { 1241 // the phone process is restarting. 1242 return DATA_DISCONNECTED; 1243 } catch (NullPointerException ex) { 1244 return DATA_DISCONNECTED; 1245 } 1246 } 1247 1248 private ITelephony getITelephony() { 1249 return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); 1250 } 1251 1252 // 1253 // 1254 // PhoneStateListener 1255 // 1256 // 1257 1258 /** 1259 * Registers a listener object to receive notification of changes 1260 * in specified telephony states. 1261 * <p> 1262 * To register a listener, pass a {@link PhoneStateListener} 1263 * and specify at least one telephony state of interest in 1264 * the events argument. 1265 * 1266 * At registration, and when a specified telephony state 1267 * changes, the telephony manager invokes the appropriate 1268 * callback method on the listener object and passes the 1269 * current (udpated) values. 1270 * <p> 1271 * To unregister a listener, pass the listener object and set the 1272 * events argument to 1273 * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0). 1274 * 1275 * @param listener The {@link PhoneStateListener} object to register 1276 * (or unregister) 1277 * @param events The telephony state(s) of interest to the listener, 1278 * as a bitwise-OR combination of {@link PhoneStateListener} 1279 * LISTEN_ flags. 1280 */ 1281 public void listen(PhoneStateListener listener, int events) { 1282 String pkgForDebug = mContext != null ? mContext.getPackageName() : "<unknown>"; 1283 try { 1284 Boolean notifyNow = true; 1285 sRegistry.listen(pkgForDebug, listener.callback, events, notifyNow); 1286 } catch (RemoteException ex) { 1287 // system process dead 1288 } catch (NullPointerException ex) { 1289 // system process dead 1290 } 1291 } 1292 1293 /** 1294 * Returns the CDMA ERI icon index to display 1295 * 1296 * @hide 1297 */ 1298 public int getCdmaEriIconIndex() { 1299 try { 1300 return getITelephony().getCdmaEriIconIndex(); 1301 } catch (RemoteException ex) { 1302 // the phone process is restarting. 1303 return -1; 1304 } catch (NullPointerException ex) { 1305 return -1; 1306 } 1307 } 1308 1309 /** 1310 * Returns the CDMA ERI icon mode, 1311 * 0 - ON 1312 * 1 - FLASHING 1313 * 1314 * @hide 1315 */ 1316 public int getCdmaEriIconMode() { 1317 try { 1318 return getITelephony().getCdmaEriIconMode(); 1319 } catch (RemoteException ex) { 1320 // the phone process is restarting. 1321 return -1; 1322 } catch (NullPointerException ex) { 1323 return -1; 1324 } 1325 } 1326 1327 /** 1328 * Returns the CDMA ERI text, 1329 * 1330 * @hide 1331 */ 1332 public String getCdmaEriText() { 1333 try { 1334 return getITelephony().getCdmaEriText(); 1335 } catch (RemoteException ex) { 1336 // the phone process is restarting. 1337 return null; 1338 } catch (NullPointerException ex) { 1339 return null; 1340 } 1341 } 1342 1343 /** 1344 * @return true if the current device is "voice capable". 1345 * <p> 1346 * "Voice capable" means that this device supports circuit-switched 1347 * (i.e. voice) phone calls over the telephony network, and is allowed 1348 * to display the in-call UI while a cellular voice call is active. 1349 * This will be false on "data only" devices which can't make voice 1350 * calls and don't support any in-call UI. 1351 * <p> 1352 * Note: the meaning of this flag is subtly different from the 1353 * PackageManager.FEATURE_TELEPHONY system feature, which is available 1354 * on any device with a telephony radio, even if the device is 1355 * data-only. 1356 * 1357 * @hide pending API review 1358 */ 1359 public boolean isVoiceCapable() { 1360 if (mContext == null) return true; 1361 return mContext.getResources().getBoolean( 1362 com.android.internal.R.bool.config_voice_capable); 1363 } 1364 1365 /** 1366 * @return true if the current device supports sms service. 1367 * <p> 1368 * If true, this means that the device supports both sending and 1369 * receiving sms via the telephony network. 1370 * <p> 1371 * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are 1372 * disabled when device doesn't support sms. 1373 * 1374 * @hide pending API review 1375 */ 1376 public boolean isSmsCapable() { 1377 if (mContext == null) return true; 1378 return mContext.getResources().getBoolean( 1379 com.android.internal.R.bool.config_sms_capable); 1380 } 1381 1382 /** 1383 * Returns all observed cell information from all radios on the 1384 * device including the primary and neighboring cells. This does 1385 * not cause or change the rate of PhoneStateListner#onCellInfoChanged. 1386 *<p> 1387 * The list can include one or more of {@link android.telephony.CellInfoGsm CellInfoGsm}, 1388 * {@link android.telephony.CellInfoCdma CellInfoCdma}, 1389 * {@link android.telephony.CellInfoLte CellInfoLte} and 1390 * {@link android.telephony.CellInfoWcdma CellInfoCdma} in any combination. 1391 * Specifically on devices with multiple radios it is typical to see instances of 1392 * one or more of any these in the list. In addition 0, 1 or more CellInfo 1393 * objects may return isRegistered() true. 1394 *<p> 1395 * This is preferred over using getCellLocation although for older 1396 * devices this may return null in which case getCellLocation should 1397 * be called. 1398 *<p> 1399 * @return List of CellInfo or null if info unavailable. 1400 * 1401 * <p>Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} 1402 */ 1403 public List<CellInfo> getAllCellInfo() { 1404 try { 1405 return getITelephony().getAllCellInfo(); 1406 } catch (RemoteException ex) { 1407 return null; 1408 } catch (NullPointerException ex) { 1409 return null; 1410 } 1411 } 1412 1413 /** 1414 * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged 1415 * PhoneStateListener.onCellInfoChanged} will be invoked. 1416 *<p> 1417 * The default, 0, means invoke onCellInfoChanged when any of the reported 1418 * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue 1419 * A onCellInfoChanged. 1420 *<p> 1421 * @param rateInMillis the rate 1422 * 1423 * @hide 1424 */ 1425 public void setCellInfoListRate(int rateInMillis) { 1426 try { 1427 getITelephony().setCellInfoListRate(rateInMillis); 1428 } catch (RemoteException ex) { 1429 } catch (NullPointerException ex) { 1430 } 1431 } 1432 1433 /** 1434 * Returns the MMS user agent. 1435 */ 1436 public String getMmsUserAgent() { 1437 if (mContext == null) return null; 1438 return mContext.getResources().getString( 1439 com.android.internal.R.string.config_mms_user_agent); 1440 } 1441 1442 /** 1443 * Returns the MMS user agent profile URL. 1444 */ 1445 public String getMmsUAProfUrl() { 1446 if (mContext == null) return null; 1447 return mContext.getResources().getString( 1448 com.android.internal.R.string.config_mms_user_agent_profile_url); 1449 } 1450} 1451