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