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