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