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