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