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