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