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