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