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