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