Home | History | Annotate | Download | only in telephony
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.telephony;
     18 
     19 import android.annotation.Nullable;
     20 import android.annotation.SystemApi;
     21 import android.annotation.SdkConstant;
     22 import android.annotation.SdkConstant.SdkConstantType;
     23 import android.content.ContentResolver;
     24 import android.content.Context;
     25 import android.content.Intent;
     26 import android.provider.Settings;
     27 import android.provider.Settings.SettingNotFoundException;
     28 import android.os.Bundle;
     29 import android.os.RemoteException;
     30 import android.os.ServiceManager;
     31 import android.os.SystemProperties;
     32 import android.util.Log;
     33 
     34 import com.android.internal.telecom.ITelecomService;
     35 import com.android.internal.telephony.IPhoneSubInfo;
     36 import com.android.internal.telephony.ITelephony;
     37 import com.android.internal.telephony.ITelephonyRegistry;
     38 import com.android.internal.telephony.PhoneConstants;
     39 import com.android.internal.telephony.RILConstants;
     40 import com.android.internal.telephony.TelephonyProperties;
     41 
     42 import java.io.FileInputStream;
     43 import java.io.IOException;
     44 import java.util.Arrays;
     45 import java.util.List;
     46 import java.util.Set;
     47 import java.util.regex.Matcher;
     48 import java.util.regex.Pattern;
     49 
     50 /**
     51  * Provides access to information about the telephony services on
     52  * the device. Applications can use the methods in this class to
     53  * determine telephony services and states, as well as to access some
     54  * types of subscriber information. Applications can also register
     55  * a listener to receive notification of telephony state changes.
     56  * <p>
     57  * You do not instantiate this class directly; instead, you retrieve
     58  * a reference to an instance through
     59  * {@link android.content.Context#getSystemService
     60  * Context.getSystemService(Context.TELEPHONY_SERVICE)}.
     61  * <p>
     62  * Note that access to some telephony information is
     63  * permission-protected. Your application cannot access the protected
     64  * information unless it has the appropriate permissions declared in
     65  * its manifest file. Where permissions apply, they are noted in the
     66  * the methods through which you access the protected information.
     67  */
     68 public class TelephonyManager {
     69     private static final String TAG = "TelephonyManager";
     70 
     71     private static ITelephonyRegistry sRegistry;
     72 
     73     /**
     74      * The allowed states of Wi-Fi calling.
     75      *
     76      * @hide
     77      */
     78     public interface WifiCallingChoices {
     79         /** Always use Wi-Fi calling */
     80         static final int ALWAYS_USE = 0;
     81         /** Ask the user whether to use Wi-Fi on every call */
     82         static final int ASK_EVERY_TIME = 1;
     83         /** Never use Wi-Fi calling */
     84         static final int NEVER_USE = 2;
     85     }
     86 
     87     private final Context mContext;
     88     private SubscriptionManager mSubscriptionManager;
     89 
     90     private static String multiSimConfig =
     91             SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG);
     92 
     93     /** Enum indicating multisim variants
     94      *  DSDS - Dual SIM Dual Standby
     95      *  DSDA - Dual SIM Dual Active
     96      *  TSTS - Triple SIM Triple Standby
     97      **/
     98     /** @hide */
     99     public enum MultiSimVariants {
    100         DSDS,
    101         DSDA,
    102         TSTS,
    103         UNKNOWN
    104     };
    105 
    106     /** @hide */
    107     public TelephonyManager(Context context) {
    108         Context appContext = context.getApplicationContext();
    109         if (appContext != null) {
    110             mContext = appContext;
    111         } else {
    112             mContext = context;
    113         }
    114         mSubscriptionManager = SubscriptionManager.from(mContext);
    115 
    116         if (sRegistry == null) {
    117             sRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService(
    118                     "telephony.registry"));
    119         }
    120     }
    121 
    122     /** @hide */
    123     private TelephonyManager() {
    124         mContext = null;
    125     }
    126 
    127     private static TelephonyManager sInstance = new TelephonyManager();
    128 
    129     /** @hide
    130     /* @deprecated - use getSystemService as described above */
    131     public static TelephonyManager getDefault() {
    132         return sInstance;
    133     }
    134 
    135 
    136     /**
    137      * Returns the multi SIM variant
    138      * Returns DSDS for Dual SIM Dual Standby
    139      * Returns DSDA for Dual SIM Dual Active
    140      * Returns TSTS for Triple SIM Triple Standby
    141      * Returns UNKNOWN for others
    142      */
    143     /** {@hide} */
    144     public MultiSimVariants getMultiSimConfiguration() {
    145         String mSimConfig =
    146             SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG);
    147         if (mSimConfig.equals("dsds")) {
    148             return MultiSimVariants.DSDS;
    149         } else if (mSimConfig.equals("dsda")) {
    150             return MultiSimVariants.DSDA;
    151         } else if (mSimConfig.equals("tsts")) {
    152             return MultiSimVariants.TSTS;
    153         } else {
    154             return MultiSimVariants.UNKNOWN;
    155         }
    156     }
    157 
    158 
    159     /**
    160      * Returns the number of phones available.
    161      * Returns 1 for Single standby mode (Single SIM functionality)
    162      * Returns 2 for Dual standby mode.(Dual SIM functionality)
    163      */
    164     /** {@hide} */
    165     public int getPhoneCount() {
    166         int phoneCount = 1;
    167         switch (getMultiSimConfiguration()) {
    168             case UNKNOWN:
    169                 phoneCount = 1;
    170                 break;
    171             case DSDS:
    172             case DSDA:
    173                 phoneCount = PhoneConstants.MAX_PHONE_COUNT_DUAL_SIM;
    174                 break;
    175             case TSTS:
    176                 phoneCount = PhoneConstants.MAX_PHONE_COUNT_TRI_SIM;
    177                 break;
    178         }
    179         return phoneCount;
    180     }
    181 
    182     /** {@hide} */
    183     public static TelephonyManager from(Context context) {
    184         return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    185     }
    186 
    187     /** {@hide} */
    188     public boolean isMultiSimEnabled() {
    189         return (multiSimConfig.equals("dsds") || multiSimConfig.equals("dsda") ||
    190             multiSimConfig.equals("tsts"));
    191     }
    192 
    193     //
    194     // Broadcast Intent actions
    195     //
    196 
    197     /**
    198      * Broadcast intent action indicating that the call state (cellular)
    199      * on the device has changed.
    200      *
    201      * <p>
    202      * The {@link #EXTRA_STATE} extra indicates the new call state.
    203      * If the new state is RINGING, a second extra
    204      * {@link #EXTRA_INCOMING_NUMBER} provides the incoming phone number as
    205      * a String.
    206      *
    207      * <p class="note">
    208      * Requires the READ_PHONE_STATE permission.
    209      *
    210      * <p class="note">
    211      * This was a {@link android.content.Context#sendStickyBroadcast sticky}
    212      * broadcast in version 1.0, but it is no longer sticky.
    213      * Instead, use {@link #getCallState} to synchronously query the current call state.
    214      *
    215      * @see #EXTRA_STATE
    216      * @see #EXTRA_INCOMING_NUMBER
    217      * @see #getCallState
    218      */
    219     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    220     public static final String ACTION_PHONE_STATE_CHANGED =
    221             "android.intent.action.PHONE_STATE";
    222 
    223     /**
    224      * The Phone app sends this intent when a user opts to respond-via-message during an incoming
    225      * call. By default, the device's default SMS app consumes this message and sends a text message
    226      * to the caller. A third party app can also provide this functionality by consuming this Intent
    227      * with a {@link android.app.Service} and sending the message using its own messaging system.
    228      * <p>The intent contains a URI (available from {@link android.content.Intent#getData})
    229      * describing the recipient, using either the {@code sms:}, {@code smsto:}, {@code mms:},
    230      * or {@code mmsto:} URI schema. Each of these URI schema carry the recipient information the
    231      * same way: the path part of the URI contains the recipient's phone number or a comma-separated
    232      * set of phone numbers if there are multiple recipients. For example, {@code
    233      * smsto:2065551234}.</p>
    234      *
    235      * <p>The intent may also contain extras for the message text (in {@link
    236      * android.content.Intent#EXTRA_TEXT}) and a message subject
    237      * (in {@link android.content.Intent#EXTRA_SUBJECT}).</p>
    238      *
    239      * <p class="note"><strong>Note:</strong>
    240      * The intent-filter that consumes this Intent needs to be in a {@link android.app.Service}
    241      * that requires the
    242      * permission {@link android.Manifest.permission#SEND_RESPOND_VIA_MESSAGE}.</p>
    243      * <p>For example, the service that receives this intent can be declared in the manifest file
    244      * with an intent filter like this:</p>
    245      * <pre>
    246      * &lt;!-- Service that delivers SMS messages received from the phone "quick response" -->
    247      * &lt;service android:name=".HeadlessSmsSendService"
    248      *          android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
    249      *          android:exported="true" >
    250      *   &lt;intent-filter>
    251      *     &lt;action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
    252      *     &lt;category android:name="android.intent.category.DEFAULT" />
    253      *     &lt;data android:scheme="sms" />
    254      *     &lt;data android:scheme="smsto" />
    255      *     &lt;data android:scheme="mms" />
    256      *     &lt;data android:scheme="mmsto" />
    257      *   &lt;/intent-filter>
    258      * &lt;/service></pre>
    259      * <p>
    260      * Output: nothing.
    261      */
    262     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    263     public static final String ACTION_RESPOND_VIA_MESSAGE =
    264             "android.intent.action.RESPOND_VIA_MESSAGE";
    265 
    266     /**
    267      * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast
    268      * for a String containing the new call state.
    269      *
    270      * @see #EXTRA_STATE_IDLE
    271      * @see #EXTRA_STATE_RINGING
    272      * @see #EXTRA_STATE_OFFHOOK
    273      *
    274      * <p class="note">
    275      * Retrieve with
    276      * {@link android.content.Intent#getStringExtra(String)}.
    277      */
    278     public static final String EXTRA_STATE = PhoneConstants.STATE_KEY;
    279 
    280     /**
    281      * Value used with {@link #EXTRA_STATE} corresponding to
    282      * {@link #CALL_STATE_IDLE}.
    283      */
    284     public static final String EXTRA_STATE_IDLE = PhoneConstants.State.IDLE.toString();
    285 
    286     /**
    287      * Value used with {@link #EXTRA_STATE} corresponding to
    288      * {@link #CALL_STATE_RINGING}.
    289      */
    290     public static final String EXTRA_STATE_RINGING = PhoneConstants.State.RINGING.toString();
    291 
    292     /**
    293      * Value used with {@link #EXTRA_STATE} corresponding to
    294      * {@link #CALL_STATE_OFFHOOK}.
    295      */
    296     public static final String EXTRA_STATE_OFFHOOK = PhoneConstants.State.OFFHOOK.toString();
    297 
    298     /**
    299      * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast
    300      * for a String containing the incoming phone number.
    301      * Only valid when the new call state is RINGING.
    302      *
    303      * <p class="note">
    304      * Retrieve with
    305      * {@link android.content.Intent#getStringExtra(String)}.
    306      */
    307     public static final String EXTRA_INCOMING_NUMBER = "incoming_number";
    308 
    309     /**
    310      * Broadcast intent action indicating that a precise call state
    311      * (cellular) on the device has changed.
    312      *
    313      * <p>
    314      * The {@link #EXTRA_RINGING_CALL_STATE} extra indicates the ringing call state.
    315      * The {@link #EXTRA_FOREGROUND_CALL_STATE} extra indicates the foreground call state.
    316      * The {@link #EXTRA_BACKGROUND_CALL_STATE} extra indicates the background call state.
    317      * The {@link #EXTRA_DISCONNECT_CAUSE} extra indicates the disconnect cause.
    318      * The {@link #EXTRA_PRECISE_DISCONNECT_CAUSE} extra indicates the precise disconnect cause.
    319      *
    320      * <p class="note">
    321      * Requires the READ_PRECISE_PHONE_STATE permission.
    322      *
    323      * @see #EXTRA_RINGING_CALL_STATE
    324      * @see #EXTRA_FOREGROUND_CALL_STATE
    325      * @see #EXTRA_BACKGROUND_CALL_STATE
    326      * @see #EXTRA_DISCONNECT_CAUSE
    327      * @see #EXTRA_PRECISE_DISCONNECT_CAUSE
    328      *
    329      * <p class="note">
    330      * Requires the READ_PRECISE_PHONE_STATE permission.
    331      *
    332      * @hide
    333      */
    334     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    335     public static final String ACTION_PRECISE_CALL_STATE_CHANGED =
    336             "android.intent.action.PRECISE_CALL_STATE";
    337 
    338     /**
    339      * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast
    340      * for an integer containing the state of the current ringing call.
    341      *
    342      * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID
    343      * @see PreciseCallState#PRECISE_CALL_STATE_IDLE
    344      * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE
    345      * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING
    346      * @see PreciseCallState#PRECISE_CALL_STATE_DIALING
    347      * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING
    348      * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING
    349      * @see PreciseCallState#PRECISE_CALL_STATE_WAITING
    350      * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED
    351      * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING
    352      *
    353      * <p class="note">
    354      * Retrieve with
    355      * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
    356      *
    357      * @hide
    358      */
    359     public static final String EXTRA_RINGING_CALL_STATE = "ringing_state";
    360 
    361     /**
    362      * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast
    363      * for an integer containing the state of the current foreground call.
    364      *
    365      * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID
    366      * @see PreciseCallState#PRECISE_CALL_STATE_IDLE
    367      * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE
    368      * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING
    369      * @see PreciseCallState#PRECISE_CALL_STATE_DIALING
    370      * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING
    371      * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING
    372      * @see PreciseCallState#PRECISE_CALL_STATE_WAITING
    373      * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED
    374      * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING
    375      *
    376      * <p class="note">
    377      * Retrieve with
    378      * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
    379      *
    380      * @hide
    381      */
    382     public static final String EXTRA_FOREGROUND_CALL_STATE = "foreground_state";
    383 
    384     /**
    385      * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast
    386      * for an integer containing the state of the current background call.
    387      *
    388      * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID
    389      * @see PreciseCallState#PRECISE_CALL_STATE_IDLE
    390      * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE
    391      * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING
    392      * @see PreciseCallState#PRECISE_CALL_STATE_DIALING
    393      * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING
    394      * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING
    395      * @see PreciseCallState#PRECISE_CALL_STATE_WAITING
    396      * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED
    397      * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING
    398      *
    399      * <p class="note">
    400      * Retrieve with
    401      * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
    402      *
    403      * @hide
    404      */
    405     public static final String EXTRA_BACKGROUND_CALL_STATE = "background_state";
    406 
    407     /**
    408      * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast
    409      * for an integer containing the disconnect cause.
    410      *
    411      * @see DisconnectCause
    412      *
    413      * <p class="note">
    414      * Retrieve with
    415      * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
    416      *
    417      * @hide
    418      */
    419     public static final String EXTRA_DISCONNECT_CAUSE = "disconnect_cause";
    420 
    421     /**
    422      * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast
    423      * for an integer containing the disconnect cause provided by the RIL.
    424      *
    425      * @see PreciseDisconnectCause
    426      *
    427      * <p class="note">
    428      * Retrieve with
    429      * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
    430      *
    431      * @hide
    432      */
    433     public static final String EXTRA_PRECISE_DISCONNECT_CAUSE = "precise_disconnect_cause";
    434 
    435     /**
    436      * Broadcast intent action indicating a data connection has changed,
    437      * providing precise information about the connection.
    438      *
    439      * <p>
    440      * The {@link #EXTRA_DATA_STATE} extra indicates the connection state.
    441      * The {@link #EXTRA_DATA_NETWORK_TYPE} extra indicates the connection network type.
    442      * The {@link #EXTRA_DATA_APN_TYPE} extra indicates the APN type.
    443      * The {@link #EXTRA_DATA_APN} extra indicates the APN.
    444      * The {@link #EXTRA_DATA_CHANGE_REASON} extra indicates the connection change reason.
    445      * The {@link #EXTRA_DATA_IFACE_PROPERTIES} extra indicates the connection interface.
    446      * The {@link #EXTRA_DATA_FAILURE_CAUSE} extra indicates the connection fail cause.
    447      *
    448      * <p class="note">
    449      * Requires the READ_PRECISE_PHONE_STATE permission.
    450      *
    451      * @see #EXTRA_DATA_STATE
    452      * @see #EXTRA_DATA_NETWORK_TYPE
    453      * @see #EXTRA_DATA_APN_TYPE
    454      * @see #EXTRA_DATA_APN
    455      * @see #EXTRA_DATA_CHANGE_REASON
    456      * @see #EXTRA_DATA_IFACE
    457      * @see #EXTRA_DATA_FAILURE_CAUSE
    458      * @hide
    459      */
    460     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    461     public static final String ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED =
    462             "android.intent.action.PRECISE_DATA_CONNECTION_STATE_CHANGED";
    463 
    464     /**
    465      * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
    466      * for an integer containing the state of the current data connection.
    467      *
    468      * @see TelephonyManager#DATA_UNKNOWN
    469      * @see TelephonyManager#DATA_DISCONNECTED
    470      * @see TelephonyManager#DATA_CONNECTING
    471      * @see TelephonyManager#DATA_CONNECTED
    472      * @see TelephonyManager#DATA_SUSPENDED
    473      *
    474      * <p class="note">
    475      * Retrieve with
    476      * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
    477      *
    478      * @hide
    479      */
    480     public static final String EXTRA_DATA_STATE = PhoneConstants.STATE_KEY;
    481 
    482     /**
    483      * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
    484      * for an integer containing the network type.
    485      *
    486      * @see TelephonyManager#NETWORK_TYPE_UNKNOWN
    487      * @see TelephonyManager#NETWORK_TYPE_GPRS
    488      * @see TelephonyManager#NETWORK_TYPE_EDGE
    489      * @see TelephonyManager#NETWORK_TYPE_UMTS
    490      * @see TelephonyManager#NETWORK_TYPE_CDMA
    491      * @see TelephonyManager#NETWORK_TYPE_EVDO_0
    492      * @see TelephonyManager#NETWORK_TYPE_EVDO_A
    493      * @see TelephonyManager#NETWORK_TYPE_1xRTT
    494      * @see TelephonyManager#NETWORK_TYPE_HSDPA
    495      * @see TelephonyManager#NETWORK_TYPE_HSUPA
    496      * @see TelephonyManager#NETWORK_TYPE_HSPA
    497      * @see TelephonyManager#NETWORK_TYPE_IDEN
    498      * @see TelephonyManager#NETWORK_TYPE_EVDO_B
    499      * @see TelephonyManager#NETWORK_TYPE_LTE
    500      * @see TelephonyManager#NETWORK_TYPE_EHRPD
    501      * @see TelephonyManager#NETWORK_TYPE_HSPAP
    502      *
    503      * <p class="note">
    504      * Retrieve with
    505      * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
    506      *
    507      * @hide
    508      */
    509     public static final String EXTRA_DATA_NETWORK_TYPE = PhoneConstants.DATA_NETWORK_TYPE_KEY;
    510 
    511     /**
    512      * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
    513      * for an String containing the data APN type.
    514      *
    515      * <p class="note">
    516      * Retrieve with
    517      * {@link android.content.Intent#getStringExtra(String name)}.
    518      *
    519      * @hide
    520      */
    521     public static final String EXTRA_DATA_APN_TYPE = PhoneConstants.DATA_APN_TYPE_KEY;
    522 
    523     /**
    524      * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
    525      * for an String containing the data APN.
    526      *
    527      * <p class="note">
    528      * Retrieve with
    529      * {@link android.content.Intent#getStringExtra(String name)}.
    530      *
    531      * @hide
    532      */
    533     public static final String EXTRA_DATA_APN = PhoneConstants.DATA_APN_KEY;
    534 
    535     /**
    536      * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
    537      * for an String representation of the change reason.
    538      *
    539      * <p class="note">
    540      * Retrieve with
    541      * {@link android.content.Intent#getStringExtra(String name)}.
    542      *
    543      * @hide
    544      */
    545     public static final String EXTRA_DATA_CHANGE_REASON = PhoneConstants.STATE_CHANGE_REASON_KEY;
    546 
    547     /**
    548      * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
    549      * for an String representation of the data interface.
    550      *
    551      * <p class="note">
    552      * Retrieve with
    553      * {@link android.content.Intent#getParcelableExtra(String name)}.
    554      *
    555      * @hide
    556      */
    557     public static final String EXTRA_DATA_LINK_PROPERTIES_KEY = PhoneConstants.DATA_LINK_PROPERTIES_KEY;
    558 
    559     /**
    560      * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
    561      * for the data connection fail cause.
    562      *
    563      * <p class="note">
    564      * Retrieve with
    565      * {@link android.content.Intent#getStringExtra(String name)}.
    566      *
    567      * @hide
    568      */
    569     public static final String EXTRA_DATA_FAILURE_CAUSE = PhoneConstants.DATA_FAILURE_CAUSE_KEY;
    570 
    571     //
    572     //
    573     // Device Info
    574     //
    575     //
    576 
    577     /**
    578      * Returns the software version number for the device, for example,
    579      * the IMEI/SV for GSM phones. Return null if the software version is
    580      * not available.
    581      *
    582      * <p>Requires Permission:
    583      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
    584      */
    585     public String getDeviceSoftwareVersion() {
    586         return getDeviceSoftwareVersion(getDefaultSim());
    587     }
    588 
    589     /**
    590      * Returns the software version number for the device, for example,
    591      * the IMEI/SV for GSM phones. Return null if the software version is
    592      * not available.
    593      *
    594      * <p>Requires Permission:
    595      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
    596      *
    597      * @param slotId of which deviceID is returned
    598      */
    599     /** {@hide} */
    600     public String getDeviceSoftwareVersion(int slotId) {
    601         // FIXME methods taking slot id should not use subscription, instead us Uicc directly
    602         int[] subId = SubscriptionManager.getSubId(slotId);
    603         if (subId == null || subId.length == 0) {
    604             return null;
    605         }
    606         try {
    607             return getSubscriberInfo().getDeviceSvnUsingSubId(subId[0]);
    608         } catch (RemoteException ex) {
    609             return null;
    610         } catch (NullPointerException ex) {
    611             return null;
    612         }
    613     }
    614 
    615     /**
    616      * Returns the unique device ID, for example, the IMEI for GSM and the MEID
    617      * or ESN for CDMA phones. Return null if device ID is not available.
    618      *
    619      * <p>Requires Permission:
    620      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
    621      */
    622     public String getDeviceId() {
    623         try {
    624             return getITelephony().getDeviceId();
    625         } catch (RemoteException ex) {
    626             return null;
    627         } catch (NullPointerException ex) {
    628             return null;
    629         }
    630     }
    631 
    632     /**
    633      * Returns the unique device ID of a subscription, for example, the IMEI for
    634      * GSM and the MEID for CDMA phones. Return null if device ID is not available.
    635      *
    636      * <p>Requires Permission:
    637      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
    638      *
    639      * @param slotId of which deviceID is returned
    640      */
    641     /** {@hide} */
    642     public String getDeviceId(int slotId) {
    643         // FIXME this assumes phoneId == slotId
    644         try {
    645             return getSubscriberInfo().getDeviceIdForPhone(slotId);
    646         } catch (RemoteException ex) {
    647             return null;
    648         } catch (NullPointerException ex) {
    649             return null;
    650         }
    651     }
    652 
    653     /**
    654      * Returns the IMEI. Return null if IMEI is not available.
    655      *
    656      * <p>Requires Permission:
    657      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
    658      */
    659     /** {@hide} */
    660     public String getImei() {
    661         return getImei(getDefaultSim());
    662     }
    663 
    664     /**
    665      * Returns the IMEI. Return null if IMEI is not available.
    666      *
    667      * <p>Requires Permission:
    668      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
    669      *
    670      * @param slotId of which deviceID is returned
    671      */
    672     /** {@hide} */
    673     public String getImei(int slotId) {
    674         int[] subId = SubscriptionManager.getSubId(slotId);
    675         try {
    676             return getSubscriberInfo().getImeiForSubscriber(subId[0]);
    677         } catch (RemoteException ex) {
    678             return null;
    679         } catch (NullPointerException ex) {
    680             return null;
    681         }
    682     }
    683 
    684     /**
    685      * Returns the NAI. Return null if NAI is not available.
    686      *
    687      */
    688     /** {@hide}*/
    689     public String getNai() {
    690         return getNai(getDefaultSim());
    691     }
    692 
    693     /**
    694      * Returns the NAI. Return null if NAI is not available.
    695      *
    696      *  @param slotId of which Nai is returned
    697      */
    698     /** {@hide}*/
    699     public String getNai(int slotId) {
    700         int[] subId = SubscriptionManager.getSubId(slotId);
    701         try {
    702             String nai = getSubscriberInfo().getNaiForSubscriber(subId[0]);
    703             if (Log.isLoggable(TAG, Log.VERBOSE)) {
    704                 Rlog.v(TAG, "Nai = " + nai);
    705             }
    706             return nai;
    707         } catch (RemoteException ex) {
    708             return null;
    709         } catch (NullPointerException ex) {
    710             return null;
    711         }
    712     }
    713 
    714     /**
    715      * Returns the current location of the device.
    716      *<p>
    717      * If there is only one radio in the device and that radio has an LTE connection,
    718      * this method will return null. The implementation must not to try add LTE
    719      * identifiers into the existing cdma/gsm classes.
    720      *<p>
    721      * In the future this call will be deprecated.
    722      *<p>
    723      * @return Current location of the device or null if not available.
    724      *
    725      * <p>Requires Permission:
    726      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or
    727      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION}.
    728      */
    729     public CellLocation getCellLocation() {
    730         try {
    731             Bundle bundle = getITelephony().getCellLocation();
    732             if (bundle.isEmpty()) return null;
    733             CellLocation cl = CellLocation.newFromBundle(bundle);
    734             if (cl.isEmpty())
    735                 return null;
    736             return cl;
    737         } catch (RemoteException ex) {
    738             return null;
    739         } catch (NullPointerException ex) {
    740             return null;
    741         }
    742     }
    743 
    744     /**
    745      * Enables location update notifications.  {@link PhoneStateListener#onCellLocationChanged
    746      * PhoneStateListener.onCellLocationChanged} will be called on location updates.
    747      *
    748      * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES
    749      * CONTROL_LOCATION_UPDATES}
    750      *
    751      * @hide
    752      */
    753     public void enableLocationUpdates() {
    754             enableLocationUpdates(getDefaultSubscription());
    755     }
    756 
    757     /**
    758      * Enables location update notifications for a subscription.
    759      * {@link PhoneStateListener#onCellLocationChanged
    760      * PhoneStateListener.onCellLocationChanged} will be called on location updates.
    761      *
    762      * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES
    763      * CONTROL_LOCATION_UPDATES}
    764      *
    765      * @param subId for which the location updates are enabled
    766      */
    767     /** @hide */
    768     public void enableLocationUpdates(int subId) {
    769         try {
    770             getITelephony().enableLocationUpdatesForSubscriber(subId);
    771         } catch (RemoteException ex) {
    772         } catch (NullPointerException ex) {
    773         }
    774     }
    775 
    776     /**
    777      * Disables location update notifications.  {@link PhoneStateListener#onCellLocationChanged
    778      * PhoneStateListener.onCellLocationChanged} will be called on location updates.
    779      *
    780      * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES
    781      * CONTROL_LOCATION_UPDATES}
    782      *
    783      * @hide
    784      */
    785     public void disableLocationUpdates() {
    786             disableLocationUpdates(getDefaultSubscription());
    787     }
    788 
    789     /** @hide */
    790     public void disableLocationUpdates(int subId) {
    791         try {
    792             getITelephony().disableLocationUpdatesForSubscriber(subId);
    793         } catch (RemoteException ex) {
    794         } catch (NullPointerException ex) {
    795         }
    796     }
    797 
    798     /**
    799      * Returns the neighboring cell information of the device. The getAllCellInfo is preferred
    800      * and use this only if getAllCellInfo return nulls or an empty list.
    801      *<p>
    802      * In the future this call will be deprecated.
    803      *<p>
    804      * @return List of NeighboringCellInfo or null if info unavailable.
    805      *
    806      * <p>Requires Permission:
    807      * (@link android.Manifest.permission#ACCESS_COARSE_UPDATES}
    808      */
    809     public List<NeighboringCellInfo> getNeighboringCellInfo() {
    810         try {
    811             return getITelephony().getNeighboringCellInfo(mContext.getOpPackageName());
    812         } catch (RemoteException ex) {
    813             return null;
    814         } catch (NullPointerException ex) {
    815             return null;
    816         }
    817     }
    818 
    819     /** No phone radio. */
    820     public static final int PHONE_TYPE_NONE = PhoneConstants.PHONE_TYPE_NONE;
    821     /** Phone radio is GSM. */
    822     public static final int PHONE_TYPE_GSM = PhoneConstants.PHONE_TYPE_GSM;
    823     /** Phone radio is CDMA. */
    824     public static final int PHONE_TYPE_CDMA = PhoneConstants.PHONE_TYPE_CDMA;
    825     /** Phone is via SIP. */
    826     public static final int PHONE_TYPE_SIP = PhoneConstants.PHONE_TYPE_SIP;
    827 
    828     /**
    829      * Returns the current phone type.
    830      * TODO: This is a last minute change and hence hidden.
    831      *
    832      * @see #PHONE_TYPE_NONE
    833      * @see #PHONE_TYPE_GSM
    834      * @see #PHONE_TYPE_CDMA
    835      * @see #PHONE_TYPE_SIP
    836      *
    837      * {@hide}
    838      */
    839     @SystemApi
    840     public int getCurrentPhoneType() {
    841         return getCurrentPhoneType(getDefaultSubscription());
    842     }
    843 
    844     /**
    845      * Returns a constant indicating the device phone type for a subscription.
    846      *
    847      * @see #PHONE_TYPE_NONE
    848      * @see #PHONE_TYPE_GSM
    849      * @see #PHONE_TYPE_CDMA
    850      *
    851      * @param subId for which phone type is returned
    852      */
    853     /** {@hide} */
    854     @SystemApi
    855     public int getCurrentPhoneType(int subId) {
    856         int phoneId = SubscriptionManager.getPhoneId(subId);
    857         try{
    858             ITelephony telephony = getITelephony();
    859             if (telephony != null) {
    860                 return telephony.getActivePhoneTypeForSubscriber(subId);
    861             } else {
    862                 // This can happen when the ITelephony interface is not up yet.
    863                 return getPhoneTypeFromProperty(phoneId);
    864             }
    865         } catch (RemoteException ex) {
    866             // This shouldn't happen in the normal case, as a backup we
    867             // read from the system property.
    868             return getPhoneTypeFromProperty(phoneId);
    869         } catch (NullPointerException ex) {
    870             // This shouldn't happen in the normal case, as a backup we
    871             // read from the system property.
    872             return getPhoneTypeFromProperty(phoneId);
    873         }
    874     }
    875 
    876     /**
    877      * Returns a constant indicating the device phone type.  This
    878      * indicates the type of radio used to transmit voice calls.
    879      *
    880      * @see #PHONE_TYPE_NONE
    881      * @see #PHONE_TYPE_GSM
    882      * @see #PHONE_TYPE_CDMA
    883      * @see #PHONE_TYPE_SIP
    884      */
    885     public int getPhoneType() {
    886         if (!isVoiceCapable()) {
    887             return PHONE_TYPE_NONE;
    888         }
    889         return getCurrentPhoneType();
    890     }
    891 
    892     private int getPhoneTypeFromProperty() {
    893         return getPhoneTypeFromProperty(getDefaultPhone());
    894     }
    895 
    896     /** {@hide} */
    897     private int getPhoneTypeFromProperty(int phoneId) {
    898         String type = getTelephonyProperty(phoneId,
    899                 TelephonyProperties.CURRENT_ACTIVE_PHONE, null);
    900         if (type == null || type.equals("")) {
    901             return getPhoneTypeFromNetworkType(phoneId);
    902         }
    903         return Integer.parseInt(type);
    904     }
    905 
    906     private int getPhoneTypeFromNetworkType() {
    907         return getPhoneTypeFromNetworkType(getDefaultPhone());
    908     }
    909 
    910     /** {@hide} */
    911     private int getPhoneTypeFromNetworkType(int phoneId) {
    912         // When the system property CURRENT_ACTIVE_PHONE, has not been set,
    913         // use the system property for default network type.
    914         // This is a fail safe, and can only happen at first boot.
    915         String mode = getTelephonyProperty(phoneId, "ro.telephony.default_network", null);
    916         if (mode != null) {
    917             return TelephonyManager.getPhoneType(Integer.parseInt(mode));
    918         }
    919         return TelephonyManager.PHONE_TYPE_NONE;
    920     }
    921 
    922     /**
    923      * This function returns the type of the phone, depending
    924      * on the network mode.
    925      *
    926      * @param networkMode
    927      * @return Phone Type
    928      *
    929      * @hide
    930      */
    931     public static int getPhoneType(int networkMode) {
    932         switch(networkMode) {
    933         case RILConstants.NETWORK_MODE_CDMA:
    934         case RILConstants.NETWORK_MODE_CDMA_NO_EVDO:
    935         case RILConstants.NETWORK_MODE_EVDO_NO_CDMA:
    936             return PhoneConstants.PHONE_TYPE_CDMA;
    937 
    938         case RILConstants.NETWORK_MODE_WCDMA_PREF:
    939         case RILConstants.NETWORK_MODE_GSM_ONLY:
    940         case RILConstants.NETWORK_MODE_WCDMA_ONLY:
    941         case RILConstants.NETWORK_MODE_GSM_UMTS:
    942         case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA:
    943         case RILConstants.NETWORK_MODE_LTE_WCDMA:
    944         case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
    945             return PhoneConstants.PHONE_TYPE_GSM;
    946 
    947         // Use CDMA Phone for the global mode including CDMA
    948         case RILConstants.NETWORK_MODE_GLOBAL:
    949         case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO:
    950             return PhoneConstants.PHONE_TYPE_CDMA;
    951 
    952         case RILConstants.NETWORK_MODE_LTE_ONLY:
    953             if (getLteOnCdmaModeStatic() == PhoneConstants.LTE_ON_CDMA_TRUE) {
    954                 return PhoneConstants.PHONE_TYPE_CDMA;
    955             } else {
    956                 return PhoneConstants.PHONE_TYPE_GSM;
    957             }
    958         default:
    959             return PhoneConstants.PHONE_TYPE_GSM;
    960         }
    961     }
    962 
    963     /**
    964      * The contents of the /proc/cmdline file
    965      */
    966     private static String getProcCmdLine()
    967     {
    968         String cmdline = "";
    969         FileInputStream is = null;
    970         try {
    971             is = new FileInputStream("/proc/cmdline");
    972             byte [] buffer = new byte[2048];
    973             int count = is.read(buffer);
    974             if (count > 0) {
    975                 cmdline = new String(buffer, 0, count);
    976             }
    977         } catch (IOException e) {
    978             Rlog.d(TAG, "No /proc/cmdline exception=" + e);
    979         } finally {
    980             if (is != null) {
    981                 try {
    982                     is.close();
    983                 } catch (IOException e) {
    984                 }
    985             }
    986         }
    987         Rlog.d(TAG, "/proc/cmdline=" + cmdline);
    988         return cmdline;
    989     }
    990 
    991     /** Kernel command line */
    992     private static final String sKernelCmdLine = getProcCmdLine();
    993 
    994     /** Pattern for selecting the product type from the kernel command line */
    995     private static final Pattern sProductTypePattern =
    996         Pattern.compile("\\sproduct_type\\s*=\\s*(\\w+)");
    997 
    998     /** The ProductType used for LTE on CDMA devices */
    999     private static final String sLteOnCdmaProductType =
   1000         SystemProperties.get(TelephonyProperties.PROPERTY_LTE_ON_CDMA_PRODUCT_TYPE, "");
   1001 
   1002     /**
   1003      * Return if the current radio is LTE on CDMA. This
   1004      * is a tri-state return value as for a period of time
   1005      * the mode may be unknown.
   1006      *
   1007      * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE}
   1008      * or {@link PhoneConstants#LTE_ON_CDMA_TRUE}
   1009      *
   1010      * @hide
   1011      */
   1012     public static int getLteOnCdmaModeStatic() {
   1013         int retVal;
   1014         int curVal;
   1015         String productType = "";
   1016 
   1017         curVal = SystemProperties.getInt(TelephonyProperties.PROPERTY_LTE_ON_CDMA_DEVICE,
   1018                     PhoneConstants.LTE_ON_CDMA_UNKNOWN);
   1019         retVal = curVal;
   1020         if (retVal == PhoneConstants.LTE_ON_CDMA_UNKNOWN) {
   1021             Matcher matcher = sProductTypePattern.matcher(sKernelCmdLine);
   1022             if (matcher.find()) {
   1023                 productType = matcher.group(1);
   1024                 if (sLteOnCdmaProductType.equals(productType)) {
   1025                     retVal = PhoneConstants.LTE_ON_CDMA_TRUE;
   1026                 } else {
   1027                     retVal = PhoneConstants.LTE_ON_CDMA_FALSE;
   1028                 }
   1029             } else {
   1030                 retVal = PhoneConstants.LTE_ON_CDMA_FALSE;
   1031             }
   1032         }
   1033 
   1034         Rlog.d(TAG, "getLteOnCdmaMode=" + retVal + " curVal=" + curVal +
   1035                 " product_type='" + productType +
   1036                 "' lteOnCdmaProductType='" + sLteOnCdmaProductType + "'");
   1037         return retVal;
   1038     }
   1039 
   1040     //
   1041     //
   1042     // Current Network
   1043     //
   1044     //
   1045 
   1046     /**
   1047      * Returns the alphabetic name of current registered operator.
   1048      * <p>
   1049      * Availability: Only when user is registered to a network. Result may be
   1050      * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
   1051      * on a CDMA network).
   1052      */
   1053     public String getNetworkOperatorName() {
   1054         return getNetworkOperatorName(getDefaultSubscription());
   1055     }
   1056 
   1057     /**
   1058      * Returns the alphabetic name of current registered operator
   1059      * for a particular subscription.
   1060      * <p>
   1061      * Availability: Only when user is registered to a network. Result may be
   1062      * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
   1063      * on a CDMA network).
   1064      * @param subId
   1065      */
   1066     /** {@hide} */
   1067     public String getNetworkOperatorName(int subId) {
   1068         int phoneId = SubscriptionManager.getPhoneId(subId);
   1069         return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, "");
   1070     }
   1071 
   1072     /**
   1073      * Returns the numeric name (MCC+MNC) of current registered operator.
   1074      * <p>
   1075      * Availability: Only when user is registered to a network. Result may be
   1076      * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
   1077      * on a CDMA network).
   1078      */
   1079     public String getNetworkOperator() {
   1080         return getNetworkOperatorForPhone(getDefaultPhone());
   1081     }
   1082 
   1083     /**
   1084      * Returns the numeric name (MCC+MNC) of current registered operator
   1085      * for a particular subscription.
   1086      * <p>
   1087      * Availability: Only when user is registered to a network. Result may be
   1088      * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
   1089      * on a CDMA network).
   1090      *
   1091      * @param subId
   1092      */
   1093     /** {@hide} */
   1094    public String getNetworkOperatorForSubscription(int subId) {
   1095         int phoneId = SubscriptionManager.getPhoneId(subId);
   1096         return getNetworkOperatorForPhone(phoneId);
   1097      }
   1098 
   1099     /**
   1100      * Returns the numeric name (MCC+MNC) of current registered operator
   1101      * for a particular subscription.
   1102      * <p>
   1103      * Availability: Only when user is registered to a network. Result may be
   1104      * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
   1105      * on a CDMA network).
   1106      *
   1107      * @param phoneId
   1108      * @hide
   1109      **/
   1110    public String getNetworkOperatorForPhone(int phoneId) {
   1111         return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, "");
   1112      }
   1113 
   1114     /**
   1115      * Returns true if the device is considered roaming on the current
   1116      * network, for GSM purposes.
   1117      * <p>
   1118      * Availability: Only when user registered to a network.
   1119      */
   1120     public boolean isNetworkRoaming() {
   1121         return isNetworkRoaming(getDefaultSubscription());
   1122     }
   1123 
   1124     /**
   1125      * Returns true if the device is considered roaming on the current
   1126      * network for a subscription.
   1127      * <p>
   1128      * Availability: Only when user registered to a network.
   1129      *
   1130      * @param subId
   1131      */
   1132     /** {@hide} */
   1133     public boolean isNetworkRoaming(int subId) {
   1134         int phoneId = SubscriptionManager.getPhoneId(subId);
   1135         return Boolean.parseBoolean(getTelephonyProperty(phoneId,
   1136                 TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, null));
   1137     }
   1138 
   1139     /**
   1140      * Returns the ISO country code equivalent of the current registered
   1141      * operator's MCC (Mobile Country Code).
   1142      * <p>
   1143      * Availability: Only when user is registered to a network. Result may be
   1144      * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
   1145      * on a CDMA network).
   1146      */
   1147     public String getNetworkCountryIso() {
   1148         return getNetworkCountryIsoForPhone(getDefaultPhone());
   1149     }
   1150 
   1151     /**
   1152      * Returns the ISO country code equivalent of the current registered
   1153      * operator's MCC (Mobile Country Code) of a subscription.
   1154      * <p>
   1155      * Availability: Only when user is registered to a network. Result may be
   1156      * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
   1157      * on a CDMA network).
   1158      *
   1159      * @param subId for which Network CountryIso is returned
   1160      */
   1161     /** {@hide} */
   1162     public String getNetworkCountryIsoForSubscription(int subId) {
   1163         int phoneId = SubscriptionManager.getPhoneId(subId);
   1164         return getNetworkCountryIsoForPhone(phoneId);
   1165     }
   1166 
   1167     /**
   1168      * Returns the ISO country code equivalent of the current registered
   1169      * operator's MCC (Mobile Country Code) of a subscription.
   1170      * <p>
   1171      * Availability: Only when user is registered to a network. Result may be
   1172      * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
   1173      * on a CDMA network).
   1174      *
   1175      * @param phoneId for which Network CountryIso is returned
   1176      */
   1177     /** {@hide} */
   1178     public String getNetworkCountryIsoForPhone(int phoneId) {
   1179         return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
   1180     }
   1181 
   1182     /** Network type is unknown */
   1183     public static final int NETWORK_TYPE_UNKNOWN = 0;
   1184     /** Current network is GPRS */
   1185     public static final int NETWORK_TYPE_GPRS = 1;
   1186     /** Current network is EDGE */
   1187     public static final int NETWORK_TYPE_EDGE = 2;
   1188     /** Current network is UMTS */
   1189     public static final int NETWORK_TYPE_UMTS = 3;
   1190     /** Current network is CDMA: Either IS95A or IS95B*/
   1191     public static final int NETWORK_TYPE_CDMA = 4;
   1192     /** Current network is EVDO revision 0*/
   1193     public static final int NETWORK_TYPE_EVDO_0 = 5;
   1194     /** Current network is EVDO revision A*/
   1195     public static final int NETWORK_TYPE_EVDO_A = 6;
   1196     /** Current network is 1xRTT*/
   1197     public static final int NETWORK_TYPE_1xRTT = 7;
   1198     /** Current network is HSDPA */
   1199     public static final int NETWORK_TYPE_HSDPA = 8;
   1200     /** Current network is HSUPA */
   1201     public static final int NETWORK_TYPE_HSUPA = 9;
   1202     /** Current network is HSPA */
   1203     public static final int NETWORK_TYPE_HSPA = 10;
   1204     /** Current network is iDen */
   1205     public static final int NETWORK_TYPE_IDEN = 11;
   1206     /** Current network is EVDO revision B*/
   1207     public static final int NETWORK_TYPE_EVDO_B = 12;
   1208     /** Current network is LTE */
   1209     public static final int NETWORK_TYPE_LTE = 13;
   1210     /** Current network is eHRPD */
   1211     public static final int NETWORK_TYPE_EHRPD = 14;
   1212     /** Current network is HSPA+ */
   1213     public static final int NETWORK_TYPE_HSPAP = 15;
   1214     /** Current network is GSM {@hide} */
   1215     public static final int NETWORK_TYPE_GSM = 16;
   1216 
   1217     /**
   1218      * @return the NETWORK_TYPE_xxxx for current data connection.
   1219      */
   1220     public int getNetworkType() {
   1221         return getDataNetworkType();
   1222     }
   1223 
   1224     /**
   1225      * Returns a constant indicating the radio technology (network type)
   1226      * currently in use on the device for a subscription.
   1227      * @return the network type
   1228      *
   1229      * @param subId for which network type is returned
   1230      *
   1231      * @see #NETWORK_TYPE_UNKNOWN
   1232      * @see #NETWORK_TYPE_GPRS
   1233      * @see #NETWORK_TYPE_EDGE
   1234      * @see #NETWORK_TYPE_UMTS
   1235      * @see #NETWORK_TYPE_HSDPA
   1236      * @see #NETWORK_TYPE_HSUPA
   1237      * @see #NETWORK_TYPE_HSPA
   1238      * @see #NETWORK_TYPE_CDMA
   1239      * @see #NETWORK_TYPE_EVDO_0
   1240      * @see #NETWORK_TYPE_EVDO_A
   1241      * @see #NETWORK_TYPE_EVDO_B
   1242      * @see #NETWORK_TYPE_1xRTT
   1243      * @see #NETWORK_TYPE_IDEN
   1244      * @see #NETWORK_TYPE_LTE
   1245      * @see #NETWORK_TYPE_EHRPD
   1246      * @see #NETWORK_TYPE_HSPAP
   1247      */
   1248     /** {@hide} */
   1249    public int getNetworkType(int subId) {
   1250        try {
   1251            ITelephony telephony = getITelephony();
   1252            if (telephony != null) {
   1253                return telephony.getNetworkTypeForSubscriber(subId);
   1254            } else {
   1255                // This can happen when the ITelephony interface is not up yet.
   1256                return NETWORK_TYPE_UNKNOWN;
   1257            }
   1258        } catch(RemoteException ex) {
   1259            // This shouldn't happen in the normal case
   1260            return NETWORK_TYPE_UNKNOWN;
   1261        } catch (NullPointerException ex) {
   1262            // This could happen before phone restarts due to crashing
   1263            return NETWORK_TYPE_UNKNOWN;
   1264        }
   1265    }
   1266 
   1267     /**
   1268      * Returns a constant indicating the radio technology (network type)
   1269      * currently in use on the device for data transmission.
   1270      * @return the network type
   1271      *
   1272      * @see #NETWORK_TYPE_UNKNOWN
   1273      * @see #NETWORK_TYPE_GPRS
   1274      * @see #NETWORK_TYPE_EDGE
   1275      * @see #NETWORK_TYPE_UMTS
   1276      * @see #NETWORK_TYPE_HSDPA
   1277      * @see #NETWORK_TYPE_HSUPA
   1278      * @see #NETWORK_TYPE_HSPA
   1279      * @see #NETWORK_TYPE_CDMA
   1280      * @see #NETWORK_TYPE_EVDO_0
   1281      * @see #NETWORK_TYPE_EVDO_A
   1282      * @see #NETWORK_TYPE_EVDO_B
   1283      * @see #NETWORK_TYPE_1xRTT
   1284      * @see #NETWORK_TYPE_IDEN
   1285      * @see #NETWORK_TYPE_LTE
   1286      * @see #NETWORK_TYPE_EHRPD
   1287      * @see #NETWORK_TYPE_HSPAP
   1288      *
   1289      * @hide
   1290      */
   1291     public int getDataNetworkType() {
   1292         return getDataNetworkType(getDefaultSubscription());
   1293     }
   1294 
   1295     /**
   1296      * Returns a constant indicating the radio technology (network type)
   1297      * currently in use on the device for data transmission for a subscription
   1298      * @return the network type
   1299      *
   1300      * @param subId for which network type is returned
   1301      */
   1302     /** {@hide} */
   1303     public int getDataNetworkType(int subId) {
   1304         try{
   1305             ITelephony telephony = getITelephony();
   1306             if (telephony != null) {
   1307                 return telephony.getDataNetworkTypeForSubscriber(subId);
   1308             } else {
   1309                 // This can happen when the ITelephony interface is not up yet.
   1310                 return NETWORK_TYPE_UNKNOWN;
   1311             }
   1312         } catch(RemoteException ex) {
   1313             // This shouldn't happen in the normal case
   1314             return NETWORK_TYPE_UNKNOWN;
   1315         } catch (NullPointerException ex) {
   1316             // This could happen before phone restarts due to crashing
   1317             return NETWORK_TYPE_UNKNOWN;
   1318         }
   1319     }
   1320 
   1321     /**
   1322      * Returns the NETWORK_TYPE_xxxx for voice
   1323      *
   1324      * @hide
   1325      */
   1326     public int getVoiceNetworkType() {
   1327         return getVoiceNetworkType(getDefaultSubscription());
   1328     }
   1329 
   1330     /**
   1331      * Returns the NETWORK_TYPE_xxxx for voice for a subId
   1332      *
   1333      */
   1334     /** {@hide} */
   1335     public int getVoiceNetworkType(int subId) {
   1336         try{
   1337             ITelephony telephony = getITelephony();
   1338             if (telephony != null) {
   1339                 return telephony.getVoiceNetworkTypeForSubscriber(subId);
   1340             } else {
   1341                 // This can happen when the ITelephony interface is not up yet.
   1342                 return NETWORK_TYPE_UNKNOWN;
   1343             }
   1344         } catch(RemoteException ex) {
   1345             // This shouldn't happen in the normal case
   1346             return NETWORK_TYPE_UNKNOWN;
   1347         } catch (NullPointerException ex) {
   1348             // This could happen before phone restarts due to crashing
   1349             return NETWORK_TYPE_UNKNOWN;
   1350         }
   1351     }
   1352 
   1353     /** Unknown network class. {@hide} */
   1354     public static final int NETWORK_CLASS_UNKNOWN = 0;
   1355     /** Class of broadly defined "2G" networks. {@hide} */
   1356     public static final int NETWORK_CLASS_2_G = 1;
   1357     /** Class of broadly defined "3G" networks. {@hide} */
   1358     public static final int NETWORK_CLASS_3_G = 2;
   1359     /** Class of broadly defined "4G" networks. {@hide} */
   1360     public static final int NETWORK_CLASS_4_G = 3;
   1361 
   1362     /**
   1363      * Return general class of network type, such as "3G" or "4G". In cases
   1364      * where classification is contentious, this method is conservative.
   1365      *
   1366      * @hide
   1367      */
   1368     public static int getNetworkClass(int networkType) {
   1369         switch (networkType) {
   1370             case NETWORK_TYPE_GPRS:
   1371             case NETWORK_TYPE_GSM:
   1372             case NETWORK_TYPE_EDGE:
   1373             case NETWORK_TYPE_CDMA:
   1374             case NETWORK_TYPE_1xRTT:
   1375             case NETWORK_TYPE_IDEN:
   1376                 return NETWORK_CLASS_2_G;
   1377             case NETWORK_TYPE_UMTS:
   1378             case NETWORK_TYPE_EVDO_0:
   1379             case NETWORK_TYPE_EVDO_A:
   1380             case NETWORK_TYPE_HSDPA:
   1381             case NETWORK_TYPE_HSUPA:
   1382             case NETWORK_TYPE_HSPA:
   1383             case NETWORK_TYPE_EVDO_B:
   1384             case NETWORK_TYPE_EHRPD:
   1385             case NETWORK_TYPE_HSPAP:
   1386                 return NETWORK_CLASS_3_G;
   1387             case NETWORK_TYPE_LTE:
   1388                 return NETWORK_CLASS_4_G;
   1389             default:
   1390                 return NETWORK_CLASS_UNKNOWN;
   1391         }
   1392     }
   1393 
   1394     /**
   1395      * Returns a string representation of the radio technology (network type)
   1396      * currently in use on the device.
   1397      * @return the name of the radio technology
   1398      *
   1399      * @hide pending API council review
   1400      */
   1401     public String getNetworkTypeName() {
   1402         return getNetworkTypeName(getNetworkType());
   1403     }
   1404 
   1405     /**
   1406      * Returns a string representation of the radio technology (network type)
   1407      * currently in use on the device.
   1408      * @param subId for which network type is returned
   1409      * @return the name of the radio technology
   1410      *
   1411      */
   1412     /** {@hide} */
   1413     public static String getNetworkTypeName(int type) {
   1414         switch (type) {
   1415             case NETWORK_TYPE_GPRS:
   1416                 return "GPRS";
   1417             case NETWORK_TYPE_EDGE:
   1418                 return "EDGE";
   1419             case NETWORK_TYPE_UMTS:
   1420                 return "UMTS";
   1421             case NETWORK_TYPE_HSDPA:
   1422                 return "HSDPA";
   1423             case NETWORK_TYPE_HSUPA:
   1424                 return "HSUPA";
   1425             case NETWORK_TYPE_HSPA:
   1426                 return "HSPA";
   1427             case NETWORK_TYPE_CDMA:
   1428                 return "CDMA";
   1429             case NETWORK_TYPE_EVDO_0:
   1430                 return "CDMA - EvDo rev. 0";
   1431             case NETWORK_TYPE_EVDO_A:
   1432                 return "CDMA - EvDo rev. A";
   1433             case NETWORK_TYPE_EVDO_B:
   1434                 return "CDMA - EvDo rev. B";
   1435             case NETWORK_TYPE_1xRTT:
   1436                 return "CDMA - 1xRTT";
   1437             case NETWORK_TYPE_LTE:
   1438                 return "LTE";
   1439             case NETWORK_TYPE_EHRPD:
   1440                 return "CDMA - eHRPD";
   1441             case NETWORK_TYPE_IDEN:
   1442                 return "iDEN";
   1443             case NETWORK_TYPE_HSPAP:
   1444                 return "HSPA+";
   1445             case NETWORK_TYPE_GSM:
   1446                 return "GSM";
   1447             default:
   1448                 return "UNKNOWN";
   1449         }
   1450     }
   1451 
   1452     //
   1453     //
   1454     // SIM Card
   1455     //
   1456     //
   1457 
   1458     /**
   1459      * SIM card state: Unknown. Signifies that the SIM is in transition
   1460      * between states. For example, when the user inputs the SIM pin
   1461      * under PIN_REQUIRED state, a query for sim status returns
   1462      * this state before turning to SIM_STATE_READY.
   1463      *
   1464      * These are the ordinal value of IccCardConstants.State.
   1465      */
   1466     public static final int SIM_STATE_UNKNOWN = 0;
   1467     /** SIM card state: no SIM card is available in the device */
   1468     public static final int SIM_STATE_ABSENT = 1;
   1469     /** SIM card state: Locked: requires the user's SIM PIN to unlock */
   1470     public static final int SIM_STATE_PIN_REQUIRED = 2;
   1471     /** SIM card state: Locked: requires the user's SIM PUK to unlock */
   1472     public static final int SIM_STATE_PUK_REQUIRED = 3;
   1473     /** SIM card state: Locked: requires a network PIN to unlock */
   1474     public static final int SIM_STATE_NETWORK_LOCKED = 4;
   1475     /** SIM card state: Ready */
   1476     public static final int SIM_STATE_READY = 5;
   1477     /** SIM card state: SIM Card is NOT READY
   1478      *@hide
   1479      */
   1480     public static final int SIM_STATE_NOT_READY = 6;
   1481     /** SIM card state: SIM Card Error, permanently disabled
   1482      *@hide
   1483      */
   1484     public static final int SIM_STATE_PERM_DISABLED = 7;
   1485     /** SIM card state: SIM Card Error, present but faulty
   1486      *@hide
   1487      */
   1488     public static final int SIM_STATE_CARD_IO_ERROR = 8;
   1489 
   1490     /**
   1491      * @return true if a ICC card is present
   1492      */
   1493     public boolean hasIccCard() {
   1494         return hasIccCard(getDefaultSim());
   1495     }
   1496 
   1497     /**
   1498      * @return true if a ICC card is present for a subscription
   1499      *
   1500      * @param slotId for which icc card presence is checked
   1501      */
   1502     /** {@hide} */
   1503     // FIXME Input argument slotId should be of type int
   1504     public boolean hasIccCard(int slotId) {
   1505 
   1506         try {
   1507             return getITelephony().hasIccCardUsingSlotId(slotId);
   1508         } catch (RemoteException ex) {
   1509             // Assume no ICC card if remote exception which shouldn't happen
   1510             return false;
   1511         } catch (NullPointerException ex) {
   1512             // This could happen before phone restarts due to crashing
   1513             return false;
   1514         }
   1515     }
   1516 
   1517     /**
   1518      * Returns a constant indicating the state of the default SIM card.
   1519      *
   1520      * @see #SIM_STATE_UNKNOWN
   1521      * @see #SIM_STATE_ABSENT
   1522      * @see #SIM_STATE_PIN_REQUIRED
   1523      * @see #SIM_STATE_PUK_REQUIRED
   1524      * @see #SIM_STATE_NETWORK_LOCKED
   1525      * @see #SIM_STATE_READY
   1526      * @see #SIM_STATE_NOT_READY
   1527      * @see #SIM_STATE_PERM_DISABLED
   1528      * @see #SIM_STATE_CARD_IO_ERROR
   1529      */
   1530     public int getSimState() {
   1531         return getSimState(getDefaultSim());
   1532     }
   1533 
   1534     /**
   1535      * Returns a constant indicating the state of the device SIM card in a slot.
   1536      *
   1537      * @param slotIdx
   1538      *
   1539      * @see #SIM_STATE_UNKNOWN
   1540      * @see #SIM_STATE_ABSENT
   1541      * @see #SIM_STATE_PIN_REQUIRED
   1542      * @see #SIM_STATE_PUK_REQUIRED
   1543      * @see #SIM_STATE_NETWORK_LOCKED
   1544      * @see #SIM_STATE_READY
   1545      * @see #SIM_STATE_NOT_READY
   1546      * @see #SIM_STATE_PERM_DISABLED
   1547      * @see #SIM_STATE_CARD_IO_ERROR
   1548      */
   1549     /** {@hide} */
   1550     public int getSimState(int slotIdx) {
   1551         int[] subId = SubscriptionManager.getSubId(slotIdx);
   1552         if (subId == null || subId.length == 0) {
   1553             Rlog.d(TAG, "getSimState:- empty subId return SIM_STATE_ABSENT");
   1554             return SIM_STATE_UNKNOWN;
   1555         }
   1556         int simState = SubscriptionManager.getSimStateForSubscriber(subId[0]);
   1557         Rlog.d(TAG, "getSimState: simState=" + simState + " slotIdx=" + slotIdx);
   1558         return simState;
   1559     }
   1560 
   1561     /**
   1562      * Returns the MCC+MNC (mobile country code + mobile network code) of the
   1563      * provider of the SIM. 5 or 6 decimal digits.
   1564      * <p>
   1565      * Availability: SIM state must be {@link #SIM_STATE_READY}
   1566      *
   1567      * @see #getSimState
   1568      */
   1569     public String getSimOperator() {
   1570         return getSimOperatorNumeric();
   1571     }
   1572 
   1573     /**
   1574      * Returns the MCC+MNC (mobile country code + mobile network code) of the
   1575      * provider of the SIM. 5 or 6 decimal digits.
   1576      * <p>
   1577      * Availability: SIM state must be {@link #SIM_STATE_READY}
   1578      *
   1579      * @see #getSimState
   1580      *
   1581      * @param subId for which SimOperator is returned
   1582      * @hide
   1583      */
   1584     public String getSimOperator(int subId) {
   1585         return getSimOperatorNumericForSubscription(subId);
   1586     }
   1587 
   1588     /**
   1589      * Returns the MCC+MNC (mobile country code + mobile network code) of the
   1590      * provider of the SIM. 5 or 6 decimal digits.
   1591      * <p>
   1592      * Availability: SIM state must be {@link #SIM_STATE_READY}
   1593      *
   1594      * @see #getSimState
   1595      * @hide
   1596      */
   1597     public String getSimOperatorNumeric() {
   1598         int subId = SubscriptionManager.getDefaultDataSubId();
   1599         if (!SubscriptionManager.isUsableSubIdValue(subId)) {
   1600             subId = SubscriptionManager.getDefaultSmsSubId();
   1601             if (!SubscriptionManager.isUsableSubIdValue(subId)) {
   1602                 subId = SubscriptionManager.getDefaultVoiceSubId();
   1603                 if (!SubscriptionManager.isUsableSubIdValue(subId)) {
   1604                     subId = SubscriptionManager.getDefaultSubId();
   1605                 }
   1606             }
   1607         }
   1608         Rlog.d(TAG, "getSimOperatorNumeric(): default subId=" + subId);
   1609         return getSimOperatorNumericForSubscription(subId);
   1610     }
   1611 
   1612     /**
   1613      * Returns the MCC+MNC (mobile country code + mobile network code) of the
   1614      * provider of the SIM for a particular subscription. 5 or 6 decimal digits.
   1615      * <p>
   1616      * Availability: SIM state must be {@link #SIM_STATE_READY}
   1617      *
   1618      * @see #getSimState
   1619      *
   1620      * @param subId for which SimOperator is returned
   1621      * @hide
   1622      */
   1623     public String getSimOperatorNumericForSubscription(int subId) {
   1624         int phoneId = SubscriptionManager.getPhoneId(subId);
   1625         return getSimOperatorNumericForPhone(phoneId);
   1626     }
   1627 
   1628    /**
   1629      * Returns the MCC+MNC (mobile country code + mobile network code) of the
   1630      * provider of the SIM for a particular subscription. 5 or 6 decimal digits.
   1631      * <p>
   1632      *
   1633      * @param phoneId for which SimOperator is returned
   1634      * @hide
   1635      */
   1636     public String getSimOperatorNumericForPhone(int phoneId) {
   1637         return getTelephonyProperty(phoneId,
   1638                 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, "");
   1639     }
   1640 
   1641     /**
   1642      * Returns the Service Provider Name (SPN).
   1643      * <p>
   1644      * Availability: SIM state must be {@link #SIM_STATE_READY}
   1645      *
   1646      * @see #getSimState
   1647      */
   1648     public String getSimOperatorName() {
   1649         return getSimOperatorNameForPhone(getDefaultPhone());
   1650     }
   1651 
   1652     /**
   1653      * Returns the Service Provider Name (SPN).
   1654      * <p>
   1655      * Availability: SIM state must be {@link #SIM_STATE_READY}
   1656      *
   1657      * @see #getSimState
   1658      *
   1659      * @param subId for which SimOperatorName is returned
   1660      * @hide
   1661      */
   1662     public String getSimOperatorNameForSubscription(int subId) {
   1663         int phoneId = SubscriptionManager.getPhoneId(subId);
   1664         return getSimOperatorNameForPhone(phoneId);
   1665     }
   1666 
   1667     /**
   1668      * Returns the Service Provider Name (SPN).
   1669      *
   1670      * @hide
   1671      */
   1672     public String getSimOperatorNameForPhone(int phoneId) {
   1673          return getTelephonyProperty(phoneId,
   1674                 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, "");
   1675     }
   1676 
   1677     /**
   1678      * Returns the ISO country code equivalent for the SIM provider's country code.
   1679      */
   1680     public String getSimCountryIso() {
   1681         return getSimCountryIsoForPhone(getDefaultPhone());
   1682     }
   1683 
   1684     /**
   1685      * Returns the ISO country code equivalent for the SIM provider's country code.
   1686      *
   1687      * @param subId for which SimCountryIso is returned
   1688      *
   1689      * @hide
   1690      */
   1691     public String getSimCountryIso(int subId) {
   1692         return getSimCountryIsoForSubscription(subId);
   1693     }
   1694 
   1695     /**
   1696      * Returns the ISO country code equivalent for the SIM provider's country code.
   1697      *
   1698      * @param subId for which SimCountryIso is returned
   1699      *
   1700      * @hide
   1701      */
   1702     public String getSimCountryIsoForSubscription(int subId) {
   1703         int phoneId = SubscriptionManager.getPhoneId(subId);
   1704         return getSimCountryIsoForPhone(phoneId);
   1705     }
   1706 
   1707     /**
   1708      * Returns the ISO country code equivalent for the SIM provider's country code.
   1709      *
   1710      * @hide
   1711      */
   1712     public String getSimCountryIsoForPhone(int phoneId) {
   1713         return getTelephonyProperty(phoneId,
   1714                 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, "");
   1715     }
   1716 
   1717     /**
   1718      * Returns the serial number of the SIM, if applicable. Return null if it is
   1719      * unavailable.
   1720      * <p>
   1721      * Requires Permission:
   1722      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   1723      */
   1724     public String getSimSerialNumber() {
   1725          return getSimSerialNumber(getDefaultSubscription());
   1726     }
   1727 
   1728     /**
   1729      * Returns the serial number for the given subscription, if applicable. Return null if it is
   1730      * unavailable.
   1731      * <p>
   1732      * @param subId for which Sim Serial number is returned
   1733      * Requires Permission:
   1734      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   1735      */
   1736     /** {@hide} */
   1737     public String getSimSerialNumber(int subId) {
   1738         try {
   1739             return getSubscriberInfo().getIccSerialNumberForSubscriber(subId);
   1740         } catch (RemoteException ex) {
   1741             return null;
   1742         } catch (NullPointerException ex) {
   1743             // This could happen before phone restarts due to crashing
   1744             return null;
   1745         }
   1746     }
   1747 
   1748     /**
   1749      * Return if the current radio is LTE on CDMA. This
   1750      * is a tri-state return value as for a period of time
   1751      * the mode may be unknown.
   1752      *
   1753      * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE}
   1754      * or {@link PhoneConstants#LTE_ON_CDMA_TRUE}
   1755      *
   1756      * @hide
   1757      */
   1758     public int getLteOnCdmaMode() {
   1759         return getLteOnCdmaMode(getDefaultSubscription());
   1760     }
   1761 
   1762     /**
   1763      * Return if the current radio is LTE on CDMA for Subscription. This
   1764      * is a tri-state return value as for a period of time
   1765      * the mode may be unknown.
   1766      *
   1767      * @param subId for which radio is LTE on CDMA is returned
   1768      * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE}
   1769      * or {@link PhoneConstants#LTE_ON_CDMA_TRUE}
   1770      *
   1771      */
   1772     /** {@hide} */
   1773     public int getLteOnCdmaMode(int subId) {
   1774         try {
   1775             return getITelephony().getLteOnCdmaModeForSubscriber(subId);
   1776         } catch (RemoteException ex) {
   1777             // Assume no ICC card if remote exception which shouldn't happen
   1778             return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
   1779         } catch (NullPointerException ex) {
   1780             // This could happen before phone restarts due to crashing
   1781             return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
   1782         }
   1783     }
   1784 
   1785     //
   1786     //
   1787     // Subscriber Info
   1788     //
   1789     //
   1790 
   1791     /**
   1792      * Returns the unique subscriber ID, for example, the IMSI for a GSM phone.
   1793      * Return null if it is unavailable.
   1794      * <p>
   1795      * Requires Permission:
   1796      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   1797      */
   1798     public String getSubscriberId() {
   1799         return getSubscriberId(getDefaultSubscription());
   1800     }
   1801 
   1802     /**
   1803      * Returns the unique subscriber ID, for example, the IMSI for a GSM phone
   1804      * for a subscription.
   1805      * Return null if it is unavailable.
   1806      * <p>
   1807      * Requires Permission:
   1808      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   1809      *
   1810      * @param subId whose subscriber id is returned
   1811      */
   1812     /** {@hide} */
   1813     public String getSubscriberId(int subId) {
   1814         try {
   1815             return getSubscriberInfo().getSubscriberIdForSubscriber(subId);
   1816         } catch (RemoteException ex) {
   1817             return null;
   1818         } catch (NullPointerException ex) {
   1819             // This could happen before phone restarts due to crashing
   1820             return null;
   1821         }
   1822     }
   1823 
   1824     /**
   1825      * Returns the Group Identifier Level1 for a GSM phone.
   1826      * Return null if it is unavailable.
   1827      * <p>
   1828      * Requires Permission:
   1829      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   1830      */
   1831     public String getGroupIdLevel1() {
   1832         try {
   1833             return getSubscriberInfo().getGroupIdLevel1();
   1834         } catch (RemoteException ex) {
   1835             return null;
   1836         } catch (NullPointerException ex) {
   1837             // This could happen before phone restarts due to crashing
   1838             return null;
   1839         }
   1840     }
   1841 
   1842     /**
   1843      * Returns the Group Identifier Level1 for a GSM phone for a particular subscription.
   1844      * Return null if it is unavailable.
   1845      * <p>
   1846      * Requires Permission:
   1847      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   1848      *
   1849      * @param subscription whose subscriber id is returned
   1850      */
   1851     /** {@hide} */
   1852     public String getGroupIdLevel1(int subId) {
   1853         try {
   1854             return getSubscriberInfo().getGroupIdLevel1ForSubscriber(subId);
   1855         } catch (RemoteException ex) {
   1856             return null;
   1857         } catch (NullPointerException ex) {
   1858             // This could happen before phone restarts due to crashing
   1859             return null;
   1860         }
   1861     }
   1862 
   1863     /**
   1864      * Returns the phone number string for line 1, for example, the MSISDN
   1865      * for a GSM phone. Return null if it is unavailable.
   1866      * <p>
   1867      * Requires Permission:
   1868      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   1869      */
   1870     public String getLine1Number() {
   1871         return getLine1NumberForSubscriber(getDefaultSubscription());
   1872     }
   1873 
   1874     /**
   1875      * Returns the phone number string for line 1, for example, the MSISDN
   1876      * for a GSM phone for a particular subscription. Return null if it is unavailable.
   1877      * <p>
   1878      * Requires Permission:
   1879      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   1880      *
   1881      * @param subId whose phone number for line 1 is returned
   1882      */
   1883     /** {@hide} */
   1884     public String getLine1NumberForSubscriber(int subId) {
   1885         String number = null;
   1886         try {
   1887             number = getITelephony().getLine1NumberForDisplay(subId);
   1888         } catch (RemoteException ex) {
   1889         } catch (NullPointerException ex) {
   1890         }
   1891         if (number != null) {
   1892             return number;
   1893         }
   1894         try {
   1895             return getSubscriberInfo().getLine1NumberForSubscriber(subId);
   1896         } catch (RemoteException ex) {
   1897             return null;
   1898         } catch (NullPointerException ex) {
   1899             // This could happen before phone restarts due to crashing
   1900             return null;
   1901         }
   1902     }
   1903 
   1904     /**
   1905      * Set the line 1 phone number string and its alphatag for the current ICCID
   1906      * for display purpose only, for example, displayed in Phone Status. It won't
   1907      * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null
   1908      * value.
   1909      *
   1910      * <p>Requires that the calling app has carrier privileges.
   1911      * @see #hasCarrierPrivileges
   1912      *
   1913      * @param alphaTag alpha-tagging of the dailing nubmer
   1914      * @param number The dialing number
   1915      * @return true if the operation was executed correctly.
   1916      */
   1917     public boolean setLine1NumberForDisplay(String alphaTag, String number) {
   1918         return setLine1NumberForDisplayForSubscriber(getDefaultSubscription(), alphaTag, number);
   1919     }
   1920 
   1921     /**
   1922      * Set the line 1 phone number string and its alphatag for the current ICCID
   1923      * for display purpose only, for example, displayed in Phone Status. It won't
   1924      * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null
   1925      * value.
   1926      *
   1927      * <p>Requires that the calling app has carrier privileges.
   1928      * @see #hasCarrierPrivileges
   1929      *
   1930      * @param subId the subscriber that the alphatag and dialing number belongs to.
   1931      * @param alphaTag alpha-tagging of the dailing nubmer
   1932      * @param number The dialing number
   1933      * @return true if the operation was executed correctly.
   1934      * @hide
   1935      */
   1936     public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, String number) {
   1937         try {
   1938             return getITelephony().setLine1NumberForDisplayForSubscriber(subId, alphaTag, number);
   1939         } catch (RemoteException ex) {
   1940         } catch (NullPointerException ex) {
   1941         }
   1942         return false;
   1943     }
   1944 
   1945     /**
   1946      * Returns the alphabetic identifier associated with the line 1 number.
   1947      * Return null if it is unavailable.
   1948      * <p>
   1949      * Requires Permission:
   1950      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   1951      * @hide
   1952      * nobody seems to call this.
   1953      */
   1954     public String getLine1AlphaTag() {
   1955         return getLine1AlphaTagForSubscriber(getDefaultSubscription());
   1956     }
   1957 
   1958     /**
   1959      * Returns the alphabetic identifier associated with the line 1 number
   1960      * for a subscription.
   1961      * Return null if it is unavailable.
   1962      * <p>
   1963      * Requires Permission:
   1964      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   1965      * @param subId whose alphabetic identifier associated with line 1 is returned
   1966      * nobody seems to call this.
   1967      */
   1968     /** {@hide} */
   1969     public String getLine1AlphaTagForSubscriber(int subId) {
   1970         String alphaTag = null;
   1971         try {
   1972             alphaTag = getITelephony().getLine1AlphaTagForDisplay(subId);
   1973         } catch (RemoteException ex) {
   1974         } catch (NullPointerException ex) {
   1975         }
   1976         if (alphaTag != null) {
   1977             return alphaTag;
   1978         }
   1979         try {
   1980             return getSubscriberInfo().getLine1AlphaTagForSubscriber(subId);
   1981         } catch (RemoteException ex) {
   1982             return null;
   1983         } catch (NullPointerException ex) {
   1984             // This could happen before phone restarts due to crashing
   1985             return null;
   1986         }
   1987     }
   1988 
   1989     /**
   1990      * Return the set of subscriber IDs that should be considered as "merged
   1991      * together" for data usage purposes. This is commonly {@code null} to
   1992      * indicate no merging is required. Any returned subscribers are sorted in a
   1993      * deterministic order.
   1994      *
   1995      * @hide
   1996      */
   1997     public @Nullable String[] getMergedSubscriberIds() {
   1998         try {
   1999             return getITelephony().getMergedSubscriberIds();
   2000         } catch (RemoteException ex) {
   2001         } catch (NullPointerException ex) {
   2002         }
   2003         return null;
   2004     }
   2005 
   2006     /**
   2007      * Returns the MSISDN string.
   2008      * for a GSM phone. Return null if it is unavailable.
   2009      * <p>
   2010      * Requires Permission:
   2011      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   2012      *
   2013      * @hide
   2014      */
   2015     public String getMsisdn() {
   2016         return getMsisdn(getDefaultSubscription());
   2017     }
   2018 
   2019     /**
   2020      * Returns the MSISDN string.
   2021      * for a GSM phone. Return null if it is unavailable.
   2022      * <p>
   2023      * Requires Permission:
   2024      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   2025      *
   2026      * @param subId for which msisdn is returned
   2027      */
   2028     /** {@hide} */
   2029     public String getMsisdn(int subId) {
   2030         try {
   2031             return getSubscriberInfo().getMsisdnForSubscriber(subId);
   2032         } catch (RemoteException ex) {
   2033             return null;
   2034         } catch (NullPointerException ex) {
   2035             // This could happen before phone restarts due to crashing
   2036             return null;
   2037         }
   2038     }
   2039 
   2040     /**
   2041      * Returns the voice mail number. Return null if it is unavailable.
   2042      * <p>
   2043      * Requires Permission:
   2044      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   2045      */
   2046     public String getVoiceMailNumber() {
   2047         return getVoiceMailNumber(getDefaultSubscription());
   2048     }
   2049 
   2050     /**
   2051      * Returns the voice mail number for a subscription.
   2052      * Return null if it is unavailable.
   2053      * <p>
   2054      * Requires Permission:
   2055      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   2056      * @param subId whose voice mail number is returned
   2057      */
   2058     /** {@hide} */
   2059     public String getVoiceMailNumber(int subId) {
   2060         try {
   2061             return getSubscriberInfo().getVoiceMailNumberForSubscriber(subId);
   2062         } catch (RemoteException ex) {
   2063             return null;
   2064         } catch (NullPointerException ex) {
   2065             // This could happen before phone restarts due to crashing
   2066             return null;
   2067         }
   2068     }
   2069 
   2070     /**
   2071      * Returns the complete voice mail number. Return null if it is unavailable.
   2072      * <p>
   2073      * Requires Permission:
   2074      *   {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED}
   2075      *
   2076      * @hide
   2077      */
   2078     public String getCompleteVoiceMailNumber() {
   2079         return getCompleteVoiceMailNumber(getDefaultSubscription());
   2080     }
   2081 
   2082     /**
   2083      * Returns the complete voice mail number. Return null if it is unavailable.
   2084      * <p>
   2085      * Requires Permission:
   2086      *   {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED}
   2087      *
   2088      * @param subId
   2089      */
   2090     /** {@hide} */
   2091     public String getCompleteVoiceMailNumber(int subId) {
   2092         try {
   2093             return getSubscriberInfo().getCompleteVoiceMailNumberForSubscriber(subId);
   2094         } catch (RemoteException ex) {
   2095             return null;
   2096         } catch (NullPointerException ex) {
   2097             // This could happen before phone restarts due to crashing
   2098             return null;
   2099         }
   2100     }
   2101 
   2102     /**
   2103      * Sets the voice mail number.
   2104      *
   2105      * <p>Requires that the calling app has carrier privileges.
   2106      * @see #hasCarrierPrivileges
   2107      *
   2108      * @param alphaTag The alpha tag to display.
   2109      * @param number The voicemail number.
   2110      */
   2111     public boolean setVoiceMailNumber(String alphaTag, String number) {
   2112         return setVoiceMailNumber(getDefaultSubscription(), alphaTag, number);
   2113     }
   2114 
   2115     /**
   2116      * Sets the voicemail number for the given subscriber.
   2117      *
   2118      * <p>Requires that the calling app has carrier privileges.
   2119      * @see #hasCarrierPrivileges
   2120      *
   2121      * @param subId The subscription id.
   2122      * @param alphaTag The alpha tag to display.
   2123      * @param number The voicemail number.
   2124      */
   2125     /** {@hide} */
   2126     public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
   2127         try {
   2128             return getITelephony().setVoiceMailNumber(subId, alphaTag, number);
   2129         } catch (RemoteException ex) {
   2130         } catch (NullPointerException ex) {
   2131         }
   2132         return false;
   2133     }
   2134 
   2135     /**
   2136      * Returns the voice mail count. Return 0 if unavailable.
   2137      * <p>
   2138      * Requires Permission:
   2139      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   2140      * @hide
   2141      */
   2142     public int getVoiceMessageCount() {
   2143         return getVoiceMessageCount(getDefaultSubscription());
   2144     }
   2145 
   2146     /**
   2147      * Returns the voice mail count for a subscription. Return 0 if unavailable.
   2148      * <p>
   2149      * Requires Permission:
   2150      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   2151      * @param subId whose voice message count is returned
   2152      */
   2153     /** {@hide} */
   2154     public int getVoiceMessageCount(int subId) {
   2155         try {
   2156             return getITelephony().getVoiceMessageCountForSubscriber(subId);
   2157         } catch (RemoteException ex) {
   2158             return 0;
   2159         } catch (NullPointerException ex) {
   2160             // This could happen before phone restarts due to crashing
   2161             return 0;
   2162         }
   2163     }
   2164 
   2165     /**
   2166      * Retrieves the alphabetic identifier associated with the voice
   2167      * mail number.
   2168      * <p>
   2169      * Requires Permission:
   2170      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   2171      */
   2172     public String getVoiceMailAlphaTag() {
   2173         return getVoiceMailAlphaTag(getDefaultSubscription());
   2174     }
   2175 
   2176     /**
   2177      * Retrieves the alphabetic identifier associated with the voice
   2178      * mail number for a subscription.
   2179      * <p>
   2180      * Requires Permission:
   2181      * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   2182      * @param subId whose alphabetic identifier associated with the
   2183      * voice mail number is returned
   2184      */
   2185     /** {@hide} */
   2186     public String getVoiceMailAlphaTag(int subId) {
   2187         try {
   2188             return getSubscriberInfo().getVoiceMailAlphaTagForSubscriber(subId);
   2189         } catch (RemoteException ex) {
   2190             return null;
   2191         } catch (NullPointerException ex) {
   2192             // This could happen before phone restarts due to crashing
   2193             return null;
   2194         }
   2195     }
   2196 
   2197     /**
   2198      * Returns the IMS private user identity (IMPI) that was loaded from the ISIM.
   2199      * @return the IMPI, or null if not present or not loaded
   2200      * @hide
   2201      */
   2202     public String getIsimImpi() {
   2203         try {
   2204             return getSubscriberInfo().getIsimImpi();
   2205         } catch (RemoteException ex) {
   2206             return null;
   2207         } catch (NullPointerException ex) {
   2208             // This could happen before phone restarts due to crashing
   2209             return null;
   2210         }
   2211     }
   2212 
   2213     /**
   2214      * Returns the IMS home network domain name that was loaded from the ISIM.
   2215      * @return the IMS domain name, or null if not present or not loaded
   2216      * @hide
   2217      */
   2218     public String getIsimDomain() {
   2219         try {
   2220             return getSubscriberInfo().getIsimDomain();
   2221         } catch (RemoteException ex) {
   2222             return null;
   2223         } catch (NullPointerException ex) {
   2224             // This could happen before phone restarts due to crashing
   2225             return null;
   2226         }
   2227     }
   2228 
   2229     /**
   2230      * Returns the IMS public user identities (IMPU) that were loaded from the ISIM.
   2231      * @return an array of IMPU strings, with one IMPU per string, or null if
   2232      *      not present or not loaded
   2233      * @hide
   2234      */
   2235     public String[] getIsimImpu() {
   2236         try {
   2237             return getSubscriberInfo().getIsimImpu();
   2238         } catch (RemoteException ex) {
   2239             return null;
   2240         } catch (NullPointerException ex) {
   2241             // This could happen before phone restarts due to crashing
   2242             return null;
   2243         }
   2244     }
   2245 
   2246    /**
   2247     * @hide
   2248     */
   2249     private IPhoneSubInfo getSubscriberInfo() {
   2250         // get it each time because that process crashes a lot
   2251         return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo"));
   2252     }
   2253 
   2254     /** Device call state: No activity. */
   2255     public static final int CALL_STATE_IDLE = 0;
   2256     /** Device call state: Ringing. A new call arrived and is
   2257      *  ringing or waiting. In the latter case, another call is
   2258      *  already active. */
   2259     public static final int CALL_STATE_RINGING = 1;
   2260     /** Device call state: Off-hook. At least one call exists
   2261       * that is dialing, active, or on hold, and no calls are ringing
   2262       * or waiting. */
   2263     public static final int CALL_STATE_OFFHOOK = 2;
   2264 
   2265     /**
   2266      * Returns a constant indicating the call state (cellular) on the device.
   2267      */
   2268     public int getCallState() {
   2269         try {
   2270             return getTelecomService().getCallState();
   2271         } catch (RemoteException | NullPointerException e) {
   2272             return CALL_STATE_IDLE;
   2273         }
   2274     }
   2275 
   2276     /**
   2277      * Returns a constant indicating the call state (cellular) on the device
   2278      * for a subscription.
   2279      *
   2280      * @param subId whose call state is returned
   2281      */
   2282     /** {@hide} */
   2283     public int getCallState(int subId) {
   2284         try {
   2285             return getITelephony().getCallStateForSubscriber(subId);
   2286         } catch (RemoteException ex) {
   2287             // the phone process is restarting.
   2288             return CALL_STATE_IDLE;
   2289         } catch (NullPointerException ex) {
   2290           // the phone process is restarting.
   2291           return CALL_STATE_IDLE;
   2292       }
   2293     }
   2294 
   2295     /** Data connection activity: No traffic. */
   2296     public static final int DATA_ACTIVITY_NONE = 0x00000000;
   2297     /** Data connection activity: Currently receiving IP PPP traffic. */
   2298     public static final int DATA_ACTIVITY_IN = 0x00000001;
   2299     /** Data connection activity: Currently sending IP PPP traffic. */
   2300     public static final int DATA_ACTIVITY_OUT = 0x00000002;
   2301     /** Data connection activity: Currently both sending and receiving
   2302      *  IP PPP traffic. */
   2303     public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT;
   2304     /**
   2305      * Data connection is active, but physical link is down
   2306      */
   2307     public static final int DATA_ACTIVITY_DORMANT = 0x00000004;
   2308 
   2309     /**
   2310      * Returns a constant indicating the type of activity on a data connection
   2311      * (cellular).
   2312      *
   2313      * @see #DATA_ACTIVITY_NONE
   2314      * @see #DATA_ACTIVITY_IN
   2315      * @see #DATA_ACTIVITY_OUT
   2316      * @see #DATA_ACTIVITY_INOUT
   2317      * @see #DATA_ACTIVITY_DORMANT
   2318      */
   2319     public int getDataActivity() {
   2320         try {
   2321             return getITelephony().getDataActivity();
   2322         } catch (RemoteException ex) {
   2323             // the phone process is restarting.
   2324             return DATA_ACTIVITY_NONE;
   2325         } catch (NullPointerException ex) {
   2326           // the phone process is restarting.
   2327           return DATA_ACTIVITY_NONE;
   2328       }
   2329     }
   2330 
   2331     /** Data connection state: Unknown.  Used before we know the state.
   2332      * @hide
   2333      */
   2334     public static final int DATA_UNKNOWN        = -1;
   2335     /** Data connection state: Disconnected. IP traffic not available. */
   2336     public static final int DATA_DISCONNECTED   = 0;
   2337     /** Data connection state: Currently setting up a data connection. */
   2338     public static final int DATA_CONNECTING     = 1;
   2339     /** Data connection state: Connected. IP traffic should be available. */
   2340     public static final int DATA_CONNECTED      = 2;
   2341     /** Data connection state: Suspended. The connection is up, but IP
   2342      * traffic is temporarily unavailable. For example, in a 2G network,
   2343      * data activity may be suspended when a voice call arrives. */
   2344     public static final int DATA_SUSPENDED      = 3;
   2345 
   2346     /**
   2347      * Returns a constant indicating the current data connection state
   2348      * (cellular).
   2349      *
   2350      * @see #DATA_DISCONNECTED
   2351      * @see #DATA_CONNECTING
   2352      * @see #DATA_CONNECTED
   2353      * @see #DATA_SUSPENDED
   2354      */
   2355     public int getDataState() {
   2356         try {
   2357             return getITelephony().getDataState();
   2358         } catch (RemoteException ex) {
   2359             // the phone process is restarting.
   2360             return DATA_DISCONNECTED;
   2361         } catch (NullPointerException ex) {
   2362             return DATA_DISCONNECTED;
   2363         }
   2364     }
   2365 
   2366    /**
   2367     * @hide
   2368     */
   2369     private ITelephony getITelephony() {
   2370         return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE));
   2371     }
   2372 
   2373     /**
   2374     * @hide
   2375     */
   2376     private ITelecomService getTelecomService() {
   2377         return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
   2378     }
   2379 
   2380     //
   2381     //
   2382     // PhoneStateListener
   2383     //
   2384     //
   2385 
   2386     /**
   2387      * Registers a listener object to receive notification of changes
   2388      * in specified telephony states.
   2389      * <p>
   2390      * To register a listener, pass a {@link PhoneStateListener}
   2391      * and specify at least one telephony state of interest in
   2392      * the events argument.
   2393      *
   2394      * At registration, and when a specified telephony state
   2395      * changes, the telephony manager invokes the appropriate
   2396      * callback method on the listener object and passes the
   2397      * current (updated) values.
   2398      * <p>
   2399      * To unregister a listener, pass the listener object and set the
   2400      * events argument to
   2401      * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0).
   2402      *
   2403      * @param listener The {@link PhoneStateListener} object to register
   2404      *                 (or unregister)
   2405      * @param events The telephony state(s) of interest to the listener,
   2406      *               as a bitwise-OR combination of {@link PhoneStateListener}
   2407      *               LISTEN_ flags.
   2408      */
   2409     public void listen(PhoneStateListener listener, int events) {
   2410         String pkgForDebug = mContext != null ? mContext.getPackageName() : "<unknown>";
   2411         try {
   2412             Boolean notifyNow = (getITelephony() != null);
   2413             sRegistry.listenForSubscriber(listener.mSubId, pkgForDebug, listener.callback, events, notifyNow);
   2414         } catch (RemoteException ex) {
   2415             // system process dead
   2416         } catch (NullPointerException ex) {
   2417             // system process dead
   2418         }
   2419     }
   2420 
   2421     /**
   2422      * Returns the CDMA ERI icon index to display
   2423      *
   2424      * @hide
   2425      */
   2426     public int getCdmaEriIconIndex() {
   2427         return getCdmaEriIconIndex(getDefaultSubscription());
   2428     }
   2429 
   2430     /**
   2431      * Returns the CDMA ERI icon index to display for a subscription
   2432      */
   2433     /** {@hide} */
   2434     public int getCdmaEriIconIndex(int subId) {
   2435         try {
   2436             return getITelephony().getCdmaEriIconIndexForSubscriber(subId);
   2437         } catch (RemoteException ex) {
   2438             // the phone process is restarting.
   2439             return -1;
   2440         } catch (NullPointerException ex) {
   2441             return -1;
   2442         }
   2443     }
   2444 
   2445     /**
   2446      * Returns the CDMA ERI icon mode,
   2447      * 0 - ON
   2448      * 1 - FLASHING
   2449      *
   2450      * @hide
   2451      */
   2452     public int getCdmaEriIconMode() {
   2453         return getCdmaEriIconMode(getDefaultSubscription());
   2454     }
   2455 
   2456     /**
   2457      * Returns the CDMA ERI icon mode for a subscription.
   2458      * 0 - ON
   2459      * 1 - FLASHING
   2460      */
   2461     /** {@hide} */
   2462     public int getCdmaEriIconMode(int subId) {
   2463         try {
   2464             return getITelephony().getCdmaEriIconModeForSubscriber(subId);
   2465         } catch (RemoteException ex) {
   2466             // the phone process is restarting.
   2467             return -1;
   2468         } catch (NullPointerException ex) {
   2469             return -1;
   2470         }
   2471     }
   2472 
   2473     /**
   2474      * Returns the CDMA ERI text,
   2475      *
   2476      * @hide
   2477      */
   2478     public String getCdmaEriText() {
   2479         return getCdmaEriText(getDefaultSubscription());
   2480     }
   2481 
   2482     /**
   2483      * Returns the CDMA ERI text, of a subscription
   2484      *
   2485      */
   2486     /** {@hide} */
   2487     public String getCdmaEriText(int subId) {
   2488         try {
   2489             return getITelephony().getCdmaEriTextForSubscriber(subId);
   2490         } catch (RemoteException ex) {
   2491             // the phone process is restarting.
   2492             return null;
   2493         } catch (NullPointerException ex) {
   2494             return null;
   2495         }
   2496     }
   2497 
   2498     /**
   2499      * @return true if the current device is "voice capable".
   2500      * <p>
   2501      * "Voice capable" means that this device supports circuit-switched
   2502      * (i.e. voice) phone calls over the telephony network, and is allowed
   2503      * to display the in-call UI while a cellular voice call is active.
   2504      * This will be false on "data only" devices which can't make voice
   2505      * calls and don't support any in-call UI.
   2506      * <p>
   2507      * Note: the meaning of this flag is subtly different from the
   2508      * PackageManager.FEATURE_TELEPHONY system feature, which is available
   2509      * on any device with a telephony radio, even if the device is
   2510      * data-only.
   2511      */
   2512     public boolean isVoiceCapable() {
   2513         if (mContext == null) return true;
   2514         return mContext.getResources().getBoolean(
   2515                 com.android.internal.R.bool.config_voice_capable);
   2516     }
   2517 
   2518     /**
   2519      * @return true if the current device supports sms service.
   2520      * <p>
   2521      * If true, this means that the device supports both sending and
   2522      * receiving sms via the telephony network.
   2523      * <p>
   2524      * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are
   2525      *       disabled when device doesn't support sms.
   2526      */
   2527     public boolean isSmsCapable() {
   2528         if (mContext == null) return true;
   2529         return mContext.getResources().getBoolean(
   2530                 com.android.internal.R.bool.config_sms_capable);
   2531     }
   2532 
   2533     /**
   2534      * Returns all observed cell information from all radios on the
   2535      * device including the primary and neighboring cells. This does
   2536      * not cause or change the rate of PhoneStateListner#onCellInfoChanged.
   2537      *<p>
   2538      * The list can include one or more of {@link android.telephony.CellInfoGsm CellInfoGsm},
   2539      * {@link android.telephony.CellInfoCdma CellInfoCdma},
   2540      * {@link android.telephony.CellInfoLte CellInfoLte} and
   2541      * {@link android.telephony.CellInfoWcdma CellInfoCdma} in any combination.
   2542      * Specifically on devices with multiple radios it is typical to see instances of
   2543      * one or more of any these in the list. In addition 0, 1 or more CellInfo
   2544      * objects may return isRegistered() true.
   2545      *<p>
   2546      * This is preferred over using getCellLocation although for older
   2547      * devices this may return null in which case getCellLocation should
   2548      * be called.
   2549      *<p>
   2550      * @return List of CellInfo or null if info unavailable.
   2551      *
   2552      * <p>Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}
   2553      */
   2554     public List<CellInfo> getAllCellInfo() {
   2555         try {
   2556             return getITelephony().getAllCellInfo();
   2557         } catch (RemoteException ex) {
   2558             return null;
   2559         } catch (NullPointerException ex) {
   2560             return null;
   2561         }
   2562     }
   2563 
   2564     /**
   2565      * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged
   2566      * PhoneStateListener.onCellInfoChanged} will be invoked.
   2567      *<p>
   2568      * The default, 0, means invoke onCellInfoChanged when any of the reported
   2569      * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue
   2570      * A onCellInfoChanged.
   2571      *<p>
   2572      * @param rateInMillis the rate
   2573      *
   2574      * @hide
   2575      */
   2576     public void setCellInfoListRate(int rateInMillis) {
   2577         try {
   2578             getITelephony().setCellInfoListRate(rateInMillis);
   2579         } catch (RemoteException ex) {
   2580         } catch (NullPointerException ex) {
   2581         }
   2582     }
   2583 
   2584     /**
   2585      * Returns the MMS user agent.
   2586      */
   2587     public String getMmsUserAgent() {
   2588         if (mContext == null) return null;
   2589         return mContext.getResources().getString(
   2590                 com.android.internal.R.string.config_mms_user_agent);
   2591     }
   2592 
   2593     /**
   2594      * Returns the MMS user agent profile URL.
   2595      */
   2596     public String getMmsUAProfUrl() {
   2597         if (mContext == null) return null;
   2598         return mContext.getResources().getString(
   2599                 com.android.internal.R.string.config_mms_user_agent_profile_url);
   2600     }
   2601 
   2602     /**
   2603      * Opens a logical channel to the ICC card.
   2604      *
   2605      * Input parameters equivalent to TS 27.007 AT+CCHO command.
   2606      *
   2607      * <p>Requires Permission:
   2608      *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
   2609      * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
   2610      *
   2611      * @param AID Application id. See ETSI 102.221 and 101.220.
   2612      * @return an IccOpenLogicalChannelResponse object.
   2613      */
   2614     public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) {
   2615         try {
   2616             return getITelephony().iccOpenLogicalChannel(AID);
   2617         } catch (RemoteException ex) {
   2618         } catch (NullPointerException ex) {
   2619         }
   2620         return null;
   2621     }
   2622 
   2623     /**
   2624      * Closes a previously opened logical channel to the ICC card.
   2625      *
   2626      * Input parameters equivalent to TS 27.007 AT+CCHC command.
   2627      *
   2628      * <p>Requires Permission:
   2629      *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
   2630      * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
   2631      *
   2632      * @param channel is the channel id to be closed as retruned by a successful
   2633      *            iccOpenLogicalChannel.
   2634      * @return true if the channel was closed successfully.
   2635      */
   2636     public boolean iccCloseLogicalChannel(int channel) {
   2637         try {
   2638             return getITelephony().iccCloseLogicalChannel(channel);
   2639         } catch (RemoteException ex) {
   2640         } catch (NullPointerException ex) {
   2641         }
   2642         return false;
   2643     }
   2644 
   2645     /**
   2646      * Transmit an APDU to the ICC card over a logical channel.
   2647      *
   2648      * Input parameters equivalent to TS 27.007 AT+CGLA command.
   2649      *
   2650      * <p>Requires Permission:
   2651      *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
   2652      * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
   2653      *
   2654      * @param channel is the channel id to be closed as returned by a successful
   2655      *            iccOpenLogicalChannel.
   2656      * @param cla Class of the APDU command.
   2657      * @param instruction Instruction of the APDU command.
   2658      * @param p1 P1 value of the APDU command.
   2659      * @param p2 P2 value of the APDU command.
   2660      * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU
   2661      *            is sent to the SIM.
   2662      * @param data Data to be sent with the APDU.
   2663      * @return The APDU response from the ICC card with the status appended at
   2664      *            the end.
   2665      */
   2666     public String iccTransmitApduLogicalChannel(int channel, int cla,
   2667             int instruction, int p1, int p2, int p3, String data) {
   2668         try {
   2669             return getITelephony().iccTransmitApduLogicalChannel(channel, cla,
   2670                     instruction, p1, p2, p3, data);
   2671         } catch (RemoteException ex) {
   2672         } catch (NullPointerException ex) {
   2673         }
   2674         return "";
   2675     }
   2676 
   2677     /**
   2678      * Transmit an APDU to the ICC card over the basic channel.
   2679      *
   2680      * Input parameters equivalent to TS 27.007 AT+CSIM command.
   2681      *
   2682      * <p>Requires Permission:
   2683      *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
   2684      * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
   2685      *
   2686      * @param cla Class of the APDU command.
   2687      * @param instruction Instruction of the APDU command.
   2688      * @param p1 P1 value of the APDU command.
   2689      * @param p2 P2 value of the APDU command.
   2690      * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU
   2691      *            is sent to the SIM.
   2692      * @param data Data to be sent with the APDU.
   2693      * @return The APDU response from the ICC card with the status appended at
   2694      *            the end.
   2695      */
   2696     public String iccTransmitApduBasicChannel(int cla,
   2697             int instruction, int p1, int p2, int p3, String data) {
   2698         try {
   2699             return getITelephony().iccTransmitApduBasicChannel(cla,
   2700                     instruction, p1, p2, p3, data);
   2701         } catch (RemoteException ex) {
   2702         } catch (NullPointerException ex) {
   2703         }
   2704         return "";
   2705     }
   2706 
   2707     /**
   2708      * Returns the response APDU for a command APDU sent through SIM_IO.
   2709      *
   2710      * <p>Requires Permission:
   2711      *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
   2712      * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
   2713      *
   2714      * @param fileID
   2715      * @param command
   2716      * @param p1 P1 value of the APDU command.
   2717      * @param p2 P2 value of the APDU command.
   2718      * @param p3 P3 value of the APDU command.
   2719      * @param filePath
   2720      * @return The APDU response.
   2721      */
   2722     public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3,
   2723             String filePath) {
   2724         try {
   2725             return getITelephony().iccExchangeSimIO(fileID, command, p1, p2,
   2726                 p3, filePath);
   2727         } catch (RemoteException ex) {
   2728         } catch (NullPointerException ex) {
   2729         }
   2730         return null;
   2731     }
   2732 
   2733     /**
   2734      * Send ENVELOPE to the SIM and return the response.
   2735      *
   2736      * <p>Requires Permission:
   2737      *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
   2738      * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
   2739      *
   2740      * @param content String containing SAT/USAT response in hexadecimal
   2741      *                format starting with command tag. See TS 102 223 for
   2742      *                details.
   2743      * @return The APDU response from the ICC card in hexadecimal format
   2744      *         with the last 4 bytes being the status word. If the command fails,
   2745      *         returns an empty string.
   2746      */
   2747     public String sendEnvelopeWithStatus(String content) {
   2748         try {
   2749             return getITelephony().sendEnvelopeWithStatus(content);
   2750         } catch (RemoteException ex) {
   2751         } catch (NullPointerException ex) {
   2752         }
   2753         return "";
   2754     }
   2755 
   2756     /**
   2757      * Read one of the NV items defined in com.android.internal.telephony.RadioNVItems.
   2758      * Used for device configuration by some CDMA operators.
   2759      * <p>
   2760      * Requires Permission:
   2761      *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
   2762      * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
   2763      *
   2764      * @param itemID the ID of the item to read.
   2765      * @return the NV item as a String, or null on any failure.
   2766      *
   2767      * @hide
   2768      */
   2769     public String nvReadItem(int itemID) {
   2770         try {
   2771             return getITelephony().nvReadItem(itemID);
   2772         } catch (RemoteException ex) {
   2773             Rlog.e(TAG, "nvReadItem RemoteException", ex);
   2774         } catch (NullPointerException ex) {
   2775             Rlog.e(TAG, "nvReadItem NPE", ex);
   2776         }
   2777         return "";
   2778     }
   2779 
   2780     /**
   2781      * Write one of the NV items defined in com.android.internal.telephony.RadioNVItems.
   2782      * Used for device configuration by some CDMA operators.
   2783      * <p>
   2784      * Requires Permission:
   2785      *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
   2786      * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
   2787      *
   2788      * @param itemID the ID of the item to read.
   2789      * @param itemValue the value to write, as a String.
   2790      * @return true on success; false on any failure.
   2791      *
   2792      * @hide
   2793      */
   2794     public boolean nvWriteItem(int itemID, String itemValue) {
   2795         try {
   2796             return getITelephony().nvWriteItem(itemID, itemValue);
   2797         } catch (RemoteException ex) {
   2798             Rlog.e(TAG, "nvWriteItem RemoteException", ex);
   2799         } catch (NullPointerException ex) {
   2800             Rlog.e(TAG, "nvWriteItem NPE", ex);
   2801         }
   2802         return false;
   2803     }
   2804 
   2805     /**
   2806      * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
   2807      * Used for device configuration by some CDMA operators.
   2808      * <p>
   2809      * Requires Permission:
   2810      *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
   2811      * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
   2812      *
   2813      * @param preferredRoamingList byte array containing the new PRL.
   2814      * @return true on success; false on any failure.
   2815      *
   2816      * @hide
   2817      */
   2818     public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
   2819         try {
   2820             return getITelephony().nvWriteCdmaPrl(preferredRoamingList);
   2821         } catch (RemoteException ex) {
   2822             Rlog.e(TAG, "nvWriteCdmaPrl RemoteException", ex);
   2823         } catch (NullPointerException ex) {
   2824             Rlog.e(TAG, "nvWriteCdmaPrl NPE", ex);
   2825         }
   2826         return false;
   2827     }
   2828 
   2829     /**
   2830      * Perform the specified type of NV config reset. The radio will be taken offline
   2831      * and the device must be rebooted after the operation. Used for device
   2832      * configuration by some CDMA operators.
   2833      * <p>
   2834      * Requires Permission:
   2835      *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
   2836      * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
   2837      *
   2838      * @param resetType reset type: 1: reload NV reset, 2: erase NV reset, 3: factory NV reset
   2839      * @return true on success; false on any failure.
   2840      *
   2841      * @hide
   2842      */
   2843     public boolean nvResetConfig(int resetType) {
   2844         try {
   2845             return getITelephony().nvResetConfig(resetType);
   2846         } catch (RemoteException ex) {
   2847             Rlog.e(TAG, "nvResetConfig RemoteException", ex);
   2848         } catch (NullPointerException ex) {
   2849             Rlog.e(TAG, "nvResetConfig NPE", ex);
   2850         }
   2851         return false;
   2852     }
   2853 
   2854     /**
   2855      * Returns Default subscription.
   2856      */
   2857     private static int getDefaultSubscription() {
   2858         return SubscriptionManager.getDefaultSubId();
   2859     }
   2860 
   2861     /**
   2862      * Returns Default phone.
   2863      */
   2864     private static int getDefaultPhone() {
   2865         return SubscriptionManager.getPhoneId(SubscriptionManager.getDefaultSubId());
   2866     }
   2867 
   2868     /** {@hide} */
   2869     public int getDefaultSim() {
   2870         return SubscriptionManager.getSlotId(SubscriptionManager.getDefaultSubId());
   2871     }
   2872 
   2873     /**
   2874      * Sets the telephony property with the value specified.
   2875      *
   2876      * @hide
   2877      */
   2878     public static void setTelephonyProperty(int phoneId, String property, String value) {
   2879         String propVal = "";
   2880         String p[] = null;
   2881         String prop = SystemProperties.get(property);
   2882 
   2883         if (value == null) {
   2884             value = "";
   2885         }
   2886 
   2887         if (prop != null) {
   2888             p = prop.split(",");
   2889         }
   2890 
   2891         if (!SubscriptionManager.isValidPhoneId(phoneId)) {
   2892             Rlog.d(TAG, "setTelephonyProperty: invalid phoneId=" + phoneId +
   2893                     " property=" + property + " value: " + value + " prop=" + prop);
   2894             return;
   2895         }
   2896 
   2897         for (int i = 0; i < phoneId; i++) {
   2898             String str = "";
   2899             if ((p != null) && (i < p.length)) {
   2900                 str = p[i];
   2901             }
   2902             propVal = propVal + str + ",";
   2903         }
   2904 
   2905         propVal = propVal + value;
   2906         if (p != null) {
   2907             for (int i = phoneId + 1; i < p.length; i++) {
   2908                 propVal = propVal + "," + p[i];
   2909             }
   2910         }
   2911 
   2912         if (property.length() > SystemProperties.PROP_NAME_MAX
   2913                 || propVal.length() > SystemProperties.PROP_VALUE_MAX) {
   2914             Rlog.d(TAG, "setTelephonyProperty: property to long phoneId=" + phoneId +
   2915                     " property=" + property + " value: " + value + " propVal=" + propVal);
   2916             return;
   2917         }
   2918 
   2919         Rlog.d(TAG, "setTelephonyProperty: success phoneId=" + phoneId +
   2920                 " property=" + property + " value: " + value + " propVal=" + propVal);
   2921         SystemProperties.set(property, propVal);
   2922     }
   2923 
   2924     /**
   2925      * Convenience function for retrieving a value from the secure settings
   2926      * value list as an integer.  Note that internally setting values are
   2927      * always stored as strings; this function converts the string to an
   2928      * integer for you.
   2929      * <p>
   2930      * This version does not take a default value.  If the setting has not
   2931      * been set, or the string value is not a number,
   2932      * it throws {@link SettingNotFoundException}.
   2933      *
   2934      * @param cr The ContentResolver to access.
   2935      * @param name The name of the setting to retrieve.
   2936      * @param index The index of the list
   2937      *
   2938      * @throws SettingNotFoundException Thrown if a setting by the given
   2939      * name can't be found or the setting value is not an integer.
   2940      *
   2941      * @return The value at the given index of settings.
   2942      * @hide
   2943      */
   2944     public static int getIntAtIndex(android.content.ContentResolver cr,
   2945             String name, int index)
   2946             throws android.provider.Settings.SettingNotFoundException {
   2947         String v = android.provider.Settings.Global.getString(cr, name);
   2948         if (v != null) {
   2949             String valArray[] = v.split(",");
   2950             if ((index >= 0) && (index < valArray.length) && (valArray[index] != null)) {
   2951                 try {
   2952                     return Integer.parseInt(valArray[index]);
   2953                 } catch (NumberFormatException e) {
   2954                     //Log.e(TAG, "Exception while parsing Integer: ", e);
   2955                 }
   2956             }
   2957         }
   2958         throw new android.provider.Settings.SettingNotFoundException(name);
   2959     }
   2960 
   2961     /**
   2962      * Convenience function for updating settings value as coma separated
   2963      * integer values. This will either create a new entry in the table if the
   2964      * given name does not exist, or modify the value of the existing row
   2965      * with that name.  Note that internally setting values are always
   2966      * stored as strings, so this function converts the given value to a
   2967      * string before storing it.
   2968      *
   2969      * @param cr The ContentResolver to access.
   2970      * @param name The name of the setting to modify.
   2971      * @param index The index of the list
   2972      * @param value The new value for the setting to be added to the list.
   2973      * @return true if the value was set, false on database errors
   2974      * @hide
   2975      */
   2976     public static boolean putIntAtIndex(android.content.ContentResolver cr,
   2977             String name, int index, int value) {
   2978         String data = "";
   2979         String valArray[] = null;
   2980         String v = android.provider.Settings.Global.getString(cr, name);
   2981 
   2982         if (index == Integer.MAX_VALUE) {
   2983             throw new RuntimeException("putIntAtIndex index == MAX_VALUE index=" + index);
   2984         }
   2985         if (index < 0) {
   2986             throw new RuntimeException("putIntAtIndex index < 0 index=" + index);
   2987         }
   2988         if (v != null) {
   2989             valArray = v.split(",");
   2990         }
   2991 
   2992         // Copy the elements from valArray till index
   2993         for (int i = 0; i < index; i++) {
   2994             String str = "";
   2995             if ((valArray != null) && (i < valArray.length)) {
   2996                 str = valArray[i];
   2997             }
   2998             data = data + str + ",";
   2999         }
   3000 
   3001         data = data + value;
   3002 
   3003         // Copy the remaining elements from valArray if any.
   3004         if (valArray != null) {
   3005             for (int i = index+1; i < valArray.length; i++) {
   3006                 data = data + "," + valArray[i];
   3007             }
   3008         }
   3009         return android.provider.Settings.Global.putString(cr, name, data);
   3010     }
   3011 
   3012     /**
   3013      * Gets the telephony property.
   3014      *
   3015      * @hide
   3016      */
   3017     public static String getTelephonyProperty(int phoneId, String property, String defaultVal) {
   3018         String propVal = null;
   3019         String prop = SystemProperties.get(property);
   3020         if ((prop != null) && (prop.length() > 0)) {
   3021             String values[] = prop.split(",");
   3022             if ((phoneId >= 0) && (phoneId < values.length) && (values[phoneId] != null)) {
   3023                 propVal = values[phoneId];
   3024             }
   3025         }
   3026         Rlog.d(TAG, "getTelephonyProperty: return propVal='" + propVal + "' phoneId=" + phoneId
   3027                 + " property='" + property + "' defaultVal='" + defaultVal + "' prop=" + prop);
   3028         return propVal == null ? defaultVal : propVal;
   3029     }
   3030 
   3031     /** @hide */
   3032     public int getSimCount() {
   3033         // FIXME Need to get it from Telephony Dev Controller when that gets implemented!
   3034         // and then this method shouldn't be used at all!
   3035         if(isMultiSimEnabled()) {
   3036             return 2;
   3037         } else {
   3038             return 1;
   3039         }
   3040     }
   3041 
   3042     /**
   3043      * Returns the IMS Service Table (IST) that was loaded from the ISIM.
   3044      * @return IMS Service Table or null if not present or not loaded
   3045      * @hide
   3046      */
   3047     public String getIsimIst() {
   3048         try {
   3049             return getSubscriberInfo().getIsimIst();
   3050         } catch (RemoteException ex) {
   3051             return null;
   3052         } catch (NullPointerException ex) {
   3053             // This could happen before phone restarts due to crashing
   3054             return null;
   3055         }
   3056     }
   3057 
   3058     /**
   3059      * Returns the IMS Proxy Call Session Control Function(PCSCF) that were loaded from the ISIM.
   3060      * @return an array of PCSCF strings with one PCSCF per string, or null if
   3061      *         not present or not loaded
   3062      * @hide
   3063      */
   3064     public String[] getIsimPcscf() {
   3065         try {
   3066             return getSubscriberInfo().getIsimPcscf();
   3067         } catch (RemoteException ex) {
   3068             return null;
   3069         } catch (NullPointerException ex) {
   3070             // This could happen before phone restarts due to crashing
   3071             return null;
   3072         }
   3073     }
   3074 
   3075     /**
   3076      * Returns the response of ISIM Authetification through RIL.
   3077      * Returns null if the Authentification hasn't been successed or isn't present iphonesubinfo.
   3078      * @return the response of ISIM Authetification, or null if not available
   3079      * @hide
   3080      * @deprecated
   3081      * @see getIccSimChallengeResponse with appType=PhoneConstants.APPTYPE_ISIM
   3082      */
   3083     public String getIsimChallengeResponse(String nonce){
   3084         try {
   3085             return getSubscriberInfo().getIsimChallengeResponse(nonce);
   3086         } catch (RemoteException ex) {
   3087             return null;
   3088         } catch (NullPointerException ex) {
   3089             // This could happen before phone restarts due to crashing
   3090             return null;
   3091         }
   3092     }
   3093 
   3094     /**
   3095      * Returns the response of SIM Authentication through RIL.
   3096      * Returns null if the Authentication hasn't been successful
   3097      * @param subId subscription ID to be queried
   3098      * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx)
   3099      * @param data authentication challenge data
   3100      * @return the response of SIM Authentication, or null if not available
   3101      * @hide
   3102      */
   3103     public String getIccSimChallengeResponse(int subId, int appType, String data) {
   3104         try {
   3105             return getSubscriberInfo().getIccSimChallengeResponse(subId, appType, data);
   3106         } catch (RemoteException ex) {
   3107             return null;
   3108         } catch (NullPointerException ex) {
   3109             // This could happen before phone starts
   3110             return null;
   3111         }
   3112     }
   3113 
   3114     /**
   3115      * Returns the response of SIM Authentication through RIL for the default subscription.
   3116      * Returns null if the Authentication hasn't been successful
   3117      * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx)
   3118      * @param data authentication challenge data
   3119      * @return the response of SIM Authentication, or null if not available
   3120      * @hide
   3121      */
   3122     public String getIccSimChallengeResponse(int appType, String data) {
   3123         return getIccSimChallengeResponse(getDefaultSubscription(), appType, data);
   3124     }
   3125 
   3126     /**
   3127      * Get P-CSCF address from PCO after data connection is established or modified.
   3128      * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN
   3129      * @return array of P-CSCF address
   3130      * @hide
   3131      */
   3132     public String[] getPcscfAddress(String apnType) {
   3133         try {
   3134             return getITelephony().getPcscfAddress(apnType);
   3135         } catch (RemoteException e) {
   3136             return new String[0];
   3137         }
   3138     }
   3139 
   3140     /**
   3141      * Set IMS registration state
   3142      *
   3143      * @param Registration state
   3144      * @hide
   3145      */
   3146     public void setImsRegistrationState(boolean registered) {
   3147         try {
   3148             getITelephony().setImsRegistrationState(registered);
   3149         } catch (RemoteException e) {
   3150         }
   3151     }
   3152 
   3153     /**
   3154      * Get the preferred network type.
   3155      * Used for device configuration by some CDMA operators.
   3156      * <p>
   3157      * Requires Permission:
   3158      *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
   3159      * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
   3160      *
   3161      * @return the preferred network type, defined in RILConstants.java.
   3162      * @hide
   3163      */
   3164     public int getPreferredNetworkType() {
   3165         try {
   3166             return getITelephony().getPreferredNetworkType();
   3167         } catch (RemoteException ex) {
   3168             Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex);
   3169         } catch (NullPointerException ex) {
   3170             Rlog.e(TAG, "getPreferredNetworkType NPE", ex);
   3171         }
   3172         return -1;
   3173     }
   3174 
   3175     /**
   3176      * Set the preferred network type.
   3177      * Used for device configuration by some CDMA operators.
   3178      * <p>
   3179      * Requires Permission:
   3180      *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
   3181      * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
   3182      *
   3183      * @param networkType the preferred network type, defined in RILConstants.java.
   3184      * @return true on success; false on any failure.
   3185      * @hide
   3186      */
   3187     public boolean setPreferredNetworkType(int networkType) {
   3188         try {
   3189             return getITelephony().setPreferredNetworkType(networkType);
   3190         } catch (RemoteException ex) {
   3191             Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex);
   3192         } catch (NullPointerException ex) {
   3193             Rlog.e(TAG, "setPreferredNetworkType NPE", ex);
   3194         }
   3195         return false;
   3196     }
   3197 
   3198     /**
   3199      * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA.
   3200      *
   3201      * <p>
   3202      * Requires that the calling app has carrier privileges.
   3203      * @see #hasCarrierPrivileges
   3204      *
   3205      * @return true on success; false on any failure.
   3206      */
   3207     public boolean setPreferredNetworkTypeToGlobal() {
   3208         return setPreferredNetworkType(RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA);
   3209     }
   3210 
   3211     /**
   3212      * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
   3213      * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
   3214      * tethering.
   3215      *
   3216      * @return 0: Not required. 1: required. 2: Not set.
   3217      * @hide
   3218      */
   3219     public int getTetherApnRequired() {
   3220         try {
   3221             return getITelephony().getTetherApnRequired();
   3222         } catch (RemoteException ex) {
   3223             Rlog.e(TAG, "hasMatchedTetherApnSetting RemoteException", ex);
   3224         } catch (NullPointerException ex) {
   3225             Rlog.e(TAG, "hasMatchedTetherApnSetting NPE", ex);
   3226         }
   3227         return 2;
   3228     }
   3229 
   3230 
   3231     /**
   3232      * Values used to return status for hasCarrierPrivileges call.
   3233      */
   3234     /** @hide */
   3235     public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1;
   3236     /** @hide */
   3237     public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0;
   3238     /** @hide */
   3239     public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1;
   3240     /** @hide */
   3241     public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2;
   3242 
   3243     /**
   3244      * Has the calling application been granted carrier privileges by the carrier.
   3245      *
   3246      * If any of the packages in the calling UID has carrier privileges, the
   3247      * call will return true. This access is granted by the owner of the UICC
   3248      * card and does not depend on the registered carrier.
   3249      *
   3250      * @return true if the app has carrier privileges.
   3251      */
   3252     public boolean hasCarrierPrivileges() {
   3253         try {
   3254             return getITelephony().getCarrierPrivilegeStatus() ==
   3255                 CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
   3256         } catch (RemoteException ex) {
   3257             Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex);
   3258         } catch (NullPointerException ex) {
   3259             Rlog.e(TAG, "hasCarrierPrivileges NPE", ex);
   3260         }
   3261         return false;
   3262     }
   3263 
   3264     /**
   3265      * Override the branding for the current ICCID.
   3266      *
   3267      * Once set, whenever the SIM is present in the device, the service
   3268      * provider name (SPN) and the operator name will both be replaced by the
   3269      * brand value input. To unset the value, the same function should be
   3270      * called with a null brand value.
   3271      *
   3272      * <p>Requires that the calling app has carrier privileges.
   3273      * @see #hasCarrierPrivileges
   3274      *
   3275      * @param brand The brand name to display/set.
   3276      * @return true if the operation was executed correctly.
   3277      */
   3278     public boolean setOperatorBrandOverride(String brand) {
   3279         try {
   3280             return getITelephony().setOperatorBrandOverride(brand);
   3281         } catch (RemoteException ex) {
   3282             Rlog.e(TAG, "setOperatorBrandOverride RemoteException", ex);
   3283         } catch (NullPointerException ex) {
   3284             Rlog.e(TAG, "setOperatorBrandOverride NPE", ex);
   3285         }
   3286         return false;
   3287     }
   3288 
   3289     /**
   3290      * Override the roaming preference for the current ICCID.
   3291      *
   3292      * Using this call, the carrier app (see #hasCarrierPrivileges) can override
   3293      * the platform's notion of a network operator being considered roaming or not.
   3294      * The change only affects the ICCID that was active when this call was made.
   3295      *
   3296      * If null is passed as any of the input, the corresponding value is deleted.
   3297      *
   3298      * <p>Requires that the caller have carrier privilege. See #hasCarrierPrivileges.
   3299      *
   3300      * @param gsmRoamingList - List of MCCMNCs to be considered roaming for 3GPP RATs.
   3301      * @param gsmNonRoamingList - List of MCCMNCs to be considered not roaming for 3GPP RATs.
   3302      * @param cdmaRoamingList - List of SIDs to be considered roaming for 3GPP2 RATs.
   3303      * @param cdmaNonRoamingList - List of SIDs to be considered not roaming for 3GPP2 RATs.
   3304      * @return true if the operation was executed correctly.
   3305      *
   3306      * @hide
   3307      */
   3308     public boolean setRoamingOverride(List<String> gsmRoamingList,
   3309             List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
   3310             List<String> cdmaNonRoamingList) {
   3311         try {
   3312             return getITelephony().setRoamingOverride(gsmRoamingList, gsmNonRoamingList,
   3313                     cdmaRoamingList, cdmaNonRoamingList);
   3314         } catch (RemoteException ex) {
   3315             Rlog.e(TAG, "setRoamingOverride RemoteException", ex);
   3316         } catch (NullPointerException ex) {
   3317             Rlog.e(TAG, "setRoamingOverride NPE", ex);
   3318         }
   3319         return false;
   3320     }
   3321 
   3322     /**
   3323      * Expose the rest of ITelephony to @SystemApi
   3324      */
   3325 
   3326     /** @hide */
   3327     @SystemApi
   3328     public String getCdmaMdn() {
   3329         return getCdmaMdn(getDefaultSubscription());
   3330     }
   3331 
   3332     /** @hide */
   3333     @SystemApi
   3334     public String getCdmaMdn(int subId) {
   3335         try {
   3336             return getITelephony().getCdmaMdn(subId);
   3337         } catch (RemoteException ex) {
   3338             return null;
   3339         } catch (NullPointerException ex) {
   3340             return null;
   3341         }
   3342     }
   3343 
   3344     /** @hide */
   3345     @SystemApi
   3346     public String getCdmaMin() {
   3347         return getCdmaMin(getDefaultSubscription());
   3348     }
   3349 
   3350     /** @hide */
   3351     @SystemApi
   3352     public String getCdmaMin(int subId) {
   3353         try {
   3354             return getITelephony().getCdmaMin(subId);
   3355         } catch (RemoteException ex) {
   3356             return null;
   3357         } catch (NullPointerException ex) {
   3358             return null;
   3359         }
   3360     }
   3361 
   3362     /** @hide */
   3363     @SystemApi
   3364     public int checkCarrierPrivilegesForPackage(String pkgname) {
   3365         try {
   3366             return getITelephony().checkCarrierPrivilegesForPackage(pkgname);
   3367         } catch (RemoteException ex) {
   3368             Rlog.e(TAG, "checkCarrierPrivilegesForPackage RemoteException", ex);
   3369         } catch (NullPointerException ex) {
   3370             Rlog.e(TAG, "checkCarrierPrivilegesForPackage NPE", ex);
   3371         }
   3372         return CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
   3373     }
   3374 
   3375     /** @hide */
   3376     @SystemApi
   3377     public List<String> getCarrierPackageNamesForIntent(Intent intent) {
   3378         try {
   3379             return getITelephony().getCarrierPackageNamesForIntent(intent);
   3380         } catch (RemoteException ex) {
   3381             Rlog.e(TAG, "getCarrierPackageNamesForIntent RemoteException", ex);
   3382         } catch (NullPointerException ex) {
   3383             Rlog.e(TAG, "getCarrierPackageNamesForIntent NPE", ex);
   3384         }
   3385         return null;
   3386     }
   3387 
   3388     /** @hide */
   3389     @SystemApi
   3390     public void dial(String number) {
   3391         try {
   3392             getITelephony().dial(number);
   3393         } catch (RemoteException e) {
   3394             Log.e(TAG, "Error calling ITelephony#dial", e);
   3395         }
   3396     }
   3397 
   3398     /** @hide */
   3399     @SystemApi
   3400     public void call(String callingPackage, String number) {
   3401         try {
   3402             getITelephony().call(callingPackage, number);
   3403         } catch (RemoteException e) {
   3404             Log.e(TAG, "Error calling ITelephony#call", e);
   3405         }
   3406     }
   3407 
   3408     /** @hide */
   3409     @SystemApi
   3410     public boolean endCall() {
   3411         try {
   3412             return getITelephony().endCall();
   3413         } catch (RemoteException e) {
   3414             Log.e(TAG, "Error calling ITelephony#endCall", e);
   3415         }
   3416         return false;
   3417     }
   3418 
   3419     /** @hide */
   3420     @SystemApi
   3421     public void answerRingingCall() {
   3422         try {
   3423             getITelephony().answerRingingCall();
   3424         } catch (RemoteException e) {
   3425             Log.e(TAG, "Error calling ITelephony#answerRingingCall", e);
   3426         }
   3427     }
   3428 
   3429     /** @hide */
   3430     @SystemApi
   3431     public void silenceRinger() {
   3432         try {
   3433             getTelecomService().silenceRinger();
   3434         } catch (RemoteException e) {
   3435             Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
   3436         }
   3437     }
   3438 
   3439     /** @hide */
   3440     @SystemApi
   3441     public boolean isOffhook() {
   3442         try {
   3443             return getITelephony().isOffhook();
   3444         } catch (RemoteException e) {
   3445             Log.e(TAG, "Error calling ITelephony#isOffhook", e);
   3446         }
   3447         return false;
   3448     }
   3449 
   3450     /** @hide */
   3451     @SystemApi
   3452     public boolean isRinging() {
   3453         try {
   3454             return getITelephony().isRinging();
   3455         } catch (RemoteException e) {
   3456             Log.e(TAG, "Error calling ITelephony#isRinging", e);
   3457         }
   3458         return false;
   3459     }
   3460 
   3461     /** @hide */
   3462     @SystemApi
   3463     public boolean isIdle() {
   3464         try {
   3465             return getITelephony().isIdle();
   3466         } catch (RemoteException e) {
   3467             Log.e(TAG, "Error calling ITelephony#isIdle", e);
   3468         }
   3469         return true;
   3470     }
   3471 
   3472     /** @hide */
   3473     @SystemApi
   3474     public boolean isRadioOn() {
   3475         try {
   3476             return getITelephony().isRadioOn();
   3477         } catch (RemoteException e) {
   3478             Log.e(TAG, "Error calling ITelephony#isRadioOn", e);
   3479         }
   3480         return false;
   3481     }
   3482 
   3483     /** @hide */
   3484     @SystemApi
   3485     public boolean isSimPinEnabled() {
   3486         try {
   3487             return getITelephony().isSimPinEnabled();
   3488         } catch (RemoteException e) {
   3489             Log.e(TAG, "Error calling ITelephony#isSimPinEnabled", e);
   3490         }
   3491         return false;
   3492     }
   3493 
   3494     /** @hide */
   3495     @SystemApi
   3496     public boolean supplyPin(String pin) {
   3497         try {
   3498             return getITelephony().supplyPin(pin);
   3499         } catch (RemoteException e) {
   3500             Log.e(TAG, "Error calling ITelephony#supplyPin", e);
   3501         }
   3502         return false;
   3503     }
   3504 
   3505     /** @hide */
   3506     @SystemApi
   3507     public boolean supplyPuk(String puk, String pin) {
   3508         try {
   3509             return getITelephony().supplyPuk(puk, pin);
   3510         } catch (RemoteException e) {
   3511             Log.e(TAG, "Error calling ITelephony#supplyPuk", e);
   3512         }
   3513         return false;
   3514     }
   3515 
   3516     /** @hide */
   3517     @SystemApi
   3518     public int[] supplyPinReportResult(String pin) {
   3519         try {
   3520             return getITelephony().supplyPinReportResult(pin);
   3521         } catch (RemoteException e) {
   3522             Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e);
   3523         }
   3524         return new int[0];
   3525     }
   3526 
   3527     /** @hide */
   3528     @SystemApi
   3529     public int[] supplyPukReportResult(String puk, String pin) {
   3530         try {
   3531             return getITelephony().supplyPukReportResult(puk, pin);
   3532         } catch (RemoteException e) {
   3533             Log.e(TAG, "Error calling ITelephony#]", e);
   3534         }
   3535         return new int[0];
   3536     }
   3537 
   3538     /** @hide */
   3539     @SystemApi
   3540     public boolean handlePinMmi(String dialString) {
   3541         try {
   3542             return getITelephony().handlePinMmi(dialString);
   3543         } catch (RemoteException e) {
   3544             Log.e(TAG, "Error calling ITelephony#handlePinMmi", e);
   3545         }
   3546         return false;
   3547     }
   3548 
   3549     /** @hide */
   3550     @SystemApi
   3551     public boolean handlePinMmiForSubscriber(int subId, String dialString) {
   3552         try {
   3553             return getITelephony().handlePinMmiForSubscriber(subId, dialString);
   3554         } catch (RemoteException e) {
   3555             Log.e(TAG, "Error calling ITelephony#handlePinMmi", e);
   3556         }
   3557         return false;
   3558     }
   3559 
   3560     /** @hide */
   3561     @SystemApi
   3562     public void toggleRadioOnOff() {
   3563         try {
   3564             getITelephony().toggleRadioOnOff();
   3565         } catch (RemoteException e) {
   3566             Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e);
   3567         }
   3568     }
   3569 
   3570     /** @hide */
   3571     @SystemApi
   3572     public boolean setRadio(boolean turnOn) {
   3573         try {
   3574             return getITelephony().setRadio(turnOn);
   3575         } catch (RemoteException e) {
   3576             Log.e(TAG, "Error calling ITelephony#setRadio", e);
   3577         }
   3578         return false;
   3579     }
   3580 
   3581     /** @hide */
   3582     @SystemApi
   3583     public boolean setRadioPower(boolean turnOn) {
   3584         try {
   3585             return getITelephony().setRadioPower(turnOn);
   3586         } catch (RemoteException e) {
   3587             Log.e(TAG, "Error calling ITelephony#setRadioPower", e);
   3588         }
   3589         return false;
   3590     }
   3591 
   3592     /** @hide */
   3593     @SystemApi
   3594     public void updateServiceLocation() {
   3595         try {
   3596             getITelephony().updateServiceLocation();
   3597         } catch (RemoteException e) {
   3598             Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e);
   3599         }
   3600     }
   3601 
   3602     /** @hide */
   3603     @SystemApi
   3604     public boolean enableDataConnectivity() {
   3605         try {
   3606             return getITelephony().enableDataConnectivity();
   3607         } catch (RemoteException e) {
   3608             Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e);
   3609         }
   3610         return false;
   3611     }
   3612 
   3613     /** @hide */
   3614     @SystemApi
   3615     public boolean disableDataConnectivity() {
   3616         try {
   3617             return getITelephony().disableDataConnectivity();
   3618         } catch (RemoteException e) {
   3619             Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e);
   3620         }
   3621         return false;
   3622     }
   3623 
   3624     /** @hide */
   3625     @SystemApi
   3626     public boolean isDataConnectivityPossible() {
   3627         try {
   3628             return getITelephony().isDataConnectivityPossible();
   3629         } catch (RemoteException e) {
   3630             Log.e(TAG, "Error calling ITelephony#isDataConnectivityPossible", e);
   3631         }
   3632         return false;
   3633     }
   3634 
   3635     /** @hide */
   3636     @SystemApi
   3637     public boolean needsOtaServiceProvisioning() {
   3638         try {
   3639             return getITelephony().needsOtaServiceProvisioning();
   3640         } catch (RemoteException e) {
   3641             Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e);
   3642         }
   3643         return false;
   3644     }
   3645 
   3646     /** @hide */
   3647     @SystemApi
   3648     public void setDataEnabled(boolean enable) {
   3649         setDataEnabled(SubscriptionManager.getDefaultDataSubId(), enable);
   3650     }
   3651 
   3652     /** @hide */
   3653     @SystemApi
   3654     public void setDataEnabled(int subId, boolean enable) {
   3655         try {
   3656             Log.d(TAG, "setDataEnabled: enabled=" + enable);
   3657             getITelephony().setDataEnabled(subId, enable);
   3658         } catch (RemoteException e) {
   3659             Log.e(TAG, "Error calling ITelephony#setDataEnabled", e);
   3660         }
   3661     }
   3662 
   3663     /** @hide */
   3664     @SystemApi
   3665     public boolean getDataEnabled() {
   3666         return getDataEnabled(SubscriptionManager.getDefaultDataSubId());
   3667     }
   3668 
   3669     /** @hide */
   3670     @SystemApi
   3671     public boolean getDataEnabled(int subId) {
   3672         boolean retVal = false;
   3673         try {
   3674             retVal = getITelephony().getDataEnabled(subId);
   3675         } catch (RemoteException e) {
   3676             Log.e(TAG, "Error calling ITelephony#getDataEnabled", e);
   3677         } catch (NullPointerException e) {
   3678         }
   3679         Log.d(TAG, "getDataEnabled: retVal=" + retVal);
   3680         return retVal;
   3681     }
   3682 
   3683     /**
   3684      * Returns the result and response from RIL for oem request
   3685      *
   3686      * @param oemReq the data is sent to ril.
   3687      * @param oemResp the respose data from RIL.
   3688      * @return negative value request was not handled or get error
   3689      *         0 request was handled succesfully, but no response data
   3690      *         positive value success, data length of response
   3691      * @hide
   3692      */
   3693     public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
   3694         try {
   3695             return getITelephony().invokeOemRilRequestRaw(oemReq, oemResp);
   3696         } catch (RemoteException ex) {
   3697         } catch (NullPointerException ex) {
   3698         }
   3699         return -1;
   3700     }
   3701 
   3702     /** @hide */
   3703     @SystemApi
   3704     public void enableVideoCalling(boolean enable) {
   3705         try {
   3706             getITelephony().enableVideoCalling(enable);
   3707         } catch (RemoteException e) {
   3708             Log.e(TAG, "Error calling ITelephony#enableVideoCalling", e);
   3709         }
   3710     }
   3711 
   3712     /** @hide */
   3713     @SystemApi
   3714     public boolean isVideoCallingEnabled() {
   3715         try {
   3716             return getITelephony().isVideoCallingEnabled();
   3717         } catch (RemoteException e) {
   3718             Log.e(TAG, "Error calling ITelephony#isVideoCallingEnabled", e);
   3719         }
   3720         return false;
   3721     }
   3722 
   3723     /**
   3724      * This function retrieves value for setting "name+subId", and if that is not found
   3725      * retrieves value for setting "name", and if that is not found uses def as default
   3726      *
   3727      * @hide */
   3728     public static int getIntWithSubId(ContentResolver cr, String name, int subId, int def) {
   3729         return Settings.Global.getInt(cr, name + subId, Settings.Global.getInt(cr, name, def));
   3730     }
   3731 
   3732     /**
   3733      * This function retrieves value for setting "name+subId", and if that is not found
   3734      * retrieves value for setting "name", and if that is not found throws
   3735      * SettingNotFoundException
   3736      *
   3737      * @hide */
   3738     public static int getIntWithSubId(ContentResolver cr, String name, int subId)
   3739             throws SettingNotFoundException {
   3740         try {
   3741             return Settings.Global.getInt(cr, name + subId);
   3742         } catch (SettingNotFoundException e) {
   3743             try {
   3744                 int val = Settings.Global.getInt(cr, name);
   3745                 Settings.Global.putInt(cr, name + subId, val);
   3746 
   3747                 /* We are now moving from 'setting' to 'setting+subId', and using the value stored
   3748                  * for 'setting' as default. Reset the default (since it may have a user set
   3749                  * value). */
   3750                 int default_val = val;
   3751                 if (name.equals(Settings.Global.MOBILE_DATA)) {
   3752                     default_val = "true".equalsIgnoreCase(
   3753                             SystemProperties.get("ro.com.android.mobiledata", "true")) ? 1 : 0;
   3754                 } else if (name.equals(Settings.Global.DATA_ROAMING)) {
   3755                     default_val = "true".equalsIgnoreCase(
   3756                             SystemProperties.get("ro.com.android.dataroaming", "false")) ? 1 : 0;
   3757                 }
   3758 
   3759                 if (default_val != val) {
   3760                     Settings.Global.putInt(cr, name, default_val);
   3761                 }
   3762 
   3763                 return val;
   3764             } catch (SettingNotFoundException exc) {
   3765                 throw new SettingNotFoundException(name);
   3766             }
   3767         }
   3768     }
   3769 
   3770    /**
   3771     * Returns the IMS Registration Status
   3772     *@hide
   3773     */
   3774    public boolean isImsRegistered() {
   3775        try {
   3776            return getITelephony().isImsRegistered();
   3777        } catch (RemoteException ex) {
   3778            return false;
   3779        } catch (NullPointerException ex) {
   3780            return false;
   3781        }
   3782    }
   3783 
   3784    /**
   3785     * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone.
   3786     *
   3787     * @hide
   3788     */
   3789     public void setSimOperatorNumeric(String numeric) {
   3790         int phoneId = getDefaultPhone();
   3791         setSimOperatorNumericForPhone(phoneId, numeric);
   3792     }
   3793 
   3794    /**
   3795     * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone.
   3796     *
   3797     * @hide
   3798     */
   3799     public void setSimOperatorNumericForPhone(int phoneId, String numeric) {
   3800         setTelephonyProperty(phoneId,
   3801                 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, numeric);
   3802     }
   3803 
   3804     /**
   3805      * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone.
   3806      *
   3807      * @hide
   3808      */
   3809     public void setSimOperatorName(String name) {
   3810         int phoneId = getDefaultPhone();
   3811         setSimOperatorNameForPhone(phoneId, name);
   3812     }
   3813 
   3814     /**
   3815      * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone.
   3816      *
   3817      * @hide
   3818      */
   3819     public void setSimOperatorNameForPhone(int phoneId, String name) {
   3820         setTelephonyProperty(phoneId,
   3821                 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, name);
   3822     }
   3823 
   3824    /**
   3825     * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the default phone.
   3826     *
   3827     * @hide
   3828     */
   3829     public void setSimCountryIso(String iso) {
   3830         int phoneId = getDefaultPhone();
   3831         setSimCountryIsoForPhone(phoneId, iso);
   3832     }
   3833 
   3834    /**
   3835     * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the given phone.
   3836     *
   3837     * @hide
   3838     */
   3839     public void setSimCountryIsoForPhone(int phoneId, String iso) {
   3840         setTelephonyProperty(phoneId,
   3841                 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, iso);
   3842     }
   3843 
   3844     /**
   3845      * Set TelephonyProperties.PROPERTY_SIM_STATE for the default phone.
   3846      *
   3847      * @hide
   3848      */
   3849     public void setSimState(String state) {
   3850         int phoneId = getDefaultPhone();
   3851         setSimStateForPhone(phoneId, state);
   3852     }
   3853 
   3854     /**
   3855      * Set TelephonyProperties.PROPERTY_SIM_STATE for the given phone.
   3856      *
   3857      * @hide
   3858      */
   3859     public void setSimStateForPhone(int phoneId, String state) {
   3860         setTelephonyProperty(phoneId,
   3861                 TelephonyProperties.PROPERTY_SIM_STATE, state);
   3862     }
   3863 
   3864     /**
   3865      * Set baseband version for the default phone.
   3866      *
   3867      * @param version baseband version
   3868      * @hide
   3869      */
   3870     public void setBasebandVersion(String version) {
   3871         int phoneId = getDefaultPhone();
   3872         setBasebandVersionForPhone(phoneId, version);
   3873     }
   3874 
   3875     /**
   3876      * Set baseband version by phone id.
   3877      *
   3878      * @param phoneId for which baseband version is set
   3879      * @param version baseband version
   3880      * @hide
   3881      */
   3882     public void setBasebandVersionForPhone(int phoneId, String version) {
   3883         if (SubscriptionManager.isValidPhoneId(phoneId)) {
   3884             String prop = TelephonyProperties.PROPERTY_BASEBAND_VERSION +
   3885                     ((phoneId == 0) ? "" : Integer.toString(phoneId));
   3886             SystemProperties.set(prop, version);
   3887         }
   3888     }
   3889 
   3890     /**
   3891      * Set phone type for the default phone.
   3892      *
   3893      * @param type phone type
   3894      *
   3895      * @hide
   3896      */
   3897     public void setPhoneType(int type) {
   3898         int phoneId = getDefaultPhone();
   3899         setPhoneType(phoneId, type);
   3900     }
   3901 
   3902     /**
   3903      * Set phone type by phone id.
   3904      *
   3905      * @param phoneId for which phone type is set
   3906      * @param type phone type
   3907      *
   3908      * @hide
   3909      */
   3910     public void setPhoneType(int phoneId, int type) {
   3911         if (SubscriptionManager.isValidPhoneId(phoneId)) {
   3912             TelephonyManager.setTelephonyProperty(phoneId,
   3913                     TelephonyProperties.CURRENT_ACTIVE_PHONE, String.valueOf(type));
   3914         }
   3915     }
   3916 
   3917     /**
   3918      * Get OTASP number schema for the default phone.
   3919      *
   3920      * @param defaultValue default value
   3921      * @return OTA SP number schema
   3922      *
   3923      * @hide
   3924      */
   3925     public String getOtaSpNumberSchema(String defaultValue) {
   3926         int phoneId = getDefaultPhone();
   3927         return getOtaSpNumberSchemaForPhone(phoneId, defaultValue);
   3928     }
   3929 
   3930     /**
   3931      * Get OTASP number schema by phone id.
   3932      *
   3933      * @param phoneId for which OTA SP number schema is get
   3934      * @param defaultValue default value
   3935      * @return OTA SP number schema
   3936      *
   3937      * @hide
   3938      */
   3939     public String getOtaSpNumberSchemaForPhone(int phoneId, String defaultValue) {
   3940         if (SubscriptionManager.isValidPhoneId(phoneId)) {
   3941             return TelephonyManager.getTelephonyProperty(phoneId,
   3942                     TelephonyProperties.PROPERTY_OTASP_NUM_SCHEMA, defaultValue);
   3943         }
   3944 
   3945         return defaultValue;
   3946     }
   3947 
   3948     /**
   3949      * Get SMS receive capable from system property for the default phone.
   3950      *
   3951      * @param defaultValue default value
   3952      * @return SMS receive capable
   3953      *
   3954      * @hide
   3955      */
   3956     public boolean getSmsReceiveCapable(boolean defaultValue) {
   3957         int phoneId = getDefaultPhone();
   3958         return getSmsReceiveCapableForPhone(phoneId, defaultValue);
   3959     }
   3960 
   3961     /**
   3962      * Get SMS receive capable from system property by phone id.
   3963      *
   3964      * @param phoneId for which SMS receive capable is get
   3965      * @param defaultValue default value
   3966      * @return SMS receive capable
   3967      *
   3968      * @hide
   3969      */
   3970     public boolean getSmsReceiveCapableForPhone(int phoneId, boolean defaultValue) {
   3971         if (SubscriptionManager.isValidPhoneId(phoneId)) {
   3972             return Boolean.valueOf(TelephonyManager.getTelephonyProperty(phoneId,
   3973                     TelephonyProperties.PROPERTY_SMS_RECEIVE, String.valueOf(defaultValue)));
   3974         }
   3975 
   3976         return defaultValue;
   3977     }
   3978 
   3979     /**
   3980      * Get SMS send capable from system property for the default phone.
   3981      *
   3982      * @param defaultValue default value
   3983      * @return SMS send capable
   3984      *
   3985      * @hide
   3986      */
   3987     public boolean getSmsSendCapable(boolean defaultValue) {
   3988         int phoneId = getDefaultPhone();
   3989         return getSmsSendCapableForPhone(phoneId, defaultValue);
   3990     }
   3991 
   3992     /**
   3993      * Get SMS send capable from system property by phone id.
   3994      *
   3995      * @param phoneId for which SMS send capable is get
   3996      * @param defaultValue default value
   3997      * @return SMS send capable
   3998      *
   3999      * @hide
   4000      */
   4001     public boolean getSmsSendCapableForPhone(int phoneId, boolean defaultValue) {
   4002         if (SubscriptionManager.isValidPhoneId(phoneId)) {
   4003             return Boolean.valueOf(TelephonyManager.getTelephonyProperty(phoneId,
   4004                     TelephonyProperties.PROPERTY_SMS_SEND, String.valueOf(defaultValue)));
   4005         }
   4006 
   4007         return defaultValue;
   4008     }
   4009 
   4010     /**
   4011      * Set the alphabetic name of current registered operator.
   4012      * @param name the alphabetic name of current registered operator.
   4013      * @hide
   4014      */
   4015     public void setNetworkOperatorName(String name) {
   4016         int phoneId = getDefaultPhone();
   4017         setNetworkOperatorNameForPhone(phoneId, name);
   4018     }
   4019 
   4020     /**
   4021      * Set the alphabetic name of current registered operator.
   4022      * @param phoneId which phone you want to set
   4023      * @param name the alphabetic name of current registered operator.
   4024      * @hide
   4025      */
   4026     public void setNetworkOperatorNameForPhone(int phoneId, String name) {
   4027         if (SubscriptionManager.isValidPhoneId(phoneId)) {
   4028             setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, name);
   4029         }
   4030     }
   4031 
   4032     /**
   4033      * Set the numeric name (MCC+MNC) of current registered operator.
   4034      * @param operator the numeric name (MCC+MNC) of current registered operator
   4035      * @hide
   4036      */
   4037     public void setNetworkOperatorNumeric(String numeric) {
   4038         int phoneId = getDefaultPhone();
   4039         setNetworkOperatorNumericForPhone(phoneId, numeric);
   4040     }
   4041 
   4042     /**
   4043      * Set the numeric name (MCC+MNC) of current registered operator.
   4044      * @param phoneId for which phone type is set
   4045      * @param operator the numeric name (MCC+MNC) of current registered operator
   4046      * @hide
   4047      */
   4048     public void setNetworkOperatorNumericForPhone(int phoneId, String numeric) {
   4049         setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, numeric);
   4050     }
   4051 
   4052     /**
   4053      * Set roaming state of the current network, for GSM purposes.
   4054      * @param isRoaming is network in romaing state or not
   4055      * @hide
   4056      */
   4057     public void setNetworkRoaming(boolean isRoaming) {
   4058         int phoneId = getDefaultPhone();
   4059         setNetworkRoamingForPhone(phoneId, isRoaming);
   4060     }
   4061 
   4062     /**
   4063      * Set roaming state of the current network, for GSM purposes.
   4064      * @param phoneId which phone you want to set
   4065      * @param isRoaming is network in romaing state or not
   4066      * @hide
   4067      */
   4068     public void setNetworkRoamingForPhone(int phoneId, boolean isRoaming) {
   4069         if (SubscriptionManager.isValidPhoneId(phoneId)) {
   4070             setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISROAMING,
   4071                     isRoaming ? "true" : "false");
   4072         }
   4073     }
   4074 
   4075     /**
   4076      * Set the ISO country code equivalent of the current registered
   4077      * operator's MCC (Mobile Country Code).
   4078      * @param iso the ISO country code equivalent of the current registered
   4079      * @hide
   4080      */
   4081     public void setNetworkCountryIso(String iso) {
   4082         int phoneId = getDefaultPhone();
   4083         setNetworkCountryIsoForPhone(phoneId, iso);
   4084     }
   4085 
   4086     /**
   4087      * Set the ISO country code equivalent of the current registered
   4088      * operator's MCC (Mobile Country Code).
   4089      * @param phoneId which phone you want to set
   4090      * @param iso the ISO country code equivalent of the current registered
   4091      * @hide
   4092      */
   4093     public void setNetworkCountryIsoForPhone(int phoneId, String iso) {
   4094         if (SubscriptionManager.isValidPhoneId(phoneId)) {
   4095             setTelephonyProperty(phoneId,
   4096                     TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, iso);
   4097         }
   4098     }
   4099 
   4100     /**
   4101      * Set the network type currently in use on the device for data transmission.
   4102      * @param type the network type currently in use on the device for data transmission
   4103      * @hide
   4104      */
   4105     public void setDataNetworkType(int type) {
   4106         int phoneId = getDefaultPhone();
   4107         setDataNetworkTypeForPhone(phoneId, type);
   4108     }
   4109 
   4110     /**
   4111      * Set the network type currently in use on the device for data transmission.
   4112      * @param phoneId which phone you want to set
   4113      * @param type the network type currently in use on the device for data transmission
   4114      * @hide
   4115      */
   4116     public void setDataNetworkTypeForPhone(int phoneId, int type) {
   4117         if (SubscriptionManager.isValidPhoneId(phoneId)) {
   4118             setTelephonyProperty(phoneId,
   4119                     TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE,
   4120                     ServiceState.rilRadioTechnologyToString(type));
   4121         }
   4122     }
   4123 }
   4124