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