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