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