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