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