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