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