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