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