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