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.SdkConstant;
     20 import android.annotation.SdkConstant.SdkConstantType;
     21 import android.content.Context;
     22 import android.os.Bundle;
     23 import android.os.RemoteException;
     24 import android.os.ServiceManager;
     25 import android.os.SystemProperties;
     26 import android.telephony.Rlog;
     27 
     28 import com.android.internal.telephony.IPhoneSubInfo;
     29 import com.android.internal.telephony.ITelephony;
     30 import com.android.internal.telephony.ITelephonyRegistry;
     31 import com.android.internal.telephony.PhoneConstants;
     32 import com.android.internal.telephony.RILConstants;
     33 import com.android.internal.telephony.TelephonyProperties;
     34 
     35 import java.io.FileInputStream;
     36 import java.io.IOException;
     37 import java.util.List;
     38 import java.util.regex.Matcher;
     39 import java.util.regex.Pattern;
     40 
     41 /**
     42  * Provides access to information about the telephony services on
     43  * the device. Applications can use the methods in this class to
     44  * determine telephony services and states, as well as to access some
     45  * types of subscriber information. Applications can also register
     46  * a listener to receive notification of telephony state changes.
     47  * <p>
     48  * You do not instantiate this class directly; instead, you retrieve
     49  * a reference to an instance through
     50  * {@link android.content.Context#getSystemService
     51  * Context.getSystemService(Context.TELEPHONY_SERVICE)}.
     52  * <p>
     53  * Note that access to some telephony information is
     54  * permission-protected. Your application cannot access the protected
     55  * information unless it has the appropriate permissions declared in
     56  * its manifest file. Where permissions apply, they are noted in the
     57  * the methods through which you access the protected information.
     58  */
     59 public class TelephonyManager {
     60     private static final String TAG = "TelephonyManager";
     61 
     62     private static ITelephonyRegistry sRegistry;
     63     private final Context mContext;
     64 
     65     /** @hide */
     66     public TelephonyManager(Context context) {
     67         Context appContext = context.getApplicationContext();
     68         if (appContext != null) {
     69             mContext = appContext;
     70         } else {
     71             mContext = context;
     72         }
     73 
     74         if (sRegistry == null) {
     75             sRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService(
     76                     "telephony.registry"));
     77         }
     78     }
     79 
     80     /** @hide */
     81     private TelephonyManager() {
     82         mContext = null;
     83     }
     84 
     85     private static TelephonyManager sInstance = new TelephonyManager();
     86 
     87     /** @hide
     88     /* @deprecated - use getSystemService as described above */
     89     public static TelephonyManager getDefault() {
     90         return sInstance;
     91     }
     92 
     93     /** {@hide} */
     94     public static TelephonyManager from(Context context) {
     95         return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
     96     }
     97 
     98     //
     99     // Broadcast Intent actions
    100     //
    101 
    102     /**
    103      * Broadcast intent action indicating that the call state (cellular)
    104      * on the device has changed.
    105      *
    106      * <p>
    107      * The {@link #EXTRA_STATE} extra indicates the new call state.
    108      * If the new state is RINGING, a second extra
    109      * {@link #EXTRA_INCOMING_NUMBER} provides the incoming phone number as
    110      * a String.
    111      *
    112      * <p class="note">
    113      * Requires the READ_PHONE_STATE permission.
    114      *
    115      * <p class="note">
    116      * This was a {@link android.content.Context#sendStickyBroadcast sticky}
    117      * broadcast in version 1.0, but it is no longer sticky.
    118      * Instead, use {@link #getCallState} to synchronously query the current call state.
    119      *
    120      * @see #EXTRA_STATE
    121      * @see #EXTRA_INCOMING_NUMBER
    122      * @see #getCallState
    123      */
    124     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    125     public static final String ACTION_PHONE_STATE_CHANGED =
    126             "android.intent.action.PHONE_STATE";
    127 
    128     /**
    129      * The Phone app sends this intent when a user opts to respond-via-message during an incoming
    130      * call. By default, the device's default SMS app consumes this message and sends a text message
    131      * to the caller. A third party app can also provide this functionality by consuming this Intent
    132      * with a {@link android.app.Service} and sending the message using its own messaging system.
    133      * <p>The intent contains a URI (available from {@link android.content.Intent#getData})
    134      * describing the recipient, using either the {@code sms:}, {@code smsto:}, {@code mms:},
    135      * or {@code mmsto:} URI schema. Each of these URI schema carry the recipient information the
    136      * same way: the path part of the URI contains the recipient's phone number or a comma-separated
    137      * set of phone numbers if there are multiple recipients. For example, {@code
    138      * smsto:2065551234}.</p>
    139      *
    140      * <p>The intent may also contain extras for the message text (in {@link
    141      * android.content.Intent#EXTRA_TEXT}) and a message subject
    142      * (in {@link android.content.Intent#EXTRA_SUBJECT}).</p>
    143      *
    144      * <p class="note"><strong>Note:</strong>
    145      * The intent-filter that consumes this Intent needs to be in a {@link android.app.Service}
    146      * that requires the
    147      * permission {@link android.Manifest.permission#SEND_RESPOND_VIA_MESSAGE}.</p>
    148      * <p>For example, the service that receives this intent can be declared in the manifest file
    149      * with an intent filter like this:</p>
    150      * <pre>
    151      * &lt;!-- Service that delivers SMS messages received from the phone "quick response" -->
    152      * &lt;service android:name=".HeadlessSmsSendService"
    153      *          android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
    154      *          android:exported="true" >
    155      *   &lt;intent-filter>
    156      *     &lt;action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
    157      *     &lt;category android:name="android.intent.category.DEFAULT" />
    158      *     &lt;data android:scheme="sms" />
    159      *     &lt;data android:scheme="smsto" />
    160      *     &lt;data android:scheme="mms" />
    161      *     &lt;data android:scheme="mmsto" />
    162      *   &lt;/intent-filter>
    163      * &lt;/service></pre>
    164      * <p>
    165      * Output: nothing.
    166      */
    167     @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    168     public static final String ACTION_RESPOND_VIA_MESSAGE =
    169             "android.intent.action.RESPOND_VIA_MESSAGE";
    170 
    171     /**
    172      * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast
    173      * for a String containing the new call state.
    174      *
    175      * @see #EXTRA_STATE_IDLE
    176      * @see #EXTRA_STATE_RINGING
    177      * @see #EXTRA_STATE_OFFHOOK
    178      *
    179      * <p class="note">
    180      * Retrieve with
    181      * {@link android.content.Intent#getStringExtra(String)}.
    182      */
    183     public static final String EXTRA_STATE = PhoneConstants.STATE_KEY;
    184 
    185     /**
    186      * Value used with {@link #EXTRA_STATE} corresponding to
    187      * {@link #CALL_STATE_IDLE}.
    188      */
    189     public static final String EXTRA_STATE_IDLE = PhoneConstants.State.IDLE.toString();
    190 
    191     /**
    192      * Value used with {@link #EXTRA_STATE} corresponding to
    193      * {@link #CALL_STATE_RINGING}.
    194      */
    195     public static final String EXTRA_STATE_RINGING = PhoneConstants.State.RINGING.toString();
    196 
    197     /**
    198      * Value used with {@link #EXTRA_STATE} corresponding to
    199      * {@link #CALL_STATE_OFFHOOK}.
    200      */
    201     public static final String EXTRA_STATE_OFFHOOK = PhoneConstants.State.OFFHOOK.toString();
    202 
    203     /**
    204      * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast
    205      * for a String containing the incoming phone number.
    206      * Only valid when the new call state is RINGING.
    207      *
    208      * <p class="note">
    209      * Retrieve with
    210      * {@link android.content.Intent#getStringExtra(String)}.
    211      */
    212     public static final String EXTRA_INCOMING_NUMBER = "incoming_number";
    213 
    214 
    215     //
    216     //
    217     // Device Info
    218     //
    219     //
    220 
    221     /**
    222      * Returns the software version number for the device, for example,
    223      * the IMEI/SV for GSM phones. Return null if the software version is
    224      * not available.
    225      *
    226      * <p>Requires Permission:
    227      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
    228      */
    229     public String getDeviceSoftwareVersion() {
    230         try {
    231             return getSubscriberInfo().getDeviceSvn();
    232         } catch (RemoteException ex) {
    233             return null;
    234         } catch (NullPointerException ex) {
    235             return null;
    236         }
    237     }
    238 
    239     /**
    240      * Returns the unique device ID, for example, the IMEI for GSM and the MEID
    241      * or ESN for CDMA phones. Return null if device ID is not available.
    242      *
    243      * <p>Requires Permission:
    244      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
    245      */
    246     public String getDeviceId() {
    247         try {
    248             return getSubscriberInfo().getDeviceId();
    249         } catch (RemoteException ex) {
    250             return null;
    251         } catch (NullPointerException ex) {
    252             return null;
    253         }
    254     }
    255 
    256     /**
    257      * Returns the current location of the device.
    258      *<p>
    259      * If there is only one radio in the device and that radio has an LTE connection,
    260      * this method will return null. The implementation must not to try add LTE
    261      * identifiers into the existing cdma/gsm classes.
    262      *<p>
    263      * In the future this call will be deprecated.
    264      *<p>
    265      * @return Current location of the device or null if not available.
    266      *
    267      * <p>Requires Permission:
    268      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or
    269      * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION}.
    270      */
    271     public CellLocation getCellLocation() {
    272         try {
    273             Bundle bundle = getITelephony().getCellLocation();
    274             if (bundle.isEmpty()) return null;
    275             CellLocation cl = CellLocation.newFromBundle(bundle);
    276             if (cl.isEmpty())
    277                 return null;
    278             return cl;
    279         } catch (RemoteException ex) {
    280             return null;
    281         } catch (NullPointerException ex) {
    282             return null;
    283         }
    284     }
    285 
    286     /**
    287      * Enables location update notifications.  {@link PhoneStateListener#onCellLocationChanged
    288      * PhoneStateListener.onCellLocationChanged} will be called on location updates.
    289      *
    290      * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES
    291      * CONTROL_LOCATION_UPDATES}
    292      *
    293      * @hide
    294      */
    295     public void enableLocationUpdates() {
    296         try {
    297             getITelephony().enableLocationUpdates();
    298         } catch (RemoteException ex) {
    299         } catch (NullPointerException ex) {
    300         }
    301     }
    302 
    303     /**
    304      * Disables location update notifications.  {@link PhoneStateListener#onCellLocationChanged
    305      * PhoneStateListener.onCellLocationChanged} will be called on location updates.
    306      *
    307      * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES
    308      * CONTROL_LOCATION_UPDATES}
    309      *
    310      * @hide
    311      */
    312     public void disableLocationUpdates() {
    313         try {
    314             getITelephony().disableLocationUpdates();
    315         } catch (RemoteException ex) {
    316         } catch (NullPointerException ex) {
    317         }
    318     }
    319 
    320     /**
    321      * Returns the neighboring cell information of the device. The getAllCellInfo is preferred
    322      * and use this only if getAllCellInfo return nulls or an empty list.
    323      *<p>
    324      * In the future this call will be deprecated.
    325      *<p>
    326      * @return List of NeighboringCellInfo or null if info unavailable.
    327      *
    328      * <p>Requires Permission:
    329      * (@link android.Manifest.permission#ACCESS_COARSE_UPDATES}
    330      */
    331     public List<NeighboringCellInfo> getNeighboringCellInfo() {
    332         try {
    333             return getITelephony().getNeighboringCellInfo(mContext.getOpPackageName());
    334         } catch (RemoteException ex) {
    335             return null;
    336         } catch (NullPointerException ex) {
    337             return null;
    338         }
    339     }
    340 
    341     /** No phone radio. */
    342     public static final int PHONE_TYPE_NONE = PhoneConstants.PHONE_TYPE_NONE;
    343     /** Phone radio is GSM. */
    344     public static final int PHONE_TYPE_GSM = PhoneConstants.PHONE_TYPE_GSM;
    345     /** Phone radio is CDMA. */
    346     public static final int PHONE_TYPE_CDMA = PhoneConstants.PHONE_TYPE_CDMA;
    347     /** Phone is via SIP. */
    348     public static final int PHONE_TYPE_SIP = PhoneConstants.PHONE_TYPE_SIP;
    349 
    350     /**
    351      * Returns the current phone type.
    352      * TODO: This is a last minute change and hence hidden.
    353      *
    354      * @see #PHONE_TYPE_NONE
    355      * @see #PHONE_TYPE_GSM
    356      * @see #PHONE_TYPE_CDMA
    357      * @see #PHONE_TYPE_SIP
    358      *
    359      * {@hide}
    360      */
    361     public int getCurrentPhoneType() {
    362         try{
    363             ITelephony telephony = getITelephony();
    364             if (telephony != null) {
    365                 return telephony.getActivePhoneType();
    366             } else {
    367                 // This can happen when the ITelephony interface is not up yet.
    368                 return getPhoneTypeFromProperty();
    369             }
    370         } catch (RemoteException ex) {
    371             // This shouldn't happen in the normal case, as a backup we
    372             // read from the system property.
    373             return getPhoneTypeFromProperty();
    374         } catch (NullPointerException ex) {
    375             // This shouldn't happen in the normal case, as a backup we
    376             // read from the system property.
    377             return getPhoneTypeFromProperty();
    378         }
    379     }
    380 
    381     /**
    382      * Returns a constant indicating the device phone type.  This
    383      * indicates the type of radio used to transmit voice calls.
    384      *
    385      * @see #PHONE_TYPE_NONE
    386      * @see #PHONE_TYPE_GSM
    387      * @see #PHONE_TYPE_CDMA
    388      * @see #PHONE_TYPE_SIP
    389      */
    390     public int getPhoneType() {
    391         if (!isVoiceCapable()) {
    392             return PHONE_TYPE_NONE;
    393         }
    394         return getCurrentPhoneType();
    395     }
    396 
    397     private int getPhoneTypeFromProperty() {
    398         int type =
    399             SystemProperties.getInt(TelephonyProperties.CURRENT_ACTIVE_PHONE,
    400                     getPhoneTypeFromNetworkType());
    401         return type;
    402     }
    403 
    404     private int getPhoneTypeFromNetworkType() {
    405         // When the system property CURRENT_ACTIVE_PHONE, has not been set,
    406         // use the system property for default network type.
    407         // This is a fail safe, and can only happen at first boot.
    408         int mode = SystemProperties.getInt("ro.telephony.default_network", -1);
    409         if (mode == -1)
    410             return PHONE_TYPE_NONE;
    411         return getPhoneType(mode);
    412     }
    413 
    414     /**
    415      * This function returns the type of the phone, depending
    416      * on the network mode.
    417      *
    418      * @param networkMode
    419      * @return Phone Type
    420      *
    421      * @hide
    422      */
    423     public static int getPhoneType(int networkMode) {
    424         switch(networkMode) {
    425         case RILConstants.NETWORK_MODE_CDMA:
    426         case RILConstants.NETWORK_MODE_CDMA_NO_EVDO:
    427         case RILConstants.NETWORK_MODE_EVDO_NO_CDMA:
    428             return PhoneConstants.PHONE_TYPE_CDMA;
    429 
    430         case RILConstants.NETWORK_MODE_WCDMA_PREF:
    431         case RILConstants.NETWORK_MODE_GSM_ONLY:
    432         case RILConstants.NETWORK_MODE_WCDMA_ONLY:
    433         case RILConstants.NETWORK_MODE_GSM_UMTS:
    434         case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA:
    435         case RILConstants.NETWORK_MODE_LTE_WCDMA:
    436         case RILConstants.NETWORK_MODE_LTE_CMDA_EVDO_GSM_WCDMA:
    437             return PhoneConstants.PHONE_TYPE_GSM;
    438 
    439         // Use CDMA Phone for the global mode including CDMA
    440         case RILConstants.NETWORK_MODE_GLOBAL:
    441         case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO:
    442             return PhoneConstants.PHONE_TYPE_CDMA;
    443 
    444         case RILConstants.NETWORK_MODE_LTE_ONLY:
    445             if (getLteOnCdmaModeStatic() == PhoneConstants.LTE_ON_CDMA_TRUE) {
    446                 return PhoneConstants.PHONE_TYPE_CDMA;
    447             } else {
    448                 return PhoneConstants.PHONE_TYPE_GSM;
    449             }
    450         default:
    451             return PhoneConstants.PHONE_TYPE_GSM;
    452         }
    453     }
    454 
    455     /**
    456      * The contents of the /proc/cmdline file
    457      */
    458     private static String getProcCmdLine()
    459     {
    460         String cmdline = "";
    461         FileInputStream is = null;
    462         try {
    463             is = new FileInputStream("/proc/cmdline");
    464             byte [] buffer = new byte[2048];
    465             int count = is.read(buffer);
    466             if (count > 0) {
    467                 cmdline = new String(buffer, 0, count);
    468             }
    469         } catch (IOException e) {
    470             Rlog.d(TAG, "No /proc/cmdline exception=" + e);
    471         } finally {
    472             if (is != null) {
    473                 try {
    474                     is.close();
    475                 } catch (IOException e) {
    476                 }
    477             }
    478         }
    479         Rlog.d(TAG, "/proc/cmdline=" + cmdline);
    480         return cmdline;
    481     }
    482 
    483     /** Kernel command line */
    484     private static final String sKernelCmdLine = getProcCmdLine();
    485 
    486     /** Pattern for selecting the product type from the kernel command line */
    487     private static final Pattern sProductTypePattern =
    488         Pattern.compile("\\sproduct_type\\s*=\\s*(\\w+)");
    489 
    490     /** The ProductType used for LTE on CDMA devices */
    491     private static final String sLteOnCdmaProductType =
    492         SystemProperties.get(TelephonyProperties.PROPERTY_LTE_ON_CDMA_PRODUCT_TYPE, "");
    493 
    494     /**
    495      * Return if the current radio is LTE on CDMA. This
    496      * is a tri-state return value as for a period of time
    497      * the mode may be unknown.
    498      *
    499      * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE}
    500      * or {@link PhoneConstants#LTE_ON_CDMA_TRUE}
    501      *
    502      * @hide
    503      */
    504     public static int getLteOnCdmaModeStatic() {
    505         int retVal;
    506         int curVal;
    507         String productType = "";
    508 
    509         curVal = SystemProperties.getInt(TelephonyProperties.PROPERTY_LTE_ON_CDMA_DEVICE,
    510                     PhoneConstants.LTE_ON_CDMA_UNKNOWN);
    511         retVal = curVal;
    512         if (retVal == PhoneConstants.LTE_ON_CDMA_UNKNOWN) {
    513             Matcher matcher = sProductTypePattern.matcher(sKernelCmdLine);
    514             if (matcher.find()) {
    515                 productType = matcher.group(1);
    516                 if (sLteOnCdmaProductType.equals(productType)) {
    517                     retVal = PhoneConstants.LTE_ON_CDMA_TRUE;
    518                 } else {
    519                     retVal = PhoneConstants.LTE_ON_CDMA_FALSE;
    520                 }
    521             } else {
    522                 retVal = PhoneConstants.LTE_ON_CDMA_FALSE;
    523             }
    524         }
    525 
    526         Rlog.d(TAG, "getLteOnCdmaMode=" + retVal + " curVal=" + curVal +
    527                 " product_type='" + productType +
    528                 "' lteOnCdmaProductType='" + sLteOnCdmaProductType + "'");
    529         return retVal;
    530     }
    531 
    532     //
    533     //
    534     // Current Network
    535     //
    536     //
    537 
    538     /**
    539      * Returns the alphabetic name of current registered operator.
    540      * <p>
    541      * Availability: Only when user is registered to a network. Result may be
    542      * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
    543      * on a CDMA network).
    544      */
    545     public String getNetworkOperatorName() {
    546         return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ALPHA);
    547     }
    548 
    549     /**
    550      * Returns the numeric name (MCC+MNC) of current registered operator.
    551      * <p>
    552      * Availability: Only when user is registered to a network. Result may be
    553      * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
    554      * on a CDMA network).
    555      */
    556     public String getNetworkOperator() {
    557         return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC);
    558     }
    559 
    560     /**
    561      * Returns true if the device is considered roaming on the current
    562      * network, for GSM purposes.
    563      * <p>
    564      * Availability: Only when user registered to a network.
    565      */
    566     public boolean isNetworkRoaming() {
    567         return "true".equals(SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ISROAMING));
    568     }
    569 
    570     /**
    571      * Returns the ISO country code equivalent of the current registered
    572      * operator's MCC (Mobile Country Code).
    573      * <p>
    574      * Availability: Only when user is registered to a network. Result may be
    575      * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
    576      * on a CDMA network).
    577      */
    578     public String getNetworkCountryIso() {
    579         return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY);
    580     }
    581 
    582     /** Network type is unknown */
    583     public static final int NETWORK_TYPE_UNKNOWN = 0;
    584     /** Current network is GPRS */
    585     public static final int NETWORK_TYPE_GPRS = 1;
    586     /** Current network is EDGE */
    587     public static final int NETWORK_TYPE_EDGE = 2;
    588     /** Current network is UMTS */
    589     public static final int NETWORK_TYPE_UMTS = 3;
    590     /** Current network is CDMA: Either IS95A or IS95B*/
    591     public static final int NETWORK_TYPE_CDMA = 4;
    592     /** Current network is EVDO revision 0*/
    593     public static final int NETWORK_TYPE_EVDO_0 = 5;
    594     /** Current network is EVDO revision A*/
    595     public static final int NETWORK_TYPE_EVDO_A = 6;
    596     /** Current network is 1xRTT*/
    597     public static final int NETWORK_TYPE_1xRTT = 7;
    598     /** Current network is HSDPA */
    599     public static final int NETWORK_TYPE_HSDPA = 8;
    600     /** Current network is HSUPA */
    601     public static final int NETWORK_TYPE_HSUPA = 9;
    602     /** Current network is HSPA */
    603     public static final int NETWORK_TYPE_HSPA = 10;
    604     /** Current network is iDen */
    605     public static final int NETWORK_TYPE_IDEN = 11;
    606     /** Current network is EVDO revision B*/
    607     public static final int NETWORK_TYPE_EVDO_B = 12;
    608     /** Current network is LTE */
    609     public static final int NETWORK_TYPE_LTE = 13;
    610     /** Current network is eHRPD */
    611     public static final int NETWORK_TYPE_EHRPD = 14;
    612     /** Current network is HSPA+ */
    613     public static final int NETWORK_TYPE_HSPAP = 15;
    614 
    615     /**
    616      * @return the NETWORK_TYPE_xxxx for current data connection.
    617      */
    618     public int getNetworkType() {
    619         return getDataNetworkType();
    620     }
    621 
    622     /**
    623      * Returns a constant indicating the radio technology (network type)
    624      * currently in use on the device for data transmission.
    625      * @return the network type
    626      *
    627      * @see #NETWORK_TYPE_UNKNOWN
    628      * @see #NETWORK_TYPE_GPRS
    629      * @see #NETWORK_TYPE_EDGE
    630      * @see #NETWORK_TYPE_UMTS
    631      * @see #NETWORK_TYPE_HSDPA
    632      * @see #NETWORK_TYPE_HSUPA
    633      * @see #NETWORK_TYPE_HSPA
    634      * @see #NETWORK_TYPE_CDMA
    635      * @see #NETWORK_TYPE_EVDO_0
    636      * @see #NETWORK_TYPE_EVDO_A
    637      * @see #NETWORK_TYPE_EVDO_B
    638      * @see #NETWORK_TYPE_1xRTT
    639      * @see #NETWORK_TYPE_IDEN
    640      * @see #NETWORK_TYPE_LTE
    641      * @see #NETWORK_TYPE_EHRPD
    642      * @see #NETWORK_TYPE_HSPAP
    643      *
    644      * @hide
    645      */
    646     public int getDataNetworkType() {
    647         try{
    648             ITelephony telephony = getITelephony();
    649             if (telephony != null) {
    650                 return telephony.getDataNetworkType();
    651             } else {
    652                 // This can happen when the ITelephony interface is not up yet.
    653                 return NETWORK_TYPE_UNKNOWN;
    654             }
    655         } catch(RemoteException ex) {
    656             // This shouldn't happen in the normal case
    657             return NETWORK_TYPE_UNKNOWN;
    658         } catch (NullPointerException ex) {
    659             // This could happen before phone restarts due to crashing
    660             return NETWORK_TYPE_UNKNOWN;
    661         }
    662     }
    663 
    664     /**
    665      * Returns the NETWORK_TYPE_xxxx for voice
    666      *
    667      * @hide
    668      */
    669     public int getVoiceNetworkType() {
    670         try{
    671             ITelephony telephony = getITelephony();
    672             if (telephony != null) {
    673                 return telephony.getVoiceNetworkType();
    674             } else {
    675                 // This can happen when the ITelephony interface is not up yet.
    676                 return NETWORK_TYPE_UNKNOWN;
    677             }
    678         } catch(RemoteException ex) {
    679             // This shouldn't happen in the normal case
    680             return NETWORK_TYPE_UNKNOWN;
    681         } catch (NullPointerException ex) {
    682             // This could happen before phone restarts due to crashing
    683             return NETWORK_TYPE_UNKNOWN;
    684         }
    685     }
    686 
    687     /** Unknown network class. {@hide} */
    688     public static final int NETWORK_CLASS_UNKNOWN = 0;
    689     /** Class of broadly defined "2G" networks. {@hide} */
    690     public static final int NETWORK_CLASS_2_G = 1;
    691     /** Class of broadly defined "3G" networks. {@hide} */
    692     public static final int NETWORK_CLASS_3_G = 2;
    693     /** Class of broadly defined "4G" networks. {@hide} */
    694     public static final int NETWORK_CLASS_4_G = 3;
    695 
    696     /**
    697      * Return general class of network type, such as "3G" or "4G". In cases
    698      * where classification is contentious, this method is conservative.
    699      *
    700      * @hide
    701      */
    702     public static int getNetworkClass(int networkType) {
    703         switch (networkType) {
    704             case NETWORK_TYPE_GPRS:
    705             case NETWORK_TYPE_EDGE:
    706             case NETWORK_TYPE_CDMA:
    707             case NETWORK_TYPE_1xRTT:
    708             case NETWORK_TYPE_IDEN:
    709                 return NETWORK_CLASS_2_G;
    710             case NETWORK_TYPE_UMTS:
    711             case NETWORK_TYPE_EVDO_0:
    712             case NETWORK_TYPE_EVDO_A:
    713             case NETWORK_TYPE_HSDPA:
    714             case NETWORK_TYPE_HSUPA:
    715             case NETWORK_TYPE_HSPA:
    716             case NETWORK_TYPE_EVDO_B:
    717             case NETWORK_TYPE_EHRPD:
    718             case NETWORK_TYPE_HSPAP:
    719                 return NETWORK_CLASS_3_G;
    720             case NETWORK_TYPE_LTE:
    721                 return NETWORK_CLASS_4_G;
    722             default:
    723                 return NETWORK_CLASS_UNKNOWN;
    724         }
    725     }
    726 
    727     /**
    728      * Returns a string representation of the radio technology (network type)
    729      * currently in use on the device.
    730      * @return the name of the radio technology
    731      *
    732      * @hide pending API council review
    733      */
    734     public String getNetworkTypeName() {
    735         return getNetworkTypeName(getNetworkType());
    736     }
    737 
    738     /** {@hide} */
    739     public static String getNetworkTypeName(int type) {
    740         switch (type) {
    741             case NETWORK_TYPE_GPRS:
    742                 return "GPRS";
    743             case NETWORK_TYPE_EDGE:
    744                 return "EDGE";
    745             case NETWORK_TYPE_UMTS:
    746                 return "UMTS";
    747             case NETWORK_TYPE_HSDPA:
    748                 return "HSDPA";
    749             case NETWORK_TYPE_HSUPA:
    750                 return "HSUPA";
    751             case NETWORK_TYPE_HSPA:
    752                 return "HSPA";
    753             case NETWORK_TYPE_CDMA:
    754                 return "CDMA";
    755             case NETWORK_TYPE_EVDO_0:
    756                 return "CDMA - EvDo rev. 0";
    757             case NETWORK_TYPE_EVDO_A:
    758                 return "CDMA - EvDo rev. A";
    759             case NETWORK_TYPE_EVDO_B:
    760                 return "CDMA - EvDo rev. B";
    761             case NETWORK_TYPE_1xRTT:
    762                 return "CDMA - 1xRTT";
    763             case NETWORK_TYPE_LTE:
    764                 return "LTE";
    765             case NETWORK_TYPE_EHRPD:
    766                 return "CDMA - eHRPD";
    767             case NETWORK_TYPE_IDEN:
    768                 return "iDEN";
    769             case NETWORK_TYPE_HSPAP:
    770                 return "HSPA+";
    771             default:
    772                 return "UNKNOWN";
    773         }
    774     }
    775 
    776     //
    777     //
    778     // SIM Card
    779     //
    780     //
    781 
    782     /** SIM card state: Unknown. Signifies that the SIM is in transition
    783      *  between states. For example, when the user inputs the SIM pin
    784      *  under PIN_REQUIRED state, a query for sim status returns
    785      *  this state before turning to SIM_STATE_READY. */
    786     public static final int SIM_STATE_UNKNOWN = 0;
    787     /** SIM card state: no SIM card is available in the device */
    788     public static final int SIM_STATE_ABSENT = 1;
    789     /** SIM card state: Locked: requires the user's SIM PIN to unlock */
    790     public static final int SIM_STATE_PIN_REQUIRED = 2;
    791     /** SIM card state: Locked: requires the user's SIM PUK to unlock */
    792     public static final int SIM_STATE_PUK_REQUIRED = 3;
    793     /** SIM card state: Locked: requries a network PIN to unlock */
    794     public static final int SIM_STATE_NETWORK_LOCKED = 4;
    795     /** SIM card state: Ready */
    796     public static final int SIM_STATE_READY = 5;
    797 
    798     /**
    799      * @return true if a ICC card is present
    800      */
    801     public boolean hasIccCard() {
    802         try {
    803             return getITelephony().hasIccCard();
    804         } catch (RemoteException ex) {
    805             // Assume no ICC card if remote exception which shouldn't happen
    806             return false;
    807         } catch (NullPointerException ex) {
    808             // This could happen before phone restarts due to crashing
    809             return false;
    810         }
    811     }
    812 
    813     /**
    814      * Returns a constant indicating the state of the
    815      * device SIM card.
    816      *
    817      * @see #SIM_STATE_UNKNOWN
    818      * @see #SIM_STATE_ABSENT
    819      * @see #SIM_STATE_PIN_REQUIRED
    820      * @see #SIM_STATE_PUK_REQUIRED
    821      * @see #SIM_STATE_NETWORK_LOCKED
    822      * @see #SIM_STATE_READY
    823      */
    824     public int getSimState() {
    825         String prop = SystemProperties.get(TelephonyProperties.PROPERTY_SIM_STATE);
    826         if ("ABSENT".equals(prop)) {
    827             return SIM_STATE_ABSENT;
    828         }
    829         else if ("PIN_REQUIRED".equals(prop)) {
    830             return SIM_STATE_PIN_REQUIRED;
    831         }
    832         else if ("PUK_REQUIRED".equals(prop)) {
    833             return SIM_STATE_PUK_REQUIRED;
    834         }
    835         else if ("NETWORK_LOCKED".equals(prop)) {
    836             return SIM_STATE_NETWORK_LOCKED;
    837         }
    838         else if ("READY".equals(prop)) {
    839             return SIM_STATE_READY;
    840         }
    841         else {
    842             return SIM_STATE_UNKNOWN;
    843         }
    844     }
    845 
    846     /**
    847      * Returns the MCC+MNC (mobile country code + mobile network code) of the
    848      * provider of the SIM. 5 or 6 decimal digits.
    849      * <p>
    850      * Availability: SIM state must be {@link #SIM_STATE_READY}
    851      *
    852      * @see #getSimState
    853      */
    854     public String getSimOperator() {
    855         return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC);
    856     }
    857 
    858     /**
    859      * Returns the Service Provider Name (SPN).
    860      * <p>
    861      * Availability: SIM state must be {@link #SIM_STATE_READY}
    862      *
    863      * @see #getSimState
    864      */
    865     public String getSimOperatorName() {
    866         return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA);
    867     }
    868 
    869     /**
    870      * Returns the ISO country code equivalent for the SIM provider's country code.
    871      */
    872     public String getSimCountryIso() {
    873         return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY);
    874     }
    875 
    876     /**
    877      * Returns the serial number of the SIM, if applicable. Return null if it is
    878      * unavailable.
    879      * <p>
    880      * Requires Permission:
    881      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
    882      */
    883     public String getSimSerialNumber() {
    884         try {
    885             return getSubscriberInfo().getIccSerialNumber();
    886         } catch (RemoteException ex) {
    887             return null;
    888         } catch (NullPointerException ex) {
    889             // This could happen before phone restarts due to crashing
    890             return null;
    891         }
    892     }
    893 
    894     /**
    895      * Return if the current radio is LTE on CDMA. This
    896      * is a tri-state return value as for a period of time
    897      * the mode may be unknown.
    898      *
    899      * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE}
    900      * or {@link PhoneConstants#LTE_ON_CDMA_TRUE}
    901      *
    902      * @hide
    903      */
    904     public int getLteOnCdmaMode() {
    905         try {
    906             return getITelephony().getLteOnCdmaMode();
    907         } catch (RemoteException ex) {
    908             // Assume no ICC card if remote exception which shouldn't happen
    909             return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
    910         } catch (NullPointerException ex) {
    911             // This could happen before phone restarts due to crashing
    912             return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
    913         }
    914     }
    915 
    916     //
    917     //
    918     // Subscriber Info
    919     //
    920     //
    921 
    922     /**
    923      * Returns the unique subscriber ID, for example, the IMSI for a GSM phone.
    924      * Return null if it is unavailable.
    925      * <p>
    926      * Requires Permission:
    927      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
    928      */
    929     public String getSubscriberId() {
    930         try {
    931             return getSubscriberInfo().getSubscriberId();
    932         } catch (RemoteException ex) {
    933             return null;
    934         } catch (NullPointerException ex) {
    935             // This could happen before phone restarts due to crashing
    936             return null;
    937         }
    938     }
    939 
    940     /**
    941      * Returns the Group Identifier Level1 for a GSM phone.
    942      * Return null if it is unavailable.
    943      * <p>
    944      * Requires Permission:
    945      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
    946      */
    947     public String getGroupIdLevel1() {
    948         try {
    949             return getSubscriberInfo().getGroupIdLevel1();
    950         } catch (RemoteException ex) {
    951             return null;
    952         } catch (NullPointerException ex) {
    953             // This could happen before phone restarts due to crashing
    954             return null;
    955         }
    956     }
    957 
    958     /**
    959      * Returns the phone number string for line 1, for example, the MSISDN
    960      * for a GSM phone. Return null if it is unavailable.
    961      * <p>
    962      * Requires Permission:
    963      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
    964      */
    965     public String getLine1Number() {
    966         try {
    967             return getSubscriberInfo().getLine1Number();
    968         } catch (RemoteException ex) {
    969             return null;
    970         } catch (NullPointerException ex) {
    971             // This could happen before phone restarts due to crashing
    972             return null;
    973         }
    974     }
    975 
    976     /**
    977      * Returns the alphabetic identifier associated with the line 1 number.
    978      * Return null if it is unavailable.
    979      * <p>
    980      * Requires Permission:
    981      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
    982      * @hide
    983      * nobody seems to call this.
    984      */
    985     public String getLine1AlphaTag() {
    986         try {
    987             return getSubscriberInfo().getLine1AlphaTag();
    988         } catch (RemoteException ex) {
    989             return null;
    990         } catch (NullPointerException ex) {
    991             // This could happen before phone restarts due to crashing
    992             return null;
    993         }
    994     }
    995 
    996     /**
    997      * Returns the MSISDN string.
    998      * for a GSM phone. Return null if it is unavailable.
    999      * <p>
   1000      * Requires Permission:
   1001      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   1002      *
   1003      * @hide
   1004      */
   1005     public String getMsisdn() {
   1006         try {
   1007             return getSubscriberInfo().getMsisdn();
   1008         } catch (RemoteException ex) {
   1009             return null;
   1010         } catch (NullPointerException ex) {
   1011             // This could happen before phone restarts due to crashing
   1012             return null;
   1013         }
   1014     }
   1015 
   1016     /**
   1017      * Returns the voice mail number. Return null if it is unavailable.
   1018      * <p>
   1019      * Requires Permission:
   1020      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   1021      */
   1022     public String getVoiceMailNumber() {
   1023         try {
   1024             return getSubscriberInfo().getVoiceMailNumber();
   1025         } catch (RemoteException ex) {
   1026             return null;
   1027         } catch (NullPointerException ex) {
   1028             // This could happen before phone restarts due to crashing
   1029             return null;
   1030         }
   1031     }
   1032 
   1033     /**
   1034      * Returns the complete voice mail number. Return null if it is unavailable.
   1035      * <p>
   1036      * Requires Permission:
   1037      *   {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED}
   1038      *
   1039      * @hide
   1040      */
   1041     public String getCompleteVoiceMailNumber() {
   1042         try {
   1043             return getSubscriberInfo().getCompleteVoiceMailNumber();
   1044         } catch (RemoteException ex) {
   1045             return null;
   1046         } catch (NullPointerException ex) {
   1047             // This could happen before phone restarts due to crashing
   1048             return null;
   1049         }
   1050     }
   1051 
   1052     /**
   1053      * Returns the voice mail count. Return 0 if unavailable.
   1054      * <p>
   1055      * Requires Permission:
   1056      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   1057      * @hide
   1058      */
   1059     public int getVoiceMessageCount() {
   1060         try {
   1061             return getITelephony().getVoiceMessageCount();
   1062         } catch (RemoteException ex) {
   1063             return 0;
   1064         } catch (NullPointerException ex) {
   1065             // This could happen before phone restarts due to crashing
   1066             return 0;
   1067         }
   1068     }
   1069 
   1070     /**
   1071      * Retrieves the alphabetic identifier associated with the voice
   1072      * mail number.
   1073      * <p>
   1074      * Requires Permission:
   1075      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
   1076      */
   1077     public String getVoiceMailAlphaTag() {
   1078         try {
   1079             return getSubscriberInfo().getVoiceMailAlphaTag();
   1080         } catch (RemoteException ex) {
   1081             return null;
   1082         } catch (NullPointerException ex) {
   1083             // This could happen before phone restarts due to crashing
   1084             return null;
   1085         }
   1086     }
   1087 
   1088     /**
   1089      * Returns the IMS private user identity (IMPI) that was loaded from the ISIM.
   1090      * @return the IMPI, or null if not present or not loaded
   1091      * @hide
   1092      */
   1093     public String getIsimImpi() {
   1094         try {
   1095             return getSubscriberInfo().getIsimImpi();
   1096         } catch (RemoteException ex) {
   1097             return null;
   1098         } catch (NullPointerException ex) {
   1099             // This could happen before phone restarts due to crashing
   1100             return null;
   1101         }
   1102     }
   1103 
   1104     /**
   1105      * Returns the IMS home network domain name that was loaded from the ISIM.
   1106      * @return the IMS domain name, or null if not present or not loaded
   1107      * @hide
   1108      */
   1109     public String getIsimDomain() {
   1110         try {
   1111             return getSubscriberInfo().getIsimDomain();
   1112         } catch (RemoteException ex) {
   1113             return null;
   1114         } catch (NullPointerException ex) {
   1115             // This could happen before phone restarts due to crashing
   1116             return null;
   1117         }
   1118     }
   1119 
   1120     /**
   1121      * Returns the IMS public user identities (IMPU) that were loaded from the ISIM.
   1122      * @return an array of IMPU strings, with one IMPU per string, or null if
   1123      *      not present or not loaded
   1124      * @hide
   1125      */
   1126     public String[] getIsimImpu() {
   1127         try {
   1128             return getSubscriberInfo().getIsimImpu();
   1129         } catch (RemoteException ex) {
   1130             return null;
   1131         } catch (NullPointerException ex) {
   1132             // This could happen before phone restarts due to crashing
   1133             return null;
   1134         }
   1135     }
   1136 
   1137     private IPhoneSubInfo getSubscriberInfo() {
   1138         // get it each time because that process crashes a lot
   1139         return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo"));
   1140     }
   1141 
   1142 
   1143     /** Device call state: No activity. */
   1144     public static final int CALL_STATE_IDLE = 0;
   1145     /** Device call state: Ringing. A new call arrived and is
   1146      *  ringing or waiting. In the latter case, another call is
   1147      *  already active. */
   1148     public static final int CALL_STATE_RINGING = 1;
   1149     /** Device call state: Off-hook. At least one call exists
   1150       * that is dialing, active, or on hold, and no calls are ringing
   1151       * or waiting. */
   1152     public static final int CALL_STATE_OFFHOOK = 2;
   1153 
   1154     /**
   1155      * Returns a constant indicating the call state (cellular) on the device.
   1156      */
   1157     public int getCallState() {
   1158         try {
   1159             return getITelephony().getCallState();
   1160         } catch (RemoteException ex) {
   1161             // the phone process is restarting.
   1162             return CALL_STATE_IDLE;
   1163         } catch (NullPointerException ex) {
   1164           // the phone process is restarting.
   1165           return CALL_STATE_IDLE;
   1166       }
   1167     }
   1168 
   1169     /** Data connection activity: No traffic. */
   1170     public static final int DATA_ACTIVITY_NONE = 0x00000000;
   1171     /** Data connection activity: Currently receiving IP PPP traffic. */
   1172     public static final int DATA_ACTIVITY_IN = 0x00000001;
   1173     /** Data connection activity: Currently sending IP PPP traffic. */
   1174     public static final int DATA_ACTIVITY_OUT = 0x00000002;
   1175     /** Data connection activity: Currently both sending and receiving
   1176      *  IP PPP traffic. */
   1177     public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT;
   1178     /**
   1179      * Data connection is active, but physical link is down
   1180      */
   1181     public static final int DATA_ACTIVITY_DORMANT = 0x00000004;
   1182 
   1183     /**
   1184      * Returns a constant indicating the type of activity on a data connection
   1185      * (cellular).
   1186      *
   1187      * @see #DATA_ACTIVITY_NONE
   1188      * @see #DATA_ACTIVITY_IN
   1189      * @see #DATA_ACTIVITY_OUT
   1190      * @see #DATA_ACTIVITY_INOUT
   1191      * @see #DATA_ACTIVITY_DORMANT
   1192      */
   1193     public int getDataActivity() {
   1194         try {
   1195             return getITelephony().getDataActivity();
   1196         } catch (RemoteException ex) {
   1197             // the phone process is restarting.
   1198             return DATA_ACTIVITY_NONE;
   1199         } catch (NullPointerException ex) {
   1200           // the phone process is restarting.
   1201           return DATA_ACTIVITY_NONE;
   1202       }
   1203     }
   1204 
   1205     /** Data connection state: Unknown.  Used before we know the state.
   1206      * @hide
   1207      */
   1208     public static final int DATA_UNKNOWN        = -1;
   1209     /** Data connection state: Disconnected. IP traffic not available. */
   1210     public static final int DATA_DISCONNECTED   = 0;
   1211     /** Data connection state: Currently setting up a data connection. */
   1212     public static final int DATA_CONNECTING     = 1;
   1213     /** Data connection state: Connected. IP traffic should be available. */
   1214     public static final int DATA_CONNECTED      = 2;
   1215     /** Data connection state: Suspended. The connection is up, but IP
   1216      * traffic is temporarily unavailable. For example, in a 2G network,
   1217      * data activity may be suspended when a voice call arrives. */
   1218     public static final int DATA_SUSPENDED      = 3;
   1219 
   1220     /**
   1221      * Returns a constant indicating the current data connection state
   1222      * (cellular).
   1223      *
   1224      * @see #DATA_DISCONNECTED
   1225      * @see #DATA_CONNECTING
   1226      * @see #DATA_CONNECTED
   1227      * @see #DATA_SUSPENDED
   1228      */
   1229     public int getDataState() {
   1230         try {
   1231             return getITelephony().getDataState();
   1232         } catch (RemoteException ex) {
   1233             // the phone process is restarting.
   1234             return DATA_DISCONNECTED;
   1235         } catch (NullPointerException ex) {
   1236             return DATA_DISCONNECTED;
   1237         }
   1238     }
   1239 
   1240     private ITelephony getITelephony() {
   1241         return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE));
   1242     }
   1243 
   1244     //
   1245     //
   1246     // PhoneStateListener
   1247     //
   1248     //
   1249 
   1250     /**
   1251      * Registers a listener object to receive notification of changes
   1252      * in specified telephony states.
   1253      * <p>
   1254      * To register a listener, pass a {@link PhoneStateListener}
   1255      * and specify at least one telephony state of interest in
   1256      * the events argument.
   1257      *
   1258      * At registration, and when a specified telephony state
   1259      * changes, the telephony manager invokes the appropriate
   1260      * callback method on the listener object and passes the
   1261      * current (udpated) values.
   1262      * <p>
   1263      * To unregister a listener, pass the listener object and set the
   1264      * events argument to
   1265      * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0).
   1266      *
   1267      * @param listener The {@link PhoneStateListener} object to register
   1268      *                 (or unregister)
   1269      * @param events The telephony state(s) of interest to the listener,
   1270      *               as a bitwise-OR combination of {@link PhoneStateListener}
   1271      *               LISTEN_ flags.
   1272      */
   1273     public void listen(PhoneStateListener listener, int events) {
   1274         String pkgForDebug = mContext != null ? mContext.getPackageName() : "<unknown>";
   1275         try {
   1276             Boolean notifyNow = true;
   1277             sRegistry.listen(pkgForDebug, listener.callback, events, notifyNow);
   1278         } catch (RemoteException ex) {
   1279             // system process dead
   1280         } catch (NullPointerException ex) {
   1281             // system process dead
   1282         }
   1283     }
   1284 
   1285     /**
   1286      * Returns the CDMA ERI icon index to display
   1287      *
   1288      * @hide
   1289      */
   1290     public int getCdmaEriIconIndex() {
   1291         try {
   1292             return getITelephony().getCdmaEriIconIndex();
   1293         } catch (RemoteException ex) {
   1294             // the phone process is restarting.
   1295             return -1;
   1296         } catch (NullPointerException ex) {
   1297             return -1;
   1298         }
   1299     }
   1300 
   1301     /**
   1302      * Returns the CDMA ERI icon mode,
   1303      * 0 - ON
   1304      * 1 - FLASHING
   1305      *
   1306      * @hide
   1307      */
   1308     public int getCdmaEriIconMode() {
   1309         try {
   1310             return getITelephony().getCdmaEriIconMode();
   1311         } catch (RemoteException ex) {
   1312             // the phone process is restarting.
   1313             return -1;
   1314         } catch (NullPointerException ex) {
   1315             return -1;
   1316         }
   1317     }
   1318 
   1319     /**
   1320      * Returns the CDMA ERI text,
   1321      *
   1322      * @hide
   1323      */
   1324     public String getCdmaEriText() {
   1325         try {
   1326             return getITelephony().getCdmaEriText();
   1327         } catch (RemoteException ex) {
   1328             // the phone process is restarting.
   1329             return null;
   1330         } catch (NullPointerException ex) {
   1331             return null;
   1332         }
   1333     }
   1334 
   1335     /**
   1336      * @return true if the current device is "voice capable".
   1337      * <p>
   1338      * "Voice capable" means that this device supports circuit-switched
   1339      * (i.e. voice) phone calls over the telephony network, and is allowed
   1340      * to display the in-call UI while a cellular voice call is active.
   1341      * This will be false on "data only" devices which can't make voice
   1342      * calls and don't support any in-call UI.
   1343      * <p>
   1344      * Note: the meaning of this flag is subtly different from the
   1345      * PackageManager.FEATURE_TELEPHONY system feature, which is available
   1346      * on any device with a telephony radio, even if the device is
   1347      * data-only.
   1348      *
   1349      * @hide pending API review
   1350      */
   1351     public boolean isVoiceCapable() {
   1352         if (mContext == null) return true;
   1353         return mContext.getResources().getBoolean(
   1354                 com.android.internal.R.bool.config_voice_capable);
   1355     }
   1356 
   1357     /**
   1358      * @return true if the current device supports sms service.
   1359      * <p>
   1360      * If true, this means that the device supports both sending and
   1361      * receiving sms via the telephony network.
   1362      * <p>
   1363      * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are
   1364      *       disabled when device doesn't support sms.
   1365      *
   1366      * @hide pending API review
   1367      */
   1368     public boolean isSmsCapable() {
   1369         if (mContext == null) return true;
   1370         return mContext.getResources().getBoolean(
   1371                 com.android.internal.R.bool.config_sms_capable);
   1372     }
   1373 
   1374     /**
   1375      * Returns all observed cell information from all radios on the
   1376      * device including the primary and neighboring cells. This does
   1377      * not cause or change the rate of PhoneStateListner#onCellInfoChanged.
   1378      *<p>
   1379      * The list can include one or more of {@link android.telephony.CellInfoGsm CellInfoGsm},
   1380      * {@link android.telephony.CellInfoCdma CellInfoCdma},
   1381      * {@link android.telephony.CellInfoLte CellInfoLte} and
   1382      * {@link android.telephony.CellInfoWcdma CellInfoCdma} in any combination.
   1383      * Specifically on devices with multiple radios it is typical to see instances of
   1384      * one or more of any these in the list. In addition 0, 1 or more CellInfo
   1385      * objects may return isRegistered() true.
   1386      *<p>
   1387      * This is preferred over using getCellLocation although for older
   1388      * devices this may return null in which case getCellLocation should
   1389      * be called.
   1390      *<p>
   1391      * @return List of CellInfo or null if info unavailable.
   1392      *
   1393      * <p>Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}
   1394      */
   1395     public List<CellInfo> getAllCellInfo() {
   1396         try {
   1397             return getITelephony().getAllCellInfo();
   1398         } catch (RemoteException ex) {
   1399             return null;
   1400         } catch (NullPointerException ex) {
   1401             return null;
   1402         }
   1403     }
   1404 
   1405     /**
   1406      * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged
   1407      * PhoneStateListener.onCellInfoChanged} will be invoked.
   1408      *<p>
   1409      * The default, 0, means invoke onCellInfoChanged when any of the reported
   1410      * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue
   1411      * A onCellInfoChanged.
   1412      *<p>
   1413      * @param rateInMillis the rate
   1414      *
   1415      * @hide
   1416      */
   1417     public void setCellInfoListRate(int rateInMillis) {
   1418         try {
   1419             getITelephony().setCellInfoListRate(rateInMillis);
   1420         } catch (RemoteException ex) {
   1421         } catch (NullPointerException ex) {
   1422         }
   1423     }
   1424 
   1425     /**
   1426      * Returns the MMS user agent.
   1427      */
   1428     public String getMmsUserAgent() {
   1429         if (mContext == null) return null;
   1430         return mContext.getResources().getString(
   1431                 com.android.internal.R.string.config_mms_user_agent);
   1432     }
   1433 
   1434     /**
   1435      * Returns the MMS user agent profile URL.
   1436      */
   1437     public String getMmsUAProfUrl() {
   1438         if (mContext == null) return null;
   1439         return mContext.getResources().getString(
   1440                 com.android.internal.R.string.config_mms_user_agent_profile_url);
   1441     }
   1442 }
   1443