TelephonyManager.java revision ae166fe9e074de30c24f5bd567f6404b50cd9cfa
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 /** SIM card state: SIM Card Error, Sim Card is present but faulty 1098 *@hide 1099 */ 1100 public static final int SIM_STATE_CARD_IO_ERROR = 6; 1101 1102 /** 1103 * @return true if a ICC card is present 1104 */ 1105 public boolean hasIccCard() { 1106 try { 1107 return getITelephony().hasIccCard(); 1108 } catch (RemoteException ex) { 1109 // Assume no ICC card if remote exception which shouldn't happen 1110 return false; 1111 } catch (NullPointerException ex) { 1112 // This could happen before phone restarts due to crashing 1113 return false; 1114 } 1115 } 1116 1117 /** 1118 * Returns a constant indicating the state of the 1119 * device SIM card. 1120 * 1121 * @see #SIM_STATE_UNKNOWN 1122 * @see #SIM_STATE_ABSENT 1123 * @see #SIM_STATE_PIN_REQUIRED 1124 * @see #SIM_STATE_PUK_REQUIRED 1125 * @see #SIM_STATE_NETWORK_LOCKED 1126 * @see #SIM_STATE_READY 1127 * @see #SIM_STATE_CARD_IO_ERROR 1128 */ 1129 public int getSimState() { 1130 String prop = SystemProperties.get(TelephonyProperties.PROPERTY_SIM_STATE); 1131 if ("ABSENT".equals(prop)) { 1132 return SIM_STATE_ABSENT; 1133 } 1134 else if ("PIN_REQUIRED".equals(prop)) { 1135 return SIM_STATE_PIN_REQUIRED; 1136 } 1137 else if ("PUK_REQUIRED".equals(prop)) { 1138 return SIM_STATE_PUK_REQUIRED; 1139 } 1140 else if ("NETWORK_LOCKED".equals(prop)) { 1141 return SIM_STATE_NETWORK_LOCKED; 1142 } 1143 else if ("READY".equals(prop)) { 1144 return SIM_STATE_READY; 1145 } 1146 else if ("CARD_IO_ERROR".equals(prop)) { 1147 return SIM_STATE_CARD_IO_ERROR; 1148 } 1149 else { 1150 return SIM_STATE_UNKNOWN; 1151 } 1152 } 1153 1154 /** 1155 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1156 * provider of the SIM. 5 or 6 decimal digits. 1157 * <p> 1158 * Availability: SIM state must be {@link #SIM_STATE_READY} 1159 * 1160 * @see #getSimState 1161 */ 1162 public String getSimOperator() { 1163 return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC); 1164 } 1165 1166 /** 1167 * Returns the Service Provider Name (SPN). 1168 * <p> 1169 * Availability: SIM state must be {@link #SIM_STATE_READY} 1170 * 1171 * @see #getSimState 1172 */ 1173 public String getSimOperatorName() { 1174 return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA); 1175 } 1176 1177 /** 1178 * Returns the ISO country code equivalent for the SIM provider's country code. 1179 */ 1180 public String getSimCountryIso() { 1181 return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY); 1182 } 1183 1184 /** 1185 * Returns the serial number of the SIM, if applicable. Return null if it is 1186 * unavailable. 1187 * <p> 1188 * Requires Permission: 1189 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1190 */ 1191 public String getSimSerialNumber() { 1192 try { 1193 return getSubscriberInfo().getIccSerialNumber(); 1194 } catch (RemoteException ex) { 1195 return null; 1196 } catch (NullPointerException ex) { 1197 // This could happen before phone restarts due to crashing 1198 return null; 1199 } 1200 } 1201 1202 /** 1203 * Return if the current radio is LTE on CDMA. This 1204 * is a tri-state return value as for a period of time 1205 * the mode may be unknown. 1206 * 1207 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 1208 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 1209 * 1210 * @hide 1211 */ 1212 public int getLteOnCdmaMode() { 1213 try { 1214 return getITelephony().getLteOnCdmaMode(); 1215 } catch (RemoteException ex) { 1216 // Assume no ICC card if remote exception which shouldn't happen 1217 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 1218 } catch (NullPointerException ex) { 1219 // This could happen before phone restarts due to crashing 1220 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 1221 } 1222 } 1223 1224 // 1225 // 1226 // Subscriber Info 1227 // 1228 // 1229 1230 /** 1231 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone. 1232 * Return null if it is unavailable. 1233 * <p> 1234 * Requires Permission: 1235 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1236 */ 1237 public String getSubscriberId() { 1238 try { 1239 return getSubscriberInfo().getSubscriberId(); 1240 } catch (RemoteException ex) { 1241 return null; 1242 } catch (NullPointerException ex) { 1243 // This could happen before phone restarts due to crashing 1244 return null; 1245 } 1246 } 1247 1248 /** 1249 * Returns the Group Identifier Level1 for a GSM phone. 1250 * Return null if it is unavailable. 1251 * <p> 1252 * Requires Permission: 1253 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1254 */ 1255 public String getGroupIdLevel1() { 1256 try { 1257 return getSubscriberInfo().getGroupIdLevel1(); 1258 } catch (RemoteException ex) { 1259 return null; 1260 } catch (NullPointerException ex) { 1261 // This could happen before phone restarts due to crashing 1262 return null; 1263 } 1264 } 1265 1266 /** 1267 * Returns the phone number string for line 1, for example, the MSISDN 1268 * for a GSM phone. Return null if it is unavailable. 1269 * <p> 1270 * Requires Permission: 1271 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1272 */ 1273 public String getLine1Number() { 1274 try { 1275 return getSubscriberInfo().getLine1Number(); 1276 } catch (RemoteException ex) { 1277 return null; 1278 } catch (NullPointerException ex) { 1279 // This could happen before phone restarts due to crashing 1280 return null; 1281 } 1282 } 1283 1284 /** 1285 * Returns the alphabetic identifier associated with the line 1 number. 1286 * Return null if it is unavailable. 1287 * <p> 1288 * Requires Permission: 1289 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1290 * @hide 1291 * nobody seems to call this. 1292 */ 1293 public String getLine1AlphaTag() { 1294 try { 1295 return getSubscriberInfo().getLine1AlphaTag(); 1296 } catch (RemoteException ex) { 1297 return null; 1298 } catch (NullPointerException ex) { 1299 // This could happen before phone restarts due to crashing 1300 return null; 1301 } 1302 } 1303 1304 /** 1305 * Returns the MSISDN string. 1306 * for a GSM phone. Return null if it is unavailable. 1307 * <p> 1308 * Requires Permission: 1309 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1310 * 1311 * @hide 1312 */ 1313 public String getMsisdn() { 1314 try { 1315 return getSubscriberInfo().getMsisdn(); 1316 } catch (RemoteException ex) { 1317 return null; 1318 } catch (NullPointerException ex) { 1319 // This could happen before phone restarts due to crashing 1320 return null; 1321 } 1322 } 1323 1324 /** 1325 * Returns the voice mail number. Return null if it is unavailable. 1326 * <p> 1327 * Requires Permission: 1328 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1329 */ 1330 public String getVoiceMailNumber() { 1331 try { 1332 return getSubscriberInfo().getVoiceMailNumber(); 1333 } catch (RemoteException ex) { 1334 return null; 1335 } catch (NullPointerException ex) { 1336 // This could happen before phone restarts due to crashing 1337 return null; 1338 } 1339 } 1340 1341 /** 1342 * Returns the complete voice mail number. Return null if it is unavailable. 1343 * <p> 1344 * Requires Permission: 1345 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 1346 * 1347 * @hide 1348 */ 1349 public String getCompleteVoiceMailNumber() { 1350 try { 1351 return getSubscriberInfo().getCompleteVoiceMailNumber(); 1352 } catch (RemoteException ex) { 1353 return null; 1354 } catch (NullPointerException ex) { 1355 // This could happen before phone restarts due to crashing 1356 return null; 1357 } 1358 } 1359 1360 /** 1361 * Returns the voice mail count. Return 0 if unavailable. 1362 * <p> 1363 * Requires Permission: 1364 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1365 * @hide 1366 */ 1367 public int getVoiceMessageCount() { 1368 try { 1369 return getITelephony().getVoiceMessageCount(); 1370 } catch (RemoteException ex) { 1371 return 0; 1372 } catch (NullPointerException ex) { 1373 // This could happen before phone restarts due to crashing 1374 return 0; 1375 } 1376 } 1377 1378 /** 1379 * Retrieves the alphabetic identifier associated with the voice 1380 * mail number. 1381 * <p> 1382 * Requires Permission: 1383 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1384 */ 1385 public String getVoiceMailAlphaTag() { 1386 try { 1387 return getSubscriberInfo().getVoiceMailAlphaTag(); 1388 } catch (RemoteException ex) { 1389 return null; 1390 } catch (NullPointerException ex) { 1391 // This could happen before phone restarts due to crashing 1392 return null; 1393 } 1394 } 1395 1396 /** 1397 * Returns the IMS private user identity (IMPI) that was loaded from the ISIM. 1398 * @return the IMPI, or null if not present or not loaded 1399 * @hide 1400 */ 1401 public String getIsimImpi() { 1402 try { 1403 return getSubscriberInfo().getIsimImpi(); 1404 } catch (RemoteException ex) { 1405 return null; 1406 } catch (NullPointerException ex) { 1407 // This could happen before phone restarts due to crashing 1408 return null; 1409 } 1410 } 1411 1412 /** 1413 * Returns the IMS home network domain name that was loaded from the ISIM. 1414 * @return the IMS domain name, or null if not present or not loaded 1415 * @hide 1416 */ 1417 public String getIsimDomain() { 1418 try { 1419 return getSubscriberInfo().getIsimDomain(); 1420 } catch (RemoteException ex) { 1421 return null; 1422 } catch (NullPointerException ex) { 1423 // This could happen before phone restarts due to crashing 1424 return null; 1425 } 1426 } 1427 1428 /** 1429 * Returns the IMS public user identities (IMPU) that were loaded from the ISIM. 1430 * @return an array of IMPU strings, with one IMPU per string, or null if 1431 * not present or not loaded 1432 * @hide 1433 */ 1434 public String[] getIsimImpu() { 1435 try { 1436 return getSubscriberInfo().getIsimImpu(); 1437 } catch (RemoteException ex) { 1438 return null; 1439 } catch (NullPointerException ex) { 1440 // This could happen before phone restarts due to crashing 1441 return null; 1442 } 1443 } 1444 1445 private IPhoneSubInfo getSubscriberInfo() { 1446 // get it each time because that process crashes a lot 1447 return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo")); 1448 } 1449 1450 1451 /** Device call state: No activity. */ 1452 public static final int CALL_STATE_IDLE = 0; 1453 /** Device call state: Ringing. A new call arrived and is 1454 * ringing or waiting. In the latter case, another call is 1455 * already active. */ 1456 public static final int CALL_STATE_RINGING = 1; 1457 /** Device call state: Off-hook. At least one call exists 1458 * that is dialing, active, or on hold, and no calls are ringing 1459 * or waiting. */ 1460 public static final int CALL_STATE_OFFHOOK = 2; 1461 1462 /** 1463 * Returns a constant indicating the call state (cellular) on the device. 1464 */ 1465 public int getCallState() { 1466 try { 1467 return getITelephony().getCallState(); 1468 } catch (RemoteException ex) { 1469 // the phone process is restarting. 1470 return CALL_STATE_IDLE; 1471 } catch (NullPointerException ex) { 1472 // the phone process is restarting. 1473 return CALL_STATE_IDLE; 1474 } 1475 } 1476 1477 /** Data connection activity: No traffic. */ 1478 public static final int DATA_ACTIVITY_NONE = 0x00000000; 1479 /** Data connection activity: Currently receiving IP PPP traffic. */ 1480 public static final int DATA_ACTIVITY_IN = 0x00000001; 1481 /** Data connection activity: Currently sending IP PPP traffic. */ 1482 public static final int DATA_ACTIVITY_OUT = 0x00000002; 1483 /** Data connection activity: Currently both sending and receiving 1484 * IP PPP traffic. */ 1485 public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT; 1486 /** 1487 * Data connection is active, but physical link is down 1488 */ 1489 public static final int DATA_ACTIVITY_DORMANT = 0x00000004; 1490 1491 /** 1492 * Returns a constant indicating the type of activity on a data connection 1493 * (cellular). 1494 * 1495 * @see #DATA_ACTIVITY_NONE 1496 * @see #DATA_ACTIVITY_IN 1497 * @see #DATA_ACTIVITY_OUT 1498 * @see #DATA_ACTIVITY_INOUT 1499 * @see #DATA_ACTIVITY_DORMANT 1500 */ 1501 public int getDataActivity() { 1502 try { 1503 return getITelephony().getDataActivity(); 1504 } catch (RemoteException ex) { 1505 // the phone process is restarting. 1506 return DATA_ACTIVITY_NONE; 1507 } catch (NullPointerException ex) { 1508 // the phone process is restarting. 1509 return DATA_ACTIVITY_NONE; 1510 } 1511 } 1512 1513 /** Data connection state: Unknown. Used before we know the state. 1514 * @hide 1515 */ 1516 public static final int DATA_UNKNOWN = -1; 1517 /** Data connection state: Disconnected. IP traffic not available. */ 1518 public static final int DATA_DISCONNECTED = 0; 1519 /** Data connection state: Currently setting up a data connection. */ 1520 public static final int DATA_CONNECTING = 1; 1521 /** Data connection state: Connected. IP traffic should be available. */ 1522 public static final int DATA_CONNECTED = 2; 1523 /** Data connection state: Suspended. The connection is up, but IP 1524 * traffic is temporarily unavailable. For example, in a 2G network, 1525 * data activity may be suspended when a voice call arrives. */ 1526 public static final int DATA_SUSPENDED = 3; 1527 1528 /** 1529 * Returns a constant indicating the current data connection state 1530 * (cellular). 1531 * 1532 * @see #DATA_DISCONNECTED 1533 * @see #DATA_CONNECTING 1534 * @see #DATA_CONNECTED 1535 * @see #DATA_SUSPENDED 1536 */ 1537 public int getDataState() { 1538 try { 1539 return getITelephony().getDataState(); 1540 } catch (RemoteException ex) { 1541 // the phone process is restarting. 1542 return DATA_DISCONNECTED; 1543 } catch (NullPointerException ex) { 1544 return DATA_DISCONNECTED; 1545 } 1546 } 1547 1548 private ITelephony getITelephony() { 1549 return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); 1550 } 1551 1552 // 1553 // 1554 // PhoneStateListener 1555 // 1556 // 1557 1558 /** 1559 * Registers a listener object to receive notification of changes 1560 * in specified telephony states. 1561 * <p> 1562 * To register a listener, pass a {@link PhoneStateListener} 1563 * and specify at least one telephony state of interest in 1564 * the events argument. 1565 * 1566 * At registration, and when a specified telephony state 1567 * changes, the telephony manager invokes the appropriate 1568 * callback method on the listener object and passes the 1569 * current (updated) values. 1570 * <p> 1571 * To unregister a listener, pass the listener object and set the 1572 * events argument to 1573 * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0). 1574 * 1575 * @param listener The {@link PhoneStateListener} object to register 1576 * (or unregister) 1577 * @param events The telephony state(s) of interest to the listener, 1578 * as a bitwise-OR combination of {@link PhoneStateListener} 1579 * LISTEN_ flags. 1580 */ 1581 public void listen(PhoneStateListener listener, int events) { 1582 String pkgForDebug = mContext != null ? mContext.getPackageName() : "<unknown>"; 1583 try { 1584 Boolean notifyNow = true; 1585 sRegistry.listen(pkgForDebug, listener.callback, events, notifyNow); 1586 } catch (RemoteException ex) { 1587 // system process dead 1588 } catch (NullPointerException ex) { 1589 // system process dead 1590 } 1591 } 1592 1593 /** 1594 * Returns the CDMA ERI icon index to display 1595 * 1596 * @hide 1597 */ 1598 public int getCdmaEriIconIndex() { 1599 try { 1600 return getITelephony().getCdmaEriIconIndex(); 1601 } catch (RemoteException ex) { 1602 // the phone process is restarting. 1603 return -1; 1604 } catch (NullPointerException ex) { 1605 return -1; 1606 } 1607 } 1608 1609 /** 1610 * Returns the CDMA ERI icon mode, 1611 * 0 - ON 1612 * 1 - FLASHING 1613 * 1614 * @hide 1615 */ 1616 public int getCdmaEriIconMode() { 1617 try { 1618 return getITelephony().getCdmaEriIconMode(); 1619 } catch (RemoteException ex) { 1620 // the phone process is restarting. 1621 return -1; 1622 } catch (NullPointerException ex) { 1623 return -1; 1624 } 1625 } 1626 1627 /** 1628 * Returns the CDMA ERI text, 1629 * 1630 * @hide 1631 */ 1632 public String getCdmaEriText() { 1633 try { 1634 return getITelephony().getCdmaEriText(); 1635 } catch (RemoteException ex) { 1636 // the phone process is restarting. 1637 return null; 1638 } catch (NullPointerException ex) { 1639 return null; 1640 } 1641 } 1642 1643 /** 1644 * @return true if the current device is "voice capable". 1645 * <p> 1646 * "Voice capable" means that this device supports circuit-switched 1647 * (i.e. voice) phone calls over the telephony network, and is allowed 1648 * to display the in-call UI while a cellular voice call is active. 1649 * This will be false on "data only" devices which can't make voice 1650 * calls and don't support any in-call UI. 1651 * <p> 1652 * Note: the meaning of this flag is subtly different from the 1653 * PackageManager.FEATURE_TELEPHONY system feature, which is available 1654 * on any device with a telephony radio, even if the device is 1655 * data-only. 1656 * 1657 * @hide pending API review 1658 */ 1659 public boolean isVoiceCapable() { 1660 if (mContext == null) return true; 1661 return mContext.getResources().getBoolean( 1662 com.android.internal.R.bool.config_voice_capable); 1663 } 1664 1665 /** 1666 * @return true if the current device supports sms service. 1667 * <p> 1668 * If true, this means that the device supports both sending and 1669 * receiving sms via the telephony network. 1670 * <p> 1671 * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are 1672 * disabled when device doesn't support sms. 1673 * 1674 * @hide pending API review 1675 */ 1676 public boolean isSmsCapable() { 1677 if (mContext == null) return true; 1678 return mContext.getResources().getBoolean( 1679 com.android.internal.R.bool.config_sms_capable); 1680 } 1681 1682 /** 1683 * Returns all observed cell information from all radios on the 1684 * device including the primary and neighboring cells. This does 1685 * not cause or change the rate of PhoneStateListner#onCellInfoChanged. 1686 *<p> 1687 * The list can include one or more of {@link android.telephony.CellInfoGsm CellInfoGsm}, 1688 * {@link android.telephony.CellInfoCdma CellInfoCdma}, 1689 * {@link android.telephony.CellInfoLte CellInfoLte} and 1690 * {@link android.telephony.CellInfoWcdma CellInfoCdma} in any combination. 1691 * Specifically on devices with multiple radios it is typical to see instances of 1692 * one or more of any these in the list. In addition 0, 1 or more CellInfo 1693 * objects may return isRegistered() true. 1694 *<p> 1695 * This is preferred over using getCellLocation although for older 1696 * devices this may return null in which case getCellLocation should 1697 * be called. 1698 *<p> 1699 * @return List of CellInfo or null if info unavailable. 1700 * 1701 * <p>Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} 1702 */ 1703 public List<CellInfo> getAllCellInfo() { 1704 try { 1705 return getITelephony().getAllCellInfo(); 1706 } catch (RemoteException ex) { 1707 return null; 1708 } catch (NullPointerException ex) { 1709 return null; 1710 } 1711 } 1712 1713 /** 1714 * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged 1715 * PhoneStateListener.onCellInfoChanged} will be invoked. 1716 *<p> 1717 * The default, 0, means invoke onCellInfoChanged when any of the reported 1718 * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue 1719 * A onCellInfoChanged. 1720 *<p> 1721 * @param rateInMillis the rate 1722 * 1723 * @hide 1724 */ 1725 public void setCellInfoListRate(int rateInMillis) { 1726 try { 1727 getITelephony().setCellInfoListRate(rateInMillis); 1728 } catch (RemoteException ex) { 1729 } catch (NullPointerException ex) { 1730 } 1731 } 1732 1733 /** 1734 * Returns the MMS user agent. 1735 */ 1736 public String getMmsUserAgent() { 1737 if (mContext == null) return null; 1738 return mContext.getResources().getString( 1739 com.android.internal.R.string.config_mms_user_agent); 1740 } 1741 1742 /** 1743 * Returns the MMS user agent profile URL. 1744 */ 1745 public String getMmsUAProfUrl() { 1746 if (mContext == null) return null; 1747 return mContext.getResources().getString( 1748 com.android.internal.R.string.config_mms_user_agent_profile_url); 1749 } 1750 1751 /** 1752 * Opens a logical channel to the ICC card. 1753 * 1754 * Input parameters equivalent to TS 27.007 AT+CCHO command. 1755 * 1756 * @param AID Application id. See ETSI 102.221 and 101.220. 1757 * @return The logical channel id which is negative on error. 1758 */ 1759 public int iccOpenLogicalChannel(String AID) { 1760 try { 1761 return getITelephony().iccOpenLogicalChannel(AID); 1762 } catch (RemoteException ex) { 1763 } catch (NullPointerException ex) { 1764 } 1765 return -1; 1766 } 1767 1768 /** 1769 * Closes a previously opened logical channel to the ICC card. 1770 * 1771 * Input parameters equivalent to TS 27.007 AT+CCHC command. 1772 * 1773 * @param channel is the channel id to be closed as retruned by a successful 1774 * iccOpenLogicalChannel. 1775 * @return true if the channel was closed successfully. 1776 */ 1777 public boolean iccCloseLogicalChannel(int channel) { 1778 try { 1779 return getITelephony().iccCloseLogicalChannel(channel); 1780 } catch (RemoteException ex) { 1781 } catch (NullPointerException ex) { 1782 } 1783 return false; 1784 } 1785 1786 /** 1787 * Transmit an APDU to the ICC card over a logical channel. 1788 * 1789 * Input parameters equivalent to TS 27.007 AT+CGLA command. 1790 * 1791 * @param channel is the channel id to be closed as returned by a successful 1792 * iccOpenLogicalChannel. 1793 * @param cla Class of the APDU command. 1794 * @param instruction Instruction of the APDU command. 1795 * @param p1 P1 value of the APDU command. 1796 * @param p2 P2 value of the APDU command. 1797 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 1798 * is sent to the SIM. 1799 * @param data Data to be sent with the APDU. 1800 * @return The APDU response from the ICC card with the status appended at 1801 * the end. If an error occurs, an empty string is returned. 1802 */ 1803 public String iccTransmitApduLogicalChannel(int channel, int cla, 1804 int instruction, int p1, int p2, int p3, String data) { 1805 try { 1806 return getITelephony().iccTransmitApduLogicalChannel(channel, cla, 1807 instruction, p1, p2, p3, data); 1808 } catch (RemoteException ex) { 1809 } catch (NullPointerException ex) { 1810 } 1811 return ""; 1812 } 1813 1814 /** 1815 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}. 1816 * Used for device configuration by some CDMA operators. 1817 * 1818 * @param itemID the ID of the item to read. 1819 * @return the NV item as a String, or null on any failure. 1820 * @hide 1821 */ 1822 public String nvReadItem(int itemID) { 1823 try { 1824 return getITelephony().nvReadItem(itemID); 1825 } catch (RemoteException ex) { 1826 Rlog.e(TAG, "nvReadItem RemoteException", ex); 1827 } catch (NullPointerException ex) { 1828 Rlog.e(TAG, "nvReadItem NPE", ex); 1829 } 1830 return ""; 1831 } 1832 1833 1834 /** 1835 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}. 1836 * Used for device configuration by some CDMA operators. 1837 * 1838 * @param itemID the ID of the item to read. 1839 * @param itemValue the value to write, as a String. 1840 * @return true on success; false on any failure. 1841 * @hide 1842 */ 1843 public boolean nvWriteItem(int itemID, String itemValue) { 1844 try { 1845 return getITelephony().nvWriteItem(itemID, itemValue); 1846 } catch (RemoteException ex) { 1847 Rlog.e(TAG, "nvWriteItem RemoteException", ex); 1848 } catch (NullPointerException ex) { 1849 Rlog.e(TAG, "nvWriteItem NPE", ex); 1850 } 1851 return false; 1852 } 1853 1854 /** 1855 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. 1856 * Used for device configuration by some CDMA operators. 1857 * 1858 * @param preferredRoamingList byte array containing the new PRL. 1859 * @return true on success; false on any failure. 1860 * @hide 1861 */ 1862 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { 1863 try { 1864 return getITelephony().nvWriteCdmaPrl(preferredRoamingList); 1865 } catch (RemoteException ex) { 1866 Rlog.e(TAG, "nvWriteCdmaPrl RemoteException", ex); 1867 } catch (NullPointerException ex) { 1868 Rlog.e(TAG, "nvWriteCdmaPrl NPE", ex); 1869 } 1870 return false; 1871 } 1872 1873 /** 1874 * Perform the specified type of NV config reset. The radio will be taken offline 1875 * and the device must be rebooted after the operation. Used for device 1876 * configuration by some CDMA operators. 1877 * 1878 * @param resetType reset type: 1: reload NV reset, 2: erase NV reset, 3: factory NV reset 1879 * @return true on success; false on any failure. 1880 * @hide 1881 */ 1882 public boolean nvResetConfig(int resetType) { 1883 try { 1884 return getITelephony().nvResetConfig(resetType); 1885 } catch (RemoteException ex) { 1886 Rlog.e(TAG, "nvResetConfig RemoteException", ex); 1887 } catch (NullPointerException ex) { 1888 Rlog.e(TAG, "nvResetConfig NPE", ex); 1889 } 1890 return false; 1891 } 1892 1893 /** 1894 * Get the preferred network type. 1895 * Used for device configuration by some CDMA operators. 1896 * 1897 * @return the preferred network type, defined in RILConstants.java. 1898 * @hide 1899 */ 1900 public int getPreferredNetworkType() { 1901 try { 1902 return getITelephony().getPreferredNetworkType(); 1903 } catch (RemoteException ex) { 1904 Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex); 1905 } catch (NullPointerException ex) { 1906 Rlog.e(TAG, "getPreferredNetworkType NPE", ex); 1907 } 1908 return -1; 1909 } 1910 1911 /** 1912 * Set the preferred network type. 1913 * Used for device configuration by some CDMA operators. 1914 * 1915 * @param networkType the preferred network type, defined in RILConstants.java. 1916 * @return true on success; false on any failure. 1917 * @hide 1918 */ 1919 public boolean setPreferredNetworkType(int networkType) { 1920 try { 1921 return getITelephony().setPreferredNetworkType(networkType); 1922 } catch (RemoteException ex) { 1923 Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex); 1924 } catch (NullPointerException ex) { 1925 Rlog.e(TAG, "setPreferredNetworkType NPE", ex); 1926 } 1927 return false; 1928 } 1929 1930 /** 1931 * Expose the rest of ITelephony to @PrivateApi 1932 */ 1933 1934 /** @hide */ 1935 @PrivateApi 1936 public void dial(String number) { 1937 try { 1938 getITelephony().dial(number); 1939 } catch (RemoteException e) { 1940 Log.e(TAG, "Error calling ITelephony#dial", e); 1941 } 1942 } 1943 1944 /** @hide */ 1945 @PrivateApi 1946 public void call(String callingPackage, String number) { 1947 try { 1948 getITelephony().call(callingPackage, number); 1949 } catch (RemoteException e) { 1950 Log.e(TAG, "Error calling ITelephony#call", e); 1951 } 1952 } 1953 1954 /** @hide */ 1955 @PrivateApi 1956 public boolean showCallScreen() { 1957 try { 1958 return getITelephony().showCallScreen(); 1959 } catch (RemoteException e) { 1960 Log.e(TAG, "Error calling ITelephony#showCallScreen", e); 1961 } 1962 return false; 1963 } 1964 1965 /** @hide */ 1966 @PrivateApi 1967 public boolean showCallScreenWithDialpad(boolean showDialpad) { 1968 try { 1969 return getITelephony().showCallScreenWithDialpad(showDialpad); 1970 } catch (RemoteException e) { 1971 Log.e(TAG, "Error calling ITelephony#showCallScreenWithDialpad", e); 1972 } 1973 return false; 1974 } 1975 1976 /** @hide */ 1977 @PrivateApi 1978 public boolean endCall() { 1979 try { 1980 return getITelephony().endCall(); 1981 } catch (RemoteException e) { 1982 Log.e(TAG, "Error calling ITelephony#endCall", e); 1983 } 1984 return false; 1985 } 1986 1987 /** @hide */ 1988 @PrivateApi 1989 public void answerRingingCall() { 1990 try { 1991 getITelephony().answerRingingCall(); 1992 } catch (RemoteException e) { 1993 Log.e(TAG, "Error calling ITelephony#answerRingingCall", e); 1994 } 1995 } 1996 1997 /** @hide */ 1998 @PrivateApi 1999 public void toggleHold() { 2000 try { 2001 getITelephony().toggleHold(); 2002 } catch (RemoteException e) { 2003 Log.e(TAG, "Error calling ITelephony#toggleHold", e); 2004 } 2005 } 2006 2007 /** @hide */ 2008 @PrivateApi 2009 public void merge() { 2010 try { 2011 getITelephony().merge(); 2012 } catch (RemoteException e) { 2013 Log.e(TAG, "Error calling ITelephony#merge", e); 2014 } 2015 } 2016 2017 /** @hide */ 2018 @PrivateApi 2019 public void swap() { 2020 try { 2021 getITelephony().swap(); 2022 } catch (RemoteException e) { 2023 Log.e(TAG, "Error calling ITelephony#swap", e); 2024 } 2025 } 2026 2027 /** @hide */ 2028 @PrivateApi 2029 public void mute(boolean mute) { 2030 try { 2031 getITelephony().mute(mute); 2032 } catch (RemoteException e) { 2033 Log.e(TAG, "Error calling ITelephony#mute", e); 2034 } 2035 } 2036 2037 /** @hide */ 2038 @PrivateApi 2039 public void silenceRinger() { 2040 try { 2041 getITelephony().silenceRinger(); 2042 } catch (RemoteException e) { 2043 Log.e(TAG, "Error calling ITelephony#silenceRinger", e); 2044 } 2045 } 2046 2047 /** @hide */ 2048 @PrivateApi 2049 public boolean isOffhook() { 2050 try { 2051 return getITelephony().isOffhook(); 2052 } catch (RemoteException e) { 2053 Log.e(TAG, "Error calling ITelephony#isOffhook", e); 2054 } 2055 return false; 2056 } 2057 2058 /** @hide */ 2059 @PrivateApi 2060 public boolean isRinging() { 2061 try { 2062 return getITelephony().isRinging(); 2063 } catch (RemoteException e) { 2064 Log.e(TAG, "Error calling ITelephony#isRinging", e); 2065 } 2066 return false; 2067 } 2068 2069 /** @hide */ 2070 @PrivateApi 2071 public boolean isIdle() { 2072 try { 2073 return getITelephony().isIdle(); 2074 } catch (RemoteException e) { 2075 Log.e(TAG, "Error calling ITelephony#isIdle", e); 2076 } 2077 return true; 2078 } 2079 2080 /** @hide */ 2081 @PrivateApi 2082 public boolean isRadioOn() { 2083 try { 2084 return getITelephony().isRadioOn(); 2085 } catch (RemoteException e) { 2086 Log.e(TAG, "Error calling ITelephony#isRadioOn", e); 2087 } 2088 return false; 2089 } 2090 2091 /** @hide */ 2092 @PrivateApi 2093 public boolean isSimPinEnabled() { 2094 try { 2095 return getITelephony().isSimPinEnabled(); 2096 } catch (RemoteException e) { 2097 Log.e(TAG, "Error calling ITelephony#isSimPinEnabled", e); 2098 } 2099 return false; 2100 } 2101 2102 /** @hide */ 2103 @PrivateApi 2104 public void cancelMissedCallsNotification() { 2105 try { 2106 getITelephony().cancelMissedCallsNotification(); 2107 } catch (RemoteException e) { 2108 Log.e(TAG, "Error calling ITelephony#cancelMissedCallsNotification", e); 2109 } 2110 } 2111 2112 /** @hide */ 2113 @PrivateApi 2114 public boolean supplyPin(String pin) { 2115 try { 2116 return getITelephony().supplyPin(pin); 2117 } catch (RemoteException e) { 2118 Log.e(TAG, "Error calling ITelephony#supplyPin", e); 2119 } 2120 return false; 2121 } 2122 2123 /** @hide */ 2124 @PrivateApi 2125 public boolean supplyPuk(String puk, String pin) { 2126 try { 2127 return getITelephony().supplyPuk(puk, pin); 2128 } catch (RemoteException e) { 2129 Log.e(TAG, "Error calling ITelephony#supplyPuk", e); 2130 } 2131 return false; 2132 } 2133 2134 /** @hide */ 2135 @PrivateApi 2136 public int[] supplyPinReportResult(String pin) { 2137 try { 2138 return getITelephony().supplyPinReportResult(pin); 2139 } catch (RemoteException e) { 2140 Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e); 2141 } 2142 return new int[0]; 2143 } 2144 2145 /** @hide */ 2146 @PrivateApi 2147 public int[] supplyPukReportResult(String puk, String pin) { 2148 try { 2149 return getITelephony().supplyPukReportResult(puk, pin); 2150 } catch (RemoteException e) { 2151 Log.e(TAG, "Error calling ITelephony#]", e); 2152 } 2153 return new int[0]; 2154 } 2155 2156 /** @hide */ 2157 @PrivateApi 2158 public boolean handlePinMmi(String dialString) { 2159 try { 2160 return getITelephony().handlePinMmi(dialString); 2161 } catch (RemoteException e) { 2162 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 2163 } 2164 return false; 2165 } 2166 2167 /** @hide */ 2168 @PrivateApi 2169 public void toggleRadioOnOff() { 2170 try { 2171 getITelephony().toggleRadioOnOff(); 2172 } catch (RemoteException e) { 2173 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 2174 } 2175 } 2176 2177 /** @hide */ 2178 @PrivateApi 2179 public boolean setRadio(boolean turnOn) { 2180 try { 2181 return getITelephony().setRadio(turnOn); 2182 } catch (RemoteException e) { 2183 Log.e(TAG, "Error calling ITelephony#setRadio", e); 2184 } 2185 return false; 2186 } 2187 2188 /** @hide */ 2189 @PrivateApi 2190 public boolean setRadioPower(boolean turnOn) { 2191 try { 2192 return getITelephony().setRadioPower(turnOn); 2193 } catch (RemoteException e) { 2194 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 2195 } 2196 return false; 2197 } 2198 2199 /** @hide */ 2200 @PrivateApi 2201 public void updateServiceLocation() { 2202 try { 2203 getITelephony().updateServiceLocation(); 2204 } catch (RemoteException e) { 2205 Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e); 2206 } 2207 } 2208 2209 /** @hide */ 2210 @PrivateApi 2211 public int enableApnType(String type) { 2212 try { 2213 return getITelephony().enableApnType(type); 2214 } catch (RemoteException e) { 2215 Log.e(TAG, "Error calling ITelephony#enableApnType", e); 2216 } 2217 return PhoneConstants.APN_REQUEST_FAILED; 2218 } 2219 2220 /** @hide */ 2221 @PrivateApi 2222 public int disableApnType(String type) { 2223 try { 2224 return getITelephony().disableApnType(type); 2225 } catch (RemoteException e) { 2226 Log.e(TAG, "Error calling ITelephony#disableApnType", e); 2227 } 2228 return PhoneConstants.APN_REQUEST_FAILED; 2229 } 2230 2231 /** @hide */ 2232 @PrivateApi 2233 public boolean enableDataConnectivity() { 2234 try { 2235 return getITelephony().enableDataConnectivity(); 2236 } catch (RemoteException e) { 2237 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 2238 } 2239 return false; 2240 } 2241 2242 /** @hide */ 2243 @PrivateApi 2244 public boolean disableDataConnectivity() { 2245 try { 2246 return getITelephony().disableDataConnectivity(); 2247 } catch (RemoteException e) { 2248 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 2249 } 2250 return false; 2251 } 2252 2253 /** @hide */ 2254 @PrivateApi 2255 public boolean isDataConnectivityPossible() { 2256 try { 2257 return getITelephony().isDataConnectivityPossible(); 2258 } catch (RemoteException e) { 2259 Log.e(TAG, "Error calling ITelephony#isDataConnectivityPossible", e); 2260 } 2261 return false; 2262 } 2263 2264 /** @hide */ 2265 @PrivateApi 2266 public boolean needsOtaServiceProvisioning() { 2267 try { 2268 return getITelephony().needsOtaServiceProvisioning(); 2269 } catch (RemoteException e) { 2270 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 2271 } 2272 return false; 2273 } 2274 2275 /** @hide */ 2276 @PrivateApi 2277 public void playDtmfTone(char digit, boolean timedShortCode) { 2278 try { 2279 getITelephony().playDtmfTone(digit, timedShortCode); 2280 } catch (RemoteException e) { 2281 Log.e(TAG, "Error calling ITelephony#playDtmfTone", e); 2282 } 2283 } 2284 2285 /** @hide */ 2286 @PrivateApi 2287 public void stopDtmfTone() { 2288 try { 2289 getITelephony().stopDtmfTone(); 2290 } catch (RemoteException e) { 2291 Log.e(TAG, "Error calling ITelephony#stopDtmfTone", e); 2292 } 2293 } 2294 2295 /** @hide */ 2296 @PrivateApi 2297 public void addCallStateListener(CallStateListener listener) { 2298 try { 2299 if (listener == null) { 2300 throw new RuntimeException("Listener can't be null"); 2301 } 2302 if (!mListeners.containsKey(listener)) { 2303 final Listener l = new Listener(listener); 2304 mListeners.put(listener, l); 2305 getITelephony().addListener(l); 2306 } 2307 } catch (RemoteException e) { 2308 Log.e(TAG, "Error calling ITelephony#addListener", e); 2309 } 2310 } 2311 2312 /** @hide */ 2313 @PrivateApi 2314 public void removeCallStateListener(CallStateListener listener) { 2315 try { 2316 final Listener l = mListeners.remove(listener); 2317 if (l != null) { 2318 // Make sure that no callbacks that are already in flight come. 2319 l.clearQueue(); 2320 getITelephony().removeListener(l); 2321 } 2322 } catch (RemoteException e) { 2323 Log.e(TAG, "Error calling ITelephony#removeListener", e); 2324 } 2325 } 2326} 2327