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