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