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