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