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