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