TelephonyManager.java revision e40f66ffc11cfc7e1bbe3e4c2ae1cf6dbc24cc17
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 = RILConstants.NO_PHONE;
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. Result may be
326     * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
327     * on a CDMA network).
328     */
329    public String getNetworkOperatorName() {
330        return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ALPHA);
331    }
332
333    /**
334     * Returns the numeric name (MCC+MNC) of current registered operator.
335     * <p>
336     * Availability: Only when user is registered to a network. Result may be
337     * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
338     * on a CDMA network).
339     */
340    public String getNetworkOperator() {
341        return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC);
342    }
343
344    /**
345     * Returns true if the device is considered roaming on the current
346     * network, for GSM purposes.
347     * <p>
348     * Availability: Only when user registered to a network.
349     */
350    public boolean isNetworkRoaming() {
351        return "true".equals(SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ISROAMING));
352    }
353
354    /**
355     * Returns the ISO country code equivilent of the current registered
356     * operator's MCC (Mobile Country Code).
357     * <p>
358     * Availability: Only when user is registered to a network. Result may be
359     * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
360     * on a CDMA network).
361     */
362    public String getNetworkCountryIso() {
363        return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY);
364    }
365
366    /** Network type is unknown */
367    public static final int NETWORK_TYPE_UNKNOWN = 0;
368    /** Current network is GPRS */
369    public static final int NETWORK_TYPE_GPRS = 1;
370    /** Current network is EDGE */
371    public static final int NETWORK_TYPE_EDGE = 2;
372    /** Current network is UMTS */
373    public static final int NETWORK_TYPE_UMTS = 3;
374    /** Current network is CDMA: Either IS95A or IS95B*/
375    /** @hide */
376    public static final int NETWORK_TYPE_CDMA = 4;
377    /** Current network is EVDO revision 0 or revision A*/
378    /** @hide */
379    public static final int NETWORK_TYPE_EVDO_0 = 5;
380    /** @hide */
381    public static final int NETWORK_TYPE_EVDO_A = 6;
382    /** Current network is 1xRTT*/
383    /** @hide */
384    public static final int NETWORK_TYPE_1xRTT = 7;
385    /** Current network is HSDPA */
386    /** @hide */
387    public static final int NETWORK_TYPE_HSDPA = 8;
388    /** Current network is HSUPA */
389    /** @hide */
390    public static final int NETWORK_TYPE_HSUPA = 9;
391    /** Current network is HSPA */
392    /** @hide */
393    public static final int NETWORK_TYPE_HSPA = 10;
394
395    /**
396     * Returns a constant indicating the radio technology (network type)
397     * currently in use on the device.
398     * @return the network type
399     *
400     * @see #NETWORK_TYPE_UNKNOWN
401     * @see #NETWORK_TYPE_GPRS
402     * @see #NETWORK_TYPE_EDGE
403     * @see #NETWORK_TYPE_UMTS
404     * @see #NETWORK_TYPE_HSDPA
405     * @see #NETWORK_TYPE_HSUPA
406     * @see #NETWORK_TYPE_HSPA
407     * @see #NETWORK_TYPE_CDMA
408     * @see #NETWORK_TYPE_EVDO_0
409     * @see #NETWORK_TYPE_EVDO_A
410     * @see #NETWORK_TYPE_1xRTT
411     */
412    public int getNetworkType() {
413        try{
414            ITelephony telephony = getITelephony();
415            if (telephony != null) {
416                return telephony.getNetworkType();
417            } else {
418                // This can happen when the ITelephony interface is not up yet.
419                return NETWORK_TYPE_UNKNOWN;
420            }
421        } catch(RemoteException ex){
422            // This shouldn't happen in the normal case
423            return NETWORK_TYPE_UNKNOWN;
424        }
425    }
426
427    /**
428     * Returns a string representation of the radio technology (network type)
429     * currently in use on the device.
430     * @return the name of the radio technology
431     *
432     * @hide pending API council review
433     */
434    public String getNetworkTypeName() {
435        switch (getNetworkType()) {
436            case NETWORK_TYPE_GPRS:
437                return "GPRS";
438            case NETWORK_TYPE_EDGE:
439                return "EDGE";
440            case NETWORK_TYPE_UMTS:
441                return "UMTS";
442            case NETWORK_TYPE_HSDPA:
443                return "HSDPA";
444            case NETWORK_TYPE_HSUPA:
445                return "HSUPA";
446            case NETWORK_TYPE_HSPA:
447                return "HSPA";
448            case NETWORK_TYPE_CDMA:
449                return "CDMA";
450            case NETWORK_TYPE_EVDO_0:
451                return "CDMA - EvDo rev. 0";
452            case NETWORK_TYPE_EVDO_A:
453                return "CDMA - EvDo rev. A";
454            case NETWORK_TYPE_1xRTT:
455                return "CDMA - 1xRTT";
456            default:
457                return "UNKNOWN";
458        }
459    }
460
461    //
462    //
463    // SIM Card
464    //
465    //
466
467    /** SIM card state: Unknown. Signifies that the SIM is in transition
468     *  between states. For example, when the user inputs the SIM pin
469     *  under PIN_REQUIRED state, a query for sim status returns
470     *  this state before turning to SIM_STATE_READY. */
471    public static final int SIM_STATE_UNKNOWN = 0;
472    /** SIM card state: no SIM card is available in the device */
473    public static final int SIM_STATE_ABSENT = 1;
474    /** SIM card state: Locked: requires the user's SIM PIN to unlock */
475    public static final int SIM_STATE_PIN_REQUIRED = 2;
476    /** SIM card state: Locked: requires the user's SIM PUK to unlock */
477    public static final int SIM_STATE_PUK_REQUIRED = 3;
478    /** SIM card state: Locked: requries a network PIN to unlock */
479    public static final int SIM_STATE_NETWORK_LOCKED = 4;
480    /** SIM card state: Ready */
481    public static final int SIM_STATE_READY = 5;
482
483    /**
484     * @return true if a ICC card is present
485     */
486    public boolean hasIccCard() {
487        try {
488            return getITelephony().hasIccCard();
489        } catch (RemoteException ex) {
490            // Assume no ICC card if remote exception which shouldn't happen
491            return false;
492        }
493    }
494
495    /**
496     * Returns a constant indicating the state of the
497     * device SIM card.
498     *
499     * @see #SIM_STATE_UNKNOWN
500     * @see #SIM_STATE_ABSENT
501     * @see #SIM_STATE_PIN_REQUIRED
502     * @see #SIM_STATE_PUK_REQUIRED
503     * @see #SIM_STATE_NETWORK_LOCKED
504     * @see #SIM_STATE_READY
505     */
506    public int getSimState() {
507        String prop = SystemProperties.get(TelephonyProperties.PROPERTY_SIM_STATE);
508        if ("ABSENT".equals(prop)) {
509            return SIM_STATE_ABSENT;
510        }
511        else if ("PIN_REQUIRED".equals(prop)) {
512            return SIM_STATE_PIN_REQUIRED;
513        }
514        else if ("PUK_REQUIRED".equals(prop)) {
515            return SIM_STATE_PUK_REQUIRED;
516        }
517        else if ("NETWORK_LOCKED".equals(prop)) {
518            return SIM_STATE_NETWORK_LOCKED;
519        }
520        else if ("READY".equals(prop)) {
521            return SIM_STATE_READY;
522        }
523        else {
524            return SIM_STATE_UNKNOWN;
525        }
526    }
527
528    /**
529     * Returns the MCC+MNC (mobile country code + mobile network code) of the
530     * provider of the SIM. 5 or 6 decimal digits.
531     * <p>
532     * Availability: SIM state must be {@link #SIM_STATE_READY}
533     *
534     * @see #getSimState
535     */
536    public String getSimOperator() {
537        return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC);
538    }
539
540    /**
541     * Returns the Service Provider Name (SPN).
542     * <p>
543     * Availability: SIM state must be {@link #SIM_STATE_READY}
544     *
545     * @see #getSimState
546     */
547    public String getSimOperatorName() {
548        return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA);
549    }
550
551    /**
552     * Returns the ISO country code equivalent for the SIM provider's country code.
553     */
554    public String getSimCountryIso() {
555        return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY);
556    }
557
558    /**
559     * Returns the serial number of the SIM, if applicable.
560     * <p>
561     * Requires Permission:
562     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
563     */
564    public String getSimSerialNumber() {
565        try {
566            return getSubscriberInfo().getIccSerialNumber();
567        } catch (RemoteException ex) {
568        }
569        return null;
570    }
571
572    //
573    //
574    // Subscriber Info
575    //
576    //
577
578    /**
579     * Returns the unique subscriber ID, for example, the IMSI for a GSM phone.
580     * <p>
581     * Requires Permission:
582     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
583     */
584    public String getSubscriberId() {
585        try {
586            return getSubscriberInfo().getSubscriberId();
587        } catch (RemoteException ex) {
588        }
589        return null;
590    }
591
592    /**
593     * Returns the phone number string for line 1, for example, the MSISDN
594     * for a GSM phone.
595     * <p>
596     * Requires Permission:
597     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
598     */
599    public String getLine1Number() {
600        try {
601            return getSubscriberInfo().getLine1Number();
602        } catch (RemoteException ex) {
603        }
604        return null;
605    }
606
607    /**
608     * Returns the alphabetic identifier associated with the line 1 number.
609     * <p>
610     * Requires Permission:
611     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
612     * @hide
613     * nobody seems to call this.
614     */
615    public String getLine1AlphaTag() {
616        try {
617            return getSubscriberInfo().getLine1AlphaTag();
618        } catch (RemoteException ex) {
619        }
620        return null;
621    }
622
623    /**
624     * Returns the voice mail number.
625     * <p>
626     * Requires Permission:
627     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
628     */
629    public String getVoiceMailNumber() {
630        try {
631            return getSubscriberInfo().getVoiceMailNumber();
632        } catch (RemoteException ex) {
633        }
634        return null;
635    }
636
637    /**
638     * Returns the voice mail count.
639     * <p>
640     * Requires Permission:
641     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
642     * @hide
643     */
644    public int getVoiceMessageCount() {
645        try {
646            return getITelephony().getVoiceMessageCount();
647        } catch (RemoteException ex) {
648        }
649        return 0;
650    }
651
652    /**
653     * Retrieves the alphabetic identifier associated with the voice
654     * mail number.
655     * <p>
656     * Requires Permission:
657     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
658     */
659    public String getVoiceMailAlphaTag() {
660        try {
661            return getSubscriberInfo().getVoiceMailAlphaTag();
662        } catch (RemoteException ex) {
663        }
664        return null;
665    }
666
667    private IPhoneSubInfo getSubscriberInfo() {
668        // get it each time because that process crashes a lot
669        return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo"));
670    }
671
672
673    /** Device call state: No activity. */
674    public static final int CALL_STATE_IDLE = 0;
675    /** Device call state: Ringing. A new call arrived and is
676     *  ringing or waiting. In the latter case, another call is
677     *  already active. */
678    public static final int CALL_STATE_RINGING = 1;
679    /** Device call state: Off-hook. At least one call exists
680      * that is dialing, active, or on hold, and no calls are ringing
681      * or waiting. */
682    public static final int CALL_STATE_OFFHOOK = 2;
683
684    /**
685     * Returns a constant indicating the call state (cellular) on the device.
686     */
687    public int getCallState() {
688        try {
689            return getITelephony().getCallState();
690        } catch (RemoteException ex) {
691            // the phone process is restarting.
692            return CALL_STATE_IDLE;
693        } catch (NullPointerException ex) {
694          // the phone process is restarting.
695          return CALL_STATE_IDLE;
696      }
697    }
698
699    /** Data connection activity: No traffic. */
700    public static final int DATA_ACTIVITY_NONE = 0x00000000;
701    /** Data connection activity: Currently receiving IP PPP traffic. */
702    public static final int DATA_ACTIVITY_IN = 0x00000001;
703    /** Data connection activity: Currently sending IP PPP traffic. */
704    public static final int DATA_ACTIVITY_OUT = 0x00000002;
705    /** Data connection activity: Currently both sending and receiving
706     *  IP PPP traffic. */
707    public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT;
708    /**
709     * Data connection is active, but physical link is down
710     * @hide
711     */
712    public static final int DATA_ACTIVITY_DORMANT = 0x00000004;
713
714    /**
715     * Returns a constant indicating the type of activity on a data connection
716     * (cellular).
717     *
718     * @see #DATA_ACTIVITY_NONE
719     * @see #DATA_ACTIVITY_IN
720     * @see #DATA_ACTIVITY_OUT
721     * @see #DATA_ACTIVITY_INOUT
722     * @see #DATA_ACTIVITY_DORMANT
723     */
724    public int getDataActivity() {
725        try {
726            return getITelephony().getDataActivity();
727        } catch (RemoteException ex) {
728            // the phone process is restarting.
729            return DATA_ACTIVITY_NONE;
730        } catch (NullPointerException ex) {
731          // the phone process is restarting.
732          return DATA_ACTIVITY_NONE;
733      }
734    }
735
736    /** Data connection state: Disconnected. IP traffic not available. */
737    public static final int DATA_DISCONNECTED   = 0;
738    /** Data connection state: Currently setting up a data connection. */
739    public static final int DATA_CONNECTING     = 1;
740    /** Data connection state: Connected. IP traffic should be available. */
741    public static final int DATA_CONNECTED      = 2;
742    /** Data connection state: Suspended. The connection is up, but IP
743     * traffic is temporarily unavailable. For example, in a 2G network,
744     * data activity may be suspended when a voice call arrives. */
745    public static final int DATA_SUSPENDED      = 3;
746
747    /**
748     * Returns a constant indicating the current data connection state
749     * (cellular).
750     *
751     * @see #DATA_DISCONNECTED
752     * @see #DATA_CONNECTING
753     * @see #DATA_CONNECTED
754     * @see #DATA_SUSPENDED
755     */
756    public int getDataState() {
757        try {
758            return getITelephony().getDataState();
759        } catch (RemoteException ex) {
760            // the phone process is restarting.
761            return DATA_DISCONNECTED;
762        }
763    }
764
765    private ITelephony getITelephony() {
766        return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE));
767    }
768
769    //
770    //
771    // PhoneStateListener
772    //
773    //
774
775    /**
776     * Registers a listener object to receive notification of changes
777     * in specified telephony states.
778     * <p>
779     * To register a listener, pass a {@link PhoneStateListener}
780     * and specify at least one telephony state of interest in
781     * the events argument.
782     *
783     * At registration, and when a specified telephony state
784     * changes, the telephony manager invokes the appropriate
785     * callback method on the listener object and passes the
786     * current (udpated) values.
787     * <p>
788     * To unregister a listener, pass the listener object and set the
789     * events argument to
790     * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0).
791     *
792     * @param listener The {@link PhoneStateListener} object to register
793     *                 (or unregister)
794     * @param events The telephony state(s) of interest to the listener,
795     *               as a bitwise-OR combination of {@link PhoneStateListener}
796     *               LISTEN_ flags.
797     */
798    public void listen(PhoneStateListener listener, int events) {
799        String pkgForDebug = mContext != null ? mContext.getPackageName() : "<unknown>";
800        try {
801            Boolean notifyNow = (getITelephony() != null);
802            mRegistry.listen(pkgForDebug, listener.callback, events, notifyNow);
803        } catch (RemoteException ex) {
804            // system process dead
805        }
806    }
807
808    /**
809     * Returns the CDMA ERI icon index to display
810     *
811     * @hide
812     */
813    public int getCdmaEriIconIndex() {
814        try {
815            return getITelephony().getCdmaEriIconIndex();
816        } catch (RemoteException ex) {
817            // the phone process is restarting.
818            return -1;
819        }
820    }
821
822    /**
823     * Returns the CDMA ERI icon mode,
824     * 0 - ON
825     * 1 - FLASHING
826     *
827     * @hide
828     */
829    public int getCdmaEriIconMode() {
830        try {
831            return getITelephony().getCdmaEriIconMode();
832        } catch (RemoteException ex) {
833            // the phone process is restarting.
834            return -1;
835        }
836    }
837
838    /**
839     * Returns the CDMA ERI text,
840     *
841     * @hide
842     */
843    public String getCdmaEriText() {
844        try {
845            return getITelephony().getCdmaEriText();
846        } catch (RemoteException ex) {
847            // the phone process is restarting.
848            return null;
849        }
850    }
851}
852