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