TelephonyManager.java revision 16578caea887c258510a885476c11a2a9bc29f71
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_CMDA_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 (udpated) 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 /** @hide */ 1744 @PrivateApi 1745 public void dial(String number) { 1746 try { 1747 getITelephony().dial(number); 1748 } catch (RemoteException e) { 1749 Log.e(TAG, "Error calling ITelephony#dial", e); 1750 } 1751 } 1752 1753 /** @hide */ 1754 @PrivateApi 1755 public void call(String callingPackage, String number) { 1756 try { 1757 getITelephony().call(callingPackage, number); 1758 } catch (RemoteException e) { 1759 Log.e(TAG, "Error calling ITelephony#call", e); 1760 } 1761 } 1762 1763 /** @hide */ 1764 @PrivateApi 1765 public boolean showCallScreen() { 1766 try { 1767 return getITelephony().showCallScreen(); 1768 } catch (RemoteException e) { 1769 Log.e(TAG, "Error calling ITelephony#showCallScreen", e); 1770 } 1771 return false; 1772 } 1773 1774 /** @hide */ 1775 @PrivateApi 1776 public boolean showCallScreenWithDialpad(boolean showDialpad) { 1777 try { 1778 return getITelephony().showCallScreenWithDialpad(showDialpad); 1779 } catch (RemoteException e) { 1780 Log.e(TAG, "Error calling ITelephony#showCallScreenWithDialpad", e); 1781 } 1782 return false; 1783 } 1784 1785 /** @hide */ 1786 @PrivateApi 1787 public boolean endCall() { 1788 try { 1789 return getITelephony().endCall(); 1790 } catch (RemoteException e) { 1791 Log.e(TAG, "Error calling ITelephony#endCall", e); 1792 } 1793 return false; 1794 } 1795 1796 /** @hide */ 1797 @PrivateApi 1798 public void answerRingingCall() { 1799 try { 1800 getITelephony().answerRingingCall(); 1801 } catch (RemoteException e) { 1802 Log.e(TAG, "Error calling ITelephony#answerRingingCall", e); 1803 } 1804 } 1805 1806 /** @hide */ 1807 @PrivateApi 1808 public void toggleHold() { 1809 try { 1810 getITelephony().toggleHold(); 1811 } catch (RemoteException e) { 1812 Log.e(TAG, "Error calling ITelephony#toggleHold", e); 1813 } 1814 } 1815 1816 /** @hide */ 1817 @PrivateApi 1818 public void merge() { 1819 try { 1820 getITelephony().merge(); 1821 } catch (RemoteException e) { 1822 Log.e(TAG, "Error calling ITelephony#merge", e); 1823 } 1824 } 1825 1826 /** @hide */ 1827 @PrivateApi 1828 public void swap() { 1829 try { 1830 getITelephony().swap(); 1831 } catch (RemoteException e) { 1832 Log.e(TAG, "Error calling ITelephony#swap", e); 1833 } 1834 } 1835 1836 /** @hide */ 1837 @PrivateApi 1838 public void mute(boolean mute) { 1839 try { 1840 getITelephony().mute(mute); 1841 } catch (RemoteException e) { 1842 Log.e(TAG, "Error calling ITelephony#mute", e); 1843 } 1844 } 1845 1846 /** @hide */ 1847 @PrivateApi 1848 public void silenceRinger() { 1849 try { 1850 getITelephony().silenceRinger(); 1851 } catch (RemoteException e) { 1852 Log.e(TAG, "Error calling ITelephony#silenceRinger", e); 1853 } 1854 } 1855 1856 /** @hide */ 1857 @PrivateApi 1858 public boolean isOffhook() { 1859 try { 1860 return getITelephony().isOffhook(); 1861 } catch (RemoteException e) { 1862 Log.e(TAG, "Error calling ITelephony#isOffhook", e); 1863 } 1864 return false; 1865 } 1866 1867 /** @hide */ 1868 @PrivateApi 1869 public boolean isRinging() { 1870 try { 1871 return getITelephony().isRinging(); 1872 } catch (RemoteException e) { 1873 Log.e(TAG, "Error calling ITelephony#isRinging", e); 1874 } 1875 return false; 1876 } 1877 1878 /** @hide */ 1879 @PrivateApi 1880 public boolean isIdle() { 1881 try { 1882 return getITelephony().isIdle(); 1883 } catch (RemoteException e) { 1884 Log.e(TAG, "Error calling ITelephony#isIdle", e); 1885 } 1886 return true; 1887 } 1888 1889 /** @hide */ 1890 @PrivateApi 1891 public boolean isRadioOn() { 1892 try { 1893 return getITelephony().isRadioOn(); 1894 } catch (RemoteException e) { 1895 Log.e(TAG, "Error calling ITelephony#isRadioOn", e); 1896 } 1897 return false; 1898 } 1899 1900 /** @hide */ 1901 @PrivateApi 1902 public boolean isSimPinEnabled() { 1903 try { 1904 return getITelephony().isSimPinEnabled(); 1905 } catch (RemoteException e) { 1906 Log.e(TAG, "Error calling ITelephony#isSimPinEnabled", e); 1907 } 1908 return false; 1909 } 1910 1911 /** @hide */ 1912 @PrivateApi 1913 public void cancelMissedCallsNotification() { 1914 try { 1915 getITelephony().cancelMissedCallsNotification(); 1916 } catch (RemoteException e) { 1917 Log.e(TAG, "Error calling ITelephony#cancelMissedCallsNotification", e); 1918 } 1919 } 1920 1921 /** @hide */ 1922 @PrivateApi 1923 public boolean supplyPin(String pin) { 1924 try { 1925 return getITelephony().supplyPin(pin); 1926 } catch (RemoteException e) { 1927 Log.e(TAG, "Error calling ITelephony#supplyPin", e); 1928 } 1929 return false; 1930 } 1931 1932 /** @hide */ 1933 @PrivateApi 1934 public boolean supplyPuk(String puk, String pin) { 1935 try { 1936 return getITelephony().supplyPuk(puk, pin); 1937 } catch (RemoteException e) { 1938 Log.e(TAG, "Error calling ITelephony#supplyPuk", e); 1939 } 1940 return false; 1941 } 1942 1943 /** @hide */ 1944 @PrivateApi 1945 public int[] supplyPinReportResult(String pin) { 1946 try { 1947 return getITelephony().supplyPinReportResult(pin); 1948 } catch (RemoteException e) { 1949 Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e); 1950 } 1951 return new int[0]; 1952 } 1953 1954 /** @hide */ 1955 @PrivateApi 1956 public int[] supplyPukReportResult(String puk, String pin) { 1957 try { 1958 return getITelephony().supplyPukReportResult(puk, pin); 1959 } catch (RemoteException e) { 1960 Log.e(TAG, "Error calling ITelephony#]", e); 1961 } 1962 return new int[0]; 1963 } 1964 1965 /** @hide */ 1966 @PrivateApi 1967 public boolean handlePinMmi(String dialString) { 1968 try { 1969 return getITelephony().handlePinMmi(dialString); 1970 } catch (RemoteException e) { 1971 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 1972 } 1973 return false; 1974 } 1975 1976 /** @hide */ 1977 @PrivateApi 1978 public void toggleRadioOnOff() { 1979 try { 1980 getITelephony().toggleRadioOnOff(); 1981 } catch (RemoteException e) { 1982 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 1983 } 1984 } 1985 1986 /** @hide */ 1987 @PrivateApi 1988 public boolean setRadio(boolean turnOn) { 1989 try { 1990 return getITelephony().setRadio(turnOn); 1991 } catch (RemoteException e) { 1992 Log.e(TAG, "Error calling ITelephony#setRadio", e); 1993 } 1994 return false; 1995 } 1996 1997 /** @hide */ 1998 @PrivateApi 1999 public boolean setRadioPower(boolean turnOn) { 2000 try { 2001 return getITelephony().setRadioPower(turnOn); 2002 } catch (RemoteException e) { 2003 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 2004 } 2005 return false; 2006 } 2007 2008 /** @hide */ 2009 @PrivateApi 2010 public void updateServiceLocation() { 2011 try { 2012 getITelephony().updateServiceLocation(); 2013 } catch (RemoteException e) { 2014 Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e); 2015 } 2016 } 2017 2018 /** @hide */ 2019 @PrivateApi 2020 public int enableApnType(String type) { 2021 try { 2022 return getITelephony().enableApnType(type); 2023 } catch (RemoteException e) { 2024 Log.e(TAG, "Error calling ITelephony#enableApnType", e); 2025 } 2026 return PhoneConstants.APN_REQUEST_FAILED; 2027 } 2028 2029 /** @hide */ 2030 @PrivateApi 2031 public int disableApnType(String type) { 2032 try { 2033 return getITelephony().disableApnType(type); 2034 } catch (RemoteException e) { 2035 Log.e(TAG, "Error calling ITelephony#disableApnType", e); 2036 } 2037 return PhoneConstants.APN_REQUEST_FAILED; 2038 } 2039 2040 /** @hide */ 2041 @PrivateApi 2042 public boolean enableDataConnectivity() { 2043 try { 2044 return getITelephony().enableDataConnectivity(); 2045 } catch (RemoteException e) { 2046 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 2047 } 2048 return false; 2049 } 2050 2051 /** @hide */ 2052 @PrivateApi 2053 public boolean disableDataConnectivity() { 2054 try { 2055 return getITelephony().disableDataConnectivity(); 2056 } catch (RemoteException e) { 2057 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 2058 } 2059 return false; 2060 } 2061 2062 /** @hide */ 2063 @PrivateApi 2064 public boolean isDataConnectivityPossible() { 2065 try { 2066 return getITelephony().isDataConnectivityPossible(); 2067 } catch (RemoteException e) { 2068 Log.e(TAG, "Error calling ITelephony#isDataConnectivityPossible", e); 2069 } 2070 return false; 2071 } 2072 2073 /** @hide */ 2074 @PrivateApi 2075 public boolean needsOtaServiceProvisioning() { 2076 try { 2077 return getITelephony().needsOtaServiceProvisioning(); 2078 } catch (RemoteException e) { 2079 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 2080 } 2081 return false; 2082 } 2083 2084 /** @hide */ 2085 @PrivateApi 2086 public void playDtmfTone(char digit, boolean timedShortCode) { 2087 try { 2088 getITelephony().playDtmfTone(digit, timedShortCode); 2089 } catch (RemoteException e) { 2090 Log.e(TAG, "Error calling ITelephony#playDtmfTone", e); 2091 } 2092 } 2093 2094 /** @hide */ 2095 @PrivateApi 2096 public void stopDtmfTone() { 2097 try { 2098 getITelephony().stopDtmfTone(); 2099 } catch (RemoteException e) { 2100 Log.e(TAG, "Error calling ITelephony#stopDtmfTone", e); 2101 } 2102 } 2103 2104 /** @hide */ 2105 @PrivateApi 2106 public void addCallStateListener(CallStateListener listener) { 2107 try { 2108 if (listener == null) { 2109 throw new RuntimeException("Listener can't be null"); 2110 } 2111 if (!mListeners.containsKey(listener)) { 2112 final Listener l = new Listener(listener); 2113 mListeners.put(listener, l); 2114 getITelephony().addListener(l); 2115 } 2116 } catch (RemoteException e) { 2117 Log.e(TAG, "Error calling ITelephony#addListener", e); 2118 } 2119 } 2120 2121 /** @hide */ 2122 @PrivateApi 2123 public void removeCallStateListener(CallStateListener listener) { 2124 try { 2125 final Listener l = mListeners.remove(listener); 2126 if (l != null) { 2127 // Make sure that no callbacks that are already in flight come. 2128 l.clearQueue(); 2129 getITelephony().removeListener(l); 2130 } 2131 } catch (RemoteException e) { 2132 Log.e(TAG, "Error calling ITelephony#removeListener", e); 2133 } 2134 } 2135} 2136