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