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