TelephonyManager.java revision 6714030083b1d8ec5b2df6dfef08034d0d30c2fe
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 PhoneStateListener#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 * This API will return valid data for registered cells on devices with 2892 * {@link android.content.pm.PackageManager#FEATURE_TELEPHONY} 2893 *<p> 2894 * @return List of CellInfo or null if info unavailable. 2895 * 2896 * <p>Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} 2897 */ 2898 public List<CellInfo> getAllCellInfo() { 2899 try { 2900 ITelephony telephony = getITelephony(); 2901 if (telephony == null) 2902 return null; 2903 return telephony.getAllCellInfo(getOpPackageName()); 2904 } catch (RemoteException ex) { 2905 return null; 2906 } catch (NullPointerException ex) { 2907 return null; 2908 } 2909 } 2910 2911 /** 2912 * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged 2913 * PhoneStateListener.onCellInfoChanged} will be invoked. 2914 *<p> 2915 * The default, 0, means invoke onCellInfoChanged when any of the reported 2916 * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue 2917 * A onCellInfoChanged. 2918 *<p> 2919 * @param rateInMillis the rate 2920 * 2921 * @hide 2922 */ 2923 public void setCellInfoListRate(int rateInMillis) { 2924 try { 2925 ITelephony telephony = getITelephony(); 2926 if (telephony != null) 2927 telephony.setCellInfoListRate(rateInMillis); 2928 } catch (RemoteException ex) { 2929 } catch (NullPointerException ex) { 2930 } 2931 } 2932 2933 /** 2934 * Returns the MMS user agent. 2935 */ 2936 public String getMmsUserAgent() { 2937 if (mContext == null) return null; 2938 return mContext.getResources().getString( 2939 com.android.internal.R.string.config_mms_user_agent); 2940 } 2941 2942 /** 2943 * Returns the MMS user agent profile URL. 2944 */ 2945 public String getMmsUAProfUrl() { 2946 if (mContext == null) return null; 2947 return mContext.getResources().getString( 2948 com.android.internal.R.string.config_mms_user_agent_profile_url); 2949 } 2950 2951 /** 2952 * Opens a logical channel to the ICC card. 2953 * 2954 * Input parameters equivalent to TS 27.007 AT+CCHO command. 2955 * 2956 * <p>Requires Permission: 2957 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2958 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2959 * 2960 * @param AID Application id. See ETSI 102.221 and 101.220. 2961 * @return an IccOpenLogicalChannelResponse object. 2962 */ 2963 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) { 2964 try { 2965 ITelephony telephony = getITelephony(); 2966 if (telephony != null) 2967 return telephony.iccOpenLogicalChannel(AID); 2968 } catch (RemoteException ex) { 2969 } catch (NullPointerException ex) { 2970 } 2971 return null; 2972 } 2973 2974 /** 2975 * Closes a previously opened logical channel to the ICC card. 2976 * 2977 * Input parameters equivalent to TS 27.007 AT+CCHC command. 2978 * 2979 * <p>Requires Permission: 2980 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2981 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2982 * 2983 * @param channel is the channel id to be closed as retruned by a successful 2984 * iccOpenLogicalChannel. 2985 * @return true if the channel was closed successfully. 2986 */ 2987 public boolean iccCloseLogicalChannel(int channel) { 2988 try { 2989 ITelephony telephony = getITelephony(); 2990 if (telephony != null) 2991 return telephony.iccCloseLogicalChannel(channel); 2992 } catch (RemoteException ex) { 2993 } catch (NullPointerException ex) { 2994 } 2995 return false; 2996 } 2997 2998 /** 2999 * Transmit an APDU to the ICC card over a logical channel. 3000 * 3001 * Input parameters equivalent to TS 27.007 AT+CGLA command. 3002 * 3003 * <p>Requires Permission: 3004 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3005 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3006 * 3007 * @param channel is the channel id to be closed as returned by a successful 3008 * iccOpenLogicalChannel. 3009 * @param cla Class of the APDU command. 3010 * @param instruction Instruction of the APDU command. 3011 * @param p1 P1 value of the APDU command. 3012 * @param p2 P2 value of the APDU command. 3013 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 3014 * is sent to the SIM. 3015 * @param data Data to be sent with the APDU. 3016 * @return The APDU response from the ICC card with the status appended at 3017 * the end. 3018 */ 3019 public String iccTransmitApduLogicalChannel(int channel, int cla, 3020 int instruction, int p1, int p2, int p3, String data) { 3021 try { 3022 ITelephony telephony = getITelephony(); 3023 if (telephony != null) 3024 return telephony.iccTransmitApduLogicalChannel(channel, cla, 3025 instruction, p1, p2, p3, data); 3026 } catch (RemoteException ex) { 3027 } catch (NullPointerException ex) { 3028 } 3029 return ""; 3030 } 3031 3032 /** 3033 * Transmit an APDU to the ICC card over the basic channel. 3034 * 3035 * Input parameters equivalent to TS 27.007 AT+CSIM command. 3036 * 3037 * <p>Requires Permission: 3038 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3039 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3040 * 3041 * @param cla Class of the APDU command. 3042 * @param instruction Instruction of the APDU command. 3043 * @param p1 P1 value of the APDU command. 3044 * @param p2 P2 value of the APDU command. 3045 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 3046 * is sent to the SIM. 3047 * @param data Data to be sent with the APDU. 3048 * @return The APDU response from the ICC card with the status appended at 3049 * the end. 3050 */ 3051 public String iccTransmitApduBasicChannel(int cla, 3052 int instruction, int p1, int p2, int p3, String data) { 3053 try { 3054 ITelephony telephony = getITelephony(); 3055 if (telephony != null) 3056 return telephony.iccTransmitApduBasicChannel(cla, 3057 instruction, p1, p2, p3, data); 3058 } catch (RemoteException ex) { 3059 } catch (NullPointerException ex) { 3060 } 3061 return ""; 3062 } 3063 3064 /** 3065 * Returns the response APDU for a command APDU sent through SIM_IO. 3066 * 3067 * <p>Requires Permission: 3068 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3069 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3070 * 3071 * @param fileID 3072 * @param command 3073 * @param p1 P1 value of the APDU command. 3074 * @param p2 P2 value of the APDU command. 3075 * @param p3 P3 value of the APDU command. 3076 * @param filePath 3077 * @return The APDU response. 3078 */ 3079 public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3, 3080 String filePath) { 3081 try { 3082 ITelephony telephony = getITelephony(); 3083 if (telephony != null) 3084 return telephony.iccExchangeSimIO(fileID, command, p1, p2, p3, filePath); 3085 } catch (RemoteException ex) { 3086 } catch (NullPointerException ex) { 3087 } 3088 return null; 3089 } 3090 3091 /** 3092 * Send ENVELOPE to the SIM and return the response. 3093 * 3094 * <p>Requires Permission: 3095 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3096 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3097 * 3098 * @param content String containing SAT/USAT response in hexadecimal 3099 * format starting with command tag. See TS 102 223 for 3100 * details. 3101 * @return The APDU response from the ICC card in hexadecimal format 3102 * with the last 4 bytes being the status word. If the command fails, 3103 * returns an empty string. 3104 */ 3105 public String sendEnvelopeWithStatus(String content) { 3106 try { 3107 ITelephony telephony = getITelephony(); 3108 if (telephony != null) 3109 return telephony.sendEnvelopeWithStatus(content); 3110 } catch (RemoteException ex) { 3111 } catch (NullPointerException ex) { 3112 } 3113 return ""; 3114 } 3115 3116 /** 3117 * Read one of the NV items defined in com.android.internal.telephony.RadioNVItems. 3118 * Used for device configuration by some CDMA operators. 3119 * <p> 3120 * Requires Permission: 3121 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3122 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3123 * 3124 * @param itemID the ID of the item to read. 3125 * @return the NV item as a String, or null on any failure. 3126 * 3127 * @hide 3128 */ 3129 public String nvReadItem(int itemID) { 3130 try { 3131 ITelephony telephony = getITelephony(); 3132 if (telephony != null) 3133 return telephony.nvReadItem(itemID); 3134 } catch (RemoteException ex) { 3135 Rlog.e(TAG, "nvReadItem RemoteException", ex); 3136 } catch (NullPointerException ex) { 3137 Rlog.e(TAG, "nvReadItem NPE", ex); 3138 } 3139 return ""; 3140 } 3141 3142 /** 3143 * Write one of the NV items defined in com.android.internal.telephony.RadioNVItems. 3144 * Used for device configuration by some CDMA operators. 3145 * <p> 3146 * Requires Permission: 3147 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3148 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3149 * 3150 * @param itemID the ID of the item to read. 3151 * @param itemValue the value to write, as a String. 3152 * @return true on success; false on any failure. 3153 * 3154 * @hide 3155 */ 3156 public boolean nvWriteItem(int itemID, String itemValue) { 3157 try { 3158 ITelephony telephony = getITelephony(); 3159 if (telephony != null) 3160 return telephony.nvWriteItem(itemID, itemValue); 3161 } catch (RemoteException ex) { 3162 Rlog.e(TAG, "nvWriteItem RemoteException", ex); 3163 } catch (NullPointerException ex) { 3164 Rlog.e(TAG, "nvWriteItem NPE", ex); 3165 } 3166 return false; 3167 } 3168 3169 /** 3170 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. 3171 * Used for device configuration by some CDMA operators. 3172 * <p> 3173 * Requires Permission: 3174 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3175 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3176 * 3177 * @param preferredRoamingList byte array containing the new PRL. 3178 * @return true on success; false on any failure. 3179 * 3180 * @hide 3181 */ 3182 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { 3183 try { 3184 ITelephony telephony = getITelephony(); 3185 if (telephony != null) 3186 return telephony.nvWriteCdmaPrl(preferredRoamingList); 3187 } catch (RemoteException ex) { 3188 Rlog.e(TAG, "nvWriteCdmaPrl RemoteException", ex); 3189 } catch (NullPointerException ex) { 3190 Rlog.e(TAG, "nvWriteCdmaPrl NPE", ex); 3191 } 3192 return false; 3193 } 3194 3195 /** 3196 * Perform the specified type of NV config reset. The radio will be taken offline 3197 * and the device must be rebooted after the operation. Used for device 3198 * configuration by some CDMA operators. 3199 * <p> 3200 * Requires Permission: 3201 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3202 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3203 * 3204 * @param resetType reset type: 1: reload NV reset, 2: erase NV reset, 3: factory NV reset 3205 * @return true on success; false on any failure. 3206 * 3207 * @hide 3208 */ 3209 public boolean nvResetConfig(int resetType) { 3210 try { 3211 ITelephony telephony = getITelephony(); 3212 if (telephony != null) 3213 return telephony.nvResetConfig(resetType); 3214 } catch (RemoteException ex) { 3215 Rlog.e(TAG, "nvResetConfig RemoteException", ex); 3216 } catch (NullPointerException ex) { 3217 Rlog.e(TAG, "nvResetConfig NPE", ex); 3218 } 3219 return false; 3220 } 3221 3222 /** 3223 * Returns Default subscription. 3224 */ 3225 private static int getDefaultSubscription() { 3226 return SubscriptionManager.getDefaultSubId(); 3227 } 3228 3229 /** 3230 * Returns Default phone. 3231 */ 3232 private static int getDefaultPhone() { 3233 return SubscriptionManager.getPhoneId(SubscriptionManager.getDefaultSubId()); 3234 } 3235 3236 /** {@hide} */ 3237 public int getDefaultSim() { 3238 return SubscriptionManager.getSlotId(SubscriptionManager.getDefaultSubId()); 3239 } 3240 3241 /** 3242 * Sets the telephony property with the value specified. 3243 * 3244 * @hide 3245 */ 3246 public static void setTelephonyProperty(int phoneId, String property, String value) { 3247 String propVal = ""; 3248 String p[] = null; 3249 String prop = SystemProperties.get(property); 3250 3251 if (value == null) { 3252 value = ""; 3253 } 3254 3255 if (prop != null) { 3256 p = prop.split(","); 3257 } 3258 3259 if (!SubscriptionManager.isValidPhoneId(phoneId)) { 3260 Rlog.d(TAG, "setTelephonyProperty: invalid phoneId=" + phoneId + 3261 " property=" + property + " value: " + value + " prop=" + prop); 3262 return; 3263 } 3264 3265 for (int i = 0; i < phoneId; i++) { 3266 String str = ""; 3267 if ((p != null) && (i < p.length)) { 3268 str = p[i]; 3269 } 3270 propVal = propVal + str + ","; 3271 } 3272 3273 propVal = propVal + value; 3274 if (p != null) { 3275 for (int i = phoneId + 1; i < p.length; i++) { 3276 propVal = propVal + "," + p[i]; 3277 } 3278 } 3279 3280 if (property.length() > SystemProperties.PROP_NAME_MAX 3281 || propVal.length() > SystemProperties.PROP_VALUE_MAX) { 3282 Rlog.d(TAG, "setTelephonyProperty: property to long phoneId=" + phoneId + 3283 " property=" + property + " value: " + value + " propVal=" + propVal); 3284 return; 3285 } 3286 3287 Rlog.d(TAG, "setTelephonyProperty: success phoneId=" + phoneId + 3288 " property=" + property + " value: " + value + " propVal=" + propVal); 3289 SystemProperties.set(property, propVal); 3290 } 3291 3292 /** 3293 * Convenience function for retrieving a value from the secure settings 3294 * value list as an integer. Note that internally setting values are 3295 * always stored as strings; this function converts the string to an 3296 * integer for you. 3297 * <p> 3298 * This version does not take a default value. If the setting has not 3299 * been set, or the string value is not a number, 3300 * it throws {@link SettingNotFoundException}. 3301 * 3302 * @param cr The ContentResolver to access. 3303 * @param name The name of the setting to retrieve. 3304 * @param index The index of the list 3305 * 3306 * @throws SettingNotFoundException Thrown if a setting by the given 3307 * name can't be found or the setting value is not an integer. 3308 * 3309 * @return The value at the given index of settings. 3310 * @hide 3311 */ 3312 public static int getIntAtIndex(android.content.ContentResolver cr, 3313 String name, int index) 3314 throws android.provider.Settings.SettingNotFoundException { 3315 String v = android.provider.Settings.Global.getString(cr, name); 3316 if (v != null) { 3317 String valArray[] = v.split(","); 3318 if ((index >= 0) && (index < valArray.length) && (valArray[index] != null)) { 3319 try { 3320 return Integer.parseInt(valArray[index]); 3321 } catch (NumberFormatException e) { 3322 //Log.e(TAG, "Exception while parsing Integer: ", e); 3323 } 3324 } 3325 } 3326 throw new android.provider.Settings.SettingNotFoundException(name); 3327 } 3328 3329 /** 3330 * Convenience function for updating settings value as coma separated 3331 * integer values. This will either create a new entry in the table if the 3332 * given name does not exist, or modify the value of the existing row 3333 * with that name. Note that internally setting values are always 3334 * stored as strings, so this function converts the given value to a 3335 * string before storing it. 3336 * 3337 * @param cr The ContentResolver to access. 3338 * @param name The name of the setting to modify. 3339 * @param index The index of the list 3340 * @param value The new value for the setting to be added to the list. 3341 * @return true if the value was set, false on database errors 3342 * @hide 3343 */ 3344 public static boolean putIntAtIndex(android.content.ContentResolver cr, 3345 String name, int index, int value) { 3346 String data = ""; 3347 String valArray[] = null; 3348 String v = android.provider.Settings.Global.getString(cr, name); 3349 3350 if (index == Integer.MAX_VALUE) { 3351 throw new RuntimeException("putIntAtIndex index == MAX_VALUE index=" + index); 3352 } 3353 if (index < 0) { 3354 throw new RuntimeException("putIntAtIndex index < 0 index=" + index); 3355 } 3356 if (v != null) { 3357 valArray = v.split(","); 3358 } 3359 3360 // Copy the elements from valArray till index 3361 for (int i = 0; i < index; i++) { 3362 String str = ""; 3363 if ((valArray != null) && (i < valArray.length)) { 3364 str = valArray[i]; 3365 } 3366 data = data + str + ","; 3367 } 3368 3369 data = data + value; 3370 3371 // Copy the remaining elements from valArray if any. 3372 if (valArray != null) { 3373 for (int i = index+1; i < valArray.length; i++) { 3374 data = data + "," + valArray[i]; 3375 } 3376 } 3377 return android.provider.Settings.Global.putString(cr, name, data); 3378 } 3379 3380 /** 3381 * Gets the telephony property. 3382 * 3383 * @hide 3384 */ 3385 public static String getTelephonyProperty(int phoneId, String property, String defaultVal) { 3386 String propVal = null; 3387 String prop = SystemProperties.get(property); 3388 if ((prop != null) && (prop.length() > 0)) { 3389 String values[] = prop.split(","); 3390 if ((phoneId >= 0) && (phoneId < values.length) && (values[phoneId] != null)) { 3391 propVal = values[phoneId]; 3392 } 3393 } 3394 return propVal == null ? defaultVal : propVal; 3395 } 3396 3397 /** @hide */ 3398 public int getSimCount() { 3399 // FIXME Need to get it from Telephony Dev Controller when that gets implemented! 3400 // and then this method shouldn't be used at all! 3401 if(isMultiSimEnabled()) { 3402 return 2; 3403 } else { 3404 return 1; 3405 } 3406 } 3407 3408 /** 3409 * Returns the IMS Service Table (IST) that was loaded from the ISIM. 3410 * @return IMS Service Table or null if not present or not loaded 3411 * @hide 3412 */ 3413 public String getIsimIst() { 3414 try { 3415 IPhoneSubInfo info = getSubscriberInfo(); 3416 if (info == null) 3417 return null; 3418 return info.getIsimIst(); 3419 } catch (RemoteException ex) { 3420 return null; 3421 } catch (NullPointerException ex) { 3422 // This could happen before phone restarts due to crashing 3423 return null; 3424 } 3425 } 3426 3427 /** 3428 * Returns the IMS Proxy Call Session Control Function(PCSCF) that were loaded from the ISIM. 3429 * @return an array of PCSCF strings with one PCSCF per string, or null if 3430 * not present or not loaded 3431 * @hide 3432 */ 3433 public String[] getIsimPcscf() { 3434 try { 3435 IPhoneSubInfo info = getSubscriberInfo(); 3436 if (info == null) 3437 return null; 3438 return info.getIsimPcscf(); 3439 } catch (RemoteException ex) { 3440 return null; 3441 } catch (NullPointerException ex) { 3442 // This could happen before phone restarts due to crashing 3443 return null; 3444 } 3445 } 3446 3447 /** 3448 * Returns the response of ISIM Authetification through RIL. 3449 * Returns null if the Authentification hasn't been successed or isn't present iphonesubinfo. 3450 * @return the response of ISIM Authetification, or null if not available 3451 * @hide 3452 * @deprecated 3453 * @see getIccSimChallengeResponse with appType=PhoneConstants.APPTYPE_ISIM 3454 */ 3455 public String getIsimChallengeResponse(String nonce){ 3456 try { 3457 IPhoneSubInfo info = getSubscriberInfo(); 3458 if (info == null) 3459 return null; 3460 return info.getIsimChallengeResponse(nonce); 3461 } catch (RemoteException ex) { 3462 return null; 3463 } catch (NullPointerException ex) { 3464 // This could happen before phone restarts due to crashing 3465 return null; 3466 } 3467 } 3468 3469 /** 3470 * Returns the response of SIM Authentication through RIL. 3471 * Returns null if the Authentication hasn't been successful 3472 * @param subId subscription ID to be queried 3473 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 3474 * @param data authentication challenge data 3475 * @return the response of SIM Authentication, or null if not available 3476 * @hide 3477 */ 3478 public String getIccSimChallengeResponse(int subId, int appType, String data) { 3479 try { 3480 IPhoneSubInfo info = getSubscriberInfo(); 3481 if (info == null) 3482 return null; 3483 return info.getIccSimChallengeResponse(subId, appType, data); 3484 } catch (RemoteException ex) { 3485 return null; 3486 } catch (NullPointerException ex) { 3487 // This could happen before phone starts 3488 return null; 3489 } 3490 } 3491 3492 /** 3493 * Returns the response of SIM Authentication through RIL for the default subscription. 3494 * Returns null if the Authentication hasn't been successful 3495 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 3496 * @param data authentication challenge data 3497 * @return the response of SIM Authentication, or null if not available 3498 * @hide 3499 */ 3500 public String getIccSimChallengeResponse(int appType, String data) { 3501 return getIccSimChallengeResponse(getDefaultSubscription(), appType, data); 3502 } 3503 3504 /** 3505 * Get P-CSCF address from PCO after data connection is established or modified. 3506 * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN 3507 * @return array of P-CSCF address 3508 * @hide 3509 */ 3510 public String[] getPcscfAddress(String apnType) { 3511 try { 3512 ITelephony telephony = getITelephony(); 3513 if (telephony == null) 3514 return new String[0]; 3515 return telephony.getPcscfAddress(apnType, getOpPackageName()); 3516 } catch (RemoteException e) { 3517 return new String[0]; 3518 } 3519 } 3520 3521 /** 3522 * Set IMS registration state 3523 * 3524 * @param Registration state 3525 * @hide 3526 */ 3527 public void setImsRegistrationState(boolean registered) { 3528 try { 3529 ITelephony telephony = getITelephony(); 3530 if (telephony != null) 3531 telephony.setImsRegistrationState(registered); 3532 } catch (RemoteException e) { 3533 } 3534 } 3535 3536 /** 3537 * Get the preferred network type. 3538 * Used for device configuration by some CDMA operators. 3539 * <p> 3540 * Requires Permission: 3541 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3542 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3543 * 3544 * @return the preferred network type, defined in RILConstants.java. 3545 * @hide 3546 */ 3547 public int getPreferredNetworkType(int subId) { 3548 try { 3549 ITelephony telephony = getITelephony(); 3550 if (telephony != null) 3551 return telephony.getPreferredNetworkType(subId); 3552 } catch (RemoteException ex) { 3553 Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex); 3554 } catch (NullPointerException ex) { 3555 Rlog.e(TAG, "getPreferredNetworkType NPE", ex); 3556 } 3557 return -1; 3558 } 3559 3560 /** 3561 * Sets the network selection mode to automatic. 3562 * <p> 3563 * Requires Permission: 3564 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3565 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3566 * 3567 * @hide 3568 */ 3569 public void setNetworkSelectionModeAutomatic(int subId) { 3570 try { 3571 ITelephony telephony = getITelephony(); 3572 if (telephony != null) 3573 telephony.setNetworkSelectionModeAutomatic(subId); 3574 } catch (RemoteException ex) { 3575 Rlog.e(TAG, "setNetworkSelectionModeAutomatic RemoteException", ex); 3576 } catch (NullPointerException ex) { 3577 Rlog.e(TAG, "setNetworkSelectionModeAutomatic NPE", ex); 3578 } 3579 } 3580 3581 /** 3582 * Perform a radio scan and return the list of avialble networks. 3583 * 3584 * The return value is a list of the OperatorInfo of the networks found. Note that this 3585 * scan can take a long time (sometimes minutes) to happen. 3586 * 3587 * <p> 3588 * Requires Permission: 3589 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3590 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3591 * 3592 * @hide 3593 */ 3594 public CellNetworkScanResult getCellNetworkScanResults(int subId) { 3595 try { 3596 ITelephony telephony = getITelephony(); 3597 if (telephony != null) 3598 return telephony.getCellNetworkScanResults(subId); 3599 } catch (RemoteException ex) { 3600 Rlog.e(TAG, "getCellNetworkScanResults RemoteException", ex); 3601 } catch (NullPointerException ex) { 3602 Rlog.e(TAG, "getCellNetworkScanResults NPE", ex); 3603 } 3604 return null; 3605 } 3606 3607 /** 3608 * Ask the radio to connect to the input network and change selection mode to manual. 3609 * 3610 * <p> 3611 * Requires Permission: 3612 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3613 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3614 * 3615 * @hide 3616 */ 3617 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator, 3618 boolean persistSelection) { 3619 try { 3620 ITelephony telephony = getITelephony(); 3621 if (telephony != null) 3622 return telephony.setNetworkSelectionModeManual(subId, operator, persistSelection); 3623 } catch (RemoteException ex) { 3624 Rlog.e(TAG, "setNetworkSelectionModeManual RemoteException", ex); 3625 } catch (NullPointerException ex) { 3626 Rlog.e(TAG, "setNetworkSelectionModeManual NPE", ex); 3627 } 3628 return false; 3629 } 3630 3631 /** 3632 * Set the preferred network type. 3633 * Used for device configuration by some CDMA operators. 3634 * <p> 3635 * Requires Permission: 3636 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3637 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3638 * 3639 * @param subId the id of the subscription to set the preferred network type for. 3640 * @param networkType the preferred network type, defined in RILConstants.java. 3641 * @return true on success; false on any failure. 3642 * @hide 3643 */ 3644 public boolean setPreferredNetworkType(int subId, int networkType) { 3645 try { 3646 ITelephony telephony = getITelephony(); 3647 if (telephony != null) 3648 return telephony.setPreferredNetworkType(subId, networkType); 3649 } catch (RemoteException ex) { 3650 Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex); 3651 } catch (NullPointerException ex) { 3652 Rlog.e(TAG, "setPreferredNetworkType NPE", ex); 3653 } 3654 return false; 3655 } 3656 3657 /** 3658 * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA. 3659 * 3660 * <p> 3661 * Requires that the calling app has carrier privileges. 3662 * @see #hasCarrierPrivileges 3663 * 3664 * @return true on success; false on any failure. 3665 */ 3666 public boolean setPreferredNetworkTypeToGlobal() { 3667 return setPreferredNetworkType(getDefaultSubscription(), 3668 RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA); 3669 } 3670 3671 /** 3672 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning 3673 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for 3674 * tethering. 3675 * 3676 * @return 0: Not required. 1: required. 2: Not set. 3677 * @hide 3678 */ 3679 public int getTetherApnRequired() { 3680 try { 3681 ITelephony telephony = getITelephony(); 3682 if (telephony != null) 3683 return telephony.getTetherApnRequired(); 3684 } catch (RemoteException ex) { 3685 Rlog.e(TAG, "hasMatchedTetherApnSetting RemoteException", ex); 3686 } catch (NullPointerException ex) { 3687 Rlog.e(TAG, "hasMatchedTetherApnSetting NPE", ex); 3688 } 3689 return 2; 3690 } 3691 3692 3693 /** 3694 * Values used to return status for hasCarrierPrivileges call. 3695 */ 3696 /** @hide */ @SystemApi 3697 public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1; 3698 /** @hide */ @SystemApi 3699 public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0; 3700 /** @hide */ @SystemApi 3701 public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1; 3702 /** @hide */ @SystemApi 3703 public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2; 3704 3705 /** 3706 * Has the calling application been granted carrier privileges by the carrier. 3707 * 3708 * If any of the packages in the calling UID has carrier privileges, the 3709 * call will return true. This access is granted by the owner of the UICC 3710 * card and does not depend on the registered carrier. 3711 * 3712 * @return true if the app has carrier privileges. 3713 */ 3714 public boolean hasCarrierPrivileges() { 3715 try { 3716 ITelephony telephony = getITelephony(); 3717 if (telephony != null) 3718 return telephony.getCarrierPrivilegeStatus() == CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; 3719 } catch (RemoteException ex) { 3720 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 3721 } catch (NullPointerException ex) { 3722 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 3723 } 3724 return false; 3725 } 3726 3727 /** 3728 * Override the branding for the current ICCID. 3729 * 3730 * Once set, whenever the SIM is present in the device, the service 3731 * provider name (SPN) and the operator name will both be replaced by the 3732 * brand value input. To unset the value, the same function should be 3733 * called with a null brand value. 3734 * 3735 * <p>Requires that the calling app has carrier privileges. 3736 * @see #hasCarrierPrivileges 3737 * 3738 * @param brand The brand name to display/set. 3739 * @return true if the operation was executed correctly. 3740 */ 3741 public boolean setOperatorBrandOverride(String brand) { 3742 try { 3743 ITelephony telephony = getITelephony(); 3744 if (telephony != null) 3745 return telephony.setOperatorBrandOverride(brand); 3746 } catch (RemoteException ex) { 3747 Rlog.e(TAG, "setOperatorBrandOverride RemoteException", ex); 3748 } catch (NullPointerException ex) { 3749 Rlog.e(TAG, "setOperatorBrandOverride NPE", ex); 3750 } 3751 return false; 3752 } 3753 3754 /** 3755 * Override the roaming preference for the current ICCID. 3756 * 3757 * Using this call, the carrier app (see #hasCarrierPrivileges) can override 3758 * the platform's notion of a network operator being considered roaming or not. 3759 * The change only affects the ICCID that was active when this call was made. 3760 * 3761 * If null is passed as any of the input, the corresponding value is deleted. 3762 * 3763 * <p>Requires that the caller have carrier privilege. See #hasCarrierPrivileges. 3764 * 3765 * @param gsmRoamingList - List of MCCMNCs to be considered roaming for 3GPP RATs. 3766 * @param gsmNonRoamingList - List of MCCMNCs to be considered not roaming for 3GPP RATs. 3767 * @param cdmaRoamingList - List of SIDs to be considered roaming for 3GPP2 RATs. 3768 * @param cdmaNonRoamingList - List of SIDs to be considered not roaming for 3GPP2 RATs. 3769 * @return true if the operation was executed correctly. 3770 * 3771 * @hide 3772 */ 3773 public boolean setRoamingOverride(List<String> gsmRoamingList, 3774 List<String> gsmNonRoamingList, List<String> cdmaRoamingList, 3775 List<String> cdmaNonRoamingList) { 3776 try { 3777 ITelephony telephony = getITelephony(); 3778 if (telephony != null) 3779 return telephony.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, 3780 cdmaRoamingList, cdmaNonRoamingList); 3781 } catch (RemoteException ex) { 3782 Rlog.e(TAG, "setRoamingOverride RemoteException", ex); 3783 } catch (NullPointerException ex) { 3784 Rlog.e(TAG, "setRoamingOverride NPE", ex); 3785 } 3786 return false; 3787 } 3788 3789 /** 3790 * Expose the rest of ITelephony to @SystemApi 3791 */ 3792 3793 /** @hide */ 3794 @SystemApi 3795 public String getCdmaMdn() { 3796 return getCdmaMdn(getDefaultSubscription()); 3797 } 3798 3799 /** @hide */ 3800 @SystemApi 3801 public String getCdmaMdn(int subId) { 3802 try { 3803 ITelephony telephony = getITelephony(); 3804 if (telephony == null) 3805 return null; 3806 return telephony.getCdmaMdn(subId); 3807 } catch (RemoteException ex) { 3808 return null; 3809 } catch (NullPointerException ex) { 3810 return null; 3811 } 3812 } 3813 3814 /** @hide */ 3815 @SystemApi 3816 public String getCdmaMin() { 3817 return getCdmaMin(getDefaultSubscription()); 3818 } 3819 3820 /** @hide */ 3821 @SystemApi 3822 public String getCdmaMin(int subId) { 3823 try { 3824 ITelephony telephony = getITelephony(); 3825 if (telephony == null) 3826 return null; 3827 return telephony.getCdmaMin(subId); 3828 } catch (RemoteException ex) { 3829 return null; 3830 } catch (NullPointerException ex) { 3831 return null; 3832 } 3833 } 3834 3835 /** @hide */ 3836 @SystemApi 3837 public int checkCarrierPrivilegesForPackage(String pkgName) { 3838 try { 3839 ITelephony telephony = getITelephony(); 3840 if (telephony != null) 3841 return telephony.checkCarrierPrivilegesForPackage(pkgName); 3842 } catch (RemoteException ex) { 3843 Rlog.e(TAG, "checkCarrierPrivilegesForPackage RemoteException", ex); 3844 } catch (NullPointerException ex) { 3845 Rlog.e(TAG, "checkCarrierPrivilegesForPackage NPE", ex); 3846 } 3847 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 3848 } 3849 3850 /** @hide */ 3851 @SystemApi 3852 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { 3853 try { 3854 ITelephony telephony = getITelephony(); 3855 if (telephony != null) 3856 return telephony.checkCarrierPrivilegesForPackageAnyPhone(pkgName); 3857 } catch (RemoteException ex) { 3858 Rlog.e(TAG, "checkCarrierPrivilegesForPackageAnyPhone RemoteException", ex); 3859 } catch (NullPointerException ex) { 3860 Rlog.e(TAG, "checkCarrierPrivilegesForPackageAnyPhone NPE", ex); 3861 } 3862 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 3863 } 3864 3865 /** @hide */ 3866 @SystemApi 3867 public List<String> getCarrierPackageNamesForIntent(Intent intent) { 3868 return getCarrierPackageNamesForIntentAndPhone(intent, getDefaultPhone()); 3869 } 3870 3871 /** @hide */ 3872 @SystemApi 3873 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { 3874 try { 3875 ITelephony telephony = getITelephony(); 3876 if (telephony != null) 3877 return telephony.getCarrierPackageNamesForIntentAndPhone(intent, phoneId); 3878 } catch (RemoteException ex) { 3879 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone RemoteException", ex); 3880 } catch (NullPointerException ex) { 3881 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone NPE", ex); 3882 } 3883 return null; 3884 } 3885 3886 /** @hide */ 3887 @SystemApi 3888 public void dial(String number) { 3889 try { 3890 ITelephony telephony = getITelephony(); 3891 if (telephony != null) 3892 telephony.dial(number); 3893 } catch (RemoteException e) { 3894 Log.e(TAG, "Error calling ITelephony#dial", e); 3895 } 3896 } 3897 3898 /** @hide */ 3899 @SystemApi 3900 public void call(String callingPackage, String number) { 3901 try { 3902 ITelephony telephony = getITelephony(); 3903 if (telephony != null) 3904 telephony.call(callingPackage, number); 3905 } catch (RemoteException e) { 3906 Log.e(TAG, "Error calling ITelephony#call", e); 3907 } 3908 } 3909 3910 /** @hide */ 3911 @SystemApi 3912 public boolean endCall() { 3913 try { 3914 ITelephony telephony = getITelephony(); 3915 if (telephony != null) 3916 return telephony.endCall(); 3917 } catch (RemoteException e) { 3918 Log.e(TAG, "Error calling ITelephony#endCall", e); 3919 } 3920 return false; 3921 } 3922 3923 /** @hide */ 3924 @SystemApi 3925 public void answerRingingCall() { 3926 try { 3927 ITelephony telephony = getITelephony(); 3928 if (telephony != null) 3929 telephony.answerRingingCall(); 3930 } catch (RemoteException e) { 3931 Log.e(TAG, "Error calling ITelephony#answerRingingCall", e); 3932 } 3933 } 3934 3935 /** @hide */ 3936 @SystemApi 3937 public void silenceRinger() { 3938 try { 3939 getTelecomService().silenceRinger(getOpPackageName()); 3940 } catch (RemoteException e) { 3941 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e); 3942 } 3943 } 3944 3945 /** @hide */ 3946 @SystemApi 3947 public boolean isOffhook() { 3948 try { 3949 ITelephony telephony = getITelephony(); 3950 if (telephony != null) 3951 return telephony.isOffhook(getOpPackageName()); 3952 } catch (RemoteException e) { 3953 Log.e(TAG, "Error calling ITelephony#isOffhook", e); 3954 } 3955 return false; 3956 } 3957 3958 /** @hide */ 3959 @SystemApi 3960 public boolean isRinging() { 3961 try { 3962 ITelephony telephony = getITelephony(); 3963 if (telephony != null) 3964 return telephony.isRinging(getOpPackageName()); 3965 } catch (RemoteException e) { 3966 Log.e(TAG, "Error calling ITelephony#isRinging", e); 3967 } 3968 return false; 3969 } 3970 3971 /** @hide */ 3972 @SystemApi 3973 public boolean isIdle() { 3974 try { 3975 ITelephony telephony = getITelephony(); 3976 if (telephony != null) 3977 return telephony.isIdle(getOpPackageName()); 3978 } catch (RemoteException e) { 3979 Log.e(TAG, "Error calling ITelephony#isIdle", e); 3980 } 3981 return true; 3982 } 3983 3984 /** @hide */ 3985 @SystemApi 3986 public boolean isRadioOn() { 3987 try { 3988 ITelephony telephony = getITelephony(); 3989 if (telephony != null) 3990 return telephony.isRadioOn(getOpPackageName()); 3991 } catch (RemoteException e) { 3992 Log.e(TAG, "Error calling ITelephony#isRadioOn", e); 3993 } 3994 return false; 3995 } 3996 3997 /** @hide */ 3998 @SystemApi 3999 public boolean isSimPinEnabled() { 4000 try { 4001 ITelephony telephony = getITelephony(); 4002 if (telephony != null) 4003 return telephony.isSimPinEnabled(getOpPackageName()); 4004 } catch (RemoteException e) { 4005 Log.e(TAG, "Error calling ITelephony#isSimPinEnabled", e); 4006 } 4007 return false; 4008 } 4009 4010 /** @hide */ 4011 @SystemApi 4012 public boolean supplyPin(String pin) { 4013 try { 4014 ITelephony telephony = getITelephony(); 4015 if (telephony != null) 4016 return telephony.supplyPin(pin); 4017 } catch (RemoteException e) { 4018 Log.e(TAG, "Error calling ITelephony#supplyPin", e); 4019 } 4020 return false; 4021 } 4022 4023 /** @hide */ 4024 @SystemApi 4025 public boolean supplyPuk(String puk, String pin) { 4026 try { 4027 ITelephony telephony = getITelephony(); 4028 if (telephony != null) 4029 return telephony.supplyPuk(puk, pin); 4030 } catch (RemoteException e) { 4031 Log.e(TAG, "Error calling ITelephony#supplyPuk", e); 4032 } 4033 return false; 4034 } 4035 4036 /** @hide */ 4037 @SystemApi 4038 public int[] supplyPinReportResult(String pin) { 4039 try { 4040 ITelephony telephony = getITelephony(); 4041 if (telephony != null) 4042 return telephony.supplyPinReportResult(pin); 4043 } catch (RemoteException e) { 4044 Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e); 4045 } 4046 return new int[0]; 4047 } 4048 4049 /** @hide */ 4050 @SystemApi 4051 public int[] supplyPukReportResult(String puk, String pin) { 4052 try { 4053 ITelephony telephony = getITelephony(); 4054 if (telephony != null) 4055 return telephony.supplyPukReportResult(puk, pin); 4056 } catch (RemoteException e) { 4057 Log.e(TAG, "Error calling ITelephony#]", e); 4058 } 4059 return new int[0]; 4060 } 4061 4062 /** @hide */ 4063 @SystemApi 4064 public boolean handlePinMmi(String dialString) { 4065 try { 4066 ITelephony telephony = getITelephony(); 4067 if (telephony != null) 4068 return telephony.handlePinMmi(dialString); 4069 } catch (RemoteException e) { 4070 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 4071 } 4072 return false; 4073 } 4074 4075 /** @hide */ 4076 @SystemApi 4077 public boolean handlePinMmiForSubscriber(int subId, String dialString) { 4078 try { 4079 ITelephony telephony = getITelephony(); 4080 if (telephony != null) 4081 return telephony.handlePinMmiForSubscriber(subId, dialString); 4082 } catch (RemoteException e) { 4083 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 4084 } 4085 return false; 4086 } 4087 4088 /** @hide */ 4089 @SystemApi 4090 public void toggleRadioOnOff() { 4091 try { 4092 ITelephony telephony = getITelephony(); 4093 if (telephony != null) 4094 telephony.toggleRadioOnOff(); 4095 } catch (RemoteException e) { 4096 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 4097 } 4098 } 4099 4100 /** @hide */ 4101 @SystemApi 4102 public boolean setRadio(boolean turnOn) { 4103 try { 4104 ITelephony telephony = getITelephony(); 4105 if (telephony != null) 4106 return telephony.setRadio(turnOn); 4107 } catch (RemoteException e) { 4108 Log.e(TAG, "Error calling ITelephony#setRadio", e); 4109 } 4110 return false; 4111 } 4112 4113 /** @hide */ 4114 @SystemApi 4115 public boolean setRadioPower(boolean turnOn) { 4116 try { 4117 ITelephony telephony = getITelephony(); 4118 if (telephony != null) 4119 return telephony.setRadioPower(turnOn); 4120 } catch (RemoteException e) { 4121 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 4122 } 4123 return false; 4124 } 4125 4126 /** @hide */ 4127 @SystemApi 4128 public void updateServiceLocation() { 4129 try { 4130 ITelephony telephony = getITelephony(); 4131 if (telephony != null) 4132 telephony.updateServiceLocation(); 4133 } catch (RemoteException e) { 4134 Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e); 4135 } 4136 } 4137 4138 /** @hide */ 4139 @SystemApi 4140 public boolean enableDataConnectivity() { 4141 try { 4142 ITelephony telephony = getITelephony(); 4143 if (telephony != null) 4144 return telephony.enableDataConnectivity(); 4145 } catch (RemoteException e) { 4146 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 4147 } 4148 return false; 4149 } 4150 4151 /** @hide */ 4152 @SystemApi 4153 public boolean disableDataConnectivity() { 4154 try { 4155 ITelephony telephony = getITelephony(); 4156 if (telephony != null) 4157 return telephony.disableDataConnectivity(); 4158 } catch (RemoteException e) { 4159 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 4160 } 4161 return false; 4162 } 4163 4164 /** @hide */ 4165 @SystemApi 4166 public boolean isDataConnectivityPossible() { 4167 try { 4168 ITelephony telephony = getITelephony(); 4169 if (telephony != null) 4170 return telephony.isDataConnectivityPossible(); 4171 } catch (RemoteException e) { 4172 Log.e(TAG, "Error calling ITelephony#isDataConnectivityPossible", e); 4173 } 4174 return false; 4175 } 4176 4177 /** @hide */ 4178 @SystemApi 4179 public boolean needsOtaServiceProvisioning() { 4180 try { 4181 ITelephony telephony = getITelephony(); 4182 if (telephony != null) 4183 return telephony.needsOtaServiceProvisioning(); 4184 } catch (RemoteException e) { 4185 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 4186 } 4187 return false; 4188 } 4189 4190 /** @hide */ 4191 @SystemApi 4192 public void setDataEnabled(boolean enable) { 4193 setDataEnabled(SubscriptionManager.getDefaultDataSubId(), enable); 4194 } 4195 4196 /** @hide */ 4197 @SystemApi 4198 public void setDataEnabled(int subId, boolean enable) { 4199 try { 4200 Log.d(TAG, "setDataEnabled: enabled=" + enable); 4201 ITelephony telephony = getITelephony(); 4202 if (telephony != null) 4203 telephony.setDataEnabled(subId, enable); 4204 } catch (RemoteException e) { 4205 Log.e(TAG, "Error calling ITelephony#setDataEnabled", e); 4206 } 4207 } 4208 4209 /** @hide */ 4210 @SystemApi 4211 public boolean getDataEnabled() { 4212 return getDataEnabled(SubscriptionManager.getDefaultDataSubId()); 4213 } 4214 4215 /** @hide */ 4216 @SystemApi 4217 public boolean getDataEnabled(int subId) { 4218 boolean retVal = false; 4219 try { 4220 ITelephony telephony = getITelephony(); 4221 if (telephony != null) 4222 retVal = telephony.getDataEnabled(subId); 4223 } catch (RemoteException e) { 4224 Log.e(TAG, "Error calling ITelephony#getDataEnabled", e); 4225 } catch (NullPointerException e) { 4226 } 4227 Log.d(TAG, "getDataEnabled: retVal=" + retVal); 4228 return retVal; 4229 } 4230 4231 /** 4232 * Returns the result and response from RIL for oem request 4233 * 4234 * @param oemReq the data is sent to ril. 4235 * @param oemResp the respose data from RIL. 4236 * @return negative value request was not handled or get error 4237 * 0 request was handled succesfully, but no response data 4238 * positive value success, data length of response 4239 * @hide 4240 */ 4241 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { 4242 try { 4243 ITelephony telephony = getITelephony(); 4244 if (telephony != null) 4245 return telephony.invokeOemRilRequestRaw(oemReq, oemResp); 4246 } catch (RemoteException ex) { 4247 } catch (NullPointerException ex) { 4248 } 4249 return -1; 4250 } 4251 4252 /** @hide */ 4253 @SystemApi 4254 public void enableVideoCalling(boolean enable) { 4255 try { 4256 ITelephony telephony = getITelephony(); 4257 if (telephony != null) 4258 telephony.enableVideoCalling(enable); 4259 } catch (RemoteException e) { 4260 Log.e(TAG, "Error calling ITelephony#enableVideoCalling", e); 4261 } 4262 } 4263 4264 /** @hide */ 4265 @SystemApi 4266 public boolean isVideoCallingEnabled() { 4267 try { 4268 ITelephony telephony = getITelephony(); 4269 if (telephony != null) 4270 return telephony.isVideoCallingEnabled(getOpPackageName()); 4271 } catch (RemoteException e) { 4272 Log.e(TAG, "Error calling ITelephony#isVideoCallingEnabled", e); 4273 } 4274 return false; 4275 } 4276 4277 /** 4278 * Whether the device supports configuring the DTMF tone length. 4279 * 4280 * @return {@code true} if the DTMF tone length can be changed, and {@code false} otherwise. 4281 */ 4282 public boolean canChangeDtmfToneLength() { 4283 try { 4284 ITelephony telephony = getITelephony(); 4285 if (telephony != null) { 4286 return telephony.canChangeDtmfToneLength(); 4287 } 4288 } catch (RemoteException e) { 4289 Log.e(TAG, "Error calling ITelephony#canChangeDtmfToneLength", e); 4290 } catch (SecurityException e) { 4291 Log.e(TAG, "Permission error calling ITelephony#canChangeDtmfToneLength", e); 4292 } 4293 return false; 4294 } 4295 4296 /** 4297 * Whether the device is a world phone. 4298 * 4299 * @return {@code true} if the device is a world phone, and {@code false} otherwise. 4300 */ 4301 public boolean isWorldPhone() { 4302 try { 4303 ITelephony telephony = getITelephony(); 4304 if (telephony != null) { 4305 return telephony.isWorldPhone(); 4306 } 4307 } catch (RemoteException e) { 4308 Log.e(TAG, "Error calling ITelephony#isWorldPhone", e); 4309 } catch (SecurityException e) { 4310 Log.e(TAG, "Permission error calling ITelephony#isWorldPhone", e); 4311 } 4312 return false; 4313 } 4314 4315 /** 4316 * Whether the phone supports TTY mode. 4317 * 4318 * @return {@code true} if the device supports TTY mode, and {@code false} otherwise. 4319 */ 4320 public boolean isTtyModeSupported() { 4321 try { 4322 ITelephony telephony = getITelephony(); 4323 if (telephony != null) { 4324 return telephony.isTtyModeSupported(); 4325 } 4326 } catch (RemoteException e) { 4327 Log.e(TAG, "Error calling ITelephony#isTtyModeSupported", e); 4328 } catch (SecurityException e) { 4329 Log.e(TAG, "Permission error calling ITelephony#isTtyModeSupported", e); 4330 } 4331 return false; 4332 } 4333 4334 /** 4335 * Whether the phone supports hearing aid compatibility. 4336 * 4337 * @return {@code true} if the device supports hearing aid compatibility, and {@code false} 4338 * otherwise. 4339 */ 4340 public boolean isHearingAidCompatibilitySupported() { 4341 try { 4342 ITelephony telephony = getITelephony(); 4343 if (telephony != null) { 4344 return telephony.isHearingAidCompatibilitySupported(); 4345 } 4346 } catch (RemoteException e) { 4347 Log.e(TAG, "Error calling ITelephony#isHearingAidCompatibilitySupported", e); 4348 } catch (SecurityException e) { 4349 Log.e(TAG, "Permission error calling ITelephony#isHearingAidCompatibilitySupported", e); 4350 } 4351 return false; 4352 } 4353 4354 /** 4355 * This function retrieves value for setting "name+subId", and if that is not found 4356 * retrieves value for setting "name", and if that is not found throws 4357 * SettingNotFoundException 4358 * 4359 * @hide */ 4360 public static int getIntWithSubId(ContentResolver cr, String name, int subId) 4361 throws SettingNotFoundException { 4362 try { 4363 return Settings.Global.getInt(cr, name + subId); 4364 } catch (SettingNotFoundException e) { 4365 try { 4366 int val = Settings.Global.getInt(cr, name); 4367 Settings.Global.putInt(cr, name + subId, val); 4368 4369 /* We are now moving from 'setting' to 'setting+subId', and using the value stored 4370 * for 'setting' as default. Reset the default (since it may have a user set 4371 * value). */ 4372 int default_val = val; 4373 if (name.equals(Settings.Global.MOBILE_DATA)) { 4374 default_val = "true".equalsIgnoreCase( 4375 SystemProperties.get("ro.com.android.mobiledata", "true")) ? 1 : 0; 4376 } else if (name.equals(Settings.Global.DATA_ROAMING)) { 4377 default_val = "true".equalsIgnoreCase( 4378 SystemProperties.get("ro.com.android.dataroaming", "false")) ? 1 : 0; 4379 } 4380 4381 if (default_val != val) { 4382 Settings.Global.putInt(cr, name, default_val); 4383 } 4384 4385 return val; 4386 } catch (SettingNotFoundException exc) { 4387 throw new SettingNotFoundException(name); 4388 } 4389 } 4390 } 4391 4392 /** 4393 * Returns the IMS Registration Status 4394 * @hide 4395 */ 4396 public boolean isImsRegistered() { 4397 try { 4398 ITelephony telephony = getITelephony(); 4399 if (telephony == null) 4400 return false; 4401 return telephony.isImsRegistered(); 4402 } catch (RemoteException ex) { 4403 return false; 4404 } catch (NullPointerException ex) { 4405 return false; 4406 } 4407 } 4408 4409 /** 4410 * Returns the Status of Volte 4411 * @hide 4412 */ 4413 public boolean isVolteAvailable() { 4414 try { 4415 return getITelephony().isVolteAvailable(); 4416 } catch (RemoteException ex) { 4417 return false; 4418 } catch (NullPointerException ex) { 4419 return false; 4420 } 4421 } 4422 4423 /** 4424 * Returns the Status of video telephony (VT) 4425 * @hide 4426 */ 4427 public boolean isVideoTelephonyAvailable() { 4428 try { 4429 return getITelephony().isVideoTelephonyAvailable(); 4430 } catch (RemoteException ex) { 4431 return false; 4432 } catch (NullPointerException ex) { 4433 return false; 4434 } 4435 } 4436 4437 /** 4438 * Returns the Status of Wi-Fi Calling 4439 * @hide 4440 */ 4441 public boolean isWifiCallingAvailable() { 4442 try { 4443 return getITelephony().isWifiCallingAvailable(); 4444 } catch (RemoteException ex) { 4445 return false; 4446 } catch (NullPointerException ex) { 4447 return false; 4448 } 4449 } 4450 4451 /** 4452 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 4453 * 4454 * @hide 4455 */ 4456 public void setSimOperatorNumeric(String numeric) { 4457 int phoneId = getDefaultPhone(); 4458 setSimOperatorNumericForPhone(phoneId, numeric); 4459 } 4460 4461 /** 4462 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 4463 * 4464 * @hide 4465 */ 4466 public void setSimOperatorNumericForPhone(int phoneId, String numeric) { 4467 setTelephonyProperty(phoneId, 4468 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, numeric); 4469 } 4470 4471 /** 4472 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 4473 * 4474 * @hide 4475 */ 4476 public void setSimOperatorName(String name) { 4477 int phoneId = getDefaultPhone(); 4478 setSimOperatorNameForPhone(phoneId, name); 4479 } 4480 4481 /** 4482 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 4483 * 4484 * @hide 4485 */ 4486 public void setSimOperatorNameForPhone(int phoneId, String name) { 4487 setTelephonyProperty(phoneId, 4488 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, name); 4489 } 4490 4491 /** 4492 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the default phone. 4493 * 4494 * @hide 4495 */ 4496 public void setSimCountryIso(String iso) { 4497 int phoneId = getDefaultPhone(); 4498 setSimCountryIsoForPhone(phoneId, iso); 4499 } 4500 4501 /** 4502 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the given phone. 4503 * 4504 * @hide 4505 */ 4506 public void setSimCountryIsoForPhone(int phoneId, String iso) { 4507 setTelephonyProperty(phoneId, 4508 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, iso); 4509 } 4510 4511 /** 4512 * Set TelephonyProperties.PROPERTY_SIM_STATE for the default phone. 4513 * 4514 * @hide 4515 */ 4516 public void setSimState(String state) { 4517 int phoneId = getDefaultPhone(); 4518 setSimStateForPhone(phoneId, state); 4519 } 4520 4521 /** 4522 * Set TelephonyProperties.PROPERTY_SIM_STATE for the given phone. 4523 * 4524 * @hide 4525 */ 4526 public void setSimStateForPhone(int phoneId, String state) { 4527 setTelephonyProperty(phoneId, 4528 TelephonyProperties.PROPERTY_SIM_STATE, state); 4529 } 4530 4531 /** 4532 * Set baseband version for the default phone. 4533 * 4534 * @param version baseband version 4535 * @hide 4536 */ 4537 public void setBasebandVersion(String version) { 4538 int phoneId = getDefaultPhone(); 4539 setBasebandVersionForPhone(phoneId, version); 4540 } 4541 4542 /** 4543 * Set baseband version by phone id. 4544 * 4545 * @param phoneId for which baseband version is set 4546 * @param version baseband version 4547 * @hide 4548 */ 4549 public void setBasebandVersionForPhone(int phoneId, String version) { 4550 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4551 String prop = TelephonyProperties.PROPERTY_BASEBAND_VERSION + 4552 ((phoneId == 0) ? "" : Integer.toString(phoneId)); 4553 SystemProperties.set(prop, version); 4554 } 4555 } 4556 4557 /** 4558 * Set phone type for the default phone. 4559 * 4560 * @param type phone type 4561 * 4562 * @hide 4563 */ 4564 public void setPhoneType(int type) { 4565 int phoneId = getDefaultPhone(); 4566 setPhoneType(phoneId, type); 4567 } 4568 4569 /** 4570 * Set phone type by phone id. 4571 * 4572 * @param phoneId for which phone type is set 4573 * @param type phone type 4574 * 4575 * @hide 4576 */ 4577 public void setPhoneType(int phoneId, int type) { 4578 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4579 TelephonyManager.setTelephonyProperty(phoneId, 4580 TelephonyProperties.CURRENT_ACTIVE_PHONE, String.valueOf(type)); 4581 } 4582 } 4583 4584 /** 4585 * Get OTASP number schema for the default phone. 4586 * 4587 * @param defaultValue default value 4588 * @return OTA SP number schema 4589 * 4590 * @hide 4591 */ 4592 public String getOtaSpNumberSchema(String defaultValue) { 4593 int phoneId = getDefaultPhone(); 4594 return getOtaSpNumberSchemaForPhone(phoneId, defaultValue); 4595 } 4596 4597 /** 4598 * Get OTASP number schema by phone id. 4599 * 4600 * @param phoneId for which OTA SP number schema is get 4601 * @param defaultValue default value 4602 * @return OTA SP number schema 4603 * 4604 * @hide 4605 */ 4606 public String getOtaSpNumberSchemaForPhone(int phoneId, String defaultValue) { 4607 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4608 return TelephonyManager.getTelephonyProperty(phoneId, 4609 TelephonyProperties.PROPERTY_OTASP_NUM_SCHEMA, defaultValue); 4610 } 4611 4612 return defaultValue; 4613 } 4614 4615 /** 4616 * Get SMS receive capable from system property for the default phone. 4617 * 4618 * @param defaultValue default value 4619 * @return SMS receive capable 4620 * 4621 * @hide 4622 */ 4623 public boolean getSmsReceiveCapable(boolean defaultValue) { 4624 int phoneId = getDefaultPhone(); 4625 return getSmsReceiveCapableForPhone(phoneId, defaultValue); 4626 } 4627 4628 /** 4629 * Get SMS receive capable from system property by phone id. 4630 * 4631 * @param phoneId for which SMS receive capable is get 4632 * @param defaultValue default value 4633 * @return SMS receive capable 4634 * 4635 * @hide 4636 */ 4637 public boolean getSmsReceiveCapableForPhone(int phoneId, boolean defaultValue) { 4638 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4639 return Boolean.valueOf(TelephonyManager.getTelephonyProperty(phoneId, 4640 TelephonyProperties.PROPERTY_SMS_RECEIVE, String.valueOf(defaultValue))); 4641 } 4642 4643 return defaultValue; 4644 } 4645 4646 /** 4647 * Get SMS send capable from system property for the default phone. 4648 * 4649 * @param defaultValue default value 4650 * @return SMS send capable 4651 * 4652 * @hide 4653 */ 4654 public boolean getSmsSendCapable(boolean defaultValue) { 4655 int phoneId = getDefaultPhone(); 4656 return getSmsSendCapableForPhone(phoneId, defaultValue); 4657 } 4658 4659 /** 4660 * Get SMS send capable from system property by phone id. 4661 * 4662 * @param phoneId for which SMS send capable is get 4663 * @param defaultValue default value 4664 * @return SMS send capable 4665 * 4666 * @hide 4667 */ 4668 public boolean getSmsSendCapableForPhone(int phoneId, boolean defaultValue) { 4669 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4670 return Boolean.valueOf(TelephonyManager.getTelephonyProperty(phoneId, 4671 TelephonyProperties.PROPERTY_SMS_SEND, String.valueOf(defaultValue))); 4672 } 4673 4674 return defaultValue; 4675 } 4676 4677 /** 4678 * Set the alphabetic name of current registered operator. 4679 * @param name the alphabetic name of current registered operator. 4680 * @hide 4681 */ 4682 public void setNetworkOperatorName(String name) { 4683 int phoneId = getDefaultPhone(); 4684 setNetworkOperatorNameForPhone(phoneId, name); 4685 } 4686 4687 /** 4688 * Set the alphabetic name of current registered operator. 4689 * @param phoneId which phone you want to set 4690 * @param name the alphabetic name of current registered operator. 4691 * @hide 4692 */ 4693 public void setNetworkOperatorNameForPhone(int phoneId, String name) { 4694 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4695 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, name); 4696 } 4697 } 4698 4699 /** 4700 * Set the numeric name (MCC+MNC) of current registered operator. 4701 * @param operator the numeric name (MCC+MNC) of current registered operator 4702 * @hide 4703 */ 4704 public void setNetworkOperatorNumeric(String numeric) { 4705 int phoneId = getDefaultPhone(); 4706 setNetworkOperatorNumericForPhone(phoneId, numeric); 4707 } 4708 4709 /** 4710 * Set the numeric name (MCC+MNC) of current registered operator. 4711 * @param phoneId for which phone type is set 4712 * @param operator the numeric name (MCC+MNC) of current registered operator 4713 * @hide 4714 */ 4715 public void setNetworkOperatorNumericForPhone(int phoneId, String numeric) { 4716 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, numeric); 4717 } 4718 4719 /** 4720 * Set roaming state of the current network, for GSM purposes. 4721 * @param isRoaming is network in romaing state or not 4722 * @hide 4723 */ 4724 public void setNetworkRoaming(boolean isRoaming) { 4725 int phoneId = getDefaultPhone(); 4726 setNetworkRoamingForPhone(phoneId, isRoaming); 4727 } 4728 4729 /** 4730 * Set roaming state of the current network, for GSM purposes. 4731 * @param phoneId which phone you want to set 4732 * @param isRoaming is network in romaing state or not 4733 * @hide 4734 */ 4735 public void setNetworkRoamingForPhone(int phoneId, boolean isRoaming) { 4736 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4737 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, 4738 isRoaming ? "true" : "false"); 4739 } 4740 } 4741 4742 /** 4743 * Set the ISO country code equivalent of the current registered 4744 * operator's MCC (Mobile Country Code). 4745 * @param iso the ISO country code equivalent of the current registered 4746 * @hide 4747 */ 4748 public void setNetworkCountryIso(String iso) { 4749 int phoneId = getDefaultPhone(); 4750 setNetworkCountryIsoForPhone(phoneId, iso); 4751 } 4752 4753 /** 4754 * Set the ISO country code equivalent of the current registered 4755 * operator's MCC (Mobile Country Code). 4756 * @param phoneId which phone you want to set 4757 * @param iso the ISO country code equivalent of the current registered 4758 * @hide 4759 */ 4760 public void setNetworkCountryIsoForPhone(int phoneId, String iso) { 4761 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4762 setTelephonyProperty(phoneId, 4763 TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, iso); 4764 } 4765 } 4766 4767 /** 4768 * Set the network type currently in use on the device for data transmission. 4769 * @param type the network type currently in use on the device for data transmission 4770 * @hide 4771 */ 4772 public void setDataNetworkType(int type) { 4773 int phoneId = getDefaultPhone(); 4774 setDataNetworkTypeForPhone(phoneId, type); 4775 } 4776 4777 /** 4778 * Set the network type currently in use on the device for data transmission. 4779 * @param phoneId which phone you want to set 4780 * @param type the network type currently in use on the device for data transmission 4781 * @hide 4782 */ 4783 public void setDataNetworkTypeForPhone(int phoneId, int type) { 4784 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4785 setTelephonyProperty(phoneId, 4786 TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE, 4787 ServiceState.rilRadioTechnologyToString(type)); 4788 } 4789 } 4790 4791 /** 4792 * Returns the subscription ID for the given phone account. 4793 * @hide 4794 */ 4795 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { 4796 int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 4797 try { 4798 ITelephony service = getITelephony(); 4799 if (service != null) { 4800 retval = service.getSubIdForPhoneAccount(phoneAccount); 4801 } 4802 } catch (RemoteException e) { 4803 } 4804 4805 return retval; 4806 } 4807 4808 /** 4809 * Resets telephony manager settings back to factory defaults. 4810 * 4811 * @hide 4812 */ 4813 public void factoryReset(int subId) { 4814 try { 4815 Log.d(TAG, "factoryReset: subId=" + subId); 4816 ITelephony telephony = getITelephony(); 4817 if (telephony != null) 4818 telephony.factoryReset(subId); 4819 } catch (RemoteException e) { 4820 } 4821 } 4822 4823 4824 /** @hide */ 4825 public String getLocaleFromDefaultSim() { 4826 try { 4827 final ITelephony telephony = getITelephony(); 4828 if (telephony != null) { 4829 return telephony.getLocaleFromDefaultSim(); 4830 } 4831 } catch (RemoteException ex) { 4832 } 4833 return null; 4834 } 4835 4836 /** 4837 * Returns the modem activity info. 4838 * @hide 4839 */ 4840 public ModemActivityInfo getModemActivityInfo() { 4841 try { 4842 ITelephony service = getITelephony(); 4843 if (service != null) { 4844 return service.getModemActivityInfo(); 4845 } 4846 } catch (RemoteException e) { 4847 Log.e(TAG, "Error calling ITelephony#getModemActivityInfo", e); 4848 } 4849 return null; 4850 } 4851 4852 /** 4853 * Returns the service state information on specified subscription. Callers require 4854 * either READ_PRIVILEGED_PHONE_STATE or READ_PHONE_STATE to retrieve the information. 4855 * @hide 4856 */ 4857 public ServiceState getServiceStateForSubscriber(int subId) { 4858 try { 4859 ITelephony service = getITelephony(); 4860 if (service != null) { 4861 return service.getServiceStateForSubscriber(subId, getOpPackageName()); 4862 } 4863 } catch (RemoteException e) { 4864 Log.e(TAG, "Error calling ITelephony#getServiceStateForSubscriber", e); 4865 } 4866 return null; 4867 } 4868}