TelephonyManager.java revision cb9086c5bfd84f8a78eb6072d9eb133bf3a523d8
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.PrivateApi; 20import android.annotation.SdkConstant; 21import android.annotation.SdkConstant.SdkConstantType; 22import android.content.ComponentName; 23import android.content.Context; 24import android.os.Bundle; 25import android.os.Handler; 26import android.os.Message; 27import android.os.RemoteException; 28import android.os.ServiceManager; 29import android.os.SystemProperties; 30import android.telephony.Rlog; 31import android.util.Log; 32 33import com.android.internal.telephony.IPhoneSubInfo; 34import com.android.internal.telephony.ITelephony; 35import com.android.internal.telephony.ITelephonyRegistry; 36import com.android.internal.telephony.PhoneConstants; 37import com.android.internal.telephony.RILConstants; 38import com.android.internal.telephony.TelephonyProperties; 39 40import java.io.FileInputStream; 41import java.io.IOException; 42import java.util.HashMap; 43import java.util.List; 44import java.util.regex.Matcher; 45import java.util.regex.Pattern; 46 47/** 48 * Provides access to information about the telephony services on 49 * the device. Applications can use the methods in this class to 50 * determine telephony services and states, as well as to access some 51 * types of subscriber information. Applications can also register 52 * a listener to receive notification of telephony state changes. 53 * <p> 54 * You do not instantiate this class directly; instead, you retrieve 55 * a reference to an instance through 56 * {@link android.content.Context#getSystemService 57 * Context.getSystemService(Context.TELEPHONY_SERVICE)}. 58 * <p> 59 * Note that access to some telephony information is 60 * permission-protected. Your application cannot access the protected 61 * information unless it has the appropriate permissions declared in 62 * its manifest file. Where permissions apply, they are noted in the 63 * the methods through which you access the protected information. 64 */ 65public class TelephonyManager { 66 private static final String TAG = "TelephonyManager"; 67 68 private static ITelephonyRegistry sRegistry; 69 70 /** 71 * The allowed states of Wi-Fi calling. 72 * 73 * @hide 74 */ 75 public interface WifiCallingChoices { 76 /** Always use Wi-Fi calling */ 77 static final int ALWAYS_USE = 0; 78 /** Ask the user whether to use Wi-Fi on every call */ 79 static final int ASK_EVERY_TIME = 1; 80 /** Never use Wi-Fi calling */ 81 static final int NEVER_USE = 2; 82 } 83 84 private final Context mContext; 85 86 /** @hide */ 87 public TelephonyManager(Context context) { 88 Context appContext = context.getApplicationContext(); 89 if (appContext != null) { 90 mContext = appContext; 91 } else { 92 mContext = context; 93 } 94 95 if (sRegistry == null) { 96 sRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService( 97 "telephony.registry")); 98 } 99 } 100 101 /** @hide */ 102 private TelephonyManager() { 103 mContext = null; 104 } 105 106 private static TelephonyManager sInstance = new TelephonyManager(); 107 108 /** @hide 109 /* @deprecated - use getSystemService as described above */ 110 public static TelephonyManager getDefault() { 111 return sInstance; 112 } 113 114 /** {@hide} */ 115 public static TelephonyManager from(Context context) { 116 return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 117 } 118 119 // 120 // Broadcast Intent actions 121 // 122 123 /** 124 * Broadcast intent action indicating that the call state (cellular) 125 * on the device has changed. 126 * 127 * <p> 128 * The {@link #EXTRA_STATE} extra indicates the new call state. 129 * If the new state is RINGING, a second extra 130 * {@link #EXTRA_INCOMING_NUMBER} provides the incoming phone number as 131 * a String. 132 * 133 * <p class="note"> 134 * Requires the READ_PHONE_STATE permission. 135 * 136 * <p class="note"> 137 * This was a {@link android.content.Context#sendStickyBroadcast sticky} 138 * broadcast in version 1.0, but it is no longer sticky. 139 * Instead, use {@link #getCallState} to synchronously query the current call state. 140 * 141 * @see #EXTRA_STATE 142 * @see #EXTRA_INCOMING_NUMBER 143 * @see #getCallState 144 */ 145 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 146 public static final String ACTION_PHONE_STATE_CHANGED = 147 "android.intent.action.PHONE_STATE"; 148 149 /** 150 * The Phone app sends this intent when a user opts to respond-via-message during an incoming 151 * call. By default, the device's default SMS app consumes this message and sends a text message 152 * to the caller. A third party app can also provide this functionality by consuming this Intent 153 * with a {@link android.app.Service} and sending the message using its own messaging system. 154 * <p>The intent contains a URI (available from {@link android.content.Intent#getData}) 155 * describing the recipient, using either the {@code sms:}, {@code smsto:}, {@code mms:}, 156 * or {@code mmsto:} URI schema. Each of these URI schema carry the recipient information the 157 * same way: the path part of the URI contains the recipient's phone number or a comma-separated 158 * set of phone numbers if there are multiple recipients. For example, {@code 159 * smsto:2065551234}.</p> 160 * 161 * <p>The intent may also contain extras for the message text (in {@link 162 * android.content.Intent#EXTRA_TEXT}) and a message subject 163 * (in {@link android.content.Intent#EXTRA_SUBJECT}).</p> 164 * 165 * <p class="note"><strong>Note:</strong> 166 * The intent-filter that consumes this Intent needs to be in a {@link android.app.Service} 167 * that requires the 168 * permission {@link android.Manifest.permission#SEND_RESPOND_VIA_MESSAGE}.</p> 169 * <p>For example, the service that receives this intent can be declared in the manifest file 170 * with an intent filter like this:</p> 171 * <pre> 172 * <!-- Service that delivers SMS messages received from the phone "quick response" --> 173 * <service android:name=".HeadlessSmsSendService" 174 * android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE" 175 * android:exported="true" > 176 * <intent-filter> 177 * <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" /> 178 * <category android:name="android.intent.category.DEFAULT" /> 179 * <data android:scheme="sms" /> 180 * <data android:scheme="smsto" /> 181 * <data android:scheme="mms" /> 182 * <data android:scheme="mmsto" /> 183 * </intent-filter> 184 * </service></pre> 185 * <p> 186 * Output: nothing. 187 */ 188 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 189 public static final String ACTION_RESPOND_VIA_MESSAGE = 190 "android.intent.action.RESPOND_VIA_MESSAGE"; 191 192 /** 193 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 194 * for a String containing the new call state. 195 * 196 * @see #EXTRA_STATE_IDLE 197 * @see #EXTRA_STATE_RINGING 198 * @see #EXTRA_STATE_OFFHOOK 199 * 200 * <p class="note"> 201 * Retrieve with 202 * {@link android.content.Intent#getStringExtra(String)}. 203 */ 204 public static final String EXTRA_STATE = PhoneConstants.STATE_KEY; 205 206 /** 207 * Value used with {@link #EXTRA_STATE} corresponding to 208 * {@link #CALL_STATE_IDLE}. 209 */ 210 public static final String EXTRA_STATE_IDLE = PhoneConstants.State.IDLE.toString(); 211 212 /** 213 * Value used with {@link #EXTRA_STATE} corresponding to 214 * {@link #CALL_STATE_RINGING}. 215 */ 216 public static final String EXTRA_STATE_RINGING = PhoneConstants.State.RINGING.toString(); 217 218 /** 219 * Value used with {@link #EXTRA_STATE} corresponding to 220 * {@link #CALL_STATE_OFFHOOK}. 221 */ 222 public static final String EXTRA_STATE_OFFHOOK = PhoneConstants.State.OFFHOOK.toString(); 223 224 /** 225 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 226 * for a String containing the incoming phone number. 227 * Only valid when the new call state is RINGING. 228 * 229 * <p class="note"> 230 * Retrieve with 231 * {@link android.content.Intent#getStringExtra(String)}. 232 */ 233 public static final String EXTRA_INCOMING_NUMBER = "incoming_number"; 234 235 /** 236 * Broadcast intent action indicating that a precise call state 237 * (cellular) on the device has changed. 238 * 239 * <p> 240 * The {@link #EXTRA_RINGING_CALL_STATE} extra indicates the ringing call state. 241 * The {@link #EXTRA_FOREGROUND_CALL_STATE} extra indicates the foreground call state. 242 * The {@link #EXTRA_BACKGROUND_CALL_STATE} extra indicates the background call state. 243 * The {@link #EXTRA_DISCONNECT_CAUSE} extra indicates the disconnect cause. 244 * The {@link #EXTRA_PRECISE_DISCONNECT_CAUSE} extra indicates the precise disconnect cause. 245 * 246 * <p class="note"> 247 * Requires the READ_PRECISE_PHONE_STATE permission. 248 * 249 * @see #EXTRA_RINGING_CALL_STATE 250 * @see #EXTRA_FOREGROUND_CALL_STATE 251 * @see #EXTRA_BACKGROUND_CALL_STATE 252 * @see #EXTRA_DISCONNECT_CAUSE 253 * @see #EXTRA_PRECISE_DISCONNECT_CAUSE 254 * 255 * <p class="note"> 256 * Requires the READ_PRECISE_PHONE_STATE permission. 257 * 258 * @hide 259 */ 260 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 261 public static final String ACTION_PRECISE_CALL_STATE_CHANGED = 262 "android.intent.action.PRECISE_CALL_STATE"; 263 264 /** 265 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 266 * for an integer containing the state of the current ringing call. 267 * 268 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 269 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 270 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 271 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 272 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 273 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 274 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 275 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 276 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 277 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 278 * 279 * <p class="note"> 280 * Retrieve with 281 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 282 * 283 * @hide 284 */ 285 public static final String EXTRA_RINGING_CALL_STATE = "ringing_state"; 286 287 /** 288 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 289 * for an integer containing the state of the current foreground call. 290 * 291 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 292 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 293 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 294 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 295 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 296 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 297 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 298 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 299 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 300 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 301 * 302 * <p class="note"> 303 * Retrieve with 304 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 305 * 306 * @hide 307 */ 308 public static final String EXTRA_FOREGROUND_CALL_STATE = "foreground_state"; 309 310 /** 311 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 312 * for an integer containing the state of the current background call. 313 * 314 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 315 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 316 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 317 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 318 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 319 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 320 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 321 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 322 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 323 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 324 * 325 * <p class="note"> 326 * Retrieve with 327 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 328 * 329 * @hide 330 */ 331 public static final String EXTRA_BACKGROUND_CALL_STATE = "background_state"; 332 333 /** 334 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 335 * for an integer containing the disconnect cause. 336 * 337 * @see DisconnectCause 338 * 339 * <p class="note"> 340 * Retrieve with 341 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 342 * 343 * @hide 344 */ 345 public static final String EXTRA_DISCONNECT_CAUSE = "disconnect_cause"; 346 347 /** 348 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 349 * for an integer containing the disconnect cause provided by the RIL. 350 * 351 * @see PreciseDisconnectCause 352 * 353 * <p class="note"> 354 * Retrieve with 355 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 356 * 357 * @hide 358 */ 359 public static final String EXTRA_PRECISE_DISCONNECT_CAUSE = "precise_disconnect_cause"; 360 361 /** 362 * Broadcast intent action indicating a data connection has changed, 363 * providing precise information about the connection. 364 * 365 * <p> 366 * The {@link #EXTRA_DATA_STATE} extra indicates the connection state. 367 * The {@link #EXTRA_DATA_NETWORK_TYPE} extra indicates the connection network type. 368 * The {@link #EXTRA_DATA_APN_TYPE} extra indicates the APN type. 369 * The {@link #EXTRA_DATA_APN} extra indicates the APN. 370 * The {@link #EXTRA_DATA_CHANGE_REASON} extra indicates the connection change reason. 371 * The {@link #EXTRA_DATA_IFACE_PROPERTIES} extra indicates the connection interface. 372 * The {@link #EXTRA_DATA_FAILURE_CAUSE} extra indicates the connection fail cause. 373 * 374 * <p class="note"> 375 * Requires the READ_PRECISE_PHONE_STATE permission. 376 * 377 * @see #EXTRA_DATA_STATE 378 * @see #EXTRA_DATA_NETWORK_TYPE 379 * @see #EXTRA_DATA_APN_TYPE 380 * @see #EXTRA_DATA_APN 381 * @see #EXTRA_DATA_CHANGE_REASON 382 * @see #EXTRA_DATA_IFACE 383 * @see #EXTRA_DATA_FAILURE_CAUSE 384 * @hide 385 */ 386 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 387 public static final String ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED = 388 "android.intent.action.PRECISE_DATA_CONNECTION_STATE_CHANGED"; 389 390 /** 391 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 392 * for an integer containing the state of the current data connection. 393 * 394 * @see TelephonyManager#DATA_UNKNOWN 395 * @see TelephonyManager#DATA_DISCONNECTED 396 * @see TelephonyManager#DATA_CONNECTING 397 * @see TelephonyManager#DATA_CONNECTED 398 * @see TelephonyManager#DATA_SUSPENDED 399 * 400 * <p class="note"> 401 * Retrieve with 402 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 403 * 404 * @hide 405 */ 406 public static final String EXTRA_DATA_STATE = PhoneConstants.STATE_KEY; 407 408 /** 409 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 410 * for an integer containing the network type. 411 * 412 * @see TelephonyManager#NETWORK_TYPE_UNKNOWN 413 * @see TelephonyManager#NETWORK_TYPE_GPRS 414 * @see TelephonyManager#NETWORK_TYPE_EDGE 415 * @see TelephonyManager#NETWORK_TYPE_UMTS 416 * @see TelephonyManager#NETWORK_TYPE_CDMA 417 * @see TelephonyManager#NETWORK_TYPE_EVDO_0 418 * @see TelephonyManager#NETWORK_TYPE_EVDO_A 419 * @see TelephonyManager#NETWORK_TYPE_1xRTT 420 * @see TelephonyManager#NETWORK_TYPE_HSDPA 421 * @see TelephonyManager#NETWORK_TYPE_HSUPA 422 * @see TelephonyManager#NETWORK_TYPE_HSPA 423 * @see TelephonyManager#NETWORK_TYPE_IDEN 424 * @see TelephonyManager#NETWORK_TYPE_EVDO_B 425 * @see TelephonyManager#NETWORK_TYPE_LTE 426 * @see TelephonyManager#NETWORK_TYPE_EHRPD 427 * @see TelephonyManager#NETWORK_TYPE_HSPAP 428 * 429 * <p class="note"> 430 * Retrieve with 431 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 432 * 433 * @hide 434 */ 435 public static final String EXTRA_DATA_NETWORK_TYPE = PhoneConstants.DATA_NETWORK_TYPE_KEY; 436 437 /** 438 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 439 * for an String containing the data APN type. 440 * 441 * <p class="note"> 442 * Retrieve with 443 * {@link android.content.Intent#getStringExtra(String name)}. 444 * 445 * @hide 446 */ 447 public static final String EXTRA_DATA_APN_TYPE = PhoneConstants.DATA_APN_TYPE_KEY; 448 449 /** 450 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 451 * for an String containing the data APN. 452 * 453 * <p class="note"> 454 * Retrieve with 455 * {@link android.content.Intent#getStringExtra(String name)}. 456 * 457 * @hide 458 */ 459 public static final String EXTRA_DATA_APN = PhoneConstants.DATA_APN_KEY; 460 461 /** 462 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 463 * for an String representation of the change reason. 464 * 465 * <p class="note"> 466 * Retrieve with 467 * {@link android.content.Intent#getStringExtra(String name)}. 468 * 469 * @hide 470 */ 471 public static final String EXTRA_DATA_CHANGE_REASON = PhoneConstants.STATE_CHANGE_REASON_KEY; 472 473 /** 474 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 475 * for an String representation of the data interface. 476 * 477 * <p class="note"> 478 * Retrieve with 479 * {@link android.content.Intent#getParcelableExtra(String name)}. 480 * 481 * @hide 482 */ 483 public static final String EXTRA_DATA_LINK_PROPERTIES_KEY = PhoneConstants.DATA_LINK_PROPERTIES_KEY; 484 485 /** 486 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 487 * for the data connection fail cause. 488 * 489 * <p class="note"> 490 * Retrieve with 491 * {@link android.content.Intent#getStringExtra(String name)}. 492 * 493 * @hide 494 */ 495 public static final String EXTRA_DATA_FAILURE_CAUSE = PhoneConstants.DATA_FAILURE_CAUSE_KEY; 496 497 // 498 // 499 // Device Info 500 // 501 // 502 503 /** 504 * Returns the software version number for the device, for example, 505 * the IMEI/SV for GSM phones. Return null if the software version is 506 * not available. 507 * 508 * <p>Requires Permission: 509 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 510 */ 511 public String getDeviceSoftwareVersion() { 512 try { 513 return getSubscriberInfo().getDeviceSvn(); 514 } catch (RemoteException ex) { 515 return null; 516 } catch (NullPointerException ex) { 517 return null; 518 } 519 } 520 521 /** 522 * Returns the unique device ID, for example, the IMEI for GSM and the MEID 523 * or ESN for CDMA phones. Return null if device ID is not available. 524 * 525 * <p>Requires Permission: 526 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 527 */ 528 public String getDeviceId() { 529 try { 530 return getSubscriberInfo().getDeviceId(); 531 } catch (RemoteException ex) { 532 return null; 533 } catch (NullPointerException ex) { 534 return null; 535 } 536 } 537 538 /** 539 * Returns the current location of the device. 540 *<p> 541 * If there is only one radio in the device and that radio has an LTE connection, 542 * this method will return null. The implementation must not to try add LTE 543 * identifiers into the existing cdma/gsm classes. 544 *<p> 545 * In the future this call will be deprecated. 546 *<p> 547 * @return Current location of the device or null if not available. 548 * 549 * <p>Requires Permission: 550 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or 551 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION}. 552 */ 553 public CellLocation getCellLocation() { 554 try { 555 Bundle bundle = getITelephony().getCellLocation(); 556 if (bundle.isEmpty()) return null; 557 CellLocation cl = CellLocation.newFromBundle(bundle); 558 if (cl.isEmpty()) 559 return null; 560 return cl; 561 } catch (RemoteException ex) { 562 return null; 563 } catch (NullPointerException ex) { 564 return null; 565 } 566 } 567 568 /** 569 * Enables location update notifications. {@link PhoneStateListener#onCellLocationChanged 570 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 571 * 572 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 573 * CONTROL_LOCATION_UPDATES} 574 * 575 * @hide 576 */ 577 public void enableLocationUpdates() { 578 try { 579 getITelephony().enableLocationUpdates(); 580 } catch (RemoteException ex) { 581 } catch (NullPointerException ex) { 582 } 583 } 584 585 /** 586 * Disables location update notifications. {@link PhoneStateListener#onCellLocationChanged 587 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 588 * 589 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 590 * CONTROL_LOCATION_UPDATES} 591 * 592 * @hide 593 */ 594 public void disableLocationUpdates() { 595 try { 596 getITelephony().disableLocationUpdates(); 597 } catch (RemoteException ex) { 598 } catch (NullPointerException ex) { 599 } 600 } 601 602 /** 603 * Returns the neighboring cell information of the device. The getAllCellInfo is preferred 604 * and use this only if getAllCellInfo return nulls or an empty list. 605 *<p> 606 * In the future this call will be deprecated. 607 *<p> 608 * @return List of NeighboringCellInfo or null if info unavailable. 609 * 610 * <p>Requires Permission: 611 * (@link android.Manifest.permission#ACCESS_COARSE_UPDATES} 612 */ 613 public List<NeighboringCellInfo> getNeighboringCellInfo() { 614 try { 615 return getITelephony().getNeighboringCellInfo(mContext.getOpPackageName()); 616 } catch (RemoteException ex) { 617 return null; 618 } catch (NullPointerException ex) { 619 return null; 620 } 621 } 622 623 /** No phone radio. */ 624 public static final int PHONE_TYPE_NONE = PhoneConstants.PHONE_TYPE_NONE; 625 /** Phone radio is GSM. */ 626 public static final int PHONE_TYPE_GSM = PhoneConstants.PHONE_TYPE_GSM; 627 /** Phone radio is CDMA. */ 628 public static final int PHONE_TYPE_CDMA = PhoneConstants.PHONE_TYPE_CDMA; 629 /** Phone is via SIP. */ 630 public static final int PHONE_TYPE_SIP = PhoneConstants.PHONE_TYPE_SIP; 631 632 /** 633 * Returns the current phone type. 634 * TODO: This is a last minute change and hence hidden. 635 * 636 * @see #PHONE_TYPE_NONE 637 * @see #PHONE_TYPE_GSM 638 * @see #PHONE_TYPE_CDMA 639 * @see #PHONE_TYPE_SIP 640 * 641 * {@hide} 642 */ 643 public int getCurrentPhoneType() { 644 try{ 645 ITelephony telephony = getITelephony(); 646 if (telephony != null) { 647 return telephony.getActivePhoneType(); 648 } else { 649 // This can happen when the ITelephony interface is not up yet. 650 return getPhoneTypeFromProperty(); 651 } 652 } catch (RemoteException ex) { 653 // This shouldn't happen in the normal case, as a backup we 654 // read from the system property. 655 return getPhoneTypeFromProperty(); 656 } catch (NullPointerException ex) { 657 // This shouldn't happen in the normal case, as a backup we 658 // read from the system property. 659 return getPhoneTypeFromProperty(); 660 } 661 } 662 663 /** 664 * Returns a constant indicating the device phone type. This 665 * indicates the type of radio used to transmit voice calls. 666 * 667 * @see #PHONE_TYPE_NONE 668 * @see #PHONE_TYPE_GSM 669 * @see #PHONE_TYPE_CDMA 670 * @see #PHONE_TYPE_SIP 671 */ 672 public int getPhoneType() { 673 if (!isVoiceCapable()) { 674 return PHONE_TYPE_NONE; 675 } 676 return getCurrentPhoneType(); 677 } 678 679 private int getPhoneTypeFromProperty() { 680 int type = 681 SystemProperties.getInt(TelephonyProperties.CURRENT_ACTIVE_PHONE, 682 getPhoneTypeFromNetworkType()); 683 return type; 684 } 685 686 private int getPhoneTypeFromNetworkType() { 687 // When the system property CURRENT_ACTIVE_PHONE, has not been set, 688 // use the system property for default network type. 689 // This is a fail safe, and can only happen at first boot. 690 int mode = SystemProperties.getInt("ro.telephony.default_network", -1); 691 if (mode == -1) 692 return PHONE_TYPE_NONE; 693 return getPhoneType(mode); 694 } 695 696 /** 697 * This function returns the type of the phone, depending 698 * on the network mode. 699 * 700 * @param networkMode 701 * @return Phone Type 702 * 703 * @hide 704 */ 705 public static int getPhoneType(int networkMode) { 706 switch(networkMode) { 707 case RILConstants.NETWORK_MODE_CDMA: 708 case RILConstants.NETWORK_MODE_CDMA_NO_EVDO: 709 case RILConstants.NETWORK_MODE_EVDO_NO_CDMA: 710 return PhoneConstants.PHONE_TYPE_CDMA; 711 712 case RILConstants.NETWORK_MODE_WCDMA_PREF: 713 case RILConstants.NETWORK_MODE_GSM_ONLY: 714 case RILConstants.NETWORK_MODE_WCDMA_ONLY: 715 case RILConstants.NETWORK_MODE_GSM_UMTS: 716 case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA: 717 case RILConstants.NETWORK_MODE_LTE_WCDMA: 718 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA: 719 return PhoneConstants.PHONE_TYPE_GSM; 720 721 // Use CDMA Phone for the global mode including CDMA 722 case RILConstants.NETWORK_MODE_GLOBAL: 723 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO: 724 return PhoneConstants.PHONE_TYPE_CDMA; 725 726 case RILConstants.NETWORK_MODE_LTE_ONLY: 727 if (getLteOnCdmaModeStatic() == PhoneConstants.LTE_ON_CDMA_TRUE) { 728 return PhoneConstants.PHONE_TYPE_CDMA; 729 } else { 730 return PhoneConstants.PHONE_TYPE_GSM; 731 } 732 default: 733 return PhoneConstants.PHONE_TYPE_GSM; 734 } 735 } 736 737 /** 738 * The contents of the /proc/cmdline file 739 */ 740 private static String getProcCmdLine() 741 { 742 String cmdline = ""; 743 FileInputStream is = null; 744 try { 745 is = new FileInputStream("/proc/cmdline"); 746 byte [] buffer = new byte[2048]; 747 int count = is.read(buffer); 748 if (count > 0) { 749 cmdline = new String(buffer, 0, count); 750 } 751 } catch (IOException e) { 752 Rlog.d(TAG, "No /proc/cmdline exception=" + e); 753 } finally { 754 if (is != null) { 755 try { 756 is.close(); 757 } catch (IOException e) { 758 } 759 } 760 } 761 Rlog.d(TAG, "/proc/cmdline=" + cmdline); 762 return cmdline; 763 } 764 765 /** Kernel command line */ 766 private static final String sKernelCmdLine = getProcCmdLine(); 767 768 /** Pattern for selecting the product type from the kernel command line */ 769 private static final Pattern sProductTypePattern = 770 Pattern.compile("\\sproduct_type\\s*=\\s*(\\w+)"); 771 772 /** The ProductType used for LTE on CDMA devices */ 773 private static final String sLteOnCdmaProductType = 774 SystemProperties.get(TelephonyProperties.PROPERTY_LTE_ON_CDMA_PRODUCT_TYPE, ""); 775 776 /** 777 * Return if the current radio is LTE on CDMA. This 778 * is a tri-state return value as for a period of time 779 * the mode may be unknown. 780 * 781 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 782 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 783 * 784 * @hide 785 */ 786 public static int getLteOnCdmaModeStatic() { 787 int retVal; 788 int curVal; 789 String productType = ""; 790 791 curVal = SystemProperties.getInt(TelephonyProperties.PROPERTY_LTE_ON_CDMA_DEVICE, 792 PhoneConstants.LTE_ON_CDMA_UNKNOWN); 793 retVal = curVal; 794 if (retVal == PhoneConstants.LTE_ON_CDMA_UNKNOWN) { 795 Matcher matcher = sProductTypePattern.matcher(sKernelCmdLine); 796 if (matcher.find()) { 797 productType = matcher.group(1); 798 if (sLteOnCdmaProductType.equals(productType)) { 799 retVal = PhoneConstants.LTE_ON_CDMA_TRUE; 800 } else { 801 retVal = PhoneConstants.LTE_ON_CDMA_FALSE; 802 } 803 } else { 804 retVal = PhoneConstants.LTE_ON_CDMA_FALSE; 805 } 806 } 807 808 Rlog.d(TAG, "getLteOnCdmaMode=" + retVal + " curVal=" + curVal + 809 " product_type='" + productType + 810 "' lteOnCdmaProductType='" + sLteOnCdmaProductType + "'"); 811 return retVal; 812 } 813 814 // 815 // 816 // Current Network 817 // 818 // 819 820 /** 821 * Returns the alphabetic name of current registered operator. 822 * <p> 823 * Availability: Only when user is registered to a network. Result may be 824 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 825 * on a CDMA network). 826 */ 827 public String getNetworkOperatorName() { 828 return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ALPHA); 829 } 830 831 /** 832 * Returns the numeric name (MCC+MNC) of current registered operator. 833 * <p> 834 * Availability: Only when user is registered to a network. Result may be 835 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 836 * on a CDMA network). 837 */ 838 public String getNetworkOperator() { 839 return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC); 840 } 841 842 /** 843 * Returns true if the device is considered roaming on the current 844 * network, for GSM purposes. 845 * <p> 846 * Availability: Only when user registered to a network. 847 */ 848 public boolean isNetworkRoaming() { 849 return "true".equals(SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ISROAMING)); 850 } 851 852 /** 853 * Returns the ISO country code equivalent of the current registered 854 * operator's MCC (Mobile Country Code). 855 * <p> 856 * Availability: Only when user is registered to a network. Result may be 857 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 858 * on a CDMA network). 859 */ 860 public String getNetworkCountryIso() { 861 return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY); 862 } 863 864 /** Network type is unknown */ 865 public static final int NETWORK_TYPE_UNKNOWN = 0; 866 /** Current network is GPRS */ 867 public static final int NETWORK_TYPE_GPRS = 1; 868 /** Current network is EDGE */ 869 public static final int NETWORK_TYPE_EDGE = 2; 870 /** Current network is UMTS */ 871 public static final int NETWORK_TYPE_UMTS = 3; 872 /** Current network is CDMA: Either IS95A or IS95B*/ 873 public static final int NETWORK_TYPE_CDMA = 4; 874 /** Current network is EVDO revision 0*/ 875 public static final int NETWORK_TYPE_EVDO_0 = 5; 876 /** Current network is EVDO revision A*/ 877 public static final int NETWORK_TYPE_EVDO_A = 6; 878 /** Current network is 1xRTT*/ 879 public static final int NETWORK_TYPE_1xRTT = 7; 880 /** Current network is HSDPA */ 881 public static final int NETWORK_TYPE_HSDPA = 8; 882 /** Current network is HSUPA */ 883 public static final int NETWORK_TYPE_HSUPA = 9; 884 /** Current network is HSPA */ 885 public static final int NETWORK_TYPE_HSPA = 10; 886 /** Current network is iDen */ 887 public static final int NETWORK_TYPE_IDEN = 11; 888 /** Current network is EVDO revision B*/ 889 public static final int NETWORK_TYPE_EVDO_B = 12; 890 /** Current network is LTE */ 891 public static final int NETWORK_TYPE_LTE = 13; 892 /** Current network is eHRPD */ 893 public static final int NETWORK_TYPE_EHRPD = 14; 894 /** Current network is HSPA+ */ 895 public static final int NETWORK_TYPE_HSPAP = 15; 896 /** Current network is GSM {@hide} */ 897 public static final int NETWORK_TYPE_GSM = 16; 898 899 /** 900 * @return the NETWORK_TYPE_xxxx for current data connection. 901 */ 902 public int getNetworkType() { 903 return getDataNetworkType(); 904 } 905 906 /** 907 * Returns a constant indicating the radio technology (network type) 908 * currently in use on the device for data transmission. 909 * @return the network type 910 * 911 * @see #NETWORK_TYPE_UNKNOWN 912 * @see #NETWORK_TYPE_GPRS 913 * @see #NETWORK_TYPE_EDGE 914 * @see #NETWORK_TYPE_UMTS 915 * @see #NETWORK_TYPE_HSDPA 916 * @see #NETWORK_TYPE_HSUPA 917 * @see #NETWORK_TYPE_HSPA 918 * @see #NETWORK_TYPE_CDMA 919 * @see #NETWORK_TYPE_EVDO_0 920 * @see #NETWORK_TYPE_EVDO_A 921 * @see #NETWORK_TYPE_EVDO_B 922 * @see #NETWORK_TYPE_1xRTT 923 * @see #NETWORK_TYPE_IDEN 924 * @see #NETWORK_TYPE_LTE 925 * @see #NETWORK_TYPE_EHRPD 926 * @see #NETWORK_TYPE_HSPAP 927 * 928 * @hide 929 */ 930 public int getDataNetworkType() { 931 try{ 932 ITelephony telephony = getITelephony(); 933 if (telephony != null) { 934 return telephony.getDataNetworkType(); 935 } else { 936 // This can happen when the ITelephony interface is not up yet. 937 return NETWORK_TYPE_UNKNOWN; 938 } 939 } catch(RemoteException ex) { 940 // This shouldn't happen in the normal case 941 return NETWORK_TYPE_UNKNOWN; 942 } catch (NullPointerException ex) { 943 // This could happen before phone restarts due to crashing 944 return NETWORK_TYPE_UNKNOWN; 945 } 946 } 947 948 /** 949 * Returns the NETWORK_TYPE_xxxx for voice 950 * 951 * @hide 952 */ 953 public int getVoiceNetworkType() { 954 try{ 955 ITelephony telephony = getITelephony(); 956 if (telephony != null) { 957 return telephony.getVoiceNetworkType(); 958 } else { 959 // This can happen when the ITelephony interface is not up yet. 960 return NETWORK_TYPE_UNKNOWN; 961 } 962 } catch(RemoteException ex) { 963 // This shouldn't happen in the normal case 964 return NETWORK_TYPE_UNKNOWN; 965 } catch (NullPointerException ex) { 966 // This could happen before phone restarts due to crashing 967 return NETWORK_TYPE_UNKNOWN; 968 } 969 } 970 971 /** Unknown network class. {@hide} */ 972 public static final int NETWORK_CLASS_UNKNOWN = 0; 973 /** Class of broadly defined "2G" networks. {@hide} */ 974 public static final int NETWORK_CLASS_2_G = 1; 975 /** Class of broadly defined "3G" networks. {@hide} */ 976 public static final int NETWORK_CLASS_3_G = 2; 977 /** Class of broadly defined "4G" networks. {@hide} */ 978 public static final int NETWORK_CLASS_4_G = 3; 979 980 /** 981 * Return general class of network type, such as "3G" or "4G". In cases 982 * where classification is contentious, this method is conservative. 983 * 984 * @hide 985 */ 986 public static int getNetworkClass(int networkType) { 987 switch (networkType) { 988 case NETWORK_TYPE_GPRS: 989 case NETWORK_TYPE_GSM: 990 case NETWORK_TYPE_EDGE: 991 case NETWORK_TYPE_CDMA: 992 case NETWORK_TYPE_1xRTT: 993 case NETWORK_TYPE_IDEN: 994 return NETWORK_CLASS_2_G; 995 case NETWORK_TYPE_UMTS: 996 case NETWORK_TYPE_EVDO_0: 997 case NETWORK_TYPE_EVDO_A: 998 case NETWORK_TYPE_HSDPA: 999 case NETWORK_TYPE_HSUPA: 1000 case NETWORK_TYPE_HSPA: 1001 case NETWORK_TYPE_EVDO_B: 1002 case NETWORK_TYPE_EHRPD: 1003 case NETWORK_TYPE_HSPAP: 1004 return NETWORK_CLASS_3_G; 1005 case NETWORK_TYPE_LTE: 1006 return NETWORK_CLASS_4_G; 1007 default: 1008 return NETWORK_CLASS_UNKNOWN; 1009 } 1010 } 1011 1012 /** 1013 * Returns a string representation of the radio technology (network type) 1014 * currently in use on the device. 1015 * @return the name of the radio technology 1016 * 1017 * @hide pending API council review 1018 */ 1019 public String getNetworkTypeName() { 1020 return getNetworkTypeName(getNetworkType()); 1021 } 1022 1023 /** {@hide} */ 1024 public static String getNetworkTypeName(int type) { 1025 switch (type) { 1026 case NETWORK_TYPE_GPRS: 1027 return "GPRS"; 1028 case NETWORK_TYPE_EDGE: 1029 return "EDGE"; 1030 case NETWORK_TYPE_UMTS: 1031 return "UMTS"; 1032 case NETWORK_TYPE_HSDPA: 1033 return "HSDPA"; 1034 case NETWORK_TYPE_HSUPA: 1035 return "HSUPA"; 1036 case NETWORK_TYPE_HSPA: 1037 return "HSPA"; 1038 case NETWORK_TYPE_CDMA: 1039 return "CDMA"; 1040 case NETWORK_TYPE_EVDO_0: 1041 return "CDMA - EvDo rev. 0"; 1042 case NETWORK_TYPE_EVDO_A: 1043 return "CDMA - EvDo rev. A"; 1044 case NETWORK_TYPE_EVDO_B: 1045 return "CDMA - EvDo rev. B"; 1046 case NETWORK_TYPE_1xRTT: 1047 return "CDMA - 1xRTT"; 1048 case NETWORK_TYPE_LTE: 1049 return "LTE"; 1050 case NETWORK_TYPE_EHRPD: 1051 return "CDMA - eHRPD"; 1052 case NETWORK_TYPE_IDEN: 1053 return "iDEN"; 1054 case NETWORK_TYPE_HSPAP: 1055 return "HSPA+"; 1056 case NETWORK_TYPE_GSM: 1057 return "GSM"; 1058 default: 1059 return "UNKNOWN"; 1060 } 1061 } 1062 1063 // 1064 // 1065 // SIM Card 1066 // 1067 // 1068 1069 /** SIM card state: Unknown. Signifies that the SIM is in transition 1070 * between states. For example, when the user inputs the SIM pin 1071 * under PIN_REQUIRED state, a query for sim status returns 1072 * this state before turning to SIM_STATE_READY. */ 1073 public static final int SIM_STATE_UNKNOWN = 0; 1074 /** SIM card state: no SIM card is available in the device */ 1075 public static final int SIM_STATE_ABSENT = 1; 1076 /** SIM card state: Locked: requires the user's SIM PIN to unlock */ 1077 public static final int SIM_STATE_PIN_REQUIRED = 2; 1078 /** SIM card state: Locked: requires the user's SIM PUK to unlock */ 1079 public static final int SIM_STATE_PUK_REQUIRED = 3; 1080 /** SIM card state: Locked: requries a network PIN to unlock */ 1081 public static final int SIM_STATE_NETWORK_LOCKED = 4; 1082 /** SIM card state: Ready */ 1083 public static final int SIM_STATE_READY = 5; 1084 /** SIM card state: SIM Card Error, Sim Card is present but faulty 1085 *@hide 1086 */ 1087 public static final int SIM_STATE_CARD_IO_ERROR = 6; 1088 1089 /** 1090 * @return true if a ICC card is present 1091 */ 1092 public boolean hasIccCard() { 1093 try { 1094 return getITelephony().hasIccCard(); 1095 } catch (RemoteException ex) { 1096 // Assume no ICC card if remote exception which shouldn't happen 1097 return false; 1098 } catch (NullPointerException ex) { 1099 // This could happen before phone restarts due to crashing 1100 return false; 1101 } 1102 } 1103 1104 /** 1105 * Returns a constant indicating the state of the 1106 * device SIM card. 1107 * 1108 * @see #SIM_STATE_UNKNOWN 1109 * @see #SIM_STATE_ABSENT 1110 * @see #SIM_STATE_PIN_REQUIRED 1111 * @see #SIM_STATE_PUK_REQUIRED 1112 * @see #SIM_STATE_NETWORK_LOCKED 1113 * @see #SIM_STATE_READY 1114 * @see #SIM_STATE_CARD_IO_ERROR 1115 */ 1116 public int getSimState() { 1117 String prop = SystemProperties.get(TelephonyProperties.PROPERTY_SIM_STATE); 1118 if ("ABSENT".equals(prop)) { 1119 return SIM_STATE_ABSENT; 1120 } 1121 else if ("PIN_REQUIRED".equals(prop)) { 1122 return SIM_STATE_PIN_REQUIRED; 1123 } 1124 else if ("PUK_REQUIRED".equals(prop)) { 1125 return SIM_STATE_PUK_REQUIRED; 1126 } 1127 else if ("NETWORK_LOCKED".equals(prop)) { 1128 return SIM_STATE_NETWORK_LOCKED; 1129 } 1130 else if ("READY".equals(prop)) { 1131 return SIM_STATE_READY; 1132 } 1133 else if ("CARD_IO_ERROR".equals(prop)) { 1134 return SIM_STATE_CARD_IO_ERROR; 1135 } 1136 else { 1137 return SIM_STATE_UNKNOWN; 1138 } 1139 } 1140 1141 /** 1142 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1143 * provider of the SIM. 5 or 6 decimal digits. 1144 * <p> 1145 * Availability: SIM state must be {@link #SIM_STATE_READY} 1146 * 1147 * @see #getSimState 1148 */ 1149 public String getSimOperator() { 1150 return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC); 1151 } 1152 1153 /** 1154 * Returns the Service Provider Name (SPN). 1155 * <p> 1156 * Availability: SIM state must be {@link #SIM_STATE_READY} 1157 * 1158 * @see #getSimState 1159 */ 1160 public String getSimOperatorName() { 1161 return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA); 1162 } 1163 1164 /** 1165 * Returns the ISO country code equivalent for the SIM provider's country code. 1166 */ 1167 public String getSimCountryIso() { 1168 return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY); 1169 } 1170 1171 /** 1172 * Returns the serial number of the SIM, if applicable. Return null if it is 1173 * unavailable. 1174 * <p> 1175 * Requires Permission: 1176 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1177 */ 1178 public String getSimSerialNumber() { 1179 try { 1180 return getSubscriberInfo().getIccSerialNumber(); 1181 } catch (RemoteException ex) { 1182 return null; 1183 } catch (NullPointerException ex) { 1184 // This could happen before phone restarts due to crashing 1185 return null; 1186 } 1187 } 1188 1189 /** 1190 * Return if the current radio is LTE on CDMA. This 1191 * is a tri-state return value as for a period of time 1192 * the mode may be unknown. 1193 * 1194 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 1195 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 1196 * 1197 * @hide 1198 */ 1199 public int getLteOnCdmaMode() { 1200 try { 1201 return getITelephony().getLteOnCdmaMode(); 1202 } catch (RemoteException ex) { 1203 // Assume no ICC card if remote exception which shouldn't happen 1204 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 1205 } catch (NullPointerException ex) { 1206 // This could happen before phone restarts due to crashing 1207 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 1208 } 1209 } 1210 1211 // 1212 // 1213 // Subscriber Info 1214 // 1215 // 1216 1217 /** 1218 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone. 1219 * Return null if it is unavailable. 1220 * <p> 1221 * Requires Permission: 1222 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1223 */ 1224 public String getSubscriberId() { 1225 try { 1226 return getSubscriberInfo().getSubscriberId(); 1227 } catch (RemoteException ex) { 1228 return null; 1229 } catch (NullPointerException ex) { 1230 // This could happen before phone restarts due to crashing 1231 return null; 1232 } 1233 } 1234 1235 /** 1236 * Returns the Group Identifier Level1 for a GSM phone. 1237 * Return null if it is unavailable. 1238 * <p> 1239 * Requires Permission: 1240 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1241 */ 1242 public String getGroupIdLevel1() { 1243 try { 1244 return getSubscriberInfo().getGroupIdLevel1(); 1245 } catch (RemoteException ex) { 1246 return null; 1247 } catch (NullPointerException ex) { 1248 // This could happen before phone restarts due to crashing 1249 return null; 1250 } 1251 } 1252 1253 /** 1254 * Returns the phone number string for line 1, for example, the MSISDN 1255 * for a GSM phone. Return null if it is unavailable. 1256 * <p> 1257 * Requires Permission: 1258 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1259 */ 1260 public String getLine1Number() { 1261 try { 1262 return getSubscriberInfo().getLine1Number(); 1263 } catch (RemoteException ex) { 1264 return null; 1265 } catch (NullPointerException ex) { 1266 // This could happen before phone restarts due to crashing 1267 return null; 1268 } 1269 } 1270 1271 /** 1272 * Returns the alphabetic identifier associated with the line 1 number. 1273 * Return null if it is unavailable. 1274 * <p> 1275 * Requires Permission: 1276 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1277 * @hide 1278 * nobody seems to call this. 1279 */ 1280 public String getLine1AlphaTag() { 1281 try { 1282 return getSubscriberInfo().getLine1AlphaTag(); 1283 } catch (RemoteException ex) { 1284 return null; 1285 } catch (NullPointerException ex) { 1286 // This could happen before phone restarts due to crashing 1287 return null; 1288 } 1289 } 1290 1291 /** 1292 * Returns the MSISDN string. 1293 * for a GSM phone. Return null if it is unavailable. 1294 * <p> 1295 * Requires Permission: 1296 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1297 * 1298 * @hide 1299 */ 1300 public String getMsisdn() { 1301 try { 1302 return getSubscriberInfo().getMsisdn(); 1303 } catch (RemoteException ex) { 1304 return null; 1305 } catch (NullPointerException ex) { 1306 // This could happen before phone restarts due to crashing 1307 return null; 1308 } 1309 } 1310 1311 /** 1312 * Returns the voice mail number. Return null if it is unavailable. 1313 * <p> 1314 * Requires Permission: 1315 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1316 */ 1317 public String getVoiceMailNumber() { 1318 try { 1319 return getSubscriberInfo().getVoiceMailNumber(); 1320 } catch (RemoteException ex) { 1321 return null; 1322 } catch (NullPointerException ex) { 1323 // This could happen before phone restarts due to crashing 1324 return null; 1325 } 1326 } 1327 1328 /** 1329 * Returns the complete voice mail number. Return null if it is unavailable. 1330 * <p> 1331 * Requires Permission: 1332 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 1333 * 1334 * @hide 1335 */ 1336 public String getCompleteVoiceMailNumber() { 1337 try { 1338 return getSubscriberInfo().getCompleteVoiceMailNumber(); 1339 } catch (RemoteException ex) { 1340 return null; 1341 } catch (NullPointerException ex) { 1342 // This could happen before phone restarts due to crashing 1343 return null; 1344 } 1345 } 1346 1347 /** 1348 * Returns the voice mail count. Return 0 if unavailable. 1349 * <p> 1350 * Requires Permission: 1351 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1352 * @hide 1353 */ 1354 public int getVoiceMessageCount() { 1355 try { 1356 return getITelephony().getVoiceMessageCount(); 1357 } catch (RemoteException ex) { 1358 return 0; 1359 } catch (NullPointerException ex) { 1360 // This could happen before phone restarts due to crashing 1361 return 0; 1362 } 1363 } 1364 1365 /** 1366 * Retrieves the alphabetic identifier associated with the voice 1367 * mail number. 1368 * <p> 1369 * Requires Permission: 1370 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1371 */ 1372 public String getVoiceMailAlphaTag() { 1373 try { 1374 return getSubscriberInfo().getVoiceMailAlphaTag(); 1375 } catch (RemoteException ex) { 1376 return null; 1377 } catch (NullPointerException ex) { 1378 // This could happen before phone restarts due to crashing 1379 return null; 1380 } 1381 } 1382 1383 /** 1384 * Returns the IMS private user identity (IMPI) that was loaded from the ISIM. 1385 * @return the IMPI, or null if not present or not loaded 1386 * @hide 1387 */ 1388 public String getIsimImpi() { 1389 try { 1390 return getSubscriberInfo().getIsimImpi(); 1391 } catch (RemoteException ex) { 1392 return null; 1393 } catch (NullPointerException ex) { 1394 // This could happen before phone restarts due to crashing 1395 return null; 1396 } 1397 } 1398 1399 /** 1400 * Returns the IMS home network domain name that was loaded from the ISIM. 1401 * @return the IMS domain name, or null if not present or not loaded 1402 * @hide 1403 */ 1404 public String getIsimDomain() { 1405 try { 1406 return getSubscriberInfo().getIsimDomain(); 1407 } catch (RemoteException ex) { 1408 return null; 1409 } catch (NullPointerException ex) { 1410 // This could happen before phone restarts due to crashing 1411 return null; 1412 } 1413 } 1414 1415 /** 1416 * Returns the IMS public user identities (IMPU) that were loaded from the ISIM. 1417 * @return an array of IMPU strings, with one IMPU per string, or null if 1418 * not present or not loaded 1419 * @hide 1420 */ 1421 public String[] getIsimImpu() { 1422 try { 1423 return getSubscriberInfo().getIsimImpu(); 1424 } catch (RemoteException ex) { 1425 return null; 1426 } catch (NullPointerException ex) { 1427 // This could happen before phone restarts due to crashing 1428 return null; 1429 } 1430 } 1431 1432 private IPhoneSubInfo getSubscriberInfo() { 1433 // get it each time because that process crashes a lot 1434 return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo")); 1435 } 1436 1437 1438 /** Device call state: No activity. */ 1439 public static final int CALL_STATE_IDLE = 0; 1440 /** Device call state: Ringing. A new call arrived and is 1441 * ringing or waiting. In the latter case, another call is 1442 * already active. */ 1443 public static final int CALL_STATE_RINGING = 1; 1444 /** Device call state: Off-hook. At least one call exists 1445 * that is dialing, active, or on hold, and no calls are ringing 1446 * or waiting. */ 1447 public static final int CALL_STATE_OFFHOOK = 2; 1448 1449 /** 1450 * Returns a constant indicating the call state (cellular) on the device. 1451 */ 1452 public int getCallState() { 1453 try { 1454 return getITelephony().getCallState(); 1455 } catch (RemoteException ex) { 1456 // the phone process is restarting. 1457 return CALL_STATE_IDLE; 1458 } catch (NullPointerException ex) { 1459 // the phone process is restarting. 1460 return CALL_STATE_IDLE; 1461 } 1462 } 1463 1464 /** Data connection activity: No traffic. */ 1465 public static final int DATA_ACTIVITY_NONE = 0x00000000; 1466 /** Data connection activity: Currently receiving IP PPP traffic. */ 1467 public static final int DATA_ACTIVITY_IN = 0x00000001; 1468 /** Data connection activity: Currently sending IP PPP traffic. */ 1469 public static final int DATA_ACTIVITY_OUT = 0x00000002; 1470 /** Data connection activity: Currently both sending and receiving 1471 * IP PPP traffic. */ 1472 public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT; 1473 /** 1474 * Data connection is active, but physical link is down 1475 */ 1476 public static final int DATA_ACTIVITY_DORMANT = 0x00000004; 1477 1478 /** 1479 * Returns a constant indicating the type of activity on a data connection 1480 * (cellular). 1481 * 1482 * @see #DATA_ACTIVITY_NONE 1483 * @see #DATA_ACTIVITY_IN 1484 * @see #DATA_ACTIVITY_OUT 1485 * @see #DATA_ACTIVITY_INOUT 1486 * @see #DATA_ACTIVITY_DORMANT 1487 */ 1488 public int getDataActivity() { 1489 try { 1490 return getITelephony().getDataActivity(); 1491 } catch (RemoteException ex) { 1492 // the phone process is restarting. 1493 return DATA_ACTIVITY_NONE; 1494 } catch (NullPointerException ex) { 1495 // the phone process is restarting. 1496 return DATA_ACTIVITY_NONE; 1497 } 1498 } 1499 1500 /** Data connection state: Unknown. Used before we know the state. 1501 * @hide 1502 */ 1503 public static final int DATA_UNKNOWN = -1; 1504 /** Data connection state: Disconnected. IP traffic not available. */ 1505 public static final int DATA_DISCONNECTED = 0; 1506 /** Data connection state: Currently setting up a data connection. */ 1507 public static final int DATA_CONNECTING = 1; 1508 /** Data connection state: Connected. IP traffic should be available. */ 1509 public static final int DATA_CONNECTED = 2; 1510 /** Data connection state: Suspended. The connection is up, but IP 1511 * traffic is temporarily unavailable. For example, in a 2G network, 1512 * data activity may be suspended when a voice call arrives. */ 1513 public static final int DATA_SUSPENDED = 3; 1514 1515 /** 1516 * Returns a constant indicating the current data connection state 1517 * (cellular). 1518 * 1519 * @see #DATA_DISCONNECTED 1520 * @see #DATA_CONNECTING 1521 * @see #DATA_CONNECTED 1522 * @see #DATA_SUSPENDED 1523 */ 1524 public int getDataState() { 1525 try { 1526 return getITelephony().getDataState(); 1527 } catch (RemoteException ex) { 1528 // the phone process is restarting. 1529 return DATA_DISCONNECTED; 1530 } catch (NullPointerException ex) { 1531 return DATA_DISCONNECTED; 1532 } 1533 } 1534 1535 private ITelephony getITelephony() { 1536 return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); 1537 } 1538 1539 // 1540 // 1541 // PhoneStateListener 1542 // 1543 // 1544 1545 /** 1546 * Registers a listener object to receive notification of changes 1547 * in specified telephony states. 1548 * <p> 1549 * To register a listener, pass a {@link PhoneStateListener} 1550 * and specify at least one telephony state of interest in 1551 * the events argument. 1552 * 1553 * At registration, and when a specified telephony state 1554 * changes, the telephony manager invokes the appropriate 1555 * callback method on the listener object and passes the 1556 * current (updated) values. 1557 * <p> 1558 * To unregister a listener, pass the listener object and set the 1559 * events argument to 1560 * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0). 1561 * 1562 * @param listener The {@link PhoneStateListener} object to register 1563 * (or unregister) 1564 * @param events The telephony state(s) of interest to the listener, 1565 * as a bitwise-OR combination of {@link PhoneStateListener} 1566 * LISTEN_ flags. 1567 */ 1568 public void listen(PhoneStateListener listener, int events) { 1569 String pkgForDebug = mContext != null ? mContext.getPackageName() : "<unknown>"; 1570 try { 1571 Boolean notifyNow = true; 1572 sRegistry.listen(pkgForDebug, listener.callback, events, notifyNow); 1573 } catch (RemoteException ex) { 1574 // system process dead 1575 } catch (NullPointerException ex) { 1576 // system process dead 1577 } 1578 } 1579 1580 /** 1581 * Returns the CDMA ERI icon index to display 1582 * 1583 * @hide 1584 */ 1585 public int getCdmaEriIconIndex() { 1586 try { 1587 return getITelephony().getCdmaEriIconIndex(); 1588 } catch (RemoteException ex) { 1589 // the phone process is restarting. 1590 return -1; 1591 } catch (NullPointerException ex) { 1592 return -1; 1593 } 1594 } 1595 1596 /** 1597 * Returns the CDMA ERI icon mode, 1598 * 0 - ON 1599 * 1 - FLASHING 1600 * 1601 * @hide 1602 */ 1603 public int getCdmaEriIconMode() { 1604 try { 1605 return getITelephony().getCdmaEriIconMode(); 1606 } catch (RemoteException ex) { 1607 // the phone process is restarting. 1608 return -1; 1609 } catch (NullPointerException ex) { 1610 return -1; 1611 } 1612 } 1613 1614 /** 1615 * Returns the CDMA ERI text, 1616 * 1617 * @hide 1618 */ 1619 public String getCdmaEriText() { 1620 try { 1621 return getITelephony().getCdmaEriText(); 1622 } catch (RemoteException ex) { 1623 // the phone process is restarting. 1624 return null; 1625 } catch (NullPointerException ex) { 1626 return null; 1627 } 1628 } 1629 1630 /** 1631 * @return true if the current device is "voice capable". 1632 * <p> 1633 * "Voice capable" means that this device supports circuit-switched 1634 * (i.e. voice) phone calls over the telephony network, and is allowed 1635 * to display the in-call UI while a cellular voice call is active. 1636 * This will be false on "data only" devices which can't make voice 1637 * calls and don't support any in-call UI. 1638 * <p> 1639 * Note: the meaning of this flag is subtly different from the 1640 * PackageManager.FEATURE_TELEPHONY system feature, which is available 1641 * on any device with a telephony radio, even if the device is 1642 * data-only. 1643 * 1644 * @hide pending API review 1645 */ 1646 public boolean isVoiceCapable() { 1647 if (mContext == null) return true; 1648 return mContext.getResources().getBoolean( 1649 com.android.internal.R.bool.config_voice_capable); 1650 } 1651 1652 /** 1653 * @return true if the current device supports sms service. 1654 * <p> 1655 * If true, this means that the device supports both sending and 1656 * receiving sms via the telephony network. 1657 * <p> 1658 * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are 1659 * disabled when device doesn't support sms. 1660 * 1661 * @hide pending API review 1662 */ 1663 public boolean isSmsCapable() { 1664 if (mContext == null) return true; 1665 return mContext.getResources().getBoolean( 1666 com.android.internal.R.bool.config_sms_capable); 1667 } 1668 1669 /** 1670 * Returns all observed cell information from all radios on the 1671 * device including the primary and neighboring cells. This does 1672 * not cause or change the rate of PhoneStateListner#onCellInfoChanged. 1673 *<p> 1674 * The list can include one or more of {@link android.telephony.CellInfoGsm CellInfoGsm}, 1675 * {@link android.telephony.CellInfoCdma CellInfoCdma}, 1676 * {@link android.telephony.CellInfoLte CellInfoLte} and 1677 * {@link android.telephony.CellInfoWcdma CellInfoCdma} in any combination. 1678 * Specifically on devices with multiple radios it is typical to see instances of 1679 * one or more of any these in the list. In addition 0, 1 or more CellInfo 1680 * objects may return isRegistered() true. 1681 *<p> 1682 * This is preferred over using getCellLocation although for older 1683 * devices this may return null in which case getCellLocation should 1684 * be called. 1685 *<p> 1686 * @return List of CellInfo or null if info unavailable. 1687 * 1688 * <p>Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} 1689 */ 1690 public List<CellInfo> getAllCellInfo() { 1691 try { 1692 return getITelephony().getAllCellInfo(); 1693 } catch (RemoteException ex) { 1694 return null; 1695 } catch (NullPointerException ex) { 1696 return null; 1697 } 1698 } 1699 1700 /** 1701 * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged 1702 * PhoneStateListener.onCellInfoChanged} will be invoked. 1703 *<p> 1704 * The default, 0, means invoke onCellInfoChanged when any of the reported 1705 * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue 1706 * A onCellInfoChanged. 1707 *<p> 1708 * @param rateInMillis the rate 1709 * 1710 * @hide 1711 */ 1712 public void setCellInfoListRate(int rateInMillis) { 1713 try { 1714 getITelephony().setCellInfoListRate(rateInMillis); 1715 } catch (RemoteException ex) { 1716 } catch (NullPointerException ex) { 1717 } 1718 } 1719 1720 /** 1721 * Returns the MMS user agent. 1722 */ 1723 public String getMmsUserAgent() { 1724 if (mContext == null) return null; 1725 return mContext.getResources().getString( 1726 com.android.internal.R.string.config_mms_user_agent); 1727 } 1728 1729 /** 1730 * Returns the MMS user agent profile URL. 1731 */ 1732 public String getMmsUAProfUrl() { 1733 if (mContext == null) return null; 1734 return mContext.getResources().getString( 1735 com.android.internal.R.string.config_mms_user_agent_profile_url); 1736 } 1737 1738 /** 1739 * Opens a logical channel to the ICC card. 1740 * 1741 * Input parameters equivalent to TS 27.007 AT+CCHO command. 1742 * 1743 * <p>Requires Permission: 1744 * {@link android.Manifest.permission#SIM_COMMUNICATION SIM_COMMUNICATION} 1745 * 1746 * @param AID Application id. See ETSI 102.221 and 101.220. 1747 * @return The logical channel id which is negative on error. 1748 */ 1749 public int iccOpenLogicalChannel(String AID) { 1750 try { 1751 return getITelephony().iccOpenLogicalChannel(AID); 1752 } catch (RemoteException ex) { 1753 } catch (NullPointerException ex) { 1754 } 1755 return -1; 1756 } 1757 1758 /** 1759 * Closes a previously opened logical channel to the ICC card. 1760 * 1761 * Input parameters equivalent to TS 27.007 AT+CCHC command. 1762 * 1763 * <p>Requires Permission: 1764 * {@link android.Manifest.permission#SIM_COMMUNICATION SIM_COMMUNICATION} 1765 * 1766 * @param channel is the channel id to be closed as retruned by a successful 1767 * iccOpenLogicalChannel. 1768 * @return true if the channel was closed successfully. 1769 */ 1770 public boolean iccCloseLogicalChannel(int channel) { 1771 try { 1772 return getITelephony().iccCloseLogicalChannel(channel); 1773 } catch (RemoteException ex) { 1774 } catch (NullPointerException ex) { 1775 } 1776 return false; 1777 } 1778 1779 /** 1780 * Transmit an APDU to the ICC card over a logical channel. 1781 * 1782 * Input parameters equivalent to TS 27.007 AT+CGLA command. 1783 * 1784 * <p>Requires Permission: 1785 * {@link android.Manifest.permission#SIM_COMMUNICATION SIM_COMMUNICATION} 1786 * 1787 * @param channel is the channel id to be closed as returned by a successful 1788 * iccOpenLogicalChannel. 1789 * @param cla Class of the APDU command. 1790 * @param instruction Instruction of the APDU command. 1791 * @param p1 P1 value of the APDU command. 1792 * @param p2 P2 value of the APDU command. 1793 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 1794 * is sent to the SIM. 1795 * @param data Data to be sent with the APDU. 1796 * @return The APDU response from the ICC card with the status appended at 1797 * the end. If an error occurs, an empty string is returned. 1798 */ 1799 public String iccTransmitApduLogicalChannel(int channel, int cla, 1800 int instruction, int p1, int p2, int p3, String data) { 1801 try { 1802 return getITelephony().iccTransmitApduLogicalChannel(channel, cla, 1803 instruction, p1, p2, p3, data); 1804 } catch (RemoteException ex) { 1805 } catch (NullPointerException ex) { 1806 } 1807 return ""; 1808 } 1809 1810 /** 1811 * Send ENVELOPE to the SIM and return the response. 1812 * 1813 * <p>Requires Permission: 1814 * {@link android.Manifest.permission#SIM_COMMUNICATION SIM_COMMUNICATION} 1815 * 1816 * @param content String containing SAT/USAT response in hexadecimal 1817 * format starting with command tag. See TS 102 223 for 1818 * details. 1819 * @return The APDU response from the ICC card, with the last 4 bytes 1820 * being the status word. If the command fails, returns an empty 1821 * string. 1822 */ 1823 public String sendEnvelopeWithStatus(String content) { 1824 try { 1825 return getITelephony().sendEnvelopeWithStatus(content); 1826 } catch (RemoteException ex) { 1827 } catch (NullPointerException ex) { 1828 } 1829 return ""; 1830 } 1831 1832 /** 1833 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}. 1834 * Used for device configuration by some CDMA operators. 1835 * 1836 * @param itemID the ID of the item to read. 1837 * @return the NV item as a String, or null on any failure. 1838 * @hide 1839 */ 1840 public String nvReadItem(int itemID) { 1841 try { 1842 return getITelephony().nvReadItem(itemID); 1843 } catch (RemoteException ex) { 1844 Rlog.e(TAG, "nvReadItem RemoteException", ex); 1845 } catch (NullPointerException ex) { 1846 Rlog.e(TAG, "nvReadItem NPE", ex); 1847 } 1848 return ""; 1849 } 1850 1851 1852 /** 1853 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}. 1854 * Used for device configuration by some CDMA operators. 1855 * 1856 * @param itemID the ID of the item to read. 1857 * @param itemValue the value to write, as a String. 1858 * @return true on success; false on any failure. 1859 * @hide 1860 */ 1861 public boolean nvWriteItem(int itemID, String itemValue) { 1862 try { 1863 return getITelephony().nvWriteItem(itemID, itemValue); 1864 } catch (RemoteException ex) { 1865 Rlog.e(TAG, "nvWriteItem RemoteException", ex); 1866 } catch (NullPointerException ex) { 1867 Rlog.e(TAG, "nvWriteItem NPE", ex); 1868 } 1869 return false; 1870 } 1871 1872 /** 1873 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. 1874 * Used for device configuration by some CDMA operators. 1875 * 1876 * @param preferredRoamingList byte array containing the new PRL. 1877 * @return true on success; false on any failure. 1878 * @hide 1879 */ 1880 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { 1881 try { 1882 return getITelephony().nvWriteCdmaPrl(preferredRoamingList); 1883 } catch (RemoteException ex) { 1884 Rlog.e(TAG, "nvWriteCdmaPrl RemoteException", ex); 1885 } catch (NullPointerException ex) { 1886 Rlog.e(TAG, "nvWriteCdmaPrl NPE", ex); 1887 } 1888 return false; 1889 } 1890 1891 /** 1892 * Perform the specified type of NV config reset. The radio will be taken offline 1893 * and the device must be rebooted after the operation. Used for device 1894 * configuration by some CDMA operators. 1895 * 1896 * @param resetType reset type: 1: reload NV reset, 2: erase NV reset, 3: factory NV reset 1897 * @return true on success; false on any failure. 1898 * @hide 1899 */ 1900 public boolean nvResetConfig(int resetType) { 1901 try { 1902 return getITelephony().nvResetConfig(resetType); 1903 } catch (RemoteException ex) { 1904 Rlog.e(TAG, "nvResetConfig RemoteException", ex); 1905 } catch (NullPointerException ex) { 1906 Rlog.e(TAG, "nvResetConfig NPE", ex); 1907 } 1908 return false; 1909 } 1910 1911 /** 1912 * Get the preferred network type. 1913 * Used for device configuration by some CDMA operators. 1914 * 1915 * @return the preferred network type, defined in RILConstants.java. 1916 * @hide 1917 */ 1918 public int getPreferredNetworkType() { 1919 try { 1920 return getITelephony().getPreferredNetworkType(); 1921 } catch (RemoteException ex) { 1922 Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex); 1923 } catch (NullPointerException ex) { 1924 Rlog.e(TAG, "getPreferredNetworkType NPE", ex); 1925 } 1926 return -1; 1927 } 1928 1929 /** 1930 * Set the preferred network type. 1931 * Used for device configuration by some CDMA operators. 1932 * 1933 * @param networkType the preferred network type, defined in RILConstants.java. 1934 * @return true on success; false on any failure. 1935 * @hide 1936 */ 1937 public boolean setPreferredNetworkType(int networkType) { 1938 try { 1939 return getITelephony().setPreferredNetworkType(networkType); 1940 } catch (RemoteException ex) { 1941 Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex); 1942 } catch (NullPointerException ex) { 1943 Rlog.e(TAG, "setPreferredNetworkType NPE", ex); 1944 } 1945 return false; 1946 } 1947 1948 /** 1949 * Expose the rest of ITelephony to @PrivateApi 1950 */ 1951 1952 /** @hide */ 1953 @PrivateApi 1954 public void dial(String number) { 1955 try { 1956 getITelephony().dial(number); 1957 } catch (RemoteException e) { 1958 Log.e(TAG, "Error calling ITelephony#dial", e); 1959 } 1960 } 1961 1962 /** @hide */ 1963 @PrivateApi 1964 public void call(String callingPackage, String number) { 1965 try { 1966 getITelephony().call(callingPackage, number); 1967 } catch (RemoteException e) { 1968 Log.e(TAG, "Error calling ITelephony#call", e); 1969 } 1970 } 1971 1972 /** @hide */ 1973 @PrivateApi 1974 public boolean showCallScreen() { 1975 try { 1976 return getITelephony().showCallScreen(); 1977 } catch (RemoteException e) { 1978 Log.e(TAG, "Error calling ITelephony#showCallScreen", e); 1979 } 1980 return false; 1981 } 1982 1983 /** @hide */ 1984 @PrivateApi 1985 public boolean showCallScreenWithDialpad(boolean showDialpad) { 1986 try { 1987 return getITelephony().showCallScreenWithDialpad(showDialpad); 1988 } catch (RemoteException e) { 1989 Log.e(TAG, "Error calling ITelephony#showCallScreenWithDialpad", e); 1990 } 1991 return false; 1992 } 1993 1994 /** @hide */ 1995 @PrivateApi 1996 public boolean endCall() { 1997 try { 1998 return getITelephony().endCall(); 1999 } catch (RemoteException e) { 2000 Log.e(TAG, "Error calling ITelephony#endCall", e); 2001 } 2002 return false; 2003 } 2004 2005 /** @hide */ 2006 @PrivateApi 2007 public void answerRingingCall() { 2008 try { 2009 getITelephony().answerRingingCall(); 2010 } catch (RemoteException e) { 2011 Log.e(TAG, "Error calling ITelephony#answerRingingCall", e); 2012 } 2013 } 2014 2015 /** @hide */ 2016 @PrivateApi 2017 public void silenceRinger() { 2018 try { 2019 getITelephony().silenceRinger(); 2020 } catch (RemoteException e) { 2021 Log.e(TAG, "Error calling ITelephony#silenceRinger", e); 2022 } 2023 } 2024 2025 /** @hide */ 2026 @PrivateApi 2027 public boolean isOffhook() { 2028 try { 2029 return getITelephony().isOffhook(); 2030 } catch (RemoteException e) { 2031 Log.e(TAG, "Error calling ITelephony#isOffhook", e); 2032 } 2033 return false; 2034 } 2035 2036 /** @hide */ 2037 @PrivateApi 2038 public boolean isRinging() { 2039 try { 2040 return getITelephony().isRinging(); 2041 } catch (RemoteException e) { 2042 Log.e(TAG, "Error calling ITelephony#isRinging", e); 2043 } 2044 return false; 2045 } 2046 2047 /** @hide */ 2048 @PrivateApi 2049 public boolean isIdle() { 2050 try { 2051 return getITelephony().isIdle(); 2052 } catch (RemoteException e) { 2053 Log.e(TAG, "Error calling ITelephony#isIdle", e); 2054 } 2055 return true; 2056 } 2057 2058 /** @hide */ 2059 @PrivateApi 2060 public boolean isRadioOn() { 2061 try { 2062 return getITelephony().isRadioOn(); 2063 } catch (RemoteException e) { 2064 Log.e(TAG, "Error calling ITelephony#isRadioOn", e); 2065 } 2066 return false; 2067 } 2068 2069 /** @hide */ 2070 @PrivateApi 2071 public boolean isSimPinEnabled() { 2072 try { 2073 return getITelephony().isSimPinEnabled(); 2074 } catch (RemoteException e) { 2075 Log.e(TAG, "Error calling ITelephony#isSimPinEnabled", e); 2076 } 2077 return false; 2078 } 2079 2080 /** @hide */ 2081 @PrivateApi 2082 public void cancelMissedCallsNotification() { 2083 try { 2084 getITelephony().cancelMissedCallsNotification(); 2085 } catch (RemoteException e) { 2086 Log.e(TAG, "Error calling ITelephony#cancelMissedCallsNotification", e); 2087 } 2088 } 2089 2090 /** @hide */ 2091 @PrivateApi 2092 public boolean supplyPin(String pin) { 2093 try { 2094 return getITelephony().supplyPin(pin); 2095 } catch (RemoteException e) { 2096 Log.e(TAG, "Error calling ITelephony#supplyPin", e); 2097 } 2098 return false; 2099 } 2100 2101 /** @hide */ 2102 @PrivateApi 2103 public boolean supplyPuk(String puk, String pin) { 2104 try { 2105 return getITelephony().supplyPuk(puk, pin); 2106 } catch (RemoteException e) { 2107 Log.e(TAG, "Error calling ITelephony#supplyPuk", e); 2108 } 2109 return false; 2110 } 2111 2112 /** @hide */ 2113 @PrivateApi 2114 public int[] supplyPinReportResult(String pin) { 2115 try { 2116 return getITelephony().supplyPinReportResult(pin); 2117 } catch (RemoteException e) { 2118 Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e); 2119 } 2120 return new int[0]; 2121 } 2122 2123 /** @hide */ 2124 @PrivateApi 2125 public int[] supplyPukReportResult(String puk, String pin) { 2126 try { 2127 return getITelephony().supplyPukReportResult(puk, pin); 2128 } catch (RemoteException e) { 2129 Log.e(TAG, "Error calling ITelephony#]", e); 2130 } 2131 return new int[0]; 2132 } 2133 2134 /** @hide */ 2135 @PrivateApi 2136 public boolean handlePinMmi(String dialString) { 2137 try { 2138 return getITelephony().handlePinMmi(dialString); 2139 } catch (RemoteException e) { 2140 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 2141 } 2142 return false; 2143 } 2144 2145 /** @hide */ 2146 @PrivateApi 2147 public void toggleRadioOnOff() { 2148 try { 2149 getITelephony().toggleRadioOnOff(); 2150 } catch (RemoteException e) { 2151 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 2152 } 2153 } 2154 2155 /** @hide */ 2156 @PrivateApi 2157 public boolean setRadio(boolean turnOn) { 2158 try { 2159 return getITelephony().setRadio(turnOn); 2160 } catch (RemoteException e) { 2161 Log.e(TAG, "Error calling ITelephony#setRadio", e); 2162 } 2163 return false; 2164 } 2165 2166 /** @hide */ 2167 @PrivateApi 2168 public boolean setRadioPower(boolean turnOn) { 2169 try { 2170 return getITelephony().setRadioPower(turnOn); 2171 } catch (RemoteException e) { 2172 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 2173 } 2174 return false; 2175 } 2176 2177 /** @hide */ 2178 @PrivateApi 2179 public void updateServiceLocation() { 2180 try { 2181 getITelephony().updateServiceLocation(); 2182 } catch (RemoteException e) { 2183 Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e); 2184 } 2185 } 2186 2187 /** @hide */ 2188 @PrivateApi 2189 public int enableApnType(String type) { 2190 try { 2191 return getITelephony().enableApnType(type); 2192 } catch (RemoteException e) { 2193 Log.e(TAG, "Error calling ITelephony#enableApnType", e); 2194 } 2195 return PhoneConstants.APN_REQUEST_FAILED; 2196 } 2197 2198 /** @hide */ 2199 @PrivateApi 2200 public int disableApnType(String type) { 2201 try { 2202 return getITelephony().disableApnType(type); 2203 } catch (RemoteException e) { 2204 Log.e(TAG, "Error calling ITelephony#disableApnType", e); 2205 } 2206 return PhoneConstants.APN_REQUEST_FAILED; 2207 } 2208 2209 /** @hide */ 2210 @PrivateApi 2211 public boolean enableDataConnectivity() { 2212 try { 2213 return getITelephony().enableDataConnectivity(); 2214 } catch (RemoteException e) { 2215 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 2216 } 2217 return false; 2218 } 2219 2220 /** @hide */ 2221 @PrivateApi 2222 public boolean disableDataConnectivity() { 2223 try { 2224 return getITelephony().disableDataConnectivity(); 2225 } catch (RemoteException e) { 2226 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 2227 } 2228 return false; 2229 } 2230 2231 /** @hide */ 2232 @PrivateApi 2233 public boolean isDataConnectivityPossible() { 2234 try { 2235 return getITelephony().isDataConnectivityPossible(); 2236 } catch (RemoteException e) { 2237 Log.e(TAG, "Error calling ITelephony#isDataConnectivityPossible", e); 2238 } 2239 return false; 2240 } 2241 2242 /** @hide */ 2243 @PrivateApi 2244 public boolean needsOtaServiceProvisioning() { 2245 try { 2246 return getITelephony().needsOtaServiceProvisioning(); 2247 } catch (RemoteException e) { 2248 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 2249 } 2250 return false; 2251 } 2252} 2253