TelephonyManager.java revision 5540908059e3d746d915cc5d7e00618dc43df585
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.Nullable; 20import android.annotation.SystemApi; 21import android.annotation.SdkConstant; 22import android.annotation.SdkConstant.SdkConstantType; 23import android.content.ContentResolver; 24import android.content.Context; 25import android.content.Intent; 26import android.provider.Settings; 27import android.provider.Settings.SettingNotFoundException; 28import android.os.Bundle; 29import android.os.RemoteException; 30import android.os.ServiceManager; 31import android.os.SystemProperties; 32import android.telecom.PhoneAccount; 33import android.util.Log; 34 35import com.android.internal.telecom.ITelecomService; 36import com.android.internal.telephony.IPhoneSubInfo; 37import com.android.internal.telephony.ITelephony; 38import com.android.internal.telephony.ITelephonyRegistry; 39import com.android.internal.telephony.PhoneConstants; 40import com.android.internal.telephony.RILConstants; 41import com.android.internal.telephony.TelephonyProperties; 42 43import java.io.FileInputStream; 44import java.io.IOException; 45import java.util.List; 46import java.util.regex.Matcher; 47import java.util.regex.Pattern; 48 49/** 50 * Provides access to information about the telephony services on 51 * the device. Applications can use the methods in this class to 52 * determine telephony services and states, as well as to access some 53 * types of subscriber information. Applications can also register 54 * a listener to receive notification of telephony state changes. 55 * <p> 56 * You do not instantiate this class directly; instead, you retrieve 57 * a reference to an instance through 58 * {@link android.content.Context#getSystemService 59 * Context.getSystemService(Context.TELEPHONY_SERVICE)}. 60 * <p> 61 * Note that access to some telephony information is 62 * permission-protected. Your application cannot access the protected 63 * information unless it has the appropriate permissions declared in 64 * its manifest file. Where permissions apply, they are noted in the 65 * the methods through which you access the protected information. 66 */ 67public class TelephonyManager { 68 private static final String TAG = "TelephonyManager"; 69 70 private static ITelephonyRegistry sRegistry; 71 72 /** 73 * The allowed states of Wi-Fi calling. 74 * 75 * @hide 76 */ 77 public interface WifiCallingChoices { 78 /** Always use Wi-Fi calling */ 79 static final int ALWAYS_USE = 0; 80 /** Ask the user whether to use Wi-Fi on every call */ 81 static final int ASK_EVERY_TIME = 1; 82 /** Never use Wi-Fi calling */ 83 static final int NEVER_USE = 2; 84 } 85 86 private final Context mContext; 87 private SubscriptionManager mSubscriptionManager; 88 89 private static String multiSimConfig = 90 SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG); 91 92 /** Enum indicating multisim variants 93 * DSDS - Dual SIM Dual Standby 94 * DSDA - Dual SIM Dual Active 95 * TSTS - Triple SIM Triple Standby 96 **/ 97 /** @hide */ 98 public enum MultiSimVariants { 99 DSDS, 100 DSDA, 101 TSTS, 102 UNKNOWN 103 }; 104 105 /** @hide */ 106 public TelephonyManager(Context context) { 107 Context appContext = context.getApplicationContext(); 108 if (appContext != null) { 109 mContext = appContext; 110 } else { 111 mContext = context; 112 } 113 mSubscriptionManager = SubscriptionManager.from(mContext); 114 115 if (sRegistry == null) { 116 sRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService( 117 "telephony.registry")); 118 } 119 } 120 121 /** @hide */ 122 private TelephonyManager() { 123 mContext = null; 124 } 125 126 private static TelephonyManager sInstance = new TelephonyManager(); 127 128 /** @hide 129 /* @deprecated - use getSystemService as described above */ 130 public static TelephonyManager getDefault() { 131 return sInstance; 132 } 133 134 135 /** 136 * Returns the multi SIM variant 137 * Returns DSDS for Dual SIM Dual Standby 138 * Returns DSDA for Dual SIM Dual Active 139 * Returns TSTS for Triple SIM Triple Standby 140 * Returns UNKNOWN for others 141 */ 142 /** {@hide} */ 143 public MultiSimVariants getMultiSimConfiguration() { 144 String mSimConfig = 145 SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG); 146 if (mSimConfig.equals("dsds")) { 147 return MultiSimVariants.DSDS; 148 } else if (mSimConfig.equals("dsda")) { 149 return MultiSimVariants.DSDA; 150 } else if (mSimConfig.equals("tsts")) { 151 return MultiSimVariants.TSTS; 152 } else { 153 return MultiSimVariants.UNKNOWN; 154 } 155 } 156 157 158 /** 159 * Returns the number of phones available. 160 * Returns 1 for Single standby mode (Single SIM functionality) 161 * Returns 2 for Dual standby mode.(Dual SIM functionality) 162 */ 163 /** {@hide} */ 164 public int getPhoneCount() { 165 int phoneCount = 1; 166 switch (getMultiSimConfiguration()) { 167 case UNKNOWN: 168 phoneCount = 1; 169 break; 170 case DSDS: 171 case DSDA: 172 phoneCount = PhoneConstants.MAX_PHONE_COUNT_DUAL_SIM; 173 break; 174 case TSTS: 175 phoneCount = PhoneConstants.MAX_PHONE_COUNT_TRI_SIM; 176 break; 177 } 178 return phoneCount; 179 } 180 181 /** {@hide} */ 182 public static TelephonyManager from(Context context) { 183 return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 184 } 185 186 /** {@hide} */ 187 public boolean isMultiSimEnabled() { 188 return (multiSimConfig.equals("dsds") || multiSimConfig.equals("dsda") || 189 multiSimConfig.equals("tsts")); 190 } 191 192 // 193 // Broadcast Intent actions 194 // 195 196 /** 197 * Broadcast intent action indicating that the call state (cellular) 198 * on the device has changed. 199 * 200 * <p> 201 * The {@link #EXTRA_STATE} extra indicates the new call state. 202 * If the new state is RINGING, a second extra 203 * {@link #EXTRA_INCOMING_NUMBER} provides the incoming phone number as 204 * a String. 205 * 206 * <p class="note"> 207 * Requires the READ_PHONE_STATE permission. 208 * 209 * <p class="note"> 210 * This was a {@link android.content.Context#sendStickyBroadcast sticky} 211 * broadcast in version 1.0, but it is no longer sticky. 212 * Instead, use {@link #getCallState} to synchronously query the current call state. 213 * 214 * @see #EXTRA_STATE 215 * @see #EXTRA_INCOMING_NUMBER 216 * @see #getCallState 217 */ 218 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 219 public static final String ACTION_PHONE_STATE_CHANGED = 220 "android.intent.action.PHONE_STATE"; 221 222 /** 223 * The Phone app sends this intent when a user opts to respond-via-message during an incoming 224 * call. By default, the device's default SMS app consumes this message and sends a text message 225 * to the caller. A third party app can also provide this functionality by consuming this Intent 226 * with a {@link android.app.Service} and sending the message using its own messaging system. 227 * <p>The intent contains a URI (available from {@link android.content.Intent#getData}) 228 * describing the recipient, using either the {@code sms:}, {@code smsto:}, {@code mms:}, 229 * or {@code mmsto:} URI schema. Each of these URI schema carry the recipient information the 230 * same way: the path part of the URI contains the recipient's phone number or a comma-separated 231 * set of phone numbers if there are multiple recipients. For example, {@code 232 * smsto:2065551234}.</p> 233 * 234 * <p>The intent may also contain extras for the message text (in {@link 235 * android.content.Intent#EXTRA_TEXT}) and a message subject 236 * (in {@link android.content.Intent#EXTRA_SUBJECT}).</p> 237 * 238 * <p class="note"><strong>Note:</strong> 239 * The intent-filter that consumes this Intent needs to be in a {@link android.app.Service} 240 * that requires the 241 * permission {@link android.Manifest.permission#SEND_RESPOND_VIA_MESSAGE}.</p> 242 * <p>For example, the service that receives this intent can be declared in the manifest file 243 * with an intent filter like this:</p> 244 * <pre> 245 * <!-- Service that delivers SMS messages received from the phone "quick response" --> 246 * <service android:name=".HeadlessSmsSendService" 247 * android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE" 248 * android:exported="true" > 249 * <intent-filter> 250 * <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" /> 251 * <category android:name="android.intent.category.DEFAULT" /> 252 * <data android:scheme="sms" /> 253 * <data android:scheme="smsto" /> 254 * <data android:scheme="mms" /> 255 * <data android:scheme="mmsto" /> 256 * </intent-filter> 257 * </service></pre> 258 * <p> 259 * Output: nothing. 260 */ 261 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 262 public static final String ACTION_RESPOND_VIA_MESSAGE = 263 "android.intent.action.RESPOND_VIA_MESSAGE"; 264 265 /** 266 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 267 * for a String containing the new call state. 268 * 269 * @see #EXTRA_STATE_IDLE 270 * @see #EXTRA_STATE_RINGING 271 * @see #EXTRA_STATE_OFFHOOK 272 * 273 * <p class="note"> 274 * Retrieve with 275 * {@link android.content.Intent#getStringExtra(String)}. 276 */ 277 public static final String EXTRA_STATE = PhoneConstants.STATE_KEY; 278 279 /** 280 * Value used with {@link #EXTRA_STATE} corresponding to 281 * {@link #CALL_STATE_IDLE}. 282 */ 283 public static final String EXTRA_STATE_IDLE = PhoneConstants.State.IDLE.toString(); 284 285 /** 286 * Value used with {@link #EXTRA_STATE} corresponding to 287 * {@link #CALL_STATE_RINGING}. 288 */ 289 public static final String EXTRA_STATE_RINGING = PhoneConstants.State.RINGING.toString(); 290 291 /** 292 * Value used with {@link #EXTRA_STATE} corresponding to 293 * {@link #CALL_STATE_OFFHOOK}. 294 */ 295 public static final String EXTRA_STATE_OFFHOOK = PhoneConstants.State.OFFHOOK.toString(); 296 297 /** 298 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 299 * for a String containing the incoming phone number. 300 * Only valid when the new call state is RINGING. 301 * 302 * <p class="note"> 303 * Retrieve with 304 * {@link android.content.Intent#getStringExtra(String)}. 305 */ 306 public static final String EXTRA_INCOMING_NUMBER = "incoming_number"; 307 308 /** 309 * Broadcast intent action indicating that a precise call state 310 * (cellular) on the device has changed. 311 * 312 * <p> 313 * The {@link #EXTRA_RINGING_CALL_STATE} extra indicates the ringing call state. 314 * The {@link #EXTRA_FOREGROUND_CALL_STATE} extra indicates the foreground call state. 315 * The {@link #EXTRA_BACKGROUND_CALL_STATE} extra indicates the background call state. 316 * The {@link #EXTRA_DISCONNECT_CAUSE} extra indicates the disconnect cause. 317 * The {@link #EXTRA_PRECISE_DISCONNECT_CAUSE} extra indicates the precise disconnect cause. 318 * 319 * <p class="note"> 320 * Requires the READ_PRECISE_PHONE_STATE permission. 321 * 322 * @see #EXTRA_RINGING_CALL_STATE 323 * @see #EXTRA_FOREGROUND_CALL_STATE 324 * @see #EXTRA_BACKGROUND_CALL_STATE 325 * @see #EXTRA_DISCONNECT_CAUSE 326 * @see #EXTRA_PRECISE_DISCONNECT_CAUSE 327 * 328 * <p class="note"> 329 * Requires the READ_PRECISE_PHONE_STATE permission. 330 * 331 * @hide 332 */ 333 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 334 public static final String ACTION_PRECISE_CALL_STATE_CHANGED = 335 "android.intent.action.PRECISE_CALL_STATE"; 336 337 /** 338 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 339 * for an integer containing the state of the current ringing call. 340 * 341 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 342 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 343 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 344 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 345 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 346 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 347 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 348 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 349 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 350 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 351 * 352 * <p class="note"> 353 * Retrieve with 354 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 355 * 356 * @hide 357 */ 358 public static final String EXTRA_RINGING_CALL_STATE = "ringing_state"; 359 360 /** 361 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 362 * for an integer containing the state of the current foreground call. 363 * 364 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 365 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 366 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 367 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 368 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 369 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 370 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 371 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 372 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 373 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 374 * 375 * <p class="note"> 376 * Retrieve with 377 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 378 * 379 * @hide 380 */ 381 public static final String EXTRA_FOREGROUND_CALL_STATE = "foreground_state"; 382 383 /** 384 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 385 * for an integer containing the state of the current background call. 386 * 387 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 388 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 389 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 390 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 391 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 392 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 393 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 394 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 395 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 396 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 397 * 398 * <p class="note"> 399 * Retrieve with 400 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 401 * 402 * @hide 403 */ 404 public static final String EXTRA_BACKGROUND_CALL_STATE = "background_state"; 405 406 /** 407 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 408 * for an integer containing the disconnect cause. 409 * 410 * @see DisconnectCause 411 * 412 * <p class="note"> 413 * Retrieve with 414 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 415 * 416 * @hide 417 */ 418 public static final String EXTRA_DISCONNECT_CAUSE = "disconnect_cause"; 419 420 /** 421 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 422 * for an integer containing the disconnect cause provided by the RIL. 423 * 424 * @see PreciseDisconnectCause 425 * 426 * <p class="note"> 427 * Retrieve with 428 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 429 * 430 * @hide 431 */ 432 public static final String EXTRA_PRECISE_DISCONNECT_CAUSE = "precise_disconnect_cause"; 433 434 /** 435 * Broadcast intent action indicating a data connection has changed, 436 * providing precise information about the connection. 437 * 438 * <p> 439 * The {@link #EXTRA_DATA_STATE} extra indicates the connection state. 440 * The {@link #EXTRA_DATA_NETWORK_TYPE} extra indicates the connection network type. 441 * The {@link #EXTRA_DATA_APN_TYPE} extra indicates the APN type. 442 * The {@link #EXTRA_DATA_APN} extra indicates the APN. 443 * The {@link #EXTRA_DATA_CHANGE_REASON} extra indicates the connection change reason. 444 * The {@link #EXTRA_DATA_IFACE_PROPERTIES} extra indicates the connection interface. 445 * The {@link #EXTRA_DATA_FAILURE_CAUSE} extra indicates the connection fail cause. 446 * 447 * <p class="note"> 448 * Requires the READ_PRECISE_PHONE_STATE permission. 449 * 450 * @see #EXTRA_DATA_STATE 451 * @see #EXTRA_DATA_NETWORK_TYPE 452 * @see #EXTRA_DATA_APN_TYPE 453 * @see #EXTRA_DATA_APN 454 * @see #EXTRA_DATA_CHANGE_REASON 455 * @see #EXTRA_DATA_IFACE 456 * @see #EXTRA_DATA_FAILURE_CAUSE 457 * @hide 458 */ 459 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 460 public static final String ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED = 461 "android.intent.action.PRECISE_DATA_CONNECTION_STATE_CHANGED"; 462 463 /** 464 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 465 * for an integer containing the state of the current data connection. 466 * 467 * @see TelephonyManager#DATA_UNKNOWN 468 * @see TelephonyManager#DATA_DISCONNECTED 469 * @see TelephonyManager#DATA_CONNECTING 470 * @see TelephonyManager#DATA_CONNECTED 471 * @see TelephonyManager#DATA_SUSPENDED 472 * 473 * <p class="note"> 474 * Retrieve with 475 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 476 * 477 * @hide 478 */ 479 public static final String EXTRA_DATA_STATE = PhoneConstants.STATE_KEY; 480 481 /** 482 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 483 * for an integer containing the network type. 484 * 485 * @see TelephonyManager#NETWORK_TYPE_UNKNOWN 486 * @see TelephonyManager#NETWORK_TYPE_GPRS 487 * @see TelephonyManager#NETWORK_TYPE_EDGE 488 * @see TelephonyManager#NETWORK_TYPE_UMTS 489 * @see TelephonyManager#NETWORK_TYPE_CDMA 490 * @see TelephonyManager#NETWORK_TYPE_EVDO_0 491 * @see TelephonyManager#NETWORK_TYPE_EVDO_A 492 * @see TelephonyManager#NETWORK_TYPE_1xRTT 493 * @see TelephonyManager#NETWORK_TYPE_HSDPA 494 * @see TelephonyManager#NETWORK_TYPE_HSUPA 495 * @see TelephonyManager#NETWORK_TYPE_HSPA 496 * @see TelephonyManager#NETWORK_TYPE_IDEN 497 * @see TelephonyManager#NETWORK_TYPE_EVDO_B 498 * @see TelephonyManager#NETWORK_TYPE_LTE 499 * @see TelephonyManager#NETWORK_TYPE_EHRPD 500 * @see TelephonyManager#NETWORK_TYPE_HSPAP 501 * 502 * <p class="note"> 503 * Retrieve with 504 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 505 * 506 * @hide 507 */ 508 public static final String EXTRA_DATA_NETWORK_TYPE = PhoneConstants.DATA_NETWORK_TYPE_KEY; 509 510 /** 511 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 512 * for an String containing the data APN type. 513 * 514 * <p class="note"> 515 * Retrieve with 516 * {@link android.content.Intent#getStringExtra(String name)}. 517 * 518 * @hide 519 */ 520 public static final String EXTRA_DATA_APN_TYPE = PhoneConstants.DATA_APN_TYPE_KEY; 521 522 /** 523 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 524 * for an String containing the data APN. 525 * 526 * <p class="note"> 527 * Retrieve with 528 * {@link android.content.Intent#getStringExtra(String name)}. 529 * 530 * @hide 531 */ 532 public static final String EXTRA_DATA_APN = PhoneConstants.DATA_APN_KEY; 533 534 /** 535 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 536 * for an String representation of the change reason. 537 * 538 * <p class="note"> 539 * Retrieve with 540 * {@link android.content.Intent#getStringExtra(String name)}. 541 * 542 * @hide 543 */ 544 public static final String EXTRA_DATA_CHANGE_REASON = PhoneConstants.STATE_CHANGE_REASON_KEY; 545 546 /** 547 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 548 * for an String representation of the data interface. 549 * 550 * <p class="note"> 551 * Retrieve with 552 * {@link android.content.Intent#getParcelableExtra(String name)}. 553 * 554 * @hide 555 */ 556 public static final String EXTRA_DATA_LINK_PROPERTIES_KEY = PhoneConstants.DATA_LINK_PROPERTIES_KEY; 557 558 /** 559 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 560 * for the data connection fail cause. 561 * 562 * <p class="note"> 563 * Retrieve with 564 * {@link android.content.Intent#getStringExtra(String name)}. 565 * 566 * @hide 567 */ 568 public static final String EXTRA_DATA_FAILURE_CAUSE = PhoneConstants.DATA_FAILURE_CAUSE_KEY; 569 570 // 571 // 572 // Device Info 573 // 574 // 575 576 /** 577 * Returns the software version number for the device, for example, 578 * the IMEI/SV for GSM phones. Return null if the software version is 579 * not available. 580 * 581 * <p>Requires Permission: 582 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 583 */ 584 public String getDeviceSoftwareVersion() { 585 return getDeviceSoftwareVersion(getDefaultSim()); 586 } 587 588 /** 589 * Returns the software version number for the device, for example, 590 * the IMEI/SV for GSM phones. Return null if the software version is 591 * not available. 592 * 593 * <p>Requires Permission: 594 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 595 * 596 * @param slotId of which deviceID is returned 597 */ 598 /** {@hide} */ 599 public String getDeviceSoftwareVersion(int slotId) { 600 // FIXME methods taking slot id should not use subscription, instead us Uicc directly 601 int[] subId = SubscriptionManager.getSubId(slotId); 602 if (subId == null || subId.length == 0) { 603 return null; 604 } 605 try { 606 return getSubscriberInfo().getDeviceSvnUsingSubId(subId[0]); 607 } catch (RemoteException ex) { 608 return null; 609 } catch (NullPointerException ex) { 610 return null; 611 } 612 } 613 614 /** 615 * Returns the unique device ID, for example, the IMEI for GSM and the MEID 616 * or ESN for CDMA phones. Return null if device ID is not available. 617 * 618 * <p>Requires Permission: 619 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 620 */ 621 public String getDeviceId() { 622 try { 623 return getITelephony().getDeviceId(); 624 } catch (RemoteException ex) { 625 return null; 626 } catch (NullPointerException ex) { 627 return null; 628 } 629 } 630 631 /** 632 * Returns the unique device ID of a subscription, for example, the IMEI for 633 * GSM and the MEID for CDMA phones. Return null if device ID is not available. 634 * 635 * <p>Requires Permission: 636 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 637 * 638 * @param slotId of which deviceID is returned 639 */ 640 /** {@hide} */ 641 public String getDeviceId(int slotId) { 642 // FIXME this assumes phoneId == slotId 643 try { 644 return getSubscriberInfo().getDeviceIdForPhone(slotId); 645 } catch (RemoteException ex) { 646 return null; 647 } catch (NullPointerException ex) { 648 return null; 649 } 650 } 651 652 /** 653 * Returns the IMEI. Return null if IMEI is not available. 654 * 655 * <p>Requires Permission: 656 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 657 */ 658 /** {@hide} */ 659 public String getImei() { 660 return getImei(getDefaultSim()); 661 } 662 663 /** 664 * Returns the IMEI. Return null if IMEI is not available. 665 * 666 * <p>Requires Permission: 667 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 668 * 669 * @param slotId of which deviceID is returned 670 */ 671 /** {@hide} */ 672 public String getImei(int slotId) { 673 int[] subId = SubscriptionManager.getSubId(slotId); 674 try { 675 return getSubscriberInfo().getImeiForSubscriber(subId[0]); 676 } catch (RemoteException ex) { 677 return null; 678 } catch (NullPointerException ex) { 679 return null; 680 } 681 } 682 683 /** 684 * Returns the NAI. Return null if NAI is not available. 685 * 686 */ 687 /** {@hide}*/ 688 public String getNai() { 689 return getNai(getDefaultSim()); 690 } 691 692 /** 693 * Returns the NAI. Return null if NAI is not available. 694 * 695 * @param slotId of which Nai is returned 696 */ 697 /** {@hide}*/ 698 public String getNai(int slotId) { 699 int[] subId = SubscriptionManager.getSubId(slotId); 700 try { 701 String nai = getSubscriberInfo().getNaiForSubscriber(subId[0]); 702 if (Log.isLoggable(TAG, Log.VERBOSE)) { 703 Rlog.v(TAG, "Nai = " + nai); 704 } 705 return nai; 706 } catch (RemoteException ex) { 707 return null; 708 } catch (NullPointerException ex) { 709 return null; 710 } 711 } 712 713 /** 714 * Returns the current location of the device. 715 *<p> 716 * If there is only one radio in the device and that radio has an LTE connection, 717 * this method will return null. The implementation must not to try add LTE 718 * identifiers into the existing cdma/gsm classes. 719 *<p> 720 * In the future this call will be deprecated. 721 *<p> 722 * @return Current location of the device or null if not available. 723 * 724 * <p>Requires Permission: 725 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or 726 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION}. 727 */ 728 public CellLocation getCellLocation() { 729 try { 730 Bundle bundle = getITelephony().getCellLocation(); 731 if (bundle.isEmpty()) return null; 732 CellLocation cl = CellLocation.newFromBundle(bundle); 733 if (cl.isEmpty()) 734 return null; 735 return cl; 736 } catch (RemoteException ex) { 737 return null; 738 } catch (NullPointerException ex) { 739 return null; 740 } 741 } 742 743 /** 744 * Enables location update notifications. {@link PhoneStateListener#onCellLocationChanged 745 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 746 * 747 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 748 * CONTROL_LOCATION_UPDATES} 749 * 750 * @hide 751 */ 752 public void enableLocationUpdates() { 753 enableLocationUpdates(getDefaultSubscription()); 754 } 755 756 /** 757 * Enables location update notifications for a subscription. 758 * {@link PhoneStateListener#onCellLocationChanged 759 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 760 * 761 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 762 * CONTROL_LOCATION_UPDATES} 763 * 764 * @param subId for which the location updates are enabled 765 */ 766 /** @hide */ 767 public void enableLocationUpdates(int subId) { 768 try { 769 getITelephony().enableLocationUpdatesForSubscriber(subId); 770 } catch (RemoteException ex) { 771 } catch (NullPointerException ex) { 772 } 773 } 774 775 /** 776 * Disables location update notifications. {@link PhoneStateListener#onCellLocationChanged 777 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 778 * 779 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 780 * CONTROL_LOCATION_UPDATES} 781 * 782 * @hide 783 */ 784 public void disableLocationUpdates() { 785 disableLocationUpdates(getDefaultSubscription()); 786 } 787 788 /** @hide */ 789 public void disableLocationUpdates(int subId) { 790 try { 791 getITelephony().disableLocationUpdatesForSubscriber(subId); 792 } catch (RemoteException ex) { 793 } catch (NullPointerException ex) { 794 } 795 } 796 797 /** 798 * Returns the neighboring cell information of the device. The getAllCellInfo is preferred 799 * and use this only if getAllCellInfo return nulls or an empty list. 800 *<p> 801 * In the future this call will be deprecated. 802 *<p> 803 * @return List of NeighboringCellInfo or null if info unavailable. 804 * 805 * <p>Requires Permission: 806 * (@link android.Manifest.permission#ACCESS_COARSE_UPDATES} 807 */ 808 public List<NeighboringCellInfo> getNeighboringCellInfo() { 809 try { 810 return getITelephony().getNeighboringCellInfo(mContext.getOpPackageName()); 811 } catch (RemoteException ex) { 812 return null; 813 } catch (NullPointerException ex) { 814 return null; 815 } 816 } 817 818 /** No phone radio. */ 819 public static final int PHONE_TYPE_NONE = PhoneConstants.PHONE_TYPE_NONE; 820 /** Phone radio is GSM. */ 821 public static final int PHONE_TYPE_GSM = PhoneConstants.PHONE_TYPE_GSM; 822 /** Phone radio is CDMA. */ 823 public static final int PHONE_TYPE_CDMA = PhoneConstants.PHONE_TYPE_CDMA; 824 /** Phone is via SIP. */ 825 public static final int PHONE_TYPE_SIP = PhoneConstants.PHONE_TYPE_SIP; 826 827 /** 828 * Returns the current phone type. 829 * TODO: This is a last minute change and hence hidden. 830 * 831 * @see #PHONE_TYPE_NONE 832 * @see #PHONE_TYPE_GSM 833 * @see #PHONE_TYPE_CDMA 834 * @see #PHONE_TYPE_SIP 835 * 836 * {@hide} 837 */ 838 @SystemApi 839 public int getCurrentPhoneType() { 840 return getCurrentPhoneType(getDefaultSubscription()); 841 } 842 843 /** 844 * Returns a constant indicating the device phone type for a subscription. 845 * 846 * @see #PHONE_TYPE_NONE 847 * @see #PHONE_TYPE_GSM 848 * @see #PHONE_TYPE_CDMA 849 * 850 * @param subId for which phone type is returned 851 */ 852 /** {@hide} */ 853 @SystemApi 854 public int getCurrentPhoneType(int subId) { 855 int phoneId = SubscriptionManager.getPhoneId(subId); 856 try{ 857 ITelephony telephony = getITelephony(); 858 if (telephony != null) { 859 return telephony.getActivePhoneTypeForSubscriber(subId); 860 } else { 861 // This can happen when the ITelephony interface is not up yet. 862 return getPhoneTypeFromProperty(phoneId); 863 } 864 } catch (RemoteException ex) { 865 // This shouldn't happen in the normal case, as a backup we 866 // read from the system property. 867 return getPhoneTypeFromProperty(phoneId); 868 } catch (NullPointerException ex) { 869 // This shouldn't happen in the normal case, as a backup we 870 // read from the system property. 871 return getPhoneTypeFromProperty(phoneId); 872 } 873 } 874 875 /** 876 * Returns a constant indicating the device phone type. This 877 * indicates the type of radio used to transmit voice calls. 878 * 879 * @see #PHONE_TYPE_NONE 880 * @see #PHONE_TYPE_GSM 881 * @see #PHONE_TYPE_CDMA 882 * @see #PHONE_TYPE_SIP 883 */ 884 public int getPhoneType() { 885 if (!isVoiceCapable()) { 886 return PHONE_TYPE_NONE; 887 } 888 return getCurrentPhoneType(); 889 } 890 891 private int getPhoneTypeFromProperty() { 892 return getPhoneTypeFromProperty(getDefaultPhone()); 893 } 894 895 /** {@hide} */ 896 private int getPhoneTypeFromProperty(int phoneId) { 897 String type = getTelephonyProperty(phoneId, 898 TelephonyProperties.CURRENT_ACTIVE_PHONE, null); 899 if (type == null || type.equals("")) { 900 return getPhoneTypeFromNetworkType(phoneId); 901 } 902 return Integer.parseInt(type); 903 } 904 905 private int getPhoneTypeFromNetworkType() { 906 return getPhoneTypeFromNetworkType(getDefaultPhone()); 907 } 908 909 /** {@hide} */ 910 private int getPhoneTypeFromNetworkType(int phoneId) { 911 // When the system property CURRENT_ACTIVE_PHONE, has not been set, 912 // use the system property for default network type. 913 // This is a fail safe, and can only happen at first boot. 914 String mode = getTelephonyProperty(phoneId, "ro.telephony.default_network", null); 915 if (mode != null) { 916 return TelephonyManager.getPhoneType(Integer.parseInt(mode)); 917 } 918 return TelephonyManager.PHONE_TYPE_NONE; 919 } 920 921 /** 922 * This function returns the type of the phone, depending 923 * on the network mode. 924 * 925 * @param networkMode 926 * @return Phone Type 927 * 928 * @hide 929 */ 930 public static int getPhoneType(int networkMode) { 931 switch(networkMode) { 932 case RILConstants.NETWORK_MODE_CDMA: 933 case RILConstants.NETWORK_MODE_CDMA_NO_EVDO: 934 case RILConstants.NETWORK_MODE_EVDO_NO_CDMA: 935 return PhoneConstants.PHONE_TYPE_CDMA; 936 937 case RILConstants.NETWORK_MODE_WCDMA_PREF: 938 case RILConstants.NETWORK_MODE_GSM_ONLY: 939 case RILConstants.NETWORK_MODE_WCDMA_ONLY: 940 case RILConstants.NETWORK_MODE_GSM_UMTS: 941 case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA: 942 case RILConstants.NETWORK_MODE_LTE_WCDMA: 943 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA: 944 return PhoneConstants.PHONE_TYPE_GSM; 945 946 // Use CDMA Phone for the global mode including CDMA 947 case RILConstants.NETWORK_MODE_GLOBAL: 948 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO: 949 return PhoneConstants.PHONE_TYPE_CDMA; 950 951 case RILConstants.NETWORK_MODE_LTE_ONLY: 952 if (getLteOnCdmaModeStatic() == PhoneConstants.LTE_ON_CDMA_TRUE) { 953 return PhoneConstants.PHONE_TYPE_CDMA; 954 } else { 955 return PhoneConstants.PHONE_TYPE_GSM; 956 } 957 default: 958 return PhoneConstants.PHONE_TYPE_GSM; 959 } 960 } 961 962 /** 963 * The contents of the /proc/cmdline file 964 */ 965 private static String getProcCmdLine() 966 { 967 String cmdline = ""; 968 FileInputStream is = null; 969 try { 970 is = new FileInputStream("/proc/cmdline"); 971 byte [] buffer = new byte[2048]; 972 int count = is.read(buffer); 973 if (count > 0) { 974 cmdline = new String(buffer, 0, count); 975 } 976 } catch (IOException e) { 977 Rlog.d(TAG, "No /proc/cmdline exception=" + e); 978 } finally { 979 if (is != null) { 980 try { 981 is.close(); 982 } catch (IOException e) { 983 } 984 } 985 } 986 Rlog.d(TAG, "/proc/cmdline=" + cmdline); 987 return cmdline; 988 } 989 990 /** Kernel command line */ 991 private static final String sKernelCmdLine = getProcCmdLine(); 992 993 /** Pattern for selecting the product type from the kernel command line */ 994 private static final Pattern sProductTypePattern = 995 Pattern.compile("\\sproduct_type\\s*=\\s*(\\w+)"); 996 997 /** The ProductType used for LTE on CDMA devices */ 998 private static final String sLteOnCdmaProductType = 999 SystemProperties.get(TelephonyProperties.PROPERTY_LTE_ON_CDMA_PRODUCT_TYPE, ""); 1000 1001 /** 1002 * Return if the current radio is LTE on CDMA. This 1003 * is a tri-state return value as for a period of time 1004 * the mode may be unknown. 1005 * 1006 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 1007 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 1008 * 1009 * @hide 1010 */ 1011 public static int getLteOnCdmaModeStatic() { 1012 int retVal; 1013 int curVal; 1014 String productType = ""; 1015 1016 curVal = SystemProperties.getInt(TelephonyProperties.PROPERTY_LTE_ON_CDMA_DEVICE, 1017 PhoneConstants.LTE_ON_CDMA_UNKNOWN); 1018 retVal = curVal; 1019 if (retVal == PhoneConstants.LTE_ON_CDMA_UNKNOWN) { 1020 Matcher matcher = sProductTypePattern.matcher(sKernelCmdLine); 1021 if (matcher.find()) { 1022 productType = matcher.group(1); 1023 if (sLteOnCdmaProductType.equals(productType)) { 1024 retVal = PhoneConstants.LTE_ON_CDMA_TRUE; 1025 } else { 1026 retVal = PhoneConstants.LTE_ON_CDMA_FALSE; 1027 } 1028 } else { 1029 retVal = PhoneConstants.LTE_ON_CDMA_FALSE; 1030 } 1031 } 1032 1033 Rlog.d(TAG, "getLteOnCdmaMode=" + retVal + " curVal=" + curVal + 1034 " product_type='" + productType + 1035 "' lteOnCdmaProductType='" + sLteOnCdmaProductType + "'"); 1036 return retVal; 1037 } 1038 1039 // 1040 // 1041 // Current Network 1042 // 1043 // 1044 1045 /** 1046 * Returns the alphabetic name of current registered operator. 1047 * <p> 1048 * Availability: Only when user is registered to a network. Result may be 1049 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1050 * on a CDMA network). 1051 */ 1052 public String getNetworkOperatorName() { 1053 return getNetworkOperatorName(getDefaultSubscription()); 1054 } 1055 1056 /** 1057 * Returns the alphabetic name of current registered operator 1058 * for a particular subscription. 1059 * <p> 1060 * Availability: Only when user is registered to a network. Result may be 1061 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1062 * on a CDMA network). 1063 * @param subId 1064 */ 1065 /** {@hide} */ 1066 public String getNetworkOperatorName(int subId) { 1067 int phoneId = SubscriptionManager.getPhoneId(subId); 1068 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, ""); 1069 } 1070 1071 /** 1072 * Returns the numeric name (MCC+MNC) of current registered operator. 1073 * <p> 1074 * Availability: Only when user is registered to a network. Result may be 1075 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1076 * on a CDMA network). 1077 */ 1078 public String getNetworkOperator() { 1079 return getNetworkOperatorForPhone(getDefaultPhone()); 1080 } 1081 1082 /** 1083 * Returns the numeric name (MCC+MNC) of current registered operator 1084 * for a particular subscription. 1085 * <p> 1086 * Availability: Only when user is registered to a network. Result may be 1087 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1088 * on a CDMA network). 1089 * 1090 * @param subId 1091 */ 1092 /** {@hide} */ 1093 public String getNetworkOperatorForSubscription(int subId) { 1094 int phoneId = SubscriptionManager.getPhoneId(subId); 1095 return getNetworkOperatorForPhone(phoneId); 1096 } 1097 1098 /** 1099 * Returns the numeric name (MCC+MNC) of current registered operator 1100 * for a particular subscription. 1101 * <p> 1102 * Availability: Only when user is registered to a network. Result may be 1103 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1104 * on a CDMA network). 1105 * 1106 * @param phoneId 1107 * @hide 1108 **/ 1109 public String getNetworkOperatorForPhone(int phoneId) { 1110 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, ""); 1111 } 1112 1113 /** 1114 * Returns true if the device is considered roaming on the current 1115 * network, for GSM purposes. 1116 * <p> 1117 * Availability: Only when user registered to a network. 1118 */ 1119 public boolean isNetworkRoaming() { 1120 return isNetworkRoaming(getDefaultSubscription()); 1121 } 1122 1123 /** 1124 * Returns true if the device is considered roaming on the current 1125 * network for a subscription. 1126 * <p> 1127 * Availability: Only when user registered to a network. 1128 * 1129 * @param subId 1130 */ 1131 /** {@hide} */ 1132 public boolean isNetworkRoaming(int subId) { 1133 int phoneId = SubscriptionManager.getPhoneId(subId); 1134 return Boolean.parseBoolean(getTelephonyProperty(phoneId, 1135 TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, null)); 1136 } 1137 1138 /** 1139 * Returns the ISO country code equivalent of the current registered 1140 * operator's MCC (Mobile Country Code). 1141 * <p> 1142 * Availability: Only when user is registered to a network. Result may be 1143 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1144 * on a CDMA network). 1145 */ 1146 public String getNetworkCountryIso() { 1147 return getNetworkCountryIsoForPhone(getDefaultPhone()); 1148 } 1149 1150 /** 1151 * Returns the ISO country code equivalent of the current registered 1152 * operator's MCC (Mobile Country Code) of a subscription. 1153 * <p> 1154 * Availability: Only when user is registered to a network. Result may be 1155 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1156 * on a CDMA network). 1157 * 1158 * @param subId for which Network CountryIso is returned 1159 */ 1160 /** {@hide} */ 1161 public String getNetworkCountryIsoForSubscription(int subId) { 1162 int phoneId = SubscriptionManager.getPhoneId(subId); 1163 return getNetworkCountryIsoForPhone(phoneId); 1164 } 1165 1166 /** 1167 * Returns the ISO country code equivalent of the current registered 1168 * operator's MCC (Mobile Country Code) of a subscription. 1169 * <p> 1170 * Availability: Only when user is registered to a network. Result may be 1171 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1172 * on a CDMA network). 1173 * 1174 * @param phoneId for which Network CountryIso is returned 1175 */ 1176 /** {@hide} */ 1177 public String getNetworkCountryIsoForPhone(int phoneId) { 1178 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, ""); 1179 } 1180 1181 /** Network type is unknown */ 1182 public static final int NETWORK_TYPE_UNKNOWN = 0; 1183 /** Current network is GPRS */ 1184 public static final int NETWORK_TYPE_GPRS = 1; 1185 /** Current network is EDGE */ 1186 public static final int NETWORK_TYPE_EDGE = 2; 1187 /** Current network is UMTS */ 1188 public static final int NETWORK_TYPE_UMTS = 3; 1189 /** Current network is CDMA: Either IS95A or IS95B*/ 1190 public static final int NETWORK_TYPE_CDMA = 4; 1191 /** Current network is EVDO revision 0*/ 1192 public static final int NETWORK_TYPE_EVDO_0 = 5; 1193 /** Current network is EVDO revision A*/ 1194 public static final int NETWORK_TYPE_EVDO_A = 6; 1195 /** Current network is 1xRTT*/ 1196 public static final int NETWORK_TYPE_1xRTT = 7; 1197 /** Current network is HSDPA */ 1198 public static final int NETWORK_TYPE_HSDPA = 8; 1199 /** Current network is HSUPA */ 1200 public static final int NETWORK_TYPE_HSUPA = 9; 1201 /** Current network is HSPA */ 1202 public static final int NETWORK_TYPE_HSPA = 10; 1203 /** Current network is iDen */ 1204 public static final int NETWORK_TYPE_IDEN = 11; 1205 /** Current network is EVDO revision B*/ 1206 public static final int NETWORK_TYPE_EVDO_B = 12; 1207 /** Current network is LTE */ 1208 public static final int NETWORK_TYPE_LTE = 13; 1209 /** Current network is eHRPD */ 1210 public static final int NETWORK_TYPE_EHRPD = 14; 1211 /** Current network is HSPA+ */ 1212 public static final int NETWORK_TYPE_HSPAP = 15; 1213 /** Current network is GSM {@hide} */ 1214 public static final int NETWORK_TYPE_GSM = 16; 1215 /** Current network is TD_SCDMA {@hide} */ 1216 public static final int NETWORK_TYPE_TD_SCDMA = 17; 1217 /** Current network is IWLAN {@hide} */ 1218 public static final int NETWORK_TYPE_IWLAN = 18; 1219 1220 /** 1221 * @return the NETWORK_TYPE_xxxx for current data connection. 1222 */ 1223 public int getNetworkType() { 1224 return getDataNetworkType(); 1225 } 1226 1227 /** 1228 * Returns a constant indicating the radio technology (network type) 1229 * currently in use on the device for a subscription. 1230 * @return the network type 1231 * 1232 * @param subId for which network type is returned 1233 * 1234 * @see #NETWORK_TYPE_UNKNOWN 1235 * @see #NETWORK_TYPE_GPRS 1236 * @see #NETWORK_TYPE_EDGE 1237 * @see #NETWORK_TYPE_UMTS 1238 * @see #NETWORK_TYPE_HSDPA 1239 * @see #NETWORK_TYPE_HSUPA 1240 * @see #NETWORK_TYPE_HSPA 1241 * @see #NETWORK_TYPE_CDMA 1242 * @see #NETWORK_TYPE_EVDO_0 1243 * @see #NETWORK_TYPE_EVDO_A 1244 * @see #NETWORK_TYPE_EVDO_B 1245 * @see #NETWORK_TYPE_1xRTT 1246 * @see #NETWORK_TYPE_IDEN 1247 * @see #NETWORK_TYPE_LTE 1248 * @see #NETWORK_TYPE_EHRPD 1249 * @see #NETWORK_TYPE_HSPAP 1250 */ 1251 /** {@hide} */ 1252 public int getNetworkType(int subId) { 1253 try { 1254 ITelephony telephony = getITelephony(); 1255 if (telephony != null) { 1256 return telephony.getNetworkTypeForSubscriber(subId); 1257 } else { 1258 // This can happen when the ITelephony interface is not up yet. 1259 return NETWORK_TYPE_UNKNOWN; 1260 } 1261 } catch(RemoteException ex) { 1262 // This shouldn't happen in the normal case 1263 return NETWORK_TYPE_UNKNOWN; 1264 } catch (NullPointerException ex) { 1265 // This could happen before phone restarts due to crashing 1266 return NETWORK_TYPE_UNKNOWN; 1267 } 1268 } 1269 1270 /** 1271 * Returns a constant indicating the radio technology (network type) 1272 * currently in use on the device for data transmission. 1273 * @return the network type 1274 * 1275 * @see #NETWORK_TYPE_UNKNOWN 1276 * @see #NETWORK_TYPE_GPRS 1277 * @see #NETWORK_TYPE_EDGE 1278 * @see #NETWORK_TYPE_UMTS 1279 * @see #NETWORK_TYPE_HSDPA 1280 * @see #NETWORK_TYPE_HSUPA 1281 * @see #NETWORK_TYPE_HSPA 1282 * @see #NETWORK_TYPE_CDMA 1283 * @see #NETWORK_TYPE_EVDO_0 1284 * @see #NETWORK_TYPE_EVDO_A 1285 * @see #NETWORK_TYPE_EVDO_B 1286 * @see #NETWORK_TYPE_1xRTT 1287 * @see #NETWORK_TYPE_IDEN 1288 * @see #NETWORK_TYPE_LTE 1289 * @see #NETWORK_TYPE_EHRPD 1290 * @see #NETWORK_TYPE_HSPAP 1291 * 1292 * @hide 1293 */ 1294 public int getDataNetworkType() { 1295 return getDataNetworkType(getDefaultSubscription()); 1296 } 1297 1298 /** 1299 * Returns a constant indicating the radio technology (network type) 1300 * currently in use on the device for data transmission for a subscription 1301 * @return the network type 1302 * 1303 * @param subId for which network type is returned 1304 */ 1305 /** {@hide} */ 1306 public int getDataNetworkType(int subId) { 1307 try{ 1308 ITelephony telephony = getITelephony(); 1309 if (telephony != null) { 1310 return telephony.getDataNetworkTypeForSubscriber(subId); 1311 } else { 1312 // This can happen when the ITelephony interface is not up yet. 1313 return NETWORK_TYPE_UNKNOWN; 1314 } 1315 } catch(RemoteException ex) { 1316 // This shouldn't happen in the normal case 1317 return NETWORK_TYPE_UNKNOWN; 1318 } catch (NullPointerException ex) { 1319 // This could happen before phone restarts due to crashing 1320 return NETWORK_TYPE_UNKNOWN; 1321 } 1322 } 1323 1324 /** 1325 * Returns the NETWORK_TYPE_xxxx for voice 1326 * 1327 * @hide 1328 */ 1329 public int getVoiceNetworkType() { 1330 return getVoiceNetworkType(getDefaultSubscription()); 1331 } 1332 1333 /** 1334 * Returns the NETWORK_TYPE_xxxx for voice for a subId 1335 * 1336 */ 1337 /** {@hide} */ 1338 public int getVoiceNetworkType(int subId) { 1339 try{ 1340 ITelephony telephony = getITelephony(); 1341 if (telephony != null) { 1342 return telephony.getVoiceNetworkTypeForSubscriber(subId); 1343 } else { 1344 // This can happen when the ITelephony interface is not up yet. 1345 return NETWORK_TYPE_UNKNOWN; 1346 } 1347 } catch(RemoteException ex) { 1348 // This shouldn't happen in the normal case 1349 return NETWORK_TYPE_UNKNOWN; 1350 } catch (NullPointerException ex) { 1351 // This could happen before phone restarts due to crashing 1352 return NETWORK_TYPE_UNKNOWN; 1353 } 1354 } 1355 1356 /** Unknown network class. {@hide} */ 1357 public static final int NETWORK_CLASS_UNKNOWN = 0; 1358 /** Class of broadly defined "2G" networks. {@hide} */ 1359 public static final int NETWORK_CLASS_2_G = 1; 1360 /** Class of broadly defined "3G" networks. {@hide} */ 1361 public static final int NETWORK_CLASS_3_G = 2; 1362 /** Class of broadly defined "4G" networks. {@hide} */ 1363 public static final int NETWORK_CLASS_4_G = 3; 1364 1365 /** 1366 * Return general class of network type, such as "3G" or "4G". In cases 1367 * where classification is contentious, this method is conservative. 1368 * 1369 * @hide 1370 */ 1371 public static int getNetworkClass(int networkType) { 1372 switch (networkType) { 1373 case NETWORK_TYPE_GPRS: 1374 case NETWORK_TYPE_GSM: 1375 case NETWORK_TYPE_EDGE: 1376 case NETWORK_TYPE_CDMA: 1377 case NETWORK_TYPE_1xRTT: 1378 case NETWORK_TYPE_IDEN: 1379 return NETWORK_CLASS_2_G; 1380 case NETWORK_TYPE_UMTS: 1381 case NETWORK_TYPE_EVDO_0: 1382 case NETWORK_TYPE_EVDO_A: 1383 case NETWORK_TYPE_HSDPA: 1384 case NETWORK_TYPE_HSUPA: 1385 case NETWORK_TYPE_HSPA: 1386 case NETWORK_TYPE_EVDO_B: 1387 case NETWORK_TYPE_EHRPD: 1388 case NETWORK_TYPE_HSPAP: 1389 case NETWORK_TYPE_TD_SCDMA: 1390 return NETWORK_CLASS_3_G; 1391 case NETWORK_TYPE_LTE: 1392 case NETWORK_TYPE_IWLAN: 1393 return NETWORK_CLASS_4_G; 1394 default: 1395 return NETWORK_CLASS_UNKNOWN; 1396 } 1397 } 1398 1399 /** 1400 * Returns a string representation of the radio technology (network type) 1401 * currently in use on the device. 1402 * @return the name of the radio technology 1403 * 1404 * @hide pending API council review 1405 */ 1406 public String getNetworkTypeName() { 1407 return getNetworkTypeName(getNetworkType()); 1408 } 1409 1410 /** 1411 * Returns a string representation of the radio technology (network type) 1412 * currently in use on the device. 1413 * @param subId for which network type is returned 1414 * @return the name of the radio technology 1415 * 1416 */ 1417 /** {@hide} */ 1418 public static String getNetworkTypeName(int type) { 1419 switch (type) { 1420 case NETWORK_TYPE_GPRS: 1421 return "GPRS"; 1422 case NETWORK_TYPE_EDGE: 1423 return "EDGE"; 1424 case NETWORK_TYPE_UMTS: 1425 return "UMTS"; 1426 case NETWORK_TYPE_HSDPA: 1427 return "HSDPA"; 1428 case NETWORK_TYPE_HSUPA: 1429 return "HSUPA"; 1430 case NETWORK_TYPE_HSPA: 1431 return "HSPA"; 1432 case NETWORK_TYPE_CDMA: 1433 return "CDMA"; 1434 case NETWORK_TYPE_EVDO_0: 1435 return "CDMA - EvDo rev. 0"; 1436 case NETWORK_TYPE_EVDO_A: 1437 return "CDMA - EvDo rev. A"; 1438 case NETWORK_TYPE_EVDO_B: 1439 return "CDMA - EvDo rev. B"; 1440 case NETWORK_TYPE_1xRTT: 1441 return "CDMA - 1xRTT"; 1442 case NETWORK_TYPE_LTE: 1443 return "LTE"; 1444 case NETWORK_TYPE_EHRPD: 1445 return "CDMA - eHRPD"; 1446 case NETWORK_TYPE_IDEN: 1447 return "iDEN"; 1448 case NETWORK_TYPE_HSPAP: 1449 return "HSPA+"; 1450 case NETWORK_TYPE_GSM: 1451 return "GSM"; 1452 case NETWORK_TYPE_TD_SCDMA: 1453 return "TD_SCDMA"; 1454 case NETWORK_TYPE_IWLAN: 1455 return "IWLAN"; 1456 default: 1457 return "UNKNOWN"; 1458 } 1459 } 1460 1461 // 1462 // 1463 // SIM Card 1464 // 1465 // 1466 1467 /** 1468 * SIM card state: Unknown. Signifies that the SIM is in transition 1469 * between states. For example, when the user inputs the SIM pin 1470 * under PIN_REQUIRED state, a query for sim status returns 1471 * this state before turning to SIM_STATE_READY. 1472 * 1473 * These are the ordinal value of IccCardConstants.State. 1474 */ 1475 public static final int SIM_STATE_UNKNOWN = 0; 1476 /** SIM card state: no SIM card is available in the device */ 1477 public static final int SIM_STATE_ABSENT = 1; 1478 /** SIM card state: Locked: requires the user's SIM PIN to unlock */ 1479 public static final int SIM_STATE_PIN_REQUIRED = 2; 1480 /** SIM card state: Locked: requires the user's SIM PUK to unlock */ 1481 public static final int SIM_STATE_PUK_REQUIRED = 3; 1482 /** SIM card state: Locked: requires a network PIN to unlock */ 1483 public static final int SIM_STATE_NETWORK_LOCKED = 4; 1484 /** SIM card state: Ready */ 1485 public static final int SIM_STATE_READY = 5; 1486 /** SIM card state: SIM Card is NOT READY 1487 *@hide 1488 */ 1489 public static final int SIM_STATE_NOT_READY = 6; 1490 /** SIM card state: SIM Card Error, permanently disabled 1491 *@hide 1492 */ 1493 public static final int SIM_STATE_PERM_DISABLED = 7; 1494 /** SIM card state: SIM Card Error, present but faulty 1495 *@hide 1496 */ 1497 public static final int SIM_STATE_CARD_IO_ERROR = 8; 1498 1499 /** 1500 * @return true if a ICC card is present 1501 */ 1502 public boolean hasIccCard() { 1503 return hasIccCard(getDefaultSim()); 1504 } 1505 1506 /** 1507 * @return true if a ICC card is present for a subscription 1508 * 1509 * @param slotId for which icc card presence is checked 1510 */ 1511 /** {@hide} */ 1512 // FIXME Input argument slotId should be of type int 1513 public boolean hasIccCard(int slotId) { 1514 1515 try { 1516 return getITelephony().hasIccCardUsingSlotId(slotId); 1517 } catch (RemoteException ex) { 1518 // Assume no ICC card if remote exception which shouldn't happen 1519 return false; 1520 } catch (NullPointerException ex) { 1521 // This could happen before phone restarts due to crashing 1522 return false; 1523 } 1524 } 1525 1526 /** 1527 * Returns a constant indicating the state of the default SIM card. 1528 * 1529 * @see #SIM_STATE_UNKNOWN 1530 * @see #SIM_STATE_ABSENT 1531 * @see #SIM_STATE_PIN_REQUIRED 1532 * @see #SIM_STATE_PUK_REQUIRED 1533 * @see #SIM_STATE_NETWORK_LOCKED 1534 * @see #SIM_STATE_READY 1535 * @see #SIM_STATE_NOT_READY 1536 * @see #SIM_STATE_PERM_DISABLED 1537 * @see #SIM_STATE_CARD_IO_ERROR 1538 */ 1539 public int getSimState() { 1540 return getSimState(getDefaultSim()); 1541 } 1542 1543 /** 1544 * Returns a constant indicating the state of the device SIM card in a slot. 1545 * 1546 * @param slotIdx 1547 * 1548 * @see #SIM_STATE_UNKNOWN 1549 * @see #SIM_STATE_ABSENT 1550 * @see #SIM_STATE_PIN_REQUIRED 1551 * @see #SIM_STATE_PUK_REQUIRED 1552 * @see #SIM_STATE_NETWORK_LOCKED 1553 * @see #SIM_STATE_READY 1554 * @see #SIM_STATE_NOT_READY 1555 * @see #SIM_STATE_PERM_DISABLED 1556 * @see #SIM_STATE_CARD_IO_ERROR 1557 */ 1558 /** {@hide} */ 1559 public int getSimState(int slotIdx) { 1560 int[] subId = SubscriptionManager.getSubId(slotIdx); 1561 if (subId == null || subId.length == 0) { 1562 Rlog.d(TAG, "getSimState:- empty subId return SIM_STATE_ABSENT"); 1563 return SIM_STATE_UNKNOWN; 1564 } 1565 int simState = SubscriptionManager.getSimStateForSubscriber(subId[0]); 1566 Rlog.d(TAG, "getSimState: simState=" + simState + " slotIdx=" + slotIdx); 1567 return simState; 1568 } 1569 1570 /** 1571 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1572 * provider of the SIM. 5 or 6 decimal digits. 1573 * <p> 1574 * Availability: SIM state must be {@link #SIM_STATE_READY} 1575 * 1576 * @see #getSimState 1577 */ 1578 public String getSimOperator() { 1579 return getSimOperatorNumeric(); 1580 } 1581 1582 /** 1583 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1584 * provider of the SIM. 5 or 6 decimal digits. 1585 * <p> 1586 * Availability: SIM state must be {@link #SIM_STATE_READY} 1587 * 1588 * @see #getSimState 1589 * 1590 * @param subId for which SimOperator is returned 1591 * @hide 1592 */ 1593 public String getSimOperator(int subId) { 1594 return getSimOperatorNumericForSubscription(subId); 1595 } 1596 1597 /** 1598 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1599 * provider of the SIM. 5 or 6 decimal digits. 1600 * <p> 1601 * Availability: SIM state must be {@link #SIM_STATE_READY} 1602 * 1603 * @see #getSimState 1604 * @hide 1605 */ 1606 public String getSimOperatorNumeric() { 1607 int subId = SubscriptionManager.getDefaultDataSubId(); 1608 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 1609 subId = SubscriptionManager.getDefaultSmsSubId(); 1610 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 1611 subId = SubscriptionManager.getDefaultVoiceSubId(); 1612 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 1613 subId = SubscriptionManager.getDefaultSubId(); 1614 } 1615 } 1616 } 1617 Rlog.d(TAG, "getSimOperatorNumeric(): default subId=" + subId); 1618 return getSimOperatorNumericForSubscription(subId); 1619 } 1620 1621 /** 1622 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1623 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 1624 * <p> 1625 * Availability: SIM state must be {@link #SIM_STATE_READY} 1626 * 1627 * @see #getSimState 1628 * 1629 * @param subId for which SimOperator is returned 1630 * @hide 1631 */ 1632 public String getSimOperatorNumericForSubscription(int subId) { 1633 int phoneId = SubscriptionManager.getPhoneId(subId); 1634 return getSimOperatorNumericForPhone(phoneId); 1635 } 1636 1637 /** 1638 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1639 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 1640 * <p> 1641 * 1642 * @param phoneId for which SimOperator is returned 1643 * @hide 1644 */ 1645 public String getSimOperatorNumericForPhone(int phoneId) { 1646 return getTelephonyProperty(phoneId, 1647 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, ""); 1648 } 1649 1650 /** 1651 * Returns the Service Provider Name (SPN). 1652 * <p> 1653 * Availability: SIM state must be {@link #SIM_STATE_READY} 1654 * 1655 * @see #getSimState 1656 */ 1657 public String getSimOperatorName() { 1658 return getSimOperatorNameForPhone(getDefaultPhone()); 1659 } 1660 1661 /** 1662 * Returns the Service Provider Name (SPN). 1663 * <p> 1664 * Availability: SIM state must be {@link #SIM_STATE_READY} 1665 * 1666 * @see #getSimState 1667 * 1668 * @param subId for which SimOperatorName is returned 1669 * @hide 1670 */ 1671 public String getSimOperatorNameForSubscription(int subId) { 1672 int phoneId = SubscriptionManager.getPhoneId(subId); 1673 return getSimOperatorNameForPhone(phoneId); 1674 } 1675 1676 /** 1677 * Returns the Service Provider Name (SPN). 1678 * 1679 * @hide 1680 */ 1681 public String getSimOperatorNameForPhone(int phoneId) { 1682 return getTelephonyProperty(phoneId, 1683 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, ""); 1684 } 1685 1686 /** 1687 * Returns the ISO country code equivalent for the SIM provider's country code. 1688 */ 1689 public String getSimCountryIso() { 1690 return getSimCountryIsoForPhone(getDefaultPhone()); 1691 } 1692 1693 /** 1694 * Returns the ISO country code equivalent for the SIM provider's country code. 1695 * 1696 * @param subId for which SimCountryIso is returned 1697 * 1698 * @hide 1699 */ 1700 public String getSimCountryIso(int subId) { 1701 return getSimCountryIsoForSubscription(subId); 1702 } 1703 1704 /** 1705 * Returns the ISO country code equivalent for the SIM provider's country code. 1706 * 1707 * @param subId for which SimCountryIso is returned 1708 * 1709 * @hide 1710 */ 1711 public String getSimCountryIsoForSubscription(int subId) { 1712 int phoneId = SubscriptionManager.getPhoneId(subId); 1713 return getSimCountryIsoForPhone(phoneId); 1714 } 1715 1716 /** 1717 * Returns the ISO country code equivalent for the SIM provider's country code. 1718 * 1719 * @hide 1720 */ 1721 public String getSimCountryIsoForPhone(int phoneId) { 1722 return getTelephonyProperty(phoneId, 1723 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, ""); 1724 } 1725 1726 /** 1727 * Returns the serial number of the SIM, if applicable. Return null if it is 1728 * unavailable. 1729 * <p> 1730 * Requires Permission: 1731 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1732 */ 1733 public String getSimSerialNumber() { 1734 return getSimSerialNumber(getDefaultSubscription()); 1735 } 1736 1737 /** 1738 * Returns the serial number for the given subscription, if applicable. Return null if it is 1739 * unavailable. 1740 * <p> 1741 * @param subId for which Sim Serial number is returned 1742 * Requires Permission: 1743 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1744 */ 1745 /** {@hide} */ 1746 public String getSimSerialNumber(int subId) { 1747 try { 1748 return getSubscriberInfo().getIccSerialNumberForSubscriber(subId); 1749 } catch (RemoteException ex) { 1750 return null; 1751 } catch (NullPointerException ex) { 1752 // This could happen before phone restarts due to crashing 1753 return null; 1754 } 1755 } 1756 1757 /** 1758 * Return if the current radio is LTE on CDMA. This 1759 * is a tri-state return value as for a period of time 1760 * the mode may be unknown. 1761 * 1762 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 1763 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 1764 * 1765 * @hide 1766 */ 1767 public int getLteOnCdmaMode() { 1768 return getLteOnCdmaMode(getDefaultSubscription()); 1769 } 1770 1771 /** 1772 * Return if the current radio is LTE on CDMA for Subscription. This 1773 * is a tri-state return value as for a period of time 1774 * the mode may be unknown. 1775 * 1776 * @param subId for which radio is LTE on CDMA is returned 1777 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 1778 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 1779 * 1780 */ 1781 /** {@hide} */ 1782 public int getLteOnCdmaMode(int subId) { 1783 try { 1784 return getITelephony().getLteOnCdmaModeForSubscriber(subId); 1785 } catch (RemoteException ex) { 1786 // Assume no ICC card if remote exception which shouldn't happen 1787 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 1788 } catch (NullPointerException ex) { 1789 // This could happen before phone restarts due to crashing 1790 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 1791 } 1792 } 1793 1794 // 1795 // 1796 // Subscriber Info 1797 // 1798 // 1799 1800 /** 1801 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone. 1802 * Return null if it is unavailable. 1803 * <p> 1804 * Requires Permission: 1805 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1806 */ 1807 public String getSubscriberId() { 1808 return getSubscriberId(getDefaultSubscription()); 1809 } 1810 1811 /** 1812 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone 1813 * for a subscription. 1814 * Return null if it is unavailable. 1815 * <p> 1816 * Requires Permission: 1817 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1818 * 1819 * @param subId whose subscriber id is returned 1820 */ 1821 /** {@hide} */ 1822 public String getSubscriberId(int subId) { 1823 try { 1824 return getSubscriberInfo().getSubscriberIdForSubscriber(subId); 1825 } catch (RemoteException ex) { 1826 return null; 1827 } catch (NullPointerException ex) { 1828 // This could happen before phone restarts due to crashing 1829 return null; 1830 } 1831 } 1832 1833 /** 1834 * Returns the Group Identifier Level1 for a GSM phone. 1835 * Return null if it is unavailable. 1836 * <p> 1837 * Requires Permission: 1838 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1839 */ 1840 public String getGroupIdLevel1() { 1841 try { 1842 return getSubscriberInfo().getGroupIdLevel1(); 1843 } catch (RemoteException ex) { 1844 return null; 1845 } catch (NullPointerException ex) { 1846 // This could happen before phone restarts due to crashing 1847 return null; 1848 } 1849 } 1850 1851 /** 1852 * Returns the Group Identifier Level1 for a GSM phone for a particular subscription. 1853 * Return null if it is unavailable. 1854 * <p> 1855 * Requires Permission: 1856 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1857 * 1858 * @param subscription whose subscriber id is returned 1859 */ 1860 /** {@hide} */ 1861 public String getGroupIdLevel1(int subId) { 1862 try { 1863 return getSubscriberInfo().getGroupIdLevel1ForSubscriber(subId); 1864 } catch (RemoteException ex) { 1865 return null; 1866 } catch (NullPointerException ex) { 1867 // This could happen before phone restarts due to crashing 1868 return null; 1869 } 1870 } 1871 1872 /** 1873 * Returns the phone number string for line 1, for example, the MSISDN 1874 * for a GSM phone. Return null if it is unavailable. 1875 * <p> 1876 * Requires Permission: 1877 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1878 */ 1879 public String getLine1Number() { 1880 return getLine1NumberForSubscriber(getDefaultSubscription()); 1881 } 1882 1883 /** 1884 * Returns the phone number string for line 1, for example, the MSISDN 1885 * for a GSM phone for a particular subscription. Return null if it is unavailable. 1886 * <p> 1887 * Requires Permission: 1888 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1889 * 1890 * @param subId whose phone number for line 1 is returned 1891 */ 1892 /** {@hide} */ 1893 public String getLine1NumberForSubscriber(int subId) { 1894 String number = null; 1895 try { 1896 number = getITelephony().getLine1NumberForDisplay(subId); 1897 } catch (RemoteException ex) { 1898 } catch (NullPointerException ex) { 1899 } 1900 if (number != null) { 1901 return number; 1902 } 1903 try { 1904 return getSubscriberInfo().getLine1NumberForSubscriber(subId); 1905 } catch (RemoteException ex) { 1906 return null; 1907 } catch (NullPointerException ex) { 1908 // This could happen before phone restarts due to crashing 1909 return null; 1910 } 1911 } 1912 1913 /** 1914 * Set the line 1 phone number string and its alphatag for the current ICCID 1915 * for display purpose only, for example, displayed in Phone Status. It won't 1916 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 1917 * value. 1918 * 1919 * <p>Requires that the calling app has carrier privileges. 1920 * @see #hasCarrierPrivileges 1921 * 1922 * @param alphaTag alpha-tagging of the dailing nubmer 1923 * @param number The dialing number 1924 * @return true if the operation was executed correctly. 1925 */ 1926 public boolean setLine1NumberForDisplay(String alphaTag, String number) { 1927 return setLine1NumberForDisplayForSubscriber(getDefaultSubscription(), alphaTag, number); 1928 } 1929 1930 /** 1931 * Set the line 1 phone number string and its alphatag for the current ICCID 1932 * for display purpose only, for example, displayed in Phone Status. It won't 1933 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 1934 * value. 1935 * 1936 * <p>Requires that the calling app has carrier privileges. 1937 * @see #hasCarrierPrivileges 1938 * 1939 * @param subId the subscriber that the alphatag and dialing number belongs to. 1940 * @param alphaTag alpha-tagging of the dailing nubmer 1941 * @param number The dialing number 1942 * @return true if the operation was executed correctly. 1943 * @hide 1944 */ 1945 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, String number) { 1946 try { 1947 return getITelephony().setLine1NumberForDisplayForSubscriber(subId, alphaTag, number); 1948 } catch (RemoteException ex) { 1949 } catch (NullPointerException ex) { 1950 } 1951 return false; 1952 } 1953 1954 /** 1955 * Returns the alphabetic identifier associated with the line 1 number. 1956 * Return null if it is unavailable. 1957 * <p> 1958 * Requires Permission: 1959 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1960 * @hide 1961 * nobody seems to call this. 1962 */ 1963 public String getLine1AlphaTag() { 1964 return getLine1AlphaTagForSubscriber(getDefaultSubscription()); 1965 } 1966 1967 /** 1968 * Returns the alphabetic identifier associated with the line 1 number 1969 * for a subscription. 1970 * Return null if it is unavailable. 1971 * <p> 1972 * Requires Permission: 1973 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1974 * @param subId whose alphabetic identifier associated with line 1 is returned 1975 * nobody seems to call this. 1976 */ 1977 /** {@hide} */ 1978 public String getLine1AlphaTagForSubscriber(int subId) { 1979 String alphaTag = null; 1980 try { 1981 alphaTag = getITelephony().getLine1AlphaTagForDisplay(subId); 1982 } catch (RemoteException ex) { 1983 } catch (NullPointerException ex) { 1984 } 1985 if (alphaTag != null) { 1986 return alphaTag; 1987 } 1988 try { 1989 return getSubscriberInfo().getLine1AlphaTagForSubscriber(subId); 1990 } catch (RemoteException ex) { 1991 return null; 1992 } catch (NullPointerException ex) { 1993 // This could happen before phone restarts due to crashing 1994 return null; 1995 } 1996 } 1997 1998 /** 1999 * Return the set of subscriber IDs that should be considered as "merged 2000 * together" for data usage purposes. This is commonly {@code null} to 2001 * indicate no merging is required. Any returned subscribers are sorted in a 2002 * deterministic order. 2003 * 2004 * @hide 2005 */ 2006 public @Nullable String[] getMergedSubscriberIds() { 2007 try { 2008 return getITelephony().getMergedSubscriberIds(); 2009 } catch (RemoteException ex) { 2010 } catch (NullPointerException ex) { 2011 } 2012 return null; 2013 } 2014 2015 /** 2016 * Returns the MSISDN string. 2017 * for a GSM phone. Return null if it is unavailable. 2018 * <p> 2019 * Requires Permission: 2020 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2021 * 2022 * @hide 2023 */ 2024 public String getMsisdn() { 2025 return getMsisdn(getDefaultSubscription()); 2026 } 2027 2028 /** 2029 * Returns the MSISDN string. 2030 * for a GSM phone. Return null if it is unavailable. 2031 * <p> 2032 * Requires Permission: 2033 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2034 * 2035 * @param subId for which msisdn is returned 2036 */ 2037 /** {@hide} */ 2038 public String getMsisdn(int subId) { 2039 try { 2040 return getSubscriberInfo().getMsisdnForSubscriber(subId); 2041 } catch (RemoteException ex) { 2042 return null; 2043 } catch (NullPointerException ex) { 2044 // This could happen before phone restarts due to crashing 2045 return null; 2046 } 2047 } 2048 2049 /** 2050 * Returns the voice mail number. Return null if it is unavailable. 2051 * <p> 2052 * Requires Permission: 2053 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2054 */ 2055 public String getVoiceMailNumber() { 2056 return getVoiceMailNumber(getDefaultSubscription()); 2057 } 2058 2059 /** 2060 * Returns the voice mail number for a subscription. 2061 * Return null if it is unavailable. 2062 * <p> 2063 * Requires Permission: 2064 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2065 * @param subId whose voice mail number is returned 2066 */ 2067 /** {@hide} */ 2068 public String getVoiceMailNumber(int subId) { 2069 try { 2070 return getSubscriberInfo().getVoiceMailNumberForSubscriber(subId); 2071 } catch (RemoteException ex) { 2072 return null; 2073 } catch (NullPointerException ex) { 2074 // This could happen before phone restarts due to crashing 2075 return null; 2076 } 2077 } 2078 2079 /** 2080 * Returns the complete voice mail number. Return null if it is unavailable. 2081 * <p> 2082 * Requires Permission: 2083 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 2084 * 2085 * @hide 2086 */ 2087 public String getCompleteVoiceMailNumber() { 2088 return getCompleteVoiceMailNumber(getDefaultSubscription()); 2089 } 2090 2091 /** 2092 * Returns the complete voice mail number. Return null if it is unavailable. 2093 * <p> 2094 * Requires Permission: 2095 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 2096 * 2097 * @param subId 2098 */ 2099 /** {@hide} */ 2100 public String getCompleteVoiceMailNumber(int subId) { 2101 try { 2102 return getSubscriberInfo().getCompleteVoiceMailNumberForSubscriber(subId); 2103 } catch (RemoteException ex) { 2104 return null; 2105 } catch (NullPointerException ex) { 2106 // This could happen before phone restarts due to crashing 2107 return null; 2108 } 2109 } 2110 2111 /** 2112 * Sets the voice mail number. 2113 * 2114 * <p>Requires that the calling app has carrier privileges. 2115 * @see #hasCarrierPrivileges 2116 * 2117 * @param alphaTag The alpha tag to display. 2118 * @param number The voicemail number. 2119 */ 2120 public boolean setVoiceMailNumber(String alphaTag, String number) { 2121 return setVoiceMailNumber(getDefaultSubscription(), alphaTag, number); 2122 } 2123 2124 /** 2125 * Sets the voicemail number for the given subscriber. 2126 * 2127 * <p>Requires that the calling app has carrier privileges. 2128 * @see #hasCarrierPrivileges 2129 * 2130 * @param subId The subscription id. 2131 * @param alphaTag The alpha tag to display. 2132 * @param number The voicemail number. 2133 */ 2134 /** {@hide} */ 2135 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { 2136 try { 2137 return getITelephony().setVoiceMailNumber(subId, alphaTag, number); 2138 } catch (RemoteException ex) { 2139 } catch (NullPointerException ex) { 2140 } 2141 return false; 2142 } 2143 2144 /** 2145 * Returns the voice mail count. Return 0 if unavailable. 2146 * <p> 2147 * Requires Permission: 2148 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2149 * @hide 2150 */ 2151 public int getVoiceMessageCount() { 2152 return getVoiceMessageCount(getDefaultSubscription()); 2153 } 2154 2155 /** 2156 * Returns the voice mail count for a subscription. Return 0 if unavailable. 2157 * <p> 2158 * Requires Permission: 2159 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2160 * @param subId whose voice message count is returned 2161 */ 2162 /** {@hide} */ 2163 public int getVoiceMessageCount(int subId) { 2164 try { 2165 return getITelephony().getVoiceMessageCountForSubscriber(subId); 2166 } catch (RemoteException ex) { 2167 return 0; 2168 } catch (NullPointerException ex) { 2169 // This could happen before phone restarts due to crashing 2170 return 0; 2171 } 2172 } 2173 2174 /** 2175 * Retrieves the alphabetic identifier associated with the voice 2176 * mail number. 2177 * <p> 2178 * Requires Permission: 2179 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2180 */ 2181 public String getVoiceMailAlphaTag() { 2182 return getVoiceMailAlphaTag(getDefaultSubscription()); 2183 } 2184 2185 /** 2186 * Retrieves the alphabetic identifier associated with the voice 2187 * mail number for a subscription. 2188 * <p> 2189 * Requires Permission: 2190 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2191 * @param subId whose alphabetic identifier associated with the 2192 * voice mail number is returned 2193 */ 2194 /** {@hide} */ 2195 public String getVoiceMailAlphaTag(int subId) { 2196 try { 2197 return getSubscriberInfo().getVoiceMailAlphaTagForSubscriber(subId); 2198 } catch (RemoteException ex) { 2199 return null; 2200 } catch (NullPointerException ex) { 2201 // This could happen before phone restarts due to crashing 2202 return null; 2203 } 2204 } 2205 2206 /** 2207 * Returns the IMS private user identity (IMPI) that was loaded from the ISIM. 2208 * @return the IMPI, or null if not present or not loaded 2209 * @hide 2210 */ 2211 public String getIsimImpi() { 2212 try { 2213 return getSubscriberInfo().getIsimImpi(); 2214 } catch (RemoteException ex) { 2215 return null; 2216 } catch (NullPointerException ex) { 2217 // This could happen before phone restarts due to crashing 2218 return null; 2219 } 2220 } 2221 2222 /** 2223 * Returns the IMS home network domain name that was loaded from the ISIM. 2224 * @return the IMS domain name, or null if not present or not loaded 2225 * @hide 2226 */ 2227 public String getIsimDomain() { 2228 try { 2229 return getSubscriberInfo().getIsimDomain(); 2230 } catch (RemoteException ex) { 2231 return null; 2232 } catch (NullPointerException ex) { 2233 // This could happen before phone restarts due to crashing 2234 return null; 2235 } 2236 } 2237 2238 /** 2239 * Returns the IMS public user identities (IMPU) that were loaded from the ISIM. 2240 * @return an array of IMPU strings, with one IMPU per string, or null if 2241 * not present or not loaded 2242 * @hide 2243 */ 2244 public String[] getIsimImpu() { 2245 try { 2246 return getSubscriberInfo().getIsimImpu(); 2247 } catch (RemoteException ex) { 2248 return null; 2249 } catch (NullPointerException ex) { 2250 // This could happen before phone restarts due to crashing 2251 return null; 2252 } 2253 } 2254 2255 /** 2256 * @hide 2257 */ 2258 private IPhoneSubInfo getSubscriberInfo() { 2259 // get it each time because that process crashes a lot 2260 return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo")); 2261 } 2262 2263 /** Device call state: No activity. */ 2264 public static final int CALL_STATE_IDLE = 0; 2265 /** Device call state: Ringing. A new call arrived and is 2266 * ringing or waiting. In the latter case, another call is 2267 * already active. */ 2268 public static final int CALL_STATE_RINGING = 1; 2269 /** Device call state: Off-hook. At least one call exists 2270 * that is dialing, active, or on hold, and no calls are ringing 2271 * or waiting. */ 2272 public static final int CALL_STATE_OFFHOOK = 2; 2273 2274 /** 2275 * Returns a constant indicating the call state (cellular) on the device. 2276 */ 2277 public int getCallState() { 2278 return getCallState(getDefaultSubscription()); 2279 } 2280 2281 /** 2282 * Returns a constant indicating the call state (cellular) on the device 2283 * for a subscription. 2284 * 2285 * @param subId whose call state is returned 2286 */ 2287 /** {@hide} */ 2288 public int getCallState(int subId) { 2289 try { 2290 return getITelephony().getCallStateForSubscriber(subId); 2291 } catch (RemoteException ex) { 2292 // the phone process is restarting. 2293 return CALL_STATE_IDLE; 2294 } catch (NullPointerException ex) { 2295 // the phone process is restarting. 2296 return CALL_STATE_IDLE; 2297 } 2298 } 2299 2300 /** Data connection activity: No traffic. */ 2301 public static final int DATA_ACTIVITY_NONE = 0x00000000; 2302 /** Data connection activity: Currently receiving IP PPP traffic. */ 2303 public static final int DATA_ACTIVITY_IN = 0x00000001; 2304 /** Data connection activity: Currently sending IP PPP traffic. */ 2305 public static final int DATA_ACTIVITY_OUT = 0x00000002; 2306 /** Data connection activity: Currently both sending and receiving 2307 * IP PPP traffic. */ 2308 public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT; 2309 /** 2310 * Data connection is active, but physical link is down 2311 */ 2312 public static final int DATA_ACTIVITY_DORMANT = 0x00000004; 2313 2314 /** 2315 * Returns a constant indicating the type of activity on a data connection 2316 * (cellular). 2317 * 2318 * @see #DATA_ACTIVITY_NONE 2319 * @see #DATA_ACTIVITY_IN 2320 * @see #DATA_ACTIVITY_OUT 2321 * @see #DATA_ACTIVITY_INOUT 2322 * @see #DATA_ACTIVITY_DORMANT 2323 */ 2324 public int getDataActivity() { 2325 try { 2326 return getITelephony().getDataActivity(); 2327 } catch (RemoteException ex) { 2328 // the phone process is restarting. 2329 return DATA_ACTIVITY_NONE; 2330 } catch (NullPointerException ex) { 2331 // the phone process is restarting. 2332 return DATA_ACTIVITY_NONE; 2333 } 2334 } 2335 2336 /** Data connection state: Unknown. Used before we know the state. 2337 * @hide 2338 */ 2339 public static final int DATA_UNKNOWN = -1; 2340 /** Data connection state: Disconnected. IP traffic not available. */ 2341 public static final int DATA_DISCONNECTED = 0; 2342 /** Data connection state: Currently setting up a data connection. */ 2343 public static final int DATA_CONNECTING = 1; 2344 /** Data connection state: Connected. IP traffic should be available. */ 2345 public static final int DATA_CONNECTED = 2; 2346 /** Data connection state: Suspended. The connection is up, but IP 2347 * traffic is temporarily unavailable. For example, in a 2G network, 2348 * data activity may be suspended when a voice call arrives. */ 2349 public static final int DATA_SUSPENDED = 3; 2350 2351 /** 2352 * Returns a constant indicating the current data connection state 2353 * (cellular). 2354 * 2355 * @see #DATA_DISCONNECTED 2356 * @see #DATA_CONNECTING 2357 * @see #DATA_CONNECTED 2358 * @see #DATA_SUSPENDED 2359 */ 2360 public int getDataState() { 2361 try { 2362 return getITelephony().getDataState(); 2363 } catch (RemoteException ex) { 2364 // the phone process is restarting. 2365 return DATA_DISCONNECTED; 2366 } catch (NullPointerException ex) { 2367 return DATA_DISCONNECTED; 2368 } 2369 } 2370 2371 /** 2372 * @hide 2373 */ 2374 private ITelephony getITelephony() { 2375 return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); 2376 } 2377 2378 /** 2379 * @hide 2380 */ 2381 private ITelecomService getTelecomService() { 2382 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE)); 2383 } 2384 2385 // 2386 // 2387 // PhoneStateListener 2388 // 2389 // 2390 2391 /** 2392 * Registers a listener object to receive notification of changes 2393 * in specified telephony states. 2394 * <p> 2395 * To register a listener, pass a {@link PhoneStateListener} 2396 * and specify at least one telephony state of interest in 2397 * the events argument. 2398 * 2399 * At registration, and when a specified telephony state 2400 * changes, the telephony manager invokes the appropriate 2401 * callback method on the listener object and passes the 2402 * current (updated) values. 2403 * <p> 2404 * To unregister a listener, pass the listener object and set the 2405 * events argument to 2406 * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0). 2407 * 2408 * @param listener The {@link PhoneStateListener} object to register 2409 * (or unregister) 2410 * @param events The telephony state(s) of interest to the listener, 2411 * as a bitwise-OR combination of {@link PhoneStateListener} 2412 * LISTEN_ flags. 2413 */ 2414 public void listen(PhoneStateListener listener, int events) { 2415 String pkgForDebug = mContext != null ? mContext.getPackageName() : "<unknown>"; 2416 try { 2417 Boolean notifyNow = (getITelephony() != null); 2418 sRegistry.listenForSubscriber(listener.mSubId, pkgForDebug, listener.callback, events, notifyNow); 2419 } catch (RemoteException ex) { 2420 // system process dead 2421 } catch (NullPointerException ex) { 2422 // system process dead 2423 } 2424 } 2425 2426 /** 2427 * Returns the CDMA ERI icon index to display 2428 * 2429 * @hide 2430 */ 2431 public int getCdmaEriIconIndex() { 2432 return getCdmaEriIconIndex(getDefaultSubscription()); 2433 } 2434 2435 /** 2436 * Returns the CDMA ERI icon index to display for a subscription 2437 */ 2438 /** {@hide} */ 2439 public int getCdmaEriIconIndex(int subId) { 2440 try { 2441 return getITelephony().getCdmaEriIconIndexForSubscriber(subId); 2442 } catch (RemoteException ex) { 2443 // the phone process is restarting. 2444 return -1; 2445 } catch (NullPointerException ex) { 2446 return -1; 2447 } 2448 } 2449 2450 /** 2451 * Returns the CDMA ERI icon mode, 2452 * 0 - ON 2453 * 1 - FLASHING 2454 * 2455 * @hide 2456 */ 2457 public int getCdmaEriIconMode() { 2458 return getCdmaEriIconMode(getDefaultSubscription()); 2459 } 2460 2461 /** 2462 * Returns the CDMA ERI icon mode for a subscription. 2463 * 0 - ON 2464 * 1 - FLASHING 2465 */ 2466 /** {@hide} */ 2467 public int getCdmaEriIconMode(int subId) { 2468 try { 2469 return getITelephony().getCdmaEriIconModeForSubscriber(subId); 2470 } catch (RemoteException ex) { 2471 // the phone process is restarting. 2472 return -1; 2473 } catch (NullPointerException ex) { 2474 return -1; 2475 } 2476 } 2477 2478 /** 2479 * Returns the CDMA ERI text, 2480 * 2481 * @hide 2482 */ 2483 public String getCdmaEriText() { 2484 return getCdmaEriText(getDefaultSubscription()); 2485 } 2486 2487 /** 2488 * Returns the CDMA ERI text, of a subscription 2489 * 2490 */ 2491 /** {@hide} */ 2492 public String getCdmaEriText(int subId) { 2493 try { 2494 return getITelephony().getCdmaEriTextForSubscriber(subId); 2495 } catch (RemoteException ex) { 2496 // the phone process is restarting. 2497 return null; 2498 } catch (NullPointerException ex) { 2499 return null; 2500 } 2501 } 2502 2503 /** 2504 * @return true if the current device is "voice capable". 2505 * <p> 2506 * "Voice capable" means that this device supports circuit-switched 2507 * (i.e. voice) phone calls over the telephony network, and is allowed 2508 * to display the in-call UI while a cellular voice call is active. 2509 * This will be false on "data only" devices which can't make voice 2510 * calls and don't support any in-call UI. 2511 * <p> 2512 * Note: the meaning of this flag is subtly different from the 2513 * PackageManager.FEATURE_TELEPHONY system feature, which is available 2514 * on any device with a telephony radio, even if the device is 2515 * data-only. 2516 */ 2517 public boolean isVoiceCapable() { 2518 if (mContext == null) return true; 2519 return mContext.getResources().getBoolean( 2520 com.android.internal.R.bool.config_voice_capable); 2521 } 2522 2523 /** 2524 * @return true if the current device supports sms service. 2525 * <p> 2526 * If true, this means that the device supports both sending and 2527 * receiving sms via the telephony network. 2528 * <p> 2529 * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are 2530 * disabled when device doesn't support sms. 2531 */ 2532 public boolean isSmsCapable() { 2533 if (mContext == null) return true; 2534 return mContext.getResources().getBoolean( 2535 com.android.internal.R.bool.config_sms_capable); 2536 } 2537 2538 /** 2539 * Returns all observed cell information from all radios on the 2540 * device including the primary and neighboring cells. This does 2541 * not cause or change the rate of PhoneStateListner#onCellInfoChanged. 2542 *<p> 2543 * The list can include one or more of {@link android.telephony.CellInfoGsm CellInfoGsm}, 2544 * {@link android.telephony.CellInfoCdma CellInfoCdma}, 2545 * {@link android.telephony.CellInfoLte CellInfoLte} and 2546 * {@link android.telephony.CellInfoWcdma CellInfoCdma} in any combination. 2547 * Specifically on devices with multiple radios it is typical to see instances of 2548 * one or more of any these in the list. In addition 0, 1 or more CellInfo 2549 * objects may return isRegistered() true. 2550 *<p> 2551 * This is preferred over using getCellLocation although for older 2552 * devices this may return null in which case getCellLocation should 2553 * be called. 2554 *<p> 2555 * @return List of CellInfo or null if info unavailable. 2556 * 2557 * <p>Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} 2558 */ 2559 public List<CellInfo> getAllCellInfo() { 2560 try { 2561 return getITelephony().getAllCellInfo(); 2562 } catch (RemoteException ex) { 2563 return null; 2564 } catch (NullPointerException ex) { 2565 return null; 2566 } 2567 } 2568 2569 /** 2570 * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged 2571 * PhoneStateListener.onCellInfoChanged} will be invoked. 2572 *<p> 2573 * The default, 0, means invoke onCellInfoChanged when any of the reported 2574 * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue 2575 * A onCellInfoChanged. 2576 *<p> 2577 * @param rateInMillis the rate 2578 * 2579 * @hide 2580 */ 2581 public void setCellInfoListRate(int rateInMillis) { 2582 try { 2583 getITelephony().setCellInfoListRate(rateInMillis); 2584 } catch (RemoteException ex) { 2585 } catch (NullPointerException ex) { 2586 } 2587 } 2588 2589 /** 2590 * Returns the MMS user agent. 2591 */ 2592 public String getMmsUserAgent() { 2593 if (mContext == null) return null; 2594 return mContext.getResources().getString( 2595 com.android.internal.R.string.config_mms_user_agent); 2596 } 2597 2598 /** 2599 * Returns the MMS user agent profile URL. 2600 */ 2601 public String getMmsUAProfUrl() { 2602 if (mContext == null) return null; 2603 return mContext.getResources().getString( 2604 com.android.internal.R.string.config_mms_user_agent_profile_url); 2605 } 2606 2607 /** 2608 * Opens a logical channel to the ICC card. 2609 * 2610 * Input parameters equivalent to TS 27.007 AT+CCHO command. 2611 * 2612 * <p>Requires Permission: 2613 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2614 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2615 * 2616 * @param AID Application id. See ETSI 102.221 and 101.220. 2617 * @return an IccOpenLogicalChannelResponse object. 2618 */ 2619 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) { 2620 try { 2621 return getITelephony().iccOpenLogicalChannel(AID); 2622 } catch (RemoteException ex) { 2623 } catch (NullPointerException ex) { 2624 } 2625 return null; 2626 } 2627 2628 /** 2629 * Closes a previously opened logical channel to the ICC card. 2630 * 2631 * Input parameters equivalent to TS 27.007 AT+CCHC command. 2632 * 2633 * <p>Requires Permission: 2634 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2635 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2636 * 2637 * @param channel is the channel id to be closed as retruned by a successful 2638 * iccOpenLogicalChannel. 2639 * @return true if the channel was closed successfully. 2640 */ 2641 public boolean iccCloseLogicalChannel(int channel) { 2642 try { 2643 return getITelephony().iccCloseLogicalChannel(channel); 2644 } catch (RemoteException ex) { 2645 } catch (NullPointerException ex) { 2646 } 2647 return false; 2648 } 2649 2650 /** 2651 * Transmit an APDU to the ICC card over a logical channel. 2652 * 2653 * Input parameters equivalent to TS 27.007 AT+CGLA command. 2654 * 2655 * <p>Requires Permission: 2656 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2657 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2658 * 2659 * @param channel is the channel id to be closed as returned by a successful 2660 * iccOpenLogicalChannel. 2661 * @param cla Class of the APDU command. 2662 * @param instruction Instruction of the APDU command. 2663 * @param p1 P1 value of the APDU command. 2664 * @param p2 P2 value of the APDU command. 2665 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 2666 * is sent to the SIM. 2667 * @param data Data to be sent with the APDU. 2668 * @return The APDU response from the ICC card with the status appended at 2669 * the end. 2670 */ 2671 public String iccTransmitApduLogicalChannel(int channel, int cla, 2672 int instruction, int p1, int p2, int p3, String data) { 2673 try { 2674 return getITelephony().iccTransmitApduLogicalChannel(channel, cla, 2675 instruction, p1, p2, p3, data); 2676 } catch (RemoteException ex) { 2677 } catch (NullPointerException ex) { 2678 } 2679 return ""; 2680 } 2681 2682 /** 2683 * Transmit an APDU to the ICC card over the basic channel. 2684 * 2685 * Input parameters equivalent to TS 27.007 AT+CSIM command. 2686 * 2687 * <p>Requires Permission: 2688 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2689 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2690 * 2691 * @param cla Class of the APDU command. 2692 * @param instruction Instruction of the APDU command. 2693 * @param p1 P1 value of the APDU command. 2694 * @param p2 P2 value of the APDU command. 2695 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 2696 * is sent to the SIM. 2697 * @param data Data to be sent with the APDU. 2698 * @return The APDU response from the ICC card with the status appended at 2699 * the end. 2700 */ 2701 public String iccTransmitApduBasicChannel(int cla, 2702 int instruction, int p1, int p2, int p3, String data) { 2703 try { 2704 return getITelephony().iccTransmitApduBasicChannel(cla, 2705 instruction, p1, p2, p3, data); 2706 } catch (RemoteException ex) { 2707 } catch (NullPointerException ex) { 2708 } 2709 return ""; 2710 } 2711 2712 /** 2713 * Returns the response APDU for a command APDU sent through SIM_IO. 2714 * 2715 * <p>Requires Permission: 2716 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2717 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2718 * 2719 * @param fileID 2720 * @param command 2721 * @param p1 P1 value of the APDU command. 2722 * @param p2 P2 value of the APDU command. 2723 * @param p3 P3 value of the APDU command. 2724 * @param filePath 2725 * @return The APDU response. 2726 */ 2727 public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3, 2728 String filePath) { 2729 try { 2730 return getITelephony().iccExchangeSimIO(fileID, command, p1, p2, 2731 p3, filePath); 2732 } catch (RemoteException ex) { 2733 } catch (NullPointerException ex) { 2734 } 2735 return null; 2736 } 2737 2738 /** 2739 * Send ENVELOPE to the SIM and return the response. 2740 * 2741 * <p>Requires Permission: 2742 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2743 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2744 * 2745 * @param content String containing SAT/USAT response in hexadecimal 2746 * format starting with command tag. See TS 102 223 for 2747 * details. 2748 * @return The APDU response from the ICC card in hexadecimal format 2749 * with the last 4 bytes being the status word. If the command fails, 2750 * returns an empty string. 2751 */ 2752 public String sendEnvelopeWithStatus(String content) { 2753 try { 2754 return getITelephony().sendEnvelopeWithStatus(content); 2755 } catch (RemoteException ex) { 2756 } catch (NullPointerException ex) { 2757 } 2758 return ""; 2759 } 2760 2761 /** 2762 * Read one of the NV items defined in com.android.internal.telephony.RadioNVItems. 2763 * Used for device configuration by some CDMA operators. 2764 * <p> 2765 * Requires Permission: 2766 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2767 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2768 * 2769 * @param itemID the ID of the item to read. 2770 * @return the NV item as a String, or null on any failure. 2771 * 2772 * @hide 2773 */ 2774 public String nvReadItem(int itemID) { 2775 try { 2776 return getITelephony().nvReadItem(itemID); 2777 } catch (RemoteException ex) { 2778 Rlog.e(TAG, "nvReadItem RemoteException", ex); 2779 } catch (NullPointerException ex) { 2780 Rlog.e(TAG, "nvReadItem NPE", ex); 2781 } 2782 return ""; 2783 } 2784 2785 /** 2786 * Write one of the NV items defined in com.android.internal.telephony.RadioNVItems. 2787 * Used for device configuration by some CDMA operators. 2788 * <p> 2789 * Requires Permission: 2790 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2791 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2792 * 2793 * @param itemID the ID of the item to read. 2794 * @param itemValue the value to write, as a String. 2795 * @return true on success; false on any failure. 2796 * 2797 * @hide 2798 */ 2799 public boolean nvWriteItem(int itemID, String itemValue) { 2800 try { 2801 return getITelephony().nvWriteItem(itemID, itemValue); 2802 } catch (RemoteException ex) { 2803 Rlog.e(TAG, "nvWriteItem RemoteException", ex); 2804 } catch (NullPointerException ex) { 2805 Rlog.e(TAG, "nvWriteItem NPE", ex); 2806 } 2807 return false; 2808 } 2809 2810 /** 2811 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. 2812 * Used for device configuration by some CDMA operators. 2813 * <p> 2814 * Requires Permission: 2815 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2816 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2817 * 2818 * @param preferredRoamingList byte array containing the new PRL. 2819 * @return true on success; false on any failure. 2820 * 2821 * @hide 2822 */ 2823 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { 2824 try { 2825 return getITelephony().nvWriteCdmaPrl(preferredRoamingList); 2826 } catch (RemoteException ex) { 2827 Rlog.e(TAG, "nvWriteCdmaPrl RemoteException", ex); 2828 } catch (NullPointerException ex) { 2829 Rlog.e(TAG, "nvWriteCdmaPrl NPE", ex); 2830 } 2831 return false; 2832 } 2833 2834 /** 2835 * Perform the specified type of NV config reset. The radio will be taken offline 2836 * and the device must be rebooted after the operation. Used for device 2837 * configuration by some CDMA operators. 2838 * <p> 2839 * Requires Permission: 2840 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2841 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2842 * 2843 * @param resetType reset type: 1: reload NV reset, 2: erase NV reset, 3: factory NV reset 2844 * @return true on success; false on any failure. 2845 * 2846 * @hide 2847 */ 2848 public boolean nvResetConfig(int resetType) { 2849 try { 2850 return getITelephony().nvResetConfig(resetType); 2851 } catch (RemoteException ex) { 2852 Rlog.e(TAG, "nvResetConfig RemoteException", ex); 2853 } catch (NullPointerException ex) { 2854 Rlog.e(TAG, "nvResetConfig NPE", ex); 2855 } 2856 return false; 2857 } 2858 2859 /** 2860 * Returns Default subscription. 2861 */ 2862 private static int getDefaultSubscription() { 2863 return SubscriptionManager.getDefaultSubId(); 2864 } 2865 2866 /** 2867 * Returns Default phone. 2868 */ 2869 private static int getDefaultPhone() { 2870 return SubscriptionManager.getPhoneId(SubscriptionManager.getDefaultSubId()); 2871 } 2872 2873 /** {@hide} */ 2874 public int getDefaultSim() { 2875 return SubscriptionManager.getSlotId(SubscriptionManager.getDefaultSubId()); 2876 } 2877 2878 /** 2879 * Sets the telephony property with the value specified. 2880 * 2881 * @hide 2882 */ 2883 public static void setTelephonyProperty(int phoneId, String property, String value) { 2884 String propVal = ""; 2885 String p[] = null; 2886 String prop = SystemProperties.get(property); 2887 2888 if (value == null) { 2889 value = ""; 2890 } 2891 2892 if (prop != null) { 2893 p = prop.split(","); 2894 } 2895 2896 if (!SubscriptionManager.isValidPhoneId(phoneId)) { 2897 Rlog.d(TAG, "setTelephonyProperty: invalid phoneId=" + phoneId + 2898 " property=" + property + " value: " + value + " prop=" + prop); 2899 return; 2900 } 2901 2902 for (int i = 0; i < phoneId; i++) { 2903 String str = ""; 2904 if ((p != null) && (i < p.length)) { 2905 str = p[i]; 2906 } 2907 propVal = propVal + str + ","; 2908 } 2909 2910 propVal = propVal + value; 2911 if (p != null) { 2912 for (int i = phoneId + 1; i < p.length; i++) { 2913 propVal = propVal + "," + p[i]; 2914 } 2915 } 2916 2917 if (property.length() > SystemProperties.PROP_NAME_MAX 2918 || propVal.length() > SystemProperties.PROP_VALUE_MAX) { 2919 Rlog.d(TAG, "setTelephonyProperty: property to long phoneId=" + phoneId + 2920 " property=" + property + " value: " + value + " propVal=" + propVal); 2921 return; 2922 } 2923 2924 Rlog.d(TAG, "setTelephonyProperty: success phoneId=" + phoneId + 2925 " property=" + property + " value: " + value + " propVal=" + propVal); 2926 SystemProperties.set(property, propVal); 2927 } 2928 2929 /** 2930 * Convenience function for retrieving a value from the secure settings 2931 * value list as an integer. Note that internally setting values are 2932 * always stored as strings; this function converts the string to an 2933 * integer for you. 2934 * <p> 2935 * This version does not take a default value. If the setting has not 2936 * been set, or the string value is not a number, 2937 * it throws {@link SettingNotFoundException}. 2938 * 2939 * @param cr The ContentResolver to access. 2940 * @param name The name of the setting to retrieve. 2941 * @param index The index of the list 2942 * 2943 * @throws SettingNotFoundException Thrown if a setting by the given 2944 * name can't be found or the setting value is not an integer. 2945 * 2946 * @return The value at the given index of settings. 2947 * @hide 2948 */ 2949 public static int getIntAtIndex(android.content.ContentResolver cr, 2950 String name, int index) 2951 throws android.provider.Settings.SettingNotFoundException { 2952 String v = android.provider.Settings.Global.getString(cr, name); 2953 if (v != null) { 2954 String valArray[] = v.split(","); 2955 if ((index >= 0) && (index < valArray.length) && (valArray[index] != null)) { 2956 try { 2957 return Integer.parseInt(valArray[index]); 2958 } catch (NumberFormatException e) { 2959 //Log.e(TAG, "Exception while parsing Integer: ", e); 2960 } 2961 } 2962 } 2963 throw new android.provider.Settings.SettingNotFoundException(name); 2964 } 2965 2966 /** 2967 * Convenience function for updating settings value as coma separated 2968 * integer values. This will either create a new entry in the table if the 2969 * given name does not exist, or modify the value of the existing row 2970 * with that name. Note that internally setting values are always 2971 * stored as strings, so this function converts the given value to a 2972 * string before storing it. 2973 * 2974 * @param cr The ContentResolver to access. 2975 * @param name The name of the setting to modify. 2976 * @param index The index of the list 2977 * @param value The new value for the setting to be added to the list. 2978 * @return true if the value was set, false on database errors 2979 * @hide 2980 */ 2981 public static boolean putIntAtIndex(android.content.ContentResolver cr, 2982 String name, int index, int value) { 2983 String data = ""; 2984 String valArray[] = null; 2985 String v = android.provider.Settings.Global.getString(cr, name); 2986 2987 if (index == Integer.MAX_VALUE) { 2988 throw new RuntimeException("putIntAtIndex index == MAX_VALUE index=" + index); 2989 } 2990 if (index < 0) { 2991 throw new RuntimeException("putIntAtIndex index < 0 index=" + index); 2992 } 2993 if (v != null) { 2994 valArray = v.split(","); 2995 } 2996 2997 // Copy the elements from valArray till index 2998 for (int i = 0; i < index; i++) { 2999 String str = ""; 3000 if ((valArray != null) && (i < valArray.length)) { 3001 str = valArray[i]; 3002 } 3003 data = data + str + ","; 3004 } 3005 3006 data = data + value; 3007 3008 // Copy the remaining elements from valArray if any. 3009 if (valArray != null) { 3010 for (int i = index+1; i < valArray.length; i++) { 3011 data = data + "," + valArray[i]; 3012 } 3013 } 3014 return android.provider.Settings.Global.putString(cr, name, data); 3015 } 3016 3017 /** 3018 * Gets the telephony property. 3019 * 3020 * @hide 3021 */ 3022 public static String getTelephonyProperty(int phoneId, String property, String defaultVal) { 3023 String propVal = null; 3024 String prop = SystemProperties.get(property); 3025 if ((prop != null) && (prop.length() > 0)) { 3026 String values[] = prop.split(","); 3027 if ((phoneId >= 0) && (phoneId < values.length) && (values[phoneId] != null)) { 3028 propVal = values[phoneId]; 3029 } 3030 } 3031 Rlog.d(TAG, "getTelephonyProperty: return propVal='" + propVal + "' phoneId=" + phoneId 3032 + " property='" + property + "' defaultVal='" + defaultVal + "' prop=" + prop); 3033 return propVal == null ? defaultVal : propVal; 3034 } 3035 3036 /** @hide */ 3037 public int getSimCount() { 3038 // FIXME Need to get it from Telephony Dev Controller when that gets implemented! 3039 // and then this method shouldn't be used at all! 3040 if(isMultiSimEnabled()) { 3041 return 2; 3042 } else { 3043 return 1; 3044 } 3045 } 3046 3047 /** 3048 * Returns the IMS Service Table (IST) that was loaded from the ISIM. 3049 * @return IMS Service Table or null if not present or not loaded 3050 * @hide 3051 */ 3052 public String getIsimIst() { 3053 try { 3054 return getSubscriberInfo().getIsimIst(); 3055 } catch (RemoteException ex) { 3056 return null; 3057 } catch (NullPointerException ex) { 3058 // This could happen before phone restarts due to crashing 3059 return null; 3060 } 3061 } 3062 3063 /** 3064 * Returns the IMS Proxy Call Session Control Function(PCSCF) that were loaded from the ISIM. 3065 * @return an array of PCSCF strings with one PCSCF per string, or null if 3066 * not present or not loaded 3067 * @hide 3068 */ 3069 public String[] getIsimPcscf() { 3070 try { 3071 return getSubscriberInfo().getIsimPcscf(); 3072 } catch (RemoteException ex) { 3073 return null; 3074 } catch (NullPointerException ex) { 3075 // This could happen before phone restarts due to crashing 3076 return null; 3077 } 3078 } 3079 3080 /** 3081 * Returns the response of ISIM Authetification through RIL. 3082 * Returns null if the Authentification hasn't been successed or isn't present iphonesubinfo. 3083 * @return the response of ISIM Authetification, or null if not available 3084 * @hide 3085 * @deprecated 3086 * @see getIccSimChallengeResponse with appType=PhoneConstants.APPTYPE_ISIM 3087 */ 3088 public String getIsimChallengeResponse(String nonce){ 3089 try { 3090 return getSubscriberInfo().getIsimChallengeResponse(nonce); 3091 } catch (RemoteException ex) { 3092 return null; 3093 } catch (NullPointerException ex) { 3094 // This could happen before phone restarts due to crashing 3095 return null; 3096 } 3097 } 3098 3099 /** 3100 * Returns the response of SIM Authentication through RIL. 3101 * Returns null if the Authentication hasn't been successful 3102 * @param subId subscription ID to be queried 3103 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 3104 * @param data authentication challenge data 3105 * @return the response of SIM Authentication, or null if not available 3106 * @hide 3107 */ 3108 public String getIccSimChallengeResponse(int subId, int appType, String data) { 3109 try { 3110 return getSubscriberInfo().getIccSimChallengeResponse(subId, appType, data); 3111 } catch (RemoteException ex) { 3112 return null; 3113 } catch (NullPointerException ex) { 3114 // This could happen before phone starts 3115 return null; 3116 } 3117 } 3118 3119 /** 3120 * Returns the response of SIM Authentication through RIL for the default subscription. 3121 * Returns null if the Authentication hasn't been successful 3122 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 3123 * @param data authentication challenge data 3124 * @return the response of SIM Authentication, or null if not available 3125 * @hide 3126 */ 3127 public String getIccSimChallengeResponse(int appType, String data) { 3128 return getIccSimChallengeResponse(getDefaultSubscription(), appType, data); 3129 } 3130 3131 /** 3132 * Get P-CSCF address from PCO after data connection is established or modified. 3133 * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN 3134 * @return array of P-CSCF address 3135 * @hide 3136 */ 3137 public String[] getPcscfAddress(String apnType) { 3138 try { 3139 return getITelephony().getPcscfAddress(apnType); 3140 } catch (RemoteException e) { 3141 return new String[0]; 3142 } 3143 } 3144 3145 /** 3146 * Set IMS registration state 3147 * 3148 * @param Registration state 3149 * @hide 3150 */ 3151 public void setImsRegistrationState(boolean registered) { 3152 try { 3153 getITelephony().setImsRegistrationState(registered); 3154 } catch (RemoteException e) { 3155 } 3156 } 3157 3158 /** 3159 * Get the preferred network type. 3160 * Used for device configuration by some CDMA operators. 3161 * <p> 3162 * Requires Permission: 3163 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3164 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3165 * 3166 * @return the preferred network type, defined in RILConstants.java. 3167 * @hide 3168 */ 3169 public int getPreferredNetworkType() { 3170 try { 3171 return getITelephony().getPreferredNetworkType(); 3172 } catch (RemoteException ex) { 3173 Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex); 3174 } catch (NullPointerException ex) { 3175 Rlog.e(TAG, "getPreferredNetworkType NPE", ex); 3176 } 3177 return -1; 3178 } 3179 3180 /** 3181 * Set the preferred network type. 3182 * Used for device configuration by some CDMA operators. 3183 * <p> 3184 * Requires Permission: 3185 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3186 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3187 * 3188 * @param networkType the preferred network type, defined in RILConstants.java. 3189 * @return true on success; false on any failure. 3190 * @hide 3191 */ 3192 public boolean setPreferredNetworkType(int networkType) { 3193 try { 3194 return getITelephony().setPreferredNetworkType(networkType); 3195 } catch (RemoteException ex) { 3196 Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex); 3197 } catch (NullPointerException ex) { 3198 Rlog.e(TAG, "setPreferredNetworkType NPE", ex); 3199 } 3200 return false; 3201 } 3202 3203 /** 3204 * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA. 3205 * 3206 * <p> 3207 * Requires that the calling app has carrier privileges. 3208 * @see #hasCarrierPrivileges 3209 * 3210 * @return true on success; false on any failure. 3211 */ 3212 public boolean setPreferredNetworkTypeToGlobal() { 3213 return setPreferredNetworkType(RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA); 3214 } 3215 3216 /** 3217 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning 3218 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for 3219 * tethering. 3220 * 3221 * @return 0: Not required. 1: required. 2: Not set. 3222 * @hide 3223 */ 3224 public int getTetherApnRequired() { 3225 try { 3226 return getITelephony().getTetherApnRequired(); 3227 } catch (RemoteException ex) { 3228 Rlog.e(TAG, "hasMatchedTetherApnSetting RemoteException", ex); 3229 } catch (NullPointerException ex) { 3230 Rlog.e(TAG, "hasMatchedTetherApnSetting NPE", ex); 3231 } 3232 return 2; 3233 } 3234 3235 3236 /** 3237 * Values used to return status for hasCarrierPrivileges call. 3238 */ 3239 /** @hide */ 3240 public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1; 3241 /** @hide */ 3242 public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0; 3243 /** @hide */ 3244 public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1; 3245 /** @hide */ 3246 public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2; 3247 3248 /** 3249 * Has the calling application been granted carrier privileges by the carrier. 3250 * 3251 * If any of the packages in the calling UID has carrier privileges, the 3252 * call will return true. This access is granted by the owner of the UICC 3253 * card and does not depend on the registered carrier. 3254 * 3255 * @return true if the app has carrier privileges. 3256 */ 3257 public boolean hasCarrierPrivileges() { 3258 try { 3259 return getITelephony().getCarrierPrivilegeStatus() == 3260 CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; 3261 } catch (RemoteException ex) { 3262 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 3263 } catch (NullPointerException ex) { 3264 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 3265 } 3266 return false; 3267 } 3268 3269 /** 3270 * Override the branding for the current ICCID. 3271 * 3272 * Once set, whenever the SIM is present in the device, the service 3273 * provider name (SPN) and the operator name will both be replaced by the 3274 * brand value input. To unset the value, the same function should be 3275 * called with a null brand value. 3276 * 3277 * <p>Requires that the calling app has carrier privileges. 3278 * @see #hasCarrierPrivileges 3279 * 3280 * @param brand The brand name to display/set. 3281 * @return true if the operation was executed correctly. 3282 */ 3283 public boolean setOperatorBrandOverride(String brand) { 3284 try { 3285 return getITelephony().setOperatorBrandOverride(brand); 3286 } catch (RemoteException ex) { 3287 Rlog.e(TAG, "setOperatorBrandOverride RemoteException", ex); 3288 } catch (NullPointerException ex) { 3289 Rlog.e(TAG, "setOperatorBrandOverride NPE", ex); 3290 } 3291 return false; 3292 } 3293 3294 /** 3295 * Override the roaming preference for the current ICCID. 3296 * 3297 * Using this call, the carrier app (see #hasCarrierPrivileges) can override 3298 * the platform's notion of a network operator being considered roaming or not. 3299 * The change only affects the ICCID that was active when this call was made. 3300 * 3301 * If null is passed as any of the input, the corresponding value is deleted. 3302 * 3303 * <p>Requires that the caller have carrier privilege. See #hasCarrierPrivileges. 3304 * 3305 * @param gsmRoamingList - List of MCCMNCs to be considered roaming for 3GPP RATs. 3306 * @param gsmNonRoamingList - List of MCCMNCs to be considered not roaming for 3GPP RATs. 3307 * @param cdmaRoamingList - List of SIDs to be considered roaming for 3GPP2 RATs. 3308 * @param cdmaNonRoamingList - List of SIDs to be considered not roaming for 3GPP2 RATs. 3309 * @return true if the operation was executed correctly. 3310 * 3311 * @hide 3312 */ 3313 public boolean setRoamingOverride(List<String> gsmRoamingList, 3314 List<String> gsmNonRoamingList, List<String> cdmaRoamingList, 3315 List<String> cdmaNonRoamingList) { 3316 try { 3317 return getITelephony().setRoamingOverride(gsmRoamingList, gsmNonRoamingList, 3318 cdmaRoamingList, cdmaNonRoamingList); 3319 } catch (RemoteException ex) { 3320 Rlog.e(TAG, "setRoamingOverride RemoteException", ex); 3321 } catch (NullPointerException ex) { 3322 Rlog.e(TAG, "setRoamingOverride NPE", ex); 3323 } 3324 return false; 3325 } 3326 3327 /** 3328 * Expose the rest of ITelephony to @SystemApi 3329 */ 3330 3331 /** @hide */ 3332 @SystemApi 3333 public String getCdmaMdn() { 3334 return getCdmaMdn(getDefaultSubscription()); 3335 } 3336 3337 /** @hide */ 3338 @SystemApi 3339 public String getCdmaMdn(int subId) { 3340 try { 3341 return getITelephony().getCdmaMdn(subId); 3342 } catch (RemoteException ex) { 3343 return null; 3344 } catch (NullPointerException ex) { 3345 return null; 3346 } 3347 } 3348 3349 /** @hide */ 3350 @SystemApi 3351 public String getCdmaMin() { 3352 return getCdmaMin(getDefaultSubscription()); 3353 } 3354 3355 /** @hide */ 3356 @SystemApi 3357 public String getCdmaMin(int subId) { 3358 try { 3359 return getITelephony().getCdmaMin(subId); 3360 } catch (RemoteException ex) { 3361 return null; 3362 } catch (NullPointerException ex) { 3363 return null; 3364 } 3365 } 3366 3367 /** @hide */ 3368 @SystemApi 3369 public int checkCarrierPrivilegesForPackage(String pkgname) { 3370 try { 3371 return getITelephony().checkCarrierPrivilegesForPackage(pkgname); 3372 } catch (RemoteException ex) { 3373 Rlog.e(TAG, "checkCarrierPrivilegesForPackage RemoteException", ex); 3374 } catch (NullPointerException ex) { 3375 Rlog.e(TAG, "checkCarrierPrivilegesForPackage NPE", ex); 3376 } 3377 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 3378 } 3379 3380 /** @hide */ 3381 @SystemApi 3382 public List<String> getCarrierPackageNamesForIntent(Intent intent) { 3383 try { 3384 return getITelephony().getCarrierPackageNamesForIntent(intent); 3385 } catch (RemoteException ex) { 3386 Rlog.e(TAG, "getCarrierPackageNamesForIntent RemoteException", ex); 3387 } catch (NullPointerException ex) { 3388 Rlog.e(TAG, "getCarrierPackageNamesForIntent NPE", ex); 3389 } 3390 return null; 3391 } 3392 3393 /** @hide */ 3394 @SystemApi 3395 public void dial(String number) { 3396 try { 3397 getITelephony().dial(number); 3398 } catch (RemoteException e) { 3399 Log.e(TAG, "Error calling ITelephony#dial", e); 3400 } 3401 } 3402 3403 /** @hide */ 3404 @SystemApi 3405 public void call(String callingPackage, String number) { 3406 try { 3407 getITelephony().call(callingPackage, number); 3408 } catch (RemoteException e) { 3409 Log.e(TAG, "Error calling ITelephony#call", e); 3410 } 3411 } 3412 3413 /** @hide */ 3414 @SystemApi 3415 public boolean endCall() { 3416 try { 3417 return getITelephony().endCall(); 3418 } catch (RemoteException e) { 3419 Log.e(TAG, "Error calling ITelephony#endCall", e); 3420 } 3421 return false; 3422 } 3423 3424 /** @hide */ 3425 @SystemApi 3426 public void answerRingingCall() { 3427 try { 3428 getITelephony().answerRingingCall(); 3429 } catch (RemoteException e) { 3430 Log.e(TAG, "Error calling ITelephony#answerRingingCall", e); 3431 } 3432 } 3433 3434 /** @hide */ 3435 @SystemApi 3436 public void silenceRinger() { 3437 try { 3438 getTelecomService().silenceRinger(); 3439 } catch (RemoteException e) { 3440 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e); 3441 } 3442 } 3443 3444 /** @hide */ 3445 @SystemApi 3446 public boolean isOffhook() { 3447 try { 3448 return getITelephony().isOffhook(); 3449 } catch (RemoteException e) { 3450 Log.e(TAG, "Error calling ITelephony#isOffhook", e); 3451 } 3452 return false; 3453 } 3454 3455 /** @hide */ 3456 @SystemApi 3457 public boolean isRinging() { 3458 try { 3459 return getITelephony().isRinging(); 3460 } catch (RemoteException e) { 3461 Log.e(TAG, "Error calling ITelephony#isRinging", e); 3462 } 3463 return false; 3464 } 3465 3466 /** @hide */ 3467 @SystemApi 3468 public boolean isIdle() { 3469 try { 3470 return getITelephony().isIdle(); 3471 } catch (RemoteException e) { 3472 Log.e(TAG, "Error calling ITelephony#isIdle", e); 3473 } 3474 return true; 3475 } 3476 3477 /** @hide */ 3478 @SystemApi 3479 public boolean isRadioOn() { 3480 try { 3481 return getITelephony().isRadioOn(); 3482 } catch (RemoteException e) { 3483 Log.e(TAG, "Error calling ITelephony#isRadioOn", e); 3484 } 3485 return false; 3486 } 3487 3488 /** @hide */ 3489 @SystemApi 3490 public boolean isSimPinEnabled() { 3491 try { 3492 return getITelephony().isSimPinEnabled(); 3493 } catch (RemoteException e) { 3494 Log.e(TAG, "Error calling ITelephony#isSimPinEnabled", e); 3495 } 3496 return false; 3497 } 3498 3499 /** @hide */ 3500 @SystemApi 3501 public boolean supplyPin(String pin) { 3502 try { 3503 return getITelephony().supplyPin(pin); 3504 } catch (RemoteException e) { 3505 Log.e(TAG, "Error calling ITelephony#supplyPin", e); 3506 } 3507 return false; 3508 } 3509 3510 /** @hide */ 3511 @SystemApi 3512 public boolean supplyPuk(String puk, String pin) { 3513 try { 3514 return getITelephony().supplyPuk(puk, pin); 3515 } catch (RemoteException e) { 3516 Log.e(TAG, "Error calling ITelephony#supplyPuk", e); 3517 } 3518 return false; 3519 } 3520 3521 /** @hide */ 3522 @SystemApi 3523 public int[] supplyPinReportResult(String pin) { 3524 try { 3525 return getITelephony().supplyPinReportResult(pin); 3526 } catch (RemoteException e) { 3527 Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e); 3528 } 3529 return new int[0]; 3530 } 3531 3532 /** @hide */ 3533 @SystemApi 3534 public int[] supplyPukReportResult(String puk, String pin) { 3535 try { 3536 return getITelephony().supplyPukReportResult(puk, pin); 3537 } catch (RemoteException e) { 3538 Log.e(TAG, "Error calling ITelephony#]", e); 3539 } 3540 return new int[0]; 3541 } 3542 3543 /** @hide */ 3544 @SystemApi 3545 public boolean handlePinMmi(String dialString) { 3546 try { 3547 return getITelephony().handlePinMmi(dialString); 3548 } catch (RemoteException e) { 3549 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 3550 } 3551 return false; 3552 } 3553 3554 /** @hide */ 3555 @SystemApi 3556 public boolean handlePinMmiForSubscriber(int subId, String dialString) { 3557 try { 3558 return getITelephony().handlePinMmiForSubscriber(subId, dialString); 3559 } catch (RemoteException e) { 3560 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 3561 } 3562 return false; 3563 } 3564 3565 /** @hide */ 3566 @SystemApi 3567 public void toggleRadioOnOff() { 3568 try { 3569 getITelephony().toggleRadioOnOff(); 3570 } catch (RemoteException e) { 3571 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 3572 } 3573 } 3574 3575 /** @hide */ 3576 @SystemApi 3577 public boolean setRadio(boolean turnOn) { 3578 try { 3579 return getITelephony().setRadio(turnOn); 3580 } catch (RemoteException e) { 3581 Log.e(TAG, "Error calling ITelephony#setRadio", e); 3582 } 3583 return false; 3584 } 3585 3586 /** @hide */ 3587 @SystemApi 3588 public boolean setRadioPower(boolean turnOn) { 3589 try { 3590 return getITelephony().setRadioPower(turnOn); 3591 } catch (RemoteException e) { 3592 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 3593 } 3594 return false; 3595 } 3596 3597 /** @hide */ 3598 @SystemApi 3599 public void updateServiceLocation() { 3600 try { 3601 getITelephony().updateServiceLocation(); 3602 } catch (RemoteException e) { 3603 Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e); 3604 } 3605 } 3606 3607 /** @hide */ 3608 @SystemApi 3609 public boolean enableDataConnectivity() { 3610 try { 3611 return getITelephony().enableDataConnectivity(); 3612 } catch (RemoteException e) { 3613 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 3614 } 3615 return false; 3616 } 3617 3618 /** @hide */ 3619 @SystemApi 3620 public boolean disableDataConnectivity() { 3621 try { 3622 return getITelephony().disableDataConnectivity(); 3623 } catch (RemoteException e) { 3624 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 3625 } 3626 return false; 3627 } 3628 3629 /** @hide */ 3630 @SystemApi 3631 public boolean isDataConnectivityPossible() { 3632 try { 3633 return getITelephony().isDataConnectivityPossible(); 3634 } catch (RemoteException e) { 3635 Log.e(TAG, "Error calling ITelephony#isDataConnectivityPossible", e); 3636 } 3637 return false; 3638 } 3639 3640 /** @hide */ 3641 @SystemApi 3642 public boolean needsOtaServiceProvisioning() { 3643 try { 3644 return getITelephony().needsOtaServiceProvisioning(); 3645 } catch (RemoteException e) { 3646 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 3647 } 3648 return false; 3649 } 3650 3651 /** @hide */ 3652 @SystemApi 3653 public void setDataEnabled(boolean enable) { 3654 setDataEnabled(SubscriptionManager.getDefaultDataSubId(), enable); 3655 } 3656 3657 /** @hide */ 3658 @SystemApi 3659 public void setDataEnabled(int subId, boolean enable) { 3660 try { 3661 Log.d(TAG, "setDataEnabled: enabled=" + enable); 3662 getITelephony().setDataEnabled(subId, enable); 3663 } catch (RemoteException e) { 3664 Log.e(TAG, "Error calling ITelephony#setDataEnabled", e); 3665 } 3666 } 3667 3668 /** @hide */ 3669 @SystemApi 3670 public boolean getDataEnabled() { 3671 return getDataEnabled(SubscriptionManager.getDefaultDataSubId()); 3672 } 3673 3674 /** @hide */ 3675 @SystemApi 3676 public boolean getDataEnabled(int subId) { 3677 boolean retVal = false; 3678 try { 3679 retVal = getITelephony().getDataEnabled(subId); 3680 } catch (RemoteException e) { 3681 Log.e(TAG, "Error calling ITelephony#getDataEnabled", e); 3682 } catch (NullPointerException e) { 3683 } 3684 Log.d(TAG, "getDataEnabled: retVal=" + retVal); 3685 return retVal; 3686 } 3687 3688 /** 3689 * Returns the result and response from RIL for oem request 3690 * 3691 * @param oemReq the data is sent to ril. 3692 * @param oemResp the respose data from RIL. 3693 * @return negative value request was not handled or get error 3694 * 0 request was handled succesfully, but no response data 3695 * positive value success, data length of response 3696 * @hide 3697 */ 3698 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { 3699 try { 3700 return getITelephony().invokeOemRilRequestRaw(oemReq, oemResp); 3701 } catch (RemoteException ex) { 3702 } catch (NullPointerException ex) { 3703 } 3704 return -1; 3705 } 3706 3707 /** @hide */ 3708 @SystemApi 3709 public void enableVideoCalling(boolean enable) { 3710 try { 3711 getITelephony().enableVideoCalling(enable); 3712 } catch (RemoteException e) { 3713 Log.e(TAG, "Error calling ITelephony#enableVideoCalling", e); 3714 } 3715 } 3716 3717 /** @hide */ 3718 @SystemApi 3719 public boolean isVideoCallingEnabled() { 3720 try { 3721 return getITelephony().isVideoCallingEnabled(); 3722 } catch (RemoteException e) { 3723 Log.e(TAG, "Error calling ITelephony#isVideoCallingEnabled", e); 3724 } 3725 return false; 3726 } 3727 3728 /** 3729 * Whether the device supports configuring the DTMF tone length. 3730 * 3731 * @return {@code true} if the DTMF tone length can be changed, and {@code false} otherwise. 3732 */ 3733 public boolean canChangeDtmfToneLength() { 3734 try { 3735 return getITelephony().canChangeDtmfToneLength(); 3736 } catch (RemoteException e) { 3737 Log.e(TAG, "Error calling ITelephony#canChangeDtmfToneLength", e); 3738 } 3739 return false; 3740 } 3741 3742 /** 3743 * Whether the device is a world phone. 3744 * 3745 * @return {@code true} if the device is a world phone, and {@code false} otherwise. 3746 */ 3747 public boolean isWorldPhone() { 3748 try { 3749 return getITelephony().isWorldPhone(); 3750 } catch (RemoteException e) { 3751 Log.e(TAG, "Error calling ITelephony#isWorldPhone", e); 3752 } 3753 return false; 3754 } 3755 3756 /** 3757 * Whether the phone supports TTY mode. 3758 * 3759 * @return {@code true} if the device supports TTY mode, and {@code false} otherwise. 3760 */ 3761 public boolean isTtyModeSupported() { 3762 try { 3763 return getITelephony().isTtyModeSupported(); 3764 } catch (RemoteException e) { 3765 Log.e(TAG, "Error calling ITelephony#isTtyModeSupported", e); 3766 } 3767 return false; 3768 } 3769 3770 /** 3771 * Whether the phone supports hearing aid compatibility. 3772 * 3773 * @return {@code true} if the device supports hearing aid compatibility, and {@code false} 3774 * otherwise. 3775 */ 3776 public boolean isHearingAidCompatibilitySupported() { 3777 try { 3778 return getITelephony().isHearingAidCompatibilitySupported(); 3779 } catch (RemoteException e) { 3780 Log.e(TAG, "Error calling ITelephony#isHearingAidCompatibilitySupported", e); 3781 } 3782 return false; 3783 } 3784 3785 /** 3786 * This function retrieves value for setting "name+subId", and if that is not found 3787 * retrieves value for setting "name", and if that is not found throws 3788 * SettingNotFoundException 3789 * 3790 * @hide */ 3791 public static int getIntWithSubId(ContentResolver cr, String name, int subId) 3792 throws SettingNotFoundException { 3793 try { 3794 return Settings.Global.getInt(cr, name + subId); 3795 } catch (SettingNotFoundException e) { 3796 try { 3797 int val = Settings.Global.getInt(cr, name); 3798 Settings.Global.putInt(cr, name + subId, val); 3799 3800 /* We are now moving from 'setting' to 'setting+subId', and using the value stored 3801 * for 'setting' as default. Reset the default (since it may have a user set 3802 * value). */ 3803 int default_val = val; 3804 if (name.equals(Settings.Global.MOBILE_DATA)) { 3805 default_val = "true".equalsIgnoreCase( 3806 SystemProperties.get("ro.com.android.mobiledata", "true")) ? 1 : 0; 3807 } else if (name.equals(Settings.Global.DATA_ROAMING)) { 3808 default_val = "true".equalsIgnoreCase( 3809 SystemProperties.get("ro.com.android.dataroaming", "false")) ? 1 : 0; 3810 } 3811 3812 if (default_val != val) { 3813 Settings.Global.putInt(cr, name, default_val); 3814 } 3815 3816 return val; 3817 } catch (SettingNotFoundException exc) { 3818 throw new SettingNotFoundException(name); 3819 } 3820 } 3821 } 3822 3823 /** 3824 * Returns the IMS Registration Status 3825 * @hide 3826 */ 3827 public boolean isImsRegistered() { 3828 try { 3829 return getITelephony().isImsRegistered(); 3830 } catch (RemoteException ex) { 3831 return false; 3832 } catch (NullPointerException ex) { 3833 return false; 3834 } 3835 } 3836 3837 /** 3838 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 3839 * 3840 * @hide 3841 */ 3842 public void setSimOperatorNumeric(String numeric) { 3843 int phoneId = getDefaultPhone(); 3844 setSimOperatorNumericForPhone(phoneId, numeric); 3845 } 3846 3847 /** 3848 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 3849 * 3850 * @hide 3851 */ 3852 public void setSimOperatorNumericForPhone(int phoneId, String numeric) { 3853 setTelephonyProperty(phoneId, 3854 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, numeric); 3855 } 3856 3857 /** 3858 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 3859 * 3860 * @hide 3861 */ 3862 public void setSimOperatorName(String name) { 3863 int phoneId = getDefaultPhone(); 3864 setSimOperatorNameForPhone(phoneId, name); 3865 } 3866 3867 /** 3868 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 3869 * 3870 * @hide 3871 */ 3872 public void setSimOperatorNameForPhone(int phoneId, String name) { 3873 setTelephonyProperty(phoneId, 3874 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, name); 3875 } 3876 3877 /** 3878 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the default phone. 3879 * 3880 * @hide 3881 */ 3882 public void setSimCountryIso(String iso) { 3883 int phoneId = getDefaultPhone(); 3884 setSimCountryIsoForPhone(phoneId, iso); 3885 } 3886 3887 /** 3888 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the given phone. 3889 * 3890 * @hide 3891 */ 3892 public void setSimCountryIsoForPhone(int phoneId, String iso) { 3893 setTelephonyProperty(phoneId, 3894 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, iso); 3895 } 3896 3897 /** 3898 * Set TelephonyProperties.PROPERTY_SIM_STATE for the default phone. 3899 * 3900 * @hide 3901 */ 3902 public void setSimState(String state) { 3903 int phoneId = getDefaultPhone(); 3904 setSimStateForPhone(phoneId, state); 3905 } 3906 3907 /** 3908 * Set TelephonyProperties.PROPERTY_SIM_STATE for the given phone. 3909 * 3910 * @hide 3911 */ 3912 public void setSimStateForPhone(int phoneId, String state) { 3913 setTelephonyProperty(phoneId, 3914 TelephonyProperties.PROPERTY_SIM_STATE, state); 3915 } 3916 3917 /** 3918 * Set baseband version for the default phone. 3919 * 3920 * @param version baseband version 3921 * @hide 3922 */ 3923 public void setBasebandVersion(String version) { 3924 int phoneId = getDefaultPhone(); 3925 setBasebandVersionForPhone(phoneId, version); 3926 } 3927 3928 /** 3929 * Set baseband version by phone id. 3930 * 3931 * @param phoneId for which baseband version is set 3932 * @param version baseband version 3933 * @hide 3934 */ 3935 public void setBasebandVersionForPhone(int phoneId, String version) { 3936 if (SubscriptionManager.isValidPhoneId(phoneId)) { 3937 String prop = TelephonyProperties.PROPERTY_BASEBAND_VERSION + 3938 ((phoneId == 0) ? "" : Integer.toString(phoneId)); 3939 SystemProperties.set(prop, version); 3940 } 3941 } 3942 3943 /** 3944 * Set phone type for the default phone. 3945 * 3946 * @param type phone type 3947 * 3948 * @hide 3949 */ 3950 public void setPhoneType(int type) { 3951 int phoneId = getDefaultPhone(); 3952 setPhoneType(phoneId, type); 3953 } 3954 3955 /** 3956 * Set phone type by phone id. 3957 * 3958 * @param phoneId for which phone type is set 3959 * @param type phone type 3960 * 3961 * @hide 3962 */ 3963 public void setPhoneType(int phoneId, int type) { 3964 if (SubscriptionManager.isValidPhoneId(phoneId)) { 3965 TelephonyManager.setTelephonyProperty(phoneId, 3966 TelephonyProperties.CURRENT_ACTIVE_PHONE, String.valueOf(type)); 3967 } 3968 } 3969 3970 /** 3971 * Get OTASP number schema for the default phone. 3972 * 3973 * @param defaultValue default value 3974 * @return OTA SP number schema 3975 * 3976 * @hide 3977 */ 3978 public String getOtaSpNumberSchema(String defaultValue) { 3979 int phoneId = getDefaultPhone(); 3980 return getOtaSpNumberSchemaForPhone(phoneId, defaultValue); 3981 } 3982 3983 /** 3984 * Get OTASP number schema by phone id. 3985 * 3986 * @param phoneId for which OTA SP number schema is get 3987 * @param defaultValue default value 3988 * @return OTA SP number schema 3989 * 3990 * @hide 3991 */ 3992 public String getOtaSpNumberSchemaForPhone(int phoneId, String defaultValue) { 3993 if (SubscriptionManager.isValidPhoneId(phoneId)) { 3994 return TelephonyManager.getTelephonyProperty(phoneId, 3995 TelephonyProperties.PROPERTY_OTASP_NUM_SCHEMA, defaultValue); 3996 } 3997 3998 return defaultValue; 3999 } 4000 4001 /** 4002 * Get SMS receive capable from system property for the default phone. 4003 * 4004 * @param defaultValue default value 4005 * @return SMS receive capable 4006 * 4007 * @hide 4008 */ 4009 public boolean getSmsReceiveCapable(boolean defaultValue) { 4010 int phoneId = getDefaultPhone(); 4011 return getSmsReceiveCapableForPhone(phoneId, defaultValue); 4012 } 4013 4014 /** 4015 * Get SMS receive capable from system property by phone id. 4016 * 4017 * @param phoneId for which SMS receive capable is get 4018 * @param defaultValue default value 4019 * @return SMS receive capable 4020 * 4021 * @hide 4022 */ 4023 public boolean getSmsReceiveCapableForPhone(int phoneId, boolean defaultValue) { 4024 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4025 return Boolean.valueOf(TelephonyManager.getTelephonyProperty(phoneId, 4026 TelephonyProperties.PROPERTY_SMS_RECEIVE, String.valueOf(defaultValue))); 4027 } 4028 4029 return defaultValue; 4030 } 4031 4032 /** 4033 * Get SMS send capable from system property for the default phone. 4034 * 4035 * @param defaultValue default value 4036 * @return SMS send capable 4037 * 4038 * @hide 4039 */ 4040 public boolean getSmsSendCapable(boolean defaultValue) { 4041 int phoneId = getDefaultPhone(); 4042 return getSmsSendCapableForPhone(phoneId, defaultValue); 4043 } 4044 4045 /** 4046 * Get SMS send capable from system property by phone id. 4047 * 4048 * @param phoneId for which SMS send capable is get 4049 * @param defaultValue default value 4050 * @return SMS send capable 4051 * 4052 * @hide 4053 */ 4054 public boolean getSmsSendCapableForPhone(int phoneId, boolean defaultValue) { 4055 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4056 return Boolean.valueOf(TelephonyManager.getTelephonyProperty(phoneId, 4057 TelephonyProperties.PROPERTY_SMS_SEND, String.valueOf(defaultValue))); 4058 } 4059 4060 return defaultValue; 4061 } 4062 4063 /** 4064 * Set the alphabetic name of current registered operator. 4065 * @param name the alphabetic name of current registered operator. 4066 * @hide 4067 */ 4068 public void setNetworkOperatorName(String name) { 4069 int phoneId = getDefaultPhone(); 4070 setNetworkOperatorNameForPhone(phoneId, name); 4071 } 4072 4073 /** 4074 * Set the alphabetic name of current registered operator. 4075 * @param phoneId which phone you want to set 4076 * @param name the alphabetic name of current registered operator. 4077 * @hide 4078 */ 4079 public void setNetworkOperatorNameForPhone(int phoneId, String name) { 4080 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4081 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, name); 4082 } 4083 } 4084 4085 /** 4086 * Set the numeric name (MCC+MNC) of current registered operator. 4087 * @param operator the numeric name (MCC+MNC) of current registered operator 4088 * @hide 4089 */ 4090 public void setNetworkOperatorNumeric(String numeric) { 4091 int phoneId = getDefaultPhone(); 4092 setNetworkOperatorNumericForPhone(phoneId, numeric); 4093 } 4094 4095 /** 4096 * Set the numeric name (MCC+MNC) of current registered operator. 4097 * @param phoneId for which phone type is set 4098 * @param operator the numeric name (MCC+MNC) of current registered operator 4099 * @hide 4100 */ 4101 public void setNetworkOperatorNumericForPhone(int phoneId, String numeric) { 4102 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, numeric); 4103 } 4104 4105 /** 4106 * Set roaming state of the current network, for GSM purposes. 4107 * @param isRoaming is network in romaing state or not 4108 * @hide 4109 */ 4110 public void setNetworkRoaming(boolean isRoaming) { 4111 int phoneId = getDefaultPhone(); 4112 setNetworkRoamingForPhone(phoneId, isRoaming); 4113 } 4114 4115 /** 4116 * Set roaming state of the current network, for GSM purposes. 4117 * @param phoneId which phone you want to set 4118 * @param isRoaming is network in romaing state or not 4119 * @hide 4120 */ 4121 public void setNetworkRoamingForPhone(int phoneId, boolean isRoaming) { 4122 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4123 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, 4124 isRoaming ? "true" : "false"); 4125 } 4126 } 4127 4128 /** 4129 * Set the ISO country code equivalent of the current registered 4130 * operator's MCC (Mobile Country Code). 4131 * @param iso the ISO country code equivalent of the current registered 4132 * @hide 4133 */ 4134 public void setNetworkCountryIso(String iso) { 4135 int phoneId = getDefaultPhone(); 4136 setNetworkCountryIsoForPhone(phoneId, iso); 4137 } 4138 4139 /** 4140 * Set the ISO country code equivalent of the current registered 4141 * operator's MCC (Mobile Country Code). 4142 * @param phoneId which phone you want to set 4143 * @param iso the ISO country code equivalent of the current registered 4144 * @hide 4145 */ 4146 public void setNetworkCountryIsoForPhone(int phoneId, String iso) { 4147 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4148 setTelephonyProperty(phoneId, 4149 TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, iso); 4150 } 4151 } 4152 4153 /** 4154 * Set the network type currently in use on the device for data transmission. 4155 * @param type the network type currently in use on the device for data transmission 4156 * @hide 4157 */ 4158 public void setDataNetworkType(int type) { 4159 int phoneId = getDefaultPhone(); 4160 setDataNetworkTypeForPhone(phoneId, type); 4161 } 4162 4163 /** 4164 * Set the network type currently in use on the device for data transmission. 4165 * @param phoneId which phone you want to set 4166 * @param type the network type currently in use on the device for data transmission 4167 * @hide 4168 */ 4169 public void setDataNetworkTypeForPhone(int phoneId, int type) { 4170 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4171 setTelephonyProperty(phoneId, 4172 TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE, 4173 ServiceState.rilRadioTechnologyToString(type)); 4174 } 4175 } 4176 4177 /** 4178 * Returns the subscription ID for the given phone account. 4179 * @hide 4180 */ 4181 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { 4182 int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 4183 try { 4184 ITelephony service = getITelephony(); 4185 if (service != null) { 4186 retval = service.getSubIdForPhoneAccount(phoneAccount); 4187 } 4188 } catch (RemoteException e) { 4189 } 4190 4191 return retval; 4192 } 4193} 4194