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