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