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