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