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