TelephonyManager.java revision ebe860e5cc8c08885787a8fc1eae4c016b092685
1/* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.telephony; 18 19import static com.android.internal.util.Preconditions.checkNotNull; 20 21import android.annotation.IntDef; 22import android.annotation.Nullable; 23import android.annotation.RequiresPermission; 24import android.annotation.SdkConstant; 25import android.annotation.SdkConstant.SdkConstantType; 26import android.annotation.SystemApi; 27import android.annotation.WorkerThread; 28import android.app.ActivityThread; 29import android.app.PendingIntent; 30import android.content.ContentResolver; 31import android.content.Context; 32import android.content.Intent; 33import android.net.ConnectivityManager; 34import android.net.Uri; 35import android.os.BatteryStats; 36import android.os.Bundle; 37import android.os.Handler; 38import android.os.PersistableBundle; 39import android.os.RemoteException; 40import android.os.ResultReceiver; 41import android.os.ServiceManager; 42import android.os.SystemProperties; 43import android.provider.Settings; 44import android.provider.Settings.SettingNotFoundException; 45import android.service.carrier.CarrierIdentifier; 46import android.telecom.PhoneAccount; 47import android.telecom.PhoneAccountHandle; 48import android.telephony.ims.feature.ImsFeature; 49import android.util.Log; 50 51import com.android.ims.internal.IImsServiceController; 52import com.android.ims.internal.IImsServiceFeatureListener; 53import com.android.internal.annotations.VisibleForTesting; 54import com.android.internal.telecom.ITelecomService; 55import com.android.internal.telephony.CellNetworkScanResult; 56import com.android.internal.telephony.IPhoneSubInfo; 57import com.android.internal.telephony.ITelephony; 58import com.android.internal.telephony.ITelephonyRegistry; 59import com.android.internal.telephony.OperatorInfo; 60import com.android.internal.telephony.PhoneConstants; 61import com.android.internal.telephony.RILConstants; 62import com.android.internal.telephony.TelephonyProperties; 63 64import java.io.FileInputStream; 65import java.io.IOException; 66import java.lang.annotation.Retention; 67import java.lang.annotation.RetentionPolicy; 68import java.util.ArrayList; 69import java.util.Collections; 70import java.util.List; 71import java.util.regex.Matcher; 72import java.util.regex.Pattern; 73 74/** 75 * Provides access to information about the telephony services on 76 * the device. Applications can use the methods in this class to 77 * determine telephony services and states, as well as to access some 78 * types of subscriber information. Applications can also register 79 * a listener to receive notification of telephony state changes. 80 * <p> 81 * You do not instantiate this class directly; instead, you retrieve 82 * a reference to an instance through 83 * {@link android.content.Context#getSystemService 84 * Context.getSystemService(Context.TELEPHONY_SERVICE)}. 85 * 86 * The returned TelephonyManager will use the default subscription for all calls. 87 * To call an API for a specific subscription, use {@link #createForSubscriptionId(int)}. e.g. 88 * <code> 89 * telephonyManager = defaultSubTelephonyManager.createForSubscriptionId(subId); 90 * </code> 91 * <p> 92 * Note that access to some telephony information is 93 * permission-protected. Your application cannot access the protected 94 * information unless it has the appropriate permissions declared in 95 * its manifest file. Where permissions apply, they are noted in the 96 * the methods through which you access the protected information. 97 */ 98public class TelephonyManager { 99 private static final String TAG = "TelephonyManager"; 100 101 /** 102 * The key to use when placing the result of {@link #requestModemActivityInfo(ResultReceiver)} 103 * into the ResultReceiver Bundle. 104 * @hide 105 */ 106 public static final String MODEM_ACTIVITY_RESULT_KEY = 107 BatteryStats.RESULT_RECEIVER_CONTROLLER_KEY; 108 109 private static ITelephonyRegistry sRegistry; 110 111 /** 112 * The allowed states of Wi-Fi calling. 113 * 114 * @hide 115 */ 116 public interface WifiCallingChoices { 117 /** Always use Wi-Fi calling */ 118 static final int ALWAYS_USE = 0; 119 /** Ask the user whether to use Wi-Fi on every call */ 120 static final int ASK_EVERY_TIME = 1; 121 /** Never use Wi-Fi calling */ 122 static final int NEVER_USE = 2; 123 } 124 125 /** The otaspMode passed to PhoneStateListener#onOtaspChanged */ 126 /** @hide */ 127 static public final int OTASP_UNINITIALIZED = 0; 128 /** @hide */ 129 static public final int OTASP_UNKNOWN = 1; 130 /** @hide */ 131 static public final int OTASP_NEEDED = 2; 132 /** @hide */ 133 static public final int OTASP_NOT_NEEDED = 3; 134 /* OtaUtil has conflict enum 4: OtaUtils.OTASP_FAILURE_SPC_RETRIES */ 135 /** @hide */ 136 static public final int OTASP_SIM_UNPROVISIONED = 5; 137 138 139 private final Context mContext; 140 private final int mSubId; 141 private SubscriptionManager mSubscriptionManager; 142 143 private static String multiSimConfig = 144 SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG); 145 146 /** Enum indicating multisim variants 147 * DSDS - Dual SIM Dual Standby 148 * DSDA - Dual SIM Dual Active 149 * TSTS - Triple SIM Triple Standby 150 **/ 151 /** @hide */ 152 public enum MultiSimVariants { 153 DSDS, 154 DSDA, 155 TSTS, 156 UNKNOWN 157 }; 158 159 /** @hide */ 160 public TelephonyManager(Context context) { 161 this(context, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID); 162 } 163 164 /** @hide */ 165 public TelephonyManager(Context context, int subId) { 166 mSubId = subId; 167 Context appContext = context.getApplicationContext(); 168 if (appContext != null) { 169 mContext = appContext; 170 } else { 171 mContext = context; 172 } 173 mSubscriptionManager = SubscriptionManager.from(mContext); 174 175 if (sRegistry == null) { 176 sRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService( 177 "telephony.registry")); 178 } 179 } 180 181 /** @hide */ 182 private TelephonyManager() { 183 mContext = null; 184 mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 185 } 186 187 private static TelephonyManager sInstance = new TelephonyManager(); 188 189 /** @hide 190 /* @deprecated - use getSystemService as described above */ 191 public static TelephonyManager getDefault() { 192 return sInstance; 193 } 194 195 private String getOpPackageName() { 196 // For legacy reasons the TelephonyManager has API for getting 197 // a static instance with no context set preventing us from 198 // getting the op package name. As a workaround we do a best 199 // effort and get the context from the current activity thread. 200 if (mContext != null) { 201 return mContext.getOpPackageName(); 202 } 203 return ActivityThread.currentOpPackageName(); 204 } 205 206 /** 207 * Returns the multi SIM variant 208 * Returns DSDS for Dual SIM Dual Standby 209 * Returns DSDA for Dual SIM Dual Active 210 * Returns TSTS for Triple SIM Triple Standby 211 * Returns UNKNOWN for others 212 */ 213 /** {@hide} */ 214 public MultiSimVariants getMultiSimConfiguration() { 215 String mSimConfig = 216 SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG); 217 if (mSimConfig.equals("dsds")) { 218 return MultiSimVariants.DSDS; 219 } else if (mSimConfig.equals("dsda")) { 220 return MultiSimVariants.DSDA; 221 } else if (mSimConfig.equals("tsts")) { 222 return MultiSimVariants.TSTS; 223 } else { 224 return MultiSimVariants.UNKNOWN; 225 } 226 } 227 228 229 /** 230 * Returns the number of phones available. 231 * Returns 0 if none of voice, sms, data is not supported 232 * Returns 1 for Single standby mode (Single SIM functionality) 233 * Returns 2 for Dual standby mode.(Dual SIM functionality) 234 */ 235 public int getPhoneCount() { 236 int phoneCount = 1; 237 switch (getMultiSimConfiguration()) { 238 case UNKNOWN: 239 // if voice or sms or data is supported, return 1 otherwise 0 240 if (isVoiceCapable() || isSmsCapable()) { 241 phoneCount = 1; 242 } else { 243 // todo: try to clean this up further by getting rid of the nested conditions 244 if (mContext == null) { 245 phoneCount = 1; 246 } else { 247 // check for data support 248 ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService( 249 Context.CONNECTIVITY_SERVICE); 250 if (cm == null) { 251 phoneCount = 1; 252 } else { 253 if (cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)) { 254 phoneCount = 1; 255 } else { 256 phoneCount = 0; 257 } 258 } 259 } 260 } 261 break; 262 case DSDS: 263 case DSDA: 264 phoneCount = PhoneConstants.MAX_PHONE_COUNT_DUAL_SIM; 265 break; 266 case TSTS: 267 phoneCount = PhoneConstants.MAX_PHONE_COUNT_TRI_SIM; 268 break; 269 } 270 return phoneCount; 271 } 272 273 /** {@hide} */ 274 public static TelephonyManager from(Context context) { 275 return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 276 } 277 278 /** 279 * Create a new TelephonyManager object pinned to the given subscription ID. 280 * 281 * @return a TelephonyManager that uses the given subId for all calls. 282 */ 283 public TelephonyManager createForSubscriptionId(int subId) { 284 // Don't reuse any TelephonyManager objects. 285 return new TelephonyManager(mContext, subId); 286 } 287 288 /** 289 * Create a new TelephonyManager object pinned to the subscription ID associated with the given 290 * phone account. 291 * 292 * @return a TelephonyManager that uses the given phone account for all calls, or {@code null} 293 * if the phone account does not correspond to a valid subscription ID. 294 */ 295 @Nullable 296 public TelephonyManager createForPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) { 297 int subId = getSubIdForPhoneAccountHandle(phoneAccountHandle); 298 if (!SubscriptionManager.isValidSubscriptionId(subId)) { 299 return null; 300 } 301 return new TelephonyManager(mContext, subId); 302 } 303 304 /** {@hide} */ 305 public boolean isMultiSimEnabled() { 306 return (multiSimConfig.equals("dsds") || multiSimConfig.equals("dsda") || 307 multiSimConfig.equals("tsts")); 308 } 309 310 // 311 // Broadcast Intent actions 312 // 313 314 /** 315 * Broadcast intent action indicating that the call state 316 * on the device has changed. 317 * 318 * <p> 319 * The {@link #EXTRA_STATE} extra indicates the new call state. 320 * If the new state is RINGING, a second extra 321 * {@link #EXTRA_INCOMING_NUMBER} provides the incoming phone number as 322 * a String. 323 * 324 * <p class="note"> 325 * Requires the READ_PHONE_STATE permission. 326 * 327 * <p class="note"> 328 * This was a {@link android.content.Context#sendStickyBroadcast sticky} 329 * broadcast in version 1.0, but it is no longer sticky. 330 * Instead, use {@link #getCallState} to synchronously query the current call state. 331 * 332 * @see #EXTRA_STATE 333 * @see #EXTRA_INCOMING_NUMBER 334 * @see #getCallState 335 */ 336 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 337 public static final String ACTION_PHONE_STATE_CHANGED = 338 "android.intent.action.PHONE_STATE"; 339 340 /** 341 * The Phone app sends this intent when a user opts to respond-via-message during an incoming 342 * call. By default, the device's default SMS app consumes this message and sends a text message 343 * to the caller. A third party app can also provide this functionality by consuming this Intent 344 * with a {@link android.app.Service} and sending the message using its own messaging system. 345 * <p>The intent contains a URI (available from {@link android.content.Intent#getData}) 346 * describing the recipient, using either the {@code sms:}, {@code smsto:}, {@code mms:}, 347 * or {@code mmsto:} URI schema. Each of these URI schema carry the recipient information the 348 * same way: the path part of the URI contains the recipient's phone number or a comma-separated 349 * set of phone numbers if there are multiple recipients. For example, {@code 350 * smsto:2065551234}.</p> 351 * 352 * <p>The intent may also contain extras for the message text (in {@link 353 * android.content.Intent#EXTRA_TEXT}) and a message subject 354 * (in {@link android.content.Intent#EXTRA_SUBJECT}).</p> 355 * 356 * <p class="note"><strong>Note:</strong> 357 * The intent-filter that consumes this Intent needs to be in a {@link android.app.Service} 358 * that requires the 359 * permission {@link android.Manifest.permission#SEND_RESPOND_VIA_MESSAGE}.</p> 360 * <p>For example, the service that receives this intent can be declared in the manifest file 361 * with an intent filter like this:</p> 362 * <pre> 363 * <!-- Service that delivers SMS messages received from the phone "quick response" --> 364 * <service android:name=".HeadlessSmsSendService" 365 * android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE" 366 * android:exported="true" > 367 * <intent-filter> 368 * <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" /> 369 * <category android:name="android.intent.category.DEFAULT" /> 370 * <data android:scheme="sms" /> 371 * <data android:scheme="smsto" /> 372 * <data android:scheme="mms" /> 373 * <data android:scheme="mmsto" /> 374 * </intent-filter> 375 * </service></pre> 376 * <p> 377 * Output: nothing. 378 */ 379 @SdkConstant(SdkConstantType.SERVICE_ACTION) 380 public static final String ACTION_RESPOND_VIA_MESSAGE = 381 "android.intent.action.RESPOND_VIA_MESSAGE"; 382 383 /** 384 * The emergency dialer may choose to present activities with intent filters for this 385 * action as emergency assistance buttons that launch the activity when clicked. 386 * 387 * @hide 388 */ 389 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 390 public static final String ACTION_EMERGENCY_ASSISTANCE = 391 "android.telephony.action.EMERGENCY_ASSISTANCE"; 392 393 /** 394 * A boolean meta-data value indicating whether the voicemail settings should be hidden in the 395 * call settings page launched by 396 * {@link android.telecom.TelecomManager#ACTION_SHOW_CALL_SETTINGS}. 397 * Dialer implementations (see {@link android.telecom.TelecomManager#getDefaultDialerPackage()}) 398 * which would also like to manage voicemail settings should set this meta-data to {@code true} 399 * in the manifest registration of their application. 400 * 401 * @see android.telecom.TelecomManager#ACTION_SHOW_CALL_SETTINGS 402 * @see #ACTION_CONFIGURE_VOICEMAIL 403 * @see #EXTRA_HIDE_PUBLIC_SETTINGS 404 */ 405 public static final String METADATA_HIDE_VOICEMAIL_SETTINGS_MENU = 406 "android.telephony.HIDE_VOICEMAIL_SETTINGS_MENU"; 407 408 /** 409 * Open the voicemail settings activity to make changes to voicemail configuration. 410 * 411 * <p> 412 * The {@link #EXTRA_HIDE_PUBLIC_SETTINGS} hides settings the dialer will modify through public 413 * API if set. 414 * 415 * @see #EXTRA_HIDE_PUBLIC_SETTINGS 416 */ 417 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 418 public static final String ACTION_CONFIGURE_VOICEMAIL = 419 "android.telephony.action.CONFIGURE_VOICEMAIL"; 420 421 /** 422 * The boolean value indicating whether the voicemail settings activity launched by {@link 423 * #ACTION_CONFIGURE_VOICEMAIL} should hide settings accessible through public API. This is 424 * used by dialer implementations which provides their own voicemail settings UI, but still 425 * needs to expose device specific voicemail settings to the user. 426 * 427 * @see #ACTION_CONFIGURE_VOICEMAIL 428 * @see #METADATA_HIDE_VOICEMAIL_SETTINGS_MENU 429 */ 430 public static final String EXTRA_HIDE_PUBLIC_SETTINGS = 431 "android.telephony.extra.HIDE_PUBLIC_SETTINGS"; 432 433 /** 434 * @hide 435 */ 436 public static final boolean EMERGENCY_ASSISTANCE_ENABLED = true; 437 438 /** 439 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 440 * for a String containing the new call state. 441 * 442 * <p class="note"> 443 * Retrieve with 444 * {@link android.content.Intent#getStringExtra(String)}. 445 * 446 * @see #EXTRA_STATE_IDLE 447 * @see #EXTRA_STATE_RINGING 448 * @see #EXTRA_STATE_OFFHOOK 449 */ 450 public static final String EXTRA_STATE = PhoneConstants.STATE_KEY; 451 452 /** 453 * Value used with {@link #EXTRA_STATE} corresponding to 454 * {@link #CALL_STATE_IDLE}. 455 */ 456 public static final String EXTRA_STATE_IDLE = PhoneConstants.State.IDLE.toString(); 457 458 /** 459 * Value used with {@link #EXTRA_STATE} corresponding to 460 * {@link #CALL_STATE_RINGING}. 461 */ 462 public static final String EXTRA_STATE_RINGING = PhoneConstants.State.RINGING.toString(); 463 464 /** 465 * Value used with {@link #EXTRA_STATE} corresponding to 466 * {@link #CALL_STATE_OFFHOOK}. 467 */ 468 public static final String EXTRA_STATE_OFFHOOK = PhoneConstants.State.OFFHOOK.toString(); 469 470 /** 471 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 472 * for a String containing the incoming phone number. 473 * Only valid when the new call state is RINGING. 474 * 475 * <p class="note"> 476 * Retrieve with 477 * {@link android.content.Intent#getStringExtra(String)}. 478 */ 479 public static final String EXTRA_INCOMING_NUMBER = "incoming_number"; 480 481 /** 482 * Broadcast intent action indicating that a precise call state 483 * (cellular) on the device has changed. 484 * 485 * <p> 486 * The {@link #EXTRA_RINGING_CALL_STATE} extra indicates the ringing call state. 487 * The {@link #EXTRA_FOREGROUND_CALL_STATE} extra indicates the foreground call state. 488 * The {@link #EXTRA_BACKGROUND_CALL_STATE} extra indicates the background call state. 489 * The {@link #EXTRA_DISCONNECT_CAUSE} extra indicates the disconnect cause. 490 * The {@link #EXTRA_PRECISE_DISCONNECT_CAUSE} extra indicates the precise disconnect cause. 491 * 492 * <p class="note"> 493 * Requires the READ_PRECISE_PHONE_STATE permission. 494 * 495 * @see #EXTRA_RINGING_CALL_STATE 496 * @see #EXTRA_FOREGROUND_CALL_STATE 497 * @see #EXTRA_BACKGROUND_CALL_STATE 498 * @see #EXTRA_DISCONNECT_CAUSE 499 * @see #EXTRA_PRECISE_DISCONNECT_CAUSE 500 * 501 * <p class="note"> 502 * Requires the READ_PRECISE_PHONE_STATE permission. 503 * 504 * @hide 505 */ 506 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 507 public static final String ACTION_PRECISE_CALL_STATE_CHANGED = 508 "android.intent.action.PRECISE_CALL_STATE"; 509 510 /** 511 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 512 * for an integer containing the state of the current ringing call. 513 * 514 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 515 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 516 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 517 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 518 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 519 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 520 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 521 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 522 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 523 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 524 * 525 * <p class="note"> 526 * Retrieve with 527 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 528 * 529 * @hide 530 */ 531 public static final String EXTRA_RINGING_CALL_STATE = "ringing_state"; 532 533 /** 534 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 535 * for an integer containing the state of the current foreground call. 536 * 537 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 538 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 539 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 540 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 541 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 542 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 543 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 544 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 545 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 546 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 547 * 548 * <p class="note"> 549 * Retrieve with 550 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 551 * 552 * @hide 553 */ 554 public static final String EXTRA_FOREGROUND_CALL_STATE = "foreground_state"; 555 556 /** 557 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 558 * for an integer containing the state of the current background call. 559 * 560 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 561 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 562 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 563 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 564 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 565 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 566 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 567 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 568 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 569 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 570 * 571 * <p class="note"> 572 * Retrieve with 573 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 574 * 575 * @hide 576 */ 577 public static final String EXTRA_BACKGROUND_CALL_STATE = "background_state"; 578 579 /** 580 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 581 * for an integer containing the disconnect cause. 582 * 583 * @see DisconnectCause 584 * 585 * <p class="note"> 586 * Retrieve with 587 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 588 * 589 * @hide 590 */ 591 public static final String EXTRA_DISCONNECT_CAUSE = "disconnect_cause"; 592 593 /** 594 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 595 * for an integer containing the disconnect cause provided by the RIL. 596 * 597 * @see PreciseDisconnectCause 598 * 599 * <p class="note"> 600 * Retrieve with 601 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 602 * 603 * @hide 604 */ 605 public static final String EXTRA_PRECISE_DISCONNECT_CAUSE = "precise_disconnect_cause"; 606 607 /** 608 * Broadcast intent action indicating a data connection has changed, 609 * providing precise information about the connection. 610 * 611 * <p> 612 * The {@link #EXTRA_DATA_STATE} extra indicates the connection state. 613 * The {@link #EXTRA_DATA_NETWORK_TYPE} extra indicates the connection network type. 614 * The {@link #EXTRA_DATA_APN_TYPE} extra indicates the APN type. 615 * The {@link #EXTRA_DATA_APN} extra indicates the APN. 616 * The {@link #EXTRA_DATA_CHANGE_REASON} extra indicates the connection change reason. 617 * The {@link #EXTRA_DATA_IFACE_PROPERTIES} extra indicates the connection interface. 618 * The {@link #EXTRA_DATA_FAILURE_CAUSE} extra indicates the connection fail cause. 619 * 620 * <p class="note"> 621 * Requires the READ_PRECISE_PHONE_STATE permission. 622 * 623 * @see #EXTRA_DATA_STATE 624 * @see #EXTRA_DATA_NETWORK_TYPE 625 * @see #EXTRA_DATA_APN_TYPE 626 * @see #EXTRA_DATA_APN 627 * @see #EXTRA_DATA_CHANGE_REASON 628 * @see #EXTRA_DATA_IFACE 629 * @see #EXTRA_DATA_FAILURE_CAUSE 630 * @hide 631 */ 632 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 633 public static final String ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED = 634 "android.intent.action.PRECISE_DATA_CONNECTION_STATE_CHANGED"; 635 636 /** 637 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 638 * for an integer containing the state of the current data connection. 639 * 640 * @see TelephonyManager#DATA_UNKNOWN 641 * @see TelephonyManager#DATA_DISCONNECTED 642 * @see TelephonyManager#DATA_CONNECTING 643 * @see TelephonyManager#DATA_CONNECTED 644 * @see TelephonyManager#DATA_SUSPENDED 645 * 646 * <p class="note"> 647 * Retrieve with 648 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 649 * 650 * @hide 651 */ 652 public static final String EXTRA_DATA_STATE = PhoneConstants.STATE_KEY; 653 654 /** 655 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 656 * for an integer containing the network type. 657 * 658 * @see TelephonyManager#NETWORK_TYPE_UNKNOWN 659 * @see TelephonyManager#NETWORK_TYPE_GPRS 660 * @see TelephonyManager#NETWORK_TYPE_EDGE 661 * @see TelephonyManager#NETWORK_TYPE_UMTS 662 * @see TelephonyManager#NETWORK_TYPE_CDMA 663 * @see TelephonyManager#NETWORK_TYPE_EVDO_0 664 * @see TelephonyManager#NETWORK_TYPE_EVDO_A 665 * @see TelephonyManager#NETWORK_TYPE_1xRTT 666 * @see TelephonyManager#NETWORK_TYPE_HSDPA 667 * @see TelephonyManager#NETWORK_TYPE_HSUPA 668 * @see TelephonyManager#NETWORK_TYPE_HSPA 669 * @see TelephonyManager#NETWORK_TYPE_IDEN 670 * @see TelephonyManager#NETWORK_TYPE_EVDO_B 671 * @see TelephonyManager#NETWORK_TYPE_LTE 672 * @see TelephonyManager#NETWORK_TYPE_EHRPD 673 * @see TelephonyManager#NETWORK_TYPE_HSPAP 674 * 675 * <p class="note"> 676 * Retrieve with 677 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 678 * 679 * @hide 680 */ 681 public static final String EXTRA_DATA_NETWORK_TYPE = PhoneConstants.DATA_NETWORK_TYPE_KEY; 682 683 /** 684 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 685 * for an String containing the data APN type. 686 * 687 * <p class="note"> 688 * Retrieve with 689 * {@link android.content.Intent#getStringExtra(String name)}. 690 * 691 * @hide 692 */ 693 public static final String EXTRA_DATA_APN_TYPE = PhoneConstants.DATA_APN_TYPE_KEY; 694 695 /** 696 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 697 * for an String containing the data APN. 698 * 699 * <p class="note"> 700 * Retrieve with 701 * {@link android.content.Intent#getStringExtra(String name)}. 702 * 703 * @hide 704 */ 705 public static final String EXTRA_DATA_APN = PhoneConstants.DATA_APN_KEY; 706 707 /** 708 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 709 * for an String representation of the change reason. 710 * 711 * <p class="note"> 712 * Retrieve with 713 * {@link android.content.Intent#getStringExtra(String name)}. 714 * 715 * @hide 716 */ 717 public static final String EXTRA_DATA_CHANGE_REASON = PhoneConstants.STATE_CHANGE_REASON_KEY; 718 719 /** 720 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 721 * for an String representation of the data interface. 722 * 723 * <p class="note"> 724 * Retrieve with 725 * {@link android.content.Intent#getParcelableExtra(String name)}. 726 * 727 * @hide 728 */ 729 public static final String EXTRA_DATA_LINK_PROPERTIES_KEY = PhoneConstants.DATA_LINK_PROPERTIES_KEY; 730 731 /** 732 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 733 * for the data connection fail cause. 734 * 735 * <p class="note"> 736 * Retrieve with 737 * {@link android.content.Intent#getStringExtra(String name)}. 738 * 739 * @hide 740 */ 741 public static final String EXTRA_DATA_FAILURE_CAUSE = PhoneConstants.DATA_FAILURE_CAUSE_KEY; 742 743 /** 744 * Broadcast intent action for letting the default dialer to know to show voicemail 745 * notification. 746 * 747 * <p> 748 * The {@link #EXTRA_PHONE_ACCOUNT_HANDLE} extra indicates which {@link PhoneAccountHandle} the 749 * voicemail is received on. 750 * The {@link #EXTRA_NOTIFICATION_COUNT} extra indicates the total numbers of unheard 751 * voicemails. 752 * The {@link #EXTRA_VOICEMAIL_NUMBER} extra indicates the voicemail number if available. 753 * The {@link #EXTRA_CALL_VOICEMAIL_INTENT} extra is a {@link android.app.PendingIntent} that 754 * will call the voicemail number when sent. This extra will be empty if the voicemail number 755 * is not set, and {@link #EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT} will be set instead. 756 * The {@link #EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT} extra is a 757 * {@link android.app.PendingIntent} that will launch the voicemail settings. This extra is only 758 * available when the voicemail number is not set. 759 * 760 * @see #EXTRA_PHONE_ACCOUNT_HANDLE 761 * @see #EXTRA_NOTIFICATION_COUNT 762 * @see #EXTRA_VOICEMAIL_NUMBER 763 * @see #EXTRA_CALL_VOICEMAIL_INTENT 764 * @see #EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT 765 */ 766 public static final String ACTION_SHOW_VOICEMAIL_NOTIFICATION = 767 "android.telephony.action.SHOW_VOICEMAIL_NOTIFICATION"; 768 769 /** 770 * The extra used with an {@link #ACTION_SHOW_VOICEMAIL_NOTIFICATION} {@code Intent} to specify 771 * the {@link PhoneAccountHandle} the notification is for. 772 * <p class="note"> 773 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}. 774 */ 775 public static final String EXTRA_PHONE_ACCOUNT_HANDLE = 776 "android.telephony.extra.PHONE_ACCOUNT_HANDLE"; 777 778 /** 779 * The number of voice messages associated with the notification. 780 */ 781 public static final String EXTRA_NOTIFICATION_COUNT = 782 "android.telephony.extra.NOTIFICATION_COUNT"; 783 784 /** 785 * The voicemail number. 786 */ 787 public static final String EXTRA_VOICEMAIL_NUMBER = 788 "android.telephony.extra.VOICEMAIL_NUMBER"; 789 790 /** 791 * The intent to call voicemail. 792 */ 793 public static final String EXTRA_CALL_VOICEMAIL_INTENT = 794 "android.telephony.extra.CALL_VOICEMAIL_INTENT"; 795 796 /** 797 * The intent to launch voicemail settings. 798 */ 799 public static final String EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT = 800 "android.telephony.extra.LAUNCH_VOICEMAIL_SETTINGS_INTENT"; 801 802 /** 803 * {@link android.telecom.Connection} event used to indicate that an IMS call has be 804 * successfully handed over from WIFI to LTE. 805 * <p> 806 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 807 * The {@link Bundle} parameter is expected to be null when this connection event is used. 808 * @hide 809 */ 810 public static final String EVENT_HANDOVER_VIDEO_FROM_WIFI_TO_LTE = 811 "android.telephony.event.EVENT_HANDOVER_VIDEO_FROM_WIFI_TO_LTE"; 812 813 /** 814 * {@link android.telecom.Connection} event used to indicate that an IMS call failed to be 815 * handed over from LTE to WIFI. 816 * <p> 817 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 818 * The {@link Bundle} parameter is expected to be null when this connection event is used. 819 * @hide 820 */ 821 public static final String EVENT_HANDOVER_TO_WIFI_FAILED = 822 "android.telephony.event.EVENT_HANDOVER_TO_WIFI_FAILED"; 823 824 /** 825 * {@link android.telecom.Connection} event used to indicate that a video call was downgraded to 826 * audio because the data limit was reached. 827 * <p> 828 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 829 * The {@link Bundle} parameter is expected to be null when this connection event is used. 830 * @hide 831 */ 832 public static final String EVENT_DOWNGRADE_DATA_LIMIT_REACHED = 833 "android.telephony.event.EVENT_DOWNGRADE_DATA_LIMIT_REACHED"; 834 835 /** 836 * {@link android.telecom.Connection} event used to indicate that a video call was downgraded to 837 * audio because the data was disabled. 838 * <p> 839 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 840 * The {@link Bundle} parameter is expected to be null when this connection event is used. 841 * @hide 842 */ 843 public static final String EVENT_DOWNGRADE_DATA_DISABLED = 844 "android.telephony.event.EVENT_DOWNGRADE_DATA_DISABLED"; 845 846 /** 847 * {@link android.telecom.Connection} event used to indicate that the InCall UI should notify 848 * the user when an international call is placed while on WFC only. 849 * <p> 850 * Used when the carrier config value 851 * {@link CarrierConfigManager#KEY_NOTIFY_INTERNATIONAL_CALL_ON_WFC_BOOL} is true, the device 852 * is on WFC (VoLTE not available) and an international number is dialed. 853 * <p> 854 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 855 * The {@link Bundle} parameter is expected to be null when this connection event is used. 856 * @hide 857 */ 858 public static final String EVENT_NOTIFY_INTERNATIONAL_CALL_ON_WFC = 859 "android.telephony.event.EVENT_NOTIFY_INTERNATIONAL_CALL_ON_WFC"; 860 861 /* Visual voicemail protocols */ 862 863 /** 864 * The OMTP protocol. 865 */ 866 public static final String VVM_TYPE_OMTP = "vvm_type_omtp"; 867 868 /** 869 * A flavor of OMTP protocol with a different mobile originated (MO) format 870 */ 871 public static final String VVM_TYPE_CVVM = "vvm_type_cvvm"; 872 873 /** 874 * @hide 875 */ 876 public static final String USSD_RESPONSE = "USSD_RESPONSE"; 877 878 /** 879 * USSD return code success. 880 */ 881 public static final int USSD_RETURN_SUCCESS = 100; 882 883 /** 884 * USSD return code for failure case. 885 */ 886 public static final int USSD_RETURN_FAILURE = -1; 887 888 /** 889 * USSD return code for failure case. 890 */ 891 public static final int USSD_ERROR_SERVICE_UNAVAIL = -2; 892 893 // 894 // 895 // Device Info 896 // 897 // 898 899 /** 900 * Returns the software version number for the device, for example, 901 * the IMEI/SV for GSM phones. Return null if the software version is 902 * not available. 903 * 904 * <p>Requires Permission: 905 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 906 */ 907 public String getDeviceSoftwareVersion() { 908 return getDeviceSoftwareVersion(getDefaultSim()); 909 } 910 911 /** 912 * Returns the software version number for the device, for example, 913 * the IMEI/SV for GSM phones. Return null if the software version is 914 * not available. 915 * 916 * <p>Requires Permission: 917 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 918 * 919 * @param slotIndex of which deviceID is returned 920 */ 921 /** {@hide} */ 922 public String getDeviceSoftwareVersion(int slotIndex) { 923 ITelephony telephony = getITelephony(); 924 if (telephony == null) return null; 925 926 try { 927 return telephony.getDeviceSoftwareVersionForSlot(slotIndex, getOpPackageName()); 928 } catch (RemoteException ex) { 929 return null; 930 } catch (NullPointerException ex) { 931 return null; 932 } 933 } 934 935 /** 936 * Returns the unique device ID, for example, the IMEI for GSM and the MEID 937 * or ESN for CDMA phones. Return null if device ID is not available. 938 * 939 * <p>Requires Permission: 940 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 941 * 942 * @deprecated Use (@link getImei} which returns IMEI for GSM or (@link getMeid} which returns 943 * MEID for CDMA. 944 */ 945 @Deprecated 946 public String getDeviceId() { 947 try { 948 ITelephony telephony = getITelephony(); 949 if (telephony == null) 950 return null; 951 return telephony.getDeviceId(mContext.getOpPackageName()); 952 } catch (RemoteException ex) { 953 return null; 954 } catch (NullPointerException ex) { 955 return null; 956 } 957 } 958 959 /** 960 * Returns the unique device ID of a subscription, for example, the IMEI for 961 * GSM and the MEID for CDMA phones. Return null if device ID is not available. 962 * 963 * <p>Requires Permission: 964 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 965 * 966 * @param slotIndex of which deviceID is returned 967 * 968 * @deprecated Use (@link getImei} which returns IMEI for GSM or (@link getMeid} which returns 969 * MEID for CDMA. 970 */ 971 @Deprecated 972 public String getDeviceId(int slotIndex) { 973 // FIXME this assumes phoneId == slotIndex 974 try { 975 IPhoneSubInfo info = getSubscriberInfo(); 976 if (info == null) 977 return null; 978 return info.getDeviceIdForPhone(slotIndex, mContext.getOpPackageName()); 979 } catch (RemoteException ex) { 980 return null; 981 } catch (NullPointerException ex) { 982 return null; 983 } 984 } 985 986 /** 987 * Returns the IMEI (International Mobile Equipment Identity). Return null if IMEI is not 988 * available. 989 * 990 * <p>Requires Permission: 991 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 992 */ 993 public String getImei() { 994 return getImei(getDefaultSim()); 995 } 996 997 /** 998 * Returns the IMEI (International Mobile Equipment Identity). Return null if IMEI is not 999 * available. 1000 * 1001 * <p>Requires Permission: 1002 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1003 * 1004 * @param slotIndex of which IMEI is returned 1005 */ 1006 public String getImei(int slotIndex) { 1007 ITelephony telephony = getITelephony(); 1008 if (telephony == null) return null; 1009 1010 try { 1011 return telephony.getImeiForSlot(slotIndex, getOpPackageName()); 1012 } catch (RemoteException ex) { 1013 return null; 1014 } catch (NullPointerException ex) { 1015 return null; 1016 } 1017 } 1018 1019 /** 1020 * Returns the MEID (Mobile Equipment Identifier). Return null if MEID is not available. 1021 * 1022 * <p>Requires Permission: 1023 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1024 */ 1025 public String getMeid() { 1026 return getMeid(getDefaultSim()); 1027 } 1028 1029 /** 1030 * Returns the MEID (Mobile Equipment Identifier). Return null if MEID is not available. 1031 * 1032 * <p>Requires Permission: 1033 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1034 * 1035 * @param slotIndex of which MEID is returned 1036 */ 1037 public String getMeid(int slotIndex) { 1038 ITelephony telephony = getITelephony(); 1039 if (telephony == null) return null; 1040 1041 try { 1042 return telephony.getMeidForSlot(slotIndex, getOpPackageName()); 1043 } catch (RemoteException ex) { 1044 return null; 1045 } catch (NullPointerException ex) { 1046 return null; 1047 } 1048 } 1049 1050 /** 1051 * Returns the NAI. Return null if NAI is not available. 1052 * 1053 */ 1054 /** {@hide}*/ 1055 public String getNai() { 1056 return getNai(getDefaultSim()); 1057 } 1058 1059 /** 1060 * Returns the NAI. Return null if NAI is not available. 1061 * 1062 * @param slotIndex of which Nai is returned 1063 */ 1064 /** {@hide}*/ 1065 public String getNai(int slotIndex) { 1066 int[] subId = SubscriptionManager.getSubId(slotIndex); 1067 try { 1068 IPhoneSubInfo info = getSubscriberInfo(); 1069 if (info == null) 1070 return null; 1071 String nai = info.getNaiForSubscriber(subId[0], mContext.getOpPackageName()); 1072 if (Log.isLoggable(TAG, Log.VERBOSE)) { 1073 Rlog.v(TAG, "Nai = " + nai); 1074 } 1075 return nai; 1076 } catch (RemoteException ex) { 1077 return null; 1078 } catch (NullPointerException ex) { 1079 return null; 1080 } 1081 } 1082 1083 /** 1084 * Returns the current location of the device. 1085 *<p> 1086 * If there is only one radio in the device and that radio has an LTE connection, 1087 * this method will return null. The implementation must not to try add LTE 1088 * identifiers into the existing cdma/gsm classes. 1089 *<p> 1090 * In the future this call will be deprecated. 1091 *<p> 1092 * @return Current location of the device or null if not available. 1093 * 1094 * <p>Requires Permission: 1095 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or 1096 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION}. 1097 */ 1098 public CellLocation getCellLocation() { 1099 try { 1100 ITelephony telephony = getITelephony(); 1101 if (telephony == null) { 1102 Rlog.d(TAG, "getCellLocation returning null because telephony is null"); 1103 return null; 1104 } 1105 Bundle bundle = telephony.getCellLocation(mContext.getOpPackageName()); 1106 if (bundle.isEmpty()) { 1107 Rlog.d(TAG, "getCellLocation returning null because bundle is empty"); 1108 return null; 1109 } 1110 CellLocation cl = CellLocation.newFromBundle(bundle); 1111 if (cl.isEmpty()) { 1112 Rlog.d(TAG, "getCellLocation returning null because CellLocation is empty"); 1113 return null; 1114 } 1115 return cl; 1116 } catch (RemoteException ex) { 1117 Rlog.d(TAG, "getCellLocation returning null due to RemoteException " + ex); 1118 return null; 1119 } catch (NullPointerException ex) { 1120 Rlog.d(TAG, "getCellLocation returning null due to NullPointerException " + ex); 1121 return null; 1122 } 1123 } 1124 1125 /** 1126 * Enables location update notifications. {@link PhoneStateListener#onCellLocationChanged 1127 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 1128 * 1129 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 1130 * CONTROL_LOCATION_UPDATES} 1131 * 1132 * @hide 1133 */ 1134 public void enableLocationUpdates() { 1135 enableLocationUpdates(getSubId()); 1136 } 1137 1138 /** 1139 * Enables location update notifications for a subscription. 1140 * {@link PhoneStateListener#onCellLocationChanged 1141 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 1142 * 1143 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 1144 * CONTROL_LOCATION_UPDATES} 1145 * 1146 * @param subId for which the location updates are enabled 1147 * @hide 1148 */ 1149 public void enableLocationUpdates(int subId) { 1150 try { 1151 ITelephony telephony = getITelephony(); 1152 if (telephony != null) 1153 telephony.enableLocationUpdatesForSubscriber(subId); 1154 } catch (RemoteException ex) { 1155 } catch (NullPointerException ex) { 1156 } 1157 } 1158 1159 /** 1160 * Disables location update notifications. {@link PhoneStateListener#onCellLocationChanged 1161 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 1162 * 1163 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 1164 * CONTROL_LOCATION_UPDATES} 1165 * 1166 * @hide 1167 */ 1168 public void disableLocationUpdates() { 1169 disableLocationUpdates(getSubId()); 1170 } 1171 1172 /** @hide */ 1173 public void disableLocationUpdates(int subId) { 1174 try { 1175 ITelephony telephony = getITelephony(); 1176 if (telephony != null) 1177 telephony.disableLocationUpdatesForSubscriber(subId); 1178 } catch (RemoteException ex) { 1179 } catch (NullPointerException ex) { 1180 } 1181 } 1182 1183 /** 1184 * Returns the neighboring cell information of the device. 1185 * 1186 * <p>Requires Permission: 1187 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} 1188 * 1189 * @return List of NeighboringCellInfo or null if info unavailable. 1190 * 1191 * @deprecated Use {@link #getAllCellInfo} which returns a superset of the information 1192 * from NeighboringCellInfo. 1193 */ 1194 @Deprecated 1195 public List<NeighboringCellInfo> getNeighboringCellInfo() { 1196 try { 1197 ITelephony telephony = getITelephony(); 1198 if (telephony == null) 1199 return null; 1200 return telephony.getNeighboringCellInfo(mContext.getOpPackageName()); 1201 } catch (RemoteException ex) { 1202 return null; 1203 } catch (NullPointerException ex) { 1204 return null; 1205 } 1206 } 1207 1208 /** No phone radio. */ 1209 public static final int PHONE_TYPE_NONE = PhoneConstants.PHONE_TYPE_NONE; 1210 /** Phone radio is GSM. */ 1211 public static final int PHONE_TYPE_GSM = PhoneConstants.PHONE_TYPE_GSM; 1212 /** Phone radio is CDMA. */ 1213 public static final int PHONE_TYPE_CDMA = PhoneConstants.PHONE_TYPE_CDMA; 1214 /** Phone is via SIP. */ 1215 public static final int PHONE_TYPE_SIP = PhoneConstants.PHONE_TYPE_SIP; 1216 1217 /** 1218 * Returns the current phone type. 1219 * TODO: This is a last minute change and hence hidden. 1220 * 1221 * @see #PHONE_TYPE_NONE 1222 * @see #PHONE_TYPE_GSM 1223 * @see #PHONE_TYPE_CDMA 1224 * @see #PHONE_TYPE_SIP 1225 * 1226 * {@hide} 1227 */ 1228 @SystemApi 1229 public int getCurrentPhoneType() { 1230 return getCurrentPhoneType(getSubId()); 1231 } 1232 1233 /** 1234 * Returns a constant indicating the device phone type for a subscription. 1235 * 1236 * @see #PHONE_TYPE_NONE 1237 * @see #PHONE_TYPE_GSM 1238 * @see #PHONE_TYPE_CDMA 1239 * 1240 * @param subId for which phone type is returned 1241 * @hide 1242 */ 1243 @SystemApi 1244 public int getCurrentPhoneType(int subId) { 1245 int phoneId; 1246 if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { 1247 // if we don't have any sims, we don't have subscriptions, but we 1248 // still may want to know what type of phone we've got. 1249 phoneId = 0; 1250 } else { 1251 phoneId = SubscriptionManager.getPhoneId(subId); 1252 } 1253 1254 return getCurrentPhoneTypeForSlot(phoneId); 1255 } 1256 1257 /** 1258 * See getCurrentPhoneType. 1259 * 1260 * @hide 1261 */ 1262 public int getCurrentPhoneTypeForSlot(int slotIndex) { 1263 try{ 1264 ITelephony telephony = getITelephony(); 1265 if (telephony != null) { 1266 return telephony.getActivePhoneTypeForSlot(slotIndex); 1267 } else { 1268 // This can happen when the ITelephony interface is not up yet. 1269 return getPhoneTypeFromProperty(slotIndex); 1270 } 1271 } catch (RemoteException ex) { 1272 // This shouldn't happen in the normal case, as a backup we 1273 // read from the system property. 1274 return getPhoneTypeFromProperty(slotIndex); 1275 } catch (NullPointerException ex) { 1276 // This shouldn't happen in the normal case, as a backup we 1277 // read from the system property. 1278 return getPhoneTypeFromProperty(slotIndex); 1279 } 1280 } 1281 1282 /** 1283 * Returns a constant indicating the device phone type. This 1284 * indicates the type of radio used to transmit voice calls. 1285 * 1286 * @see #PHONE_TYPE_NONE 1287 * @see #PHONE_TYPE_GSM 1288 * @see #PHONE_TYPE_CDMA 1289 * @see #PHONE_TYPE_SIP 1290 */ 1291 public int getPhoneType() { 1292 if (!isVoiceCapable()) { 1293 return PHONE_TYPE_NONE; 1294 } 1295 return getCurrentPhoneType(); 1296 } 1297 1298 private int getPhoneTypeFromProperty() { 1299 return getPhoneTypeFromProperty(getDefaultPhone()); 1300 } 1301 1302 /** {@hide} */ 1303 private int getPhoneTypeFromProperty(int phoneId) { 1304 String type = getTelephonyProperty(phoneId, 1305 TelephonyProperties.CURRENT_ACTIVE_PHONE, null); 1306 if (type == null || type.isEmpty()) { 1307 return getPhoneTypeFromNetworkType(phoneId); 1308 } 1309 return Integer.parseInt(type); 1310 } 1311 1312 private int getPhoneTypeFromNetworkType() { 1313 return getPhoneTypeFromNetworkType(getDefaultPhone()); 1314 } 1315 1316 /** {@hide} */ 1317 private int getPhoneTypeFromNetworkType(int phoneId) { 1318 // When the system property CURRENT_ACTIVE_PHONE, has not been set, 1319 // use the system property for default network type. 1320 // This is a fail safe, and can only happen at first boot. 1321 String mode = getTelephonyProperty(phoneId, "ro.telephony.default_network", null); 1322 if (mode != null && !mode.isEmpty()) { 1323 return TelephonyManager.getPhoneType(Integer.parseInt(mode)); 1324 } 1325 return TelephonyManager.PHONE_TYPE_NONE; 1326 } 1327 1328 /** 1329 * This function returns the type of the phone, depending 1330 * on the network mode. 1331 * 1332 * @param networkMode 1333 * @return Phone Type 1334 * 1335 * @hide 1336 */ 1337 public static int getPhoneType(int networkMode) { 1338 switch(networkMode) { 1339 case RILConstants.NETWORK_MODE_CDMA: 1340 case RILConstants.NETWORK_MODE_CDMA_NO_EVDO: 1341 case RILConstants.NETWORK_MODE_EVDO_NO_CDMA: 1342 return PhoneConstants.PHONE_TYPE_CDMA; 1343 1344 case RILConstants.NETWORK_MODE_WCDMA_PREF: 1345 case RILConstants.NETWORK_MODE_GSM_ONLY: 1346 case RILConstants.NETWORK_MODE_WCDMA_ONLY: 1347 case RILConstants.NETWORK_MODE_GSM_UMTS: 1348 case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA: 1349 case RILConstants.NETWORK_MODE_LTE_WCDMA: 1350 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA: 1351 case RILConstants.NETWORK_MODE_TDSCDMA_ONLY: 1352 case RILConstants.NETWORK_MODE_TDSCDMA_WCDMA: 1353 case RILConstants.NETWORK_MODE_LTE_TDSCDMA: 1354 case RILConstants.NETWORK_MODE_TDSCDMA_GSM: 1355 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM: 1356 case RILConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA: 1357 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA: 1358 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA: 1359 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA: 1360 return PhoneConstants.PHONE_TYPE_GSM; 1361 1362 // Use CDMA Phone for the global mode including CDMA 1363 case RILConstants.NETWORK_MODE_GLOBAL: 1364 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO: 1365 case RILConstants.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA: 1366 return PhoneConstants.PHONE_TYPE_CDMA; 1367 1368 case RILConstants.NETWORK_MODE_LTE_ONLY: 1369 if (getLteOnCdmaModeStatic() == PhoneConstants.LTE_ON_CDMA_TRUE) { 1370 return PhoneConstants.PHONE_TYPE_CDMA; 1371 } else { 1372 return PhoneConstants.PHONE_TYPE_GSM; 1373 } 1374 default: 1375 return PhoneConstants.PHONE_TYPE_GSM; 1376 } 1377 } 1378 1379 /** 1380 * The contents of the /proc/cmdline file 1381 */ 1382 private static String getProcCmdLine() 1383 { 1384 String cmdline = ""; 1385 FileInputStream is = null; 1386 try { 1387 is = new FileInputStream("/proc/cmdline"); 1388 byte [] buffer = new byte[2048]; 1389 int count = is.read(buffer); 1390 if (count > 0) { 1391 cmdline = new String(buffer, 0, count); 1392 } 1393 } catch (IOException e) { 1394 Rlog.d(TAG, "No /proc/cmdline exception=" + e); 1395 } finally { 1396 if (is != null) { 1397 try { 1398 is.close(); 1399 } catch (IOException e) { 1400 } 1401 } 1402 } 1403 Rlog.d(TAG, "/proc/cmdline=" + cmdline); 1404 return cmdline; 1405 } 1406 1407 /** Kernel command line */ 1408 private static final String sKernelCmdLine = getProcCmdLine(); 1409 1410 /** Pattern for selecting the product type from the kernel command line */ 1411 private static final Pattern sProductTypePattern = 1412 Pattern.compile("\\sproduct_type\\s*=\\s*(\\w+)"); 1413 1414 /** The ProductType used for LTE on CDMA devices */ 1415 private static final String sLteOnCdmaProductType = 1416 SystemProperties.get(TelephonyProperties.PROPERTY_LTE_ON_CDMA_PRODUCT_TYPE, ""); 1417 1418 /** 1419 * Return if the current radio is LTE on CDMA. This 1420 * is a tri-state return value as for a period of time 1421 * the mode may be unknown. 1422 * 1423 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 1424 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 1425 * 1426 * @hide 1427 */ 1428 public static int getLteOnCdmaModeStatic() { 1429 int retVal; 1430 int curVal; 1431 String productType = ""; 1432 1433 curVal = SystemProperties.getInt(TelephonyProperties.PROPERTY_LTE_ON_CDMA_DEVICE, 1434 PhoneConstants.LTE_ON_CDMA_UNKNOWN); 1435 retVal = curVal; 1436 if (retVal == PhoneConstants.LTE_ON_CDMA_UNKNOWN) { 1437 Matcher matcher = sProductTypePattern.matcher(sKernelCmdLine); 1438 if (matcher.find()) { 1439 productType = matcher.group(1); 1440 if (sLteOnCdmaProductType.equals(productType)) { 1441 retVal = PhoneConstants.LTE_ON_CDMA_TRUE; 1442 } else { 1443 retVal = PhoneConstants.LTE_ON_CDMA_FALSE; 1444 } 1445 } else { 1446 retVal = PhoneConstants.LTE_ON_CDMA_FALSE; 1447 } 1448 } 1449 1450 Rlog.d(TAG, "getLteOnCdmaMode=" + retVal + " curVal=" + curVal + 1451 " product_type='" + productType + 1452 "' lteOnCdmaProductType='" + sLteOnCdmaProductType + "'"); 1453 return retVal; 1454 } 1455 1456 // 1457 // 1458 // Current Network 1459 // 1460 // 1461 1462 /** 1463 * Returns the alphabetic name of current registered operator. 1464 * <p> 1465 * Availability: Only when user is registered to a network. Result may be 1466 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1467 * on a CDMA network). 1468 */ 1469 public String getNetworkOperatorName() { 1470 return getNetworkOperatorName(getSubId()); 1471 } 1472 1473 /** 1474 * Returns the alphabetic name of current registered operator 1475 * for a particular subscription. 1476 * <p> 1477 * Availability: Only when user is registered to a network. Result may be 1478 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1479 * on a CDMA network). 1480 * @param subId 1481 * @hide 1482 */ 1483 public String getNetworkOperatorName(int subId) { 1484 int phoneId = SubscriptionManager.getPhoneId(subId); 1485 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, ""); 1486 } 1487 1488 /** 1489 * Returns the numeric name (MCC+MNC) of current registered operator. 1490 * <p> 1491 * Availability: Only when user is registered to a network. Result may be 1492 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1493 * on a CDMA network). 1494 */ 1495 public String getNetworkOperator() { 1496 return getNetworkOperatorForPhone(getDefaultPhone()); 1497 } 1498 1499 /** 1500 * Returns the numeric name (MCC+MNC) of current registered operator 1501 * for a particular subscription. 1502 * <p> 1503 * Availability: Only when user is registered to a network. Result may be 1504 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1505 * on a CDMA network). 1506 * 1507 * @param subId 1508 * @hide 1509 */ 1510 public String getNetworkOperator(int subId) { 1511 int phoneId = SubscriptionManager.getPhoneId(subId); 1512 return getNetworkOperatorForPhone(phoneId); 1513 } 1514 1515 /** 1516 * Returns the numeric name (MCC+MNC) of current registered operator 1517 * for a particular subscription. 1518 * <p> 1519 * Availability: Only when user is registered to a network. Result may be 1520 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1521 * on a CDMA network). 1522 * 1523 * @param phoneId 1524 * @hide 1525 **/ 1526 public String getNetworkOperatorForPhone(int phoneId) { 1527 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, ""); 1528 } 1529 1530 1531 /** 1532 * Returns the network specifier of the subscription ID pinned to the TelephonyManager. The 1533 * network specifier is used by {@link 1534 * android.net.NetworkRequest.Builder#setNetworkSpecifier(String)} to create a {@link 1535 * android.net.NetworkRequest} that connects through the subscription. 1536 * 1537 * @see android.net.NetworkRequest.Builder#setNetworkSpecifier(String) 1538 * @see #createForSubscriptionId(int) 1539 * @see #createForPhoneAccountHandle(PhoneAccountHandle) 1540 */ 1541 public String getNetworkSpecifier() { 1542 return String.valueOf(mSubId); 1543 } 1544 1545 /** 1546 * Returns the carrier config of the subscription ID pinned to the TelephonyManager. If an 1547 * invalid subscription ID is pinned to the TelephonyManager, the returned config will contain 1548 * default values. 1549 * 1550 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE 1551 * READ_PHONE_STATE} 1552 * 1553 * @see CarrierConfigManager#getConfigForSubId(int) 1554 * @see #createForSubscriptionId(int) 1555 * @see #createForPhoneAccountHandle(PhoneAccountHandle) 1556 */ 1557 @WorkerThread 1558 public PersistableBundle getCarrierConfig() { 1559 CarrierConfigManager carrierConfigManager = mContext 1560 .getSystemService(CarrierConfigManager.class); 1561 return carrierConfigManager.getConfigForSubId(mSubId); 1562 } 1563 1564 /** 1565 * Returns true if the device is considered roaming on the current 1566 * network, for GSM purposes. 1567 * <p> 1568 * Availability: Only when user registered to a network. 1569 */ 1570 public boolean isNetworkRoaming() { 1571 return isNetworkRoaming(getSubId()); 1572 } 1573 1574 /** 1575 * Returns true if the device is considered roaming on the current 1576 * network for a subscription. 1577 * <p> 1578 * Availability: Only when user registered to a network. 1579 * 1580 * @param subId 1581 * @hide 1582 */ 1583 public boolean isNetworkRoaming(int subId) { 1584 int phoneId = SubscriptionManager.getPhoneId(subId); 1585 return Boolean.parseBoolean(getTelephonyProperty(phoneId, 1586 TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, null)); 1587 } 1588 1589 /** 1590 * Returns the ISO country code equivalent of the current registered 1591 * operator's MCC (Mobile Country Code). 1592 * <p> 1593 * Availability: Only when user is registered to a network. Result may be 1594 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1595 * on a CDMA network). 1596 */ 1597 public String getNetworkCountryIso() { 1598 return getNetworkCountryIsoForPhone(getDefaultPhone()); 1599 } 1600 1601 /** 1602 * Returns the ISO country code equivalent of the current registered 1603 * operator's MCC (Mobile Country Code) of a subscription. 1604 * <p> 1605 * Availability: Only when user is registered to a network. Result may be 1606 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1607 * on a CDMA network). 1608 * 1609 * @param subId for which Network CountryIso is returned 1610 * @hide 1611 */ 1612 public String getNetworkCountryIso(int subId) { 1613 int phoneId = SubscriptionManager.getPhoneId(subId); 1614 return getNetworkCountryIsoForPhone(phoneId); 1615 } 1616 1617 /** 1618 * Returns the ISO country code equivalent of the current registered 1619 * operator's MCC (Mobile Country Code) of a subscription. 1620 * <p> 1621 * Availability: Only when user is registered to a network. Result may be 1622 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1623 * on a CDMA network). 1624 * 1625 * @param phoneId for which Network CountryIso is returned 1626 */ 1627 /** {@hide} */ 1628 public String getNetworkCountryIsoForPhone(int phoneId) { 1629 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, ""); 1630 } 1631 1632 /** Network type is unknown */ 1633 public static final int NETWORK_TYPE_UNKNOWN = 0; 1634 /** Current network is GPRS */ 1635 public static final int NETWORK_TYPE_GPRS = 1; 1636 /** Current network is EDGE */ 1637 public static final int NETWORK_TYPE_EDGE = 2; 1638 /** Current network is UMTS */ 1639 public static final int NETWORK_TYPE_UMTS = 3; 1640 /** Current network is CDMA: Either IS95A or IS95B*/ 1641 public static final int NETWORK_TYPE_CDMA = 4; 1642 /** Current network is EVDO revision 0*/ 1643 public static final int NETWORK_TYPE_EVDO_0 = 5; 1644 /** Current network is EVDO revision A*/ 1645 public static final int NETWORK_TYPE_EVDO_A = 6; 1646 /** Current network is 1xRTT*/ 1647 public static final int NETWORK_TYPE_1xRTT = 7; 1648 /** Current network is HSDPA */ 1649 public static final int NETWORK_TYPE_HSDPA = 8; 1650 /** Current network is HSUPA */ 1651 public static final int NETWORK_TYPE_HSUPA = 9; 1652 /** Current network is HSPA */ 1653 public static final int NETWORK_TYPE_HSPA = 10; 1654 /** Current network is iDen */ 1655 public static final int NETWORK_TYPE_IDEN = 11; 1656 /** Current network is EVDO revision B*/ 1657 public static final int NETWORK_TYPE_EVDO_B = 12; 1658 /** Current network is LTE */ 1659 public static final int NETWORK_TYPE_LTE = 13; 1660 /** Current network is eHRPD */ 1661 public static final int NETWORK_TYPE_EHRPD = 14; 1662 /** Current network is HSPA+ */ 1663 public static final int NETWORK_TYPE_HSPAP = 15; 1664 /** Current network is GSM */ 1665 public static final int NETWORK_TYPE_GSM = 16; 1666 /** Current network is TD_SCDMA */ 1667 public static final int NETWORK_TYPE_TD_SCDMA = 17; 1668 /** Current network is IWLAN */ 1669 public static final int NETWORK_TYPE_IWLAN = 18; 1670 /** Current network is LTE_CA {@hide} */ 1671 public static final int NETWORK_TYPE_LTE_CA = 19; 1672 /** 1673 * @return the NETWORK_TYPE_xxxx for current data connection. 1674 */ 1675 public int getNetworkType() { 1676 try { 1677 ITelephony telephony = getITelephony(); 1678 if (telephony != null) { 1679 return telephony.getNetworkType(); 1680 } else { 1681 // This can happen when the ITelephony interface is not up yet. 1682 return NETWORK_TYPE_UNKNOWN; 1683 } 1684 } catch(RemoteException ex) { 1685 // This shouldn't happen in the normal case 1686 return NETWORK_TYPE_UNKNOWN; 1687 } catch (NullPointerException ex) { 1688 // This could happen before phone restarts due to crashing 1689 return NETWORK_TYPE_UNKNOWN; 1690 } 1691 } 1692 1693 /** 1694 * Returns a constant indicating the radio technology (network type) 1695 * currently in use on the device for a subscription. 1696 * @return the network type 1697 * 1698 * @param subId for which network type is returned 1699 * 1700 * @see #NETWORK_TYPE_UNKNOWN 1701 * @see #NETWORK_TYPE_GPRS 1702 * @see #NETWORK_TYPE_EDGE 1703 * @see #NETWORK_TYPE_UMTS 1704 * @see #NETWORK_TYPE_HSDPA 1705 * @see #NETWORK_TYPE_HSUPA 1706 * @see #NETWORK_TYPE_HSPA 1707 * @see #NETWORK_TYPE_CDMA 1708 * @see #NETWORK_TYPE_EVDO_0 1709 * @see #NETWORK_TYPE_EVDO_A 1710 * @see #NETWORK_TYPE_EVDO_B 1711 * @see #NETWORK_TYPE_1xRTT 1712 * @see #NETWORK_TYPE_IDEN 1713 * @see #NETWORK_TYPE_LTE 1714 * @see #NETWORK_TYPE_EHRPD 1715 * @see #NETWORK_TYPE_HSPAP 1716 * 1717 * <p> 1718 * Requires Permission: 1719 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1720 * @hide 1721 */ 1722 public int getNetworkType(int subId) { 1723 try { 1724 ITelephony telephony = getITelephony(); 1725 if (telephony != null) { 1726 return telephony.getNetworkTypeForSubscriber(subId, getOpPackageName()); 1727 } else { 1728 // This can happen when the ITelephony interface is not up yet. 1729 return NETWORK_TYPE_UNKNOWN; 1730 } 1731 } catch(RemoteException ex) { 1732 // This shouldn't happen in the normal case 1733 return NETWORK_TYPE_UNKNOWN; 1734 } catch (NullPointerException ex) { 1735 // This could happen before phone restarts due to crashing 1736 return NETWORK_TYPE_UNKNOWN; 1737 } 1738 } 1739 1740 /** 1741 * Returns a constant indicating the radio technology (network type) 1742 * currently in use on the device for data transmission. 1743 * 1744 * <p> 1745 * Requires Permission: 1746 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1747 * 1748 * @return the network type 1749 * 1750 * @see #NETWORK_TYPE_UNKNOWN 1751 * @see #NETWORK_TYPE_GPRS 1752 * @see #NETWORK_TYPE_EDGE 1753 * @see #NETWORK_TYPE_UMTS 1754 * @see #NETWORK_TYPE_HSDPA 1755 * @see #NETWORK_TYPE_HSUPA 1756 * @see #NETWORK_TYPE_HSPA 1757 * @see #NETWORK_TYPE_CDMA 1758 * @see #NETWORK_TYPE_EVDO_0 1759 * @see #NETWORK_TYPE_EVDO_A 1760 * @see #NETWORK_TYPE_EVDO_B 1761 * @see #NETWORK_TYPE_1xRTT 1762 * @see #NETWORK_TYPE_IDEN 1763 * @see #NETWORK_TYPE_LTE 1764 * @see #NETWORK_TYPE_EHRPD 1765 * @see #NETWORK_TYPE_HSPAP 1766 */ 1767 public int getDataNetworkType() { 1768 return getDataNetworkType(getSubId()); 1769 } 1770 1771 /** 1772 * Returns a constant indicating the radio technology (network type) 1773 * currently in use on the device for data transmission for a subscription 1774 * @return the network type 1775 * 1776 * @param subId for which network type is returned 1777 * 1778 * <p> 1779 * Requires Permission: 1780 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1781 * @hide 1782 */ 1783 public int getDataNetworkType(int subId) { 1784 try{ 1785 ITelephony telephony = getITelephony(); 1786 if (telephony != null) { 1787 return telephony.getDataNetworkTypeForSubscriber(subId, getOpPackageName()); 1788 } else { 1789 // This can happen when the ITelephony interface is not up yet. 1790 return NETWORK_TYPE_UNKNOWN; 1791 } 1792 } catch(RemoteException ex) { 1793 // This shouldn't happen in the normal case 1794 return NETWORK_TYPE_UNKNOWN; 1795 } catch (NullPointerException ex) { 1796 // This could happen before phone restarts due to crashing 1797 return NETWORK_TYPE_UNKNOWN; 1798 } 1799 } 1800 1801 /** 1802 * Returns the NETWORK_TYPE_xxxx for voice 1803 * 1804 * <p> 1805 * Requires Permission: 1806 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1807 */ 1808 public int getVoiceNetworkType() { 1809 return getVoiceNetworkType(getSubId()); 1810 } 1811 1812 /** 1813 * Returns the NETWORK_TYPE_xxxx for voice for a subId 1814 * 1815 * <p> 1816 * Requires Permission: 1817 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1818 * @hide 1819 */ 1820 public int getVoiceNetworkType(int subId) { 1821 try{ 1822 ITelephony telephony = getITelephony(); 1823 if (telephony != null) { 1824 return telephony.getVoiceNetworkTypeForSubscriber(subId, getOpPackageName()); 1825 } else { 1826 // This can happen when the ITelephony interface is not up yet. 1827 return NETWORK_TYPE_UNKNOWN; 1828 } 1829 } catch(RemoteException ex) { 1830 // This shouldn't happen in the normal case 1831 return NETWORK_TYPE_UNKNOWN; 1832 } catch (NullPointerException ex) { 1833 // This could happen before phone restarts due to crashing 1834 return NETWORK_TYPE_UNKNOWN; 1835 } 1836 } 1837 1838 /** 1839 * Network Class Definitions. 1840 * Do not change this order, it is used for sorting during emergency calling in 1841 * {@link TelephonyConnectionService#getFirstPhoneForEmergencyCall()}. Any newer technologies 1842 * should be added after the current definitions. 1843 */ 1844 /** Unknown network class. {@hide} */ 1845 public static final int NETWORK_CLASS_UNKNOWN = 0; 1846 /** Class of broadly defined "2G" networks. {@hide} */ 1847 public static final int NETWORK_CLASS_2_G = 1; 1848 /** Class of broadly defined "3G" networks. {@hide} */ 1849 public static final int NETWORK_CLASS_3_G = 2; 1850 /** Class of broadly defined "4G" networks. {@hide} */ 1851 public static final int NETWORK_CLASS_4_G = 3; 1852 1853 /** 1854 * Return general class of network type, such as "3G" or "4G". In cases 1855 * where classification is contentious, this method is conservative. 1856 * 1857 * @hide 1858 */ 1859 public static int getNetworkClass(int networkType) { 1860 switch (networkType) { 1861 case NETWORK_TYPE_GPRS: 1862 case NETWORK_TYPE_GSM: 1863 case NETWORK_TYPE_EDGE: 1864 case NETWORK_TYPE_CDMA: 1865 case NETWORK_TYPE_1xRTT: 1866 case NETWORK_TYPE_IDEN: 1867 return NETWORK_CLASS_2_G; 1868 case NETWORK_TYPE_UMTS: 1869 case NETWORK_TYPE_EVDO_0: 1870 case NETWORK_TYPE_EVDO_A: 1871 case NETWORK_TYPE_HSDPA: 1872 case NETWORK_TYPE_HSUPA: 1873 case NETWORK_TYPE_HSPA: 1874 case NETWORK_TYPE_EVDO_B: 1875 case NETWORK_TYPE_EHRPD: 1876 case NETWORK_TYPE_HSPAP: 1877 case NETWORK_TYPE_TD_SCDMA: 1878 return NETWORK_CLASS_3_G; 1879 case NETWORK_TYPE_LTE: 1880 case NETWORK_TYPE_IWLAN: 1881 case NETWORK_TYPE_LTE_CA: 1882 return NETWORK_CLASS_4_G; 1883 default: 1884 return NETWORK_CLASS_UNKNOWN; 1885 } 1886 } 1887 1888 /** 1889 * Returns a string representation of the radio technology (network type) 1890 * currently in use on the device. 1891 * @return the name of the radio technology 1892 * 1893 * @hide pending API council review 1894 */ 1895 public String getNetworkTypeName() { 1896 return getNetworkTypeName(getNetworkType()); 1897 } 1898 1899 /** 1900 * Returns a string representation of the radio technology (network type) 1901 * currently in use on the device. 1902 * @param subId for which network type is returned 1903 * @return the name of the radio technology 1904 * 1905 */ 1906 /** {@hide} */ 1907 public static String getNetworkTypeName(int type) { 1908 switch (type) { 1909 case NETWORK_TYPE_GPRS: 1910 return "GPRS"; 1911 case NETWORK_TYPE_EDGE: 1912 return "EDGE"; 1913 case NETWORK_TYPE_UMTS: 1914 return "UMTS"; 1915 case NETWORK_TYPE_HSDPA: 1916 return "HSDPA"; 1917 case NETWORK_TYPE_HSUPA: 1918 return "HSUPA"; 1919 case NETWORK_TYPE_HSPA: 1920 return "HSPA"; 1921 case NETWORK_TYPE_CDMA: 1922 return "CDMA"; 1923 case NETWORK_TYPE_EVDO_0: 1924 return "CDMA - EvDo rev. 0"; 1925 case NETWORK_TYPE_EVDO_A: 1926 return "CDMA - EvDo rev. A"; 1927 case NETWORK_TYPE_EVDO_B: 1928 return "CDMA - EvDo rev. B"; 1929 case NETWORK_TYPE_1xRTT: 1930 return "CDMA - 1xRTT"; 1931 case NETWORK_TYPE_LTE: 1932 return "LTE"; 1933 case NETWORK_TYPE_EHRPD: 1934 return "CDMA - eHRPD"; 1935 case NETWORK_TYPE_IDEN: 1936 return "iDEN"; 1937 case NETWORK_TYPE_HSPAP: 1938 return "HSPA+"; 1939 case NETWORK_TYPE_GSM: 1940 return "GSM"; 1941 case NETWORK_TYPE_TD_SCDMA: 1942 return "TD_SCDMA"; 1943 case NETWORK_TYPE_IWLAN: 1944 return "IWLAN"; 1945 case NETWORK_TYPE_LTE_CA: 1946 return "LTE_CA"; 1947 default: 1948 return "UNKNOWN"; 1949 } 1950 } 1951 1952 // 1953 // 1954 // SIM Card 1955 // 1956 // 1957 1958 /** 1959 * SIM card state: Unknown. Signifies that the SIM is in transition 1960 * between states. For example, when the user inputs the SIM pin 1961 * under PIN_REQUIRED state, a query for sim status returns 1962 * this state before turning to SIM_STATE_READY. 1963 * 1964 * These are the ordinal value of IccCardConstants.State. 1965 */ 1966 public static final int SIM_STATE_UNKNOWN = 0; 1967 /** SIM card state: no SIM card is available in the device */ 1968 public static final int SIM_STATE_ABSENT = 1; 1969 /** SIM card state: Locked: requires the user's SIM PIN to unlock */ 1970 public static final int SIM_STATE_PIN_REQUIRED = 2; 1971 /** SIM card state: Locked: requires the user's SIM PUK to unlock */ 1972 public static final int SIM_STATE_PUK_REQUIRED = 3; 1973 /** SIM card state: Locked: requires a network PIN to unlock */ 1974 public static final int SIM_STATE_NETWORK_LOCKED = 4; 1975 /** SIM card state: Ready */ 1976 public static final int SIM_STATE_READY = 5; 1977 /** SIM card state: SIM Card is NOT READY */ 1978 public static final int SIM_STATE_NOT_READY = 6; 1979 /** SIM card state: SIM Card Error, permanently disabled */ 1980 public static final int SIM_STATE_PERM_DISABLED = 7; 1981 /** SIM card state: SIM Card Error, present but faulty */ 1982 public static final int SIM_STATE_CARD_IO_ERROR = 8; 1983 /** SIM card state: SIM Card restricted, present but not usable due to 1984 * carrier restrictions. 1985 */ 1986 public static final int SIM_STATE_CARD_RESTRICTED = 9; 1987 1988 /** 1989 * @return true if a ICC card is present 1990 */ 1991 public boolean hasIccCard() { 1992 return hasIccCard(getDefaultSim()); 1993 } 1994 1995 /** 1996 * @return true if a ICC card is present for a subscription 1997 * 1998 * @param slotIndex for which icc card presence is checked 1999 */ 2000 /** {@hide} */ 2001 // FIXME Input argument slotIndex should be of type int 2002 public boolean hasIccCard(int slotIndex) { 2003 2004 try { 2005 ITelephony telephony = getITelephony(); 2006 if (telephony == null) 2007 return false; 2008 return telephony.hasIccCardUsingSlotIndex(slotIndex); 2009 } catch (RemoteException ex) { 2010 // Assume no ICC card if remote exception which shouldn't happen 2011 return false; 2012 } catch (NullPointerException ex) { 2013 // This could happen before phone restarts due to crashing 2014 return false; 2015 } 2016 } 2017 2018 /** 2019 * Returns a constant indicating the state of the default SIM card. 2020 * 2021 * @see #SIM_STATE_UNKNOWN 2022 * @see #SIM_STATE_ABSENT 2023 * @see #SIM_STATE_PIN_REQUIRED 2024 * @see #SIM_STATE_PUK_REQUIRED 2025 * @see #SIM_STATE_NETWORK_LOCKED 2026 * @see #SIM_STATE_READY 2027 * @see #SIM_STATE_NOT_READY 2028 * @see #SIM_STATE_PERM_DISABLED 2029 * @see #SIM_STATE_CARD_IO_ERROR 2030 * @see #SIM_STATE_CARD_RESTRICTED 2031 */ 2032 public int getSimState() { 2033 int slotIndex = getDefaultSim(); 2034 // slotIndex may be invalid due to sim being absent. In that case query all slots to get 2035 // sim state 2036 if (slotIndex < 0) { 2037 // query for all slots and return absent if all sim states are absent, otherwise 2038 // return unknown 2039 for (int i = 0; i < getPhoneCount(); i++) { 2040 int simState = getSimState(i); 2041 if (simState != SIM_STATE_ABSENT) { 2042 Rlog.d(TAG, "getSimState: default sim:" + slotIndex + ", sim state for " + 2043 "slotIndex=" + i + " is " + simState + ", return state as unknown"); 2044 return SIM_STATE_UNKNOWN; 2045 } 2046 } 2047 Rlog.d(TAG, "getSimState: default sim:" + slotIndex + ", all SIMs absent, return " + 2048 "state as absent"); 2049 return SIM_STATE_ABSENT; 2050 } 2051 return getSimState(slotIndex); 2052 } 2053 2054 /** 2055 * Returns a constant indicating the state of the device SIM card in a slot. 2056 * 2057 * @param slotIndex 2058 * 2059 * @see #SIM_STATE_UNKNOWN 2060 * @see #SIM_STATE_ABSENT 2061 * @see #SIM_STATE_PIN_REQUIRED 2062 * @see #SIM_STATE_PUK_REQUIRED 2063 * @see #SIM_STATE_NETWORK_LOCKED 2064 * @see #SIM_STATE_READY 2065 * @see #SIM_STATE_NOT_READY 2066 * @see #SIM_STATE_PERM_DISABLED 2067 * @see #SIM_STATE_CARD_IO_ERROR 2068 * @see #SIM_STATE_CARD_RESTRICTED 2069 */ 2070 public int getSimState(int slotIndex) { 2071 int simState = SubscriptionManager.getSimStateForSlotIndex(slotIndex); 2072 return simState; 2073 } 2074 2075 /** 2076 * Returns the MCC+MNC (mobile country code + mobile network code) of the 2077 * provider of the SIM. 5 or 6 decimal digits. 2078 * <p> 2079 * Availability: SIM state must be {@link #SIM_STATE_READY} 2080 * 2081 * @see #getSimState 2082 */ 2083 public String getSimOperator() { 2084 return getSimOperatorNumeric(); 2085 } 2086 2087 /** 2088 * Returns the MCC+MNC (mobile country code + mobile network code) of the 2089 * provider of the SIM. 5 or 6 decimal digits. 2090 * <p> 2091 * Availability: SIM state must be {@link #SIM_STATE_READY} 2092 * 2093 * @see #getSimState 2094 * 2095 * @param subId for which SimOperator is returned 2096 * @hide 2097 */ 2098 public String getSimOperator(int subId) { 2099 return getSimOperatorNumeric(subId); 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 * @hide 2110 */ 2111 public String getSimOperatorNumeric() { 2112 int subId = SubscriptionManager.getDefaultDataSubscriptionId(); 2113 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 2114 subId = SubscriptionManager.getDefaultSmsSubscriptionId(); 2115 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 2116 subId = SubscriptionManager.getDefaultVoiceSubscriptionId(); 2117 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 2118 subId = SubscriptionManager.getDefaultSubscriptionId(); 2119 } 2120 } 2121 } 2122 return getSimOperatorNumeric(subId); 2123 } 2124 2125 /** 2126 * Returns the MCC+MNC (mobile country code + mobile network code) of the 2127 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 2128 * <p> 2129 * Availability: SIM state must be {@link #SIM_STATE_READY} 2130 * 2131 * @see #getSimState 2132 * 2133 * @param subId for which SimOperator is returned 2134 * @hide 2135 */ 2136 public String getSimOperatorNumeric(int subId) { 2137 int phoneId = SubscriptionManager.getPhoneId(subId); 2138 return getSimOperatorNumericForPhone(phoneId); 2139 } 2140 2141 /** 2142 * Returns the MCC+MNC (mobile country code + mobile network code) of the 2143 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 2144 * <p> 2145 * 2146 * @param phoneId for which SimOperator is returned 2147 * @hide 2148 */ 2149 public String getSimOperatorNumericForPhone(int phoneId) { 2150 return getTelephonyProperty(phoneId, 2151 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, ""); 2152 } 2153 2154 /** 2155 * Returns the Service Provider Name (SPN). 2156 * <p> 2157 * Availability: SIM state must be {@link #SIM_STATE_READY} 2158 * 2159 * @see #getSimState 2160 */ 2161 public String getSimOperatorName() { 2162 return getSimOperatorNameForPhone(getDefaultPhone()); 2163 } 2164 2165 /** 2166 * Returns the Service Provider Name (SPN). 2167 * <p> 2168 * Availability: SIM state must be {@link #SIM_STATE_READY} 2169 * 2170 * @see #getSimState 2171 * 2172 * @param subId for which SimOperatorName is returned 2173 * @hide 2174 */ 2175 public String getSimOperatorName(int subId) { 2176 int phoneId = SubscriptionManager.getPhoneId(subId); 2177 return getSimOperatorNameForPhone(phoneId); 2178 } 2179 2180 /** 2181 * Returns the Service Provider Name (SPN). 2182 * 2183 * @hide 2184 */ 2185 public String getSimOperatorNameForPhone(int phoneId) { 2186 return getTelephonyProperty(phoneId, 2187 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, ""); 2188 } 2189 2190 /** 2191 * Returns the ISO country code equivalent for the SIM provider's country code. 2192 */ 2193 public String getSimCountryIso() { 2194 return getSimCountryIsoForPhone(getDefaultPhone()); 2195 } 2196 2197 /** 2198 * Returns the ISO country code equivalent for the SIM provider's country code. 2199 * 2200 * @param subId for which SimCountryIso is returned 2201 * @hide 2202 */ 2203 public String getSimCountryIso(int subId) { 2204 int phoneId = SubscriptionManager.getPhoneId(subId); 2205 return getSimCountryIsoForPhone(phoneId); 2206 } 2207 2208 /** 2209 * Returns the ISO country code equivalent for the SIM provider's country code. 2210 * 2211 * @hide 2212 */ 2213 public String getSimCountryIsoForPhone(int phoneId) { 2214 return getTelephonyProperty(phoneId, 2215 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, ""); 2216 } 2217 2218 /** 2219 * Returns the serial number of the SIM, if applicable. Return null if it is 2220 * unavailable. 2221 * <p> 2222 * Requires Permission: 2223 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2224 */ 2225 public String getSimSerialNumber() { 2226 return getSimSerialNumber(getSubId()); 2227 } 2228 2229 /** 2230 * Returns the serial number for the given subscription, if applicable. Return null if it is 2231 * unavailable. 2232 * <p> 2233 * @param subId for which Sim Serial number is returned 2234 * Requires Permission: 2235 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2236 * @hide 2237 */ 2238 public String getSimSerialNumber(int subId) { 2239 try { 2240 IPhoneSubInfo info = getSubscriberInfo(); 2241 if (info == null) 2242 return null; 2243 return info.getIccSerialNumberForSubscriber(subId, mContext.getOpPackageName()); 2244 } catch (RemoteException ex) { 2245 return null; 2246 } catch (NullPointerException ex) { 2247 // This could happen before phone restarts due to crashing 2248 return null; 2249 } 2250 } 2251 2252 /** 2253 * Return if the current radio is LTE on CDMA. This 2254 * is a tri-state return value as for a period of time 2255 * the mode may be unknown. 2256 * 2257 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 2258 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 2259 * 2260 * <p> 2261 * Requires Permission: 2262 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2263 * 2264 * @hide 2265 */ 2266 public int getLteOnCdmaMode() { 2267 return getLteOnCdmaMode(getSubId()); 2268 } 2269 2270 /** 2271 * Return if the current radio is LTE on CDMA for Subscription. This 2272 * is a tri-state return value as for a period of time 2273 * the mode may be unknown. 2274 * 2275 * @param subId for which radio is LTE on CDMA is returned 2276 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 2277 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 2278 * 2279 * <p> 2280 * Requires Permission: 2281 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2282 * @hide 2283 */ 2284 public int getLteOnCdmaMode(int subId) { 2285 try { 2286 ITelephony telephony = getITelephony(); 2287 if (telephony == null) 2288 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 2289 return telephony.getLteOnCdmaModeForSubscriber(subId, getOpPackageName()); 2290 } catch (RemoteException ex) { 2291 // Assume no ICC card if remote exception which shouldn't happen 2292 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 2293 } catch (NullPointerException ex) { 2294 // This could happen before phone restarts due to crashing 2295 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 2296 } 2297 } 2298 2299 // 2300 // 2301 // Subscriber Info 2302 // 2303 // 2304 2305 /** 2306 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone. 2307 * Return null if it is unavailable. 2308 * <p> 2309 * Requires Permission: 2310 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2311 */ 2312 public String getSubscriberId() { 2313 return getSubscriberId(getSubId()); 2314 } 2315 2316 /** 2317 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone 2318 * for a subscription. 2319 * Return null if it is unavailable. 2320 * <p> 2321 * Requires Permission: 2322 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2323 * 2324 * @param subId whose subscriber id is returned 2325 * @hide 2326 */ 2327 public String getSubscriberId(int subId) { 2328 try { 2329 IPhoneSubInfo info = getSubscriberInfo(); 2330 if (info == null) 2331 return null; 2332 return info.getSubscriberIdForSubscriber(subId, mContext.getOpPackageName()); 2333 } catch (RemoteException ex) { 2334 return null; 2335 } catch (NullPointerException ex) { 2336 // This could happen before phone restarts due to crashing 2337 return null; 2338 } 2339 } 2340 2341 /** 2342 * Returns the Group Identifier Level1 for a GSM phone. 2343 * Return null if it is unavailable. 2344 * <p> 2345 * Requires Permission: 2346 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2347 */ 2348 public String getGroupIdLevel1() { 2349 try { 2350 IPhoneSubInfo info = getSubscriberInfo(); 2351 if (info == null) 2352 return null; 2353 return info.getGroupIdLevel1(mContext.getOpPackageName()); 2354 } catch (RemoteException ex) { 2355 return null; 2356 } catch (NullPointerException ex) { 2357 // This could happen before phone restarts due to crashing 2358 return null; 2359 } 2360 } 2361 2362 /** 2363 * Returns the Group Identifier Level1 for a GSM phone for a particular subscription. 2364 * Return null if it is unavailable. 2365 * <p> 2366 * Requires Permission: 2367 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2368 * 2369 * @param subId whose subscriber id is returned 2370 * @hide 2371 */ 2372 public String getGroupIdLevel1(int subId) { 2373 try { 2374 IPhoneSubInfo info = getSubscriberInfo(); 2375 if (info == null) 2376 return null; 2377 return info.getGroupIdLevel1ForSubscriber(subId, mContext.getOpPackageName()); 2378 } catch (RemoteException ex) { 2379 return null; 2380 } catch (NullPointerException ex) { 2381 // This could happen before phone restarts due to crashing 2382 return null; 2383 } 2384 } 2385 2386 /** 2387 * Returns the phone number string for line 1, for example, the MSISDN 2388 * for a GSM phone. Return null if it is unavailable. 2389 * <p> 2390 * Requires Permission: 2391 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2392 * OR 2393 * {@link android.Manifest.permission#READ_SMS} 2394 * OR 2395 * {@link android.Manifest.permission#READ_PHONE_NUMBERS} 2396 * <p> 2397 * The default SMS app can also use this. 2398 */ 2399 public String getLine1Number() { 2400 return getLine1Number(getSubId()); 2401 } 2402 2403 /** 2404 * Returns the phone number string for line 1, for example, the MSISDN 2405 * for a GSM phone for a particular subscription. Return null if it is unavailable. 2406 * <p> 2407 * Requires Permission: 2408 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2409 * OR 2410 * {@link android.Manifest.permission#READ_SMS} 2411 * OR 2412 * {@link android.Manifest.permission#READ_PHONE_NUMBERS} 2413 * <p> 2414 * The default SMS app can also use this. 2415 * 2416 * @param subId whose phone number for line 1 is returned 2417 * @hide 2418 */ 2419 public String getLine1Number(int subId) { 2420 String number = null; 2421 try { 2422 ITelephony telephony = getITelephony(); 2423 if (telephony != null) 2424 number = telephony.getLine1NumberForDisplay(subId, mContext.getOpPackageName()); 2425 } catch (RemoteException ex) { 2426 } catch (NullPointerException ex) { 2427 } 2428 if (number != null) { 2429 return number; 2430 } 2431 try { 2432 IPhoneSubInfo info = getSubscriberInfo(); 2433 if (info == null) 2434 return null; 2435 return info.getLine1NumberForSubscriber(subId, mContext.getOpPackageName()); 2436 } catch (RemoteException ex) { 2437 return null; 2438 } catch (NullPointerException ex) { 2439 // This could happen before phone restarts due to crashing 2440 return null; 2441 } 2442 } 2443 2444 /** 2445 * Set the line 1 phone number string and its alphatag for the current ICCID 2446 * for display purpose only, for example, displayed in Phone Status. It won't 2447 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 2448 * value. 2449 * 2450 * <p>Requires that the calling app has carrier privileges. 2451 * @see #hasCarrierPrivileges 2452 * 2453 * @param alphaTag alpha-tagging of the dailing nubmer 2454 * @param number The dialing number 2455 * @return true if the operation was executed correctly. 2456 */ 2457 public boolean setLine1NumberForDisplay(String alphaTag, String number) { 2458 return setLine1NumberForDisplay(getSubId(), alphaTag, number); 2459 } 2460 2461 /** 2462 * Set the line 1 phone number string and its alphatag for the current ICCID 2463 * for display purpose only, for example, displayed in Phone Status. It won't 2464 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 2465 * value. 2466 * 2467 * <p>Requires that the calling app has carrier privileges. 2468 * @see #hasCarrierPrivileges 2469 * 2470 * @param subId the subscriber that the alphatag and dialing number belongs to. 2471 * @param alphaTag alpha-tagging of the dailing nubmer 2472 * @param number The dialing number 2473 * @return true if the operation was executed correctly. 2474 * @hide 2475 */ 2476 public boolean setLine1NumberForDisplay(int subId, String alphaTag, String number) { 2477 try { 2478 ITelephony telephony = getITelephony(); 2479 if (telephony != null) 2480 return telephony.setLine1NumberForDisplayForSubscriber(subId, alphaTag, number); 2481 } catch (RemoteException ex) { 2482 } catch (NullPointerException ex) { 2483 } 2484 return false; 2485 } 2486 2487 /** 2488 * Returns the alphabetic identifier associated with the line 1 number. 2489 * Return null if it is unavailable. 2490 * <p> 2491 * Requires Permission: 2492 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2493 * @hide 2494 * nobody seems to call this. 2495 */ 2496 public String getLine1AlphaTag() { 2497 return getLine1AlphaTag(getSubId()); 2498 } 2499 2500 /** 2501 * Returns the alphabetic identifier associated with the line 1 number 2502 * for a subscription. 2503 * Return null if it is unavailable. 2504 * <p> 2505 * Requires Permission: 2506 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2507 * @param subId whose alphabetic identifier associated with line 1 is returned 2508 * nobody seems to call this. 2509 * @hide 2510 */ 2511 public String getLine1AlphaTag(int subId) { 2512 String alphaTag = null; 2513 try { 2514 ITelephony telephony = getITelephony(); 2515 if (telephony != null) 2516 alphaTag = telephony.getLine1AlphaTagForDisplay(subId, 2517 getOpPackageName()); 2518 } catch (RemoteException ex) { 2519 } catch (NullPointerException ex) { 2520 } 2521 if (alphaTag != null) { 2522 return alphaTag; 2523 } 2524 try { 2525 IPhoneSubInfo info = getSubscriberInfo(); 2526 if (info == null) 2527 return null; 2528 return info.getLine1AlphaTagForSubscriber(subId, getOpPackageName()); 2529 } catch (RemoteException ex) { 2530 return null; 2531 } catch (NullPointerException ex) { 2532 // This could happen before phone restarts due to crashing 2533 return null; 2534 } 2535 } 2536 2537 /** 2538 * Return the set of subscriber IDs that should be considered as "merged 2539 * together" for data usage purposes. This is commonly {@code null} to 2540 * indicate no merging is required. Any returned subscribers are sorted in a 2541 * deterministic order. 2542 * 2543 * @hide 2544 */ 2545 public @Nullable String[] getMergedSubscriberIds() { 2546 try { 2547 ITelephony telephony = getITelephony(); 2548 if (telephony != null) 2549 return telephony.getMergedSubscriberIds(getOpPackageName()); 2550 } catch (RemoteException ex) { 2551 } catch (NullPointerException ex) { 2552 } 2553 return null; 2554 } 2555 2556 /** 2557 * Returns the MSISDN string. 2558 * for a GSM phone. Return null if it is unavailable. 2559 * <p> 2560 * Requires Permission: 2561 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2562 * 2563 * @hide 2564 */ 2565 public String getMsisdn() { 2566 return getMsisdn(getSubId()); 2567 } 2568 2569 /** 2570 * Returns the MSISDN string. 2571 * for a GSM phone. Return null if it is unavailable. 2572 * <p> 2573 * Requires Permission: 2574 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2575 * 2576 * @param subId for which msisdn is returned 2577 * @hide 2578 */ 2579 public String getMsisdn(int subId) { 2580 try { 2581 IPhoneSubInfo info = getSubscriberInfo(); 2582 if (info == null) 2583 return null; 2584 return info.getMsisdnForSubscriber(subId, getOpPackageName()); 2585 } catch (RemoteException ex) { 2586 return null; 2587 } catch (NullPointerException ex) { 2588 // This could happen before phone restarts due to crashing 2589 return null; 2590 } 2591 } 2592 2593 /** 2594 * Returns the voice mail number. Return null if it is unavailable. 2595 * <p> 2596 * Requires Permission: 2597 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2598 */ 2599 public String getVoiceMailNumber() { 2600 return getVoiceMailNumber(getSubId()); 2601 } 2602 2603 /** 2604 * Returns the voice mail number for a subscription. 2605 * Return null if it is unavailable. 2606 * <p> 2607 * Requires Permission: 2608 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2609 * @param subId whose voice mail number is returned 2610 * @hide 2611 */ 2612 public String getVoiceMailNumber(int subId) { 2613 try { 2614 IPhoneSubInfo info = getSubscriberInfo(); 2615 if (info == null) 2616 return null; 2617 return info.getVoiceMailNumberForSubscriber(subId, getOpPackageName()); 2618 } catch (RemoteException ex) { 2619 return null; 2620 } catch (NullPointerException ex) { 2621 // This could happen before phone restarts due to crashing 2622 return null; 2623 } 2624 } 2625 2626 /** 2627 * Returns the complete voice mail number. Return null if it is unavailable. 2628 * <p> 2629 * Requires Permission: 2630 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 2631 * 2632 * @hide 2633 */ 2634 public String getCompleteVoiceMailNumber() { 2635 return getCompleteVoiceMailNumber(getSubId()); 2636 } 2637 2638 /** 2639 * Returns the complete voice mail number. Return null if it is unavailable. 2640 * <p> 2641 * Requires Permission: 2642 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 2643 * 2644 * @param subId 2645 * @hide 2646 */ 2647 public String getCompleteVoiceMailNumber(int subId) { 2648 try { 2649 IPhoneSubInfo info = getSubscriberInfo(); 2650 if (info == null) 2651 return null; 2652 return info.getCompleteVoiceMailNumberForSubscriber(subId); 2653 } catch (RemoteException ex) { 2654 return null; 2655 } catch (NullPointerException ex) { 2656 // This could happen before phone restarts due to crashing 2657 return null; 2658 } 2659 } 2660 2661 /** 2662 * Sets the voice mail number. 2663 * 2664 * <p>Requires that the calling app has carrier privileges. 2665 * @see #hasCarrierPrivileges 2666 * 2667 * @param alphaTag The alpha tag to display. 2668 * @param number The voicemail number. 2669 */ 2670 public boolean setVoiceMailNumber(String alphaTag, String number) { 2671 return setVoiceMailNumber(getSubId(), alphaTag, number); 2672 } 2673 2674 /** 2675 * Sets the voicemail number for the given subscriber. 2676 * 2677 * <p>Requires that the calling app has carrier privileges. 2678 * @see #hasCarrierPrivileges 2679 * 2680 * @param subId The subscription id. 2681 * @param alphaTag The alpha tag to display. 2682 * @param number The voicemail number. 2683 * @hide 2684 */ 2685 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { 2686 try { 2687 ITelephony telephony = getITelephony(); 2688 if (telephony != null) 2689 return telephony.setVoiceMailNumber(subId, alphaTag, number); 2690 } catch (RemoteException ex) { 2691 } catch (NullPointerException ex) { 2692 } 2693 return false; 2694 } 2695 2696 /** 2697 * Enables or disables the visual voicemail client for a phone account. 2698 * 2699 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or 2700 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 2701 * @see #hasCarrierPrivileges 2702 * 2703 * @param phoneAccountHandle the phone account to change the client state 2704 * @param enabled the new state of the client 2705 * @hide 2706 */ 2707 @SystemApi 2708 public void setVisualVoicemailEnabled(PhoneAccountHandle phoneAccountHandle, boolean enabled){ 2709 try { 2710 ITelephony telephony = getITelephony(); 2711 if (telephony != null) { 2712 telephony.setVisualVoicemailEnabled(mContext.getOpPackageName(), phoneAccountHandle, 2713 enabled); 2714 } 2715 } catch (RemoteException ex) { 2716 } catch (NullPointerException ex) { 2717 // This could happen before phone restarts due to crashing 2718 } 2719 } 2720 2721 /** 2722 * Returns whether the visual voicemail client is enabled. 2723 * 2724 * <p>Requires Permission: 2725 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2726 * 2727 * @param phoneAccountHandle the phone account to check for. 2728 * @return {@code true} when the visual voicemail client is enabled for this client 2729 * @hide 2730 */ 2731 @SystemApi 2732 public boolean isVisualVoicemailEnabled(PhoneAccountHandle phoneAccountHandle){ 2733 try { 2734 ITelephony telephony = getITelephony(); 2735 if (telephony != null) { 2736 return telephony.isVisualVoicemailEnabled( 2737 mContext.getOpPackageName(), phoneAccountHandle); 2738 } 2739 } catch (RemoteException ex) { 2740 } catch (NullPointerException ex) { 2741 // This could happen before phone restarts due to crashing 2742 } 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 /* The caller of {@link #sendUssdRequest(String, UssdResponseCallback, Handler} provides 5110 * once the network returns a USSD message or if there is failure. 5111 * Either {@link #onReceiveUssdResponse(TelephonyManager, String, CharSequence} or 5112 * {@link #onReceiveUssdResponseFailed(TelephonyManager, String, int} will be called. 5113 */ 5114 public static abstract class UssdResponseCallback { 5115 /** 5116 * Called when USSD has succeeded. The calling app can choose to either display the message 5117 * or interpret the message. 5118 * @param telephonyManager the TelephonyManager the callback is registered to. 5119 * @param request the ussd code sent to the network. 5120 * @param response the response from the network. 5121 **/ 5122 public void onReceiveUssdResponse(final TelephonyManager telephonyManager, 5123 String request, CharSequence response) {}; 5124 5125 /** 5126 * Called when USSD has failed. 5127 * @param telephonyManager the TelephonyManager the callback is registered to 5128 * @param request the ussd code. 5129 * @param failureCode failure code, should be either of 5130 * {@link TelephonyManager#USSD_RETURN_FAILURE} or 5131 * {@link TelephonyManager#USSD_ERROR_SERVICE_UNAVAIL}. 5132 **/ 5133 public void onReceiveUssdResponseFailed(final TelephonyManager telephonyManager, 5134 String request, int failureCode) {}; 5135 } 5136 5137 /** 5138 * Sends an Unstructured Supplementary Service Data (USSD) request to the cellular network and 5139 * informs the caller of the response via {@code callback}. 5140 * <p>Carriers define USSD codes which can be sent by the user to request information such as 5141 * the user's current data balance or minutes balance. 5142 * <p>Requires permission: 5143 * {@link android.Manifest.permission#CALL_PHONE} 5144 * @param ussdRequest the USSD command to be executed. 5145 * @param callback called by the framework to inform the caller of the result of executing the 5146 * USSD request (see {@link UssdResponseCallback}). 5147 * @param handler the {@link Handler} to run the request on. 5148 */ 5149 @RequiresPermission(android.Manifest.permission.CALL_PHONE) 5150 public void sendUssdRequest(String ussdRequest, 5151 final UssdResponseCallback callback, Handler handler) { 5152 checkNotNull(callback, "UssdResponseCallback cannot be null."); 5153 final TelephonyManager telephonyManager = this; 5154 5155 ResultReceiver wrappedCallback = new ResultReceiver(handler) { 5156 @Override 5157 protected void onReceiveResult(int resultCode, Bundle ussdResponse) { 5158 Rlog.d(TAG, "USSD:" + resultCode); 5159 checkNotNull(ussdResponse, "ussdResponse cannot be null."); 5160 UssdResponse response = ussdResponse.getParcelable(USSD_RESPONSE); 5161 5162 if (resultCode == USSD_RETURN_SUCCESS) { 5163 callback.onReceiveUssdResponse(telephonyManager, response.getUssdRequest(), 5164 response.getReturnMessage()); 5165 } else { 5166 callback.onReceiveUssdResponseFailed(telephonyManager, 5167 response.getUssdRequest(), resultCode); 5168 } 5169 } 5170 }; 5171 5172 try { 5173 ITelephony telephony = getITelephony(); 5174 if (telephony != null) { 5175 telephony.handleUssdRequest(mSubId, ussdRequest, wrappedCallback); 5176 } 5177 } catch (RemoteException e) { 5178 Log.e(TAG, "Error calling ITelephony#sendUSSDCode", e); 5179 UssdResponse response = new UssdResponse(ussdRequest, ""); 5180 Bundle returnData = new Bundle(); 5181 returnData.putParcelable(USSD_RESPONSE, response); 5182 wrappedCallback.send(USSD_ERROR_SERVICE_UNAVAIL, returnData); 5183 } 5184 } 5185 5186 /** 5187 * Whether the device is currently on a technology (e.g. UMTS or LTE) which can support 5188 * voice and data simultaneously. This can change based on location or network condition. 5189 * 5190 * @return {@code true} if simultaneous voice and data supported, and {@code false} otherwise. 5191 */ 5192 public boolean isConcurrentVoiceAndDataSupported() { 5193 try { 5194 ITelephony telephony = getITelephony(); 5195 return (telephony == null ? false : telephony.isConcurrentVoiceAndDataAllowed(mSubId)); 5196 } catch (RemoteException e) { 5197 Log.e(TAG, "Error calling ITelephony#isConcurrentVoiceAndDataAllowed", e); 5198 } 5199 return false; 5200 } 5201 5202 /** @hide */ 5203 @SystemApi 5204 public boolean handlePinMmi(String dialString) { 5205 try { 5206 ITelephony telephony = getITelephony(); 5207 if (telephony != null) 5208 return telephony.handlePinMmi(dialString); 5209 } catch (RemoteException e) { 5210 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 5211 } 5212 return false; 5213 } 5214 5215 /** @hide */ 5216 @SystemApi 5217 public boolean handlePinMmiForSubscriber(int subId, String dialString) { 5218 try { 5219 ITelephony telephony = getITelephony(); 5220 if (telephony != null) 5221 return telephony.handlePinMmiForSubscriber(subId, dialString); 5222 } catch (RemoteException e) { 5223 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 5224 } 5225 return false; 5226 } 5227 5228 /** @hide */ 5229 @SystemApi 5230 public void toggleRadioOnOff() { 5231 try { 5232 ITelephony telephony = getITelephony(); 5233 if (telephony != null) 5234 telephony.toggleRadioOnOff(); 5235 } catch (RemoteException e) { 5236 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 5237 } 5238 } 5239 5240 /** @hide */ 5241 @SystemApi 5242 public boolean setRadio(boolean turnOn) { 5243 try { 5244 ITelephony telephony = getITelephony(); 5245 if (telephony != null) 5246 return telephony.setRadio(turnOn); 5247 } catch (RemoteException e) { 5248 Log.e(TAG, "Error calling ITelephony#setRadio", e); 5249 } 5250 return false; 5251 } 5252 5253 /** @hide */ 5254 @SystemApi 5255 public boolean setRadioPower(boolean turnOn) { 5256 try { 5257 ITelephony telephony = getITelephony(); 5258 if (telephony != null) 5259 return telephony.setRadioPower(turnOn); 5260 } catch (RemoteException e) { 5261 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 5262 } 5263 return false; 5264 } 5265 5266 /** @hide */ 5267 @SystemApi 5268 public void updateServiceLocation() { 5269 try { 5270 ITelephony telephony = getITelephony(); 5271 if (telephony != null) 5272 telephony.updateServiceLocation(); 5273 } catch (RemoteException e) { 5274 Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e); 5275 } 5276 } 5277 5278 /** @hide */ 5279 @SystemApi 5280 public boolean enableDataConnectivity() { 5281 try { 5282 ITelephony telephony = getITelephony(); 5283 if (telephony != null) 5284 return telephony.enableDataConnectivity(); 5285 } catch (RemoteException e) { 5286 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 5287 } 5288 return false; 5289 } 5290 5291 /** @hide */ 5292 @SystemApi 5293 public boolean disableDataConnectivity() { 5294 try { 5295 ITelephony telephony = getITelephony(); 5296 if (telephony != null) 5297 return telephony.disableDataConnectivity(); 5298 } catch (RemoteException e) { 5299 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 5300 } 5301 return false; 5302 } 5303 5304 /** @hide */ 5305 @SystemApi 5306 public boolean isDataConnectivityPossible() { 5307 try { 5308 ITelephony telephony = getITelephony(); 5309 if (telephony != null) 5310 return telephony.isDataConnectivityPossible(); 5311 } catch (RemoteException e) { 5312 Log.e(TAG, "Error calling ITelephony#isDataConnectivityPossible", e); 5313 } 5314 return false; 5315 } 5316 5317 /** @hide */ 5318 @SystemApi 5319 public boolean needsOtaServiceProvisioning() { 5320 try { 5321 ITelephony telephony = getITelephony(); 5322 if (telephony != null) 5323 return telephony.needsOtaServiceProvisioning(); 5324 } catch (RemoteException e) { 5325 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 5326 } 5327 return false; 5328 } 5329 5330 /** 5331 * Turns mobile data on or off. 5332 * 5333 * <p>Requires Permission: 5334 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the 5335 * calling app has carrier privileges. 5336 * 5337 * @param enable Whether to enable mobile data. 5338 * 5339 * @see #hasCarrierPrivileges 5340 */ 5341 public void setDataEnabled(boolean enable) { 5342 setDataEnabled(getSubId(), enable); 5343 } 5344 5345 /** @hide */ 5346 @SystemApi 5347 public void setDataEnabled(int subId, boolean enable) { 5348 try { 5349 Log.d(TAG, "setDataEnabled: enabled=" + enable); 5350 ITelephony telephony = getITelephony(); 5351 if (telephony != null) 5352 telephony.setDataEnabled(subId, enable); 5353 } catch (RemoteException e) { 5354 Log.e(TAG, "Error calling ITelephony#setDataEnabled", e); 5355 } 5356 } 5357 5358 5359 /** 5360 * @deprecated use {@link #isDataEnabled()} instead. 5361 * @hide 5362 */ 5363 @SystemApi 5364 @Deprecated 5365 public boolean getDataEnabled() { 5366 return isDataEnabled(); 5367 } 5368 5369 /** 5370 * Returns whether mobile data is enabled or not. 5371 * 5372 * <p>Requires one of the following permissions: 5373 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE ACCESS_NETWORK_STATE}, 5374 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}, or that the 5375 * calling app has carrier privileges. 5376 * 5377 * <p>Note that this does not take into account any data restrictions that may be present on the 5378 * calling app. Such restrictions may be inspected with 5379 * {@link ConnectivityManager#getRestrictBackgroundStatus}. 5380 * 5381 * @return true if mobile data is enabled. 5382 * 5383 * @see #hasCarrierPrivileges 5384 */ 5385 @SuppressWarnings("deprecation") 5386 public boolean isDataEnabled() { 5387 return getDataEnabled(getSubId()); 5388 } 5389 5390 /** 5391 * @deprecated use {@link #isDataEnabled(int)} instead. 5392 * @hide 5393 */ 5394 @SystemApi 5395 public boolean getDataEnabled(int subId) { 5396 boolean retVal = false; 5397 try { 5398 ITelephony telephony = getITelephony(); 5399 if (telephony != null) 5400 retVal = telephony.getDataEnabled(subId); 5401 } catch (RemoteException e) { 5402 Log.e(TAG, "Error calling ITelephony#getDataEnabled", e); 5403 } catch (NullPointerException e) { 5404 } 5405 return retVal; 5406 } 5407 5408 /** 5409 * Returns the result and response from RIL for oem request 5410 * 5411 * @param oemReq the data is sent to ril. 5412 * @param oemResp the respose data from RIL. 5413 * @return negative value request was not handled or get error 5414 * 0 request was handled succesfully, but no response data 5415 * positive value success, data length of response 5416 * @hide 5417 * @deprecated OEM needs a vendor-extension hal and their apps should use that instead 5418 */ 5419 @Deprecated 5420 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { 5421 try { 5422 ITelephony telephony = getITelephony(); 5423 if (telephony != null) 5424 return telephony.invokeOemRilRequestRaw(oemReq, oemResp); 5425 } catch (RemoteException ex) { 5426 } catch (NullPointerException ex) { 5427 } 5428 return -1; 5429 } 5430 5431 /** @hide */ 5432 @SystemApi 5433 public void enableVideoCalling(boolean enable) { 5434 try { 5435 ITelephony telephony = getITelephony(); 5436 if (telephony != null) 5437 telephony.enableVideoCalling(enable); 5438 } catch (RemoteException e) { 5439 Log.e(TAG, "Error calling ITelephony#enableVideoCalling", e); 5440 } 5441 } 5442 5443 /** @hide */ 5444 @SystemApi 5445 public boolean isVideoCallingEnabled() { 5446 try { 5447 ITelephony telephony = getITelephony(); 5448 if (telephony != null) 5449 return telephony.isVideoCallingEnabled(getOpPackageName()); 5450 } catch (RemoteException e) { 5451 Log.e(TAG, "Error calling ITelephony#isVideoCallingEnabled", e); 5452 } 5453 return false; 5454 } 5455 5456 /** 5457 * Whether the device supports configuring the DTMF tone length. 5458 * 5459 * @return {@code true} if the DTMF tone length can be changed, and {@code false} otherwise. 5460 */ 5461 public boolean canChangeDtmfToneLength() { 5462 try { 5463 ITelephony telephony = getITelephony(); 5464 if (telephony != null) { 5465 return telephony.canChangeDtmfToneLength(); 5466 } 5467 } catch (RemoteException e) { 5468 Log.e(TAG, "Error calling ITelephony#canChangeDtmfToneLength", e); 5469 } catch (SecurityException e) { 5470 Log.e(TAG, "Permission error calling ITelephony#canChangeDtmfToneLength", e); 5471 } 5472 return false; 5473 } 5474 5475 /** 5476 * Whether the device is a world phone. 5477 * 5478 * @return {@code true} if the device is a world phone, and {@code false} otherwise. 5479 */ 5480 public boolean isWorldPhone() { 5481 try { 5482 ITelephony telephony = getITelephony(); 5483 if (telephony != null) { 5484 return telephony.isWorldPhone(); 5485 } 5486 } catch (RemoteException e) { 5487 Log.e(TAG, "Error calling ITelephony#isWorldPhone", e); 5488 } catch (SecurityException e) { 5489 Log.e(TAG, "Permission error calling ITelephony#isWorldPhone", e); 5490 } 5491 return false; 5492 } 5493 5494 /** 5495 * Whether the phone supports TTY mode. 5496 * 5497 * @return {@code true} if the device supports TTY mode, and {@code false} otherwise. 5498 */ 5499 public boolean isTtyModeSupported() { 5500 try { 5501 ITelephony telephony = getITelephony(); 5502 if (telephony != null) { 5503 return telephony.isTtyModeSupported(); 5504 } 5505 } catch (RemoteException e) { 5506 Log.e(TAG, "Error calling ITelephony#isTtyModeSupported", e); 5507 } catch (SecurityException e) { 5508 Log.e(TAG, "Permission error calling ITelephony#isTtyModeSupported", e); 5509 } 5510 return false; 5511 } 5512 5513 /** 5514 * Whether the phone supports hearing aid compatibility. 5515 * 5516 * @return {@code true} if the device supports hearing aid compatibility, and {@code false} 5517 * otherwise. 5518 */ 5519 public boolean isHearingAidCompatibilitySupported() { 5520 try { 5521 ITelephony telephony = getITelephony(); 5522 if (telephony != null) { 5523 return telephony.isHearingAidCompatibilitySupported(); 5524 } 5525 } catch (RemoteException e) { 5526 Log.e(TAG, "Error calling ITelephony#isHearingAidCompatibilitySupported", e); 5527 } catch (SecurityException e) { 5528 Log.e(TAG, "Permission error calling ITelephony#isHearingAidCompatibilitySupported", e); 5529 } 5530 return false; 5531 } 5532 5533 /** 5534 * This function retrieves value for setting "name+subId", and if that is not found 5535 * retrieves value for setting "name", and if that is not found throws 5536 * SettingNotFoundException 5537 * 5538 * @hide 5539 */ 5540 public static int getIntWithSubId(ContentResolver cr, String name, int subId) 5541 throws SettingNotFoundException { 5542 try { 5543 return Settings.Global.getInt(cr, name + subId); 5544 } catch (SettingNotFoundException e) { 5545 try { 5546 int val = Settings.Global.getInt(cr, name); 5547 Settings.Global.putInt(cr, name + subId, val); 5548 5549 /* We are now moving from 'setting' to 'setting+subId', and using the value stored 5550 * for 'setting' as default. Reset the default (since it may have a user set 5551 * value). */ 5552 int default_val = val; 5553 if (name.equals(Settings.Global.MOBILE_DATA)) { 5554 default_val = "true".equalsIgnoreCase( 5555 SystemProperties.get("ro.com.android.mobiledata", "true")) ? 1 : 0; 5556 } else if (name.equals(Settings.Global.DATA_ROAMING)) { 5557 default_val = "true".equalsIgnoreCase( 5558 SystemProperties.get("ro.com.android.dataroaming", "false")) ? 1 : 0; 5559 } 5560 5561 if (default_val != val) { 5562 Settings.Global.putInt(cr, name, default_val); 5563 } 5564 5565 return val; 5566 } catch (SettingNotFoundException exc) { 5567 throw new SettingNotFoundException(name); 5568 } 5569 } 5570 } 5571 5572 /** 5573 * Returns the IMS Registration Status 5574 * @hide 5575 */ 5576 public boolean isImsRegistered() { 5577 try { 5578 ITelephony telephony = getITelephony(); 5579 if (telephony == null) 5580 return false; 5581 return telephony.isImsRegistered(); 5582 } catch (RemoteException ex) { 5583 return false; 5584 } catch (NullPointerException ex) { 5585 return false; 5586 } 5587 } 5588 5589 /** 5590 * Returns the Status of Volte 5591 * @hide 5592 */ 5593 public boolean isVolteAvailable() { 5594 try { 5595 return getITelephony().isVolteAvailable(); 5596 } catch (RemoteException ex) { 5597 return false; 5598 } catch (NullPointerException ex) { 5599 return false; 5600 } 5601 } 5602 5603 /** 5604 * Returns the Status of video telephony (VT) 5605 * @hide 5606 */ 5607 public boolean isVideoTelephonyAvailable() { 5608 try { 5609 return getITelephony().isVideoTelephonyAvailable(); 5610 } catch (RemoteException ex) { 5611 return false; 5612 } catch (NullPointerException ex) { 5613 return false; 5614 } 5615 } 5616 5617 /** 5618 * Returns the Status of Wi-Fi Calling 5619 * @hide 5620 */ 5621 public boolean isWifiCallingAvailable() { 5622 try { 5623 return getITelephony().isWifiCallingAvailable(); 5624 } catch (RemoteException ex) { 5625 return false; 5626 } catch (NullPointerException ex) { 5627 return false; 5628 } 5629 } 5630 5631 /** 5632 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 5633 * 5634 * @hide 5635 */ 5636 public void setSimOperatorNumeric(String numeric) { 5637 int phoneId = getDefaultPhone(); 5638 setSimOperatorNumericForPhone(phoneId, numeric); 5639 } 5640 5641 /** 5642 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 5643 * 5644 * @hide 5645 */ 5646 public void setSimOperatorNumericForPhone(int phoneId, String numeric) { 5647 setTelephonyProperty(phoneId, 5648 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, numeric); 5649 } 5650 5651 /** 5652 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 5653 * 5654 * @hide 5655 */ 5656 public void setSimOperatorName(String name) { 5657 int phoneId = getDefaultPhone(); 5658 setSimOperatorNameForPhone(phoneId, name); 5659 } 5660 5661 /** 5662 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 5663 * 5664 * @hide 5665 */ 5666 public void setSimOperatorNameForPhone(int phoneId, String name) { 5667 setTelephonyProperty(phoneId, 5668 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, name); 5669 } 5670 5671 /** 5672 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the default phone. 5673 * 5674 * @hide 5675 */ 5676 public void setSimCountryIso(String iso) { 5677 int phoneId = getDefaultPhone(); 5678 setSimCountryIsoForPhone(phoneId, iso); 5679 } 5680 5681 /** 5682 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the given phone. 5683 * 5684 * @hide 5685 */ 5686 public void setSimCountryIsoForPhone(int phoneId, String iso) { 5687 setTelephonyProperty(phoneId, 5688 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, iso); 5689 } 5690 5691 /** 5692 * Set TelephonyProperties.PROPERTY_SIM_STATE for the default phone. 5693 * 5694 * @hide 5695 */ 5696 public void setSimState(String state) { 5697 int phoneId = getDefaultPhone(); 5698 setSimStateForPhone(phoneId, state); 5699 } 5700 5701 /** 5702 * Set TelephonyProperties.PROPERTY_SIM_STATE for the given phone. 5703 * 5704 * @hide 5705 */ 5706 public void setSimStateForPhone(int phoneId, String state) { 5707 setTelephonyProperty(phoneId, 5708 TelephonyProperties.PROPERTY_SIM_STATE, state); 5709 } 5710 5711 /** 5712 * Set SIM card power state. Request is equivalent to inserting or removing the card. 5713 * 5714 * @param powerUp True if powering up the SIM, otherwise powering down 5715 * 5716 * <p>Requires Permission: 5717 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 5718 * 5719 * @hide 5720 **/ 5721 public void setSimPowerState(boolean powerUp) { 5722 setSimPowerStateForSlot(getDefaultSim(), powerUp); 5723 } 5724 5725 /** 5726 * Set SIM card power state. Request is equivalent to inserting or removing the card. 5727 * 5728 * @param slotIndex SIM slot id 5729 * @param powerUp True if powering up the SIM, otherwise powering down 5730 * 5731 * <p>Requires Permission: 5732 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 5733 * 5734 * @hide 5735 **/ 5736 public void setSimPowerStateForSlot(int slotIndex, boolean powerUp) { 5737 try { 5738 ITelephony telephony = getITelephony(); 5739 if (telephony != null) { 5740 telephony.setSimPowerStateForSlot(slotIndex, powerUp); 5741 } 5742 } catch (RemoteException e) { 5743 Log.e(TAG, "Error calling ITelephony#setSimPowerStateForSlot", e); 5744 } catch (SecurityException e) { 5745 Log.e(TAG, "Permission error calling ITelephony#setSimPowerStateForSlot", e); 5746 } 5747 } 5748 5749 /** 5750 * Set baseband version for the default phone. 5751 * 5752 * @param version baseband version 5753 * @hide 5754 */ 5755 public void setBasebandVersion(String version) { 5756 int phoneId = getDefaultPhone(); 5757 setBasebandVersionForPhone(phoneId, version); 5758 } 5759 5760 /** 5761 * Set baseband version by phone id. 5762 * 5763 * @param phoneId for which baseband version is set 5764 * @param version baseband version 5765 * @hide 5766 */ 5767 public void setBasebandVersionForPhone(int phoneId, String version) { 5768 if (SubscriptionManager.isValidPhoneId(phoneId)) { 5769 String prop = TelephonyProperties.PROPERTY_BASEBAND_VERSION + 5770 ((phoneId == 0) ? "" : Integer.toString(phoneId)); 5771 SystemProperties.set(prop, version); 5772 } 5773 } 5774 5775 /** 5776 * Set phone type for the default phone. 5777 * 5778 * @param type phone type 5779 * 5780 * @hide 5781 */ 5782 public void setPhoneType(int type) { 5783 int phoneId = getDefaultPhone(); 5784 setPhoneType(phoneId, type); 5785 } 5786 5787 /** 5788 * Set phone type by phone id. 5789 * 5790 * @param phoneId for which phone type is set 5791 * @param type phone type 5792 * 5793 * @hide 5794 */ 5795 public void setPhoneType(int phoneId, int type) { 5796 if (SubscriptionManager.isValidPhoneId(phoneId)) { 5797 TelephonyManager.setTelephonyProperty(phoneId, 5798 TelephonyProperties.CURRENT_ACTIVE_PHONE, String.valueOf(type)); 5799 } 5800 } 5801 5802 /** 5803 * Get OTASP number schema for the default phone. 5804 * 5805 * @param defaultValue default value 5806 * @return OTA SP number schema 5807 * 5808 * @hide 5809 */ 5810 public String getOtaSpNumberSchema(String defaultValue) { 5811 int phoneId = getDefaultPhone(); 5812 return getOtaSpNumberSchemaForPhone(phoneId, defaultValue); 5813 } 5814 5815 /** 5816 * Get OTASP number schema by phone id. 5817 * 5818 * @param phoneId for which OTA SP number schema is get 5819 * @param defaultValue default value 5820 * @return OTA SP number schema 5821 * 5822 * @hide 5823 */ 5824 public String getOtaSpNumberSchemaForPhone(int phoneId, String defaultValue) { 5825 if (SubscriptionManager.isValidPhoneId(phoneId)) { 5826 return TelephonyManager.getTelephonyProperty(phoneId, 5827 TelephonyProperties.PROPERTY_OTASP_NUM_SCHEMA, defaultValue); 5828 } 5829 5830 return defaultValue; 5831 } 5832 5833 /** 5834 * Get SMS receive capable from system property for the default phone. 5835 * 5836 * @param defaultValue default value 5837 * @return SMS receive capable 5838 * 5839 * @hide 5840 */ 5841 public boolean getSmsReceiveCapable(boolean defaultValue) { 5842 int phoneId = getDefaultPhone(); 5843 return getSmsReceiveCapableForPhone(phoneId, defaultValue); 5844 } 5845 5846 /** 5847 * Get SMS receive capable from system property by phone id. 5848 * 5849 * @param phoneId for which SMS receive capable is get 5850 * @param defaultValue default value 5851 * @return SMS receive capable 5852 * 5853 * @hide 5854 */ 5855 public boolean getSmsReceiveCapableForPhone(int phoneId, boolean defaultValue) { 5856 if (SubscriptionManager.isValidPhoneId(phoneId)) { 5857 return Boolean.parseBoolean(TelephonyManager.getTelephonyProperty(phoneId, 5858 TelephonyProperties.PROPERTY_SMS_RECEIVE, String.valueOf(defaultValue))); 5859 } 5860 5861 return defaultValue; 5862 } 5863 5864 /** 5865 * Get SMS send capable from system property for the default phone. 5866 * 5867 * @param defaultValue default value 5868 * @return SMS send capable 5869 * 5870 * @hide 5871 */ 5872 public boolean getSmsSendCapable(boolean defaultValue) { 5873 int phoneId = getDefaultPhone(); 5874 return getSmsSendCapableForPhone(phoneId, defaultValue); 5875 } 5876 5877 /** 5878 * Get SMS send capable from system property by phone id. 5879 * 5880 * @param phoneId for which SMS send capable is get 5881 * @param defaultValue default value 5882 * @return SMS send capable 5883 * 5884 * @hide 5885 */ 5886 public boolean getSmsSendCapableForPhone(int phoneId, boolean defaultValue) { 5887 if (SubscriptionManager.isValidPhoneId(phoneId)) { 5888 return Boolean.parseBoolean(TelephonyManager.getTelephonyProperty(phoneId, 5889 TelephonyProperties.PROPERTY_SMS_SEND, String.valueOf(defaultValue))); 5890 } 5891 5892 return defaultValue; 5893 } 5894 5895 /** 5896 * Set the alphabetic name of current registered operator. 5897 * @param name the alphabetic name of current registered operator. 5898 * @hide 5899 */ 5900 public void setNetworkOperatorName(String name) { 5901 int phoneId = getDefaultPhone(); 5902 setNetworkOperatorNameForPhone(phoneId, name); 5903 } 5904 5905 /** 5906 * Set the alphabetic name of current registered operator. 5907 * @param phoneId which phone you want to set 5908 * @param name the alphabetic name of current registered operator. 5909 * @hide 5910 */ 5911 public void setNetworkOperatorNameForPhone(int phoneId, String name) { 5912 if (SubscriptionManager.isValidPhoneId(phoneId)) { 5913 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, name); 5914 } 5915 } 5916 5917 /** 5918 * Set the numeric name (MCC+MNC) of current registered operator. 5919 * @param operator the numeric name (MCC+MNC) of current registered operator 5920 * @hide 5921 */ 5922 public void setNetworkOperatorNumeric(String numeric) { 5923 int phoneId = getDefaultPhone(); 5924 setNetworkOperatorNumericForPhone(phoneId, numeric); 5925 } 5926 5927 /** 5928 * Set the numeric name (MCC+MNC) of current registered operator. 5929 * @param phoneId for which phone type is set 5930 * @param operator the numeric name (MCC+MNC) of current registered operator 5931 * @hide 5932 */ 5933 public void setNetworkOperatorNumericForPhone(int phoneId, String numeric) { 5934 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, numeric); 5935 } 5936 5937 /** 5938 * Set roaming state of the current network, for GSM purposes. 5939 * @param isRoaming is network in romaing state or not 5940 * @hide 5941 */ 5942 public void setNetworkRoaming(boolean isRoaming) { 5943 int phoneId = getDefaultPhone(); 5944 setNetworkRoamingForPhone(phoneId, isRoaming); 5945 } 5946 5947 /** 5948 * Set roaming state of the current network, for GSM purposes. 5949 * @param phoneId which phone you want to set 5950 * @param isRoaming is network in romaing state or not 5951 * @hide 5952 */ 5953 public void setNetworkRoamingForPhone(int phoneId, boolean isRoaming) { 5954 if (SubscriptionManager.isValidPhoneId(phoneId)) { 5955 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, 5956 isRoaming ? "true" : "false"); 5957 } 5958 } 5959 5960 /** 5961 * Set the ISO country code equivalent of the current registered 5962 * operator's MCC (Mobile Country Code). 5963 * @param iso the ISO country code equivalent of the current registered 5964 * @hide 5965 */ 5966 public void setNetworkCountryIso(String iso) { 5967 int phoneId = getDefaultPhone(); 5968 setNetworkCountryIsoForPhone(phoneId, iso); 5969 } 5970 5971 /** 5972 * Set the ISO country code equivalent of the current registered 5973 * operator's MCC (Mobile Country Code). 5974 * @param phoneId which phone you want to set 5975 * @param iso the ISO country code equivalent of the current registered 5976 * @hide 5977 */ 5978 public void setNetworkCountryIsoForPhone(int phoneId, String iso) { 5979 if (SubscriptionManager.isValidPhoneId(phoneId)) { 5980 setTelephonyProperty(phoneId, 5981 TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, iso); 5982 } 5983 } 5984 5985 /** 5986 * Set the network type currently in use on the device for data transmission. 5987 * @param type the network type currently in use on the device for data transmission 5988 * @hide 5989 */ 5990 public void setDataNetworkType(int type) { 5991 int phoneId = getDefaultPhone(); 5992 setDataNetworkTypeForPhone(phoneId, type); 5993 } 5994 5995 /** 5996 * Set the network type currently in use on the device for data transmission. 5997 * @param phoneId which phone you want to set 5998 * @param type the network type currently in use on the device for data transmission 5999 * @hide 6000 */ 6001 public void setDataNetworkTypeForPhone(int phoneId, int type) { 6002 if (SubscriptionManager.isValidPhoneId(phoneId)) { 6003 setTelephonyProperty(phoneId, 6004 TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE, 6005 ServiceState.rilRadioTechnologyToString(type)); 6006 } 6007 } 6008 6009 /** 6010 * Returns the subscription ID for the given phone account. 6011 * @hide 6012 */ 6013 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { 6014 int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 6015 try { 6016 ITelephony service = getITelephony(); 6017 if (service != null) { 6018 retval = service.getSubIdForPhoneAccount(phoneAccount); 6019 } 6020 } catch (RemoteException e) { 6021 } 6022 6023 return retval; 6024 } 6025 6026 private int getSubIdForPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) { 6027 int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 6028 try { 6029 ITelecomService service = getTelecomService(); 6030 if (service != null) { 6031 retval = getSubIdForPhoneAccount(service.getPhoneAccount(phoneAccountHandle)); 6032 } 6033 } catch (RemoteException e) { 6034 } 6035 6036 return retval; 6037 } 6038 6039 /** 6040 * Resets telephony manager settings back to factory defaults. 6041 * 6042 * @hide 6043 */ 6044 public void factoryReset(int subId) { 6045 try { 6046 Log.d(TAG, "factoryReset: subId=" + subId); 6047 ITelephony telephony = getITelephony(); 6048 if (telephony != null) 6049 telephony.factoryReset(subId); 6050 } catch (RemoteException e) { 6051 } 6052 } 6053 6054 6055 /** @hide */ 6056 public String getLocaleFromDefaultSim() { 6057 try { 6058 final ITelephony telephony = getITelephony(); 6059 if (telephony != null) { 6060 return telephony.getLocaleFromDefaultSim(); 6061 } 6062 } catch (RemoteException ex) { 6063 } 6064 return null; 6065 } 6066 6067 /** 6068 * Requests the modem activity info. The recipient will place the result 6069 * in `result`. 6070 * @param result The object on which the recipient will send the resulting 6071 * {@link android.telephony.ModemActivityInfo} object. 6072 * @hide 6073 */ 6074 public void requestModemActivityInfo(ResultReceiver result) { 6075 try { 6076 ITelephony service = getITelephony(); 6077 if (service != null) { 6078 service.requestModemActivityInfo(result); 6079 return; 6080 } 6081 } catch (RemoteException e) { 6082 Log.e(TAG, "Error calling ITelephony#getModemActivityInfo", e); 6083 } 6084 result.send(0, null); 6085 } 6086 6087 /** 6088 * Returns the current {@link ServiceState} information. 6089 * 6090 * <p>Requires Permission: 6091 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 6092 */ 6093 public ServiceState getServiceState() { 6094 return getServiceStateForSubscriber(getSubId()); 6095 } 6096 6097 /** 6098 * Returns the service state information on specified subscription. Callers require 6099 * either READ_PRIVILEGED_PHONE_STATE or READ_PHONE_STATE to retrieve the information. 6100 * @hide 6101 */ 6102 public ServiceState getServiceStateForSubscriber(int subId) { 6103 try { 6104 ITelephony service = getITelephony(); 6105 if (service != null) { 6106 return service.getServiceStateForSubscriber(subId, getOpPackageName()); 6107 } 6108 } catch (RemoteException e) { 6109 Log.e(TAG, "Error calling ITelephony#getServiceStateForSubscriber", e); 6110 } 6111 return null; 6112 } 6113 6114 /** 6115 * Returns the URI for the per-account voicemail ringtone set in Phone settings. 6116 * 6117 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the 6118 * voicemail ringtone. 6119 * @return The URI for the ringtone to play when receiving a voicemail from a specific 6120 * PhoneAccount. 6121 */ 6122 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { 6123 try { 6124 ITelephony service = getITelephony(); 6125 if (service != null) { 6126 return service.getVoicemailRingtoneUri(accountHandle); 6127 } 6128 } catch (RemoteException e) { 6129 Log.e(TAG, "Error calling ITelephony#getVoicemailRingtoneUri", e); 6130 } 6131 return null; 6132 } 6133 6134 /** 6135 * Sets the per-account voicemail ringtone. 6136 * 6137 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or has 6138 * permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 6139 * 6140 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the 6141 * voicemail ringtone. 6142 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific 6143 * PhoneAccount. 6144 * @see #hasCarrierPrivileges 6145 */ 6146 public void setVoicemailRingtoneUri(PhoneAccountHandle phoneAccountHandle, Uri uri) { 6147 try { 6148 ITelephony service = getITelephony(); 6149 if (service != null) { 6150 service.setVoicemailRingtoneUri(getOpPackageName(), phoneAccountHandle, uri); 6151 } 6152 } catch (RemoteException e) { 6153 Log.e(TAG, "Error calling ITelephony#setVoicemailRingtoneUri", e); 6154 } 6155 } 6156 6157 /** 6158 * Returns whether vibration is set for voicemail notification in Phone settings. 6159 * 6160 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the 6161 * voicemail vibration setting. 6162 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. 6163 */ 6164 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { 6165 try { 6166 ITelephony service = getITelephony(); 6167 if (service != null) { 6168 return service.isVoicemailVibrationEnabled(accountHandle); 6169 } 6170 } catch (RemoteException e) { 6171 Log.e(TAG, "Error calling ITelephony#isVoicemailVibrationEnabled", e); 6172 } 6173 return false; 6174 } 6175 6176 /** 6177 * Sets the per-account preference whether vibration is enabled for voicemail notifications. 6178 * 6179 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or has 6180 * permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 6181 * 6182 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the 6183 * voicemail vibration setting. 6184 * @param enabled Whether to enable or disable vibration for voicemail notifications from a 6185 * specific PhoneAccount. 6186 * @see #hasCarrierPrivileges 6187 */ 6188 public void setVoicemailVibrationEnabled(PhoneAccountHandle phoneAccountHandle, 6189 boolean enabled) { 6190 try { 6191 ITelephony service = getITelephony(); 6192 if (service != null) { 6193 service.setVoicemailVibrationEnabled(getOpPackageName(), phoneAccountHandle, 6194 enabled); 6195 } 6196 } catch (RemoteException e) { 6197 Log.e(TAG, "Error calling ITelephony#isVoicemailVibrationEnabled", e); 6198 } 6199 } 6200 6201 /** 6202 * Return the application ID for the app type like {@link APPTYPE_CSIM}. 6203 * 6204 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 6205 * 6206 * @param appType the uicc app type like {@link APPTYPE_CSIM} 6207 * @return Application ID for specificied app type or null if no uicc or error. 6208 * @hide 6209 */ 6210 public String getAidForAppType(int appType) { 6211 return getAidForAppType(getDefaultSubscription(), appType); 6212 } 6213 6214 /** 6215 * Return the application ID for the app type like {@link APPTYPE_CSIM}. 6216 * 6217 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 6218 * 6219 * @param subId the subscription ID that this request applies to. 6220 * @param appType the uicc app type, like {@link APPTYPE_CSIM} 6221 * @return Application ID for specificied app type or null if no uicc or error. 6222 * @hide 6223 */ 6224 public String getAidForAppType(int subId, int appType) { 6225 try { 6226 ITelephony service = getITelephony(); 6227 if (service != null) { 6228 return service.getAidForAppType(subId, appType); 6229 } 6230 } catch (RemoteException e) { 6231 Log.e(TAG, "Error calling ITelephony#getAidForAppType", e); 6232 } 6233 return null; 6234 } 6235 6236 /** 6237 * Return the Electronic Serial Number. 6238 * 6239 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 6240 * 6241 * @return ESN or null if error. 6242 * @hide 6243 */ 6244 public String getEsn() { 6245 return getEsn(getDefaultSubscription()); 6246 } 6247 6248 /** 6249 * Return the Electronic Serial Number. 6250 * 6251 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 6252 * 6253 * @param subId the subscription ID that this request applies to. 6254 * @return ESN or null if error. 6255 * @hide 6256 */ 6257 public String getEsn(int subId) { 6258 try { 6259 ITelephony service = getITelephony(); 6260 if (service != null) { 6261 return service.getEsn(subId); 6262 } 6263 } catch (RemoteException e) { 6264 Log.e(TAG, "Error calling ITelephony#getEsn", e); 6265 } 6266 return null; 6267 } 6268 6269 /** 6270 * Return the Preferred Roaming List Version 6271 * 6272 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 6273 * 6274 * @return PRLVersion or null if error. 6275 * @hide 6276 */ 6277 public String getCdmaPrlVersion() { 6278 return getCdmaPrlVersion(getDefaultSubscription()); 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 * @param subId the subscription ID that this request applies to. 6287 * @return PRLVersion or null if error. 6288 * @hide 6289 */ 6290 public String getCdmaPrlVersion(int subId) { 6291 try { 6292 ITelephony service = getITelephony(); 6293 if (service != null) { 6294 return service.getCdmaPrlVersion(subId); 6295 } 6296 } catch (RemoteException e) { 6297 Log.e(TAG, "Error calling ITelephony#getCdmaPrlVersion", e); 6298 } 6299 return null; 6300 } 6301 6302 /** 6303 * Get snapshot of Telephony histograms 6304 * @return List of Telephony histograms 6305 * Requires Permission: 6306 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 6307 * Or the calling app has carrier privileges. 6308 * @hide 6309 */ 6310 @SystemApi 6311 public List<TelephonyHistogram> getTelephonyHistograms() { 6312 try { 6313 ITelephony service = getITelephony(); 6314 if (service != null) { 6315 return service.getTelephonyHistograms(); 6316 } 6317 } catch (RemoteException e) { 6318 Log.e(TAG, "Error calling ITelephony#getTelephonyHistograms", e); 6319 } 6320 return null; 6321 } 6322 6323 /** 6324 * Set the allowed carrier list for slotIndex 6325 * Require system privileges. In the future we may add this to carrier APIs. 6326 * 6327 * <p>Requires Permission: 6328 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} 6329 * 6330 * <p>This method works only on devices with {@link 6331 * android.content.pm.PackageManager#FEATURE_TELEPHONY_CARRIERLOCK} enabled. 6332 * 6333 * @return The number of carriers set successfully. Should be length of 6334 * carrierList on success; -1 if carrierList null or on error. 6335 * @hide 6336 */ 6337 @SystemApi 6338 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) { 6339 try { 6340 ITelephony service = getITelephony(); 6341 if (service != null) { 6342 return service.setAllowedCarriers(slotIndex, carriers); 6343 } 6344 } catch (RemoteException e) { 6345 Log.e(TAG, "Error calling ITelephony#setAllowedCarriers", e); 6346 } catch (NullPointerException e) { 6347 Log.e(TAG, "Error calling ITelephony#setAllowedCarriers", e); 6348 } 6349 return -1; 6350 } 6351 6352 /** 6353 * Get the allowed carrier list for slotIndex. 6354 * Require system privileges. In the future we may add this to carrier APIs. 6355 * 6356 * <p>Requires Permission: 6357 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} 6358 * 6359 * <p>This method returns valid data on devices with {@link 6360 * android.content.pm.PackageManager#FEATURE_TELEPHONY_CARRIERLOCK} enabled. 6361 * 6362 * @return List of {@link android.telephony.CarrierIdentifier}; empty list 6363 * means all carriers are allowed. 6364 * @hide 6365 */ 6366 @SystemApi 6367 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) { 6368 try { 6369 ITelephony service = getITelephony(); 6370 if (service != null) { 6371 return service.getAllowedCarriers(slotIndex); 6372 } 6373 } catch (RemoteException e) { 6374 Log.e(TAG, "Error calling ITelephony#getAllowedCarriers", e); 6375 } catch (NullPointerException e) { 6376 Log.e(TAG, "Error calling ITelephony#setAllowedCarriers", e); 6377 } 6378 return new ArrayList<CarrierIdentifier>(0); 6379 } 6380 6381 /** 6382 * Action set from carrier signalling broadcast receivers to enable/disable metered apns 6383 * Permissions android.Manifest.permission.MODIFY_PHONE_STATE is required 6384 * @param subId the subscription ID that this action applies to. 6385 * @param enabled control enable or disable metered apns. 6386 * @hide 6387 */ 6388 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { 6389 try { 6390 ITelephony service = getITelephony(); 6391 if (service != null) { 6392 service.carrierActionSetMeteredApnsEnabled(subId, enabled); 6393 } 6394 } catch (RemoteException e) { 6395 Log.e(TAG, "Error calling ITelephony#carrierActionSetMeteredApnsEnabled", e); 6396 } 6397 } 6398 6399 /** 6400 * Action set from carrier signalling broadcast receivers to enable/disable radio 6401 * Permissions android.Manifest.permission.MODIFY_PHONE_STATE is required 6402 * @param subId the subscription ID that this action applies to. 6403 * @param enabled control enable or disable radio. 6404 * @hide 6405 */ 6406 public void carrierActionSetRadioEnabled(int subId, boolean enabled) { 6407 try { 6408 ITelephony service = getITelephony(); 6409 if (service != null) { 6410 service.carrierActionSetRadioEnabled(subId, enabled); 6411 } 6412 } catch (RemoteException e) { 6413 Log.e(TAG, "Error calling ITelephony#carrierActionSetRadioEnabled", e); 6414 } 6415 } 6416 6417 /** 6418 * Get aggregated video call data usage since boot. 6419 * Permissions android.Manifest.permission.READ_NETWORK_USAGE_HISTORY is required. 6420 * @return total data usage in bytes 6421 * @hide 6422 */ 6423 public long getVtDataUsage() { 6424 6425 try { 6426 ITelephony service = getITelephony(); 6427 if (service != null) { 6428 return service.getVtDataUsage(); 6429 } 6430 } catch (RemoteException e) { 6431 Log.e(TAG, "Error calling getVtDataUsage", e); 6432 } 6433 return 0; 6434 } 6435 6436 /** 6437 * Policy control of data connection. Usually used when data limit is passed. 6438 * @param enabled True if enabling the data, otherwise disabling. 6439 * @param subId sub id 6440 * @hide 6441 */ 6442 public void setPolicyDataEnabled(boolean enabled, int subId) { 6443 try { 6444 ITelephony service = getITelephony(); 6445 if (service != null) { 6446 service.setPolicyDataEnabled(enabled, subId); 6447 } 6448 } catch (RemoteException e) { 6449 Log.e(TAG, "Error calling ITelephony#setPolicyDataEnabled", e); 6450 } 6451 } 6452 6453 /** 6454 * Get Client request stats which will contain statistical information 6455 * on each request made by client. 6456 * Callers require either READ_PRIVILEGED_PHONE_STATE or 6457 * READ_PHONE_STATE to retrieve the information. 6458 * @param subId sub id 6459 * @return List of Client Request Stats 6460 * @hide 6461 */ 6462 public List<ClientRequestStats> getClientRequestStats(int subId) { 6463 try { 6464 ITelephony service = getITelephony(); 6465 if (service != null) { 6466 return service.getClientRequestStats(getOpPackageName(), subId); 6467 } 6468 } catch (RemoteException e) { 6469 Log.e(TAG, "Error calling ITelephony#getClientRequestStats", e); 6470 } 6471 6472 return null; 6473 } 6474} 6475 6476