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