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