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