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