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