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