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