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