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