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