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