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