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