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