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