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