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