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