TelephonyManager.java revision 08c7116ab9cd04ad6dd3c04aa1017237e7f409ac
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 1216 /** 1217 * @return the NETWORK_TYPE_xxxx for current data connection. 1218 */ 1219 public int getNetworkType() { 1220 return getDataNetworkType(); 1221 } 1222 1223 /** 1224 * Returns a constant indicating the radio technology (network type) 1225 * currently in use on the device for a subscription. 1226 * @return the network type 1227 * 1228 * @param subId for which network type is returned 1229 * 1230 * @see #NETWORK_TYPE_UNKNOWN 1231 * @see #NETWORK_TYPE_GPRS 1232 * @see #NETWORK_TYPE_EDGE 1233 * @see #NETWORK_TYPE_UMTS 1234 * @see #NETWORK_TYPE_HSDPA 1235 * @see #NETWORK_TYPE_HSUPA 1236 * @see #NETWORK_TYPE_HSPA 1237 * @see #NETWORK_TYPE_CDMA 1238 * @see #NETWORK_TYPE_EVDO_0 1239 * @see #NETWORK_TYPE_EVDO_A 1240 * @see #NETWORK_TYPE_EVDO_B 1241 * @see #NETWORK_TYPE_1xRTT 1242 * @see #NETWORK_TYPE_IDEN 1243 * @see #NETWORK_TYPE_LTE 1244 * @see #NETWORK_TYPE_EHRPD 1245 * @see #NETWORK_TYPE_HSPAP 1246 */ 1247 /** {@hide} */ 1248 public int getNetworkType(int subId) { 1249 try { 1250 ITelephony telephony = getITelephony(); 1251 if (telephony != null) { 1252 return telephony.getNetworkTypeForSubscriber(subId); 1253 } else { 1254 // This can happen when the ITelephony interface is not up yet. 1255 return NETWORK_TYPE_UNKNOWN; 1256 } 1257 } catch(RemoteException ex) { 1258 // This shouldn't happen in the normal case 1259 return NETWORK_TYPE_UNKNOWN; 1260 } catch (NullPointerException ex) { 1261 // This could happen before phone restarts due to crashing 1262 return NETWORK_TYPE_UNKNOWN; 1263 } 1264 } 1265 1266 /** 1267 * Returns a constant indicating the radio technology (network type) 1268 * currently in use on the device for data transmission. 1269 * @return the network type 1270 * 1271 * @see #NETWORK_TYPE_UNKNOWN 1272 * @see #NETWORK_TYPE_GPRS 1273 * @see #NETWORK_TYPE_EDGE 1274 * @see #NETWORK_TYPE_UMTS 1275 * @see #NETWORK_TYPE_HSDPA 1276 * @see #NETWORK_TYPE_HSUPA 1277 * @see #NETWORK_TYPE_HSPA 1278 * @see #NETWORK_TYPE_CDMA 1279 * @see #NETWORK_TYPE_EVDO_0 1280 * @see #NETWORK_TYPE_EVDO_A 1281 * @see #NETWORK_TYPE_EVDO_B 1282 * @see #NETWORK_TYPE_1xRTT 1283 * @see #NETWORK_TYPE_IDEN 1284 * @see #NETWORK_TYPE_LTE 1285 * @see #NETWORK_TYPE_EHRPD 1286 * @see #NETWORK_TYPE_HSPAP 1287 * 1288 * @hide 1289 */ 1290 public int getDataNetworkType() { 1291 return getDataNetworkType(getDefaultSubscription()); 1292 } 1293 1294 /** 1295 * Returns a constant indicating the radio technology (network type) 1296 * currently in use on the device for data transmission for a subscription 1297 * @return the network type 1298 * 1299 * @param subId for which network type is returned 1300 */ 1301 /** {@hide} */ 1302 public int getDataNetworkType(int subId) { 1303 try{ 1304 ITelephony telephony = getITelephony(); 1305 if (telephony != null) { 1306 return telephony.getDataNetworkTypeForSubscriber(subId); 1307 } else { 1308 // This can happen when the ITelephony interface is not up yet. 1309 return NETWORK_TYPE_UNKNOWN; 1310 } 1311 } catch(RemoteException ex) { 1312 // This shouldn't happen in the normal case 1313 return NETWORK_TYPE_UNKNOWN; 1314 } catch (NullPointerException ex) { 1315 // This could happen before phone restarts due to crashing 1316 return NETWORK_TYPE_UNKNOWN; 1317 } 1318 } 1319 1320 /** 1321 * Returns the NETWORK_TYPE_xxxx for voice 1322 * 1323 * @hide 1324 */ 1325 public int getVoiceNetworkType() { 1326 return getVoiceNetworkType(getDefaultSubscription()); 1327 } 1328 1329 /** 1330 * Returns the NETWORK_TYPE_xxxx for voice for a subId 1331 * 1332 */ 1333 /** {@hide} */ 1334 public int getVoiceNetworkType(int subId) { 1335 try{ 1336 ITelephony telephony = getITelephony(); 1337 if (telephony != null) { 1338 return telephony.getVoiceNetworkTypeForSubscriber(subId); 1339 } else { 1340 // This can happen when the ITelephony interface is not up yet. 1341 return NETWORK_TYPE_UNKNOWN; 1342 } 1343 } catch(RemoteException ex) { 1344 // This shouldn't happen in the normal case 1345 return NETWORK_TYPE_UNKNOWN; 1346 } catch (NullPointerException ex) { 1347 // This could happen before phone restarts due to crashing 1348 return NETWORK_TYPE_UNKNOWN; 1349 } 1350 } 1351 1352 /** Unknown network class. {@hide} */ 1353 public static final int NETWORK_CLASS_UNKNOWN = 0; 1354 /** Class of broadly defined "2G" networks. {@hide} */ 1355 public static final int NETWORK_CLASS_2_G = 1; 1356 /** Class of broadly defined "3G" networks. {@hide} */ 1357 public static final int NETWORK_CLASS_3_G = 2; 1358 /** Class of broadly defined "4G" networks. {@hide} */ 1359 public static final int NETWORK_CLASS_4_G = 3; 1360 1361 /** 1362 * Return general class of network type, such as "3G" or "4G". In cases 1363 * where classification is contentious, this method is conservative. 1364 * 1365 * @hide 1366 */ 1367 public static int getNetworkClass(int networkType) { 1368 switch (networkType) { 1369 case NETWORK_TYPE_GPRS: 1370 case NETWORK_TYPE_GSM: 1371 case NETWORK_TYPE_EDGE: 1372 case NETWORK_TYPE_CDMA: 1373 case NETWORK_TYPE_1xRTT: 1374 case NETWORK_TYPE_IDEN: 1375 return NETWORK_CLASS_2_G; 1376 case NETWORK_TYPE_UMTS: 1377 case NETWORK_TYPE_EVDO_0: 1378 case NETWORK_TYPE_EVDO_A: 1379 case NETWORK_TYPE_HSDPA: 1380 case NETWORK_TYPE_HSUPA: 1381 case NETWORK_TYPE_HSPA: 1382 case NETWORK_TYPE_EVDO_B: 1383 case NETWORK_TYPE_EHRPD: 1384 case NETWORK_TYPE_HSPAP: 1385 return NETWORK_CLASS_3_G; 1386 case NETWORK_TYPE_LTE: 1387 return NETWORK_CLASS_4_G; 1388 default: 1389 return NETWORK_CLASS_UNKNOWN; 1390 } 1391 } 1392 1393 /** 1394 * Returns a string representation of the radio technology (network type) 1395 * currently in use on the device. 1396 * @return the name of the radio technology 1397 * 1398 * @hide pending API council review 1399 */ 1400 public String getNetworkTypeName() { 1401 return getNetworkTypeName(getNetworkType()); 1402 } 1403 1404 /** 1405 * Returns a string representation of the radio technology (network type) 1406 * currently in use on the device. 1407 * @param subId for which network type is returned 1408 * @return the name of the radio technology 1409 * 1410 */ 1411 /** {@hide} */ 1412 public static String getNetworkTypeName(int type) { 1413 switch (type) { 1414 case NETWORK_TYPE_GPRS: 1415 return "GPRS"; 1416 case NETWORK_TYPE_EDGE: 1417 return "EDGE"; 1418 case NETWORK_TYPE_UMTS: 1419 return "UMTS"; 1420 case NETWORK_TYPE_HSDPA: 1421 return "HSDPA"; 1422 case NETWORK_TYPE_HSUPA: 1423 return "HSUPA"; 1424 case NETWORK_TYPE_HSPA: 1425 return "HSPA"; 1426 case NETWORK_TYPE_CDMA: 1427 return "CDMA"; 1428 case NETWORK_TYPE_EVDO_0: 1429 return "CDMA - EvDo rev. 0"; 1430 case NETWORK_TYPE_EVDO_A: 1431 return "CDMA - EvDo rev. A"; 1432 case NETWORK_TYPE_EVDO_B: 1433 return "CDMA - EvDo rev. B"; 1434 case NETWORK_TYPE_1xRTT: 1435 return "CDMA - 1xRTT"; 1436 case NETWORK_TYPE_LTE: 1437 return "LTE"; 1438 case NETWORK_TYPE_EHRPD: 1439 return "CDMA - eHRPD"; 1440 case NETWORK_TYPE_IDEN: 1441 return "iDEN"; 1442 case NETWORK_TYPE_HSPAP: 1443 return "HSPA+"; 1444 case NETWORK_TYPE_GSM: 1445 return "GSM"; 1446 default: 1447 return "UNKNOWN"; 1448 } 1449 } 1450 1451 // 1452 // 1453 // SIM Card 1454 // 1455 // 1456 1457 /** 1458 * SIM card state: Unknown. Signifies that the SIM is in transition 1459 * between states. For example, when the user inputs the SIM pin 1460 * under PIN_REQUIRED state, a query for sim status returns 1461 * this state before turning to SIM_STATE_READY. 1462 * 1463 * These are the ordinal value of IccCardConstants.State. 1464 */ 1465 public static final int SIM_STATE_UNKNOWN = 0; 1466 /** SIM card state: no SIM card is available in the device */ 1467 public static final int SIM_STATE_ABSENT = 1; 1468 /** SIM card state: Locked: requires the user's SIM PIN to unlock */ 1469 public static final int SIM_STATE_PIN_REQUIRED = 2; 1470 /** SIM card state: Locked: requires the user's SIM PUK to unlock */ 1471 public static final int SIM_STATE_PUK_REQUIRED = 3; 1472 /** SIM card state: Locked: requires a network PIN to unlock */ 1473 public static final int SIM_STATE_NETWORK_LOCKED = 4; 1474 /** SIM card state: Ready */ 1475 public static final int SIM_STATE_READY = 5; 1476 /** SIM card state: SIM Card is NOT READY 1477 *@hide 1478 */ 1479 public static final int SIM_STATE_NOT_READY = 6; 1480 /** SIM card state: SIM Card Error, permanently disabled 1481 *@hide 1482 */ 1483 public static final int SIM_STATE_PERM_DISABLED = 7; 1484 /** SIM card state: SIM Card Error, present but faulty 1485 *@hide 1486 */ 1487 public static final int SIM_STATE_CARD_IO_ERROR = 8; 1488 1489 /** 1490 * @return true if a ICC card is present 1491 */ 1492 public boolean hasIccCard() { 1493 return hasIccCard(getDefaultSim()); 1494 } 1495 1496 /** 1497 * @return true if a ICC card is present for a subscription 1498 * 1499 * @param slotId for which icc card presence is checked 1500 */ 1501 /** {@hide} */ 1502 // FIXME Input argument slotId should be of type int 1503 public boolean hasIccCard(int slotId) { 1504 1505 try { 1506 return getITelephony().hasIccCardUsingSlotId(slotId); 1507 } catch (RemoteException ex) { 1508 // Assume no ICC card if remote exception which shouldn't happen 1509 return false; 1510 } catch (NullPointerException ex) { 1511 // This could happen before phone restarts due to crashing 1512 return false; 1513 } 1514 } 1515 1516 /** 1517 * Returns a constant indicating the state of the default SIM card. 1518 * 1519 * @see #SIM_STATE_UNKNOWN 1520 * @see #SIM_STATE_ABSENT 1521 * @see #SIM_STATE_PIN_REQUIRED 1522 * @see #SIM_STATE_PUK_REQUIRED 1523 * @see #SIM_STATE_NETWORK_LOCKED 1524 * @see #SIM_STATE_READY 1525 * @see #SIM_STATE_NOT_READY 1526 * @see #SIM_STATE_PERM_DISABLED 1527 * @see #SIM_STATE_CARD_IO_ERROR 1528 */ 1529 public int getSimState() { 1530 return getSimState(getDefaultSim()); 1531 } 1532 1533 /** 1534 * Returns a constant indicating the state of the device SIM card in a slot. 1535 * 1536 * @param slotIdx 1537 * 1538 * @see #SIM_STATE_UNKNOWN 1539 * @see #SIM_STATE_ABSENT 1540 * @see #SIM_STATE_PIN_REQUIRED 1541 * @see #SIM_STATE_PUK_REQUIRED 1542 * @see #SIM_STATE_NETWORK_LOCKED 1543 * @see #SIM_STATE_READY 1544 * @see #SIM_STATE_NOT_READY 1545 * @see #SIM_STATE_PERM_DISABLED 1546 * @see #SIM_STATE_CARD_IO_ERROR 1547 */ 1548 /** {@hide} */ 1549 public int getSimState(int slotIdx) { 1550 int[] subId = SubscriptionManager.getSubId(slotIdx); 1551 if (subId == null || subId.length == 0) { 1552 Rlog.d(TAG, "getSimState:- empty subId return SIM_STATE_ABSENT"); 1553 return SIM_STATE_UNKNOWN; 1554 } 1555 int simState = SubscriptionManager.getSimStateForSubscriber(subId[0]); 1556 Rlog.d(TAG, "getSimState: simState=" + simState + " slotIdx=" + slotIdx); 1557 return simState; 1558 } 1559 1560 /** 1561 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1562 * provider of the SIM. 5 or 6 decimal digits. 1563 * <p> 1564 * Availability: SIM state must be {@link #SIM_STATE_READY} 1565 * 1566 * @see #getSimState 1567 */ 1568 public String getSimOperator() { 1569 return getSimOperatorNumeric(); 1570 } 1571 1572 /** 1573 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1574 * provider of the SIM. 5 or 6 decimal digits. 1575 * <p> 1576 * Availability: SIM state must be {@link #SIM_STATE_READY} 1577 * 1578 * @see #getSimState 1579 * 1580 * @param subId for which SimOperator is returned 1581 * @hide 1582 */ 1583 public String getSimOperator(int subId) { 1584 return getSimOperatorNumericForSubscription(subId); 1585 } 1586 1587 /** 1588 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1589 * provider of the SIM. 5 or 6 decimal digits. 1590 * <p> 1591 * Availability: SIM state must be {@link #SIM_STATE_READY} 1592 * 1593 * @see #getSimState 1594 * @hide 1595 */ 1596 public String getSimOperatorNumeric() { 1597 int subId = SubscriptionManager.getDefaultDataSubId(); 1598 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 1599 subId = SubscriptionManager.getDefaultSmsSubId(); 1600 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 1601 subId = SubscriptionManager.getDefaultVoiceSubId(); 1602 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 1603 subId = SubscriptionManager.getDefaultSubId(); 1604 } 1605 } 1606 } 1607 Rlog.d(TAG, "getSimOperatorNumeric(): default subId=" + subId); 1608 return getSimOperatorNumericForSubscription(subId); 1609 } 1610 1611 /** 1612 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1613 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 1614 * <p> 1615 * Availability: SIM state must be {@link #SIM_STATE_READY} 1616 * 1617 * @see #getSimState 1618 * 1619 * @param subId for which SimOperator is returned 1620 * @hide 1621 */ 1622 public String getSimOperatorNumericForSubscription(int subId) { 1623 int phoneId = SubscriptionManager.getPhoneId(subId); 1624 return getSimOperatorNumericForPhone(phoneId); 1625 } 1626 1627 /** 1628 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1629 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 1630 * <p> 1631 * 1632 * @param phoneId for which SimOperator is returned 1633 * @hide 1634 */ 1635 public String getSimOperatorNumericForPhone(int phoneId) { 1636 return getTelephonyProperty(phoneId, 1637 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, ""); 1638 } 1639 1640 /** 1641 * Returns the Service Provider Name (SPN). 1642 * <p> 1643 * Availability: SIM state must be {@link #SIM_STATE_READY} 1644 * 1645 * @see #getSimState 1646 */ 1647 public String getSimOperatorName() { 1648 return getSimOperatorNameForPhone(getDefaultPhone()); 1649 } 1650 1651 /** 1652 * Returns the Service Provider Name (SPN). 1653 * <p> 1654 * Availability: SIM state must be {@link #SIM_STATE_READY} 1655 * 1656 * @see #getSimState 1657 * 1658 * @param subId for which SimOperatorName is returned 1659 * @hide 1660 */ 1661 public String getSimOperatorNameForSubscription(int subId) { 1662 int phoneId = SubscriptionManager.getPhoneId(subId); 1663 return getSimOperatorNameForPhone(phoneId); 1664 } 1665 1666 /** 1667 * Returns the Service Provider Name (SPN). 1668 * 1669 * @hide 1670 */ 1671 public String getSimOperatorNameForPhone(int phoneId) { 1672 return getTelephonyProperty(phoneId, 1673 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, ""); 1674 } 1675 1676 /** 1677 * Returns the ISO country code equivalent for the SIM provider's country code. 1678 */ 1679 public String getSimCountryIso() { 1680 return getSimCountryIsoForPhone(getDefaultPhone()); 1681 } 1682 1683 /** 1684 * Returns the ISO country code equivalent for the SIM provider's country code. 1685 * 1686 * @param subId for which SimCountryIso is returned 1687 * 1688 * @hide 1689 */ 1690 public String getSimCountryIso(int subId) { 1691 return getSimCountryIsoForSubscription(subId); 1692 } 1693 1694 /** 1695 * Returns the ISO country code equivalent for the SIM provider's country code. 1696 * 1697 * @param subId for which SimCountryIso is returned 1698 * 1699 * @hide 1700 */ 1701 public String getSimCountryIsoForSubscription(int subId) { 1702 int phoneId = SubscriptionManager.getPhoneId(subId); 1703 return getSimCountryIsoForPhone(phoneId); 1704 } 1705 1706 /** 1707 * Returns the ISO country code equivalent for the SIM provider's country code. 1708 * 1709 * @hide 1710 */ 1711 public String getSimCountryIsoForPhone(int phoneId) { 1712 return getTelephonyProperty(phoneId, 1713 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, ""); 1714 } 1715 1716 /** 1717 * Returns the serial number of the SIM, if applicable. Return null if it is 1718 * unavailable. 1719 * <p> 1720 * Requires Permission: 1721 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1722 */ 1723 public String getSimSerialNumber() { 1724 return getSimSerialNumber(getDefaultSubscription()); 1725 } 1726 1727 /** 1728 * Returns the serial number for the given subscription, if applicable. Return null if it is 1729 * unavailable. 1730 * <p> 1731 * @param subId for which Sim Serial number is returned 1732 * Requires Permission: 1733 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1734 */ 1735 /** {@hide} */ 1736 public String getSimSerialNumber(int subId) { 1737 try { 1738 return getSubscriberInfo().getIccSerialNumberForSubscriber(subId); 1739 } catch (RemoteException ex) { 1740 return null; 1741 } catch (NullPointerException ex) { 1742 // This could happen before phone restarts due to crashing 1743 return null; 1744 } 1745 } 1746 1747 /** 1748 * Return if the current radio is LTE on CDMA. This 1749 * is a tri-state return value as for a period of time 1750 * the mode may be unknown. 1751 * 1752 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 1753 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 1754 * 1755 * @hide 1756 */ 1757 public int getLteOnCdmaMode() { 1758 return getLteOnCdmaMode(getDefaultSubscription()); 1759 } 1760 1761 /** 1762 * Return if the current radio is LTE on CDMA for Subscription. This 1763 * is a tri-state return value as for a period of time 1764 * the mode may be unknown. 1765 * 1766 * @param subId for which radio is LTE on CDMA is returned 1767 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 1768 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 1769 * 1770 */ 1771 /** {@hide} */ 1772 public int getLteOnCdmaMode(int subId) { 1773 try { 1774 return getITelephony().getLteOnCdmaModeForSubscriber(subId); 1775 } catch (RemoteException ex) { 1776 // Assume no ICC card if remote exception which shouldn't happen 1777 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 1778 } catch (NullPointerException ex) { 1779 // This could happen before phone restarts due to crashing 1780 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 1781 } 1782 } 1783 1784 // 1785 // 1786 // Subscriber Info 1787 // 1788 // 1789 1790 /** 1791 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone. 1792 * Return null if it is unavailable. 1793 * <p> 1794 * Requires Permission: 1795 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1796 */ 1797 public String getSubscriberId() { 1798 return getSubscriberId(getDefaultSubscription()); 1799 } 1800 1801 /** 1802 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone 1803 * for a subscription. 1804 * Return null if it is unavailable. 1805 * <p> 1806 * Requires Permission: 1807 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1808 * 1809 * @param subId whose subscriber id is returned 1810 */ 1811 /** {@hide} */ 1812 public String getSubscriberId(int subId) { 1813 try { 1814 return getSubscriberInfo().getSubscriberIdForSubscriber(subId); 1815 } catch (RemoteException ex) { 1816 return null; 1817 } catch (NullPointerException ex) { 1818 // This could happen before phone restarts due to crashing 1819 return null; 1820 } 1821 } 1822 1823 /** 1824 * Returns the Group Identifier Level1 for a GSM phone. 1825 * Return null if it is unavailable. 1826 * <p> 1827 * Requires Permission: 1828 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1829 */ 1830 public String getGroupIdLevel1() { 1831 try { 1832 return getSubscriberInfo().getGroupIdLevel1(); 1833 } catch (RemoteException ex) { 1834 return null; 1835 } catch (NullPointerException ex) { 1836 // This could happen before phone restarts due to crashing 1837 return null; 1838 } 1839 } 1840 1841 /** 1842 * Returns the Group Identifier Level1 for a GSM phone for a particular subscription. 1843 * Return null if it is unavailable. 1844 * <p> 1845 * Requires Permission: 1846 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1847 * 1848 * @param subscription whose subscriber id is returned 1849 */ 1850 /** {@hide} */ 1851 public String getGroupIdLevel1(int subId) { 1852 try { 1853 return getSubscriberInfo().getGroupIdLevel1ForSubscriber(subId); 1854 } catch (RemoteException ex) { 1855 return null; 1856 } catch (NullPointerException ex) { 1857 // This could happen before phone restarts due to crashing 1858 return null; 1859 } 1860 } 1861 1862 /** 1863 * Returns the phone number string for line 1, for example, the MSISDN 1864 * for a GSM phone. Return null if it is unavailable. 1865 * <p> 1866 * Requires Permission: 1867 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1868 */ 1869 public String getLine1Number() { 1870 return getLine1NumberForSubscriber(getDefaultSubscription()); 1871 } 1872 1873 /** 1874 * Returns the phone number string for line 1, for example, the MSISDN 1875 * for a GSM phone for a particular subscription. Return null if it is unavailable. 1876 * <p> 1877 * Requires Permission: 1878 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1879 * 1880 * @param subId whose phone number for line 1 is returned 1881 */ 1882 /** {@hide} */ 1883 public String getLine1NumberForSubscriber(int subId) { 1884 String number = null; 1885 try { 1886 number = getITelephony().getLine1NumberForDisplay(subId); 1887 } catch (RemoteException ex) { 1888 } catch (NullPointerException ex) { 1889 } 1890 if (number != null) { 1891 return number; 1892 } 1893 try { 1894 return getSubscriberInfo().getLine1NumberForSubscriber(subId); 1895 } catch (RemoteException ex) { 1896 return null; 1897 } catch (NullPointerException ex) { 1898 // This could happen before phone restarts due to crashing 1899 return null; 1900 } 1901 } 1902 1903 /** 1904 * Set the line 1 phone number string and its alphatag for the current ICCID 1905 * for display purpose only, for example, displayed in Phone Status. It won't 1906 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 1907 * value. 1908 * 1909 * <p>Requires that the calling app has carrier privileges. 1910 * @see #hasCarrierPrivileges 1911 * 1912 * @param alphaTag alpha-tagging of the dailing nubmer 1913 * @param number The dialing number 1914 * @return true if the operation was executed correctly. 1915 */ 1916 public boolean setLine1NumberForDisplay(String alphaTag, String number) { 1917 return setLine1NumberForDisplayForSubscriber(getDefaultSubscription(), alphaTag, number); 1918 } 1919 1920 /** 1921 * Set the line 1 phone number string and its alphatag for the current ICCID 1922 * for display purpose only, for example, displayed in Phone Status. It won't 1923 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 1924 * value. 1925 * 1926 * <p>Requires that the calling app has carrier privileges. 1927 * @see #hasCarrierPrivileges 1928 * 1929 * @param subId the subscriber that the alphatag and dialing number belongs to. 1930 * @param alphaTag alpha-tagging of the dailing nubmer 1931 * @param number The dialing number 1932 * @return true if the operation was executed correctly. 1933 * @hide 1934 */ 1935 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, String number) { 1936 try { 1937 return getITelephony().setLine1NumberForDisplayForSubscriber(subId, alphaTag, number); 1938 } catch (RemoteException ex) { 1939 } catch (NullPointerException ex) { 1940 } 1941 return false; 1942 } 1943 1944 /** 1945 * Returns the alphabetic identifier associated with the line 1 number. 1946 * Return null if it is unavailable. 1947 * <p> 1948 * Requires Permission: 1949 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1950 * @hide 1951 * nobody seems to call this. 1952 */ 1953 public String getLine1AlphaTag() { 1954 return getLine1AlphaTagForSubscriber(getDefaultSubscription()); 1955 } 1956 1957 /** 1958 * Returns the alphabetic identifier associated with the line 1 number 1959 * for a subscription. 1960 * Return null if it is unavailable. 1961 * <p> 1962 * Requires Permission: 1963 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1964 * @param subId whose alphabetic identifier associated with line 1 is returned 1965 * nobody seems to call this. 1966 */ 1967 /** {@hide} */ 1968 public String getLine1AlphaTagForSubscriber(int subId) { 1969 String alphaTag = null; 1970 try { 1971 alphaTag = getITelephony().getLine1AlphaTagForDisplay(subId); 1972 } catch (RemoteException ex) { 1973 } catch (NullPointerException ex) { 1974 } 1975 if (alphaTag != null) { 1976 return alphaTag; 1977 } 1978 try { 1979 return getSubscriberInfo().getLine1AlphaTagForSubscriber(subId); 1980 } catch (RemoteException ex) { 1981 return null; 1982 } catch (NullPointerException ex) { 1983 // This could happen before phone restarts due to crashing 1984 return null; 1985 } 1986 } 1987 1988 /** 1989 * Return the set of subscriber IDs that should be considered as "merged 1990 * together" for data usage purposes. This is commonly {@code null} to 1991 * indicate no merging is required. Any returned subscribers are sorted in a 1992 * deterministic order. 1993 * 1994 * @hide 1995 */ 1996 public @Nullable String[] getMergedSubscriberIds() { 1997 try { 1998 return getITelephony().getMergedSubscriberIds(); 1999 } catch (RemoteException ex) { 2000 } catch (NullPointerException ex) { 2001 } 2002 return null; 2003 } 2004 2005 /** 2006 * Returns the MSISDN string. 2007 * for a GSM phone. Return null if it is unavailable. 2008 * <p> 2009 * Requires Permission: 2010 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2011 * 2012 * @hide 2013 */ 2014 public String getMsisdn() { 2015 return getMsisdn(getDefaultSubscription()); 2016 } 2017 2018 /** 2019 * Returns the MSISDN string. 2020 * for a GSM phone. Return null if it is unavailable. 2021 * <p> 2022 * Requires Permission: 2023 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2024 * 2025 * @param subId for which msisdn is returned 2026 */ 2027 /** {@hide} */ 2028 public String getMsisdn(int subId) { 2029 try { 2030 return getSubscriberInfo().getMsisdnForSubscriber(subId); 2031 } catch (RemoteException ex) { 2032 return null; 2033 } catch (NullPointerException ex) { 2034 // This could happen before phone restarts due to crashing 2035 return null; 2036 } 2037 } 2038 2039 /** 2040 * Returns the voice mail number. Return null if it is unavailable. 2041 * <p> 2042 * Requires Permission: 2043 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2044 */ 2045 public String getVoiceMailNumber() { 2046 return getVoiceMailNumber(getDefaultSubscription()); 2047 } 2048 2049 /** 2050 * Returns the voice mail number for a subscription. 2051 * Return null if it is unavailable. 2052 * <p> 2053 * Requires Permission: 2054 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2055 * @param subId whose voice mail number is returned 2056 */ 2057 /** {@hide} */ 2058 public String getVoiceMailNumber(int subId) { 2059 try { 2060 return getSubscriberInfo().getVoiceMailNumberForSubscriber(subId); 2061 } catch (RemoteException ex) { 2062 return null; 2063 } catch (NullPointerException ex) { 2064 // This could happen before phone restarts due to crashing 2065 return null; 2066 } 2067 } 2068 2069 /** 2070 * Returns the complete voice mail number. Return null if it is unavailable. 2071 * <p> 2072 * Requires Permission: 2073 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 2074 * 2075 * @hide 2076 */ 2077 public String getCompleteVoiceMailNumber() { 2078 return getCompleteVoiceMailNumber(getDefaultSubscription()); 2079 } 2080 2081 /** 2082 * Returns the complete voice mail number. Return null if it is unavailable. 2083 * <p> 2084 * Requires Permission: 2085 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 2086 * 2087 * @param subId 2088 */ 2089 /** {@hide} */ 2090 public String getCompleteVoiceMailNumber(int subId) { 2091 try { 2092 return getSubscriberInfo().getCompleteVoiceMailNumberForSubscriber(subId); 2093 } catch (RemoteException ex) { 2094 return null; 2095 } catch (NullPointerException ex) { 2096 // This could happen before phone restarts due to crashing 2097 return null; 2098 } 2099 } 2100 2101 /** 2102 * Sets the voice mail number. 2103 * 2104 * <p>Requires that the calling app has carrier privileges. 2105 * @see #hasCarrierPrivileges 2106 * 2107 * @param alphaTag The alpha tag to display. 2108 * @param number The voicemail number. 2109 */ 2110 public boolean setVoiceMailNumber(String alphaTag, String number) { 2111 return setVoiceMailNumber(getDefaultSubscription(), alphaTag, number); 2112 } 2113 2114 /** 2115 * Sets the voicemail number for the given subscriber. 2116 * 2117 * <p>Requires that the calling app has carrier privileges. 2118 * @see #hasCarrierPrivileges 2119 * 2120 * @param subId The subscription id. 2121 * @param alphaTag The alpha tag to display. 2122 * @param number The voicemail number. 2123 */ 2124 /** {@hide} */ 2125 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { 2126 try { 2127 return getITelephony().setVoiceMailNumber(subId, alphaTag, number); 2128 } catch (RemoteException ex) { 2129 } catch (NullPointerException ex) { 2130 } 2131 return false; 2132 } 2133 2134 /** 2135 * Returns the voice mail count. Return 0 if unavailable. 2136 * <p> 2137 * Requires Permission: 2138 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2139 * @hide 2140 */ 2141 public int getVoiceMessageCount() { 2142 return getVoiceMessageCount(getDefaultSubscription()); 2143 } 2144 2145 /** 2146 * Returns the voice mail count for a subscription. Return 0 if unavailable. 2147 * <p> 2148 * Requires Permission: 2149 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2150 * @param subId whose voice message count is returned 2151 */ 2152 /** {@hide} */ 2153 public int getVoiceMessageCount(int subId) { 2154 try { 2155 return getITelephony().getVoiceMessageCountForSubscriber(subId); 2156 } catch (RemoteException ex) { 2157 return 0; 2158 } catch (NullPointerException ex) { 2159 // This could happen before phone restarts due to crashing 2160 return 0; 2161 } 2162 } 2163 2164 /** 2165 * Retrieves the alphabetic identifier associated with the voice 2166 * mail number. 2167 * <p> 2168 * Requires Permission: 2169 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2170 */ 2171 public String getVoiceMailAlphaTag() { 2172 return getVoiceMailAlphaTag(getDefaultSubscription()); 2173 } 2174 2175 /** 2176 * Retrieves the alphabetic identifier associated with the voice 2177 * mail number for a subscription. 2178 * <p> 2179 * Requires Permission: 2180 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2181 * @param subId whose alphabetic identifier associated with the 2182 * voice mail number is returned 2183 */ 2184 /** {@hide} */ 2185 public String getVoiceMailAlphaTag(int subId) { 2186 try { 2187 return getSubscriberInfo().getVoiceMailAlphaTagForSubscriber(subId); 2188 } catch (RemoteException ex) { 2189 return null; 2190 } catch (NullPointerException ex) { 2191 // This could happen before phone restarts due to crashing 2192 return null; 2193 } 2194 } 2195 2196 /** 2197 * Returns the IMS private user identity (IMPI) that was loaded from the ISIM. 2198 * @return the IMPI, or null if not present or not loaded 2199 * @hide 2200 */ 2201 public String getIsimImpi() { 2202 try { 2203 return getSubscriberInfo().getIsimImpi(); 2204 } catch (RemoteException ex) { 2205 return null; 2206 } catch (NullPointerException ex) { 2207 // This could happen before phone restarts due to crashing 2208 return null; 2209 } 2210 } 2211 2212 /** 2213 * Returns the IMS home network domain name that was loaded from the ISIM. 2214 * @return the IMS domain name, or null if not present or not loaded 2215 * @hide 2216 */ 2217 public String getIsimDomain() { 2218 try { 2219 return getSubscriberInfo().getIsimDomain(); 2220 } catch (RemoteException ex) { 2221 return null; 2222 } catch (NullPointerException ex) { 2223 // This could happen before phone restarts due to crashing 2224 return null; 2225 } 2226 } 2227 2228 /** 2229 * Returns the IMS public user identities (IMPU) that were loaded from the ISIM. 2230 * @return an array of IMPU strings, with one IMPU per string, or null if 2231 * not present or not loaded 2232 * @hide 2233 */ 2234 public String[] getIsimImpu() { 2235 try { 2236 return getSubscriberInfo().getIsimImpu(); 2237 } catch (RemoteException ex) { 2238 return null; 2239 } catch (NullPointerException ex) { 2240 // This could happen before phone restarts due to crashing 2241 return null; 2242 } 2243 } 2244 2245 /** 2246 * @hide 2247 */ 2248 private IPhoneSubInfo getSubscriberInfo() { 2249 // get it each time because that process crashes a lot 2250 return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo")); 2251 } 2252 2253 /** Device call state: No activity. */ 2254 public static final int CALL_STATE_IDLE = 0; 2255 /** Device call state: Ringing. A new call arrived and is 2256 * ringing or waiting. In the latter case, another call is 2257 * already active. */ 2258 public static final int CALL_STATE_RINGING = 1; 2259 /** Device call state: Off-hook. At least one call exists 2260 * that is dialing, active, or on hold, and no calls are ringing 2261 * or waiting. */ 2262 public static final int CALL_STATE_OFFHOOK = 2; 2263 2264 /** 2265 * Returns a constant indicating the call state (cellular) on the device. 2266 */ 2267 public int getCallState() { 2268 return getCallState(getDefaultSubscription()); 2269 } 2270 2271 /** 2272 * Returns a constant indicating the call state (cellular) on the device 2273 * for a subscription. 2274 * 2275 * @param subId whose call state is returned 2276 */ 2277 /** {@hide} */ 2278 public int getCallState(int subId) { 2279 try { 2280 return getITelephony().getCallStateForSubscriber(subId); 2281 } catch (RemoteException ex) { 2282 // the phone process is restarting. 2283 return CALL_STATE_IDLE; 2284 } catch (NullPointerException ex) { 2285 // the phone process is restarting. 2286 return CALL_STATE_IDLE; 2287 } 2288 } 2289 2290 /** Data connection activity: No traffic. */ 2291 public static final int DATA_ACTIVITY_NONE = 0x00000000; 2292 /** Data connection activity: Currently receiving IP PPP traffic. */ 2293 public static final int DATA_ACTIVITY_IN = 0x00000001; 2294 /** Data connection activity: Currently sending IP PPP traffic. */ 2295 public static final int DATA_ACTIVITY_OUT = 0x00000002; 2296 /** Data connection activity: Currently both sending and receiving 2297 * IP PPP traffic. */ 2298 public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT; 2299 /** 2300 * Data connection is active, but physical link is down 2301 */ 2302 public static final int DATA_ACTIVITY_DORMANT = 0x00000004; 2303 2304 /** 2305 * Returns a constant indicating the type of activity on a data connection 2306 * (cellular). 2307 * 2308 * @see #DATA_ACTIVITY_NONE 2309 * @see #DATA_ACTIVITY_IN 2310 * @see #DATA_ACTIVITY_OUT 2311 * @see #DATA_ACTIVITY_INOUT 2312 * @see #DATA_ACTIVITY_DORMANT 2313 */ 2314 public int getDataActivity() { 2315 try { 2316 return getITelephony().getDataActivity(); 2317 } catch (RemoteException ex) { 2318 // the phone process is restarting. 2319 return DATA_ACTIVITY_NONE; 2320 } catch (NullPointerException ex) { 2321 // the phone process is restarting. 2322 return DATA_ACTIVITY_NONE; 2323 } 2324 } 2325 2326 /** Data connection state: Unknown. Used before we know the state. 2327 * @hide 2328 */ 2329 public static final int DATA_UNKNOWN = -1; 2330 /** Data connection state: Disconnected. IP traffic not available. */ 2331 public static final int DATA_DISCONNECTED = 0; 2332 /** Data connection state: Currently setting up a data connection. */ 2333 public static final int DATA_CONNECTING = 1; 2334 /** Data connection state: Connected. IP traffic should be available. */ 2335 public static final int DATA_CONNECTED = 2; 2336 /** Data connection state: Suspended. The connection is up, but IP 2337 * traffic is temporarily unavailable. For example, in a 2G network, 2338 * data activity may be suspended when a voice call arrives. */ 2339 public static final int DATA_SUSPENDED = 3; 2340 2341 /** 2342 * Returns a constant indicating the current data connection state 2343 * (cellular). 2344 * 2345 * @see #DATA_DISCONNECTED 2346 * @see #DATA_CONNECTING 2347 * @see #DATA_CONNECTED 2348 * @see #DATA_SUSPENDED 2349 */ 2350 public int getDataState() { 2351 try { 2352 return getITelephony().getDataState(); 2353 } catch (RemoteException ex) { 2354 // the phone process is restarting. 2355 return DATA_DISCONNECTED; 2356 } catch (NullPointerException ex) { 2357 return DATA_DISCONNECTED; 2358 } 2359 } 2360 2361 /** 2362 * @hide 2363 */ 2364 private ITelephony getITelephony() { 2365 return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); 2366 } 2367 2368 /** 2369 * @hide 2370 */ 2371 private ITelecomService getTelecomService() { 2372 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE)); 2373 } 2374 2375 // 2376 // 2377 // PhoneStateListener 2378 // 2379 // 2380 2381 /** 2382 * Registers a listener object to receive notification of changes 2383 * in specified telephony states. 2384 * <p> 2385 * To register a listener, pass a {@link PhoneStateListener} 2386 * and specify at least one telephony state of interest in 2387 * the events argument. 2388 * 2389 * At registration, and when a specified telephony state 2390 * changes, the telephony manager invokes the appropriate 2391 * callback method on the listener object and passes the 2392 * current (updated) values. 2393 * <p> 2394 * To unregister a listener, pass the listener object and set the 2395 * events argument to 2396 * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0). 2397 * 2398 * @param listener The {@link PhoneStateListener} object to register 2399 * (or unregister) 2400 * @param events The telephony state(s) of interest to the listener, 2401 * as a bitwise-OR combination of {@link PhoneStateListener} 2402 * LISTEN_ flags. 2403 */ 2404 public void listen(PhoneStateListener listener, int events) { 2405 String pkgForDebug = mContext != null ? mContext.getPackageName() : "<unknown>"; 2406 try { 2407 Boolean notifyNow = (getITelephony() != null); 2408 sRegistry.listenForSubscriber(listener.mSubId, pkgForDebug, listener.callback, events, notifyNow); 2409 } catch (RemoteException ex) { 2410 // system process dead 2411 } catch (NullPointerException ex) { 2412 // system process dead 2413 } 2414 } 2415 2416 /** 2417 * Returns the CDMA ERI icon index to display 2418 * 2419 * @hide 2420 */ 2421 public int getCdmaEriIconIndex() { 2422 return getCdmaEriIconIndex(getDefaultSubscription()); 2423 } 2424 2425 /** 2426 * Returns the CDMA ERI icon index to display for a subscription 2427 */ 2428 /** {@hide} */ 2429 public int getCdmaEriIconIndex(int subId) { 2430 try { 2431 return getITelephony().getCdmaEriIconIndexForSubscriber(subId); 2432 } catch (RemoteException ex) { 2433 // the phone process is restarting. 2434 return -1; 2435 } catch (NullPointerException ex) { 2436 return -1; 2437 } 2438 } 2439 2440 /** 2441 * Returns the CDMA ERI icon mode, 2442 * 0 - ON 2443 * 1 - FLASHING 2444 * 2445 * @hide 2446 */ 2447 public int getCdmaEriIconMode() { 2448 return getCdmaEriIconMode(getDefaultSubscription()); 2449 } 2450 2451 /** 2452 * Returns the CDMA ERI icon mode for a subscription. 2453 * 0 - ON 2454 * 1 - FLASHING 2455 */ 2456 /** {@hide} */ 2457 public int getCdmaEriIconMode(int subId) { 2458 try { 2459 return getITelephony().getCdmaEriIconModeForSubscriber(subId); 2460 } catch (RemoteException ex) { 2461 // the phone process is restarting. 2462 return -1; 2463 } catch (NullPointerException ex) { 2464 return -1; 2465 } 2466 } 2467 2468 /** 2469 * Returns the CDMA ERI text, 2470 * 2471 * @hide 2472 */ 2473 public String getCdmaEriText() { 2474 return getCdmaEriText(getDefaultSubscription()); 2475 } 2476 2477 /** 2478 * Returns the CDMA ERI text, of a subscription 2479 * 2480 */ 2481 /** {@hide} */ 2482 public String getCdmaEriText(int subId) { 2483 try { 2484 return getITelephony().getCdmaEriTextForSubscriber(subId); 2485 } catch (RemoteException ex) { 2486 // the phone process is restarting. 2487 return null; 2488 } catch (NullPointerException ex) { 2489 return null; 2490 } 2491 } 2492 2493 /** 2494 * @return true if the current device is "voice capable". 2495 * <p> 2496 * "Voice capable" means that this device supports circuit-switched 2497 * (i.e. voice) phone calls over the telephony network, and is allowed 2498 * to display the in-call UI while a cellular voice call is active. 2499 * This will be false on "data only" devices which can't make voice 2500 * calls and don't support any in-call UI. 2501 * <p> 2502 * Note: the meaning of this flag is subtly different from the 2503 * PackageManager.FEATURE_TELEPHONY system feature, which is available 2504 * on any device with a telephony radio, even if the device is 2505 * data-only. 2506 */ 2507 public boolean isVoiceCapable() { 2508 if (mContext == null) return true; 2509 return mContext.getResources().getBoolean( 2510 com.android.internal.R.bool.config_voice_capable); 2511 } 2512 2513 /** 2514 * @return true if the current device supports sms service. 2515 * <p> 2516 * If true, this means that the device supports both sending and 2517 * receiving sms via the telephony network. 2518 * <p> 2519 * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are 2520 * disabled when device doesn't support sms. 2521 */ 2522 public boolean isSmsCapable() { 2523 if (mContext == null) return true; 2524 return mContext.getResources().getBoolean( 2525 com.android.internal.R.bool.config_sms_capable); 2526 } 2527 2528 /** 2529 * Returns all observed cell information from all radios on the 2530 * device including the primary and neighboring cells. This does 2531 * not cause or change the rate of PhoneStateListner#onCellInfoChanged. 2532 *<p> 2533 * The list can include one or more of {@link android.telephony.CellInfoGsm CellInfoGsm}, 2534 * {@link android.telephony.CellInfoCdma CellInfoCdma}, 2535 * {@link android.telephony.CellInfoLte CellInfoLte} and 2536 * {@link android.telephony.CellInfoWcdma CellInfoCdma} in any combination. 2537 * Specifically on devices with multiple radios it is typical to see instances of 2538 * one or more of any these in the list. In addition 0, 1 or more CellInfo 2539 * objects may return isRegistered() true. 2540 *<p> 2541 * This is preferred over using getCellLocation although for older 2542 * devices this may return null in which case getCellLocation should 2543 * be called. 2544 *<p> 2545 * @return List of CellInfo or null if info unavailable. 2546 * 2547 * <p>Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} 2548 */ 2549 public List<CellInfo> getAllCellInfo() { 2550 try { 2551 return getITelephony().getAllCellInfo(); 2552 } catch (RemoteException ex) { 2553 return null; 2554 } catch (NullPointerException ex) { 2555 return null; 2556 } 2557 } 2558 2559 /** 2560 * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged 2561 * PhoneStateListener.onCellInfoChanged} will be invoked. 2562 *<p> 2563 * The default, 0, means invoke onCellInfoChanged when any of the reported 2564 * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue 2565 * A onCellInfoChanged. 2566 *<p> 2567 * @param rateInMillis the rate 2568 * 2569 * @hide 2570 */ 2571 public void setCellInfoListRate(int rateInMillis) { 2572 try { 2573 getITelephony().setCellInfoListRate(rateInMillis); 2574 } catch (RemoteException ex) { 2575 } catch (NullPointerException ex) { 2576 } 2577 } 2578 2579 /** 2580 * Returns the MMS user agent. 2581 */ 2582 public String getMmsUserAgent() { 2583 if (mContext == null) return null; 2584 return mContext.getResources().getString( 2585 com.android.internal.R.string.config_mms_user_agent); 2586 } 2587 2588 /** 2589 * Returns the MMS user agent profile URL. 2590 */ 2591 public String getMmsUAProfUrl() { 2592 if (mContext == null) return null; 2593 return mContext.getResources().getString( 2594 com.android.internal.R.string.config_mms_user_agent_profile_url); 2595 } 2596 2597 /** 2598 * Opens a logical channel to the ICC card. 2599 * 2600 * Input parameters equivalent to TS 27.007 AT+CCHO command. 2601 * 2602 * <p>Requires Permission: 2603 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2604 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2605 * 2606 * @param AID Application id. See ETSI 102.221 and 101.220. 2607 * @return an IccOpenLogicalChannelResponse object. 2608 */ 2609 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) { 2610 try { 2611 return getITelephony().iccOpenLogicalChannel(AID); 2612 } catch (RemoteException ex) { 2613 } catch (NullPointerException ex) { 2614 } 2615 return null; 2616 } 2617 2618 /** 2619 * Closes a previously opened logical channel to the ICC card. 2620 * 2621 * Input parameters equivalent to TS 27.007 AT+CCHC command. 2622 * 2623 * <p>Requires Permission: 2624 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2625 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2626 * 2627 * @param channel is the channel id to be closed as retruned by a successful 2628 * iccOpenLogicalChannel. 2629 * @return true if the channel was closed successfully. 2630 */ 2631 public boolean iccCloseLogicalChannel(int channel) { 2632 try { 2633 return getITelephony().iccCloseLogicalChannel(channel); 2634 } catch (RemoteException ex) { 2635 } catch (NullPointerException ex) { 2636 } 2637 return false; 2638 } 2639 2640 /** 2641 * Transmit an APDU to the ICC card over a logical channel. 2642 * 2643 * Input parameters equivalent to TS 27.007 AT+CGLA command. 2644 * 2645 * <p>Requires Permission: 2646 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2647 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2648 * 2649 * @param channel is the channel id to be closed as returned by a successful 2650 * iccOpenLogicalChannel. 2651 * @param cla Class of the APDU command. 2652 * @param instruction Instruction of the APDU command. 2653 * @param p1 P1 value of the APDU command. 2654 * @param p2 P2 value of the APDU command. 2655 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 2656 * is sent to the SIM. 2657 * @param data Data to be sent with the APDU. 2658 * @return The APDU response from the ICC card with the status appended at 2659 * the end. 2660 */ 2661 public String iccTransmitApduLogicalChannel(int channel, int cla, 2662 int instruction, int p1, int p2, int p3, String data) { 2663 try { 2664 return getITelephony().iccTransmitApduLogicalChannel(channel, cla, 2665 instruction, p1, p2, p3, data); 2666 } catch (RemoteException ex) { 2667 } catch (NullPointerException ex) { 2668 } 2669 return ""; 2670 } 2671 2672 /** 2673 * Transmit an APDU to the ICC card over the basic channel. 2674 * 2675 * Input parameters equivalent to TS 27.007 AT+CSIM command. 2676 * 2677 * <p>Requires Permission: 2678 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2679 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2680 * 2681 * @param cla Class of the APDU command. 2682 * @param instruction Instruction of the APDU command. 2683 * @param p1 P1 value of the APDU command. 2684 * @param p2 P2 value of the APDU command. 2685 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 2686 * is sent to the SIM. 2687 * @param data Data to be sent with the APDU. 2688 * @return The APDU response from the ICC card with the status appended at 2689 * the end. 2690 */ 2691 public String iccTransmitApduBasicChannel(int cla, 2692 int instruction, int p1, int p2, int p3, String data) { 2693 try { 2694 return getITelephony().iccTransmitApduBasicChannel(cla, 2695 instruction, p1, p2, p3, data); 2696 } catch (RemoteException ex) { 2697 } catch (NullPointerException ex) { 2698 } 2699 return ""; 2700 } 2701 2702 /** 2703 * Returns the response APDU for a command APDU sent through SIM_IO. 2704 * 2705 * <p>Requires Permission: 2706 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2707 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2708 * 2709 * @param fileID 2710 * @param command 2711 * @param p1 P1 value of the APDU command. 2712 * @param p2 P2 value of the APDU command. 2713 * @param p3 P3 value of the APDU command. 2714 * @param filePath 2715 * @return The APDU response. 2716 */ 2717 public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3, 2718 String filePath) { 2719 try { 2720 return getITelephony().iccExchangeSimIO(fileID, command, p1, p2, 2721 p3, filePath); 2722 } catch (RemoteException ex) { 2723 } catch (NullPointerException ex) { 2724 } 2725 return null; 2726 } 2727 2728 /** 2729 * Send ENVELOPE to the SIM and return the response. 2730 * 2731 * <p>Requires Permission: 2732 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2733 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2734 * 2735 * @param content String containing SAT/USAT response in hexadecimal 2736 * format starting with command tag. See TS 102 223 for 2737 * details. 2738 * @return The APDU response from the ICC card in hexadecimal format 2739 * with the last 4 bytes being the status word. If the command fails, 2740 * returns an empty string. 2741 */ 2742 public String sendEnvelopeWithStatus(String content) { 2743 try { 2744 return getITelephony().sendEnvelopeWithStatus(content); 2745 } catch (RemoteException ex) { 2746 } catch (NullPointerException ex) { 2747 } 2748 return ""; 2749 } 2750 2751 /** 2752 * Read one of the NV items defined in com.android.internal.telephony.RadioNVItems. 2753 * Used for device configuration by some CDMA operators. 2754 * <p> 2755 * Requires Permission: 2756 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2757 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2758 * 2759 * @param itemID the ID of the item to read. 2760 * @return the NV item as a String, or null on any failure. 2761 * 2762 * @hide 2763 */ 2764 public String nvReadItem(int itemID) { 2765 try { 2766 return getITelephony().nvReadItem(itemID); 2767 } catch (RemoteException ex) { 2768 Rlog.e(TAG, "nvReadItem RemoteException", ex); 2769 } catch (NullPointerException ex) { 2770 Rlog.e(TAG, "nvReadItem NPE", ex); 2771 } 2772 return ""; 2773 } 2774 2775 /** 2776 * Write one of the NV items defined in com.android.internal.telephony.RadioNVItems. 2777 * Used for device configuration by some CDMA operators. 2778 * <p> 2779 * Requires Permission: 2780 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2781 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2782 * 2783 * @param itemID the ID of the item to read. 2784 * @param itemValue the value to write, as a String. 2785 * @return true on success; false on any failure. 2786 * 2787 * @hide 2788 */ 2789 public boolean nvWriteItem(int itemID, String itemValue) { 2790 try { 2791 return getITelephony().nvWriteItem(itemID, itemValue); 2792 } catch (RemoteException ex) { 2793 Rlog.e(TAG, "nvWriteItem RemoteException", ex); 2794 } catch (NullPointerException ex) { 2795 Rlog.e(TAG, "nvWriteItem NPE", ex); 2796 } 2797 return false; 2798 } 2799 2800 /** 2801 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. 2802 * Used for device configuration by some CDMA operators. 2803 * <p> 2804 * Requires Permission: 2805 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2806 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2807 * 2808 * @param preferredRoamingList byte array containing the new PRL. 2809 * @return true on success; false on any failure. 2810 * 2811 * @hide 2812 */ 2813 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { 2814 try { 2815 return getITelephony().nvWriteCdmaPrl(preferredRoamingList); 2816 } catch (RemoteException ex) { 2817 Rlog.e(TAG, "nvWriteCdmaPrl RemoteException", ex); 2818 } catch (NullPointerException ex) { 2819 Rlog.e(TAG, "nvWriteCdmaPrl NPE", ex); 2820 } 2821 return false; 2822 } 2823 2824 /** 2825 * Perform the specified type of NV config reset. The radio will be taken offline 2826 * and the device must be rebooted after the operation. Used for device 2827 * configuration by some CDMA operators. 2828 * <p> 2829 * Requires Permission: 2830 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2831 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2832 * 2833 * @param resetType reset type: 1: reload NV reset, 2: erase NV reset, 3: factory NV reset 2834 * @return true on success; false on any failure. 2835 * 2836 * @hide 2837 */ 2838 public boolean nvResetConfig(int resetType) { 2839 try { 2840 return getITelephony().nvResetConfig(resetType); 2841 } catch (RemoteException ex) { 2842 Rlog.e(TAG, "nvResetConfig RemoteException", ex); 2843 } catch (NullPointerException ex) { 2844 Rlog.e(TAG, "nvResetConfig NPE", ex); 2845 } 2846 return false; 2847 } 2848 2849 /** 2850 * Returns Default subscription. 2851 */ 2852 private static int getDefaultSubscription() { 2853 return SubscriptionManager.getDefaultSubId(); 2854 } 2855 2856 /** 2857 * Returns Default phone. 2858 */ 2859 private static int getDefaultPhone() { 2860 return SubscriptionManager.getPhoneId(SubscriptionManager.getDefaultSubId()); 2861 } 2862 2863 /** {@hide} */ 2864 public int getDefaultSim() { 2865 return SubscriptionManager.getSlotId(SubscriptionManager.getDefaultSubId()); 2866 } 2867 2868 /** 2869 * Sets the telephony property with the value specified. 2870 * 2871 * @hide 2872 */ 2873 public static void setTelephonyProperty(int phoneId, String property, String value) { 2874 String propVal = ""; 2875 String p[] = null; 2876 String prop = SystemProperties.get(property); 2877 2878 if (value == null) { 2879 value = ""; 2880 } 2881 2882 if (prop != null) { 2883 p = prop.split(","); 2884 } 2885 2886 if (!SubscriptionManager.isValidPhoneId(phoneId)) { 2887 Rlog.d(TAG, "setTelephonyProperty: invalid phoneId=" + phoneId + 2888 " property=" + property + " value: " + value + " prop=" + prop); 2889 return; 2890 } 2891 2892 for (int i = 0; i < phoneId; i++) { 2893 String str = ""; 2894 if ((p != null) && (i < p.length)) { 2895 str = p[i]; 2896 } 2897 propVal = propVal + str + ","; 2898 } 2899 2900 propVal = propVal + value; 2901 if (p != null) { 2902 for (int i = phoneId + 1; i < p.length; i++) { 2903 propVal = propVal + "," + p[i]; 2904 } 2905 } 2906 2907 if (property.length() > SystemProperties.PROP_NAME_MAX 2908 || propVal.length() > SystemProperties.PROP_VALUE_MAX) { 2909 Rlog.d(TAG, "setTelephonyProperty: property to long phoneId=" + phoneId + 2910 " property=" + property + " value: " + value + " propVal=" + propVal); 2911 return; 2912 } 2913 2914 Rlog.d(TAG, "setTelephonyProperty: success phoneId=" + phoneId + 2915 " property=" + property + " value: " + value + " propVal=" + propVal); 2916 SystemProperties.set(property, propVal); 2917 } 2918 2919 /** 2920 * Convenience function for retrieving a value from the secure settings 2921 * value list as an integer. Note that internally setting values are 2922 * always stored as strings; this function converts the string to an 2923 * integer for you. 2924 * <p> 2925 * This version does not take a default value. If the setting has not 2926 * been set, or the string value is not a number, 2927 * it throws {@link SettingNotFoundException}. 2928 * 2929 * @param cr The ContentResolver to access. 2930 * @param name The name of the setting to retrieve. 2931 * @param index The index of the list 2932 * 2933 * @throws SettingNotFoundException Thrown if a setting by the given 2934 * name can't be found or the setting value is not an integer. 2935 * 2936 * @return The value at the given index of settings. 2937 * @hide 2938 */ 2939 public static int getIntAtIndex(android.content.ContentResolver cr, 2940 String name, int index) 2941 throws android.provider.Settings.SettingNotFoundException { 2942 String v = android.provider.Settings.Global.getString(cr, name); 2943 if (v != null) { 2944 String valArray[] = v.split(","); 2945 if ((index >= 0) && (index < valArray.length) && (valArray[index] != null)) { 2946 try { 2947 return Integer.parseInt(valArray[index]); 2948 } catch (NumberFormatException e) { 2949 //Log.e(TAG, "Exception while parsing Integer: ", e); 2950 } 2951 } 2952 } 2953 throw new android.provider.Settings.SettingNotFoundException(name); 2954 } 2955 2956 /** 2957 * Convenience function for updating settings value as coma separated 2958 * integer values. This will either create a new entry in the table if the 2959 * given name does not exist, or modify the value of the existing row 2960 * with that name. Note that internally setting values are always 2961 * stored as strings, so this function converts the given value to a 2962 * string before storing it. 2963 * 2964 * @param cr The ContentResolver to access. 2965 * @param name The name of the setting to modify. 2966 * @param index The index of the list 2967 * @param value The new value for the setting to be added to the list. 2968 * @return true if the value was set, false on database errors 2969 * @hide 2970 */ 2971 public static boolean putIntAtIndex(android.content.ContentResolver cr, 2972 String name, int index, int value) { 2973 String data = ""; 2974 String valArray[] = null; 2975 String v = android.provider.Settings.Global.getString(cr, name); 2976 2977 if (index == Integer.MAX_VALUE) { 2978 throw new RuntimeException("putIntAtIndex index == MAX_VALUE index=" + index); 2979 } 2980 if (index < 0) { 2981 throw new RuntimeException("putIntAtIndex index < 0 index=" + index); 2982 } 2983 if (v != null) { 2984 valArray = v.split(","); 2985 } 2986 2987 // Copy the elements from valArray till index 2988 for (int i = 0; i < index; i++) { 2989 String str = ""; 2990 if ((valArray != null) && (i < valArray.length)) { 2991 str = valArray[i]; 2992 } 2993 data = data + str + ","; 2994 } 2995 2996 data = data + value; 2997 2998 // Copy the remaining elements from valArray if any. 2999 if (valArray != null) { 3000 for (int i = index+1; i < valArray.length; i++) { 3001 data = data + "," + valArray[i]; 3002 } 3003 } 3004 return android.provider.Settings.Global.putString(cr, name, data); 3005 } 3006 3007 /** 3008 * Gets the telephony property. 3009 * 3010 * @hide 3011 */ 3012 public static String getTelephonyProperty(int phoneId, String property, String defaultVal) { 3013 String propVal = null; 3014 String prop = SystemProperties.get(property); 3015 if ((prop != null) && (prop.length() > 0)) { 3016 String values[] = prop.split(","); 3017 if ((phoneId >= 0) && (phoneId < values.length) && (values[phoneId] != null)) { 3018 propVal = values[phoneId]; 3019 } 3020 } 3021 Rlog.d(TAG, "getTelephonyProperty: return propVal='" + propVal + "' phoneId=" + phoneId 3022 + " property='" + property + "' defaultVal='" + defaultVal + "' prop=" + prop); 3023 return propVal == null ? defaultVal : propVal; 3024 } 3025 3026 /** @hide */ 3027 public int getSimCount() { 3028 // FIXME Need to get it from Telephony Dev Controller when that gets implemented! 3029 // and then this method shouldn't be used at all! 3030 if(isMultiSimEnabled()) { 3031 return 2; 3032 } else { 3033 return 1; 3034 } 3035 } 3036 3037 /** 3038 * Returns the IMS Service Table (IST) that was loaded from the ISIM. 3039 * @return IMS Service Table or null if not present or not loaded 3040 * @hide 3041 */ 3042 public String getIsimIst() { 3043 try { 3044 return getSubscriberInfo().getIsimIst(); 3045 } catch (RemoteException ex) { 3046 return null; 3047 } catch (NullPointerException ex) { 3048 // This could happen before phone restarts due to crashing 3049 return null; 3050 } 3051 } 3052 3053 /** 3054 * Returns the IMS Proxy Call Session Control Function(PCSCF) that were loaded from the ISIM. 3055 * @return an array of PCSCF strings with one PCSCF per string, or null if 3056 * not present or not loaded 3057 * @hide 3058 */ 3059 public String[] getIsimPcscf() { 3060 try { 3061 return getSubscriberInfo().getIsimPcscf(); 3062 } catch (RemoteException ex) { 3063 return null; 3064 } catch (NullPointerException ex) { 3065 // This could happen before phone restarts due to crashing 3066 return null; 3067 } 3068 } 3069 3070 /** 3071 * Returns the response of ISIM Authetification through RIL. 3072 * Returns null if the Authentification hasn't been successed or isn't present iphonesubinfo. 3073 * @return the response of ISIM Authetification, or null if not available 3074 * @hide 3075 * @deprecated 3076 * @see getIccSimChallengeResponse with appType=PhoneConstants.APPTYPE_ISIM 3077 */ 3078 public String getIsimChallengeResponse(String nonce){ 3079 try { 3080 return getSubscriberInfo().getIsimChallengeResponse(nonce); 3081 } catch (RemoteException ex) { 3082 return null; 3083 } catch (NullPointerException ex) { 3084 // This could happen before phone restarts due to crashing 3085 return null; 3086 } 3087 } 3088 3089 /** 3090 * Returns the response of SIM Authentication through RIL. 3091 * Returns null if the Authentication hasn't been successful 3092 * @param subId subscription ID to be queried 3093 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 3094 * @param data authentication challenge data 3095 * @return the response of SIM Authentication, or null if not available 3096 * @hide 3097 */ 3098 public String getIccSimChallengeResponse(int subId, int appType, String data) { 3099 try { 3100 return getSubscriberInfo().getIccSimChallengeResponse(subId, appType, data); 3101 } catch (RemoteException ex) { 3102 return null; 3103 } catch (NullPointerException ex) { 3104 // This could happen before phone starts 3105 return null; 3106 } 3107 } 3108 3109 /** 3110 * Returns the response of SIM Authentication through RIL for the default subscription. 3111 * Returns null if the Authentication hasn't been successful 3112 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 3113 * @param data authentication challenge data 3114 * @return the response of SIM Authentication, or null if not available 3115 * @hide 3116 */ 3117 public String getIccSimChallengeResponse(int appType, String data) { 3118 return getIccSimChallengeResponse(getDefaultSubscription(), appType, data); 3119 } 3120 3121 /** 3122 * Get P-CSCF address from PCO after data connection is established or modified. 3123 * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN 3124 * @return array of P-CSCF address 3125 * @hide 3126 */ 3127 public String[] getPcscfAddress(String apnType) { 3128 try { 3129 return getITelephony().getPcscfAddress(apnType); 3130 } catch (RemoteException e) { 3131 return new String[0]; 3132 } 3133 } 3134 3135 /** 3136 * Set IMS registration state 3137 * 3138 * @param Registration state 3139 * @hide 3140 */ 3141 public void setImsRegistrationState(boolean registered) { 3142 try { 3143 getITelephony().setImsRegistrationState(registered); 3144 } catch (RemoteException e) { 3145 } 3146 } 3147 3148 /** 3149 * Get the preferred network type. 3150 * Used for device configuration by some CDMA operators. 3151 * <p> 3152 * Requires Permission: 3153 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3154 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3155 * 3156 * @return the preferred network type, defined in RILConstants.java. 3157 * @hide 3158 */ 3159 public int getPreferredNetworkType() { 3160 try { 3161 return getITelephony().getPreferredNetworkType(); 3162 } catch (RemoteException ex) { 3163 Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex); 3164 } catch (NullPointerException ex) { 3165 Rlog.e(TAG, "getPreferredNetworkType NPE", ex); 3166 } 3167 return -1; 3168 } 3169 3170 /** 3171 * Set the preferred network type. 3172 * Used for device configuration by some CDMA operators. 3173 * <p> 3174 * Requires Permission: 3175 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3176 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3177 * 3178 * @param networkType the preferred network type, defined in RILConstants.java. 3179 * @return true on success; false on any failure. 3180 * @hide 3181 */ 3182 public boolean setPreferredNetworkType(int networkType) { 3183 try { 3184 return getITelephony().setPreferredNetworkType(networkType); 3185 } catch (RemoteException ex) { 3186 Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex); 3187 } catch (NullPointerException ex) { 3188 Rlog.e(TAG, "setPreferredNetworkType NPE", ex); 3189 } 3190 return false; 3191 } 3192 3193 /** 3194 * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA. 3195 * 3196 * <p> 3197 * Requires that the calling app has carrier privileges. 3198 * @see #hasCarrierPrivileges 3199 * 3200 * @return true on success; false on any failure. 3201 */ 3202 public boolean setPreferredNetworkTypeToGlobal() { 3203 return setPreferredNetworkType(RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA); 3204 } 3205 3206 /** 3207 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning 3208 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for 3209 * tethering. 3210 * 3211 * @return 0: Not required. 1: required. 2: Not set. 3212 * @hide 3213 */ 3214 public int getTetherApnRequired() { 3215 try { 3216 return getITelephony().getTetherApnRequired(); 3217 } catch (RemoteException ex) { 3218 Rlog.e(TAG, "hasMatchedTetherApnSetting RemoteException", ex); 3219 } catch (NullPointerException ex) { 3220 Rlog.e(TAG, "hasMatchedTetherApnSetting NPE", ex); 3221 } 3222 return 2; 3223 } 3224 3225 3226 /** 3227 * Values used to return status for hasCarrierPrivileges call. 3228 */ 3229 /** @hide */ 3230 public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1; 3231 /** @hide */ 3232 public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0; 3233 /** @hide */ 3234 public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1; 3235 /** @hide */ 3236 public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2; 3237 3238 /** 3239 * Has the calling application been granted carrier privileges by the carrier. 3240 * 3241 * If any of the packages in the calling UID has carrier privileges, the 3242 * call will return true. This access is granted by the owner of the UICC 3243 * card and does not depend on the registered carrier. 3244 * 3245 * @return true if the app has carrier privileges. 3246 */ 3247 public boolean hasCarrierPrivileges() { 3248 try { 3249 return getITelephony().getCarrierPrivilegeStatus() == 3250 CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; 3251 } catch (RemoteException ex) { 3252 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 3253 } catch (NullPointerException ex) { 3254 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 3255 } 3256 return false; 3257 } 3258 3259 /** 3260 * Override the branding for the current ICCID. 3261 * 3262 * Once set, whenever the SIM is present in the device, the service 3263 * provider name (SPN) and the operator name will both be replaced by the 3264 * brand value input. To unset the value, the same function should be 3265 * called with a null brand value. 3266 * 3267 * <p>Requires that the calling app has carrier privileges. 3268 * @see #hasCarrierPrivileges 3269 * 3270 * @param brand The brand name to display/set. 3271 * @return true if the operation was executed correctly. 3272 */ 3273 public boolean setOperatorBrandOverride(String brand) { 3274 try { 3275 return getITelephony().setOperatorBrandOverride(brand); 3276 } catch (RemoteException ex) { 3277 Rlog.e(TAG, "setOperatorBrandOverride RemoteException", ex); 3278 } catch (NullPointerException ex) { 3279 Rlog.e(TAG, "setOperatorBrandOverride NPE", ex); 3280 } 3281 return false; 3282 } 3283 3284 /** 3285 * Override the roaming preference for the current ICCID. 3286 * 3287 * Using this call, the carrier app (see #hasCarrierPrivileges) can override 3288 * the platform's notion of a network operator being considered roaming or not. 3289 * The change only affects the ICCID that was active when this call was made. 3290 * 3291 * If null is passed as any of the input, the corresponding value is deleted. 3292 * 3293 * <p>Requires that the caller have carrier privilege. See #hasCarrierPrivileges. 3294 * 3295 * @param gsmRoamingList - List of MCCMNCs to be considered roaming for 3GPP RATs. 3296 * @param gsmNonRoamingList - List of MCCMNCs to be considered not roaming for 3GPP RATs. 3297 * @param cdmaRoamingList - List of SIDs to be considered roaming for 3GPP2 RATs. 3298 * @param cdmaNonRoamingList - List of SIDs to be considered not roaming for 3GPP2 RATs. 3299 * @return true if the operation was executed correctly. 3300 * 3301 * @hide 3302 */ 3303 public boolean setRoamingOverride(List<String> gsmRoamingList, 3304 List<String> gsmNonRoamingList, List<String> cdmaRoamingList, 3305 List<String> cdmaNonRoamingList) { 3306 try { 3307 return getITelephony().setRoamingOverride(gsmRoamingList, gsmNonRoamingList, 3308 cdmaRoamingList, cdmaNonRoamingList); 3309 } catch (RemoteException ex) { 3310 Rlog.e(TAG, "setRoamingOverride RemoteException", ex); 3311 } catch (NullPointerException ex) { 3312 Rlog.e(TAG, "setRoamingOverride NPE", ex); 3313 } 3314 return false; 3315 } 3316 3317 /** 3318 * Expose the rest of ITelephony to @SystemApi 3319 */ 3320 3321 /** @hide */ 3322 @SystemApi 3323 public String getCdmaMdn() { 3324 return getCdmaMdn(getDefaultSubscription()); 3325 } 3326 3327 /** @hide */ 3328 @SystemApi 3329 public String getCdmaMdn(int subId) { 3330 try { 3331 return getITelephony().getCdmaMdn(subId); 3332 } catch (RemoteException ex) { 3333 return null; 3334 } catch (NullPointerException ex) { 3335 return null; 3336 } 3337 } 3338 3339 /** @hide */ 3340 @SystemApi 3341 public String getCdmaMin() { 3342 return getCdmaMin(getDefaultSubscription()); 3343 } 3344 3345 /** @hide */ 3346 @SystemApi 3347 public String getCdmaMin(int subId) { 3348 try { 3349 return getITelephony().getCdmaMin(subId); 3350 } catch (RemoteException ex) { 3351 return null; 3352 } catch (NullPointerException ex) { 3353 return null; 3354 } 3355 } 3356 3357 /** @hide */ 3358 @SystemApi 3359 public int checkCarrierPrivilegesForPackage(String pkgname) { 3360 try { 3361 return getITelephony().checkCarrierPrivilegesForPackage(pkgname); 3362 } catch (RemoteException ex) { 3363 Rlog.e(TAG, "checkCarrierPrivilegesForPackage RemoteException", ex); 3364 } catch (NullPointerException ex) { 3365 Rlog.e(TAG, "checkCarrierPrivilegesForPackage NPE", ex); 3366 } 3367 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 3368 } 3369 3370 /** @hide */ 3371 @SystemApi 3372 public List<String> getCarrierPackageNamesForIntent(Intent intent) { 3373 try { 3374 return getITelephony().getCarrierPackageNamesForIntent(intent); 3375 } catch (RemoteException ex) { 3376 Rlog.e(TAG, "getCarrierPackageNamesForIntent RemoteException", ex); 3377 } catch (NullPointerException ex) { 3378 Rlog.e(TAG, "getCarrierPackageNamesForIntent NPE", ex); 3379 } 3380 return null; 3381 } 3382 3383 /** @hide */ 3384 @SystemApi 3385 public void dial(String number) { 3386 try { 3387 getITelephony().dial(number); 3388 } catch (RemoteException e) { 3389 Log.e(TAG, "Error calling ITelephony#dial", e); 3390 } 3391 } 3392 3393 /** @hide */ 3394 @SystemApi 3395 public void call(String callingPackage, String number) { 3396 try { 3397 getITelephony().call(callingPackage, number); 3398 } catch (RemoteException e) { 3399 Log.e(TAG, "Error calling ITelephony#call", e); 3400 } 3401 } 3402 3403 /** @hide */ 3404 @SystemApi 3405 public boolean endCall() { 3406 try { 3407 return getITelephony().endCall(); 3408 } catch (RemoteException e) { 3409 Log.e(TAG, "Error calling ITelephony#endCall", e); 3410 } 3411 return false; 3412 } 3413 3414 /** @hide */ 3415 @SystemApi 3416 public void answerRingingCall() { 3417 try { 3418 getITelephony().answerRingingCall(); 3419 } catch (RemoteException e) { 3420 Log.e(TAG, "Error calling ITelephony#answerRingingCall", e); 3421 } 3422 } 3423 3424 /** @hide */ 3425 @SystemApi 3426 public void silenceRinger() { 3427 try { 3428 getTelecomService().silenceRinger(); 3429 } catch (RemoteException e) { 3430 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e); 3431 } 3432 } 3433 3434 /** @hide */ 3435 @SystemApi 3436 public boolean isOffhook() { 3437 try { 3438 return getITelephony().isOffhook(); 3439 } catch (RemoteException e) { 3440 Log.e(TAG, "Error calling ITelephony#isOffhook", e); 3441 } 3442 return false; 3443 } 3444 3445 /** @hide */ 3446 @SystemApi 3447 public boolean isRinging() { 3448 try { 3449 return getITelephony().isRinging(); 3450 } catch (RemoteException e) { 3451 Log.e(TAG, "Error calling ITelephony#isRinging", e); 3452 } 3453 return false; 3454 } 3455 3456 /** @hide */ 3457 @SystemApi 3458 public boolean isIdle() { 3459 try { 3460 return getITelephony().isIdle(); 3461 } catch (RemoteException e) { 3462 Log.e(TAG, "Error calling ITelephony#isIdle", e); 3463 } 3464 return true; 3465 } 3466 3467 /** @hide */ 3468 @SystemApi 3469 public boolean isRadioOn() { 3470 try { 3471 return getITelephony().isRadioOn(); 3472 } catch (RemoteException e) { 3473 Log.e(TAG, "Error calling ITelephony#isRadioOn", e); 3474 } 3475 return false; 3476 } 3477 3478 /** @hide */ 3479 @SystemApi 3480 public boolean isSimPinEnabled() { 3481 try { 3482 return getITelephony().isSimPinEnabled(); 3483 } catch (RemoteException e) { 3484 Log.e(TAG, "Error calling ITelephony#isSimPinEnabled", e); 3485 } 3486 return false; 3487 } 3488 3489 /** @hide */ 3490 @SystemApi 3491 public boolean supplyPin(String pin) { 3492 try { 3493 return getITelephony().supplyPin(pin); 3494 } catch (RemoteException e) { 3495 Log.e(TAG, "Error calling ITelephony#supplyPin", e); 3496 } 3497 return false; 3498 } 3499 3500 /** @hide */ 3501 @SystemApi 3502 public boolean supplyPuk(String puk, String pin) { 3503 try { 3504 return getITelephony().supplyPuk(puk, pin); 3505 } catch (RemoteException e) { 3506 Log.e(TAG, "Error calling ITelephony#supplyPuk", e); 3507 } 3508 return false; 3509 } 3510 3511 /** @hide */ 3512 @SystemApi 3513 public int[] supplyPinReportResult(String pin) { 3514 try { 3515 return getITelephony().supplyPinReportResult(pin); 3516 } catch (RemoteException e) { 3517 Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e); 3518 } 3519 return new int[0]; 3520 } 3521 3522 /** @hide */ 3523 @SystemApi 3524 public int[] supplyPukReportResult(String puk, String pin) { 3525 try { 3526 return getITelephony().supplyPukReportResult(puk, pin); 3527 } catch (RemoteException e) { 3528 Log.e(TAG, "Error calling ITelephony#]", e); 3529 } 3530 return new int[0]; 3531 } 3532 3533 /** @hide */ 3534 @SystemApi 3535 public boolean handlePinMmi(String dialString) { 3536 try { 3537 return getITelephony().handlePinMmi(dialString); 3538 } catch (RemoteException e) { 3539 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 3540 } 3541 return false; 3542 } 3543 3544 /** @hide */ 3545 @SystemApi 3546 public boolean handlePinMmiForSubscriber(int subId, String dialString) { 3547 try { 3548 return getITelephony().handlePinMmiForSubscriber(subId, dialString); 3549 } catch (RemoteException e) { 3550 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 3551 } 3552 return false; 3553 } 3554 3555 /** @hide */ 3556 @SystemApi 3557 public void toggleRadioOnOff() { 3558 try { 3559 getITelephony().toggleRadioOnOff(); 3560 } catch (RemoteException e) { 3561 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 3562 } 3563 } 3564 3565 /** @hide */ 3566 @SystemApi 3567 public boolean setRadio(boolean turnOn) { 3568 try { 3569 return getITelephony().setRadio(turnOn); 3570 } catch (RemoteException e) { 3571 Log.e(TAG, "Error calling ITelephony#setRadio", e); 3572 } 3573 return false; 3574 } 3575 3576 /** @hide */ 3577 @SystemApi 3578 public boolean setRadioPower(boolean turnOn) { 3579 try { 3580 return getITelephony().setRadioPower(turnOn); 3581 } catch (RemoteException e) { 3582 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 3583 } 3584 return false; 3585 } 3586 3587 /** @hide */ 3588 @SystemApi 3589 public void updateServiceLocation() { 3590 try { 3591 getITelephony().updateServiceLocation(); 3592 } catch (RemoteException e) { 3593 Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e); 3594 } 3595 } 3596 3597 /** @hide */ 3598 @SystemApi 3599 public boolean enableDataConnectivity() { 3600 try { 3601 return getITelephony().enableDataConnectivity(); 3602 } catch (RemoteException e) { 3603 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 3604 } 3605 return false; 3606 } 3607 3608 /** @hide */ 3609 @SystemApi 3610 public boolean disableDataConnectivity() { 3611 try { 3612 return getITelephony().disableDataConnectivity(); 3613 } catch (RemoteException e) { 3614 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 3615 } 3616 return false; 3617 } 3618 3619 /** @hide */ 3620 @SystemApi 3621 public boolean isDataConnectivityPossible() { 3622 try { 3623 return getITelephony().isDataConnectivityPossible(); 3624 } catch (RemoteException e) { 3625 Log.e(TAG, "Error calling ITelephony#isDataConnectivityPossible", e); 3626 } 3627 return false; 3628 } 3629 3630 /** @hide */ 3631 @SystemApi 3632 public boolean needsOtaServiceProvisioning() { 3633 try { 3634 return getITelephony().needsOtaServiceProvisioning(); 3635 } catch (RemoteException e) { 3636 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 3637 } 3638 return false; 3639 } 3640 3641 /** @hide */ 3642 @SystemApi 3643 public void setDataEnabled(boolean enable) { 3644 setDataEnabled(SubscriptionManager.getDefaultDataSubId(), enable); 3645 } 3646 3647 /** @hide */ 3648 @SystemApi 3649 public void setDataEnabled(int subId, boolean enable) { 3650 try { 3651 Log.d(TAG, "setDataEnabled: enabled=" + enable); 3652 getITelephony().setDataEnabled(subId, enable); 3653 } catch (RemoteException e) { 3654 Log.e(TAG, "Error calling ITelephony#setDataEnabled", e); 3655 } 3656 } 3657 3658 /** @hide */ 3659 @SystemApi 3660 public boolean getDataEnabled() { 3661 return getDataEnabled(SubscriptionManager.getDefaultDataSubId()); 3662 } 3663 3664 /** @hide */ 3665 @SystemApi 3666 public boolean getDataEnabled(int subId) { 3667 boolean retVal = false; 3668 try { 3669 retVal = getITelephony().getDataEnabled(subId); 3670 } catch (RemoteException e) { 3671 Log.e(TAG, "Error calling ITelephony#getDataEnabled", e); 3672 } catch (NullPointerException e) { 3673 } 3674 Log.d(TAG, "getDataEnabled: retVal=" + retVal); 3675 return retVal; 3676 } 3677 3678 /** 3679 * Returns the result and response from RIL for oem request 3680 * 3681 * @param oemReq the data is sent to ril. 3682 * @param oemResp the respose data from RIL. 3683 * @return negative value request was not handled or get error 3684 * 0 request was handled succesfully, but no response data 3685 * positive value success, data length of response 3686 * @hide 3687 */ 3688 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { 3689 try { 3690 return getITelephony().invokeOemRilRequestRaw(oemReq, oemResp); 3691 } catch (RemoteException ex) { 3692 } catch (NullPointerException ex) { 3693 } 3694 return -1; 3695 } 3696 3697 /** @hide */ 3698 @SystemApi 3699 public void enableVideoCalling(boolean enable) { 3700 try { 3701 getITelephony().enableVideoCalling(enable); 3702 } catch (RemoteException e) { 3703 Log.e(TAG, "Error calling ITelephony#enableVideoCalling", e); 3704 } 3705 } 3706 3707 /** @hide */ 3708 @SystemApi 3709 public boolean isVideoCallingEnabled() { 3710 try { 3711 return getITelephony().isVideoCallingEnabled(); 3712 } catch (RemoteException e) { 3713 Log.e(TAG, "Error calling ITelephony#isVideoCallingEnabled", e); 3714 } 3715 return false; 3716 } 3717 3718 /** 3719 * This function retrieves value for setting "name+subId", and if that is not found 3720 * retrieves value for setting "name", and if that is not found uses def as default 3721 * 3722 * @hide */ 3723 public static int getIntWithSubId(ContentResolver cr, String name, int subId, int def) { 3724 return Settings.Global.getInt(cr, name + subId, Settings.Global.getInt(cr, name, def)); 3725 } 3726 3727 /** 3728 * This function retrieves value for setting "name+subId", and if that is not found 3729 * retrieves value for setting "name", and if that is not found throws 3730 * SettingNotFoundException 3731 * 3732 * @hide */ 3733 public static int getIntWithSubId(ContentResolver cr, String name, int subId) 3734 throws SettingNotFoundException { 3735 try { 3736 return Settings.Global.getInt(cr, name + subId); 3737 } catch (SettingNotFoundException e) { 3738 try { 3739 int val = Settings.Global.getInt(cr, name); 3740 Settings.Global.putInt(cr, name + subId, val); 3741 3742 /* We are now moving from 'setting' to 'setting+subId', and using the value stored 3743 * for 'setting' as default. Reset the default (since it may have a user set 3744 * value). */ 3745 int default_val = val; 3746 if (name.equals(Settings.Global.MOBILE_DATA)) { 3747 default_val = "true".equalsIgnoreCase( 3748 SystemProperties.get("ro.com.android.mobiledata", "true")) ? 1 : 0; 3749 } else if (name.equals(Settings.Global.DATA_ROAMING)) { 3750 default_val = "true".equalsIgnoreCase( 3751 SystemProperties.get("ro.com.android.dataroaming", "false")) ? 1 : 0; 3752 } 3753 3754 if (default_val != val) { 3755 Settings.Global.putInt(cr, name, default_val); 3756 } 3757 3758 return val; 3759 } catch (SettingNotFoundException exc) { 3760 throw new SettingNotFoundException(name); 3761 } 3762 } 3763 } 3764 3765 /** 3766 * Returns the IMS Registration Status 3767 * @hide 3768 */ 3769 public boolean isImsRegistered() { 3770 try { 3771 return getITelephony().isImsRegistered(); 3772 } catch (RemoteException ex) { 3773 return false; 3774 } catch (NullPointerException ex) { 3775 return false; 3776 } 3777 } 3778 3779 /** 3780 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 3781 * 3782 * @hide 3783 */ 3784 public void setSimOperatorNumeric(String numeric) { 3785 int phoneId = getDefaultPhone(); 3786 setSimOperatorNumericForPhone(phoneId, numeric); 3787 } 3788 3789 /** 3790 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 3791 * 3792 * @hide 3793 */ 3794 public void setSimOperatorNumericForPhone(int phoneId, String numeric) { 3795 setTelephonyProperty(phoneId, 3796 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, numeric); 3797 } 3798 3799 /** 3800 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 3801 * 3802 * @hide 3803 */ 3804 public void setSimOperatorName(String name) { 3805 int phoneId = getDefaultPhone(); 3806 setSimOperatorNameForPhone(phoneId, name); 3807 } 3808 3809 /** 3810 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 3811 * 3812 * @hide 3813 */ 3814 public void setSimOperatorNameForPhone(int phoneId, String name) { 3815 setTelephonyProperty(phoneId, 3816 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, name); 3817 } 3818 3819 /** 3820 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the default phone. 3821 * 3822 * @hide 3823 */ 3824 public void setSimCountryIso(String iso) { 3825 int phoneId = getDefaultPhone(); 3826 setSimCountryIsoForPhone(phoneId, iso); 3827 } 3828 3829 /** 3830 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the given phone. 3831 * 3832 * @hide 3833 */ 3834 public void setSimCountryIsoForPhone(int phoneId, String iso) { 3835 setTelephonyProperty(phoneId, 3836 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, iso); 3837 } 3838 3839 /** 3840 * Set TelephonyProperties.PROPERTY_SIM_STATE for the default phone. 3841 * 3842 * @hide 3843 */ 3844 public void setSimState(String state) { 3845 int phoneId = getDefaultPhone(); 3846 setSimStateForPhone(phoneId, state); 3847 } 3848 3849 /** 3850 * Set TelephonyProperties.PROPERTY_SIM_STATE for the given phone. 3851 * 3852 * @hide 3853 */ 3854 public void setSimStateForPhone(int phoneId, String state) { 3855 setTelephonyProperty(phoneId, 3856 TelephonyProperties.PROPERTY_SIM_STATE, state); 3857 } 3858 3859 /** 3860 * Set baseband version for the default phone. 3861 * 3862 * @param version baseband version 3863 * @hide 3864 */ 3865 public void setBasebandVersion(String version) { 3866 int phoneId = getDefaultPhone(); 3867 setBasebandVersionForPhone(phoneId, version); 3868 } 3869 3870 /** 3871 * Set baseband version by phone id. 3872 * 3873 * @param phoneId for which baseband version is set 3874 * @param version baseband version 3875 * @hide 3876 */ 3877 public void setBasebandVersionForPhone(int phoneId, String version) { 3878 if (SubscriptionManager.isValidPhoneId(phoneId)) { 3879 String prop = TelephonyProperties.PROPERTY_BASEBAND_VERSION + 3880 ((phoneId == 0) ? "" : Integer.toString(phoneId)); 3881 SystemProperties.set(prop, version); 3882 } 3883 } 3884 3885 /** 3886 * Set phone type for the default phone. 3887 * 3888 * @param type phone type 3889 * 3890 * @hide 3891 */ 3892 public void setPhoneType(int type) { 3893 int phoneId = getDefaultPhone(); 3894 setPhoneType(phoneId, type); 3895 } 3896 3897 /** 3898 * Set phone type by phone id. 3899 * 3900 * @param phoneId for which phone type is set 3901 * @param type phone type 3902 * 3903 * @hide 3904 */ 3905 public void setPhoneType(int phoneId, int type) { 3906 if (SubscriptionManager.isValidPhoneId(phoneId)) { 3907 TelephonyManager.setTelephonyProperty(phoneId, 3908 TelephonyProperties.CURRENT_ACTIVE_PHONE, String.valueOf(type)); 3909 } 3910 } 3911 3912 /** 3913 * Get OTASP number schema for the default phone. 3914 * 3915 * @param defaultValue default value 3916 * @return OTA SP number schema 3917 * 3918 * @hide 3919 */ 3920 public String getOtaSpNumberSchema(String defaultValue) { 3921 int phoneId = getDefaultPhone(); 3922 return getOtaSpNumberSchemaForPhone(phoneId, defaultValue); 3923 } 3924 3925 /** 3926 * Get OTASP number schema by phone id. 3927 * 3928 * @param phoneId for which OTA SP number schema is get 3929 * @param defaultValue default value 3930 * @return OTA SP number schema 3931 * 3932 * @hide 3933 */ 3934 public String getOtaSpNumberSchemaForPhone(int phoneId, String defaultValue) { 3935 if (SubscriptionManager.isValidPhoneId(phoneId)) { 3936 return TelephonyManager.getTelephonyProperty(phoneId, 3937 TelephonyProperties.PROPERTY_OTASP_NUM_SCHEMA, defaultValue); 3938 } 3939 3940 return defaultValue; 3941 } 3942 3943 /** 3944 * Get SMS receive capable from system property for the default phone. 3945 * 3946 * @param defaultValue default value 3947 * @return SMS receive capable 3948 * 3949 * @hide 3950 */ 3951 public boolean getSmsReceiveCapable(boolean defaultValue) { 3952 int phoneId = getDefaultPhone(); 3953 return getSmsReceiveCapableForPhone(phoneId, defaultValue); 3954 } 3955 3956 /** 3957 * Get SMS receive capable from system property by phone id. 3958 * 3959 * @param phoneId for which SMS receive capable is get 3960 * @param defaultValue default value 3961 * @return SMS receive capable 3962 * 3963 * @hide 3964 */ 3965 public boolean getSmsReceiveCapableForPhone(int phoneId, boolean defaultValue) { 3966 if (SubscriptionManager.isValidPhoneId(phoneId)) { 3967 return Boolean.valueOf(TelephonyManager.getTelephonyProperty(phoneId, 3968 TelephonyProperties.PROPERTY_SMS_RECEIVE, String.valueOf(defaultValue))); 3969 } 3970 3971 return defaultValue; 3972 } 3973 3974 /** 3975 * Get SMS send capable from system property for the default phone. 3976 * 3977 * @param defaultValue default value 3978 * @return SMS send capable 3979 * 3980 * @hide 3981 */ 3982 public boolean getSmsSendCapable(boolean defaultValue) { 3983 int phoneId = getDefaultPhone(); 3984 return getSmsSendCapableForPhone(phoneId, defaultValue); 3985 } 3986 3987 /** 3988 * Get SMS send capable from system property by phone id. 3989 * 3990 * @param phoneId for which SMS send capable is get 3991 * @param defaultValue default value 3992 * @return SMS send capable 3993 * 3994 * @hide 3995 */ 3996 public boolean getSmsSendCapableForPhone(int phoneId, boolean defaultValue) { 3997 if (SubscriptionManager.isValidPhoneId(phoneId)) { 3998 return Boolean.valueOf(TelephonyManager.getTelephonyProperty(phoneId, 3999 TelephonyProperties.PROPERTY_SMS_SEND, String.valueOf(defaultValue))); 4000 } 4001 4002 return defaultValue; 4003 } 4004 4005 /** 4006 * Set the alphabetic name of current registered operator. 4007 * @param name the alphabetic name of current registered operator. 4008 * @hide 4009 */ 4010 public void setNetworkOperatorName(String name) { 4011 int phoneId = getDefaultPhone(); 4012 setNetworkOperatorNameForPhone(phoneId, name); 4013 } 4014 4015 /** 4016 * Set the alphabetic name of current registered operator. 4017 * @param phoneId which phone you want to set 4018 * @param name the alphabetic name of current registered operator. 4019 * @hide 4020 */ 4021 public void setNetworkOperatorNameForPhone(int phoneId, String name) { 4022 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4023 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, name); 4024 } 4025 } 4026 4027 /** 4028 * Set the numeric name (MCC+MNC) of current registered operator. 4029 * @param operator the numeric name (MCC+MNC) of current registered operator 4030 * @hide 4031 */ 4032 public void setNetworkOperatorNumeric(String numeric) { 4033 int phoneId = getDefaultPhone(); 4034 setNetworkOperatorNumericForPhone(phoneId, numeric); 4035 } 4036 4037 /** 4038 * Set the numeric name (MCC+MNC) of current registered operator. 4039 * @param phoneId for which phone type is set 4040 * @param operator the numeric name (MCC+MNC) of current registered operator 4041 * @hide 4042 */ 4043 public void setNetworkOperatorNumericForPhone(int phoneId, String numeric) { 4044 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, numeric); 4045 } 4046 4047 /** 4048 * Set roaming state of the current network, for GSM purposes. 4049 * @param isRoaming is network in romaing state or not 4050 * @hide 4051 */ 4052 public void setNetworkRoaming(boolean isRoaming) { 4053 int phoneId = getDefaultPhone(); 4054 setNetworkRoamingForPhone(phoneId, isRoaming); 4055 } 4056 4057 /** 4058 * Set roaming state of the current network, for GSM purposes. 4059 * @param phoneId which phone you want to set 4060 * @param isRoaming is network in romaing state or not 4061 * @hide 4062 */ 4063 public void setNetworkRoamingForPhone(int phoneId, boolean isRoaming) { 4064 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4065 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, 4066 isRoaming ? "true" : "false"); 4067 } 4068 } 4069 4070 /** 4071 * Set the ISO country code equivalent of the current registered 4072 * operator's MCC (Mobile Country Code). 4073 * @param iso the ISO country code equivalent of the current registered 4074 * @hide 4075 */ 4076 public void setNetworkCountryIso(String iso) { 4077 int phoneId = getDefaultPhone(); 4078 setNetworkCountryIsoForPhone(phoneId, iso); 4079 } 4080 4081 /** 4082 * Set the ISO country code equivalent of the current registered 4083 * operator's MCC (Mobile Country Code). 4084 * @param phoneId which phone you want to set 4085 * @param iso the ISO country code equivalent of the current registered 4086 * @hide 4087 */ 4088 public void setNetworkCountryIsoForPhone(int phoneId, String iso) { 4089 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4090 setTelephonyProperty(phoneId, 4091 TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, iso); 4092 } 4093 } 4094 4095 /** 4096 * Set the network type currently in use on the device for data transmission. 4097 * @param type the network type currently in use on the device for data transmission 4098 * @hide 4099 */ 4100 public void setDataNetworkType(int type) { 4101 int phoneId = getDefaultPhone(); 4102 setDataNetworkTypeForPhone(phoneId, type); 4103 } 4104 4105 /** 4106 * Set the network type currently in use on the device for data transmission. 4107 * @param phoneId which phone you want to set 4108 * @param type the network type currently in use on the device for data transmission 4109 * @hide 4110 */ 4111 public void setDataNetworkTypeForPhone(int phoneId, int type) { 4112 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4113 setTelephonyProperty(phoneId, 4114 TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE, 4115 ServiceState.rilRadioTechnologyToString(type)); 4116 } 4117 } 4118 4119 /** 4120 * Returns the subscription ID for the given phone account. 4121 * @hide 4122 */ 4123 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { 4124 int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 4125 try { 4126 ITelephony service = getITelephony(); 4127 if (service != null) { 4128 retval = service.getSubIdForPhoneAccount(phoneAccount); 4129 } 4130 } catch (RemoteException e) { 4131 } 4132 4133 return retval; 4134 } 4135} 4136