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