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