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