TelephonyManager.java revision bc0272754df7a2fb71bf709a2a8a7c852ee69e5c
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.SystemApi;
20import android.annotation.SdkConstant;
21import android.annotation.SdkConstant.SdkConstantType;
22import android.content.Context;
23import android.content.Intent;
24import android.os.Bundle;
25import android.os.RemoteException;
26import android.os.ServiceManager;
27import android.os.SystemProperties;
28import android.util.Log;
29import android.util.Pair;
30
31import com.android.internal.telecomm.ITelecommService;
32import com.android.internal.telephony.IPhoneSubInfo;
33import com.android.internal.telephony.ITelephony;
34import com.android.internal.telephony.ITelephonyRegistry;
35import com.android.internal.telephony.PhoneConstants;
36import com.android.internal.telephony.RILConstants;
37import com.android.internal.telephony.TelephonyProperties;
38
39import java.io.FileInputStream;
40import java.io.IOException;
41import java.util.List;
42import java.util.regex.Matcher;
43import java.util.regex.Pattern;
44
45/**
46 * Provides access to information about the telephony services on
47 * the device. Applications can use the methods in this class to
48 * determine telephony services and states, as well as to access some
49 * types of subscriber information. Applications can also register
50 * a listener to receive notification of telephony state changes.
51 * <p>
52 * You do not instantiate this class directly; instead, you retrieve
53 * a reference to an instance through
54 * {@link android.content.Context#getSystemService
55 * Context.getSystemService(Context.TELEPHONY_SERVICE)}.
56 * <p>
57 * Note that access to some telephony information is
58 * permission-protected. Your application cannot access the protected
59 * information unless it has the appropriate permissions declared in
60 * its manifest file. Where permissions apply, they are noted in the
61 * the methods through which you access the protected information.
62 */
63public class TelephonyManager {
64    private static final String TAG = "TelephonyManager";
65
66    private static final String TELECOMM_SERVICE_NAME = "telecomm";
67
68    private static ITelephonyRegistry sRegistry;
69
70    /**
71     * The allowed states of Wi-Fi calling.
72     *
73     * @hide
74     */
75    public interface WifiCallingChoices {
76        /** Always use Wi-Fi calling */
77        static final int ALWAYS_USE = 0;
78        /** Ask the user whether to use Wi-Fi on every call */
79        static final int ASK_EVERY_TIME = 1;
80        /** Never use Wi-Fi calling */
81        static final int NEVER_USE = 2;
82    }
83
84    private final Context mContext;
85
86    private static String multiSimConfig =
87            SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG);
88
89    /** Enum indicating multisim variants
90     *  DSDS - Dual SIM Dual Standby
91     *  DSDA - Dual SIM Dual Active
92     *  TSTS - Triple SIM Triple Standby
93     **/
94    /** @hide */
95    public enum MultiSimVariants {
96        DSDS,
97        DSDA,
98        TSTS,
99        UNKNOWN
100    };
101
102    /** @hide */
103    public TelephonyManager(Context context) {
104        Context appContext = context.getApplicationContext();
105        if (appContext != null) {
106            mContext = appContext;
107        } else {
108            mContext = context;
109        }
110
111        if (sRegistry == null) {
112            sRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService(
113                    "telephony.registry"));
114        }
115    }
116
117    /** @hide */
118    private TelephonyManager() {
119        mContext = null;
120    }
121
122    private static TelephonyManager sInstance = new TelephonyManager();
123
124    /** @hide
125    /* @deprecated - use getSystemService as described above */
126    public static TelephonyManager getDefault() {
127        return sInstance;
128    }
129
130
131    /**
132     * Returns the multi SIM variant
133     * Returns DSDS for Dual SIM Dual Standby
134     * Returns DSDA for Dual SIM Dual Active
135     * Returns TSTS for Triple SIM Triple Standby
136     * Returns UNKNOWN for others
137     */
138    /** {@hide} */
139    public MultiSimVariants getMultiSimConfiguration() {
140        String mSimConfig =
141            SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG);
142        if (mSimConfig.equals("dsds")) {
143            return MultiSimVariants.DSDS;
144        } else if (mSimConfig.equals("dsda")) {
145            return MultiSimVariants.DSDA;
146        } else if (mSimConfig.equals("tsts")) {
147            return MultiSimVariants.TSTS;
148        } else {
149            return MultiSimVariants.UNKNOWN;
150        }
151    }
152
153
154    /**
155     * Returns the number of phones available.
156     * Returns 1 for Single standby mode (Single SIM functionality)
157     * Returns 2 for Dual standby mode.(Dual SIM functionality)
158     */
159    /** {@hide} */
160    public int getPhoneCount() {
161        int phoneCount = 1;
162        switch (getMultiSimConfiguration()) {
163            case DSDS:
164            case DSDA:
165                phoneCount = PhoneConstants.MAX_PHONE_COUNT_DUAL_SIM;
166                break;
167            case TSTS:
168                phoneCount = PhoneConstants.MAX_PHONE_COUNT_TRI_SIM;
169                break;
170        }
171        return phoneCount;
172    }
173
174    /** {@hide} */
175    public static TelephonyManager from(Context context) {
176        return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
177    }
178
179    /** {@hide} */
180    public boolean isMultiSimEnabled() {
181        return (multiSimConfig.equals("dsds") || multiSimConfig.equals("dsda") ||
182            multiSimConfig.equals("tsts"));
183    }
184
185    //
186    // Broadcast Intent actions
187    //
188
189    /**
190     * Broadcast intent action indicating that the call state (cellular)
191     * on the device has changed.
192     *
193     * <p>
194     * The {@link #EXTRA_STATE} extra indicates the new call state.
195     * If the new state is RINGING, a second extra
196     * {@link #EXTRA_INCOMING_NUMBER} provides the incoming phone number as
197     * a String.
198     *
199     * <p class="note">
200     * Requires the READ_PHONE_STATE permission.
201     *
202     * <p class="note">
203     * This was a {@link android.content.Context#sendStickyBroadcast sticky}
204     * broadcast in version 1.0, but it is no longer sticky.
205     * Instead, use {@link #getCallState} to synchronously query the current call state.
206     *
207     * @see #EXTRA_STATE
208     * @see #EXTRA_INCOMING_NUMBER
209     * @see #getCallState
210     */
211    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
212    public static final String ACTION_PHONE_STATE_CHANGED =
213            "android.intent.action.PHONE_STATE";
214
215    /**
216     * The Phone app sends this intent when a user opts to respond-via-message during an incoming
217     * call. By default, the device's default SMS app consumes this message and sends a text message
218     * to the caller. A third party app can also provide this functionality by consuming this Intent
219     * with a {@link android.app.Service} and sending the message using its own messaging system.
220     * <p>The intent contains a URI (available from {@link android.content.Intent#getData})
221     * describing the recipient, using either the {@code sms:}, {@code smsto:}, {@code mms:},
222     * or {@code mmsto:} URI schema. Each of these URI schema carry the recipient information the
223     * same way: the path part of the URI contains the recipient's phone number or a comma-separated
224     * set of phone numbers if there are multiple recipients. For example, {@code
225     * smsto:2065551234}.</p>
226     *
227     * <p>The intent may also contain extras for the message text (in {@link
228     * android.content.Intent#EXTRA_TEXT}) and a message subject
229     * (in {@link android.content.Intent#EXTRA_SUBJECT}).</p>
230     *
231     * <p class="note"><strong>Note:</strong>
232     * The intent-filter that consumes this Intent needs to be in a {@link android.app.Service}
233     * that requires the
234     * permission {@link android.Manifest.permission#SEND_RESPOND_VIA_MESSAGE}.</p>
235     * <p>For example, the service that receives this intent can be declared in the manifest file
236     * with an intent filter like this:</p>
237     * <pre>
238     * &lt;!-- Service that delivers SMS messages received from the phone "quick response" -->
239     * &lt;service android:name=".HeadlessSmsSendService"
240     *          android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
241     *          android:exported="true" >
242     *   &lt;intent-filter>
243     *     &lt;action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
244     *     &lt;category android:name="android.intent.category.DEFAULT" />
245     *     &lt;data android:scheme="sms" />
246     *     &lt;data android:scheme="smsto" />
247     *     &lt;data android:scheme="mms" />
248     *     &lt;data android:scheme="mmsto" />
249     *   &lt;/intent-filter>
250     * &lt;/service></pre>
251     * <p>
252     * Output: nothing.
253     */
254    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
255    public static final String ACTION_RESPOND_VIA_MESSAGE =
256            "android.intent.action.RESPOND_VIA_MESSAGE";
257
258    /**
259     * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast
260     * for a String containing the new call state.
261     *
262     * @see #EXTRA_STATE_IDLE
263     * @see #EXTRA_STATE_RINGING
264     * @see #EXTRA_STATE_OFFHOOK
265     *
266     * <p class="note">
267     * Retrieve with
268     * {@link android.content.Intent#getStringExtra(String)}.
269     */
270    public static final String EXTRA_STATE = PhoneConstants.STATE_KEY;
271
272    /**
273     * Value used with {@link #EXTRA_STATE} corresponding to
274     * {@link #CALL_STATE_IDLE}.
275     */
276    public static final String EXTRA_STATE_IDLE = PhoneConstants.State.IDLE.toString();
277
278    /**
279     * Value used with {@link #EXTRA_STATE} corresponding to
280     * {@link #CALL_STATE_RINGING}.
281     */
282    public static final String EXTRA_STATE_RINGING = PhoneConstants.State.RINGING.toString();
283
284    /**
285     * Value used with {@link #EXTRA_STATE} corresponding to
286     * {@link #CALL_STATE_OFFHOOK}.
287     */
288    public static final String EXTRA_STATE_OFFHOOK = PhoneConstants.State.OFFHOOK.toString();
289
290    /**
291     * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast
292     * for a String containing the incoming phone number.
293     * Only valid when the new call state is RINGING.
294     *
295     * <p class="note">
296     * Retrieve with
297     * {@link android.content.Intent#getStringExtra(String)}.
298     */
299    public static final String EXTRA_INCOMING_NUMBER = "incoming_number";
300
301    /**
302     * Broadcast intent action indicating that a precise call state
303     * (cellular) on the device has changed.
304     *
305     * <p>
306     * The {@link #EXTRA_RINGING_CALL_STATE} extra indicates the ringing call state.
307     * The {@link #EXTRA_FOREGROUND_CALL_STATE} extra indicates the foreground call state.
308     * The {@link #EXTRA_BACKGROUND_CALL_STATE} extra indicates the background call state.
309     * The {@link #EXTRA_DISCONNECT_CAUSE} extra indicates the disconnect cause.
310     * The {@link #EXTRA_PRECISE_DISCONNECT_CAUSE} extra indicates the precise disconnect cause.
311     *
312     * <p class="note">
313     * Requires the READ_PRECISE_PHONE_STATE permission.
314     *
315     * @see #EXTRA_RINGING_CALL_STATE
316     * @see #EXTRA_FOREGROUND_CALL_STATE
317     * @see #EXTRA_BACKGROUND_CALL_STATE
318     * @see #EXTRA_DISCONNECT_CAUSE
319     * @see #EXTRA_PRECISE_DISCONNECT_CAUSE
320     *
321     * <p class="note">
322     * Requires the READ_PRECISE_PHONE_STATE permission.
323     *
324     * @hide
325     */
326    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
327    public static final String ACTION_PRECISE_CALL_STATE_CHANGED =
328            "android.intent.action.PRECISE_CALL_STATE";
329
330    /**
331     * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast
332     * for an integer containing the state of the current ringing call.
333     *
334     * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID
335     * @see PreciseCallState#PRECISE_CALL_STATE_IDLE
336     * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE
337     * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING
338     * @see PreciseCallState#PRECISE_CALL_STATE_DIALING
339     * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING
340     * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING
341     * @see PreciseCallState#PRECISE_CALL_STATE_WAITING
342     * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED
343     * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING
344     *
345     * <p class="note">
346     * Retrieve with
347     * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
348     *
349     * @hide
350     */
351    public static final String EXTRA_RINGING_CALL_STATE = "ringing_state";
352
353    /**
354     * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast
355     * for an integer containing the state of the current foreground call.
356     *
357     * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID
358     * @see PreciseCallState#PRECISE_CALL_STATE_IDLE
359     * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE
360     * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING
361     * @see PreciseCallState#PRECISE_CALL_STATE_DIALING
362     * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING
363     * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING
364     * @see PreciseCallState#PRECISE_CALL_STATE_WAITING
365     * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED
366     * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING
367     *
368     * <p class="note">
369     * Retrieve with
370     * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
371     *
372     * @hide
373     */
374    public static final String EXTRA_FOREGROUND_CALL_STATE = "foreground_state";
375
376    /**
377     * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast
378     * for an integer containing the state of the current background call.
379     *
380     * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID
381     * @see PreciseCallState#PRECISE_CALL_STATE_IDLE
382     * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE
383     * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING
384     * @see PreciseCallState#PRECISE_CALL_STATE_DIALING
385     * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING
386     * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING
387     * @see PreciseCallState#PRECISE_CALL_STATE_WAITING
388     * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED
389     * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING
390     *
391     * <p class="note">
392     * Retrieve with
393     * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
394     *
395     * @hide
396     */
397    public static final String EXTRA_BACKGROUND_CALL_STATE = "background_state";
398
399    /**
400     * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast
401     * for an integer containing the disconnect cause.
402     *
403     * @see DisconnectCause
404     *
405     * <p class="note">
406     * Retrieve with
407     * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
408     *
409     * @hide
410     */
411    public static final String EXTRA_DISCONNECT_CAUSE = "disconnect_cause";
412
413    /**
414     * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast
415     * for an integer containing the disconnect cause provided by the RIL.
416     *
417     * @see PreciseDisconnectCause
418     *
419     * <p class="note">
420     * Retrieve with
421     * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
422     *
423     * @hide
424     */
425    public static final String EXTRA_PRECISE_DISCONNECT_CAUSE = "precise_disconnect_cause";
426
427    /**
428     * Broadcast intent action indicating a data connection has changed,
429     * providing precise information about the connection.
430     *
431     * <p>
432     * The {@link #EXTRA_DATA_STATE} extra indicates the connection state.
433     * The {@link #EXTRA_DATA_NETWORK_TYPE} extra indicates the connection network type.
434     * The {@link #EXTRA_DATA_APN_TYPE} extra indicates the APN type.
435     * The {@link #EXTRA_DATA_APN} extra indicates the APN.
436     * The {@link #EXTRA_DATA_CHANGE_REASON} extra indicates the connection change reason.
437     * The {@link #EXTRA_DATA_IFACE_PROPERTIES} extra indicates the connection interface.
438     * The {@link #EXTRA_DATA_FAILURE_CAUSE} extra indicates the connection fail cause.
439     *
440     * <p class="note">
441     * Requires the READ_PRECISE_PHONE_STATE permission.
442     *
443     * @see #EXTRA_DATA_STATE
444     * @see #EXTRA_DATA_NETWORK_TYPE
445     * @see #EXTRA_DATA_APN_TYPE
446     * @see #EXTRA_DATA_APN
447     * @see #EXTRA_DATA_CHANGE_REASON
448     * @see #EXTRA_DATA_IFACE
449     * @see #EXTRA_DATA_FAILURE_CAUSE
450     * @hide
451     */
452    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
453    public static final String ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED =
454            "android.intent.action.PRECISE_DATA_CONNECTION_STATE_CHANGED";
455
456    /**
457     * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
458     * for an integer containing the state of the current data connection.
459     *
460     * @see TelephonyManager#DATA_UNKNOWN
461     * @see TelephonyManager#DATA_DISCONNECTED
462     * @see TelephonyManager#DATA_CONNECTING
463     * @see TelephonyManager#DATA_CONNECTED
464     * @see TelephonyManager#DATA_SUSPENDED
465     *
466     * <p class="note">
467     * Retrieve with
468     * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
469     *
470     * @hide
471     */
472    public static final String EXTRA_DATA_STATE = PhoneConstants.STATE_KEY;
473
474    /**
475     * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
476     * for an integer containing the network type.
477     *
478     * @see TelephonyManager#NETWORK_TYPE_UNKNOWN
479     * @see TelephonyManager#NETWORK_TYPE_GPRS
480     * @see TelephonyManager#NETWORK_TYPE_EDGE
481     * @see TelephonyManager#NETWORK_TYPE_UMTS
482     * @see TelephonyManager#NETWORK_TYPE_CDMA
483     * @see TelephonyManager#NETWORK_TYPE_EVDO_0
484     * @see TelephonyManager#NETWORK_TYPE_EVDO_A
485     * @see TelephonyManager#NETWORK_TYPE_1xRTT
486     * @see TelephonyManager#NETWORK_TYPE_HSDPA
487     * @see TelephonyManager#NETWORK_TYPE_HSUPA
488     * @see TelephonyManager#NETWORK_TYPE_HSPA
489     * @see TelephonyManager#NETWORK_TYPE_IDEN
490     * @see TelephonyManager#NETWORK_TYPE_EVDO_B
491     * @see TelephonyManager#NETWORK_TYPE_LTE
492     * @see TelephonyManager#NETWORK_TYPE_EHRPD
493     * @see TelephonyManager#NETWORK_TYPE_HSPAP
494     *
495     * <p class="note">
496     * Retrieve with
497     * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
498     *
499     * @hide
500     */
501    public static final String EXTRA_DATA_NETWORK_TYPE = PhoneConstants.DATA_NETWORK_TYPE_KEY;
502
503    /**
504     * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
505     * for an String containing the data APN type.
506     *
507     * <p class="note">
508     * Retrieve with
509     * {@link android.content.Intent#getStringExtra(String name)}.
510     *
511     * @hide
512     */
513    public static final String EXTRA_DATA_APN_TYPE = PhoneConstants.DATA_APN_TYPE_KEY;
514
515    /**
516     * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
517     * for an String containing the data APN.
518     *
519     * <p class="note">
520     * Retrieve with
521     * {@link android.content.Intent#getStringExtra(String name)}.
522     *
523     * @hide
524     */
525    public static final String EXTRA_DATA_APN = PhoneConstants.DATA_APN_KEY;
526
527    /**
528     * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
529     * for an String representation of the change reason.
530     *
531     * <p class="note">
532     * Retrieve with
533     * {@link android.content.Intent#getStringExtra(String name)}.
534     *
535     * @hide
536     */
537    public static final String EXTRA_DATA_CHANGE_REASON = PhoneConstants.STATE_CHANGE_REASON_KEY;
538
539    /**
540     * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
541     * for an String representation of the data interface.
542     *
543     * <p class="note">
544     * Retrieve with
545     * {@link android.content.Intent#getParcelableExtra(String name)}.
546     *
547     * @hide
548     */
549    public static final String EXTRA_DATA_LINK_PROPERTIES_KEY = PhoneConstants.DATA_LINK_PROPERTIES_KEY;
550
551    /**
552     * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
553     * for the data connection fail cause.
554     *
555     * <p class="note">
556     * Retrieve with
557     * {@link android.content.Intent#getStringExtra(String name)}.
558     *
559     * @hide
560     */
561    public static final String EXTRA_DATA_FAILURE_CAUSE = PhoneConstants.DATA_FAILURE_CAUSE_KEY;
562
563    //
564    //
565    // Device Info
566    //
567    //
568
569    /**
570     * Returns the software version number for the device, for example,
571     * the IMEI/SV for GSM phones. Return null if the software version is
572     * not available.
573     *
574     * <p>Requires Permission:
575     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
576     */
577    public String getDeviceSoftwareVersion() {
578        try {
579            return getSubscriberInfo().getDeviceSvn();
580        } catch (RemoteException ex) {
581            return null;
582        } catch (NullPointerException ex) {
583            return null;
584        }
585    }
586
587    /**
588     * Returns the unique device ID, for example, the IMEI for GSM and the MEID
589     * or ESN for CDMA phones. Return null if device ID is not available.
590     *
591     * <p>Requires Permission:
592     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
593     */
594    public String getDeviceId() {
595        return getDeviceId(getDefaultSim());
596    }
597
598    /**
599     * Returns the unique device ID of a subscription, for example, the IMEI for
600     * GSM and the MEID for CDMA phones. Return null if device ID is not available.
601     *
602     * <p>Requires Permission:
603     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
604     *
605     * @param slotId of which deviceID is returned
606     */
607    /** {@hide} */
608    public String getDeviceId(int slotId) {
609        long[] subId = SubscriptionManager.getSubId(slotId);
610        try {
611            return getSubscriberInfo().getDeviceIdForSubscriber(subId[0]);
612        } catch (RemoteException ex) {
613            return null;
614        } catch (NullPointerException ex) {
615            return null;
616        }
617    }
618
619    /**
620     * Returns the IMEI. Return null if IMEI is not available.
621     *
622     * <p>Requires Permission:
623     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
624     */
625    /** {@hide} */
626    public String getImei() {
627        return getImei(getDefaultSim());
628    }
629
630    /**
631     * Returns the IMEI. Return null if IMEI is not available.
632     *
633     * <p>Requires Permission:
634     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
635     *
636     * @param slotId of which deviceID is returned
637     */
638    /** {@hide} */
639    public String getImei(int slotId) {
640        long[] subId = SubscriptionManager.getSubId(slotId);
641        try {
642            return getSubscriberInfo().getImeiForSubscriber(subId[0]);
643        } catch (RemoteException ex) {
644            return null;
645        } catch (NullPointerException ex) {
646            return null;
647        }
648    }
649
650    /**
651     * Returns the current location of the device.
652     *<p>
653     * If there is only one radio in the device and that radio has an LTE connection,
654     * this method will return null. The implementation must not to try add LTE
655     * identifiers into the existing cdma/gsm classes.
656     *<p>
657     * In the future this call will be deprecated.
658     *<p>
659     * @return Current location of the device or null if not available.
660     *
661     * <p>Requires Permission:
662     * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or
663     * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION}.
664     */
665    public CellLocation getCellLocation() {
666        try {
667            Bundle bundle = getITelephony().getCellLocation();
668            if (bundle.isEmpty()) return null;
669            CellLocation cl = CellLocation.newFromBundle(bundle);
670            if (cl.isEmpty())
671                return null;
672            return cl;
673        } catch (RemoteException ex) {
674            return null;
675        } catch (NullPointerException ex) {
676            return null;
677        }
678    }
679
680    /**
681     * Enables location update notifications.  {@link PhoneStateListener#onCellLocationChanged
682     * PhoneStateListener.onCellLocationChanged} will be called on location updates.
683     *
684     * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES
685     * CONTROL_LOCATION_UPDATES}
686     *
687     * @hide
688     */
689    public void enableLocationUpdates() {
690            enableLocationUpdates(getDefaultSubscription());
691    }
692
693    /**
694     * Enables location update notifications for a subscription.
695     * {@link PhoneStateListener#onCellLocationChanged
696     * PhoneStateListener.onCellLocationChanged} will be called on location updates.
697     *
698     * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES
699     * CONTROL_LOCATION_UPDATES}
700     *
701     * @param subId for which the location updates are enabled
702     */
703    /** @hide */
704    public void enableLocationUpdates(long subId) {
705        try {
706            getITelephony().enableLocationUpdatesForSubscriber(subId);
707        } catch (RemoteException ex) {
708        } catch (NullPointerException ex) {
709        }
710    }
711
712    /**
713     * Disables location update notifications.  {@link PhoneStateListener#onCellLocationChanged
714     * PhoneStateListener.onCellLocationChanged} will be called on location updates.
715     *
716     * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES
717     * CONTROL_LOCATION_UPDATES}
718     *
719     * @hide
720     */
721    public void disableLocationUpdates() {
722            disableLocationUpdates(getDefaultSubscription());
723    }
724
725    /** @hide */
726    public void disableLocationUpdates(long subId) {
727        try {
728            getITelephony().disableLocationUpdatesForSubscriber(subId);
729        } catch (RemoteException ex) {
730        } catch (NullPointerException ex) {
731        }
732    }
733
734    /**
735     * Returns the neighboring cell information of the device. The getAllCellInfo is preferred
736     * and use this only if getAllCellInfo return nulls or an empty list.
737     *<p>
738     * In the future this call will be deprecated.
739     *<p>
740     * @return List of NeighboringCellInfo or null if info unavailable.
741     *
742     * <p>Requires Permission:
743     * (@link android.Manifest.permission#ACCESS_COARSE_UPDATES}
744     */
745    public List<NeighboringCellInfo> getNeighboringCellInfo() {
746        try {
747            return getITelephony().getNeighboringCellInfo(mContext.getOpPackageName());
748        } catch (RemoteException ex) {
749            return null;
750        } catch (NullPointerException ex) {
751            return null;
752        }
753    }
754
755    /** No phone radio. */
756    public static final int PHONE_TYPE_NONE = PhoneConstants.PHONE_TYPE_NONE;
757    /** Phone radio is GSM. */
758    public static final int PHONE_TYPE_GSM = PhoneConstants.PHONE_TYPE_GSM;
759    /** Phone radio is CDMA. */
760    public static final int PHONE_TYPE_CDMA = PhoneConstants.PHONE_TYPE_CDMA;
761    /** Phone is via SIP. */
762    public static final int PHONE_TYPE_SIP = PhoneConstants.PHONE_TYPE_SIP;
763
764    /**
765     * Returns the current phone type.
766     * TODO: This is a last minute change and hence hidden.
767     *
768     * @see #PHONE_TYPE_NONE
769     * @see #PHONE_TYPE_GSM
770     * @see #PHONE_TYPE_CDMA
771     * @see #PHONE_TYPE_SIP
772     *
773     * {@hide}
774     */
775    @SystemApi
776    public int getCurrentPhoneType() {
777        return getCurrentPhoneType(getDefaultSubscription());
778    }
779
780    /**
781     * Returns a constant indicating the device phone type for a subscription.
782     *
783     * @see #PHONE_TYPE_NONE
784     * @see #PHONE_TYPE_GSM
785     * @see #PHONE_TYPE_CDMA
786     *
787     * @param subId for which phone type is returned
788     */
789    /** {@hide} */
790    @SystemApi
791    public int getCurrentPhoneType(long subId) {
792
793        try{
794            ITelephony telephony = getITelephony();
795            if (telephony != null) {
796                return telephony.getActivePhoneTypeForSubscriber(subId);
797            } else {
798                // This can happen when the ITelephony interface is not up yet.
799                return getPhoneTypeFromProperty(subId);
800            }
801        } catch (RemoteException ex) {
802            // This shouldn't happen in the normal case, as a backup we
803            // read from the system property.
804            return getPhoneTypeFromProperty(subId);
805        } catch (NullPointerException ex) {
806            // This shouldn't happen in the normal case, as a backup we
807            // read from the system property.
808            return getPhoneTypeFromProperty(subId);
809        }
810    }
811
812    /**
813     * Returns a constant indicating the device phone type.  This
814     * indicates the type of radio used to transmit voice calls.
815     *
816     * @see #PHONE_TYPE_NONE
817     * @see #PHONE_TYPE_GSM
818     * @see #PHONE_TYPE_CDMA
819     * @see #PHONE_TYPE_SIP
820     */
821    public int getPhoneType() {
822        if (!isVoiceCapable()) {
823            return PHONE_TYPE_NONE;
824        }
825        return getCurrentPhoneType();
826    }
827
828    private int getPhoneTypeFromProperty() {
829        return getPhoneTypeFromProperty(getDefaultSubscription());
830    }
831
832    /** {@hide} */
833    private int getPhoneTypeFromProperty(long subId) {
834        String type =
835            getTelephonyProperty
836                (TelephonyProperties.CURRENT_ACTIVE_PHONE, subId, null);
837        if (type != null) {
838            return (Integer.parseInt(type));
839        } else {
840            return getPhoneTypeFromNetworkType(subId);
841        }
842    }
843
844    private int getPhoneTypeFromNetworkType() {
845        return getPhoneTypeFromNetworkType(getDefaultSubscription());
846    }
847
848    /** {@hide} */
849    private int getPhoneTypeFromNetworkType(long subId) {
850        // When the system property CURRENT_ACTIVE_PHONE, has not been set,
851        // use the system property for default network type.
852        // This is a fail safe, and can only happen at first boot.
853        String mode = getTelephonyProperty("ro.telephony.default_network", subId, null);
854        if (mode != null) {
855            return TelephonyManager.getPhoneType(Integer.parseInt(mode));
856        }
857        return TelephonyManager.PHONE_TYPE_NONE;
858    }
859
860    /**
861     * This function returns the type of the phone, depending
862     * on the network mode.
863     *
864     * @param networkMode
865     * @return Phone Type
866     *
867     * @hide
868     */
869    public static int getPhoneType(int networkMode) {
870        switch(networkMode) {
871        case RILConstants.NETWORK_MODE_CDMA:
872        case RILConstants.NETWORK_MODE_CDMA_NO_EVDO:
873        case RILConstants.NETWORK_MODE_EVDO_NO_CDMA:
874            return PhoneConstants.PHONE_TYPE_CDMA;
875
876        case RILConstants.NETWORK_MODE_WCDMA_PREF:
877        case RILConstants.NETWORK_MODE_GSM_ONLY:
878        case RILConstants.NETWORK_MODE_WCDMA_ONLY:
879        case RILConstants.NETWORK_MODE_GSM_UMTS:
880        case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA:
881        case RILConstants.NETWORK_MODE_LTE_WCDMA:
882        case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
883            return PhoneConstants.PHONE_TYPE_GSM;
884
885        // Use CDMA Phone for the global mode including CDMA
886        case RILConstants.NETWORK_MODE_GLOBAL:
887        case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO:
888            return PhoneConstants.PHONE_TYPE_CDMA;
889
890        case RILConstants.NETWORK_MODE_LTE_ONLY:
891            if (getLteOnCdmaModeStatic() == PhoneConstants.LTE_ON_CDMA_TRUE) {
892                return PhoneConstants.PHONE_TYPE_CDMA;
893            } else {
894                return PhoneConstants.PHONE_TYPE_GSM;
895            }
896        default:
897            return PhoneConstants.PHONE_TYPE_GSM;
898        }
899    }
900
901    /**
902     * The contents of the /proc/cmdline file
903     */
904    private static String getProcCmdLine()
905    {
906        String cmdline = "";
907        FileInputStream is = null;
908        try {
909            is = new FileInputStream("/proc/cmdline");
910            byte [] buffer = new byte[2048];
911            int count = is.read(buffer);
912            if (count > 0) {
913                cmdline = new String(buffer, 0, count);
914            }
915        } catch (IOException e) {
916            Rlog.d(TAG, "No /proc/cmdline exception=" + e);
917        } finally {
918            if (is != null) {
919                try {
920                    is.close();
921                } catch (IOException e) {
922                }
923            }
924        }
925        Rlog.d(TAG, "/proc/cmdline=" + cmdline);
926        return cmdline;
927    }
928
929    /** Kernel command line */
930    private static final String sKernelCmdLine = getProcCmdLine();
931
932    /** Pattern for selecting the product type from the kernel command line */
933    private static final Pattern sProductTypePattern =
934        Pattern.compile("\\sproduct_type\\s*=\\s*(\\w+)");
935
936    /** The ProductType used for LTE on CDMA devices */
937    private static final String sLteOnCdmaProductType =
938        SystemProperties.get(TelephonyProperties.PROPERTY_LTE_ON_CDMA_PRODUCT_TYPE, "");
939
940    /**
941     * Return if the current radio is LTE on CDMA. This
942     * is a tri-state return value as for a period of time
943     * the mode may be unknown.
944     *
945     * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE}
946     * or {@link PhoneConstants#LTE_ON_CDMA_TRUE}
947     *
948     * @hide
949     */
950    public static int getLteOnCdmaModeStatic() {
951        int retVal;
952        int curVal;
953        String productType = "";
954
955        curVal = SystemProperties.getInt(TelephonyProperties.PROPERTY_LTE_ON_CDMA_DEVICE,
956                    PhoneConstants.LTE_ON_CDMA_UNKNOWN);
957        retVal = curVal;
958        if (retVal == PhoneConstants.LTE_ON_CDMA_UNKNOWN) {
959            Matcher matcher = sProductTypePattern.matcher(sKernelCmdLine);
960            if (matcher.find()) {
961                productType = matcher.group(1);
962                if (sLteOnCdmaProductType.equals(productType)) {
963                    retVal = PhoneConstants.LTE_ON_CDMA_TRUE;
964                } else {
965                    retVal = PhoneConstants.LTE_ON_CDMA_FALSE;
966                }
967            } else {
968                retVal = PhoneConstants.LTE_ON_CDMA_FALSE;
969            }
970        }
971
972        Rlog.d(TAG, "getLteOnCdmaMode=" + retVal + " curVal=" + curVal +
973                " product_type='" + productType +
974                "' lteOnCdmaProductType='" + sLteOnCdmaProductType + "'");
975        return retVal;
976    }
977
978    //
979    //
980    // Current Network
981    //
982    //
983
984    /**
985     * Returns the alphabetic name of current registered operator.
986     * <p>
987     * Availability: Only when user is registered to a network. Result may be
988     * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
989     * on a CDMA network).
990     */
991    public String getNetworkOperatorName() {
992        return getNetworkOperatorName(getDefaultSubscription());
993    }
994
995    /**
996     * Returns the alphabetic name of current registered operator
997     * for a particular subscription.
998     * <p>
999     * Availability: Only when user is registered to a network. Result may be
1000     * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
1001     * on a CDMA network).
1002     * @param subId
1003     */
1004    /** {@hide} */
1005    public String getNetworkOperatorName(long subId) {
1006
1007        return getTelephonyProperty(TelephonyProperties.PROPERTY_OPERATOR_ALPHA,
1008                subId, "");
1009    }
1010
1011    /**
1012     * Returns the numeric name (MCC+MNC) of current registered operator.
1013     * <p>
1014     * Availability: Only when user is registered to a network. Result may be
1015     * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
1016     * on a CDMA network).
1017     */
1018    public String getNetworkOperator() {
1019        return getNetworkOperator(getDefaultSubscription());
1020    }
1021
1022    /**
1023     * Returns the numeric name (MCC+MNC) of current registered operator
1024     * for a particular subscription.
1025     * <p>
1026     * Availability: Only when user is registered to a network. Result may be
1027     * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
1028     * on a CDMA network).
1029     *
1030     * @param subId
1031     */
1032    /** {@hide} */
1033   public String getNetworkOperator(long subId) {
1034
1035        return getTelephonyProperty(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC,
1036                subId, "");
1037     }
1038
1039    /**
1040     * Returns true if the device is considered roaming on the current
1041     * network, for GSM purposes.
1042     * <p>
1043     * Availability: Only when user registered to a network.
1044     */
1045    public boolean isNetworkRoaming() {
1046        return isNetworkRoaming(getDefaultSubscription());
1047    }
1048
1049    /**
1050     * Returns true if the device is considered roaming on the current
1051     * network for a subscription.
1052     * <p>
1053     * Availability: Only when user registered to a network.
1054     *
1055     * @param subId
1056     */
1057    /** {@hide} */
1058    public boolean isNetworkRoaming(long subId) {
1059        return "true".equals(getTelephonyProperty(TelephonyProperties.PROPERTY_OPERATOR_ISROAMING,
1060                subId, null));
1061    }
1062
1063    /**
1064     * Returns the ISO country code equivalent of the current registered
1065     * operator's MCC (Mobile Country Code).
1066     * <p>
1067     * Availability: Only when user is registered to a network. Result may be
1068     * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
1069     * on a CDMA network).
1070     */
1071    public String getNetworkCountryIso() {
1072        return getNetworkCountryIso(getDefaultSubscription());
1073    }
1074
1075    /**
1076     * Returns the ISO country code equivalent of the current registered
1077     * operator's MCC (Mobile Country Code) of a subscription.
1078     * <p>
1079     * Availability: Only when user is registered to a network. Result may be
1080     * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
1081     * on a CDMA network).
1082     *
1083     * @param subId for which Network CountryIso is returned
1084     */
1085    /** {@hide} */
1086    public String getNetworkCountryIso(long subId) {
1087        return getTelephonyProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY,
1088                subId, "");
1089    }
1090
1091    /** Network type is unknown */
1092    public static final int NETWORK_TYPE_UNKNOWN = 0;
1093    /** Current network is GPRS */
1094    public static final int NETWORK_TYPE_GPRS = 1;
1095    /** Current network is EDGE */
1096    public static final int NETWORK_TYPE_EDGE = 2;
1097    /** Current network is UMTS */
1098    public static final int NETWORK_TYPE_UMTS = 3;
1099    /** Current network is CDMA: Either IS95A or IS95B*/
1100    public static final int NETWORK_TYPE_CDMA = 4;
1101    /** Current network is EVDO revision 0*/
1102    public static final int NETWORK_TYPE_EVDO_0 = 5;
1103    /** Current network is EVDO revision A*/
1104    public static final int NETWORK_TYPE_EVDO_A = 6;
1105    /** Current network is 1xRTT*/
1106    public static final int NETWORK_TYPE_1xRTT = 7;
1107    /** Current network is HSDPA */
1108    public static final int NETWORK_TYPE_HSDPA = 8;
1109    /** Current network is HSUPA */
1110    public static final int NETWORK_TYPE_HSUPA = 9;
1111    /** Current network is HSPA */
1112    public static final int NETWORK_TYPE_HSPA = 10;
1113    /** Current network is iDen */
1114    public static final int NETWORK_TYPE_IDEN = 11;
1115    /** Current network is EVDO revision B*/
1116    public static final int NETWORK_TYPE_EVDO_B = 12;
1117    /** Current network is LTE */
1118    public static final int NETWORK_TYPE_LTE = 13;
1119    /** Current network is eHRPD */
1120    public static final int NETWORK_TYPE_EHRPD = 14;
1121    /** Current network is HSPA+ */
1122    public static final int NETWORK_TYPE_HSPAP = 15;
1123    /** Current network is GSM {@hide} */
1124    public static final int NETWORK_TYPE_GSM = 16;
1125
1126    /**
1127     * @return the NETWORK_TYPE_xxxx for current data connection.
1128     */
1129    public int getNetworkType() {
1130        return getDataNetworkType();
1131    }
1132
1133    /**
1134     * Returns a constant indicating the radio technology (network type)
1135     * currently in use on the device for a subscription.
1136     * @return the network type
1137     *
1138     * @param subId for which network type is returned
1139     *
1140     * @see #NETWORK_TYPE_UNKNOWN
1141     * @see #NETWORK_TYPE_GPRS
1142     * @see #NETWORK_TYPE_EDGE
1143     * @see #NETWORK_TYPE_UMTS
1144     * @see #NETWORK_TYPE_HSDPA
1145     * @see #NETWORK_TYPE_HSUPA
1146     * @see #NETWORK_TYPE_HSPA
1147     * @see #NETWORK_TYPE_CDMA
1148     * @see #NETWORK_TYPE_EVDO_0
1149     * @see #NETWORK_TYPE_EVDO_A
1150     * @see #NETWORK_TYPE_EVDO_B
1151     * @see #NETWORK_TYPE_1xRTT
1152     * @see #NETWORK_TYPE_IDEN
1153     * @see #NETWORK_TYPE_LTE
1154     * @see #NETWORK_TYPE_EHRPD
1155     * @see #NETWORK_TYPE_HSPAP
1156     */
1157    /** {@hide} */
1158   public int getNetworkType(long subId) {
1159       try {
1160           ITelephony telephony = getITelephony();
1161           if (telephony != null) {
1162               return telephony.getNetworkTypeForSubscriber(subId);
1163           } else {
1164               // This can happen when the ITelephony interface is not up yet.
1165               return NETWORK_TYPE_UNKNOWN;
1166           }
1167       } catch(RemoteException ex) {
1168           // This shouldn't happen in the normal case
1169           return NETWORK_TYPE_UNKNOWN;
1170       } catch (NullPointerException ex) {
1171           // This could happen before phone restarts due to crashing
1172           return NETWORK_TYPE_UNKNOWN;
1173       }
1174   }
1175
1176    /**
1177     * Returns a constant indicating the radio technology (network type)
1178     * currently in use on the device for data transmission.
1179     * @return the network type
1180     *
1181     * @see #NETWORK_TYPE_UNKNOWN
1182     * @see #NETWORK_TYPE_GPRS
1183     * @see #NETWORK_TYPE_EDGE
1184     * @see #NETWORK_TYPE_UMTS
1185     * @see #NETWORK_TYPE_HSDPA
1186     * @see #NETWORK_TYPE_HSUPA
1187     * @see #NETWORK_TYPE_HSPA
1188     * @see #NETWORK_TYPE_CDMA
1189     * @see #NETWORK_TYPE_EVDO_0
1190     * @see #NETWORK_TYPE_EVDO_A
1191     * @see #NETWORK_TYPE_EVDO_B
1192     * @see #NETWORK_TYPE_1xRTT
1193     * @see #NETWORK_TYPE_IDEN
1194     * @see #NETWORK_TYPE_LTE
1195     * @see #NETWORK_TYPE_EHRPD
1196     * @see #NETWORK_TYPE_HSPAP
1197     *
1198     * @hide
1199     */
1200    public int getDataNetworkType() {
1201        return getDataNetworkType(getDefaultSubscription());
1202    }
1203
1204    /**
1205     * Returns a constant indicating the radio technology (network type)
1206     * currently in use on the device for data transmission for a subscription
1207     * @return the network type
1208     *
1209     * @param subId for which network type is returned
1210     */
1211    /** {@hide} */
1212    public int getDataNetworkType(long subId) {
1213        try{
1214            ITelephony telephony = getITelephony();
1215            if (telephony != null) {
1216                return telephony.getDataNetworkTypeForSubscriber(subId);
1217            } else {
1218                // This can happen when the ITelephony interface is not up yet.
1219                return NETWORK_TYPE_UNKNOWN;
1220            }
1221        } catch(RemoteException ex) {
1222            // This shouldn't happen in the normal case
1223            return NETWORK_TYPE_UNKNOWN;
1224        } catch (NullPointerException ex) {
1225            // This could happen before phone restarts due to crashing
1226            return NETWORK_TYPE_UNKNOWN;
1227        }
1228    }
1229
1230    /**
1231     * Returns the NETWORK_TYPE_xxxx for voice
1232     *
1233     * @hide
1234     */
1235    public int getVoiceNetworkType() {
1236        return getVoiceNetworkType(getDefaultSubscription());
1237    }
1238
1239    /**
1240     * Returns the NETWORK_TYPE_xxxx for voice for a subId
1241     *
1242     */
1243    /** {@hide} */
1244    public int getVoiceNetworkType(long subId) {
1245        try{
1246            ITelephony telephony = getITelephony();
1247            if (telephony != null) {
1248                return telephony.getVoiceNetworkTypeForSubscriber(subId);
1249            } else {
1250                // This can happen when the ITelephony interface is not up yet.
1251                return NETWORK_TYPE_UNKNOWN;
1252            }
1253        } catch(RemoteException ex) {
1254            // This shouldn't happen in the normal case
1255            return NETWORK_TYPE_UNKNOWN;
1256        } catch (NullPointerException ex) {
1257            // This could happen before phone restarts due to crashing
1258            return NETWORK_TYPE_UNKNOWN;
1259        }
1260    }
1261
1262    /** Unknown network class. {@hide} */
1263    public static final int NETWORK_CLASS_UNKNOWN = 0;
1264    /** Class of broadly defined "2G" networks. {@hide} */
1265    public static final int NETWORK_CLASS_2_G = 1;
1266    /** Class of broadly defined "3G" networks. {@hide} */
1267    public static final int NETWORK_CLASS_3_G = 2;
1268    /** Class of broadly defined "4G" networks. {@hide} */
1269    public static final int NETWORK_CLASS_4_G = 3;
1270
1271    /**
1272     * Return general class of network type, such as "3G" or "4G". In cases
1273     * where classification is contentious, this method is conservative.
1274     *
1275     * @hide
1276     */
1277    public static int getNetworkClass(int networkType) {
1278        switch (networkType) {
1279            case NETWORK_TYPE_GPRS:
1280            case NETWORK_TYPE_GSM:
1281            case NETWORK_TYPE_EDGE:
1282            case NETWORK_TYPE_CDMA:
1283            case NETWORK_TYPE_1xRTT:
1284            case NETWORK_TYPE_IDEN:
1285                return NETWORK_CLASS_2_G;
1286            case NETWORK_TYPE_UMTS:
1287            case NETWORK_TYPE_EVDO_0:
1288            case NETWORK_TYPE_EVDO_A:
1289            case NETWORK_TYPE_HSDPA:
1290            case NETWORK_TYPE_HSUPA:
1291            case NETWORK_TYPE_HSPA:
1292            case NETWORK_TYPE_EVDO_B:
1293            case NETWORK_TYPE_EHRPD:
1294            case NETWORK_TYPE_HSPAP:
1295                return NETWORK_CLASS_3_G;
1296            case NETWORK_TYPE_LTE:
1297                return NETWORK_CLASS_4_G;
1298            default:
1299                return NETWORK_CLASS_UNKNOWN;
1300        }
1301    }
1302
1303    /**
1304     * Returns a string representation of the radio technology (network type)
1305     * currently in use on the device.
1306     * @return the name of the radio technology
1307     *
1308     * @hide pending API council review
1309     */
1310    public String getNetworkTypeName() {
1311        return getNetworkTypeName(getNetworkType());
1312    }
1313
1314    /**
1315     * Returns a string representation of the radio technology (network type)
1316     * currently in use on the device.
1317     * @param subId for which network type is returned
1318     * @return the name of the radio technology
1319     *
1320     */
1321    /** {@hide} */
1322    public static String getNetworkTypeName(int type) {
1323        switch (type) {
1324            case NETWORK_TYPE_GPRS:
1325                return "GPRS";
1326            case NETWORK_TYPE_EDGE:
1327                return "EDGE";
1328            case NETWORK_TYPE_UMTS:
1329                return "UMTS";
1330            case NETWORK_TYPE_HSDPA:
1331                return "HSDPA";
1332            case NETWORK_TYPE_HSUPA:
1333                return "HSUPA";
1334            case NETWORK_TYPE_HSPA:
1335                return "HSPA";
1336            case NETWORK_TYPE_CDMA:
1337                return "CDMA";
1338            case NETWORK_TYPE_EVDO_0:
1339                return "CDMA - EvDo rev. 0";
1340            case NETWORK_TYPE_EVDO_A:
1341                return "CDMA - EvDo rev. A";
1342            case NETWORK_TYPE_EVDO_B:
1343                return "CDMA - EvDo rev. B";
1344            case NETWORK_TYPE_1xRTT:
1345                return "CDMA - 1xRTT";
1346            case NETWORK_TYPE_LTE:
1347                return "LTE";
1348            case NETWORK_TYPE_EHRPD:
1349                return "CDMA - eHRPD";
1350            case NETWORK_TYPE_IDEN:
1351                return "iDEN";
1352            case NETWORK_TYPE_HSPAP:
1353                return "HSPA+";
1354            case NETWORK_TYPE_GSM:
1355                return "GSM";
1356            default:
1357                return "UNKNOWN";
1358        }
1359    }
1360
1361    //
1362    //
1363    // SIM Card
1364    //
1365    //
1366
1367    /** SIM card state: Unknown. Signifies that the SIM is in transition
1368     *  between states. For example, when the user inputs the SIM pin
1369     *  under PIN_REQUIRED state, a query for sim status returns
1370     *  this state before turning to SIM_STATE_READY. */
1371    public static final int SIM_STATE_UNKNOWN = 0;
1372    /** SIM card state: no SIM card is available in the device */
1373    public static final int SIM_STATE_ABSENT = 1;
1374    /** SIM card state: Locked: requires the user's SIM PIN to unlock */
1375    public static final int SIM_STATE_PIN_REQUIRED = 2;
1376    /** SIM card state: Locked: requires the user's SIM PUK to unlock */
1377    public static final int SIM_STATE_PUK_REQUIRED = 3;
1378    /** SIM card state: Locked: requries a network PIN to unlock */
1379    public static final int SIM_STATE_NETWORK_LOCKED = 4;
1380    /** SIM card state: Ready */
1381    public static final int SIM_STATE_READY = 5;
1382    /** SIM card state: SIM Card Error, Sim Card is present but faulty
1383     *@hide
1384     */
1385    public static final int SIM_STATE_CARD_IO_ERROR = 6;
1386
1387    /**
1388     * @return true if a ICC card is present
1389     */
1390    public boolean hasIccCard() {
1391        return hasIccCard(getDefaultSim());
1392    }
1393
1394    /**
1395     * @return true if a ICC card is present for a subscription
1396     *
1397     * @param slotId for which icc card presence is checked
1398     */
1399    /** {@hide} */
1400    // FIXME Input argument slotId should be of type int
1401    public boolean hasIccCard(long slotId) {
1402
1403        try {
1404            return getITelephony().hasIccCardUsingSlotId(slotId);
1405        } catch (RemoteException ex) {
1406            // Assume no ICC card if remote exception which shouldn't happen
1407            return false;
1408        } catch (NullPointerException ex) {
1409            // This could happen before phone restarts due to crashing
1410            return false;
1411        }
1412    }
1413
1414    /**
1415     * Returns a constant indicating the state of the
1416     * device SIM card.
1417     *
1418     * @see #SIM_STATE_UNKNOWN
1419     * @see #SIM_STATE_ABSENT
1420     * @see #SIM_STATE_PIN_REQUIRED
1421     * @see #SIM_STATE_PUK_REQUIRED
1422     * @see #SIM_STATE_NETWORK_LOCKED
1423     * @see #SIM_STATE_READY
1424     * @see #SIM_STATE_CARD_IO_ERROR
1425     */
1426    public int getSimState() {
1427        return getSimState(getDefaultSim());
1428    }
1429
1430    /**
1431     * Returns a constant indicating the state of the
1432     * device SIM card in a slot.
1433     *
1434     * @param slotId
1435     *
1436     * @see #SIM_STATE_UNKNOWN
1437     * @see #SIM_STATE_ABSENT
1438     * @see #SIM_STATE_PIN_REQUIRED
1439     * @see #SIM_STATE_PUK_REQUIRED
1440     * @see #SIM_STATE_NETWORK_LOCKED
1441     * @see #SIM_STATE_READY
1442     */
1443    /** {@hide} */
1444    // FIXME the argument to pass is subId ??
1445    public int getSimState(int slotId) {
1446        long[] subId = SubscriptionManager.getSubId(slotId);
1447        if (subId == null) {
1448            return SIM_STATE_ABSENT;
1449        }
1450        // FIXME Do not use a property to determine SIM_STATE, call
1451        // appropriate method on some object.
1452        String prop =
1453            getTelephonyProperty(TelephonyProperties.PROPERTY_SIM_STATE, subId[0], "");
1454        if ("ABSENT".equals(prop)) {
1455            return SIM_STATE_ABSENT;
1456        }
1457        else if ("PIN_REQUIRED".equals(prop)) {
1458            return SIM_STATE_PIN_REQUIRED;
1459        }
1460        else if ("PUK_REQUIRED".equals(prop)) {
1461            return SIM_STATE_PUK_REQUIRED;
1462        }
1463        else if ("NETWORK_LOCKED".equals(prop)) {
1464            return SIM_STATE_NETWORK_LOCKED;
1465        }
1466        else if ("READY".equals(prop)) {
1467            return SIM_STATE_READY;
1468        }
1469        else if ("CARD_IO_ERROR".equals(prop)) {
1470            return SIM_STATE_CARD_IO_ERROR;
1471        }
1472        else {
1473            return SIM_STATE_UNKNOWN;
1474        }
1475    }
1476
1477    /**
1478     * Returns the MCC+MNC (mobile country code + mobile network code) of the
1479     * provider of the SIM. 5 or 6 decimal digits.
1480     * <p>
1481     * Availability: SIM state must be {@link #SIM_STATE_READY}
1482     *
1483     * @see #getSimState
1484     */
1485    public String getSimOperator() {
1486        long subId = getDefaultSubscription();
1487        Rlog.d(TAG, "getSimOperator(): default subId=" + subId);
1488        return getSimOperator(subId);
1489    }
1490
1491    /**
1492     * Returns the MCC+MNC (mobile country code + mobile network code) of the
1493     * provider of the SIM for a particular subscription. 5 or 6 decimal digits.
1494     * <p>
1495     * Availability: SIM state must be {@link #SIM_STATE_READY}
1496     *
1497     * @see #getSimState
1498     *
1499     * @param subId for which SimOperator is returned
1500     */
1501    /** {@hide} */
1502    public String getSimOperator(long subId) {
1503        String operator = getTelephonyProperty(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC,
1504                subId, "");
1505        Rlog.d(TAG, "getSimOperator: subId=" + subId + " operator=" + operator);
1506        return operator;
1507    }
1508
1509    /**
1510     * Returns the Service Provider Name (SPN).
1511     * <p>
1512     * Availability: SIM state must be {@link #SIM_STATE_READY}
1513     *
1514     * @see #getSimState
1515     */
1516    public String getSimOperatorName() {
1517        return getSimOperatorName(getDefaultSubscription());
1518    }
1519
1520    /**
1521     * Returns the Service Provider Name (SPN).
1522     * <p>
1523     * Availability: SIM state must be {@link #SIM_STATE_READY}
1524     *
1525     * @see #getSimState
1526     *
1527     * @param subId for which SimOperatorName is returned
1528     */
1529    /** {@hide} */
1530    public String getSimOperatorName(long subId) {
1531        return getTelephonyProperty(TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA,
1532                subId, "");
1533    }
1534
1535    /**
1536     * Returns the ISO country code equivalent for the SIM provider's country code.
1537     */
1538    public String getSimCountryIso() {
1539        return getSimCountryIso(getDefaultSubscription());
1540    }
1541
1542    /**
1543     * Returns the ISO country code equivalent for the SIM provider's country code.
1544     *
1545     * @param subId for which SimCountryIso is returned
1546     */
1547    /** {@hide} */
1548    public String getSimCountryIso(long subId) {
1549        return getTelephonyProperty(TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY,
1550                subId, "");
1551    }
1552
1553    /**
1554     * Returns the serial number of the SIM, if applicable. Return null if it is
1555     * unavailable.
1556     * <p>
1557     * Requires Permission:
1558     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1559     */
1560    public String getSimSerialNumber() {
1561         return getSimSerialNumber(getDefaultSubscription());
1562    }
1563
1564    /**
1565     * Returns the serial number for the given subscription, if applicable. Return null if it is
1566     * unavailable.
1567     * <p>
1568     * @param subId for which Sim Serial number is returned
1569     * Requires Permission:
1570     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1571     */
1572    /** {@hide} */
1573    public String getSimSerialNumber(long subId) {
1574        try {
1575            return getSubscriberInfo().getIccSerialNumberForSubscriber(subId);
1576        } catch (RemoteException ex) {
1577            return null;
1578        } catch (NullPointerException ex) {
1579            // This could happen before phone restarts due to crashing
1580            return null;
1581        }
1582    }
1583
1584    /**
1585     * Return if the current radio is LTE on CDMA. This
1586     * is a tri-state return value as for a period of time
1587     * the mode may be unknown.
1588     *
1589     * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE}
1590     * or {@link PhoneConstants#LTE_ON_CDMA_TRUE}
1591     *
1592     * @hide
1593     */
1594    public int getLteOnCdmaMode() {
1595        return getLteOnCdmaMode(getDefaultSubscription());
1596    }
1597
1598    /**
1599     * Return if the current radio is LTE on CDMA for Subscription. This
1600     * is a tri-state return value as for a period of time
1601     * the mode may be unknown.
1602     *
1603     * @param subId for which radio is LTE on CDMA is returned
1604     * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE}
1605     * or {@link PhoneConstants#LTE_ON_CDMA_TRUE}
1606     *
1607     */
1608    /** {@hide} */
1609    public int getLteOnCdmaMode(long subId) {
1610        try {
1611            return getITelephony().getLteOnCdmaModeForSubscriber(subId);
1612        } catch (RemoteException ex) {
1613            // Assume no ICC card if remote exception which shouldn't happen
1614            return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
1615        } catch (NullPointerException ex) {
1616            // This could happen before phone restarts due to crashing
1617            return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
1618        }
1619    }
1620
1621    //
1622    //
1623    // Subscriber Info
1624    //
1625    //
1626
1627    /**
1628     * Returns the unique subscriber ID, for example, the IMSI for a GSM phone.
1629     * Return null if it is unavailable.
1630     * <p>
1631     * Requires Permission:
1632     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1633     */
1634    public String getSubscriberId() {
1635        return getSubscriberId(getDefaultSubscription());
1636    }
1637
1638    /**
1639     * Returns the unique subscriber ID, for example, the IMSI for a GSM phone
1640     * for a subscription.
1641     * Return null if it is unavailable.
1642     * <p>
1643     * Requires Permission:
1644     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1645     *
1646     * @param subId whose subscriber id is returned
1647     */
1648    /** {@hide} */
1649    public String getSubscriberId(long subId) {
1650        try {
1651            return getSubscriberInfo().getSubscriberIdForSubscriber(subId);
1652        } catch (RemoteException ex) {
1653            return null;
1654        } catch (NullPointerException ex) {
1655            // This could happen before phone restarts due to crashing
1656            return null;
1657        }
1658    }
1659
1660    /**
1661     * Returns the Group Identifier Level1 for a GSM phone.
1662     * Return null if it is unavailable.
1663     * <p>
1664     * Requires Permission:
1665     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1666     */
1667    public String getGroupIdLevel1() {
1668        try {
1669            return getSubscriberInfo().getGroupIdLevel1();
1670        } catch (RemoteException ex) {
1671            return null;
1672        } catch (NullPointerException ex) {
1673            // This could happen before phone restarts due to crashing
1674            return null;
1675        }
1676    }
1677
1678    /**
1679     * Returns the Group Identifier Level1 for a GSM phone for a particular subscription.
1680     * Return null if it is unavailable.
1681     * <p>
1682     * Requires Permission:
1683     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1684     *
1685     * @param subscription whose subscriber id is returned
1686     */
1687    /** {@hide} */
1688    public String getGroupIdLevel1(long subId) {
1689        try {
1690            return getSubscriberInfo().getGroupIdLevel1ForSubscriber(subId);
1691        } catch (RemoteException ex) {
1692            return null;
1693        } catch (NullPointerException ex) {
1694            // This could happen before phone restarts due to crashing
1695            return null;
1696        }
1697    }
1698
1699    /**
1700     * Returns the phone number string for line 1, for example, the MSISDN
1701     * for a GSM phone. Return null if it is unavailable.
1702     * <p>
1703     * Requires Permission:
1704     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1705     */
1706    public String getLine1Number() {
1707        return getLine1Number(getDefaultSubscription());
1708    }
1709
1710    /**
1711     * Returns the phone number string for line 1, for example, the MSISDN
1712     * for a GSM phone for a particular subscription. Return null if it is unavailable.
1713     * <p>
1714     * Requires Permission:
1715     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1716     *
1717     * @param subId whose phone number for line 1 is returned
1718     */
1719    /** {@hide} */
1720    public String getLine1Number(long subId) {
1721        String number = null;
1722        try {
1723            number = getITelephony().getLine1NumberForDisplay(subId);
1724        } catch (RemoteException ex) {
1725        } catch (NullPointerException ex) {
1726        }
1727        if (number != null) {
1728            return number;
1729        }
1730        try {
1731            return getSubscriberInfo().getLine1NumberForSubscriber(subId);
1732        } catch (RemoteException ex) {
1733            return null;
1734        } catch (NullPointerException ex) {
1735            // This could happen before phone restarts due to crashing
1736            return null;
1737        }
1738    }
1739
1740    /**
1741     * Set the phone number string and its alphatag for line 1 for display
1742     * purpose only, for example, displayed in Phone Status. It won't change
1743     * the actual MSISDN/MDN. This setting won't be persisted during power cycle
1744     * and it should be set again after reboot.
1745     * <p>
1746     * Requires Permission:
1747     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
1748     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
1749     *
1750     * @param alphaTag alpha-tagging of the dailing nubmer
1751     * @param number The dialing number
1752     */
1753    public void setLine1NumberForDisplay(String alphaTag, String number) {
1754        setLine1NumberForDisplay(getDefaultSubscription(), alphaTag, number);
1755    }
1756
1757    /**
1758     * Set the phone number string and its alphatag for line 1 for display
1759     * purpose only, for example, displayed in Phone Status. It won't change
1760     * the actual MSISDN/MDN. This setting won't be persisted during power cycle
1761     * and it should be set again after reboot.
1762     * <p>
1763     * Requires Permission:
1764     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
1765     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
1766     *
1767     * @param subId the subscriber that the alphatag and dialing number belongs to.
1768     * @param alphaTag alpha-tagging of the dailing nubmer
1769     * @param number The dialing number
1770     */
1771    public void setLine1NumberForDisplay(long subId, String alphaTag, String number) {
1772        try {
1773            getITelephony().setLine1NumberForDisplay(subId, alphaTag, number);
1774        } catch (RemoteException ex) {
1775        } catch (NullPointerException ex) {
1776        }
1777    }
1778
1779    /**
1780     * Returns the alphabetic identifier associated with the line 1 number.
1781     * Return null if it is unavailable.
1782     * <p>
1783     * Requires Permission:
1784     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1785     * @hide
1786     * nobody seems to call this.
1787     */
1788    public String getLine1AlphaTag() {
1789        return getLine1AlphaTag(getDefaultSubscription());
1790    }
1791
1792    /**
1793     * Returns the alphabetic identifier associated with the line 1 number
1794     * for a subscription.
1795     * Return null if it is unavailable.
1796     * <p>
1797     * Requires Permission:
1798     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1799     * @param subId whose alphabetic identifier associated with line 1 is returned
1800     * nobody seems to call this.
1801     */
1802    /** {@hide} */
1803    public String getLine1AlphaTag(long subId) {
1804        String alphaTag = null;
1805        try {
1806            alphaTag = getITelephony().getLine1AlphaTagForDisplay(subId);
1807        } catch (RemoteException ex) {
1808        } catch (NullPointerException ex) {
1809        }
1810        if (alphaTag != null) {
1811            return alphaTag;
1812        }
1813        try {
1814            return getSubscriberInfo().getLine1AlphaTagForSubscriber(subId);
1815        } catch (RemoteException ex) {
1816            return null;
1817        } catch (NullPointerException ex) {
1818            // This could happen before phone restarts due to crashing
1819            return null;
1820        }
1821    }
1822
1823    /**
1824     * Returns the MSISDN string.
1825     * for a GSM phone. Return null if it is unavailable.
1826     * <p>
1827     * Requires Permission:
1828     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1829     *
1830     * @hide
1831     */
1832    public String getMsisdn() {
1833        return getMsisdn(getDefaultSubscription());
1834    }
1835
1836    /**
1837     * Returns the MSISDN string.
1838     * for a GSM phone. Return null if it is unavailable.
1839     * <p>
1840     * Requires Permission:
1841     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1842     *
1843     * @param subId for which msisdn is returned
1844     */
1845    /** {@hide} */
1846    public String getMsisdn(long subId) {
1847        try {
1848            return getSubscriberInfo().getMsisdnForSubscriber(subId);
1849        } catch (RemoteException ex) {
1850            return null;
1851        } catch (NullPointerException ex) {
1852            // This could happen before phone restarts due to crashing
1853            return null;
1854        }
1855    }
1856
1857    /**
1858     * Returns the voice mail number. Return null if it is unavailable.
1859     * <p>
1860     * Requires Permission:
1861     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1862     */
1863    public String getVoiceMailNumber() {
1864        return getVoiceMailNumber(getDefaultSubscription());
1865    }
1866
1867    /**
1868     * Returns the voice mail number for a subscription.
1869     * Return null if it is unavailable.
1870     * <p>
1871     * Requires Permission:
1872     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1873     * @param subId whose voice mail number is returned
1874     */
1875    /** {@hide} */
1876    public String getVoiceMailNumber(long subId) {
1877        try {
1878            return getSubscriberInfo().getVoiceMailNumberForSubscriber(subId);
1879        } catch (RemoteException ex) {
1880            return null;
1881        } catch (NullPointerException ex) {
1882            // This could happen before phone restarts due to crashing
1883            return null;
1884        }
1885    }
1886
1887    /**
1888     * Returns the complete voice mail number. Return null if it is unavailable.
1889     * <p>
1890     * Requires Permission:
1891     *   {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED}
1892     *
1893     * @hide
1894     */
1895    public String getCompleteVoiceMailNumber() {
1896        return getCompleteVoiceMailNumber(getDefaultSubscription());
1897    }
1898
1899    /**
1900     * Returns the complete voice mail number. Return null if it is unavailable.
1901     * <p>
1902     * Requires Permission:
1903     *   {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED}
1904     *
1905     * @param subId
1906     */
1907    /** {@hide} */
1908    public String getCompleteVoiceMailNumber(long subId) {
1909        try {
1910            return getSubscriberInfo().getCompleteVoiceMailNumberForSubscriber(subId);
1911        } catch (RemoteException ex) {
1912            return null;
1913        } catch (NullPointerException ex) {
1914            // This could happen before phone restarts due to crashing
1915            return null;
1916        }
1917    }
1918
1919    /**
1920     * Returns the voice mail count. Return 0 if unavailable.
1921     * <p>
1922     * Requires Permission:
1923     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1924     * @hide
1925     */
1926    public int getVoiceMessageCount() {
1927        return getVoiceMessageCount(getDefaultSubscription());
1928    }
1929
1930    /**
1931     * Returns the voice mail count for a subscription. Return 0 if unavailable.
1932     * <p>
1933     * Requires Permission:
1934     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1935     * @param subId whose voice message count is returned
1936     */
1937    /** {@hide} */
1938    public int getVoiceMessageCount(long subId) {
1939        try {
1940            return getITelephony().getVoiceMessageCountForSubscriber(subId);
1941        } catch (RemoteException ex) {
1942            return 0;
1943        } catch (NullPointerException ex) {
1944            // This could happen before phone restarts due to crashing
1945            return 0;
1946        }
1947    }
1948
1949    /**
1950     * Retrieves the alphabetic identifier associated with the voice
1951     * mail number.
1952     * <p>
1953     * Requires Permission:
1954     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1955     */
1956    public String getVoiceMailAlphaTag() {
1957        return getVoiceMailAlphaTag(getDefaultSubscription());
1958    }
1959
1960    /**
1961     * Retrieves the alphabetic identifier associated with the voice
1962     * mail number for a subscription.
1963     * <p>
1964     * Requires Permission:
1965     * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1966     * @param subId whose alphabetic identifier associated with the
1967     * voice mail number is returned
1968     */
1969    /** {@hide} */
1970    public String getVoiceMailAlphaTag(long subId) {
1971        try {
1972            return getSubscriberInfo().getVoiceMailAlphaTagForSubscriber(subId);
1973        } catch (RemoteException ex) {
1974            return null;
1975        } catch (NullPointerException ex) {
1976            // This could happen before phone restarts due to crashing
1977            return null;
1978        }
1979    }
1980
1981    /**
1982     * Returns the IMS private user identity (IMPI) that was loaded from the ISIM.
1983     * @return the IMPI, or null if not present or not loaded
1984     * @hide
1985     */
1986    public String getIsimImpi() {
1987        try {
1988            return getSubscriberInfo().getIsimImpi();
1989        } catch (RemoteException ex) {
1990            return null;
1991        } catch (NullPointerException ex) {
1992            // This could happen before phone restarts due to crashing
1993            return null;
1994        }
1995    }
1996
1997    /**
1998     * Returns the IMS home network domain name that was loaded from the ISIM.
1999     * @return the IMS domain name, or null if not present or not loaded
2000     * @hide
2001     */
2002    public String getIsimDomain() {
2003        try {
2004            return getSubscriberInfo().getIsimDomain();
2005        } catch (RemoteException ex) {
2006            return null;
2007        } catch (NullPointerException ex) {
2008            // This could happen before phone restarts due to crashing
2009            return null;
2010        }
2011    }
2012
2013    /**
2014     * Returns the IMS public user identities (IMPU) that were loaded from the ISIM.
2015     * @return an array of IMPU strings, with one IMPU per string, or null if
2016     *      not present or not loaded
2017     * @hide
2018     */
2019    public String[] getIsimImpu() {
2020        try {
2021            return getSubscriberInfo().getIsimImpu();
2022        } catch (RemoteException ex) {
2023            return null;
2024        } catch (NullPointerException ex) {
2025            // This could happen before phone restarts due to crashing
2026            return null;
2027        }
2028    }
2029
2030    private IPhoneSubInfo getSubscriberInfo() {
2031        // get it each time because that process crashes a lot
2032        return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo"));
2033    }
2034
2035    /** Device call state: No activity. */
2036    public static final int CALL_STATE_IDLE = 0;
2037    /** Device call state: Ringing. A new call arrived and is
2038     *  ringing or waiting. In the latter case, another call is
2039     *  already active. */
2040    public static final int CALL_STATE_RINGING = 1;
2041    /** Device call state: Off-hook. At least one call exists
2042      * that is dialing, active, or on hold, and no calls are ringing
2043      * or waiting. */
2044    public static final int CALL_STATE_OFFHOOK = 2;
2045
2046    /**
2047     * Returns a constant indicating the call state (cellular) on the device.
2048     */
2049    public int getCallState() {
2050        return getCallState(getDefaultSubscription());
2051    }
2052
2053    /**
2054     * Returns a constant indicating the call state (cellular) on the device
2055     * for a subscription.
2056     *
2057     * @param subId whose call state is returned
2058     */
2059    /** {@hide} */
2060    public int getCallState(long subId) {
2061        try {
2062            return getITelephony().getCallStateForSubscriber(subId);
2063        } catch (RemoteException ex) {
2064            // the phone process is restarting.
2065            return CALL_STATE_IDLE;
2066        } catch (NullPointerException ex) {
2067          // the phone process is restarting.
2068          return CALL_STATE_IDLE;
2069      }
2070    }
2071
2072    /** Data connection activity: No traffic. */
2073    public static final int DATA_ACTIVITY_NONE = 0x00000000;
2074    /** Data connection activity: Currently receiving IP PPP traffic. */
2075    public static final int DATA_ACTIVITY_IN = 0x00000001;
2076    /** Data connection activity: Currently sending IP PPP traffic. */
2077    public static final int DATA_ACTIVITY_OUT = 0x00000002;
2078    /** Data connection activity: Currently both sending and receiving
2079     *  IP PPP traffic. */
2080    public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT;
2081    /**
2082     * Data connection is active, but physical link is down
2083     */
2084    public static final int DATA_ACTIVITY_DORMANT = 0x00000004;
2085
2086    /**
2087     * Returns a constant indicating the type of activity on a data connection
2088     * (cellular).
2089     *
2090     * @see #DATA_ACTIVITY_NONE
2091     * @see #DATA_ACTIVITY_IN
2092     * @see #DATA_ACTIVITY_OUT
2093     * @see #DATA_ACTIVITY_INOUT
2094     * @see #DATA_ACTIVITY_DORMANT
2095     */
2096    public int getDataActivity() {
2097        try {
2098            return getITelephony().getDataActivity();
2099        } catch (RemoteException ex) {
2100            // the phone process is restarting.
2101            return DATA_ACTIVITY_NONE;
2102        } catch (NullPointerException ex) {
2103          // the phone process is restarting.
2104          return DATA_ACTIVITY_NONE;
2105      }
2106    }
2107
2108    /** Data connection state: Unknown.  Used before we know the state.
2109     * @hide
2110     */
2111    public static final int DATA_UNKNOWN        = -1;
2112    /** Data connection state: Disconnected. IP traffic not available. */
2113    public static final int DATA_DISCONNECTED   = 0;
2114    /** Data connection state: Currently setting up a data connection. */
2115    public static final int DATA_CONNECTING     = 1;
2116    /** Data connection state: Connected. IP traffic should be available. */
2117    public static final int DATA_CONNECTED      = 2;
2118    /** Data connection state: Suspended. The connection is up, but IP
2119     * traffic is temporarily unavailable. For example, in a 2G network,
2120     * data activity may be suspended when a voice call arrives. */
2121    public static final int DATA_SUSPENDED      = 3;
2122
2123    /**
2124     * Returns a constant indicating the current data connection state
2125     * (cellular).
2126     *
2127     * @see #DATA_DISCONNECTED
2128     * @see #DATA_CONNECTING
2129     * @see #DATA_CONNECTED
2130     * @see #DATA_SUSPENDED
2131     */
2132    public int getDataState() {
2133        try {
2134            return getITelephony().getDataState();
2135        } catch (RemoteException ex) {
2136            // the phone process is restarting.
2137            return DATA_DISCONNECTED;
2138        } catch (NullPointerException ex) {
2139            return DATA_DISCONNECTED;
2140        }
2141    }
2142
2143    private ITelephony getITelephony() {
2144        return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE));
2145    }
2146
2147    private ITelecommService getTelecommService() {
2148        return ITelecommService.Stub.asInterface(ServiceManager.getService(TELECOMM_SERVICE_NAME));
2149    }
2150
2151    //
2152    //
2153    // PhoneStateListener
2154    //
2155    //
2156
2157    /**
2158     * Registers a listener object to receive notification of changes
2159     * in specified telephony states.
2160     * <p>
2161     * To register a listener, pass a {@link PhoneStateListener}
2162     * and specify at least one telephony state of interest in
2163     * the events argument.
2164     *
2165     * At registration, and when a specified telephony state
2166     * changes, the telephony manager invokes the appropriate
2167     * callback method on the listener object and passes the
2168     * current (updated) values.
2169     * <p>
2170     * To unregister a listener, pass the listener object and set the
2171     * events argument to
2172     * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0).
2173     *
2174     * @param listener The {@link PhoneStateListener} object to register
2175     *                 (or unregister)
2176     * @param events The telephony state(s) of interest to the listener,
2177     *               as a bitwise-OR combination of {@link PhoneStateListener}
2178     *               LISTEN_ flags.
2179     */
2180    public void listen(PhoneStateListener listener, int events) {
2181        String pkgForDebug = mContext != null ? mContext.getPackageName() : "<unknown>";
2182        try {
2183            Boolean notifyNow = (getITelephony() != null);
2184            sRegistry.listenForSubscriber(listener.mSubId, pkgForDebug, listener.callback, events, notifyNow);
2185        } catch (RemoteException ex) {
2186            // system process dead
2187        } catch (NullPointerException ex) {
2188            // system process dead
2189        }
2190    }
2191
2192    /**
2193     * Returns the CDMA ERI icon index to display
2194     *
2195     * @hide
2196     */
2197    public int getCdmaEriIconIndex() {
2198        return getCdmaEriIconIndex(getDefaultSubscription());
2199    }
2200
2201    /**
2202     * Returns the CDMA ERI icon index to display for a subscription
2203     */
2204    /** {@hide} */
2205    public int getCdmaEriIconIndex(long subId) {
2206        try {
2207            return getITelephony().getCdmaEriIconIndexForSubscriber(subId);
2208        } catch (RemoteException ex) {
2209            // the phone process is restarting.
2210            return -1;
2211        } catch (NullPointerException ex) {
2212            return -1;
2213        }
2214    }
2215
2216    /**
2217     * Returns the CDMA ERI icon mode,
2218     * 0 - ON
2219     * 1 - FLASHING
2220     *
2221     * @hide
2222     */
2223    public int getCdmaEriIconMode() {
2224        return getCdmaEriIconMode(getDefaultSubscription());
2225    }
2226
2227    /**
2228     * Returns the CDMA ERI icon mode for a subscription.
2229     * 0 - ON
2230     * 1 - FLASHING
2231     */
2232    /** {@hide} */
2233    public int getCdmaEriIconMode(long subId) {
2234        try {
2235            return getITelephony().getCdmaEriIconModeForSubscriber(subId);
2236        } catch (RemoteException ex) {
2237            // the phone process is restarting.
2238            return -1;
2239        } catch (NullPointerException ex) {
2240            return -1;
2241        }
2242    }
2243
2244    /**
2245     * Returns the CDMA ERI text,
2246     *
2247     * @hide
2248     */
2249    public String getCdmaEriText() {
2250        return getCdmaEriText(getDefaultSubscription());
2251    }
2252
2253    /**
2254     * Returns the CDMA ERI text, of a subscription
2255     *
2256     */
2257    /** {@hide} */
2258    public String getCdmaEriText(long subId) {
2259        try {
2260            return getITelephony().getCdmaEriTextForSubscriber(subId);
2261        } catch (RemoteException ex) {
2262            // the phone process is restarting.
2263            return null;
2264        } catch (NullPointerException ex) {
2265            return null;
2266        }
2267    }
2268
2269    /**
2270     * @return true if the current device is "voice capable".
2271     * <p>
2272     * "Voice capable" means that this device supports circuit-switched
2273     * (i.e. voice) phone calls over the telephony network, and is allowed
2274     * to display the in-call UI while a cellular voice call is active.
2275     * This will be false on "data only" devices which can't make voice
2276     * calls and don't support any in-call UI.
2277     * <p>
2278     * Note: the meaning of this flag is subtly different from the
2279     * PackageManager.FEATURE_TELEPHONY system feature, which is available
2280     * on any device with a telephony radio, even if the device is
2281     * data-only.
2282     *
2283     * @hide pending API review
2284     */
2285    public boolean isVoiceCapable() {
2286        if (mContext == null) return true;
2287        return mContext.getResources().getBoolean(
2288                com.android.internal.R.bool.config_voice_capable);
2289    }
2290
2291    /**
2292     * @return true if the current device supports sms service.
2293     * <p>
2294     * If true, this means that the device supports both sending and
2295     * receiving sms via the telephony network.
2296     * <p>
2297     * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are
2298     *       disabled when device doesn't support sms.
2299     */
2300    public boolean isSmsCapable() {
2301        if (mContext == null) return true;
2302        return mContext.getResources().getBoolean(
2303                com.android.internal.R.bool.config_sms_capable);
2304    }
2305
2306    /**
2307     * Returns all observed cell information from all radios on the
2308     * device including the primary and neighboring cells. This does
2309     * not cause or change the rate of PhoneStateListner#onCellInfoChanged.
2310     *<p>
2311     * The list can include one or more of {@link android.telephony.CellInfoGsm CellInfoGsm},
2312     * {@link android.telephony.CellInfoCdma CellInfoCdma},
2313     * {@link android.telephony.CellInfoLte CellInfoLte} and
2314     * {@link android.telephony.CellInfoWcdma CellInfoCdma} in any combination.
2315     * Specifically on devices with multiple radios it is typical to see instances of
2316     * one or more of any these in the list. In addition 0, 1 or more CellInfo
2317     * objects may return isRegistered() true.
2318     *<p>
2319     * This is preferred over using getCellLocation although for older
2320     * devices this may return null in which case getCellLocation should
2321     * be called.
2322     *<p>
2323     * @return List of CellInfo or null if info unavailable.
2324     *
2325     * <p>Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}
2326     */
2327    public List<CellInfo> getAllCellInfo() {
2328        try {
2329            return getITelephony().getAllCellInfo();
2330        } catch (RemoteException ex) {
2331            return null;
2332        } catch (NullPointerException ex) {
2333            return null;
2334        }
2335    }
2336
2337    /**
2338     * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged
2339     * PhoneStateListener.onCellInfoChanged} will be invoked.
2340     *<p>
2341     * The default, 0, means invoke onCellInfoChanged when any of the reported
2342     * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue
2343     * A onCellInfoChanged.
2344     *<p>
2345     * @param rateInMillis the rate
2346     *
2347     * @hide
2348     */
2349    public void setCellInfoListRate(int rateInMillis) {
2350        try {
2351            getITelephony().setCellInfoListRate(rateInMillis);
2352        } catch (RemoteException ex) {
2353        } catch (NullPointerException ex) {
2354        }
2355    }
2356
2357    /**
2358     * Returns the MMS user agent.
2359     */
2360    public String getMmsUserAgent() {
2361        if (mContext == null) return null;
2362        return mContext.getResources().getString(
2363                com.android.internal.R.string.config_mms_user_agent);
2364    }
2365
2366    /**
2367     * Returns the MMS user agent profile URL.
2368     */
2369    public String getMmsUAProfUrl() {
2370        if (mContext == null) return null;
2371        return mContext.getResources().getString(
2372                com.android.internal.R.string.config_mms_user_agent_profile_url);
2373    }
2374
2375    /**
2376     * Opens a logical channel to the ICC card.
2377     *
2378     * Input parameters equivalent to TS 27.007 AT+CCHO command.
2379     *
2380     * <p>Requires Permission:
2381     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2382     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2383     *
2384     * @param AID Application id. See ETSI 102.221 and 101.220.
2385     * @return an IccOpenLogicalChannelResponse object.
2386     */
2387    public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) {
2388        try {
2389            return getITelephony().iccOpenLogicalChannel(AID);
2390        } catch (RemoteException ex) {
2391        } catch (NullPointerException ex) {
2392        }
2393        return null;
2394    }
2395
2396    /**
2397     * Closes a previously opened logical channel to the ICC card.
2398     *
2399     * Input parameters equivalent to TS 27.007 AT+CCHC command.
2400     *
2401     * <p>Requires Permission:
2402     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2403     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2404     *
2405     * @param channel is the channel id to be closed as retruned by a successful
2406     *            iccOpenLogicalChannel.
2407     * @return true if the channel was closed successfully.
2408     */
2409    public boolean iccCloseLogicalChannel(int channel) {
2410        try {
2411            return getITelephony().iccCloseLogicalChannel(channel);
2412        } catch (RemoteException ex) {
2413        } catch (NullPointerException ex) {
2414        }
2415        return false;
2416    }
2417
2418    /**
2419     * Transmit an APDU to the ICC card over a logical channel.
2420     *
2421     * Input parameters equivalent to TS 27.007 AT+CGLA command.
2422     *
2423     * <p>Requires Permission:
2424     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2425     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2426     *
2427     * @param channel is the channel id to be closed as returned by a successful
2428     *            iccOpenLogicalChannel.
2429     * @param cla Class of the APDU command.
2430     * @param instruction Instruction of the APDU command.
2431     * @param p1 P1 value of the APDU command.
2432     * @param p2 P2 value of the APDU command.
2433     * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU
2434     *            is sent to the SIM.
2435     * @param data Data to be sent with the APDU.
2436     * @return The APDU response from the ICC card with the status appended at
2437     *            the end.
2438     */
2439    public String iccTransmitApduLogicalChannel(int channel, int cla,
2440            int instruction, int p1, int p2, int p3, String data) {
2441        try {
2442            return getITelephony().iccTransmitApduLogicalChannel(channel, cla,
2443                    instruction, p1, p2, p3, data);
2444        } catch (RemoteException ex) {
2445        } catch (NullPointerException ex) {
2446        }
2447        return "";
2448    }
2449
2450    /**
2451     * Transmit an APDU to the ICC card over the basic channel.
2452     *
2453     * Input parameters equivalent to TS 27.007 AT+CSIM command.
2454     *
2455     * <p>Requires Permission:
2456     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2457     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2458     *
2459     * @param cla Class of the APDU command.
2460     * @param instruction Instruction of the APDU command.
2461     * @param p1 P1 value of the APDU command.
2462     * @param p2 P2 value of the APDU command.
2463     * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU
2464     *            is sent to the SIM.
2465     * @param data Data to be sent with the APDU.
2466     * @return The APDU response from the ICC card with the status appended at
2467     *            the end.
2468     */
2469    public String iccTransmitApduBasicChannel(int cla,
2470            int instruction, int p1, int p2, int p3, String data) {
2471        try {
2472            return getITelephony().iccTransmitApduBasicChannel(cla,
2473                    instruction, p1, p2, p3, data);
2474        } catch (RemoteException ex) {
2475        } catch (NullPointerException ex) {
2476        }
2477        return "";
2478    }
2479
2480    /**
2481     * Returns the response APDU for a command APDU sent through SIM_IO.
2482     *
2483     * <p>Requires Permission:
2484     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2485     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2486     *
2487     * @param fileID
2488     * @param command
2489     * @param p1 P1 value of the APDU command.
2490     * @param p2 P2 value of the APDU command.
2491     * @param p3 P3 value of the APDU command.
2492     * @param filePath
2493     * @return The APDU response.
2494     */
2495    public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3,
2496            String filePath) {
2497        try {
2498            return getITelephony().iccExchangeSimIO(fileID, command, p1, p2,
2499                p3, filePath);
2500        } catch (RemoteException ex) {
2501        } catch (NullPointerException ex) {
2502        }
2503        return null;
2504    }
2505
2506    /**
2507     * Send ENVELOPE to the SIM and return the response.
2508     *
2509     * <p>Requires Permission:
2510     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2511     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2512     *
2513     * @param content String containing SAT/USAT response in hexadecimal
2514     *                format starting with command tag. See TS 102 223 for
2515     *                details.
2516     * @return The APDU response from the ICC card in hexadecimal format
2517     *         with the last 4 bytes being the status word. If the command fails,
2518     *         returns an empty string.
2519     */
2520    public String sendEnvelopeWithStatus(String content) {
2521        try {
2522            return getITelephony().sendEnvelopeWithStatus(content);
2523        } catch (RemoteException ex) {
2524        } catch (NullPointerException ex) {
2525        }
2526        return "";
2527    }
2528
2529    /**
2530     * Read one of the NV items defined in com.android.internal.telephony.RadioNVItems.
2531     * Used for device configuration by some CDMA operators.
2532     * <p>
2533     * Requires Permission:
2534     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2535     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2536     *
2537     * @param itemID the ID of the item to read.
2538     * @return the NV item as a String, or null on any failure.
2539     *
2540     * @hide
2541     */
2542    public String nvReadItem(int itemID) {
2543        try {
2544            return getITelephony().nvReadItem(itemID);
2545        } catch (RemoteException ex) {
2546            Rlog.e(TAG, "nvReadItem RemoteException", ex);
2547        } catch (NullPointerException ex) {
2548            Rlog.e(TAG, "nvReadItem NPE", ex);
2549        }
2550        return "";
2551    }
2552
2553    /**
2554     * Write one of the NV items defined in com.android.internal.telephony.RadioNVItems.
2555     * Used for device configuration by some CDMA operators.
2556     * <p>
2557     * Requires Permission:
2558     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2559     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2560     *
2561     * @param itemID the ID of the item to read.
2562     * @param itemValue the value to write, as a String.
2563     * @return true on success; false on any failure.
2564     *
2565     * @hide
2566     */
2567    public boolean nvWriteItem(int itemID, String itemValue) {
2568        try {
2569            return getITelephony().nvWriteItem(itemID, itemValue);
2570        } catch (RemoteException ex) {
2571            Rlog.e(TAG, "nvWriteItem RemoteException", ex);
2572        } catch (NullPointerException ex) {
2573            Rlog.e(TAG, "nvWriteItem NPE", ex);
2574        }
2575        return false;
2576    }
2577
2578    /**
2579     * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2580     * Used for device configuration by some CDMA operators.
2581     * <p>
2582     * Requires Permission:
2583     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2584     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2585     *
2586     * @param preferredRoamingList byte array containing the new PRL.
2587     * @return true on success; false on any failure.
2588     *
2589     * @hide
2590     */
2591    public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
2592        try {
2593            return getITelephony().nvWriteCdmaPrl(preferredRoamingList);
2594        } catch (RemoteException ex) {
2595            Rlog.e(TAG, "nvWriteCdmaPrl RemoteException", ex);
2596        } catch (NullPointerException ex) {
2597            Rlog.e(TAG, "nvWriteCdmaPrl NPE", ex);
2598        }
2599        return false;
2600    }
2601
2602    /**
2603     * Perform the specified type of NV config reset. The radio will be taken offline
2604     * and the device must be rebooted after the operation. Used for device
2605     * configuration by some CDMA operators.
2606     * <p>
2607     * Requires Permission:
2608     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2609     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2610     *
2611     * @param resetType reset type: 1: reload NV reset, 2: erase NV reset, 3: factory NV reset
2612     * @return true on success; false on any failure.
2613     *
2614     * @hide
2615     */
2616    public boolean nvResetConfig(int resetType) {
2617        try {
2618            return getITelephony().nvResetConfig(resetType);
2619        } catch (RemoteException ex) {
2620            Rlog.e(TAG, "nvResetConfig RemoteException", ex);
2621        } catch (NullPointerException ex) {
2622            Rlog.e(TAG, "nvResetConfig NPE", ex);
2623        }
2624        return false;
2625    }
2626
2627    /**
2628     * Returns Default subscription.
2629     */
2630    private static long getDefaultSubscription() {
2631        return SubscriptionManager.getDefaultSubId();
2632    }
2633
2634    /** {@hide} */
2635    public int getDefaultSim() {
2636        //TODO Need to get it from Telephony Devcontroller
2637        return 0;
2638    }
2639
2640    /**
2641     * Sets the telephony property with the value specified.
2642     *
2643     * @hide
2644     */
2645    public static void setTelephonyProperty(String property, long subId, String value) {
2646        String propVal = "";
2647        String p[] = null;
2648        String prop = SystemProperties.get(property);
2649        int phoneId = SubscriptionManager.getPhoneId(subId);
2650
2651        if (value == null) {
2652            value = "";
2653        }
2654
2655        if (prop != null) {
2656            p = prop.split(",");
2657        }
2658
2659        if (phoneId < 0) return;
2660
2661        for (int i = 0; i < phoneId; i++) {
2662            String str = "";
2663            if ((p != null) && (i < p.length)) {
2664                str = p[i];
2665            }
2666            propVal = propVal + str + ",";
2667        }
2668
2669        propVal = propVal + value;
2670        if (p != null) {
2671            for (int i = phoneId + 1; i < p.length; i++) {
2672                propVal = propVal + "," + p[i];
2673            }
2674        }
2675
2676        // TODO: workaround for QC
2677        if (property.length() > SystemProperties.PROP_NAME_MAX || propVal.length() > SystemProperties.PROP_VALUE_MAX) {
2678            Rlog.d(TAG, "setTelephonyProperty length too long:" + property + ", " + propVal);
2679            return;
2680        }
2681
2682        Rlog.d(TAG, "setTelephonyProperty property=" + property + " propVal=" + propVal);
2683        SystemProperties.set(property, propVal);
2684    }
2685
2686    /**
2687     * Convenience function for retrieving a value from the secure settings
2688     * value list as an integer.  Note that internally setting values are
2689     * always stored as strings; this function converts the string to an
2690     * integer for you.
2691     * <p>
2692     * This version does not take a default value.  If the setting has not
2693     * been set, or the string value is not a number,
2694     * it throws {@link SettingNotFoundException}.
2695     *
2696     * @param cr The ContentResolver to access.
2697     * @param name The name of the setting to retrieve.
2698     * @param index The index of the list
2699     *
2700     * @throws SettingNotFoundException Thrown if a setting by the given
2701     * name can't be found or the setting value is not an integer.
2702     *
2703     * @return The value at the given index of settings.
2704     * @hide
2705     */
2706    public static int getIntAtIndex(android.content.ContentResolver cr,
2707            String name, int index)
2708            throws android.provider.Settings.SettingNotFoundException {
2709        String v = android.provider.Settings.Global.getString(cr, name);
2710        if (v != null) {
2711            String valArray[] = v.split(",");
2712            if ((index >= 0) && (index < valArray.length) && (valArray[index] != null)) {
2713                try {
2714                    return Integer.parseInt(valArray[index]);
2715                } catch (NumberFormatException e) {
2716                    //Log.e(TAG, "Exception while parsing Integer: ", e);
2717                }
2718            }
2719        }
2720        throw new android.provider.Settings.SettingNotFoundException(name);
2721    }
2722
2723    /**
2724     * Convenience function for updating settings value as coma separated
2725     * integer values. This will either create a new entry in the table if the
2726     * given name does not exist, or modify the value of the existing row
2727     * with that name.  Note that internally setting values are always
2728     * stored as strings, so this function converts the given value to a
2729     * string before storing it.
2730     *
2731     * @param cr The ContentResolver to access.
2732     * @param name The name of the setting to modify.
2733     * @param index The index of the list
2734     * @param value The new value for the setting to be added to the list.
2735     * @return true if the value was set, false on database errors
2736     * @hide
2737     */
2738    public static boolean putIntAtIndex(android.content.ContentResolver cr,
2739            String name, int index, int value) {
2740        String data = "";
2741        String valArray[] = null;
2742        String v = android.provider.Settings.Global.getString(cr, name);
2743
2744        if (v != null) {
2745            valArray = v.split(",");
2746        }
2747
2748        // Copy the elements from valArray till index
2749        for (int i = 0; i < index; i++) {
2750            String str = "";
2751            if ((valArray != null) && (i < valArray.length)) {
2752                str = valArray[i];
2753            }
2754            data = data + str + ",";
2755        }
2756
2757        data = data + value;
2758
2759        // Copy the remaining elements from valArray if any.
2760        if (valArray != null) {
2761            for (int i = index+1; i < valArray.length; i++) {
2762                data = data + "," + valArray[i];
2763            }
2764        }
2765        return android.provider.Settings.Global.putString(cr, name, data);
2766    }
2767
2768    /**
2769     * Gets the telephony property.
2770     *
2771     * @hide
2772     */
2773    public static String getTelephonyProperty(String property, long subId, String defaultVal) {
2774        String propVal = null;
2775        int phoneId = SubscriptionManager.getPhoneId(subId);
2776        String prop = SystemProperties.get(property);
2777        if ((prop != null) && (prop.length() > 0)) {
2778            String values[] = prop.split(",");
2779            if ((phoneId >= 0) && (phoneId < values.length) && (values[phoneId] != null)) {
2780                propVal = values[phoneId];
2781            }
2782        }
2783        return propVal == null ? defaultVal : propVal;
2784    }
2785
2786    /** @hide */
2787    public int getSimCount() {
2788        if(isMultiSimEnabled()) {
2789        //TODO Need to get it from Telephony Devcontroller
2790            return 2;
2791        } else {
2792           return 1;
2793        }
2794    }
2795
2796    /**
2797     * Returns the IMS Service Table (IST) that was loaded from the ISIM.
2798     * @return IMS Service Table or null if not present or not loaded
2799     * @hide
2800     */
2801    public String getIsimIst() {
2802        try {
2803            return getSubscriberInfo().getIsimIst();
2804        } catch (RemoteException ex) {
2805            return null;
2806        } catch (NullPointerException ex) {
2807            // This could happen before phone restarts due to crashing
2808            return null;
2809        }
2810    }
2811
2812    /**
2813     * Returns the IMS Proxy Call Session Control Function(PCSCF) that were loaded from the ISIM.
2814     * @return an array of PCSCF strings with one PCSCF per string, or null if
2815     *         not present or not loaded
2816     * @hide
2817     */
2818    public String[] getIsimPcscf() {
2819        try {
2820            return getSubscriberInfo().getIsimPcscf();
2821        } catch (RemoteException ex) {
2822            return null;
2823        } catch (NullPointerException ex) {
2824            // This could happen before phone restarts due to crashing
2825            return null;
2826        }
2827    }
2828
2829    /**
2830     * Returns the response of ISIM Authetification through RIL.
2831     * Returns null if the Authentification hasn't been successed or isn't present iphonesubinfo.
2832     * @return the response of ISIM Authetification, or null if not available
2833     * @hide
2834     * @deprecated
2835     * @see getIccSimChallengeResponse with appType=PhoneConstants.APPTYPE_ISIM
2836     */
2837    public String getIsimChallengeResponse(String nonce){
2838        try {
2839            return getSubscriberInfo().getIsimChallengeResponse(nonce);
2840        } catch (RemoteException ex) {
2841            return null;
2842        } catch (NullPointerException ex) {
2843            // This could happen before phone restarts due to crashing
2844            return null;
2845        }
2846    }
2847
2848    /**
2849     * Returns the response of SIM Authentication through RIL.
2850     * Returns null if the Authentication hasn't been successful
2851     * @param subId subscription ID to be queried
2852     * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx)
2853     * @param data authentication challenge data
2854     * @return the response of SIM Authentication, or null if not available
2855     * @hide
2856     */
2857    public String getIccSimChallengeResponse(long subId, int appType, String data) {
2858        try {
2859            return getSubscriberInfo().getIccSimChallengeResponse(subId, appType, data);
2860        } catch (RemoteException ex) {
2861            return null;
2862        } catch (NullPointerException ex) {
2863            // This could happen before phone starts
2864            return null;
2865        }
2866    }
2867
2868    /**
2869     * Returns the response of SIM Authentication through RIL for the default subscription.
2870     * Returns null if the Authentication hasn't been successful
2871     * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx)
2872     * @param data authentication challenge data
2873     * @return the response of SIM Authentication, or null if not available
2874     * @hide
2875     */
2876    public String getIccSimChallengeResponse(int appType, String data) {
2877        return getIccSimChallengeResponse(getDefaultSubscription(), appType, data);
2878    }
2879
2880    /**
2881     * Get P-CSCF address from PCO after data connection is established or modified.
2882     * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN
2883     * @return array of P-CSCF address
2884     * @hide
2885     */
2886    public String[] getPcscfAddress(String apnType) {
2887        try {
2888            return getITelephony().getPcscfAddress(apnType);
2889        } catch (RemoteException e) {
2890            return new String[0];
2891        }
2892    }
2893
2894    /**
2895     * Set IMS registration state
2896     *
2897     * @param Registration state
2898     * @hide
2899     */
2900    public void setImsRegistrationState(boolean registered) {
2901        try {
2902            getITelephony().setImsRegistrationState(registered);
2903        } catch (RemoteException e) {
2904        }
2905    }
2906
2907    /**
2908     * Get the preferred network type.
2909     * Used for device configuration by some CDMA operators.
2910     * <p>
2911     * Requires Permission:
2912     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2913     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2914     *
2915     * @return the preferred network type, defined in RILConstants.java.
2916     * @hide
2917     */
2918    public int getPreferredNetworkType() {
2919        try {
2920            return getITelephony().getPreferredNetworkType();
2921        } catch (RemoteException ex) {
2922            Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex);
2923        } catch (NullPointerException ex) {
2924            Rlog.e(TAG, "getPreferredNetworkType NPE", ex);
2925        }
2926        return -1;
2927    }
2928
2929    /**
2930     * Set the preferred network type.
2931     * Used for device configuration by some CDMA operators.
2932     * <p>
2933     * Requires Permission:
2934     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2935     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2936     *
2937     * @param networkType the preferred network type, defined in RILConstants.java.
2938     * @return true on success; false on any failure.
2939     * @hide
2940     */
2941    public boolean setPreferredNetworkType(int networkType) {
2942        try {
2943            return getITelephony().setPreferredNetworkType(networkType);
2944        } catch (RemoteException ex) {
2945            Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex);
2946        } catch (NullPointerException ex) {
2947            Rlog.e(TAG, "setPreferredNetworkType NPE", ex);
2948        }
2949        return false;
2950    }
2951
2952    /**
2953     * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA.
2954     *
2955     * <p>
2956     * Requires Permission:
2957     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2958     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2959     *
2960     * @return true on success; false on any failure.
2961     */
2962    public boolean setGlobalPreferredNetworkType() {
2963        return setPreferredNetworkType(RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA);
2964    }
2965
2966    /**
2967     * Values used to return status for hasCarrierPrivileges call.
2968     */
2969    public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1;
2970    public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0;
2971    public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1;
2972    public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2;
2973
2974    /**
2975     * Has the calling application been granted carrier privileges by the carrier.
2976     *
2977     * If any of the packages in the calling UID has carrier privileges, the
2978     * call will return true. This access is granted by the owner of the UICC
2979     * card and does not depend on the registered carrier.
2980     *
2981     * TODO: Add a link to documentation.
2982     *
2983     * @return CARRIER_PRIVILEGE_STATUS_HAS_ACCESS if the app has carrier privileges.
2984     *         CARRIER_PRIVILEGE_STATUS_NO_ACCESS if the app does not have carrier privileges.
2985     *         CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED if the carrier rules are not loaded.
2986     *         CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES if there was an error loading carrier
2987     *             rules (or if there are no rules).
2988     */
2989    public int hasCarrierPrivileges() {
2990        try {
2991            return getITelephony().hasCarrierPrivileges();
2992        } catch (RemoteException ex) {
2993            Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex);
2994        } catch (NullPointerException ex) {
2995            Rlog.e(TAG, "hasCarrierPrivileges NPE", ex);
2996        }
2997        return CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2998    }
2999
3000    /**
3001     * Override the branding for the current ICCID.
3002     *
3003     * Once set, whenever the SIM is present in the device, the service
3004     * provider name (SPN) and the operator name will both be replaced by the
3005     * brand value input. To unset the value, the same function should be
3006     * called with a null brand value.
3007     *
3008     * <p>Requires Permission:
3009     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
3010     *  or has to be carrier app - see #hasCarrierPrivileges.
3011     *
3012     * @param brand The brand name to display/set.
3013     * @return true if the operation was executed correctly.
3014     */
3015    public boolean setOperatorBrandOverride(String brand) {
3016        try {
3017            return getITelephony().setOperatorBrandOverride(brand);
3018        } catch (RemoteException ex) {
3019            Rlog.e(TAG, "setOperatorBrandOverride RemoteException", ex);
3020        } catch (NullPointerException ex) {
3021            Rlog.e(TAG, "setOperatorBrandOverride NPE", ex);
3022        }
3023        return false;
3024    }
3025
3026    /**
3027     * Expose the rest of ITelephony to @SystemApi
3028     */
3029
3030    /** @hide */
3031    @SystemApi
3032    public String getCdmaMdn() {
3033        return getCdmaMdn(getDefaultSubscription());
3034    }
3035
3036    /** @hide */
3037    @SystemApi
3038    public String getCdmaMdn(long subId) {
3039        try {
3040            return getITelephony().getCdmaMdn(subId);
3041        } catch (RemoteException ex) {
3042            return null;
3043        } catch (NullPointerException ex) {
3044            return null;
3045        }
3046    }
3047
3048    /** @hide */
3049    @SystemApi
3050    public String getCdmaMin() {
3051        return getCdmaMin(getDefaultSubscription());
3052    }
3053
3054    /** @hide */
3055    @SystemApi
3056    public String getCdmaMin(long subId) {
3057        try {
3058            return getITelephony().getCdmaMin(subId);
3059        } catch (RemoteException ex) {
3060            return null;
3061        } catch (NullPointerException ex) {
3062            return null;
3063        }
3064    }
3065
3066    /** @hide */
3067    @SystemApi
3068    public int checkCarrierPrivilegesForPackage(String pkgname) {
3069        try {
3070            return getITelephony().checkCarrierPrivilegesForPackage(pkgname);
3071        } catch (RemoteException ex) {
3072            Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex);
3073        } catch (NullPointerException ex) {
3074            Rlog.e(TAG, "hasCarrierPrivileges NPE", ex);
3075        }
3076        return CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3077    }
3078
3079    /** @hide */
3080    @SystemApi
3081    public List<String> getCarrierPackageNamesForIntent(Intent intent) {
3082        try {
3083            return getITelephony().getCarrierPackageNamesForIntent(intent);
3084        } catch (RemoteException ex) {
3085            Rlog.e(TAG, "getCarrierPackageNamesForIntent RemoteException", ex);
3086        } catch (NullPointerException ex) {
3087            Rlog.e(TAG, "getCarrierPackageNamesForIntent NPE", ex);
3088        }
3089        return null;
3090    }
3091
3092    /** @hide */
3093    @SystemApi
3094    public void dial(String number) {
3095        try {
3096            getITelephony().dial(number);
3097        } catch (RemoteException e) {
3098            Log.e(TAG, "Error calling ITelephony#dial", e);
3099        }
3100    }
3101
3102    /** @hide */
3103    @SystemApi
3104    public void call(String callingPackage, String number) {
3105        try {
3106            getITelephony().call(callingPackage, number);
3107        } catch (RemoteException e) {
3108            Log.e(TAG, "Error calling ITelephony#call", e);
3109        }
3110    }
3111
3112    /** @hide */
3113    @SystemApi
3114    public boolean endCall() {
3115        try {
3116            return getITelephony().endCall();
3117        } catch (RemoteException e) {
3118            Log.e(TAG, "Error calling ITelephony#endCall", e);
3119        }
3120        return false;
3121    }
3122
3123    /** @hide */
3124    @SystemApi
3125    public void answerRingingCall() {
3126        try {
3127            getITelephony().answerRingingCall();
3128        } catch (RemoteException e) {
3129            Log.e(TAG, "Error calling ITelephony#answerRingingCall", e);
3130        }
3131    }
3132
3133    /** @hide */
3134    @SystemApi
3135    public void silenceRinger() {
3136        try {
3137            getTelecommService().silenceRinger();
3138        } catch (RemoteException e) {
3139            Log.e(TAG, "Error calling ITelecommService#silenceRinger", e);
3140        }
3141    }
3142
3143    /** @hide */
3144    @SystemApi
3145    public boolean isOffhook() {
3146        try {
3147            return getITelephony().isOffhook();
3148        } catch (RemoteException e) {
3149            Log.e(TAG, "Error calling ITelephony#isOffhook", e);
3150        }
3151        return false;
3152    }
3153
3154    /** @hide */
3155    @SystemApi
3156    public boolean isRinging() {
3157        try {
3158            return getITelephony().isRinging();
3159        } catch (RemoteException e) {
3160            Log.e(TAG, "Error calling ITelephony#isRinging", e);
3161        }
3162        return false;
3163    }
3164
3165    /** @hide */
3166    @SystemApi
3167    public boolean isIdle() {
3168        try {
3169            return getITelephony().isIdle();
3170        } catch (RemoteException e) {
3171            Log.e(TAG, "Error calling ITelephony#isIdle", e);
3172        }
3173        return true;
3174    }
3175
3176    /** @hide */
3177    @SystemApi
3178    public boolean isRadioOn() {
3179        try {
3180            return getITelephony().isRadioOn();
3181        } catch (RemoteException e) {
3182            Log.e(TAG, "Error calling ITelephony#isRadioOn", e);
3183        }
3184        return false;
3185    }
3186
3187    /** @hide */
3188    @SystemApi
3189    public boolean isSimPinEnabled() {
3190        try {
3191            return getITelephony().isSimPinEnabled();
3192        } catch (RemoteException e) {
3193            Log.e(TAG, "Error calling ITelephony#isSimPinEnabled", e);
3194        }
3195        return false;
3196    }
3197
3198    /** @hide */
3199    @SystemApi
3200    public boolean supplyPin(String pin) {
3201        try {
3202            return getITelephony().supplyPin(pin);
3203        } catch (RemoteException e) {
3204            Log.e(TAG, "Error calling ITelephony#supplyPin", e);
3205        }
3206        return false;
3207    }
3208
3209    /** @hide */
3210    @SystemApi
3211    public boolean supplyPuk(String puk, String pin) {
3212        try {
3213            return getITelephony().supplyPuk(puk, pin);
3214        } catch (RemoteException e) {
3215            Log.e(TAG, "Error calling ITelephony#supplyPuk", e);
3216        }
3217        return false;
3218    }
3219
3220    /** @hide */
3221    @SystemApi
3222    public int[] supplyPinReportResult(String pin) {
3223        try {
3224            return getITelephony().supplyPinReportResult(pin);
3225        } catch (RemoteException e) {
3226            Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e);
3227        }
3228        return new int[0];
3229    }
3230
3231    /** @hide */
3232    @SystemApi
3233    public int[] supplyPukReportResult(String puk, String pin) {
3234        try {
3235            return getITelephony().supplyPukReportResult(puk, pin);
3236        } catch (RemoteException e) {
3237            Log.e(TAG, "Error calling ITelephony#]", e);
3238        }
3239        return new int[0];
3240    }
3241
3242    /** @hide */
3243    @SystemApi
3244    public boolean handlePinMmi(String dialString) {
3245        try {
3246            return getITelephony().handlePinMmi(dialString);
3247        } catch (RemoteException e) {
3248            Log.e(TAG, "Error calling ITelephony#handlePinMmi", e);
3249        }
3250        return false;
3251    }
3252
3253    /** @hide */
3254    @SystemApi
3255    public void toggleRadioOnOff() {
3256        try {
3257            getITelephony().toggleRadioOnOff();
3258        } catch (RemoteException e) {
3259            Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e);
3260        }
3261    }
3262
3263    /** @hide */
3264    @SystemApi
3265    public boolean setRadio(boolean turnOn) {
3266        try {
3267            return getITelephony().setRadio(turnOn);
3268        } catch (RemoteException e) {
3269            Log.e(TAG, "Error calling ITelephony#setRadio", e);
3270        }
3271        return false;
3272    }
3273
3274    /** @hide */
3275    @SystemApi
3276    public boolean setRadioPower(boolean turnOn) {
3277        try {
3278            return getITelephony().setRadioPower(turnOn);
3279        } catch (RemoteException e) {
3280            Log.e(TAG, "Error calling ITelephony#setRadioPower", e);
3281        }
3282        return false;
3283    }
3284
3285    /** @hide */
3286    @SystemApi
3287    public void updateServiceLocation() {
3288        try {
3289            getITelephony().updateServiceLocation();
3290        } catch (RemoteException e) {
3291            Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e);
3292        }
3293    }
3294
3295    /** @hide */
3296    @SystemApi
3297    public boolean enableDataConnectivity() {
3298        try {
3299            return getITelephony().enableDataConnectivity();
3300        } catch (RemoteException e) {
3301            Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e);
3302        }
3303        return false;
3304    }
3305
3306    /** @hide */
3307    @SystemApi
3308    public boolean disableDataConnectivity() {
3309        try {
3310            return getITelephony().disableDataConnectivity();
3311        } catch (RemoteException e) {
3312            Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e);
3313        }
3314        return false;
3315    }
3316
3317    /** @hide */
3318    @SystemApi
3319    public boolean isDataConnectivityPossible() {
3320        try {
3321            return getITelephony().isDataConnectivityPossible();
3322        } catch (RemoteException e) {
3323            Log.e(TAG, "Error calling ITelephony#isDataConnectivityPossible", e);
3324        }
3325        return false;
3326    }
3327
3328    /** @hide */
3329    @SystemApi
3330    public boolean needsOtaServiceProvisioning() {
3331        try {
3332            return getITelephony().needsOtaServiceProvisioning();
3333        } catch (RemoteException e) {
3334            Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e);
3335        }
3336        return false;
3337    }
3338
3339    /** @hide */
3340    @SystemApi
3341    public void setDataEnabled(boolean enable) {
3342        try {
3343            getITelephony().setDataEnabled(enable);
3344        } catch (RemoteException e) {
3345            Log.e(TAG, "Error calling ITelephony#setDataEnabled", e);
3346        }
3347    }
3348
3349    /** @hide */
3350    @SystemApi
3351    public boolean getDataEnabled() {
3352        try {
3353            return getITelephony().getDataEnabled();
3354        } catch (RemoteException e) {
3355            Log.e(TAG, "Error calling ITelephony#getDataEnabled", e);
3356        }
3357        return false;
3358    }
3359
3360    /**
3361     * Set whether Android should display a simplified Mobile Network Settings UI.
3362     * The setting won't be persisted during power cycle.
3363     * <p>
3364     * Requires Permission:
3365     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
3366     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
3367     *
3368     * @param enable true means enabling the simplified UI.
3369     * @hide
3370     */
3371    public void enableSimplifiedNetworkSettings(boolean enable) {
3372        enableSimplifiedNetworkSettings(getDefaultSubscription(), enable);
3373    }
3374
3375    /**
3376     * Set whether Android should display a simplified Mobile Network Settings UI.
3377     * The setting won't be persisted during power cycle.
3378     * <p>
3379     * Requires Permission:
3380     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
3381     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
3382     *
3383     * @param subId for which the simplified UI should be enabled or disabled.
3384     * @param enable true means enabling the simplified UI.
3385     * @hide
3386     */
3387    public void enableSimplifiedNetworkSettings(long subId, boolean enable) {
3388        try {
3389            getITelephony().enableSimplifiedNetworkSettings(subId, enable);
3390        } catch (RemoteException ex) {
3391        } catch (NullPointerException ex) {
3392        }
3393    }
3394
3395    /**
3396     * Get whether a simplified Mobile Network Settings UI is enabled.
3397     * <p>
3398     * Requires Permission:
3399     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3400     *
3401     * @return true if the simplified UI is enabled.
3402     * @hide
3403     */
3404    public boolean getSimplifiedNetworkSettingsEnabled() {
3405        return getSimplifiedNetworkSettingsEnabled(getDefaultSubscription());
3406    }
3407
3408    /**
3409     * Get whether a simplified Mobile Network Settings UI is enabled.
3410     * <p>
3411     * Requires Permission:
3412     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3413     *
3414     * @param subId for which the simplified UI should be enabled or disabled.
3415     * @return true if the simplified UI is enabled.
3416     * @hide
3417     */
3418    public boolean getSimplifiedNetworkSettingsEnabled(long subId) {
3419        try {
3420            return getITelephony().getSimplifiedNetworkSettingsEnabled(subId);
3421        } catch (RemoteException ex) {
3422        } catch (NullPointerException ex) {
3423        }
3424        return false;
3425    }
3426
3427    /**
3428     * Returns the result and response from RIL for oem request
3429     *
3430     * @param oemReq the data is sent to ril.
3431     * @param oemResp the respose data from RIL.
3432     * @return negative value request was not handled or get error
3433     *         0 request was handled succesfully, but no response data
3434     *         positive value success, data length of response
3435     * @hide
3436     */
3437    public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3438        try {
3439            return getITelephony().invokeOemRilRequestRaw(oemReq, oemResp);
3440        } catch (RemoteException ex) {
3441        } catch (NullPointerException ex) {
3442        }
3443        return -1;
3444    }
3445}
3446