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