TelephonyManager.java revision 1845a3bf5691f9d674f943d3ca36603e4ca2cb0a
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, mContext.getOpPackageName()); 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 * 3496 * <p>Requires that the calling app has carrier privileges. 3497 * @see #hasCarrierPrivileges 3498 * 3499 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 3500 * @param data authentication challenge data 3501 * @return the response of SIM Authentication, or null if not available 3502 */ 3503 public String getIccSimChallengeResponse(int appType, String data) { 3504 return getIccSimChallengeResponse(getDefaultSubscription(), appType, data); 3505 } 3506 3507 /** 3508 * Get P-CSCF address from PCO after data connection is established or modified. 3509 * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN 3510 * @return array of P-CSCF address 3511 * @hide 3512 */ 3513 public String[] getPcscfAddress(String apnType) { 3514 try { 3515 ITelephony telephony = getITelephony(); 3516 if (telephony == null) 3517 return new String[0]; 3518 return telephony.getPcscfAddress(apnType, getOpPackageName()); 3519 } catch (RemoteException e) { 3520 return new String[0]; 3521 } 3522 } 3523 3524 /** 3525 * Set IMS registration state 3526 * 3527 * @param Registration state 3528 * @hide 3529 */ 3530 public void setImsRegistrationState(boolean registered) { 3531 try { 3532 ITelephony telephony = getITelephony(); 3533 if (telephony != null) 3534 telephony.setImsRegistrationState(registered); 3535 } catch (RemoteException e) { 3536 } 3537 } 3538 3539 /** 3540 * Get the preferred network type. 3541 * Used for device configuration by some CDMA operators. 3542 * <p> 3543 * Requires Permission: 3544 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3545 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3546 * 3547 * @return the preferred network type, defined in RILConstants.java. 3548 * @hide 3549 */ 3550 public int getPreferredNetworkType(int subId) { 3551 try { 3552 ITelephony telephony = getITelephony(); 3553 if (telephony != null) 3554 return telephony.getPreferredNetworkType(subId); 3555 } catch (RemoteException ex) { 3556 Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex); 3557 } catch (NullPointerException ex) { 3558 Rlog.e(TAG, "getPreferredNetworkType NPE", ex); 3559 } 3560 return -1; 3561 } 3562 3563 /** 3564 * Sets the network selection mode to automatic. 3565 * <p> 3566 * Requires Permission: 3567 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3568 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3569 * 3570 * @hide 3571 */ 3572 public void setNetworkSelectionModeAutomatic(int subId) { 3573 try { 3574 ITelephony telephony = getITelephony(); 3575 if (telephony != null) 3576 telephony.setNetworkSelectionModeAutomatic(subId); 3577 } catch (RemoteException ex) { 3578 Rlog.e(TAG, "setNetworkSelectionModeAutomatic RemoteException", ex); 3579 } catch (NullPointerException ex) { 3580 Rlog.e(TAG, "setNetworkSelectionModeAutomatic NPE", ex); 3581 } 3582 } 3583 3584 /** 3585 * Perform a radio scan and return the list of avialble networks. 3586 * 3587 * The return value is a list of the OperatorInfo of the networks found. Note that this 3588 * scan can take a long time (sometimes minutes) to happen. 3589 * 3590 * <p> 3591 * Requires Permission: 3592 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3593 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3594 * 3595 * @hide 3596 */ 3597 public CellNetworkScanResult getCellNetworkScanResults(int subId) { 3598 try { 3599 ITelephony telephony = getITelephony(); 3600 if (telephony != null) 3601 return telephony.getCellNetworkScanResults(subId); 3602 } catch (RemoteException ex) { 3603 Rlog.e(TAG, "getCellNetworkScanResults RemoteException", ex); 3604 } catch (NullPointerException ex) { 3605 Rlog.e(TAG, "getCellNetworkScanResults NPE", ex); 3606 } 3607 return null; 3608 } 3609 3610 /** 3611 * Ask the radio to connect to the input network and change selection mode to manual. 3612 * 3613 * <p> 3614 * Requires Permission: 3615 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3616 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3617 * 3618 * @hide 3619 */ 3620 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator, 3621 boolean persistSelection) { 3622 try { 3623 ITelephony telephony = getITelephony(); 3624 if (telephony != null) 3625 return telephony.setNetworkSelectionModeManual(subId, operator, persistSelection); 3626 } catch (RemoteException ex) { 3627 Rlog.e(TAG, "setNetworkSelectionModeManual RemoteException", ex); 3628 } catch (NullPointerException ex) { 3629 Rlog.e(TAG, "setNetworkSelectionModeManual NPE", ex); 3630 } 3631 return false; 3632 } 3633 3634 /** 3635 * Set the preferred network type. 3636 * Used for device configuration by some CDMA operators. 3637 * <p> 3638 * Requires Permission: 3639 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3640 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3641 * 3642 * @param subId the id of the subscription to set the preferred network type for. 3643 * @param networkType the preferred network type, defined in RILConstants.java. 3644 * @return true on success; false on any failure. 3645 * @hide 3646 */ 3647 public boolean setPreferredNetworkType(int subId, int networkType) { 3648 try { 3649 ITelephony telephony = getITelephony(); 3650 if (telephony != null) 3651 return telephony.setPreferredNetworkType(subId, networkType); 3652 } catch (RemoteException ex) { 3653 Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex); 3654 } catch (NullPointerException ex) { 3655 Rlog.e(TAG, "setPreferredNetworkType NPE", ex); 3656 } 3657 return false; 3658 } 3659 3660 /** 3661 * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA. 3662 * 3663 * <p> 3664 * Requires that the calling app has carrier privileges. 3665 * @see #hasCarrierPrivileges 3666 * 3667 * @return true on success; false on any failure. 3668 */ 3669 public boolean setPreferredNetworkTypeToGlobal() { 3670 return setPreferredNetworkType(getDefaultSubscription(), 3671 RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA); 3672 } 3673 3674 /** 3675 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning 3676 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for 3677 * tethering. 3678 * 3679 * @return 0: Not required. 1: required. 2: Not set. 3680 * @hide 3681 */ 3682 public int getTetherApnRequired() { 3683 try { 3684 ITelephony telephony = getITelephony(); 3685 if (telephony != null) 3686 return telephony.getTetherApnRequired(); 3687 } catch (RemoteException ex) { 3688 Rlog.e(TAG, "hasMatchedTetherApnSetting RemoteException", ex); 3689 } catch (NullPointerException ex) { 3690 Rlog.e(TAG, "hasMatchedTetherApnSetting NPE", ex); 3691 } 3692 return 2; 3693 } 3694 3695 3696 /** 3697 * Values used to return status for hasCarrierPrivileges call. 3698 */ 3699 /** @hide */ @SystemApi 3700 public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1; 3701 /** @hide */ @SystemApi 3702 public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0; 3703 /** @hide */ @SystemApi 3704 public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1; 3705 /** @hide */ @SystemApi 3706 public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2; 3707 3708 /** 3709 * Has the calling application been granted carrier privileges by the carrier. 3710 * 3711 * If any of the packages in the calling UID has carrier privileges, the 3712 * call will return true. This access is granted by the owner of the UICC 3713 * card and does not depend on the registered carrier. 3714 * 3715 * @return true if the app has carrier privileges. 3716 */ 3717 public boolean hasCarrierPrivileges() { 3718 try { 3719 ITelephony telephony = getITelephony(); 3720 if (telephony != null) 3721 return telephony.getCarrierPrivilegeStatus() == CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; 3722 } catch (RemoteException ex) { 3723 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 3724 } catch (NullPointerException ex) { 3725 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 3726 } 3727 return false; 3728 } 3729 3730 /** 3731 * Override the branding for the current ICCID. 3732 * 3733 * Once set, whenever the SIM is present in the device, the service 3734 * provider name (SPN) and the operator name will both be replaced by the 3735 * brand value input. To unset the value, the same function should be 3736 * called with a null brand value. 3737 * 3738 * <p>Requires that the calling app has carrier privileges. 3739 * @see #hasCarrierPrivileges 3740 * 3741 * @param brand The brand name to display/set. 3742 * @return true if the operation was executed correctly. 3743 */ 3744 public boolean setOperatorBrandOverride(String brand) { 3745 try { 3746 ITelephony telephony = getITelephony(); 3747 if (telephony != null) 3748 return telephony.setOperatorBrandOverride(brand); 3749 } catch (RemoteException ex) { 3750 Rlog.e(TAG, "setOperatorBrandOverride RemoteException", ex); 3751 } catch (NullPointerException ex) { 3752 Rlog.e(TAG, "setOperatorBrandOverride NPE", ex); 3753 } 3754 return false; 3755 } 3756 3757 /** 3758 * Override the roaming preference for the current ICCID. 3759 * 3760 * Using this call, the carrier app (see #hasCarrierPrivileges) can override 3761 * the platform's notion of a network operator being considered roaming or not. 3762 * The change only affects the ICCID that was active when this call was made. 3763 * 3764 * If null is passed as any of the input, the corresponding value is deleted. 3765 * 3766 * <p>Requires that the caller have carrier privilege. See #hasCarrierPrivileges. 3767 * 3768 * @param gsmRoamingList - List of MCCMNCs to be considered roaming for 3GPP RATs. 3769 * @param gsmNonRoamingList - List of MCCMNCs to be considered not roaming for 3GPP RATs. 3770 * @param cdmaRoamingList - List of SIDs to be considered roaming for 3GPP2 RATs. 3771 * @param cdmaNonRoamingList - List of SIDs to be considered not roaming for 3GPP2 RATs. 3772 * @return true if the operation was executed correctly. 3773 * 3774 * @hide 3775 */ 3776 public boolean setRoamingOverride(List<String> gsmRoamingList, 3777 List<String> gsmNonRoamingList, List<String> cdmaRoamingList, 3778 List<String> cdmaNonRoamingList) { 3779 try { 3780 ITelephony telephony = getITelephony(); 3781 if (telephony != null) 3782 return telephony.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, 3783 cdmaRoamingList, cdmaNonRoamingList); 3784 } catch (RemoteException ex) { 3785 Rlog.e(TAG, "setRoamingOverride RemoteException", ex); 3786 } catch (NullPointerException ex) { 3787 Rlog.e(TAG, "setRoamingOverride NPE", ex); 3788 } 3789 return false; 3790 } 3791 3792 /** 3793 * Expose the rest of ITelephony to @SystemApi 3794 */ 3795 3796 /** @hide */ 3797 @SystemApi 3798 public String getCdmaMdn() { 3799 return getCdmaMdn(getDefaultSubscription()); 3800 } 3801 3802 /** @hide */ 3803 @SystemApi 3804 public String getCdmaMdn(int subId) { 3805 try { 3806 ITelephony telephony = getITelephony(); 3807 if (telephony == null) 3808 return null; 3809 return telephony.getCdmaMdn(subId); 3810 } catch (RemoteException ex) { 3811 return null; 3812 } catch (NullPointerException ex) { 3813 return null; 3814 } 3815 } 3816 3817 /** @hide */ 3818 @SystemApi 3819 public String getCdmaMin() { 3820 return getCdmaMin(getDefaultSubscription()); 3821 } 3822 3823 /** @hide */ 3824 @SystemApi 3825 public String getCdmaMin(int subId) { 3826 try { 3827 ITelephony telephony = getITelephony(); 3828 if (telephony == null) 3829 return null; 3830 return telephony.getCdmaMin(subId); 3831 } catch (RemoteException ex) { 3832 return null; 3833 } catch (NullPointerException ex) { 3834 return null; 3835 } 3836 } 3837 3838 /** @hide */ 3839 @SystemApi 3840 public int checkCarrierPrivilegesForPackage(String pkgName) { 3841 try { 3842 ITelephony telephony = getITelephony(); 3843 if (telephony != null) 3844 return telephony.checkCarrierPrivilegesForPackage(pkgName); 3845 } catch (RemoteException ex) { 3846 Rlog.e(TAG, "checkCarrierPrivilegesForPackage RemoteException", ex); 3847 } catch (NullPointerException ex) { 3848 Rlog.e(TAG, "checkCarrierPrivilegesForPackage NPE", ex); 3849 } 3850 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 3851 } 3852 3853 /** @hide */ 3854 @SystemApi 3855 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { 3856 try { 3857 ITelephony telephony = getITelephony(); 3858 if (telephony != null) 3859 return telephony.checkCarrierPrivilegesForPackageAnyPhone(pkgName); 3860 } catch (RemoteException ex) { 3861 Rlog.e(TAG, "checkCarrierPrivilegesForPackageAnyPhone RemoteException", ex); 3862 } catch (NullPointerException ex) { 3863 Rlog.e(TAG, "checkCarrierPrivilegesForPackageAnyPhone NPE", ex); 3864 } 3865 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 3866 } 3867 3868 /** @hide */ 3869 @SystemApi 3870 public List<String> getCarrierPackageNamesForIntent(Intent intent) { 3871 return getCarrierPackageNamesForIntentAndPhone(intent, getDefaultPhone()); 3872 } 3873 3874 /** @hide */ 3875 @SystemApi 3876 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { 3877 try { 3878 ITelephony telephony = getITelephony(); 3879 if (telephony != null) 3880 return telephony.getCarrierPackageNamesForIntentAndPhone(intent, phoneId); 3881 } catch (RemoteException ex) { 3882 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone RemoteException", ex); 3883 } catch (NullPointerException ex) { 3884 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone NPE", ex); 3885 } 3886 return null; 3887 } 3888 3889 /** @hide */ 3890 @SystemApi 3891 public void dial(String number) { 3892 try { 3893 ITelephony telephony = getITelephony(); 3894 if (telephony != null) 3895 telephony.dial(number); 3896 } catch (RemoteException e) { 3897 Log.e(TAG, "Error calling ITelephony#dial", e); 3898 } 3899 } 3900 3901 /** @hide */ 3902 @SystemApi 3903 public void call(String callingPackage, String number) { 3904 try { 3905 ITelephony telephony = getITelephony(); 3906 if (telephony != null) 3907 telephony.call(callingPackage, number); 3908 } catch (RemoteException e) { 3909 Log.e(TAG, "Error calling ITelephony#call", e); 3910 } 3911 } 3912 3913 /** @hide */ 3914 @SystemApi 3915 public boolean endCall() { 3916 try { 3917 ITelephony telephony = getITelephony(); 3918 if (telephony != null) 3919 return telephony.endCall(); 3920 } catch (RemoteException e) { 3921 Log.e(TAG, "Error calling ITelephony#endCall", e); 3922 } 3923 return false; 3924 } 3925 3926 /** @hide */ 3927 @SystemApi 3928 public void answerRingingCall() { 3929 try { 3930 ITelephony telephony = getITelephony(); 3931 if (telephony != null) 3932 telephony.answerRingingCall(); 3933 } catch (RemoteException e) { 3934 Log.e(TAG, "Error calling ITelephony#answerRingingCall", e); 3935 } 3936 } 3937 3938 /** @hide */ 3939 @SystemApi 3940 public void silenceRinger() { 3941 try { 3942 getTelecomService().silenceRinger(getOpPackageName()); 3943 } catch (RemoteException e) { 3944 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e); 3945 } 3946 } 3947 3948 /** @hide */ 3949 @SystemApi 3950 public boolean isOffhook() { 3951 try { 3952 ITelephony telephony = getITelephony(); 3953 if (telephony != null) 3954 return telephony.isOffhook(getOpPackageName()); 3955 } catch (RemoteException e) { 3956 Log.e(TAG, "Error calling ITelephony#isOffhook", e); 3957 } 3958 return false; 3959 } 3960 3961 /** @hide */ 3962 @SystemApi 3963 public boolean isRinging() { 3964 try { 3965 ITelephony telephony = getITelephony(); 3966 if (telephony != null) 3967 return telephony.isRinging(getOpPackageName()); 3968 } catch (RemoteException e) { 3969 Log.e(TAG, "Error calling ITelephony#isRinging", e); 3970 } 3971 return false; 3972 } 3973 3974 /** @hide */ 3975 @SystemApi 3976 public boolean isIdle() { 3977 try { 3978 ITelephony telephony = getITelephony(); 3979 if (telephony != null) 3980 return telephony.isIdle(getOpPackageName()); 3981 } catch (RemoteException e) { 3982 Log.e(TAG, "Error calling ITelephony#isIdle", e); 3983 } 3984 return true; 3985 } 3986 3987 /** @hide */ 3988 @SystemApi 3989 public boolean isRadioOn() { 3990 try { 3991 ITelephony telephony = getITelephony(); 3992 if (telephony != null) 3993 return telephony.isRadioOn(getOpPackageName()); 3994 } catch (RemoteException e) { 3995 Log.e(TAG, "Error calling ITelephony#isRadioOn", e); 3996 } 3997 return false; 3998 } 3999 4000 /** @hide */ 4001 @SystemApi 4002 public boolean isSimPinEnabled() { 4003 try { 4004 ITelephony telephony = getITelephony(); 4005 if (telephony != null) 4006 return telephony.isSimPinEnabled(getOpPackageName()); 4007 } catch (RemoteException e) { 4008 Log.e(TAG, "Error calling ITelephony#isSimPinEnabled", e); 4009 } 4010 return false; 4011 } 4012 4013 /** @hide */ 4014 @SystemApi 4015 public boolean supplyPin(String pin) { 4016 try { 4017 ITelephony telephony = getITelephony(); 4018 if (telephony != null) 4019 return telephony.supplyPin(pin); 4020 } catch (RemoteException e) { 4021 Log.e(TAG, "Error calling ITelephony#supplyPin", e); 4022 } 4023 return false; 4024 } 4025 4026 /** @hide */ 4027 @SystemApi 4028 public boolean supplyPuk(String puk, String pin) { 4029 try { 4030 ITelephony telephony = getITelephony(); 4031 if (telephony != null) 4032 return telephony.supplyPuk(puk, pin); 4033 } catch (RemoteException e) { 4034 Log.e(TAG, "Error calling ITelephony#supplyPuk", e); 4035 } 4036 return false; 4037 } 4038 4039 /** @hide */ 4040 @SystemApi 4041 public int[] supplyPinReportResult(String pin) { 4042 try { 4043 ITelephony telephony = getITelephony(); 4044 if (telephony != null) 4045 return telephony.supplyPinReportResult(pin); 4046 } catch (RemoteException e) { 4047 Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e); 4048 } 4049 return new int[0]; 4050 } 4051 4052 /** @hide */ 4053 @SystemApi 4054 public int[] supplyPukReportResult(String puk, String pin) { 4055 try { 4056 ITelephony telephony = getITelephony(); 4057 if (telephony != null) 4058 return telephony.supplyPukReportResult(puk, pin); 4059 } catch (RemoteException e) { 4060 Log.e(TAG, "Error calling ITelephony#]", e); 4061 } 4062 return new int[0]; 4063 } 4064 4065 /** @hide */ 4066 @SystemApi 4067 public boolean handlePinMmi(String dialString) { 4068 try { 4069 ITelephony telephony = getITelephony(); 4070 if (telephony != null) 4071 return telephony.handlePinMmi(dialString); 4072 } catch (RemoteException e) { 4073 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 4074 } 4075 return false; 4076 } 4077 4078 /** @hide */ 4079 @SystemApi 4080 public boolean handlePinMmiForSubscriber(int subId, String dialString) { 4081 try { 4082 ITelephony telephony = getITelephony(); 4083 if (telephony != null) 4084 return telephony.handlePinMmiForSubscriber(subId, dialString); 4085 } catch (RemoteException e) { 4086 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 4087 } 4088 return false; 4089 } 4090 4091 /** @hide */ 4092 @SystemApi 4093 public void toggleRadioOnOff() { 4094 try { 4095 ITelephony telephony = getITelephony(); 4096 if (telephony != null) 4097 telephony.toggleRadioOnOff(); 4098 } catch (RemoteException e) { 4099 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 4100 } 4101 } 4102 4103 /** @hide */ 4104 @SystemApi 4105 public boolean setRadio(boolean turnOn) { 4106 try { 4107 ITelephony telephony = getITelephony(); 4108 if (telephony != null) 4109 return telephony.setRadio(turnOn); 4110 } catch (RemoteException e) { 4111 Log.e(TAG, "Error calling ITelephony#setRadio", e); 4112 } 4113 return false; 4114 } 4115 4116 /** @hide */ 4117 @SystemApi 4118 public boolean setRadioPower(boolean turnOn) { 4119 try { 4120 ITelephony telephony = getITelephony(); 4121 if (telephony != null) 4122 return telephony.setRadioPower(turnOn); 4123 } catch (RemoteException e) { 4124 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 4125 } 4126 return false; 4127 } 4128 4129 /** @hide */ 4130 @SystemApi 4131 public void updateServiceLocation() { 4132 try { 4133 ITelephony telephony = getITelephony(); 4134 if (telephony != null) 4135 telephony.updateServiceLocation(); 4136 } catch (RemoteException e) { 4137 Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e); 4138 } 4139 } 4140 4141 /** @hide */ 4142 @SystemApi 4143 public boolean enableDataConnectivity() { 4144 try { 4145 ITelephony telephony = getITelephony(); 4146 if (telephony != null) 4147 return telephony.enableDataConnectivity(); 4148 } catch (RemoteException e) { 4149 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 4150 } 4151 return false; 4152 } 4153 4154 /** @hide */ 4155 @SystemApi 4156 public boolean disableDataConnectivity() { 4157 try { 4158 ITelephony telephony = getITelephony(); 4159 if (telephony != null) 4160 return telephony.disableDataConnectivity(); 4161 } catch (RemoteException e) { 4162 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 4163 } 4164 return false; 4165 } 4166 4167 /** @hide */ 4168 @SystemApi 4169 public boolean isDataConnectivityPossible() { 4170 try { 4171 ITelephony telephony = getITelephony(); 4172 if (telephony != null) 4173 return telephony.isDataConnectivityPossible(); 4174 } catch (RemoteException e) { 4175 Log.e(TAG, "Error calling ITelephony#isDataConnectivityPossible", e); 4176 } 4177 return false; 4178 } 4179 4180 /** @hide */ 4181 @SystemApi 4182 public boolean needsOtaServiceProvisioning() { 4183 try { 4184 ITelephony telephony = getITelephony(); 4185 if (telephony != null) 4186 return telephony.needsOtaServiceProvisioning(); 4187 } catch (RemoteException e) { 4188 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 4189 } 4190 return false; 4191 } 4192 4193 /** @hide */ 4194 @SystemApi 4195 public void setDataEnabled(boolean enable) { 4196 setDataEnabled(SubscriptionManager.getDefaultDataSubId(), enable); 4197 } 4198 4199 /** @hide */ 4200 @SystemApi 4201 public void setDataEnabled(int subId, boolean enable) { 4202 try { 4203 Log.d(TAG, "setDataEnabled: enabled=" + enable); 4204 ITelephony telephony = getITelephony(); 4205 if (telephony != null) 4206 telephony.setDataEnabled(subId, enable); 4207 } catch (RemoteException e) { 4208 Log.e(TAG, "Error calling ITelephony#setDataEnabled", e); 4209 } 4210 } 4211 4212 /** @hide */ 4213 @SystemApi 4214 public boolean getDataEnabled() { 4215 return getDataEnabled(SubscriptionManager.getDefaultDataSubId()); 4216 } 4217 4218 /** @hide */ 4219 @SystemApi 4220 public boolean getDataEnabled(int subId) { 4221 boolean retVal = false; 4222 try { 4223 ITelephony telephony = getITelephony(); 4224 if (telephony != null) 4225 retVal = telephony.getDataEnabled(subId); 4226 } catch (RemoteException e) { 4227 Log.e(TAG, "Error calling ITelephony#getDataEnabled", e); 4228 } catch (NullPointerException e) { 4229 } 4230 Log.d(TAG, "getDataEnabled: retVal=" + retVal); 4231 return retVal; 4232 } 4233 4234 /** 4235 * Returns the result and response from RIL for oem request 4236 * 4237 * @param oemReq the data is sent to ril. 4238 * @param oemResp the respose data from RIL. 4239 * @return negative value request was not handled or get error 4240 * 0 request was handled succesfully, but no response data 4241 * positive value success, data length of response 4242 * @hide 4243 */ 4244 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { 4245 try { 4246 ITelephony telephony = getITelephony(); 4247 if (telephony != null) 4248 return telephony.invokeOemRilRequestRaw(oemReq, oemResp); 4249 } catch (RemoteException ex) { 4250 } catch (NullPointerException ex) { 4251 } 4252 return -1; 4253 } 4254 4255 /** @hide */ 4256 @SystemApi 4257 public void enableVideoCalling(boolean enable) { 4258 try { 4259 ITelephony telephony = getITelephony(); 4260 if (telephony != null) 4261 telephony.enableVideoCalling(enable); 4262 } catch (RemoteException e) { 4263 Log.e(TAG, "Error calling ITelephony#enableVideoCalling", e); 4264 } 4265 } 4266 4267 /** @hide */ 4268 @SystemApi 4269 public boolean isVideoCallingEnabled() { 4270 try { 4271 ITelephony telephony = getITelephony(); 4272 if (telephony != null) 4273 return telephony.isVideoCallingEnabled(getOpPackageName()); 4274 } catch (RemoteException e) { 4275 Log.e(TAG, "Error calling ITelephony#isVideoCallingEnabled", e); 4276 } 4277 return false; 4278 } 4279 4280 /** 4281 * Whether the device supports configuring the DTMF tone length. 4282 * 4283 * @return {@code true} if the DTMF tone length can be changed, and {@code false} otherwise. 4284 */ 4285 public boolean canChangeDtmfToneLength() { 4286 try { 4287 ITelephony telephony = getITelephony(); 4288 if (telephony != null) { 4289 return telephony.canChangeDtmfToneLength(); 4290 } 4291 } catch (RemoteException e) { 4292 Log.e(TAG, "Error calling ITelephony#canChangeDtmfToneLength", e); 4293 } catch (SecurityException e) { 4294 Log.e(TAG, "Permission error calling ITelephony#canChangeDtmfToneLength", e); 4295 } 4296 return false; 4297 } 4298 4299 /** 4300 * Whether the device is a world phone. 4301 * 4302 * @return {@code true} if the device is a world phone, and {@code false} otherwise. 4303 */ 4304 public boolean isWorldPhone() { 4305 try { 4306 ITelephony telephony = getITelephony(); 4307 if (telephony != null) { 4308 return telephony.isWorldPhone(); 4309 } 4310 } catch (RemoteException e) { 4311 Log.e(TAG, "Error calling ITelephony#isWorldPhone", e); 4312 } catch (SecurityException e) { 4313 Log.e(TAG, "Permission error calling ITelephony#isWorldPhone", e); 4314 } 4315 return false; 4316 } 4317 4318 /** 4319 * Whether the phone supports TTY mode. 4320 * 4321 * @return {@code true} if the device supports TTY mode, and {@code false} otherwise. 4322 */ 4323 public boolean isTtyModeSupported() { 4324 try { 4325 ITelephony telephony = getITelephony(); 4326 if (telephony != null) { 4327 return telephony.isTtyModeSupported(); 4328 } 4329 } catch (RemoteException e) { 4330 Log.e(TAG, "Error calling ITelephony#isTtyModeSupported", e); 4331 } catch (SecurityException e) { 4332 Log.e(TAG, "Permission error calling ITelephony#isTtyModeSupported", e); 4333 } 4334 return false; 4335 } 4336 4337 /** 4338 * Whether the phone supports hearing aid compatibility. 4339 * 4340 * @return {@code true} if the device supports hearing aid compatibility, and {@code false} 4341 * otherwise. 4342 */ 4343 public boolean isHearingAidCompatibilitySupported() { 4344 try { 4345 ITelephony telephony = getITelephony(); 4346 if (telephony != null) { 4347 return telephony.isHearingAidCompatibilitySupported(); 4348 } 4349 } catch (RemoteException e) { 4350 Log.e(TAG, "Error calling ITelephony#isHearingAidCompatibilitySupported", e); 4351 } catch (SecurityException e) { 4352 Log.e(TAG, "Permission error calling ITelephony#isHearingAidCompatibilitySupported", e); 4353 } 4354 return false; 4355 } 4356 4357 /** 4358 * This function retrieves value for setting "name+subId", and if that is not found 4359 * retrieves value for setting "name", and if that is not found throws 4360 * SettingNotFoundException 4361 * 4362 * @hide */ 4363 public static int getIntWithSubId(ContentResolver cr, String name, int subId) 4364 throws SettingNotFoundException { 4365 try { 4366 return Settings.Global.getInt(cr, name + subId); 4367 } catch (SettingNotFoundException e) { 4368 try { 4369 int val = Settings.Global.getInt(cr, name); 4370 Settings.Global.putInt(cr, name + subId, val); 4371 4372 /* We are now moving from 'setting' to 'setting+subId', and using the value stored 4373 * for 'setting' as default. Reset the default (since it may have a user set 4374 * value). */ 4375 int default_val = val; 4376 if (name.equals(Settings.Global.MOBILE_DATA)) { 4377 default_val = "true".equalsIgnoreCase( 4378 SystemProperties.get("ro.com.android.mobiledata", "true")) ? 1 : 0; 4379 } else if (name.equals(Settings.Global.DATA_ROAMING)) { 4380 default_val = "true".equalsIgnoreCase( 4381 SystemProperties.get("ro.com.android.dataroaming", "false")) ? 1 : 0; 4382 } 4383 4384 if (default_val != val) { 4385 Settings.Global.putInt(cr, name, default_val); 4386 } 4387 4388 return val; 4389 } catch (SettingNotFoundException exc) { 4390 throw new SettingNotFoundException(name); 4391 } 4392 } 4393 } 4394 4395 /** 4396 * Returns the IMS Registration Status 4397 * @hide 4398 */ 4399 public boolean isImsRegistered() { 4400 try { 4401 ITelephony telephony = getITelephony(); 4402 if (telephony == null) 4403 return false; 4404 return telephony.isImsRegistered(); 4405 } catch (RemoteException ex) { 4406 return false; 4407 } catch (NullPointerException ex) { 4408 return false; 4409 } 4410 } 4411 4412 /** 4413 * Returns the Status of Volte 4414 * @hide 4415 */ 4416 public boolean isVolteAvailable() { 4417 try { 4418 return getITelephony().isVolteAvailable(); 4419 } catch (RemoteException ex) { 4420 return false; 4421 } catch (NullPointerException ex) { 4422 return false; 4423 } 4424 } 4425 4426 /** 4427 * Returns the Status of video telephony (VT) 4428 * @hide 4429 */ 4430 public boolean isVideoTelephonyAvailable() { 4431 try { 4432 return getITelephony().isVideoTelephonyAvailable(); 4433 } catch (RemoteException ex) { 4434 return false; 4435 } catch (NullPointerException ex) { 4436 return false; 4437 } 4438 } 4439 4440 /** 4441 * Returns the Status of Wi-Fi Calling 4442 * @hide 4443 */ 4444 public boolean isWifiCallingAvailable() { 4445 try { 4446 return getITelephony().isWifiCallingAvailable(); 4447 } catch (RemoteException ex) { 4448 return false; 4449 } catch (NullPointerException ex) { 4450 return false; 4451 } 4452 } 4453 4454 /** 4455 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 4456 * 4457 * @hide 4458 */ 4459 public void setSimOperatorNumeric(String numeric) { 4460 int phoneId = getDefaultPhone(); 4461 setSimOperatorNumericForPhone(phoneId, numeric); 4462 } 4463 4464 /** 4465 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 4466 * 4467 * @hide 4468 */ 4469 public void setSimOperatorNumericForPhone(int phoneId, String numeric) { 4470 setTelephonyProperty(phoneId, 4471 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, numeric); 4472 } 4473 4474 /** 4475 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 4476 * 4477 * @hide 4478 */ 4479 public void setSimOperatorName(String name) { 4480 int phoneId = getDefaultPhone(); 4481 setSimOperatorNameForPhone(phoneId, name); 4482 } 4483 4484 /** 4485 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 4486 * 4487 * @hide 4488 */ 4489 public void setSimOperatorNameForPhone(int phoneId, String name) { 4490 setTelephonyProperty(phoneId, 4491 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, name); 4492 } 4493 4494 /** 4495 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the default phone. 4496 * 4497 * @hide 4498 */ 4499 public void setSimCountryIso(String iso) { 4500 int phoneId = getDefaultPhone(); 4501 setSimCountryIsoForPhone(phoneId, iso); 4502 } 4503 4504 /** 4505 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the given phone. 4506 * 4507 * @hide 4508 */ 4509 public void setSimCountryIsoForPhone(int phoneId, String iso) { 4510 setTelephonyProperty(phoneId, 4511 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, iso); 4512 } 4513 4514 /** 4515 * Set TelephonyProperties.PROPERTY_SIM_STATE for the default phone. 4516 * 4517 * @hide 4518 */ 4519 public void setSimState(String state) { 4520 int phoneId = getDefaultPhone(); 4521 setSimStateForPhone(phoneId, state); 4522 } 4523 4524 /** 4525 * Set TelephonyProperties.PROPERTY_SIM_STATE for the given phone. 4526 * 4527 * @hide 4528 */ 4529 public void setSimStateForPhone(int phoneId, String state) { 4530 setTelephonyProperty(phoneId, 4531 TelephonyProperties.PROPERTY_SIM_STATE, state); 4532 } 4533 4534 /** 4535 * Set baseband version for the default phone. 4536 * 4537 * @param version baseband version 4538 * @hide 4539 */ 4540 public void setBasebandVersion(String version) { 4541 int phoneId = getDefaultPhone(); 4542 setBasebandVersionForPhone(phoneId, version); 4543 } 4544 4545 /** 4546 * Set baseband version by phone id. 4547 * 4548 * @param phoneId for which baseband version is set 4549 * @param version baseband version 4550 * @hide 4551 */ 4552 public void setBasebandVersionForPhone(int phoneId, String version) { 4553 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4554 String prop = TelephonyProperties.PROPERTY_BASEBAND_VERSION + 4555 ((phoneId == 0) ? "" : Integer.toString(phoneId)); 4556 SystemProperties.set(prop, version); 4557 } 4558 } 4559 4560 /** 4561 * Set phone type for the default phone. 4562 * 4563 * @param type phone type 4564 * 4565 * @hide 4566 */ 4567 public void setPhoneType(int type) { 4568 int phoneId = getDefaultPhone(); 4569 setPhoneType(phoneId, type); 4570 } 4571 4572 /** 4573 * Set phone type by phone id. 4574 * 4575 * @param phoneId for which phone type is set 4576 * @param type phone type 4577 * 4578 * @hide 4579 */ 4580 public void setPhoneType(int phoneId, int type) { 4581 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4582 TelephonyManager.setTelephonyProperty(phoneId, 4583 TelephonyProperties.CURRENT_ACTIVE_PHONE, String.valueOf(type)); 4584 } 4585 } 4586 4587 /** 4588 * Get OTASP number schema for the default phone. 4589 * 4590 * @param defaultValue default value 4591 * @return OTA SP number schema 4592 * 4593 * @hide 4594 */ 4595 public String getOtaSpNumberSchema(String defaultValue) { 4596 int phoneId = getDefaultPhone(); 4597 return getOtaSpNumberSchemaForPhone(phoneId, defaultValue); 4598 } 4599 4600 /** 4601 * Get OTASP number schema by phone id. 4602 * 4603 * @param phoneId for which OTA SP number schema is get 4604 * @param defaultValue default value 4605 * @return OTA SP number schema 4606 * 4607 * @hide 4608 */ 4609 public String getOtaSpNumberSchemaForPhone(int phoneId, String defaultValue) { 4610 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4611 return TelephonyManager.getTelephonyProperty(phoneId, 4612 TelephonyProperties.PROPERTY_OTASP_NUM_SCHEMA, defaultValue); 4613 } 4614 4615 return defaultValue; 4616 } 4617 4618 /** 4619 * Get SMS receive capable from system property for the default phone. 4620 * 4621 * @param defaultValue default value 4622 * @return SMS receive capable 4623 * 4624 * @hide 4625 */ 4626 public boolean getSmsReceiveCapable(boolean defaultValue) { 4627 int phoneId = getDefaultPhone(); 4628 return getSmsReceiveCapableForPhone(phoneId, defaultValue); 4629 } 4630 4631 /** 4632 * Get SMS receive capable from system property by phone id. 4633 * 4634 * @param phoneId for which SMS receive capable is get 4635 * @param defaultValue default value 4636 * @return SMS receive capable 4637 * 4638 * @hide 4639 */ 4640 public boolean getSmsReceiveCapableForPhone(int phoneId, boolean defaultValue) { 4641 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4642 return Boolean.valueOf(TelephonyManager.getTelephonyProperty(phoneId, 4643 TelephonyProperties.PROPERTY_SMS_RECEIVE, String.valueOf(defaultValue))); 4644 } 4645 4646 return defaultValue; 4647 } 4648 4649 /** 4650 * Get SMS send capable from system property for the default phone. 4651 * 4652 * @param defaultValue default value 4653 * @return SMS send capable 4654 * 4655 * @hide 4656 */ 4657 public boolean getSmsSendCapable(boolean defaultValue) { 4658 int phoneId = getDefaultPhone(); 4659 return getSmsSendCapableForPhone(phoneId, defaultValue); 4660 } 4661 4662 /** 4663 * Get SMS send capable from system property by phone id. 4664 * 4665 * @param phoneId for which SMS send capable is get 4666 * @param defaultValue default value 4667 * @return SMS send capable 4668 * 4669 * @hide 4670 */ 4671 public boolean getSmsSendCapableForPhone(int phoneId, boolean defaultValue) { 4672 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4673 return Boolean.valueOf(TelephonyManager.getTelephonyProperty(phoneId, 4674 TelephonyProperties.PROPERTY_SMS_SEND, String.valueOf(defaultValue))); 4675 } 4676 4677 return defaultValue; 4678 } 4679 4680 /** 4681 * Set the alphabetic name of current registered operator. 4682 * @param name the alphabetic name of current registered operator. 4683 * @hide 4684 */ 4685 public void setNetworkOperatorName(String name) { 4686 int phoneId = getDefaultPhone(); 4687 setNetworkOperatorNameForPhone(phoneId, name); 4688 } 4689 4690 /** 4691 * Set the alphabetic name of current registered operator. 4692 * @param phoneId which phone you want to set 4693 * @param name the alphabetic name of current registered operator. 4694 * @hide 4695 */ 4696 public void setNetworkOperatorNameForPhone(int phoneId, String name) { 4697 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4698 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, name); 4699 } 4700 } 4701 4702 /** 4703 * Set the numeric name (MCC+MNC) of current registered operator. 4704 * @param operator the numeric name (MCC+MNC) of current registered operator 4705 * @hide 4706 */ 4707 public void setNetworkOperatorNumeric(String numeric) { 4708 int phoneId = getDefaultPhone(); 4709 setNetworkOperatorNumericForPhone(phoneId, numeric); 4710 } 4711 4712 /** 4713 * Set the numeric name (MCC+MNC) of current registered operator. 4714 * @param phoneId for which phone type is set 4715 * @param operator the numeric name (MCC+MNC) of current registered operator 4716 * @hide 4717 */ 4718 public void setNetworkOperatorNumericForPhone(int phoneId, String numeric) { 4719 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, numeric); 4720 } 4721 4722 /** 4723 * Set roaming state of the current network, for GSM purposes. 4724 * @param isRoaming is network in romaing state or not 4725 * @hide 4726 */ 4727 public void setNetworkRoaming(boolean isRoaming) { 4728 int phoneId = getDefaultPhone(); 4729 setNetworkRoamingForPhone(phoneId, isRoaming); 4730 } 4731 4732 /** 4733 * Set roaming state of the current network, for GSM purposes. 4734 * @param phoneId which phone you want to set 4735 * @param isRoaming is network in romaing state or not 4736 * @hide 4737 */ 4738 public void setNetworkRoamingForPhone(int phoneId, boolean isRoaming) { 4739 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4740 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, 4741 isRoaming ? "true" : "false"); 4742 } 4743 } 4744 4745 /** 4746 * Set the ISO country code equivalent of the current registered 4747 * operator's MCC (Mobile Country Code). 4748 * @param iso the ISO country code equivalent of the current registered 4749 * @hide 4750 */ 4751 public void setNetworkCountryIso(String iso) { 4752 int phoneId = getDefaultPhone(); 4753 setNetworkCountryIsoForPhone(phoneId, iso); 4754 } 4755 4756 /** 4757 * Set the ISO country code equivalent of the current registered 4758 * operator's MCC (Mobile Country Code). 4759 * @param phoneId which phone you want to set 4760 * @param iso the ISO country code equivalent of the current registered 4761 * @hide 4762 */ 4763 public void setNetworkCountryIsoForPhone(int phoneId, String iso) { 4764 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4765 setTelephonyProperty(phoneId, 4766 TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, iso); 4767 } 4768 } 4769 4770 /** 4771 * Set the network type currently in use on the device for data transmission. 4772 * @param type the network type currently in use on the device for data transmission 4773 * @hide 4774 */ 4775 public void setDataNetworkType(int type) { 4776 int phoneId = getDefaultPhone(); 4777 setDataNetworkTypeForPhone(phoneId, type); 4778 } 4779 4780 /** 4781 * Set the network type currently in use on the device for data transmission. 4782 * @param phoneId which phone you want to set 4783 * @param type the network type currently in use on the device for data transmission 4784 * @hide 4785 */ 4786 public void setDataNetworkTypeForPhone(int phoneId, int type) { 4787 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4788 setTelephonyProperty(phoneId, 4789 TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE, 4790 ServiceState.rilRadioTechnologyToString(type)); 4791 } 4792 } 4793 4794 /** 4795 * Returns the subscription ID for the given phone account. 4796 * @hide 4797 */ 4798 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { 4799 int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 4800 try { 4801 ITelephony service = getITelephony(); 4802 if (service != null) { 4803 retval = service.getSubIdForPhoneAccount(phoneAccount); 4804 } 4805 } catch (RemoteException e) { 4806 } 4807 4808 return retval; 4809 } 4810 4811 /** 4812 * Resets telephony manager settings back to factory defaults. 4813 * 4814 * @hide 4815 */ 4816 public void factoryReset(int subId) { 4817 try { 4818 Log.d(TAG, "factoryReset: subId=" + subId); 4819 ITelephony telephony = getITelephony(); 4820 if (telephony != null) 4821 telephony.factoryReset(subId); 4822 } catch (RemoteException e) { 4823 } 4824 } 4825 4826 4827 /** @hide */ 4828 public String getLocaleFromDefaultSim() { 4829 try { 4830 final ITelephony telephony = getITelephony(); 4831 if (telephony != null) { 4832 return telephony.getLocaleFromDefaultSim(); 4833 } 4834 } catch (RemoteException ex) { 4835 } 4836 return null; 4837 } 4838 4839 /** 4840 * Returns the modem activity info. 4841 * @hide 4842 */ 4843 public ModemActivityInfo getModemActivityInfo() { 4844 try { 4845 ITelephony service = getITelephony(); 4846 if (service != null) { 4847 return service.getModemActivityInfo(); 4848 } 4849 } catch (RemoteException e) { 4850 Log.e(TAG, "Error calling ITelephony#getModemActivityInfo", e); 4851 } 4852 return null; 4853 } 4854 4855 /** 4856 * Returns the service state information on specified subscription. Callers require 4857 * either READ_PRIVILEGED_PHONE_STATE or READ_PHONE_STATE to retrieve the information. 4858 * @hide 4859 */ 4860 public ServiceState getServiceStateForSubscriber(int subId) { 4861 try { 4862 ITelephony service = getITelephony(); 4863 if (service != null) { 4864 return service.getServiceStateForSubscriber(subId, getOpPackageName()); 4865 } 4866 } catch (RemoteException e) { 4867 Log.e(TAG, "Error calling ITelephony#getServiceStateForSubscriber", e); 4868 } 4869 return null; 4870 } 4871} 4872