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