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