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