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