TelephonyManager.java revision ce099c3226b33b43e0dd5d1f24347b14a2223ee1
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.Phone;
31import com.android.internal.telephony.PhoneFactory;
32import com.android.internal.telephony.RILConstants;
33import com.android.internal.telephony.TelephonyProperties;
34
35import java.util.List;
36
37/**
38 * Provides access to information about the telephony services on
39 * the device. Applications can use the methods in this class to
40 * determine telephony services and states, as well as to access some
41 * types of subscriber information. Applications can also register
42 * a listener to receive notification of telephony state changes.
43 * <p>
44 * You do not instantiate this class directly; instead, you retrieve
45 * a reference to an instance through
46 * {@link android.content.Context#getSystemService
47 * Context.getSystemService(Context.TELEPHONY_SERVICE)}.
48 * <p>
49 * Note that acess to some telephony information is
50 * permission-protected. Your application cannot access the protected
51 * information unless it has the appropriate permissions declared in
52 * its manifest file. Where permissions apply, they are noted in the
53 * the methods through which you access the protected information.
54 */
55public class TelephonyManager {
56    private static final String TAG = "TelephonyManager";
57
58    private Context mContext;
59    private ITelephonyRegistry mRegistry;
60
61    /** @hide */
62    public TelephonyManager(Context context) {
63        mContext = context;
64        mRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService(
65                    "telephony.registry"));
66    }
67
68    /** @hide */
69    private TelephonyManager() {
70    }
71
72    private static TelephonyManager sInstance = new TelephonyManager();
73
74    /** @hide */
75    public static TelephonyManager getDefault() {
76        return sInstance;
77    }
78
79
80    //
81    // Broadcast Intent actions
82    //
83
84    /**
85     * Broadcast intent action indicating that the call state (cellular)
86     * on the device has changed.
87     *
88     * <p>
89     * The {@link #EXTRA_STATE} extra indicates the new call state.
90     * If the new state is RINGING, a second extra
91     * {@link #EXTRA_INCOMING_NUMBER} provides the incoming phone number as
92     * a String.
93     *
94     * <p class="note">
95     * Requires the READ_PHONE_STATE permission.
96     *
97     * <p class="note">
98     * This was a {@link android.content.Context#sendStickyBroadcast sticky}
99     * broadcast in version 1.0, but it is no longer sticky.
100     * Instead, use {@link #getCallState} to synchronously query the current call state.
101     *
102     * @see #EXTRA_STATE
103     * @see #EXTRA_INCOMING_NUMBER
104     * @see #getCallState
105     */
106    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
107    public static final String ACTION_PHONE_STATE_CHANGED =
108            "android.intent.action.PHONE_STATE";
109
110    /**
111     * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast
112     * for a String containing the new call state.
113     *
114     * @see #EXTRA_STATE_IDLE
115     * @see #EXTRA_STATE_RINGING
116     * @see #EXTRA_STATE_OFFHOOK
117     *
118     * <p class="note">
119     * Retrieve with
120     * {@link android.content.Intent#getStringExtra(String)}.
121     */
122    public static final String EXTRA_STATE = Phone.STATE_KEY;
123
124    /**
125     * Value used with {@link #EXTRA_STATE} corresponding to
126     * {@link #CALL_STATE_IDLE}.
127     */
128    public static final String EXTRA_STATE_IDLE = Phone.State.IDLE.toString();
129
130    /**
131     * Value used with {@link #EXTRA_STATE} corresponding to
132     * {@link #CALL_STATE_RINGING}.
133     */
134    public static final String EXTRA_STATE_RINGING = Phone.State.RINGING.toString();
135
136    /**
137     * Value used with {@link #EXTRA_STATE} corresponding to
138     * {@link #CALL_STATE_OFFHOOK}.
139     */
140    public static final String EXTRA_STATE_OFFHOOK = Phone.State.OFFHOOK.toString();
141
142    /**
143     * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast
144     * for a String containing the incoming phone number.
145     * Only valid when the new call state is RINGING.
146     *
147     * <p class="note">
148     * Retrieve with
149     * {@link android.content.Intent#getStringExtra(String)}.
150     */
151    public static final String EXTRA_INCOMING_NUMBER = "incoming_number";
152
153
154    //
155    //
156    // Device Info
157    //
158    //
159
160    /**
161     * Returns the software version number for the device, for example,
162     * the IMEI/SV for GSM phones.
163     *
164     * <p>Requires Permission:
165     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
166     */
167    public String getDeviceSoftwareVersion() {
168        try {
169            return getSubscriberInfo().getDeviceSvn();
170        } catch (RemoteException ex) {
171        }
172        return null;
173    }
174
175    /**
176     * Returns the unique device ID, for example, the IMEI for GSM and the MEID for CDMA
177     * phones.
178     *
179     * <p>Requires Permission:
180     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
181     */
182    public String getDeviceId() {
183        try {
184            return getSubscriberInfo().getDeviceId();
185        } catch (RemoteException ex) {
186        }
187        return null;
188    }
189
190    /**
191     * Returns the current location of the device.
192     *
193     * <p>Requires Permission:
194     * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or
195     * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION}.
196     */
197    public CellLocation getCellLocation() {
198        try {
199            Bundle bundle = getITelephony().getCellLocation();
200            return CellLocation.newFromBundle(bundle);
201        } catch (RemoteException ex) {
202        }
203        return null;
204    }
205
206    /**
207     * Enables location update notifications.  {@link PhoneStateListener#onCellLocationChanged
208     * PhoneStateListener.onCellLocationChanged} will be called on location updates.
209     *
210     * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES
211     * CONTROL_LOCATION_UPDATES}
212     *
213     * @hide
214     */
215    public void enableLocationUpdates() {
216        try {
217            getITelephony().enableLocationUpdates();
218        } catch (RemoteException ex) {
219        }
220    }
221
222    /**
223     * Disables location update notifications.  {@link PhoneStateListener#onCellLocationChanged
224     * PhoneStateListener.onCellLocationChanged} will be called on location updates.
225     *
226     * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES
227     * CONTROL_LOCATION_UPDATES}
228     *
229     * @hide
230     */
231    public void disableLocationUpdates() {
232        try {
233            getITelephony().disableLocationUpdates();
234        } catch (RemoteException ex) {
235        }
236    }
237
238    /**
239     * Returns the neighboring cell information of the device.
240     *
241     * @return List of NeighboringCellInfo or null if info unavailable.
242     *
243     * <p>Requires Permission:
244     * (@link android.Manifest.permission#ACCESS_COARSE_UPDATES}
245     */
246    public List<NeighboringCellInfo> getNeighboringCellInfo() {
247       try {
248           return getITelephony().getNeighboringCellInfo();
249       } catch (RemoteException ex) {
250       }
251       return null;
252
253    }
254
255    /**
256     * No phone module
257     *
258     */
259    public static final int PHONE_TYPE_NONE = 0;
260
261    /**
262     * GSM phone
263     */
264    public static final int PHONE_TYPE_GSM = RILConstants.GSM_PHONE;
265
266    /**
267     * CDMA phone
268     * @hide
269     */
270    public static final int PHONE_TYPE_CDMA = RILConstants.CDMA_PHONE;
271
272    /**
273     * Returns a constant indicating the device phone type.
274     *
275     * @see #PHONE_TYPE_NONE
276     * @see #PHONE_TYPE_GSM
277     * @see #PHONE_TYPE_CDMA
278     */
279    public int getPhoneType() {
280        try{
281            ITelephony telephony = getITelephony();
282            if (telephony != null) {
283                if(telephony.getActivePhoneType() == RILConstants.CDMA_PHONE) {
284                    return PHONE_TYPE_CDMA;
285                } else {
286                    return PHONE_TYPE_GSM;
287                }
288            } else {
289                // This can happen when the ITelephony interface is not up yet.
290                return getPhoneTypeFromProperty();
291            }
292        } catch(RemoteException ex){
293            // This shouldn't happen in the normal case, as a backup we
294            // read from the system property.
295            return getPhoneTypeFromProperty();
296        }
297    }
298
299
300    private int getPhoneTypeFromProperty() {
301        int type =
302            SystemProperties.getInt(TelephonyProperties.CURRENT_ACTIVE_PHONE,
303                    getPhoneTypeFromNetworkType());
304        return type;
305    }
306
307    private int getPhoneTypeFromNetworkType() {
308        // When the system property CURRENT_ACTIVE_PHONE, has not been set,
309        // use the system property for default network type.
310        // This is a fail safe, and can only happen at first boot.
311        int mode = SystemProperties.getInt("ro.telephony.default_network", -1);
312        if (mode == -1)
313            return PHONE_TYPE_NONE;
314        return PhoneFactory.getPhoneType(mode);
315    }
316    //
317    //
318    // Current Network
319    //
320    //
321
322    /**
323     * Returns the alphabetic name of current registered operator.
324     * <p>
325     * Availability: Only when user is registered to a network
326     */
327    public String getNetworkOperatorName() {
328        return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ALPHA);
329    }
330
331    /**
332     * Returns the numeric name (MCC+MNC) of current registered operator.
333     * <p>
334     * Availability: Only when user is registered to a network
335     */
336    public String getNetworkOperator() {
337        return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC);
338    }
339
340    /**
341     * Returns true if the device is considered roaming on the current
342     * network, for GSM purposes.
343     * <p>
344     * Availability: Only when user registered to a network
345     */
346    public boolean isNetworkRoaming() {
347        return "true".equals(SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ISROAMING));
348    }
349
350    /**
351     * Returns the ISO country code equivilent of the current registered
352     * operator's MCC (Mobile Country Code).
353     * <p>
354     * Availability: Only when user is registered to a network
355     */
356    public String getNetworkCountryIso() {
357        return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY);
358    }
359
360    /** Network type is unknown */
361    public static final int NETWORK_TYPE_UNKNOWN = 0;
362    /** Current network is GPRS */
363    public static final int NETWORK_TYPE_GPRS = 1;
364    /** Current network is EDGE */
365    public static final int NETWORK_TYPE_EDGE = 2;
366    /** Current network is UMTS */
367    public static final int NETWORK_TYPE_UMTS = 3;
368    /** Current network is CDMA: Either IS95A or IS95B*/
369    /** @hide */
370    public static final int NETWORK_TYPE_CDMA = 4;
371    /** Current network is EVDO revision 0 or revision A*/
372    /** @hide */
373    public static final int NETWORK_TYPE_EVDO_0 = 5;
374    /** @hide */
375    public static final int NETWORK_TYPE_EVDO_A = 6;
376    /** Current network is 1xRTT*/
377    /** @hide */
378    public static final int NETWORK_TYPE_1xRTT = 7;
379
380    /**
381     * Returns a constant indicating the radio technology (network type)
382     * currently in use on the device.
383     * @return the network type
384     *
385     * @see #NETWORK_TYPE_UNKNOWN
386     * @see #NETWORK_TYPE_GPRS
387     * @see #NETWORK_TYPE_EDGE
388     * @see #NETWORK_TYPE_UMTS
389     * @see #NETWORK_TYPE_CDMA
390     * @see #NETWORK_TYPE_EVDO_0
391     * @see #NETWORK_TYPE_EVDO_A
392     * @see #NETWORK_TYPE_1xRTT
393     */
394    public int getNetworkType() {
395        String prop = SystemProperties.get(TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE);
396        if ("GPRS".equals(prop)) {
397            return NETWORK_TYPE_GPRS;
398        }
399        else if ("EDGE".equals(prop)) {
400            return NETWORK_TYPE_EDGE;
401        }
402        else if ("UMTS".equals(prop)) {
403            return NETWORK_TYPE_UMTS;
404        }
405        else if ("CDMA".equals(prop)) {
406            return NETWORK_TYPE_CDMA;
407                }
408        else if ("CDMA - EvDo rev. 0".equals(prop)) {
409            return NETWORK_TYPE_EVDO_0;
410            }
411        else if ("CDMA - EvDo rev. A".equals(prop)) {
412            return NETWORK_TYPE_EVDO_A;
413            }
414        else if ("CDMA - 1xRTT".equals(prop)) {
415            return NETWORK_TYPE_1xRTT;
416            }
417        else {
418            return NETWORK_TYPE_UNKNOWN;
419        }
420    }
421
422    /**
423     * Returns a string representation of the radio technology (network type)
424     * currently in use on the device.
425     * @return the name of the radio technology
426     *
427     * @hide pending API council review
428     */
429    public String getNetworkTypeName() {
430        switch (getNetworkType()) {
431            case NETWORK_TYPE_GPRS:
432                return "GPRS";
433            case NETWORK_TYPE_EDGE:
434                return "EDGE";
435            case NETWORK_TYPE_UMTS:
436                return "UMTS";
437            case NETWORK_TYPE_CDMA:
438                return "CDMA";
439            case NETWORK_TYPE_EVDO_0:
440                return "CDMA - EvDo rev. 0";
441            case NETWORK_TYPE_EVDO_A:
442                return "CDMA - EvDo rev. A";
443            case NETWORK_TYPE_1xRTT:
444                return "CDMA - 1xRTT";
445            default:
446                return "UNKNOWN";
447        }
448    }
449
450    //
451    //
452    // SIM Card
453    //
454    //
455
456    /** SIM card state: Unknown. Signifies that the SIM is in transition
457     *  between states. For example, when the user inputs the SIM pin
458     *  under PIN_REQUIRED state, a query for sim status returns
459     *  this state before turning to SIM_STATE_READY. */
460    public static final int SIM_STATE_UNKNOWN = 0;
461    /** SIM card state: no SIM card is available in the device */
462    public static final int SIM_STATE_ABSENT = 1;
463    /** SIM card state: Locked: requires the user's SIM PIN to unlock */
464    public static final int SIM_STATE_PIN_REQUIRED = 2;
465    /** SIM card state: Locked: requires the user's SIM PUK to unlock */
466    public static final int SIM_STATE_PUK_REQUIRED = 3;
467    /** SIM card state: Locked: requries a network PIN to unlock */
468    public static final int SIM_STATE_NETWORK_LOCKED = 4;
469    /** SIM card state: Ready */
470    public static final int SIM_STATE_READY = 5;
471
472    /**
473     * Returns a constant indicating the state of the
474     * device SIM card.
475     *
476     * @see #SIM_STATE_UNKNOWN
477     * @see #SIM_STATE_ABSENT
478     * @see #SIM_STATE_PIN_REQUIRED
479     * @see #SIM_STATE_PUK_REQUIRED
480     * @see #SIM_STATE_NETWORK_LOCKED
481     * @see #SIM_STATE_READY
482     */
483    public int getSimState() {
484        String prop = SystemProperties.get(TelephonyProperties.PROPERTY_SIM_STATE);
485        if ("ABSENT".equals(prop)) {
486            return SIM_STATE_ABSENT;
487        }
488        else if ("PIN_REQUIRED".equals(prop)) {
489            return SIM_STATE_PIN_REQUIRED;
490        }
491        else if ("PUK_REQUIRED".equals(prop)) {
492            return SIM_STATE_PUK_REQUIRED;
493        }
494        else if ("NETWORK_LOCKED".equals(prop)) {
495            return SIM_STATE_NETWORK_LOCKED;
496        }
497        else if ("READY".equals(prop)) {
498            return SIM_STATE_READY;
499        }
500        else {
501            return SIM_STATE_UNKNOWN;
502        }
503    }
504
505    /**
506     * Returns the MCC+MNC (mobile country code + mobile network code) of the
507     * provider of the SIM. 5 or 6 decimal digits.
508     * <p>
509     * Availability: SIM state must be {@link #SIM_STATE_READY}
510     *
511     * @see #getSimState
512     */
513    public String getSimOperator() {
514        return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC);
515    }
516
517    /**
518     * Returns the Service Provider Name (SPN).
519     * <p>
520     * Availability: SIM state must be {@link #SIM_STATE_READY}
521     *
522     * @see #getSimState
523     */
524    public String getSimOperatorName() {
525        return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA);
526    }
527
528    /**
529     * Returns the ISO country code equivalent for the SIM provider's country code.
530     */
531    public String getSimCountryIso() {
532        return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY);
533    }
534
535    /**
536     * Returns the serial number of the SIM, if applicable.
537     * <p>
538     * Requires Permission:
539     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
540     */
541    public String getSimSerialNumber() {
542        try {
543            return getSubscriberInfo().getIccSerialNumber();
544        } catch (RemoteException ex) {
545        }
546        return null;
547    }
548
549    //
550    //
551    // Subscriber Info
552    //
553    //
554
555    /**
556     * Returns the unique subscriber ID, for example, the IMSI for a GSM phone.
557     * <p>
558     * Requires Permission:
559     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
560     */
561    public String getSubscriberId() {
562        try {
563            return getSubscriberInfo().getSubscriberId();
564        } catch (RemoteException ex) {
565        }
566        return null;
567    }
568
569    /**
570     * Returns the phone number string for line 1, for example, the MSISDN
571     * for a GSM phone.
572     * <p>
573     * Requires Permission:
574     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
575     */
576    public String getLine1Number() {
577        try {
578            return getSubscriberInfo().getLine1Number();
579        } catch (RemoteException ex) {
580        }
581        return null;
582    }
583
584    /**
585     * Returns the alphabetic identifier associated with the line 1 number.
586     * <p>
587     * Requires Permission:
588     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
589     * @hide
590     * nobody seems to call this.
591     */
592    public String getLine1AlphaTag() {
593        try {
594            return getSubscriberInfo().getLine1AlphaTag();
595        } catch (RemoteException ex) {
596        }
597        return null;
598    }
599
600    /**
601     * Returns the voice mail number.
602     * <p>
603     * Requires Permission:
604     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
605     */
606    public String getVoiceMailNumber() {
607        try {
608            return getSubscriberInfo().getVoiceMailNumber();
609        } catch (RemoteException ex) {
610        }
611        return null;
612    }
613
614    /**
615     * Returns the voice mail count.
616     * <p>
617     * Requires Permission:
618     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
619     * @hide
620     */
621    public int getVoiceMessageCount() {
622        try {
623            return getITelephony().getVoiceMessageCount();
624        } catch (RemoteException ex) {
625        }
626        return 0;
627    }
628
629    /**
630     * Retrieves the alphabetic identifier associated with the voice
631     * mail number.
632     * <p>
633     * Requires Permission:
634     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
635     */
636    public String getVoiceMailAlphaTag() {
637        try {
638            return getSubscriberInfo().getVoiceMailAlphaTag();
639        } catch (RemoteException ex) {
640        }
641        return null;
642    }
643
644    private IPhoneSubInfo getSubscriberInfo() {
645        // get it each time because that process crashes a lot
646        return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo"));
647    }
648
649
650    /** Device call state: No activity. */
651    public static final int CALL_STATE_IDLE = 0;
652    /** Device call state: Ringing. A new call arrived and is
653     *  ringing or waiting. In the latter case, another call is
654     *  already active. */
655    public static final int CALL_STATE_RINGING = 1;
656    /** Device call state: Off-hook. At least one call exists
657      * that is dialing, active, or on hold, and no calls are ringing
658      * or waiting. */
659    public static final int CALL_STATE_OFFHOOK = 2;
660
661    /**
662     * Returns a constant indicating the call state (cellular) on the device.
663     */
664    public int getCallState() {
665        try {
666            return getITelephony().getCallState();
667        } catch (RemoteException ex) {
668            // the phone process is restarting.
669            return CALL_STATE_IDLE;
670        }
671    }
672
673    /** Data connection activity: No traffic. */
674    public static final int DATA_ACTIVITY_NONE = 0x00000000;
675    /** Data connection activity: Currently receiving IP PPP traffic. */
676    public static final int DATA_ACTIVITY_IN = 0x00000001;
677    /** Data connection activity: Currently sending IP PPP traffic. */
678    public static final int DATA_ACTIVITY_OUT = 0x00000002;
679    /** Data connection activity: Currently both sending and receiving
680     *  IP PPP traffic. */
681    public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT;
682    /**
683     * Data connection is active, but physical link is down
684     * @hide
685     */
686    public static final int DATA_ACTIVITY_DORMANT = 0x00000004;
687
688    /**
689     * Returns a constant indicating the type of activity on a data connection
690     * (cellular).
691     *
692     * @see #DATA_ACTIVITY_NONE
693     * @see #DATA_ACTIVITY_IN
694     * @see #DATA_ACTIVITY_OUT
695     * @see #DATA_ACTIVITY_INOUT
696     * @see #DATA_ACTIVITY_DORMANT
697     */
698    public int getDataActivity() {
699        try {
700            return getITelephony().getDataActivity();
701        } catch (RemoteException ex) {
702            // the phone process is restarting.
703            return DATA_ACTIVITY_NONE;
704        }
705    }
706
707    /** Data connection state: Disconnected. IP traffic not available. */
708    public static final int DATA_DISCONNECTED   = 0;
709    /** Data connection state: Currently setting up a data connection. */
710    public static final int DATA_CONNECTING     = 1;
711    /** Data connection state: Connected. IP traffic should be available. */
712    public static final int DATA_CONNECTED      = 2;
713    /** Data connection state: Suspended. The connection is up, but IP
714     * traffic is temporarily unavailable. For example, in a 2G network,
715     * data activity may be suspended when a voice call arrives. */
716    public static final int DATA_SUSPENDED      = 3;
717
718    /**
719     * Returns a constant indicating the current data connection state
720     * (cellular).
721     *
722     * @see #DATA_DISCONNECTED
723     * @see #DATA_CONNECTING
724     * @see #DATA_CONNECTED
725     * @see #DATA_SUSPENDED
726     */
727    public int getDataState() {
728        try {
729            return getITelephony().getDataState();
730        } catch (RemoteException ex) {
731            // the phone process is restarting.
732            return DATA_DISCONNECTED;
733        }
734    }
735
736    private ITelephony getITelephony() {
737        return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE));
738    }
739
740    //
741    //
742    // PhoneStateListener
743    //
744    //
745
746    /**
747     * Registers a listener object to receive notification of changes
748     * in specified telephony states.
749     * <p>
750     * To register a listener, pass a {@link PhoneStateListener}
751     * and specify at least one telephony state of interest in
752     * the events argument.
753     *
754     * At registration, and when a specified telephony state
755     * changes, the telephony manager invokes the appropriate
756     * callback method on the listener object and passes the
757     * current (udpated) values.
758     * <p>
759     * To unregister a listener, pass the listener object and set the
760     * events argument to
761     * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0).
762     *
763     * @param listener The {@link PhoneStateListener} object to register
764     *                 (or unregister)
765     * @param events The telephony state(s) of interest to the listener,
766     *               as a bitwise-OR combination of {@link PhoneStateListener}
767     *               LISTEN_ flags.
768     */
769    public void listen(PhoneStateListener listener, int events) {
770        String pkgForDebug = mContext != null ? mContext.getPackageName() : "<unknown>";
771        try {
772            Boolean notifyNow = (getITelephony() != null);
773            mRegistry.listen(pkgForDebug, listener.callback, events, notifyNow);
774        } catch (RemoteException ex) {
775            // system process dead
776        }
777    }
778
779    /**
780     * Returns the CDMA ERI icon index to display
781     *
782     * @hide
783     */
784    public int getCdmaEriIconIndex() {
785        try {
786            return getITelephony().getCdmaEriIconIndex();
787        } catch (RemoteException ex) {
788            // the phone process is restarting.
789            return -1;
790        }
791    }
792
793    /**
794     * Returns the CDMA ERI icon mode,
795     * 0 - ON
796     * 1 - FLASHING
797     *
798     * @hide
799     */
800    public int getCdmaEriIconMode() {
801        try {
802            return getITelephony().getCdmaEriIconMode();
803        } catch (RemoteException ex) {
804            // the phone process is restarting.
805            return -1;
806        }
807    }
808
809    /**
810     * Returns the CDMA ERI text,
811     *
812     * @hide
813     */
814    public String getCdmaEriText() {
815        try {
816            return getITelephony().getCdmaEriText();
817        } catch (RemoteException ex) {
818            // the phone process is restarting.
819            return null;
820        }
821    }
822}
823