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