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