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