TelephonyManager.java revision 8110da62ed1bddf8150488613a0747cf6d2fd6a9
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.SystemApi;
20import android.annotation.SdkConstant;
21import android.annotation.SdkConstant.SdkConstantType;
22import android.content.Context;
23import android.content.Intent;
24import android.os.Bundle;
25import android.os.RemoteException;
26import android.os.ServiceManager;
27import android.os.SystemProperties;
28import android.util.Log;
29import android.util.Pair;
30
31import com.android.internal.telecomm.ITelecommService;
32import com.android.internal.telephony.IPhoneSubInfo;
33import com.android.internal.telephony.ITelephony;
34import com.android.internal.telephony.ITelephonyRegistry;
35import com.android.internal.telephony.PhoneConstants;
36import com.android.internal.telephony.RILConstants;
37import com.android.internal.telephony.TelephonyProperties;
38
39import java.io.FileInputStream;
40import java.io.IOException;
41import java.util.List;
42import java.util.regex.Matcher;
43import java.util.regex.Pattern;
44
45/**
46 * Provides access to information about the telephony services on
47 * the device. Applications can use the methods in this class to
48 * determine telephony services and states, as well as to access some
49 * types of subscriber information. Applications can also register
50 * a listener to receive notification of telephony state changes.
51 * <p>
52 * You do not instantiate this class directly; instead, you retrieve
53 * a reference to an instance through
54 * {@link android.content.Context#getSystemService
55 * Context.getSystemService(Context.TELEPHONY_SERVICE)}.
56 * <p>
57 * Note that access to some telephony information is
58 * permission-protected. Your application cannot access the protected
59 * information unless it has the appropriate permissions declared in
60 * its manifest file. Where permissions apply, they are noted in the
61 * the methods through which you access the protected information.
62 */
63public class TelephonyManager {
64    private static final String TAG = "TelephonyManager";
65
66    private static final String TELECOMM_SERVICE_NAME = "telecomm";
67
68    private static ITelephonyRegistry sRegistry;
69
70    /**
71     * The allowed states of Wi-Fi calling.
72     *
73     * @hide
74     */
75    public interface WifiCallingChoices {
76        /** Always use Wi-Fi calling */
77        static final int ALWAYS_USE = 0;
78        /** Ask the user whether to use Wi-Fi on every call */
79        static final int ASK_EVERY_TIME = 1;
80        /** Never use Wi-Fi calling */
81        static final int NEVER_USE = 2;
82    }
83
84    private final Context mContext;
85
86    private static String multiSimConfig =
87            SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG);
88
89    /** Enum indicating multisim variants
90     *  DSDS - Dual SIM Dual Standby
91     *  DSDA - Dual SIM Dual Active
92     *  TSTS - Triple SIM Triple Standby
93     **/
94    /** @hide */
95    public enum MultiSimVariants {
96        DSDS,
97        DSDA,
98        TSTS,
99        UNKNOWN
100    };
101
102    /** @hide */
103    public TelephonyManager(Context context) {
104        Context appContext = context.getApplicationContext();
105        if (appContext != null) {
106            mContext = appContext;
107        } else {
108            mContext = context;
109        }
110
111        if (sRegistry == null) {
112            sRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService(
113                    "telephony.registry"));
114        }
115    }
116
117    /** @hide */
118    private TelephonyManager() {
119        mContext = null;
120    }
121
122    private static TelephonyManager sInstance = new TelephonyManager();
123
124    /** @hide
125    /* @deprecated - use getSystemService as described above */
126    public static TelephonyManager getDefault() {
127        return sInstance;
128    }
129
130
131    /**
132     * Returns the multi SIM variant
133     * Returns DSDS for Dual SIM Dual Standby
134     * Returns DSDA for Dual SIM Dual Active
135     * Returns TSTS for Triple SIM Triple Standby
136     * Returns UNKNOWN for others
137     */
138    /** {@hide} */
139    public MultiSimVariants getMultiSimConfiguration() {
140        String mSimConfig =
141            SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG);
142        if (mSimConfig.equals("dsds")) {
143            return MultiSimVariants.DSDS;
144        } else if (mSimConfig.equals("dsda")) {
145            return MultiSimVariants.DSDA;
146        } else if (mSimConfig.equals("tsts")) {
147            return MultiSimVariants.TSTS;
148        } else {
149            return MultiSimVariants.UNKNOWN;
150        }
151    }
152
153
154    /**
155     * Returns the number of phones available.
156     * Returns 1 for Single standby mode (Single SIM functionality)
157     * Returns 2 for Dual standby mode.(Dual SIM functionality)
158     */
159    /** {@hide} */
160    public int getPhoneCount() {
161        int phoneCount = 1;
162        switch (getMultiSimConfiguration()) {
163            case DSDS:
164            case DSDA:
165                phoneCount = PhoneConstants.MAX_PHONE_COUNT_DUAL_SIM;
166                break;
167            case TSTS:
168                phoneCount = PhoneConstants.MAX_PHONE_COUNT_TRI_SIM;
169                break;
170        }
171        return phoneCount;
172    }
173
174    /** {@hide} */
175    public static TelephonyManager from(Context context) {
176        return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
177    }
178
179    /** {@hide} */
180    public boolean isMultiSimEnabled() {
181        return (multiSimConfig.equals("dsds") || multiSimConfig.equals("dsda") ||
182            multiSimConfig.equals("tsts"));
183    }
184
185    //
186    // Broadcast Intent actions
187    //
188
189    /**
190     * Broadcast intent action indicating that the call state (cellular)
191     * on the device has changed.
192     *
193     * <p>
194     * The {@link #EXTRA_STATE} extra indicates the new call state.
195     * If the new state is RINGING, a second extra
196     * {@link #EXTRA_INCOMING_NUMBER} provides the incoming phone number as
197     * a String.
198     *
199     * <p class="note">
200     * Requires the READ_PHONE_STATE permission.
201     *
202     * <p class="note">
203     * This was a {@link android.content.Context#sendStickyBroadcast sticky}
204     * broadcast in version 1.0, but it is no longer sticky.
205     * Instead, use {@link #getCallState} to synchronously query the current call state.
206     *
207     * @see #EXTRA_STATE
208     * @see #EXTRA_INCOMING_NUMBER
209     * @see #getCallState
210     */
211    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
212    public static final String ACTION_PHONE_STATE_CHANGED =
213            "android.intent.action.PHONE_STATE";
214
215    /**
216     * The Phone app sends this intent when a user opts to respond-via-message during an incoming
217     * call. By default, the device's default SMS app consumes this message and sends a text message
218     * to the caller. A third party app can also provide this functionality by consuming this Intent
219     * with a {@link android.app.Service} and sending the message using its own messaging system.
220     * <p>The intent contains a URI (available from {@link android.content.Intent#getData})
221     * describing the recipient, using either the {@code sms:}, {@code smsto:}, {@code mms:},
222     * or {@code mmsto:} URI schema. Each of these URI schema carry the recipient information the
223     * same way: the path part of the URI contains the recipient's phone number or a comma-separated
224     * set of phone numbers if there are multiple recipients. For example, {@code
225     * smsto:2065551234}.</p>
226     *
227     * <p>The intent may also contain extras for the message text (in {@link
228     * android.content.Intent#EXTRA_TEXT}) and a message subject
229     * (in {@link android.content.Intent#EXTRA_SUBJECT}).</p>
230     *
231     * <p class="note"><strong>Note:</strong>
232     * The intent-filter that consumes this Intent needs to be in a {@link android.app.Service}
233     * that requires the
234     * permission {@link android.Manifest.permission#SEND_RESPOND_VIA_MESSAGE}.</p>
235     * <p>For example, the service that receives this intent can be declared in the manifest file
236     * with an intent filter like this:</p>
237     * <pre>
238     * &lt;!-- Service that delivers SMS messages received from the phone "quick response" -->
239     * &lt;service android:name=".HeadlessSmsSendService"
240     *          android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
241     *          android:exported="true" >
242     *   &lt;intent-filter>
243     *     &lt;action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
244     *     &lt;category android:name="android.intent.category.DEFAULT" />
245     *     &lt;data android:scheme="sms" />
246     *     &lt;data android:scheme="smsto" />
247     *     &lt;data android:scheme="mms" />
248     *     &lt;data android:scheme="mmsto" />
249     *   &lt;/intent-filter>
250     * &lt;/service></pre>
251     * <p>
252     * Output: nothing.
253     */
254    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
255    public static final String ACTION_RESPOND_VIA_MESSAGE =
256            "android.intent.action.RESPOND_VIA_MESSAGE";
257
258    /**
259     * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast
260     * for a String containing the new call state.
261     *
262     * @see #EXTRA_STATE_IDLE
263     * @see #EXTRA_STATE_RINGING
264     * @see #EXTRA_STATE_OFFHOOK
265     *
266     * <p class="note">
267     * Retrieve with
268     * {@link android.content.Intent#getStringExtra(String)}.
269     */
270    public static final String EXTRA_STATE = PhoneConstants.STATE_KEY;
271
272    /**
273     * Value used with {@link #EXTRA_STATE} corresponding to
274     * {@link #CALL_STATE_IDLE}.
275     */
276    public static final String EXTRA_STATE_IDLE = PhoneConstants.State.IDLE.toString();
277
278    /**
279     * Value used with {@link #EXTRA_STATE} corresponding to
280     * {@link #CALL_STATE_RINGING}.
281     */
282    public static final String EXTRA_STATE_RINGING = PhoneConstants.State.RINGING.toString();
283
284    /**
285     * Value used with {@link #EXTRA_STATE} corresponding to
286     * {@link #CALL_STATE_OFFHOOK}.
287     */
288    public static final String EXTRA_STATE_OFFHOOK = PhoneConstants.State.OFFHOOK.toString();
289
290    /**
291     * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast
292     * for a String containing the incoming phone number.
293     * Only valid when the new call state is RINGING.
294     *
295     * <p class="note">
296     * Retrieve with
297     * {@link android.content.Intent#getStringExtra(String)}.
298     */
299    public static final String EXTRA_INCOMING_NUMBER = "incoming_number";
300
301    /**
302     * Broadcast intent action indicating that a precise call state
303     * (cellular) on the device has changed.
304     *
305     * <p>
306     * The {@link #EXTRA_RINGING_CALL_STATE} extra indicates the ringing call state.
307     * The {@link #EXTRA_FOREGROUND_CALL_STATE} extra indicates the foreground call state.
308     * The {@link #EXTRA_BACKGROUND_CALL_STATE} extra indicates the background call state.
309     * The {@link #EXTRA_DISCONNECT_CAUSE} extra indicates the disconnect cause.
310     * The {@link #EXTRA_PRECISE_DISCONNECT_CAUSE} extra indicates the precise disconnect cause.
311     *
312     * <p class="note">
313     * Requires the READ_PRECISE_PHONE_STATE permission.
314     *
315     * @see #EXTRA_RINGING_CALL_STATE
316     * @see #EXTRA_FOREGROUND_CALL_STATE
317     * @see #EXTRA_BACKGROUND_CALL_STATE
318     * @see #EXTRA_DISCONNECT_CAUSE
319     * @see #EXTRA_PRECISE_DISCONNECT_CAUSE
320     *
321     * <p class="note">
322     * Requires the READ_PRECISE_PHONE_STATE permission.
323     *
324     * @hide
325     */
326    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
327    public static final String ACTION_PRECISE_CALL_STATE_CHANGED =
328            "android.intent.action.PRECISE_CALL_STATE";
329
330    /**
331     * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast
332     * for an integer containing the state of the current ringing call.
333     *
334     * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID
335     * @see PreciseCallState#PRECISE_CALL_STATE_IDLE
336     * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE
337     * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING
338     * @see PreciseCallState#PRECISE_CALL_STATE_DIALING
339     * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING
340     * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING
341     * @see PreciseCallState#PRECISE_CALL_STATE_WAITING
342     * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED
343     * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING
344     *
345     * <p class="note">
346     * Retrieve with
347     * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
348     *
349     * @hide
350     */
351    public static final String EXTRA_RINGING_CALL_STATE = "ringing_state";
352
353    /**
354     * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast
355     * for an integer containing the state of the current foreground call.
356     *
357     * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID
358     * @see PreciseCallState#PRECISE_CALL_STATE_IDLE
359     * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE
360     * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING
361     * @see PreciseCallState#PRECISE_CALL_STATE_DIALING
362     * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING
363     * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING
364     * @see PreciseCallState#PRECISE_CALL_STATE_WAITING
365     * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED
366     * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING
367     *
368     * <p class="note">
369     * Retrieve with
370     * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
371     *
372     * @hide
373     */
374    public static final String EXTRA_FOREGROUND_CALL_STATE = "foreground_state";
375
376    /**
377     * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast
378     * for an integer containing the state of the current background call.
379     *
380     * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID
381     * @see PreciseCallState#PRECISE_CALL_STATE_IDLE
382     * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE
383     * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING
384     * @see PreciseCallState#PRECISE_CALL_STATE_DIALING
385     * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING
386     * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING
387     * @see PreciseCallState#PRECISE_CALL_STATE_WAITING
388     * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED
389     * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING
390     *
391     * <p class="note">
392     * Retrieve with
393     * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
394     *
395     * @hide
396     */
397    public static final String EXTRA_BACKGROUND_CALL_STATE = "background_state";
398
399    /**
400     * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast
401     * for an integer containing the disconnect cause.
402     *
403     * @see DisconnectCause
404     *
405     * <p class="note">
406     * Retrieve with
407     * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
408     *
409     * @hide
410     */
411    public static final String EXTRA_DISCONNECT_CAUSE = "disconnect_cause";
412
413    /**
414     * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast
415     * for an integer containing the disconnect cause provided by the RIL.
416     *
417     * @see PreciseDisconnectCause
418     *
419     * <p class="note">
420     * Retrieve with
421     * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
422     *
423     * @hide
424     */
425    public static final String EXTRA_PRECISE_DISCONNECT_CAUSE = "precise_disconnect_cause";
426
427    /**
428     * Broadcast intent action indicating a data connection has changed,
429     * providing precise information about the connection.
430     *
431     * <p>
432     * The {@link #EXTRA_DATA_STATE} extra indicates the connection state.
433     * The {@link #EXTRA_DATA_NETWORK_TYPE} extra indicates the connection network type.
434     * The {@link #EXTRA_DATA_APN_TYPE} extra indicates the APN type.
435     * The {@link #EXTRA_DATA_APN} extra indicates the APN.
436     * The {@link #EXTRA_DATA_CHANGE_REASON} extra indicates the connection change reason.
437     * The {@link #EXTRA_DATA_IFACE_PROPERTIES} extra indicates the connection interface.
438     * The {@link #EXTRA_DATA_FAILURE_CAUSE} extra indicates the connection fail cause.
439     *
440     * <p class="note">
441     * Requires the READ_PRECISE_PHONE_STATE permission.
442     *
443     * @see #EXTRA_DATA_STATE
444     * @see #EXTRA_DATA_NETWORK_TYPE
445     * @see #EXTRA_DATA_APN_TYPE
446     * @see #EXTRA_DATA_APN
447     * @see #EXTRA_DATA_CHANGE_REASON
448     * @see #EXTRA_DATA_IFACE
449     * @see #EXTRA_DATA_FAILURE_CAUSE
450     * @hide
451     */
452    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
453    public static final String ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED =
454            "android.intent.action.PRECISE_DATA_CONNECTION_STATE_CHANGED";
455
456    /**
457     * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
458     * for an integer containing the state of the current data connection.
459     *
460     * @see TelephonyManager#DATA_UNKNOWN
461     * @see TelephonyManager#DATA_DISCONNECTED
462     * @see TelephonyManager#DATA_CONNECTING
463     * @see TelephonyManager#DATA_CONNECTED
464     * @see TelephonyManager#DATA_SUSPENDED
465     *
466     * <p class="note">
467     * Retrieve with
468     * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
469     *
470     * @hide
471     */
472    public static final String EXTRA_DATA_STATE = PhoneConstants.STATE_KEY;
473
474    /**
475     * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
476     * for an integer containing the network type.
477     *
478     * @see TelephonyManager#NETWORK_TYPE_UNKNOWN
479     * @see TelephonyManager#NETWORK_TYPE_GPRS
480     * @see TelephonyManager#NETWORK_TYPE_EDGE
481     * @see TelephonyManager#NETWORK_TYPE_UMTS
482     * @see TelephonyManager#NETWORK_TYPE_CDMA
483     * @see TelephonyManager#NETWORK_TYPE_EVDO_0
484     * @see TelephonyManager#NETWORK_TYPE_EVDO_A
485     * @see TelephonyManager#NETWORK_TYPE_1xRTT
486     * @see TelephonyManager#NETWORK_TYPE_HSDPA
487     * @see TelephonyManager#NETWORK_TYPE_HSUPA
488     * @see TelephonyManager#NETWORK_TYPE_HSPA
489     * @see TelephonyManager#NETWORK_TYPE_IDEN
490     * @see TelephonyManager#NETWORK_TYPE_EVDO_B
491     * @see TelephonyManager#NETWORK_TYPE_LTE
492     * @see TelephonyManager#NETWORK_TYPE_EHRPD
493     * @see TelephonyManager#NETWORK_TYPE_HSPAP
494     *
495     * <p class="note">
496     * Retrieve with
497     * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
498     *
499     * @hide
500     */
501    public static final String EXTRA_DATA_NETWORK_TYPE = PhoneConstants.DATA_NETWORK_TYPE_KEY;
502
503    /**
504     * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
505     * for an String containing the data APN type.
506     *
507     * <p class="note">
508     * Retrieve with
509     * {@link android.content.Intent#getStringExtra(String name)}.
510     *
511     * @hide
512     */
513    public static final String EXTRA_DATA_APN_TYPE = PhoneConstants.DATA_APN_TYPE_KEY;
514
515    /**
516     * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
517     * for an String containing the data APN.
518     *
519     * <p class="note">
520     * Retrieve with
521     * {@link android.content.Intent#getStringExtra(String name)}.
522     *
523     * @hide
524     */
525    public static final String EXTRA_DATA_APN = PhoneConstants.DATA_APN_KEY;
526
527    /**
528     * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
529     * for an String representation of the change reason.
530     *
531     * <p class="note">
532     * Retrieve with
533     * {@link android.content.Intent#getStringExtra(String name)}.
534     *
535     * @hide
536     */
537    public static final String EXTRA_DATA_CHANGE_REASON = PhoneConstants.STATE_CHANGE_REASON_KEY;
538
539    /**
540     * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
541     * for an String representation of the data interface.
542     *
543     * <p class="note">
544     * Retrieve with
545     * {@link android.content.Intent#getParcelableExtra(String name)}.
546     *
547     * @hide
548     */
549    public static final String EXTRA_DATA_LINK_PROPERTIES_KEY = PhoneConstants.DATA_LINK_PROPERTIES_KEY;
550
551    /**
552     * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
553     * for the data connection fail cause.
554     *
555     * <p class="note">
556     * Retrieve with
557     * {@link android.content.Intent#getStringExtra(String name)}.
558     *
559     * @hide
560     */
561    public static final String EXTRA_DATA_FAILURE_CAUSE = PhoneConstants.DATA_FAILURE_CAUSE_KEY;
562
563    //
564    //
565    // Device Info
566    //
567    //
568
569    /**
570     * Returns the software version number for the device, for example,
571     * the IMEI/SV for GSM phones. Return null if the software version is
572     * not available.
573     *
574     * <p>Requires Permission:
575     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
576     */
577    public String getDeviceSoftwareVersion() {
578        return getDeviceSoftwareVersion(getDefaultSim());
579    }
580
581    /**
582     * Returns the software version number for the device, for example,
583     * the IMEI/SV for GSM phones. Return null if the software version is
584     * not available.
585     *
586     * <p>Requires Permission:
587     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
588     *
589     * @param slotId of which deviceID is returned
590     */
591    /** {@hide} */
592    public String getDeviceSoftwareVersion(int slotId) {
593        // FIXME methods taking slot id should not use subscription, instead us Uicc directly
594        long[] subId = SubscriptionManager.getSubId(slotId);
595        if (subId == null || subId.length == 0) {
596            return null;
597        }
598        try {
599            return getSubscriberInfo().getDeviceSvnUsingSubId(subId[0]);
600        } catch (RemoteException ex) {
601            return null;
602        } catch (NullPointerException ex) {
603            return null;
604        }
605    }
606
607    /**
608     * Returns the unique device ID, for example, the IMEI for GSM and the MEID
609     * or ESN for CDMA phones. Return null if device ID is not available.
610     *
611     * <p>Requires Permission:
612     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
613     */
614    public String getDeviceId() {
615        return getDeviceId(getDefaultSim());
616    }
617
618    /**
619     * Returns the unique device ID of a subscription, for example, the IMEI for
620     * GSM and the MEID for CDMA phones. Return null if device ID is not available.
621     *
622     * <p>Requires Permission:
623     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
624     *
625     * @param slotId of which deviceID is returned
626     */
627    /** {@hide} */
628    public String getDeviceId(int slotId) {
629        // FIXME methods taking slot id should not use subscription, instead us Uicc directly
630        long[] subId = SubscriptionManager.getSubId(slotId);
631        if (subId == null || subId.length == 0) {
632            return null;
633        }
634        try {
635            return getSubscriberInfo().getDeviceIdUsingSubId(subId[0]);
636        } catch (RemoteException ex) {
637            return null;
638        } catch (NullPointerException ex) {
639            return null;
640        }
641    }
642
643    /**
644     * Returns the IMEI. Return null if IMEI is not available.
645     *
646     * <p>Requires Permission:
647     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
648     */
649    /** {@hide} */
650    public String getImei() {
651        return getImei(getDefaultSim());
652    }
653
654    /**
655     * Returns the IMEI. Return null if IMEI is not available.
656     *
657     * <p>Requires Permission:
658     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
659     *
660     * @param slotId of which deviceID is returned
661     */
662    /** {@hide} */
663    public String getImei(int slotId) {
664        long[] subId = SubscriptionManager.getSubId(slotId);
665        try {
666            return getSubscriberInfo().getImeiUsingSubId(subId[0]);
667        } catch (RemoteException ex) {
668            return null;
669        } catch (NullPointerException ex) {
670            return null;
671        }
672    }
673
674    /**
675     * Returns the current location of the device.
676     *<p>
677     * If there is only one radio in the device and that radio has an LTE connection,
678     * this method will return null. The implementation must not to try add LTE
679     * identifiers into the existing cdma/gsm classes.
680     *<p>
681     * In the future this call will be deprecated.
682     *<p>
683     * @return Current location of the device or null if not available.
684     *
685     * <p>Requires Permission:
686     * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or
687     * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION}.
688     */
689    public CellLocation getCellLocation() {
690        try {
691            Bundle bundle = getITelephony().getCellLocation();
692            if (bundle.isEmpty()) return null;
693            CellLocation cl = CellLocation.newFromBundle(bundle);
694            if (cl.isEmpty())
695                return null;
696            return cl;
697        } catch (RemoteException ex) {
698            return null;
699        } catch (NullPointerException ex) {
700            return null;
701        }
702    }
703
704    /**
705     * Enables location update notifications.  {@link PhoneStateListener#onCellLocationChanged
706     * PhoneStateListener.onCellLocationChanged} will be called on location updates.
707     *
708     * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES
709     * CONTROL_LOCATION_UPDATES}
710     *
711     * @hide
712     */
713    public void enableLocationUpdates() {
714            enableLocationUpdates(getDefaultSubscription());
715    }
716
717    /**
718     * Enables location update notifications for a subscription.
719     * {@link PhoneStateListener#onCellLocationChanged
720     * PhoneStateListener.onCellLocationChanged} will be called on location updates.
721     *
722     * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES
723     * CONTROL_LOCATION_UPDATES}
724     *
725     * @param subId for which the location updates are enabled
726     */
727    /** @hide */
728    public void enableLocationUpdates(long subId) {
729        try {
730            getITelephony().enableLocationUpdatesUsingSubId(subId);
731        } catch (RemoteException ex) {
732        } catch (NullPointerException ex) {
733        }
734    }
735
736    /**
737     * Disables location update notifications.  {@link PhoneStateListener#onCellLocationChanged
738     * PhoneStateListener.onCellLocationChanged} will be called on location updates.
739     *
740     * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES
741     * CONTROL_LOCATION_UPDATES}
742     *
743     * @hide
744     */
745    public void disableLocationUpdates() {
746            disableLocationUpdates(getDefaultSubscription());
747    }
748
749    /** @hide */
750    public void disableLocationUpdates(long subId) {
751        try {
752            getITelephony().disableLocationUpdatesUsingSubId(subId);
753        } catch (RemoteException ex) {
754        } catch (NullPointerException ex) {
755        }
756    }
757
758    /**
759     * Returns the neighboring cell information of the device. The getAllCellInfo is preferred
760     * and use this only if getAllCellInfo return nulls or an empty list.
761     *<p>
762     * In the future this call will be deprecated.
763     *<p>
764     * @return List of NeighboringCellInfo or null if info unavailable.
765     *
766     * <p>Requires Permission:
767     * (@link android.Manifest.permission#ACCESS_COARSE_UPDATES}
768     */
769    public List<NeighboringCellInfo> getNeighboringCellInfo() {
770        try {
771            return getITelephony().getNeighboringCellInfo(mContext.getOpPackageName());
772        } catch (RemoteException ex) {
773            return null;
774        } catch (NullPointerException ex) {
775            return null;
776        }
777    }
778
779    /** No phone radio. */
780    public static final int PHONE_TYPE_NONE = PhoneConstants.PHONE_TYPE_NONE;
781    /** Phone radio is GSM. */
782    public static final int PHONE_TYPE_GSM = PhoneConstants.PHONE_TYPE_GSM;
783    /** Phone radio is CDMA. */
784    public static final int PHONE_TYPE_CDMA = PhoneConstants.PHONE_TYPE_CDMA;
785    /** Phone is via SIP. */
786    public static final int PHONE_TYPE_SIP = PhoneConstants.PHONE_TYPE_SIP;
787
788    /**
789     * Returns the current phone type.
790     * TODO: This is a last minute change and hence hidden.
791     *
792     * @see #PHONE_TYPE_NONE
793     * @see #PHONE_TYPE_GSM
794     * @see #PHONE_TYPE_CDMA
795     * @see #PHONE_TYPE_SIP
796     *
797     * {@hide}
798     */
799    @SystemApi
800    public int getCurrentPhoneType() {
801        return getCurrentPhoneType(getDefaultSubscription());
802    }
803
804    /**
805     * Returns a constant indicating the device phone type for a subscription.
806     *
807     * @see #PHONE_TYPE_NONE
808     * @see #PHONE_TYPE_GSM
809     * @see #PHONE_TYPE_CDMA
810     *
811     * @param subId for which phone type is returned
812     */
813    /** {@hide} */
814    @SystemApi
815    public int getCurrentPhoneType(long subId) {
816        int phoneId = SubscriptionManager.getPhoneId(subId);
817        try{
818            ITelephony telephony = getITelephony();
819            if (telephony != null) {
820                return telephony.getActivePhoneTypeUsingSubId(subId);
821            } else {
822                // This can happen when the ITelephony interface is not up yet.
823                return getPhoneTypeFromProperty(phoneId);
824            }
825        } catch (RemoteException ex) {
826            // This shouldn't happen in the normal case, as a backup we
827            // read from the system property.
828            return getPhoneTypeFromProperty(phoneId);
829        } catch (NullPointerException ex) {
830            // This shouldn't happen in the normal case, as a backup we
831            // read from the system property.
832            return getPhoneTypeFromProperty(phoneId);
833        }
834    }
835
836    /**
837     * Returns a constant indicating the device phone type.  This
838     * indicates the type of radio used to transmit voice calls.
839     *
840     * @see #PHONE_TYPE_NONE
841     * @see #PHONE_TYPE_GSM
842     * @see #PHONE_TYPE_CDMA
843     * @see #PHONE_TYPE_SIP
844     */
845    public int getPhoneType() {
846        if (!isVoiceCapable()) {
847            return PHONE_TYPE_NONE;
848        }
849        return getCurrentPhoneType();
850    }
851
852    private int getPhoneTypeFromProperty() {
853        return getPhoneTypeFromProperty(getDefaultPhone());
854    }
855
856    /** {@hide} */
857    private int getPhoneTypeFromProperty(int phoneId) {
858        String type = getTelephonyProperty(phoneId,
859                TelephonyProperties.CURRENT_ACTIVE_PHONE, null);
860        if (type == null || type.equals("")) {
861            return getPhoneTypeFromNetworkType(phoneId);
862        }
863        return Integer.parseInt(type);
864    }
865
866    private int getPhoneTypeFromNetworkType() {
867        return getPhoneTypeFromNetworkType(getDefaultPhone());
868    }
869
870    /** {@hide} */
871    private int getPhoneTypeFromNetworkType(int phoneId) {
872        // When the system property CURRENT_ACTIVE_PHONE, has not been set,
873        // use the system property for default network type.
874        // This is a fail safe, and can only happen at first boot.
875        String mode = getTelephonyProperty(phoneId, "ro.telephony.default_network", null);
876        if (mode != null) {
877            return TelephonyManager.getPhoneType(Integer.parseInt(mode));
878        }
879        return TelephonyManager.PHONE_TYPE_NONE;
880    }
881
882    /**
883     * This function returns the type of the phone, depending
884     * on the network mode.
885     *
886     * @param networkMode
887     * @return Phone Type
888     *
889     * @hide
890     */
891    public static int getPhoneType(int networkMode) {
892        switch(networkMode) {
893        case RILConstants.NETWORK_MODE_CDMA:
894        case RILConstants.NETWORK_MODE_CDMA_NO_EVDO:
895        case RILConstants.NETWORK_MODE_EVDO_NO_CDMA:
896            return PhoneConstants.PHONE_TYPE_CDMA;
897
898        case RILConstants.NETWORK_MODE_WCDMA_PREF:
899        case RILConstants.NETWORK_MODE_GSM_ONLY:
900        case RILConstants.NETWORK_MODE_WCDMA_ONLY:
901        case RILConstants.NETWORK_MODE_GSM_UMTS:
902        case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA:
903        case RILConstants.NETWORK_MODE_LTE_WCDMA:
904        case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
905            return PhoneConstants.PHONE_TYPE_GSM;
906
907        // Use CDMA Phone for the global mode including CDMA
908        case RILConstants.NETWORK_MODE_GLOBAL:
909        case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO:
910            return PhoneConstants.PHONE_TYPE_CDMA;
911
912        case RILConstants.NETWORK_MODE_LTE_ONLY:
913            if (getLteOnCdmaModeStatic() == PhoneConstants.LTE_ON_CDMA_TRUE) {
914                return PhoneConstants.PHONE_TYPE_CDMA;
915            } else {
916                return PhoneConstants.PHONE_TYPE_GSM;
917            }
918        default:
919            return PhoneConstants.PHONE_TYPE_GSM;
920        }
921    }
922
923    /**
924     * The contents of the /proc/cmdline file
925     */
926    private static String getProcCmdLine()
927    {
928        String cmdline = "";
929        FileInputStream is = null;
930        try {
931            is = new FileInputStream("/proc/cmdline");
932            byte [] buffer = new byte[2048];
933            int count = is.read(buffer);
934            if (count > 0) {
935                cmdline = new String(buffer, 0, count);
936            }
937        } catch (IOException e) {
938            Rlog.d(TAG, "No /proc/cmdline exception=" + e);
939        } finally {
940            if (is != null) {
941                try {
942                    is.close();
943                } catch (IOException e) {
944                }
945            }
946        }
947        Rlog.d(TAG, "/proc/cmdline=" + cmdline);
948        return cmdline;
949    }
950
951    /** Kernel command line */
952    private static final String sKernelCmdLine = getProcCmdLine();
953
954    /** Pattern for selecting the product type from the kernel command line */
955    private static final Pattern sProductTypePattern =
956        Pattern.compile("\\sproduct_type\\s*=\\s*(\\w+)");
957
958    /** The ProductType used for LTE on CDMA devices */
959    private static final String sLteOnCdmaProductType =
960        SystemProperties.get(TelephonyProperties.PROPERTY_LTE_ON_CDMA_PRODUCT_TYPE, "");
961
962    /**
963     * Return if the current radio is LTE on CDMA. This
964     * is a tri-state return value as for a period of time
965     * the mode may be unknown.
966     *
967     * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE}
968     * or {@link PhoneConstants#LTE_ON_CDMA_TRUE}
969     *
970     * @hide
971     */
972    public static int getLteOnCdmaModeStatic() {
973        int retVal;
974        int curVal;
975        String productType = "";
976
977        curVal = SystemProperties.getInt(TelephonyProperties.PROPERTY_LTE_ON_CDMA_DEVICE,
978                    PhoneConstants.LTE_ON_CDMA_UNKNOWN);
979        retVal = curVal;
980        if (retVal == PhoneConstants.LTE_ON_CDMA_UNKNOWN) {
981            Matcher matcher = sProductTypePattern.matcher(sKernelCmdLine);
982            if (matcher.find()) {
983                productType = matcher.group(1);
984                if (sLteOnCdmaProductType.equals(productType)) {
985                    retVal = PhoneConstants.LTE_ON_CDMA_TRUE;
986                } else {
987                    retVal = PhoneConstants.LTE_ON_CDMA_FALSE;
988                }
989            } else {
990                retVal = PhoneConstants.LTE_ON_CDMA_FALSE;
991            }
992        }
993
994        Rlog.d(TAG, "getLteOnCdmaMode=" + retVal + " curVal=" + curVal +
995                " product_type='" + productType +
996                "' lteOnCdmaProductType='" + sLteOnCdmaProductType + "'");
997        return retVal;
998    }
999
1000    //
1001    //
1002    // Current Network
1003    //
1004    //
1005
1006    /**
1007     * Returns the alphabetic name of current registered operator.
1008     * <p>
1009     * Availability: Only when user is registered to a network. Result may be
1010     * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
1011     * on a CDMA network).
1012     */
1013    public String getNetworkOperatorName() {
1014        return getNetworkOperatorName(getDefaultSubscription());
1015    }
1016
1017    /**
1018     * Returns the alphabetic name of current registered operator
1019     * for a particular subscription.
1020     * <p>
1021     * Availability: Only when user is registered to a network. Result may be
1022     * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
1023     * on a CDMA network).
1024     * @param subId
1025     */
1026    /** {@hide} */
1027    public String getNetworkOperatorName(long subId) {
1028        int phoneId = SubscriptionManager.getPhoneId(subId);
1029        return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, "");
1030    }
1031
1032    /**
1033     * Returns the numeric name (MCC+MNC) of current registered operator.
1034     * <p>
1035     * Availability: Only when user is registered to a network. Result may be
1036     * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
1037     * on a CDMA network).
1038     */
1039    public String getNetworkOperator() {
1040        return getNetworkOperator(getDefaultSubscription());
1041    }
1042
1043    /**
1044     * Returns the numeric name (MCC+MNC) of current registered operator
1045     * for a particular subscription.
1046     * <p>
1047     * Availability: Only when user is registered to a network. Result may be
1048     * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
1049     * on a CDMA network).
1050     *
1051     * @param subId
1052     */
1053    /** {@hide} */
1054   public String getNetworkOperator(long subId) {
1055        int phoneId = SubscriptionManager.getPhoneId(subId);
1056        return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, "");
1057     }
1058
1059    /**
1060     * Returns true if the device is considered roaming on the current
1061     * network, for GSM purposes.
1062     * <p>
1063     * Availability: Only when user registered to a network.
1064     */
1065    public boolean isNetworkRoaming() {
1066        return isNetworkRoaming(getDefaultSubscription());
1067    }
1068
1069    /**
1070     * Returns true if the device is considered roaming on the current
1071     * network for a subscription.
1072     * <p>
1073     * Availability: Only when user registered to a network.
1074     *
1075     * @param subId
1076     */
1077    /** {@hide} */
1078    public boolean isNetworkRoaming(long subId) {
1079        int phoneId = SubscriptionManager.getPhoneId(subId);
1080        return Boolean.parseBoolean(getTelephonyProperty(phoneId,
1081                TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, null));
1082    }
1083
1084    /**
1085     * Returns the ISO country code equivalent of the current registered
1086     * operator's MCC (Mobile Country Code).
1087     * <p>
1088     * Availability: Only when user is registered to a network. Result may be
1089     * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
1090     * on a CDMA network).
1091     */
1092    public String getNetworkCountryIso() {
1093        return getNetworkCountryIso(getDefaultSubscription());
1094    }
1095
1096    /**
1097     * Returns the ISO country code equivalent of the current registered
1098     * operator's MCC (Mobile Country Code) of a subscription.
1099     * <p>
1100     * Availability: Only when user is registered to a network. Result may be
1101     * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
1102     * on a CDMA network).
1103     *
1104     * @param subId for which Network CountryIso is returned
1105     */
1106    /** {@hide} */
1107    public String getNetworkCountryIso(long subId) {
1108        int phoneId = SubscriptionManager.getPhoneId(subId);
1109        return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1110    }
1111
1112    /** Network type is unknown */
1113    public static final int NETWORK_TYPE_UNKNOWN = 0;
1114    /** Current network is GPRS */
1115    public static final int NETWORK_TYPE_GPRS = 1;
1116    /** Current network is EDGE */
1117    public static final int NETWORK_TYPE_EDGE = 2;
1118    /** Current network is UMTS */
1119    public static final int NETWORK_TYPE_UMTS = 3;
1120    /** Current network is CDMA: Either IS95A or IS95B*/
1121    public static final int NETWORK_TYPE_CDMA = 4;
1122    /** Current network is EVDO revision 0*/
1123    public static final int NETWORK_TYPE_EVDO_0 = 5;
1124    /** Current network is EVDO revision A*/
1125    public static final int NETWORK_TYPE_EVDO_A = 6;
1126    /** Current network is 1xRTT*/
1127    public static final int NETWORK_TYPE_1xRTT = 7;
1128    /** Current network is HSDPA */
1129    public static final int NETWORK_TYPE_HSDPA = 8;
1130    /** Current network is HSUPA */
1131    public static final int NETWORK_TYPE_HSUPA = 9;
1132    /** Current network is HSPA */
1133    public static final int NETWORK_TYPE_HSPA = 10;
1134    /** Current network is iDen */
1135    public static final int NETWORK_TYPE_IDEN = 11;
1136    /** Current network is EVDO revision B*/
1137    public static final int NETWORK_TYPE_EVDO_B = 12;
1138    /** Current network is LTE */
1139    public static final int NETWORK_TYPE_LTE = 13;
1140    /** Current network is eHRPD */
1141    public static final int NETWORK_TYPE_EHRPD = 14;
1142    /** Current network is HSPA+ */
1143    public static final int NETWORK_TYPE_HSPAP = 15;
1144    /** Current network is GSM {@hide} */
1145    public static final int NETWORK_TYPE_GSM = 16;
1146
1147    /**
1148     * @return the NETWORK_TYPE_xxxx for current data connection.
1149     */
1150    public int getNetworkType() {
1151        return getDataNetworkType();
1152    }
1153
1154    /**
1155     * Returns a constant indicating the radio technology (network type)
1156     * currently in use on the device for a subscription.
1157     * @return the network type
1158     *
1159     * @param subId for which network type is returned
1160     *
1161     * @see #NETWORK_TYPE_UNKNOWN
1162     * @see #NETWORK_TYPE_GPRS
1163     * @see #NETWORK_TYPE_EDGE
1164     * @see #NETWORK_TYPE_UMTS
1165     * @see #NETWORK_TYPE_HSDPA
1166     * @see #NETWORK_TYPE_HSUPA
1167     * @see #NETWORK_TYPE_HSPA
1168     * @see #NETWORK_TYPE_CDMA
1169     * @see #NETWORK_TYPE_EVDO_0
1170     * @see #NETWORK_TYPE_EVDO_A
1171     * @see #NETWORK_TYPE_EVDO_B
1172     * @see #NETWORK_TYPE_1xRTT
1173     * @see #NETWORK_TYPE_IDEN
1174     * @see #NETWORK_TYPE_LTE
1175     * @see #NETWORK_TYPE_EHRPD
1176     * @see #NETWORK_TYPE_HSPAP
1177     */
1178    /** {@hide} */
1179   public int getNetworkType(long subId) {
1180       try {
1181           ITelephony telephony = getITelephony();
1182           if (telephony != null) {
1183               return telephony.getNetworkTypeUsingSubId(subId);
1184           } else {
1185               // This can happen when the ITelephony interface is not up yet.
1186               return NETWORK_TYPE_UNKNOWN;
1187           }
1188       } catch(RemoteException ex) {
1189           // This shouldn't happen in the normal case
1190           return NETWORK_TYPE_UNKNOWN;
1191       } catch (NullPointerException ex) {
1192           // This could happen before phone restarts due to crashing
1193           return NETWORK_TYPE_UNKNOWN;
1194       }
1195   }
1196
1197    /**
1198     * Returns a constant indicating the radio technology (network type)
1199     * currently in use on the device for data transmission.
1200     * @return the network type
1201     *
1202     * @see #NETWORK_TYPE_UNKNOWN
1203     * @see #NETWORK_TYPE_GPRS
1204     * @see #NETWORK_TYPE_EDGE
1205     * @see #NETWORK_TYPE_UMTS
1206     * @see #NETWORK_TYPE_HSDPA
1207     * @see #NETWORK_TYPE_HSUPA
1208     * @see #NETWORK_TYPE_HSPA
1209     * @see #NETWORK_TYPE_CDMA
1210     * @see #NETWORK_TYPE_EVDO_0
1211     * @see #NETWORK_TYPE_EVDO_A
1212     * @see #NETWORK_TYPE_EVDO_B
1213     * @see #NETWORK_TYPE_1xRTT
1214     * @see #NETWORK_TYPE_IDEN
1215     * @see #NETWORK_TYPE_LTE
1216     * @see #NETWORK_TYPE_EHRPD
1217     * @see #NETWORK_TYPE_HSPAP
1218     *
1219     * @hide
1220     */
1221    public int getDataNetworkType() {
1222        return getDataNetworkType(getDefaultSubscription());
1223    }
1224
1225    /**
1226     * Returns a constant indicating the radio technology (network type)
1227     * currently in use on the device for data transmission for a subscription
1228     * @return the network type
1229     *
1230     * @param subId for which network type is returned
1231     */
1232    /** {@hide} */
1233    public int getDataNetworkType(long subId) {
1234        try{
1235            ITelephony telephony = getITelephony();
1236            if (telephony != null) {
1237                return telephony.getDataNetworkTypeUsingSubId(subId);
1238            } else {
1239                // This can happen when the ITelephony interface is not up yet.
1240                return NETWORK_TYPE_UNKNOWN;
1241            }
1242        } catch(RemoteException ex) {
1243            // This shouldn't happen in the normal case
1244            return NETWORK_TYPE_UNKNOWN;
1245        } catch (NullPointerException ex) {
1246            // This could happen before phone restarts due to crashing
1247            return NETWORK_TYPE_UNKNOWN;
1248        }
1249    }
1250
1251    /**
1252     * Returns the NETWORK_TYPE_xxxx for voice
1253     *
1254     * @hide
1255     */
1256    public int getVoiceNetworkType() {
1257        return getVoiceNetworkType(getDefaultSubscription());
1258    }
1259
1260    /**
1261     * Returns the NETWORK_TYPE_xxxx for voice for a subId
1262     *
1263     */
1264    /** {@hide} */
1265    public int getVoiceNetworkType(long subId) {
1266        try{
1267            ITelephony telephony = getITelephony();
1268            if (telephony != null) {
1269                return telephony.getVoiceNetworkTypeUsingSubId(subId);
1270            } else {
1271                // This can happen when the ITelephony interface is not up yet.
1272                return NETWORK_TYPE_UNKNOWN;
1273            }
1274        } catch(RemoteException ex) {
1275            // This shouldn't happen in the normal case
1276            return NETWORK_TYPE_UNKNOWN;
1277        } catch (NullPointerException ex) {
1278            // This could happen before phone restarts due to crashing
1279            return NETWORK_TYPE_UNKNOWN;
1280        }
1281    }
1282
1283    /** Unknown network class. {@hide} */
1284    public static final int NETWORK_CLASS_UNKNOWN = 0;
1285    /** Class of broadly defined "2G" networks. {@hide} */
1286    public static final int NETWORK_CLASS_2_G = 1;
1287    /** Class of broadly defined "3G" networks. {@hide} */
1288    public static final int NETWORK_CLASS_3_G = 2;
1289    /** Class of broadly defined "4G" networks. {@hide} */
1290    public static final int NETWORK_CLASS_4_G = 3;
1291
1292    /**
1293     * Return general class of network type, such as "3G" or "4G". In cases
1294     * where classification is contentious, this method is conservative.
1295     *
1296     * @hide
1297     */
1298    public static int getNetworkClass(int networkType) {
1299        switch (networkType) {
1300            case NETWORK_TYPE_GPRS:
1301            case NETWORK_TYPE_GSM:
1302            case NETWORK_TYPE_EDGE:
1303            case NETWORK_TYPE_CDMA:
1304            case NETWORK_TYPE_1xRTT:
1305            case NETWORK_TYPE_IDEN:
1306                return NETWORK_CLASS_2_G;
1307            case NETWORK_TYPE_UMTS:
1308            case NETWORK_TYPE_EVDO_0:
1309            case NETWORK_TYPE_EVDO_A:
1310            case NETWORK_TYPE_HSDPA:
1311            case NETWORK_TYPE_HSUPA:
1312            case NETWORK_TYPE_HSPA:
1313            case NETWORK_TYPE_EVDO_B:
1314            case NETWORK_TYPE_EHRPD:
1315            case NETWORK_TYPE_HSPAP:
1316                return NETWORK_CLASS_3_G;
1317            case NETWORK_TYPE_LTE:
1318                return NETWORK_CLASS_4_G;
1319            default:
1320                return NETWORK_CLASS_UNKNOWN;
1321        }
1322    }
1323
1324    /**
1325     * Returns a string representation of the radio technology (network type)
1326     * currently in use on the device.
1327     * @return the name of the radio technology
1328     *
1329     * @hide pending API council review
1330     */
1331    public String getNetworkTypeName() {
1332        return getNetworkTypeName(getNetworkType());
1333    }
1334
1335    /**
1336     * Returns a string representation of the radio technology (network type)
1337     * currently in use on the device.
1338     * @param subId for which network type is returned
1339     * @return the name of the radio technology
1340     *
1341     */
1342    /** {@hide} */
1343    public static String getNetworkTypeName(int type) {
1344        switch (type) {
1345            case NETWORK_TYPE_GPRS:
1346                return "GPRS";
1347            case NETWORK_TYPE_EDGE:
1348                return "EDGE";
1349            case NETWORK_TYPE_UMTS:
1350                return "UMTS";
1351            case NETWORK_TYPE_HSDPA:
1352                return "HSDPA";
1353            case NETWORK_TYPE_HSUPA:
1354                return "HSUPA";
1355            case NETWORK_TYPE_HSPA:
1356                return "HSPA";
1357            case NETWORK_TYPE_CDMA:
1358                return "CDMA";
1359            case NETWORK_TYPE_EVDO_0:
1360                return "CDMA - EvDo rev. 0";
1361            case NETWORK_TYPE_EVDO_A:
1362                return "CDMA - EvDo rev. A";
1363            case NETWORK_TYPE_EVDO_B:
1364                return "CDMA - EvDo rev. B";
1365            case NETWORK_TYPE_1xRTT:
1366                return "CDMA - 1xRTT";
1367            case NETWORK_TYPE_LTE:
1368                return "LTE";
1369            case NETWORK_TYPE_EHRPD:
1370                return "CDMA - eHRPD";
1371            case NETWORK_TYPE_IDEN:
1372                return "iDEN";
1373            case NETWORK_TYPE_HSPAP:
1374                return "HSPA+";
1375            case NETWORK_TYPE_GSM:
1376                return "GSM";
1377            default:
1378                return "UNKNOWN";
1379        }
1380    }
1381
1382    //
1383    //
1384    // SIM Card
1385    //
1386    //
1387
1388    /** SIM card state: Unknown. Signifies that the SIM is in transition
1389     *  between states. For example, when the user inputs the SIM pin
1390     *  under PIN_REQUIRED state, a query for sim status returns
1391     *  this state before turning to SIM_STATE_READY. */
1392    public static final int SIM_STATE_UNKNOWN = 0;
1393    /** SIM card state: no SIM card is available in the device */
1394    public static final int SIM_STATE_ABSENT = 1;
1395    /** SIM card state: Locked: requires the user's SIM PIN to unlock */
1396    public static final int SIM_STATE_PIN_REQUIRED = 2;
1397    /** SIM card state: Locked: requires the user's SIM PUK to unlock */
1398    public static final int SIM_STATE_PUK_REQUIRED = 3;
1399    /** SIM card state: Locked: requries a network PIN to unlock */
1400    public static final int SIM_STATE_NETWORK_LOCKED = 4;
1401    /** SIM card state: Ready */
1402    public static final int SIM_STATE_READY = 5;
1403    /** SIM card state: SIM Card Error, Sim Card is present but faulty
1404     *@hide
1405     */
1406    public static final int SIM_STATE_CARD_IO_ERROR = 6;
1407
1408    /**
1409     * @return true if a ICC card is present
1410     */
1411    public boolean hasIccCard() {
1412        return hasIccCard(getDefaultSim());
1413    }
1414
1415    /**
1416     * @return true if a ICC card is present for a subscription
1417     *
1418     * @param slotId for which icc card presence is checked
1419     */
1420    /** {@hide} */
1421    // FIXME Input argument slotId should be of type int
1422    public boolean hasIccCard(long slotId) {
1423
1424        try {
1425            return getITelephony().hasIccCardUsingSlotId(slotId);
1426        } catch (RemoteException ex) {
1427            // Assume no ICC card if remote exception which shouldn't happen
1428            return false;
1429        } catch (NullPointerException ex) {
1430            // This could happen before phone restarts due to crashing
1431            return false;
1432        }
1433    }
1434
1435    /**
1436     * Returns a constant indicating the state of the
1437     * device SIM card.
1438     *
1439     * @see #SIM_STATE_UNKNOWN
1440     * @see #SIM_STATE_ABSENT
1441     * @see #SIM_STATE_PIN_REQUIRED
1442     * @see #SIM_STATE_PUK_REQUIRED
1443     * @see #SIM_STATE_NETWORK_LOCKED
1444     * @see #SIM_STATE_READY
1445     * @see #SIM_STATE_CARD_IO_ERROR
1446     */
1447    public int getSimState() {
1448        return getSimState(getDefaultSim());
1449    }
1450
1451    /**
1452     * Returns a constant indicating the state of the
1453     * device SIM card in a slot.
1454     *
1455     * @param slotId
1456     *
1457     * @see #SIM_STATE_UNKNOWN
1458     * @see #SIM_STATE_ABSENT
1459     * @see #SIM_STATE_PIN_REQUIRED
1460     * @see #SIM_STATE_PUK_REQUIRED
1461     * @see #SIM_STATE_NETWORK_LOCKED
1462     * @see #SIM_STATE_READY
1463     */
1464    /** {@hide} */
1465    // FIXME the argument to pass is subId ??
1466    public int getSimState(int slotId) {
1467        long[] subId = SubscriptionManager.getSubId(slotId);
1468        if (subId == null || subId.length == 0) {
1469            return SIM_STATE_ABSENT;
1470        }
1471        // FIXME Do not use a property to determine SIM_STATE, call
1472        // appropriate method on some object.
1473        int phoneId = SubscriptionManager.getPhoneId(subId[0]);
1474        String prop = getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_SIM_STATE, "");
1475        if ("ABSENT".equals(prop)) {
1476            return SIM_STATE_ABSENT;
1477        }
1478        else if ("PIN_REQUIRED".equals(prop)) {
1479            return SIM_STATE_PIN_REQUIRED;
1480        }
1481        else if ("PUK_REQUIRED".equals(prop)) {
1482            return SIM_STATE_PUK_REQUIRED;
1483        }
1484        else if ("NETWORK_LOCKED".equals(prop)) {
1485            return SIM_STATE_NETWORK_LOCKED;
1486        }
1487        else if ("READY".equals(prop)) {
1488            return SIM_STATE_READY;
1489        }
1490        else if ("CARD_IO_ERROR".equals(prop)) {
1491            return SIM_STATE_CARD_IO_ERROR;
1492        }
1493        else {
1494            return SIM_STATE_UNKNOWN;
1495        }
1496    }
1497
1498    /**
1499     * Returns the MCC+MNC (mobile country code + mobile network code) of the
1500     * provider of the SIM. 5 or 6 decimal digits.
1501     * <p>
1502     * Availability: SIM state must be {@link #SIM_STATE_READY}
1503     *
1504     * @see #getSimState
1505     */
1506    public String getSimOperator() {
1507        long subId = getDefaultSubscription();
1508        Rlog.d(TAG, "getSimOperator(): default subId=" + subId);
1509        return getSimOperator(subId);
1510    }
1511
1512    /**
1513     * Returns the MCC+MNC (mobile country code + mobile network code) of the
1514     * provider of the SIM for a particular subscription. 5 or 6 decimal digits.
1515     * <p>
1516     * Availability: SIM state must be {@link #SIM_STATE_READY}
1517     *
1518     * @see #getSimState
1519     *
1520     * @param subId for which SimOperator is returned
1521     */
1522    /** {@hide} */
1523    public String getSimOperator(long subId) {
1524        int phoneId = SubscriptionManager.getPhoneId(subId);
1525        String operator = getTelephonyProperty(phoneId,
1526                TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, "");
1527        Rlog.d(TAG, "getSimOperator: subId=" + subId + " operator=" + operator);
1528        return operator;
1529    }
1530
1531    /**
1532     * Returns the Service Provider Name (SPN).
1533     * <p>
1534     * Availability: SIM state must be {@link #SIM_STATE_READY}
1535     *
1536     * @see #getSimState
1537     */
1538    public String getSimOperatorName() {
1539        return getSimOperatorName(getDefaultSubscription());
1540    }
1541
1542    /**
1543     * Returns the Service Provider Name (SPN).
1544     * <p>
1545     * Availability: SIM state must be {@link #SIM_STATE_READY}
1546     *
1547     * @see #getSimState
1548     *
1549     * @param subId for which SimOperatorName is returned
1550     */
1551    /** {@hide} */
1552    public String getSimOperatorName(long subId) {
1553        int phoneId = SubscriptionManager.getPhoneId(subId);
1554        return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, "");
1555    }
1556
1557    /**
1558     * Returns the ISO country code equivalent for the SIM provider's country code.
1559     */
1560    public String getSimCountryIso() {
1561        return getSimCountryIso(getDefaultSubscription());
1562    }
1563
1564    /**
1565     * Returns the ISO country code equivalent for the SIM provider's country code.
1566     *
1567     * @param subId for which SimCountryIso is returned
1568     */
1569    /** {@hide} */
1570    public String getSimCountryIso(long subId) {
1571        int phoneId = SubscriptionManager.getPhoneId(subId);
1572        return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY,
1573                "");
1574    }
1575
1576    /**
1577     * Returns the serial number of the SIM, if applicable. Return null if it is
1578     * unavailable.
1579     * <p>
1580     * Requires Permission:
1581     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1582     */
1583    public String getSimSerialNumber() {
1584         return getSimSerialNumber(getDefaultSubscription());
1585    }
1586
1587    /**
1588     * Returns the serial number for the given subscription, if applicable. Return null if it is
1589     * unavailable.
1590     * <p>
1591     * @param subId for which Sim Serial number is returned
1592     * Requires Permission:
1593     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1594     */
1595    /** {@hide} */
1596    public String getSimSerialNumber(long subId) {
1597        try {
1598            return getSubscriberInfo().getIccSerialNumberUsingSubId(subId);
1599        } catch (RemoteException ex) {
1600            return null;
1601        } catch (NullPointerException ex) {
1602            // This could happen before phone restarts due to crashing
1603            return null;
1604        }
1605    }
1606
1607    /**
1608     * Return if the current radio is LTE on CDMA. This
1609     * is a tri-state return value as for a period of time
1610     * the mode may be unknown.
1611     *
1612     * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE}
1613     * or {@link PhoneConstants#LTE_ON_CDMA_TRUE}
1614     *
1615     * @hide
1616     */
1617    public int getLteOnCdmaMode() {
1618        return getLteOnCdmaMode(getDefaultSubscription());
1619    }
1620
1621    /**
1622     * Return if the current radio is LTE on CDMA for Subscription. This
1623     * is a tri-state return value as for a period of time
1624     * the mode may be unknown.
1625     *
1626     * @param subId for which radio is LTE on CDMA is returned
1627     * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE}
1628     * or {@link PhoneConstants#LTE_ON_CDMA_TRUE}
1629     *
1630     */
1631    /** {@hide} */
1632    public int getLteOnCdmaMode(long subId) {
1633        try {
1634            return getITelephony().getLteOnCdmaModeUsingSubId(subId);
1635        } catch (RemoteException ex) {
1636            // Assume no ICC card if remote exception which shouldn't happen
1637            return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
1638        } catch (NullPointerException ex) {
1639            // This could happen before phone restarts due to crashing
1640            return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
1641        }
1642    }
1643
1644    //
1645    //
1646    // Subscriber Info
1647    //
1648    //
1649
1650    /**
1651     * Returns the unique subscriber ID, for example, the IMSI for a GSM phone.
1652     * Return null if it is unavailable.
1653     * <p>
1654     * Requires Permission:
1655     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1656     */
1657    public String getSubscriberId() {
1658        return getSubscriberId(getDefaultSubscription());
1659    }
1660
1661    /**
1662     * Returns the unique subscriber ID, for example, the IMSI for a GSM phone
1663     * for a subscription.
1664     * Return null if it is unavailable.
1665     * <p>
1666     * Requires Permission:
1667     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1668     *
1669     * @param subId whose subscriber id is returned
1670     */
1671    /** {@hide} */
1672    public String getSubscriberId(long subId) {
1673        try {
1674            return getSubscriberInfo().getSubscriberIdUsingSubId(subId);
1675        } catch (RemoteException ex) {
1676            return null;
1677        } catch (NullPointerException ex) {
1678            // This could happen before phone restarts due to crashing
1679            return null;
1680        }
1681    }
1682
1683    /**
1684     * Returns the Group Identifier Level1 for a GSM phone.
1685     * Return null if it is unavailable.
1686     * <p>
1687     * Requires Permission:
1688     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1689     */
1690    public String getGroupIdLevel1() {
1691        try {
1692            return getSubscriberInfo().getGroupIdLevel1();
1693        } catch (RemoteException ex) {
1694            return null;
1695        } catch (NullPointerException ex) {
1696            // This could happen before phone restarts due to crashing
1697            return null;
1698        }
1699    }
1700
1701    /**
1702     * Returns the Group Identifier Level1 for a GSM phone for a particular subscription.
1703     * Return null if it is unavailable.
1704     * <p>
1705     * Requires Permission:
1706     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1707     *
1708     * @param subscription whose subscriber id is returned
1709     */
1710    /** {@hide} */
1711    public String getGroupIdLevel1(long subId) {
1712        try {
1713            return getSubscriberInfo().getGroupIdLevel1UsingSubId(subId);
1714        } catch (RemoteException ex) {
1715            return null;
1716        } catch (NullPointerException ex) {
1717            // This could happen before phone restarts due to crashing
1718            return null;
1719        }
1720    }
1721
1722    /**
1723     * Returns the phone number string for line 1, for example, the MSISDN
1724     * for a GSM phone. Return null if it is unavailable.
1725     * <p>
1726     * Requires Permission:
1727     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1728     */
1729    public String getLine1Number() {
1730        return getLine1Number(getDefaultSubscription());
1731    }
1732
1733    /**
1734     * Returns the phone number string for line 1, for example, the MSISDN
1735     * for a GSM phone for a particular subscription. Return null if it is unavailable.
1736     * <p>
1737     * Requires Permission:
1738     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1739     *
1740     * @param subId whose phone number for line 1 is returned
1741     */
1742    /** {@hide} */
1743    public String getLine1Number(long subId) {
1744        String number = null;
1745        try {
1746            number = getITelephony().getLine1NumberForDisplay(subId);
1747        } catch (RemoteException ex) {
1748        } catch (NullPointerException ex) {
1749        }
1750        if (number != null) {
1751            return number;
1752        }
1753        try {
1754            return getSubscriberInfo().getLine1NumberUsingSubId(subId);
1755        } catch (RemoteException ex) {
1756            return null;
1757        } catch (NullPointerException ex) {
1758            // This could happen before phone restarts due to crashing
1759            return null;
1760        }
1761    }
1762
1763    /**
1764     * Set the phone number string and its alphatag for line 1 for display
1765     * purpose only, for example, displayed in Phone Status. It won't change
1766     * the actual MSISDN/MDN. This setting won't be persisted during power cycle
1767     * and it should be set again after reboot.
1768     * <p>
1769     * Requires Permission:
1770     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
1771     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
1772     *
1773     * @param alphaTag alpha-tagging of the dailing nubmer
1774     * @param number The dialing number
1775     */
1776    public void setLine1NumberForDisplay(String alphaTag, String number) {
1777        setLine1NumberForDisplay(getDefaultSubscription(), alphaTag, number);
1778    }
1779
1780    /**
1781     * Set the phone number string and its alphatag for line 1 for display
1782     * purpose only, for example, displayed in Phone Status. It won't change
1783     * the actual MSISDN/MDN. This setting won't be persisted during power cycle
1784     * and it should be set again after reboot.
1785     * <p>
1786     * Requires Permission:
1787     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
1788     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
1789     *
1790     * @param subId the subscriber that the alphatag and dialing number belongs to.
1791     * @param alphaTag alpha-tagging of the dailing nubmer
1792     * @param number The dialing number
1793     */
1794    public void setLine1NumberForDisplay(long subId, String alphaTag, String number) {
1795        try {
1796            getITelephony().setLine1NumberForDisplay(subId, alphaTag, number);
1797        } catch (RemoteException ex) {
1798        } catch (NullPointerException ex) {
1799        }
1800    }
1801
1802    /**
1803     * Returns the alphabetic identifier associated with the line 1 number.
1804     * Return null if it is unavailable.
1805     * <p>
1806     * Requires Permission:
1807     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1808     * @hide
1809     * nobody seems to call this.
1810     */
1811    public String getLine1AlphaTag() {
1812        return getLine1AlphaTag(getDefaultSubscription());
1813    }
1814
1815    /**
1816     * Returns the alphabetic identifier associated with the line 1 number
1817     * for a subscription.
1818     * Return null if it is unavailable.
1819     * <p>
1820     * Requires Permission:
1821     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1822     * @param subId whose alphabetic identifier associated with line 1 is returned
1823     * nobody seems to call this.
1824     */
1825    /** {@hide} */
1826    public String getLine1AlphaTag(long subId) {
1827        String alphaTag = null;
1828        try {
1829            alphaTag = getITelephony().getLine1AlphaTagForDisplay(subId);
1830        } catch (RemoteException ex) {
1831        } catch (NullPointerException ex) {
1832        }
1833        if (alphaTag != null) {
1834            return alphaTag;
1835        }
1836        try {
1837            return getSubscriberInfo().getLine1AlphaTagUsingSubId(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     * Returns the MSISDN string.
1848     * for a GSM phone. Return null if it is unavailable.
1849     * <p>
1850     * Requires Permission:
1851     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1852     *
1853     * @hide
1854     */
1855    public String getMsisdn() {
1856        return getMsisdn(getDefaultSubscription());
1857    }
1858
1859    /**
1860     * Returns the MSISDN string.
1861     * for a GSM phone. Return null if it is unavailable.
1862     * <p>
1863     * Requires Permission:
1864     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1865     *
1866     * @param subId for which msisdn is returned
1867     */
1868    /** {@hide} */
1869    public String getMsisdn(long subId) {
1870        try {
1871            return getSubscriberInfo().getMsisdnUsingSubId(subId);
1872        } catch (RemoteException ex) {
1873            return null;
1874        } catch (NullPointerException ex) {
1875            // This could happen before phone restarts due to crashing
1876            return null;
1877        }
1878    }
1879
1880    /**
1881     * Returns the voice mail number. Return null if it is unavailable.
1882     * <p>
1883     * Requires Permission:
1884     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1885     */
1886    public String getVoiceMailNumber() {
1887        return getVoiceMailNumber(getDefaultSubscription());
1888    }
1889
1890    /**
1891     * Returns the voice mail number for a subscription.
1892     * Return null if it is unavailable.
1893     * <p>
1894     * Requires Permission:
1895     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1896     * @param subId whose voice mail number is returned
1897     */
1898    /** {@hide} */
1899    public String getVoiceMailNumber(long subId) {
1900        try {
1901            return getSubscriberInfo().getVoiceMailNumberUsingSubId(subId);
1902        } catch (RemoteException ex) {
1903            return null;
1904        } catch (NullPointerException ex) {
1905            // This could happen before phone restarts due to crashing
1906            return null;
1907        }
1908    }
1909
1910    /**
1911     * Returns the complete voice mail number. Return null if it is unavailable.
1912     * <p>
1913     * Requires Permission:
1914     *   {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED}
1915     *
1916     * @hide
1917     */
1918    public String getCompleteVoiceMailNumber() {
1919        return getCompleteVoiceMailNumber(getDefaultSubscription());
1920    }
1921
1922    /**
1923     * Returns the complete voice mail number. Return null if it is unavailable.
1924     * <p>
1925     * Requires Permission:
1926     *   {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED}
1927     *
1928     * @param subId
1929     */
1930    /** {@hide} */
1931    public String getCompleteVoiceMailNumber(long subId) {
1932        try {
1933            return getSubscriberInfo().getCompleteVoiceMailNumberUsingSubId(subId);
1934        } catch (RemoteException ex) {
1935            return null;
1936        } catch (NullPointerException ex) {
1937            // This could happen before phone restarts due to crashing
1938            return null;
1939        }
1940    }
1941
1942    /**
1943     * Returns the voice mail count. Return 0 if unavailable.
1944     * <p>
1945     * Requires Permission:
1946     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1947     * @hide
1948     */
1949    public int getVoiceMessageCount() {
1950        return getVoiceMessageCount(getDefaultSubscription());
1951    }
1952
1953    /**
1954     * Returns the voice mail count for a subscription. Return 0 if unavailable.
1955     * <p>
1956     * Requires Permission:
1957     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1958     * @param subId whose voice message count is returned
1959     */
1960    /** {@hide} */
1961    public int getVoiceMessageCount(long subId) {
1962        try {
1963            return getITelephony().getVoiceMessageCountUsingSubId(subId);
1964        } catch (RemoteException ex) {
1965            return 0;
1966        } catch (NullPointerException ex) {
1967            // This could happen before phone restarts due to crashing
1968            return 0;
1969        }
1970    }
1971
1972    /**
1973     * Retrieves the alphabetic identifier associated with the voice
1974     * mail number.
1975     * <p>
1976     * Requires Permission:
1977     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1978     */
1979    public String getVoiceMailAlphaTag() {
1980        return getVoiceMailAlphaTag(getDefaultSubscription());
1981    }
1982
1983    /**
1984     * Retrieves the alphabetic identifier associated with the voice
1985     * mail number for a subscription.
1986     * <p>
1987     * Requires Permission:
1988     * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1989     * @param subId whose alphabetic identifier associated with the
1990     * voice mail number is returned
1991     */
1992    /** {@hide} */
1993    public String getVoiceMailAlphaTag(long subId) {
1994        try {
1995            return getSubscriberInfo().getVoiceMailAlphaTagUsingSubId(subId);
1996        } catch (RemoteException ex) {
1997            return null;
1998        } catch (NullPointerException ex) {
1999            // This could happen before phone restarts due to crashing
2000            return null;
2001        }
2002    }
2003
2004    /**
2005     * Returns the IMS private user identity (IMPI) that was loaded from the ISIM.
2006     * @return the IMPI, or null if not present or not loaded
2007     * @hide
2008     */
2009    public String getIsimImpi() {
2010        try {
2011            return getSubscriberInfo().getIsimImpi();
2012        } catch (RemoteException ex) {
2013            return null;
2014        } catch (NullPointerException ex) {
2015            // This could happen before phone restarts due to crashing
2016            return null;
2017        }
2018    }
2019
2020    /**
2021     * Returns the IMS home network domain name that was loaded from the ISIM.
2022     * @return the IMS domain name, or null if not present or not loaded
2023     * @hide
2024     */
2025    public String getIsimDomain() {
2026        try {
2027            return getSubscriberInfo().getIsimDomain();
2028        } catch (RemoteException ex) {
2029            return null;
2030        } catch (NullPointerException ex) {
2031            // This could happen before phone restarts due to crashing
2032            return null;
2033        }
2034    }
2035
2036    /**
2037     * Returns the IMS public user identities (IMPU) that were loaded from the ISIM.
2038     * @return an array of IMPU strings, with one IMPU per string, or null if
2039     *      not present or not loaded
2040     * @hide
2041     */
2042    public String[] getIsimImpu() {
2043        try {
2044            return getSubscriberInfo().getIsimImpu();
2045        } catch (RemoteException ex) {
2046            return null;
2047        } catch (NullPointerException ex) {
2048            // This could happen before phone restarts due to crashing
2049            return null;
2050        }
2051    }
2052
2053   /**
2054    * @hide
2055    */
2056    private IPhoneSubInfo getSubscriberInfo() {
2057        // get it each time because that process crashes a lot
2058        return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo"));
2059    }
2060
2061    /** Device call state: No activity. */
2062    public static final int CALL_STATE_IDLE = 0;
2063    /** Device call state: Ringing. A new call arrived and is
2064     *  ringing or waiting. In the latter case, another call is
2065     *  already active. */
2066    public static final int CALL_STATE_RINGING = 1;
2067    /** Device call state: Off-hook. At least one call exists
2068      * that is dialing, active, or on hold, and no calls are ringing
2069      * or waiting. */
2070    public static final int CALL_STATE_OFFHOOK = 2;
2071
2072    /**
2073     * Returns a constant indicating the call state (cellular) on the device.
2074     */
2075    public int getCallState() {
2076        return getCallState(getDefaultSubscription());
2077    }
2078
2079    /**
2080     * Returns a constant indicating the call state (cellular) on the device
2081     * for a subscription.
2082     *
2083     * @param subId whose call state is returned
2084     */
2085    /** {@hide} */
2086    public int getCallState(long subId) {
2087        try {
2088            return getITelephony().getCallStateUsingSubId(subId);
2089        } catch (RemoteException ex) {
2090            // the phone process is restarting.
2091            return CALL_STATE_IDLE;
2092        } catch (NullPointerException ex) {
2093          // the phone process is restarting.
2094          return CALL_STATE_IDLE;
2095      }
2096    }
2097
2098    /** Data connection activity: No traffic. */
2099    public static final int DATA_ACTIVITY_NONE = 0x00000000;
2100    /** Data connection activity: Currently receiving IP PPP traffic. */
2101    public static final int DATA_ACTIVITY_IN = 0x00000001;
2102    /** Data connection activity: Currently sending IP PPP traffic. */
2103    public static final int DATA_ACTIVITY_OUT = 0x00000002;
2104    /** Data connection activity: Currently both sending and receiving
2105     *  IP PPP traffic. */
2106    public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT;
2107    /**
2108     * Data connection is active, but physical link is down
2109     */
2110    public static final int DATA_ACTIVITY_DORMANT = 0x00000004;
2111
2112    /**
2113     * Returns a constant indicating the type of activity on a data connection
2114     * (cellular).
2115     *
2116     * @see #DATA_ACTIVITY_NONE
2117     * @see #DATA_ACTIVITY_IN
2118     * @see #DATA_ACTIVITY_OUT
2119     * @see #DATA_ACTIVITY_INOUT
2120     * @see #DATA_ACTIVITY_DORMANT
2121     */
2122    public int getDataActivity() {
2123        try {
2124            return getITelephony().getDataActivity();
2125        } catch (RemoteException ex) {
2126            // the phone process is restarting.
2127            return DATA_ACTIVITY_NONE;
2128        } catch (NullPointerException ex) {
2129          // the phone process is restarting.
2130          return DATA_ACTIVITY_NONE;
2131      }
2132    }
2133
2134    /** Data connection state: Unknown.  Used before we know the state.
2135     * @hide
2136     */
2137    public static final int DATA_UNKNOWN        = -1;
2138    /** Data connection state: Disconnected. IP traffic not available. */
2139    public static final int DATA_DISCONNECTED   = 0;
2140    /** Data connection state: Currently setting up a data connection. */
2141    public static final int DATA_CONNECTING     = 1;
2142    /** Data connection state: Connected. IP traffic should be available. */
2143    public static final int DATA_CONNECTED      = 2;
2144    /** Data connection state: Suspended. The connection is up, but IP
2145     * traffic is temporarily unavailable. For example, in a 2G network,
2146     * data activity may be suspended when a voice call arrives. */
2147    public static final int DATA_SUSPENDED      = 3;
2148
2149    /**
2150     * Returns a constant indicating the current data connection state
2151     * (cellular).
2152     *
2153     * @see #DATA_DISCONNECTED
2154     * @see #DATA_CONNECTING
2155     * @see #DATA_CONNECTED
2156     * @see #DATA_SUSPENDED
2157     */
2158    public int getDataState() {
2159        try {
2160            return getITelephony().getDataState();
2161        } catch (RemoteException ex) {
2162            // the phone process is restarting.
2163            return DATA_DISCONNECTED;
2164        } catch (NullPointerException ex) {
2165            return DATA_DISCONNECTED;
2166        }
2167    }
2168
2169   /**
2170    * @hide
2171    */
2172    private ITelephony getITelephony() {
2173        return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE));
2174    }
2175
2176    /**
2177    * @hide
2178    */
2179    private ITelecommService getTelecommService() {
2180        return ITelecommService.Stub.asInterface(ServiceManager.getService(TELECOMM_SERVICE_NAME));
2181    }
2182
2183    //
2184    //
2185    // PhoneStateListener
2186    //
2187    //
2188
2189    /**
2190     * Registers a listener object to receive notification of changes
2191     * in specified telephony states.
2192     * <p>
2193     * To register a listener, pass a {@link PhoneStateListener}
2194     * and specify at least one telephony state of interest in
2195     * the events argument.
2196     *
2197     * At registration, and when a specified telephony state
2198     * changes, the telephony manager invokes the appropriate
2199     * callback method on the listener object and passes the
2200     * current (updated) values.
2201     * <p>
2202     * To unregister a listener, pass the listener object and set the
2203     * events argument to
2204     * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0).
2205     *
2206     * @param listener The {@link PhoneStateListener} object to register
2207     *                 (or unregister)
2208     * @param events The telephony state(s) of interest to the listener,
2209     *               as a bitwise-OR combination of {@link PhoneStateListener}
2210     *               LISTEN_ flags.
2211     */
2212    public void listen(PhoneStateListener listener, int events) {
2213        String pkgForDebug = mContext != null ? mContext.getPackageName() : "<unknown>";
2214        try {
2215            Boolean notifyNow = (getITelephony() != null);
2216            sRegistry.listenUsingSubId(listener.mSubId, pkgForDebug, listener.callback, events, notifyNow);
2217        } catch (RemoteException ex) {
2218            // system process dead
2219        } catch (NullPointerException ex) {
2220            // system process dead
2221        }
2222    }
2223
2224    /**
2225     * Returns the CDMA ERI icon index to display
2226     *
2227     * @hide
2228     */
2229    public int getCdmaEriIconIndex() {
2230        return getCdmaEriIconIndex(getDefaultSubscription());
2231    }
2232
2233    /**
2234     * Returns the CDMA ERI icon index to display for a subscription
2235     */
2236    /** {@hide} */
2237    public int getCdmaEriIconIndex(long subId) {
2238        try {
2239            return getITelephony().getCdmaEriIconIndexUsingSubId(subId);
2240        } catch (RemoteException ex) {
2241            // the phone process is restarting.
2242            return -1;
2243        } catch (NullPointerException ex) {
2244            return -1;
2245        }
2246    }
2247
2248    /**
2249     * Returns the CDMA ERI icon mode,
2250     * 0 - ON
2251     * 1 - FLASHING
2252     *
2253     * @hide
2254     */
2255    public int getCdmaEriIconMode() {
2256        return getCdmaEriIconMode(getDefaultSubscription());
2257    }
2258
2259    /**
2260     * Returns the CDMA ERI icon mode for a subscription.
2261     * 0 - ON
2262     * 1 - FLASHING
2263     */
2264    /** {@hide} */
2265    public int getCdmaEriIconMode(long subId) {
2266        try {
2267            return getITelephony().getCdmaEriIconModeUsingSubId(subId);
2268        } catch (RemoteException ex) {
2269            // the phone process is restarting.
2270            return -1;
2271        } catch (NullPointerException ex) {
2272            return -1;
2273        }
2274    }
2275
2276    /**
2277     * Returns the CDMA ERI text,
2278     *
2279     * @hide
2280     */
2281    public String getCdmaEriText() {
2282        return getCdmaEriText(getDefaultSubscription());
2283    }
2284
2285    /**
2286     * Returns the CDMA ERI text, of a subscription
2287     *
2288     */
2289    /** {@hide} */
2290    public String getCdmaEriText(long subId) {
2291        try {
2292            return getITelephony().getCdmaEriTextUsingSubId(subId);
2293        } catch (RemoteException ex) {
2294            // the phone process is restarting.
2295            return null;
2296        } catch (NullPointerException ex) {
2297            return null;
2298        }
2299    }
2300
2301    /**
2302     * @return true if the current device is "voice capable".
2303     * <p>
2304     * "Voice capable" means that this device supports circuit-switched
2305     * (i.e. voice) phone calls over the telephony network, and is allowed
2306     * to display the in-call UI while a cellular voice call is active.
2307     * This will be false on "data only" devices which can't make voice
2308     * calls and don't support any in-call UI.
2309     * <p>
2310     * Note: the meaning of this flag is subtly different from the
2311     * PackageManager.FEATURE_TELEPHONY system feature, which is available
2312     * on any device with a telephony radio, even if the device is
2313     * data-only.
2314     *
2315     * @hide pending API review
2316     */
2317    public boolean isVoiceCapable() {
2318        if (mContext == null) return true;
2319        return mContext.getResources().getBoolean(
2320                com.android.internal.R.bool.config_voice_capable);
2321    }
2322
2323    /**
2324     * @return true if the current device supports sms service.
2325     * <p>
2326     * If true, this means that the device supports both sending and
2327     * receiving sms via the telephony network.
2328     * <p>
2329     * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are
2330     *       disabled when device doesn't support sms.
2331     */
2332    public boolean isSmsCapable() {
2333        if (mContext == null) return true;
2334        return mContext.getResources().getBoolean(
2335                com.android.internal.R.bool.config_sms_capable);
2336    }
2337
2338    /**
2339     * Returns all observed cell information from all radios on the
2340     * device including the primary and neighboring cells. This does
2341     * not cause or change the rate of PhoneStateListner#onCellInfoChanged.
2342     *<p>
2343     * The list can include one or more of {@link android.telephony.CellInfoGsm CellInfoGsm},
2344     * {@link android.telephony.CellInfoCdma CellInfoCdma},
2345     * {@link android.telephony.CellInfoLte CellInfoLte} and
2346     * {@link android.telephony.CellInfoWcdma CellInfoCdma} in any combination.
2347     * Specifically on devices with multiple radios it is typical to see instances of
2348     * one or more of any these in the list. In addition 0, 1 or more CellInfo
2349     * objects may return isRegistered() true.
2350     *<p>
2351     * This is preferred over using getCellLocation although for older
2352     * devices this may return null in which case getCellLocation should
2353     * be called.
2354     *<p>
2355     * @return List of CellInfo or null if info unavailable.
2356     *
2357     * <p>Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}
2358     */
2359    public List<CellInfo> getAllCellInfo() {
2360        try {
2361            return getITelephony().getAllCellInfo();
2362        } catch (RemoteException ex) {
2363            return null;
2364        } catch (NullPointerException ex) {
2365            return null;
2366        }
2367    }
2368
2369    /**
2370     * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged
2371     * PhoneStateListener.onCellInfoChanged} will be invoked.
2372     *<p>
2373     * The default, 0, means invoke onCellInfoChanged when any of the reported
2374     * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue
2375     * A onCellInfoChanged.
2376     *<p>
2377     * @param rateInMillis the rate
2378     *
2379     * @hide
2380     */
2381    public void setCellInfoListRate(int rateInMillis) {
2382        try {
2383            getITelephony().setCellInfoListRate(rateInMillis);
2384        } catch (RemoteException ex) {
2385        } catch (NullPointerException ex) {
2386        }
2387    }
2388
2389    /**
2390     * Returns the MMS user agent.
2391     */
2392    public String getMmsUserAgent() {
2393        if (mContext == null) return null;
2394        return mContext.getResources().getString(
2395                com.android.internal.R.string.config_mms_user_agent);
2396    }
2397
2398    /**
2399     * Returns the MMS user agent profile URL.
2400     */
2401    public String getMmsUAProfUrl() {
2402        if (mContext == null) return null;
2403        return mContext.getResources().getString(
2404                com.android.internal.R.string.config_mms_user_agent_profile_url);
2405    }
2406
2407    /**
2408     * Opens a logical channel to the ICC card.
2409     *
2410     * Input parameters equivalent to TS 27.007 AT+CCHO command.
2411     *
2412     * <p>Requires Permission:
2413     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2414     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2415     *
2416     * @param AID Application id. See ETSI 102.221 and 101.220.
2417     * @return an IccOpenLogicalChannelResponse object.
2418     */
2419    public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) {
2420        try {
2421            return getITelephony().iccOpenLogicalChannel(AID);
2422        } catch (RemoteException ex) {
2423        } catch (NullPointerException ex) {
2424        }
2425        return null;
2426    }
2427
2428    /**
2429     * Closes a previously opened logical channel to the ICC card.
2430     *
2431     * Input parameters equivalent to TS 27.007 AT+CCHC command.
2432     *
2433     * <p>Requires Permission:
2434     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2435     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2436     *
2437     * @param channel is the channel id to be closed as retruned by a successful
2438     *            iccOpenLogicalChannel.
2439     * @return true if the channel was closed successfully.
2440     */
2441    public boolean iccCloseLogicalChannel(int channel) {
2442        try {
2443            return getITelephony().iccCloseLogicalChannel(channel);
2444        } catch (RemoteException ex) {
2445        } catch (NullPointerException ex) {
2446        }
2447        return false;
2448    }
2449
2450    /**
2451     * Transmit an APDU to the ICC card over a logical channel.
2452     *
2453     * Input parameters equivalent to TS 27.007 AT+CGLA command.
2454     *
2455     * <p>Requires Permission:
2456     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2457     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2458     *
2459     * @param channel is the channel id to be closed as returned by a successful
2460     *            iccOpenLogicalChannel.
2461     * @param cla Class of the APDU command.
2462     * @param instruction Instruction of the APDU command.
2463     * @param p1 P1 value of the APDU command.
2464     * @param p2 P2 value of the APDU command.
2465     * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU
2466     *            is sent to the SIM.
2467     * @param data Data to be sent with the APDU.
2468     * @return The APDU response from the ICC card with the status appended at
2469     *            the end.
2470     */
2471    public String iccTransmitApduLogicalChannel(int channel, int cla,
2472            int instruction, int p1, int p2, int p3, String data) {
2473        try {
2474            return getITelephony().iccTransmitApduLogicalChannel(channel, cla,
2475                    instruction, p1, p2, p3, data);
2476        } catch (RemoteException ex) {
2477        } catch (NullPointerException ex) {
2478        }
2479        return "";
2480    }
2481
2482    /**
2483     * Transmit an APDU to the ICC card over the basic channel.
2484     *
2485     * Input parameters equivalent to TS 27.007 AT+CSIM command.
2486     *
2487     * <p>Requires Permission:
2488     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2489     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2490     *
2491     * @param cla Class of the APDU command.
2492     * @param instruction Instruction of the APDU command.
2493     * @param p1 P1 value of the APDU command.
2494     * @param p2 P2 value of the APDU command.
2495     * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU
2496     *            is sent to the SIM.
2497     * @param data Data to be sent with the APDU.
2498     * @return The APDU response from the ICC card with the status appended at
2499     *            the end.
2500     */
2501    public String iccTransmitApduBasicChannel(int cla,
2502            int instruction, int p1, int p2, int p3, String data) {
2503        try {
2504            return getITelephony().iccTransmitApduBasicChannel(cla,
2505                    instruction, p1, p2, p3, data);
2506        } catch (RemoteException ex) {
2507        } catch (NullPointerException ex) {
2508        }
2509        return "";
2510    }
2511
2512    /**
2513     * Returns the response APDU for a command APDU sent through SIM_IO.
2514     *
2515     * <p>Requires Permission:
2516     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2517     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2518     *
2519     * @param fileID
2520     * @param command
2521     * @param p1 P1 value of the APDU command.
2522     * @param p2 P2 value of the APDU command.
2523     * @param p3 P3 value of the APDU command.
2524     * @param filePath
2525     * @return The APDU response.
2526     */
2527    public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3,
2528            String filePath) {
2529        try {
2530            return getITelephony().iccExchangeSimIO(fileID, command, p1, p2,
2531                p3, filePath);
2532        } catch (RemoteException ex) {
2533        } catch (NullPointerException ex) {
2534        }
2535        return null;
2536    }
2537
2538    /**
2539     * Send ENVELOPE to the SIM and return the response.
2540     *
2541     * <p>Requires Permission:
2542     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2543     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2544     *
2545     * @param content String containing SAT/USAT response in hexadecimal
2546     *                format starting with command tag. See TS 102 223 for
2547     *                details.
2548     * @return The APDU response from the ICC card in hexadecimal format
2549     *         with the last 4 bytes being the status word. If the command fails,
2550     *         returns an empty string.
2551     */
2552    public String sendEnvelopeWithStatus(String content) {
2553        try {
2554            return getITelephony().sendEnvelopeWithStatus(content);
2555        } catch (RemoteException ex) {
2556        } catch (NullPointerException ex) {
2557        }
2558        return "";
2559    }
2560
2561    /**
2562     * Read one of the NV items defined in com.android.internal.telephony.RadioNVItems.
2563     * Used for device configuration by some CDMA operators.
2564     * <p>
2565     * Requires Permission:
2566     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2567     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2568     *
2569     * @param itemID the ID of the item to read.
2570     * @return the NV item as a String, or null on any failure.
2571     *
2572     * @hide
2573     */
2574    public String nvReadItem(int itemID) {
2575        try {
2576            return getITelephony().nvReadItem(itemID);
2577        } catch (RemoteException ex) {
2578            Rlog.e(TAG, "nvReadItem RemoteException", ex);
2579        } catch (NullPointerException ex) {
2580            Rlog.e(TAG, "nvReadItem NPE", ex);
2581        }
2582        return "";
2583    }
2584
2585    /**
2586     * Write one of the NV items defined in com.android.internal.telephony.RadioNVItems.
2587     * Used for device configuration by some CDMA operators.
2588     * <p>
2589     * Requires Permission:
2590     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2591     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2592     *
2593     * @param itemID the ID of the item to read.
2594     * @param itemValue the value to write, as a String.
2595     * @return true on success; false on any failure.
2596     *
2597     * @hide
2598     */
2599    public boolean nvWriteItem(int itemID, String itemValue) {
2600        try {
2601            return getITelephony().nvWriteItem(itemID, itemValue);
2602        } catch (RemoteException ex) {
2603            Rlog.e(TAG, "nvWriteItem RemoteException", ex);
2604        } catch (NullPointerException ex) {
2605            Rlog.e(TAG, "nvWriteItem NPE", ex);
2606        }
2607        return false;
2608    }
2609
2610    /**
2611     * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2612     * Used for device configuration by some CDMA operators.
2613     * <p>
2614     * Requires Permission:
2615     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2616     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2617     *
2618     * @param preferredRoamingList byte array containing the new PRL.
2619     * @return true on success; false on any failure.
2620     *
2621     * @hide
2622     */
2623    public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
2624        try {
2625            return getITelephony().nvWriteCdmaPrl(preferredRoamingList);
2626        } catch (RemoteException ex) {
2627            Rlog.e(TAG, "nvWriteCdmaPrl RemoteException", ex);
2628        } catch (NullPointerException ex) {
2629            Rlog.e(TAG, "nvWriteCdmaPrl NPE", ex);
2630        }
2631        return false;
2632    }
2633
2634    /**
2635     * Perform the specified type of NV config reset. The radio will be taken offline
2636     * and the device must be rebooted after the operation. Used for device
2637     * configuration by some CDMA operators.
2638     * <p>
2639     * Requires Permission:
2640     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2641     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2642     *
2643     * @param resetType reset type: 1: reload NV reset, 2: erase NV reset, 3: factory NV reset
2644     * @return true on success; false on any failure.
2645     *
2646     * @hide
2647     */
2648    public boolean nvResetConfig(int resetType) {
2649        try {
2650            return getITelephony().nvResetConfig(resetType);
2651        } catch (RemoteException ex) {
2652            Rlog.e(TAG, "nvResetConfig RemoteException", ex);
2653        } catch (NullPointerException ex) {
2654            Rlog.e(TAG, "nvResetConfig NPE", ex);
2655        }
2656        return false;
2657    }
2658
2659    /**
2660     * Returns Default subscription.
2661     */
2662    private static long getDefaultSubscription() {
2663        return SubscriptionManager.getDefaultSubId();
2664    }
2665
2666    /**
2667     * Returns Default phone.
2668     */
2669    private static int getDefaultPhone() {
2670        return SubscriptionManager.getPhoneId(SubscriptionManager.getDefaultSubId());
2671    }
2672
2673    /** {@hide} */
2674    public int getDefaultSim() {
2675        return SubscriptionManager.getSlotId(SubscriptionManager.getDefaultSubId());
2676    }
2677
2678    /**
2679     * Sets the telephony property with the value specified.
2680     *
2681     * @hide
2682     */
2683    public static void setTelephonyProperty(int phoneId, String property, String value) {
2684        Rlog.d(TAG, "setTelephonyProperty property: " + property + " phoneId: " + phoneId +
2685                " value: " + value);
2686        String propVal = "";
2687        String p[] = null;
2688        String prop = SystemProperties.get(property);
2689
2690        if (value == null) {
2691            value = "";
2692        }
2693
2694        if (prop != null) {
2695            p = prop.split(",");
2696        }
2697
2698        if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2699            Rlog.d(TAG, "setTelephonyProperty invalid phone id");
2700            return;
2701        }
2702
2703        for (int i = 0; i < phoneId; i++) {
2704            String str = "";
2705            if ((p != null) && (i < p.length)) {
2706                str = p[i];
2707            }
2708            propVal = propVal + str + ",";
2709        }
2710
2711        propVal = propVal + value;
2712        if (p != null) {
2713            for (int i = phoneId + 1; i < p.length; i++) {
2714                propVal = propVal + "," + p[i];
2715            }
2716        }
2717
2718        // TODO: workaround for QC
2719        if (property.length() > SystemProperties.PROP_NAME_MAX || propVal.length() > SystemProperties.PROP_VALUE_MAX) {
2720            Rlog.d(TAG, "setTelephonyProperty length too long:" + property + ", " + propVal);
2721            return;
2722        }
2723
2724        Rlog.d(TAG, "setTelephonyProperty property=" + property + " propVal=" + propVal);
2725        SystemProperties.set(property, propVal);
2726    }
2727
2728    /**
2729     * Convenience function for retrieving a value from the secure settings
2730     * value list as an integer.  Note that internally setting values are
2731     * always stored as strings; this function converts the string to an
2732     * integer for you.
2733     * <p>
2734     * This version does not take a default value.  If the setting has not
2735     * been set, or the string value is not a number,
2736     * it throws {@link SettingNotFoundException}.
2737     *
2738     * @param cr The ContentResolver to access.
2739     * @param name The name of the setting to retrieve.
2740     * @param index The index of the list
2741     *
2742     * @throws SettingNotFoundException Thrown if a setting by the given
2743     * name can't be found or the setting value is not an integer.
2744     *
2745     * @return The value at the given index of settings.
2746     * @hide
2747     */
2748    public static int getIntAtIndex(android.content.ContentResolver cr,
2749            String name, int index)
2750            throws android.provider.Settings.SettingNotFoundException {
2751        String v = android.provider.Settings.Global.getString(cr, name);
2752        if (v != null) {
2753            String valArray[] = v.split(",");
2754            if ((index >= 0) && (index < valArray.length) && (valArray[index] != null)) {
2755                try {
2756                    return Integer.parseInt(valArray[index]);
2757                } catch (NumberFormatException e) {
2758                    //Log.e(TAG, "Exception while parsing Integer: ", e);
2759                }
2760            }
2761        }
2762        throw new android.provider.Settings.SettingNotFoundException(name);
2763    }
2764
2765    /**
2766     * Convenience function for updating settings value as coma separated
2767     * integer values. This will either create a new entry in the table if the
2768     * given name does not exist, or modify the value of the existing row
2769     * with that name.  Note that internally setting values are always
2770     * stored as strings, so this function converts the given value to a
2771     * string before storing it.
2772     *
2773     * @param cr The ContentResolver to access.
2774     * @param name The name of the setting to modify.
2775     * @param index The index of the list
2776     * @param value The new value for the setting to be added to the list.
2777     * @return true if the value was set, false on database errors
2778     * @hide
2779     */
2780    public static boolean putIntAtIndex(android.content.ContentResolver cr,
2781            String name, int index, int value) {
2782        String data = "";
2783        String valArray[] = null;
2784        String v = android.provider.Settings.Global.getString(cr, name);
2785
2786        if (index == Integer.MAX_VALUE) {
2787            throw new RuntimeException("putIntAtIndex index == MAX_VALUE index=" + index);
2788        }
2789        if (index < 0) {
2790            throw new RuntimeException("putIntAtIndex index < 0 index=" + index);
2791        }
2792        if (v != null) {
2793            valArray = v.split(",");
2794        }
2795
2796        // Copy the elements from valArray till index
2797        for (int i = 0; i < index; i++) {
2798            String str = "";
2799            if ((valArray != null) && (i < valArray.length)) {
2800                str = valArray[i];
2801            }
2802            data = data + str + ",";
2803        }
2804
2805        data = data + value;
2806
2807        // Copy the remaining elements from valArray if any.
2808        if (valArray != null) {
2809            for (int i = index+1; i < valArray.length; i++) {
2810                data = data + "," + valArray[i];
2811            }
2812        }
2813        return android.provider.Settings.Global.putString(cr, name, data);
2814    }
2815
2816    /**
2817     * Gets the telephony property.
2818     *
2819     * @hide
2820     */
2821    public static String getTelephonyProperty(int phoneId, String property, String defaultVal) {
2822        String propVal = null;
2823        String prop = SystemProperties.get(property);
2824        if ((prop != null) && (prop.length() > 0)) {
2825            String values[] = prop.split(",");
2826            if ((phoneId >= 0) && (phoneId < values.length) && (values[phoneId] != null)) {
2827                propVal = values[phoneId];
2828            }
2829        }
2830        return propVal == null ? defaultVal : propVal;
2831    }
2832
2833    /** @hide */
2834    public int getSimCount() {
2835        if(isMultiSimEnabled()) {
2836            //FIXME Need to get it from Telephony Devcontroller
2837            return 2;
2838        } else {
2839            return 1;
2840        }
2841    }
2842
2843    /**
2844     * Returns the IMS Service Table (IST) that was loaded from the ISIM.
2845     * @return IMS Service Table or null if not present or not loaded
2846     * @hide
2847     */
2848    public String getIsimIst() {
2849        try {
2850            return getSubscriberInfo().getIsimIst();
2851        } catch (RemoteException ex) {
2852            return null;
2853        } catch (NullPointerException ex) {
2854            // This could happen before phone restarts due to crashing
2855            return null;
2856        }
2857    }
2858
2859    /**
2860     * Returns the IMS Proxy Call Session Control Function(PCSCF) that were loaded from the ISIM.
2861     * @return an array of PCSCF strings with one PCSCF per string, or null if
2862     *         not present or not loaded
2863     * @hide
2864     */
2865    public String[] getIsimPcscf() {
2866        try {
2867            return getSubscriberInfo().getIsimPcscf();
2868        } catch (RemoteException ex) {
2869            return null;
2870        } catch (NullPointerException ex) {
2871            // This could happen before phone restarts due to crashing
2872            return null;
2873        }
2874    }
2875
2876    /**
2877     * Returns the response of ISIM Authetification through RIL.
2878     * Returns null if the Authentification hasn't been successed or isn't present iphonesubinfo.
2879     * @return the response of ISIM Authetification, or null if not available
2880     * @hide
2881     * @deprecated
2882     * @see getIccSimChallengeResponse with appType=PhoneConstants.APPTYPE_ISIM
2883     */
2884    public String getIsimChallengeResponse(String nonce){
2885        try {
2886            return getSubscriberInfo().getIsimChallengeResponse(nonce);
2887        } catch (RemoteException ex) {
2888            return null;
2889        } catch (NullPointerException ex) {
2890            // This could happen before phone restarts due to crashing
2891            return null;
2892        }
2893    }
2894
2895    /**
2896     * Returns the response of SIM Authentication through RIL.
2897     * Returns null if the Authentication hasn't been successful
2898     * @param subId subscription ID to be queried
2899     * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx)
2900     * @param data authentication challenge data
2901     * @return the response of SIM Authentication, or null if not available
2902     * @hide
2903     */
2904    public String getIccSimChallengeResponse(long subId, int appType, String data) {
2905        try {
2906            return getSubscriberInfo().getIccSimChallengeResponse(subId, appType, data);
2907        } catch (RemoteException ex) {
2908            return null;
2909        } catch (NullPointerException ex) {
2910            // This could happen before phone starts
2911            return null;
2912        }
2913    }
2914
2915    /**
2916     * Returns the response of SIM Authentication through RIL for the default subscription.
2917     * Returns null if the Authentication hasn't been successful
2918     * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx)
2919     * @param data authentication challenge data
2920     * @return the response of SIM Authentication, or null if not available
2921     * @hide
2922     */
2923    public String getIccSimChallengeResponse(int appType, String data) {
2924        return getIccSimChallengeResponse(getDefaultSubscription(), appType, data);
2925    }
2926
2927    /**
2928     * Get P-CSCF address from PCO after data connection is established or modified.
2929     * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN
2930     * @return array of P-CSCF address
2931     * @hide
2932     */
2933    public String[] getPcscfAddress(String apnType) {
2934        try {
2935            return getITelephony().getPcscfAddress(apnType);
2936        } catch (RemoteException e) {
2937            return new String[0];
2938        }
2939    }
2940
2941    /**
2942     * Set IMS registration state
2943     *
2944     * @param Registration state
2945     * @hide
2946     */
2947    public void setImsRegistrationState(boolean registered) {
2948        try {
2949            getITelephony().setImsRegistrationState(registered);
2950        } catch (RemoteException e) {
2951        }
2952    }
2953
2954    /**
2955     * Get the preferred network type.
2956     * Used for device configuration by some CDMA operators.
2957     * <p>
2958     * Requires Permission:
2959     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2960     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2961     *
2962     * @return the preferred network type, defined in RILConstants.java.
2963     * @hide
2964     */
2965    public int getPreferredNetworkType() {
2966        try {
2967            return getITelephony().getPreferredNetworkType();
2968        } catch (RemoteException ex) {
2969            Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex);
2970        } catch (NullPointerException ex) {
2971            Rlog.e(TAG, "getPreferredNetworkType NPE", ex);
2972        }
2973        return -1;
2974    }
2975
2976    /**
2977     * Set the preferred network type.
2978     * Used for device configuration by some CDMA operators.
2979     * <p>
2980     * Requires Permission:
2981     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
2982     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
2983     *
2984     * @param networkType the preferred network type, defined in RILConstants.java.
2985     * @return true on success; false on any failure.
2986     * @hide
2987     */
2988    public boolean setPreferredNetworkType(int networkType) {
2989        try {
2990            return getITelephony().setPreferredNetworkType(networkType);
2991        } catch (RemoteException ex) {
2992            Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex);
2993        } catch (NullPointerException ex) {
2994            Rlog.e(TAG, "setPreferredNetworkType NPE", ex);
2995        }
2996        return false;
2997    }
2998
2999    /**
3000     * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA.
3001     *
3002     * <p>
3003     * Requires Permission:
3004     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
3005     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
3006     *
3007     * @return true on success; false on any failure.
3008     */
3009    public boolean setGlobalPreferredNetworkType() {
3010        return setPreferredNetworkType(RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA);
3011    }
3012
3013    /**
3014     * Values used to return status for hasCarrierPrivileges call.
3015     */
3016    public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1;
3017    public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0;
3018    public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1;
3019    public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2;
3020
3021    /**
3022     * Has the calling application been granted carrier privileges by the carrier.
3023     *
3024     * If any of the packages in the calling UID has carrier privileges, the
3025     * call will return true. This access is granted by the owner of the UICC
3026     * card and does not depend on the registered carrier.
3027     *
3028     * TODO: Add a link to documentation.
3029     *
3030     * @return CARRIER_PRIVILEGE_STATUS_HAS_ACCESS if the app has carrier privileges.
3031     *         CARRIER_PRIVILEGE_STATUS_NO_ACCESS if the app does not have carrier privileges.
3032     *         CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED if the carrier rules are not loaded.
3033     *         CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES if there was an error loading carrier
3034     *             rules (or if there are no rules).
3035     */
3036    public int hasCarrierPrivileges() {
3037        try {
3038            return getITelephony().hasCarrierPrivileges();
3039        } catch (RemoteException ex) {
3040            Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex);
3041        } catch (NullPointerException ex) {
3042            Rlog.e(TAG, "hasCarrierPrivileges NPE", ex);
3043        }
3044        return CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3045    }
3046
3047    /**
3048     * Override the branding for the current ICCID.
3049     *
3050     * Once set, whenever the SIM is present in the device, the service
3051     * provider name (SPN) and the operator name will both be replaced by the
3052     * brand value input. To unset the value, the same function should be
3053     * called with a null brand value.
3054     *
3055     * <p>Requires Permission:
3056     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
3057     *  or has to be carrier app - see #hasCarrierPrivileges.
3058     *
3059     * @param brand The brand name to display/set.
3060     * @return true if the operation was executed correctly.
3061     */
3062    public boolean setOperatorBrandOverride(String brand) {
3063        try {
3064            return getITelephony().setOperatorBrandOverride(brand);
3065        } catch (RemoteException ex) {
3066            Rlog.e(TAG, "setOperatorBrandOverride RemoteException", ex);
3067        } catch (NullPointerException ex) {
3068            Rlog.e(TAG, "setOperatorBrandOverride NPE", ex);
3069        }
3070        return false;
3071    }
3072
3073    /**
3074     * Expose the rest of ITelephony to @SystemApi
3075     */
3076
3077    /** @hide */
3078    @SystemApi
3079    public String getCdmaMdn() {
3080        return getCdmaMdn(getDefaultSubscription());
3081    }
3082
3083    /** @hide */
3084    @SystemApi
3085    public String getCdmaMdn(long subId) {
3086        try {
3087            return getITelephony().getCdmaMdn(subId);
3088        } catch (RemoteException ex) {
3089            return null;
3090        } catch (NullPointerException ex) {
3091            return null;
3092        }
3093    }
3094
3095    /** @hide */
3096    @SystemApi
3097    public String getCdmaMin() {
3098        return getCdmaMin(getDefaultSubscription());
3099    }
3100
3101    /** @hide */
3102    @SystemApi
3103    public String getCdmaMin(long subId) {
3104        try {
3105            return getITelephony().getCdmaMin(subId);
3106        } catch (RemoteException ex) {
3107            return null;
3108        } catch (NullPointerException ex) {
3109            return null;
3110        }
3111    }
3112
3113    /** @hide */
3114    @SystemApi
3115    public int checkCarrierPrivilegesForPackage(String pkgname) {
3116        try {
3117            return getITelephony().checkCarrierPrivilegesForPackage(pkgname);
3118        } catch (RemoteException ex) {
3119            Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex);
3120        } catch (NullPointerException ex) {
3121            Rlog.e(TAG, "hasCarrierPrivileges NPE", ex);
3122        }
3123        return CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3124    }
3125
3126    /** @hide */
3127    @SystemApi
3128    public List<String> getCarrierPackageNamesForIntent(Intent intent) {
3129        try {
3130            return getITelephony().getCarrierPackageNamesForIntent(intent);
3131        } catch (RemoteException ex) {
3132            Rlog.e(TAG, "getCarrierPackageNamesForIntent RemoteException", ex);
3133        } catch (NullPointerException ex) {
3134            Rlog.e(TAG, "getCarrierPackageNamesForIntent NPE", ex);
3135        }
3136        return null;
3137    }
3138
3139    /** @hide */
3140    @SystemApi
3141    public void dial(String number) {
3142        try {
3143            getITelephony().dial(number);
3144        } catch (RemoteException e) {
3145            Log.e(TAG, "Error calling ITelephony#dial", e);
3146        }
3147    }
3148
3149    /** @hide */
3150    @SystemApi
3151    public void call(String callingPackage, String number) {
3152        try {
3153            getITelephony().call(callingPackage, number);
3154        } catch (RemoteException e) {
3155            Log.e(TAG, "Error calling ITelephony#call", e);
3156        }
3157    }
3158
3159    /** @hide */
3160    @SystemApi
3161    public boolean endCall() {
3162        try {
3163            return getITelephony().endCall();
3164        } catch (RemoteException e) {
3165            Log.e(TAG, "Error calling ITelephony#endCall", e);
3166        }
3167        return false;
3168    }
3169
3170    /** @hide */
3171    @SystemApi
3172    public void answerRingingCall() {
3173        try {
3174            getITelephony().answerRingingCall();
3175        } catch (RemoteException e) {
3176            Log.e(TAG, "Error calling ITelephony#answerRingingCall", e);
3177        }
3178    }
3179
3180    /** @hide */
3181    @SystemApi
3182    public void silenceRinger() {
3183        try {
3184            getTelecommService().silenceRinger();
3185        } catch (RemoteException e) {
3186            Log.e(TAG, "Error calling ITelecommService#silenceRinger", e);
3187        }
3188    }
3189
3190    /** @hide */
3191    @SystemApi
3192    public boolean isOffhook() {
3193        try {
3194            return getITelephony().isOffhook();
3195        } catch (RemoteException e) {
3196            Log.e(TAG, "Error calling ITelephony#isOffhook", e);
3197        }
3198        return false;
3199    }
3200
3201    /** @hide */
3202    @SystemApi
3203    public boolean isRinging() {
3204        try {
3205            return getITelephony().isRinging();
3206        } catch (RemoteException e) {
3207            Log.e(TAG, "Error calling ITelephony#isRinging", e);
3208        }
3209        return false;
3210    }
3211
3212    /** @hide */
3213    @SystemApi
3214    public boolean isIdle() {
3215        try {
3216            return getITelephony().isIdle();
3217        } catch (RemoteException e) {
3218            Log.e(TAG, "Error calling ITelephony#isIdle", e);
3219        }
3220        return true;
3221    }
3222
3223    /** @hide */
3224    @SystemApi
3225    public boolean isRadioOn() {
3226        try {
3227            return getITelephony().isRadioOn();
3228        } catch (RemoteException e) {
3229            Log.e(TAG, "Error calling ITelephony#isRadioOn", e);
3230        }
3231        return false;
3232    }
3233
3234    /** @hide */
3235    @SystemApi
3236    public boolean isSimPinEnabled() {
3237        try {
3238            return getITelephony().isSimPinEnabled();
3239        } catch (RemoteException e) {
3240            Log.e(TAG, "Error calling ITelephony#isSimPinEnabled", e);
3241        }
3242        return false;
3243    }
3244
3245    /** @hide */
3246    @SystemApi
3247    public boolean supplyPin(String pin) {
3248        try {
3249            return getITelephony().supplyPin(pin);
3250        } catch (RemoteException e) {
3251            Log.e(TAG, "Error calling ITelephony#supplyPin", e);
3252        }
3253        return false;
3254    }
3255
3256    /** @hide */
3257    @SystemApi
3258    public boolean supplyPuk(String puk, String pin) {
3259        try {
3260            return getITelephony().supplyPuk(puk, pin);
3261        } catch (RemoteException e) {
3262            Log.e(TAG, "Error calling ITelephony#supplyPuk", e);
3263        }
3264        return false;
3265    }
3266
3267    /** @hide */
3268    @SystemApi
3269    public int[] supplyPinReportResult(String pin) {
3270        try {
3271            return getITelephony().supplyPinReportResult(pin);
3272        } catch (RemoteException e) {
3273            Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e);
3274        }
3275        return new int[0];
3276    }
3277
3278    /** @hide */
3279    @SystemApi
3280    public int[] supplyPukReportResult(String puk, String pin) {
3281        try {
3282            return getITelephony().supplyPukReportResult(puk, pin);
3283        } catch (RemoteException e) {
3284            Log.e(TAG, "Error calling ITelephony#]", e);
3285        }
3286        return new int[0];
3287    }
3288
3289    /** @hide */
3290    @SystemApi
3291    public boolean handlePinMmi(String dialString) {
3292        try {
3293            return getITelephony().handlePinMmi(dialString);
3294        } catch (RemoteException e) {
3295            Log.e(TAG, "Error calling ITelephony#handlePinMmi", e);
3296        }
3297        return false;
3298    }
3299
3300    /** @hide */
3301    @SystemApi
3302    public void toggleRadioOnOff() {
3303        try {
3304            getITelephony().toggleRadioOnOff();
3305        } catch (RemoteException e) {
3306            Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e);
3307        }
3308    }
3309
3310    /** @hide */
3311    @SystemApi
3312    public boolean setRadio(boolean turnOn) {
3313        try {
3314            return getITelephony().setRadio(turnOn);
3315        } catch (RemoteException e) {
3316            Log.e(TAG, "Error calling ITelephony#setRadio", e);
3317        }
3318        return false;
3319    }
3320
3321    /** @hide */
3322    @SystemApi
3323    public boolean setRadioPower(boolean turnOn) {
3324        try {
3325            return getITelephony().setRadioPower(turnOn);
3326        } catch (RemoteException e) {
3327            Log.e(TAG, "Error calling ITelephony#setRadioPower", e);
3328        }
3329        return false;
3330    }
3331
3332    /** @hide */
3333    @SystemApi
3334    public void updateServiceLocation() {
3335        try {
3336            getITelephony().updateServiceLocation();
3337        } catch (RemoteException e) {
3338            Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e);
3339        }
3340    }
3341
3342    /** @hide */
3343    @SystemApi
3344    public boolean enableDataConnectivity() {
3345        try {
3346            return getITelephony().enableDataConnectivity();
3347        } catch (RemoteException e) {
3348            Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e);
3349        }
3350        return false;
3351    }
3352
3353    /** @hide */
3354    @SystemApi
3355    public boolean disableDataConnectivity() {
3356        try {
3357            return getITelephony().disableDataConnectivity();
3358        } catch (RemoteException e) {
3359            Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e);
3360        }
3361        return false;
3362    }
3363
3364    /** @hide */
3365    @SystemApi
3366    public boolean isDataConnectivityPossible() {
3367        try {
3368            return getITelephony().isDataConnectivityPossible();
3369        } catch (RemoteException e) {
3370            Log.e(TAG, "Error calling ITelephony#isDataConnectivityPossible", e);
3371        }
3372        return false;
3373    }
3374
3375    /** @hide */
3376    @SystemApi
3377    public boolean needsOtaServiceProvisioning() {
3378        try {
3379            return getITelephony().needsOtaServiceProvisioning();
3380        } catch (RemoteException e) {
3381            Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e);
3382        }
3383        return false;
3384    }
3385
3386    /** @hide */
3387    @SystemApi
3388    public void setDataEnabled(boolean enable) {
3389        try {
3390            getITelephony().setDataEnabled(enable);
3391        } catch (RemoteException e) {
3392            Log.e(TAG, "Error calling ITelephony#setDataEnabled", e);
3393        }
3394    }
3395
3396    /** @hide */
3397    @SystemApi
3398    public boolean getDataEnabled() {
3399        try {
3400            return getITelephony().getDataEnabled();
3401        } catch (RemoteException e) {
3402            Log.e(TAG, "Error calling ITelephony#getDataEnabled", e);
3403        }
3404        return false;
3405    }
3406
3407    /**
3408     * Set whether Android should display a simplified Mobile Network Settings UI.
3409     * The setting won't be persisted during power cycle.
3410     * <p>
3411     * Requires Permission:
3412     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
3413     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
3414     *
3415     * @param enable true means enabling the simplified UI.
3416     * @hide
3417     */
3418    public void enableSimplifiedNetworkSettings(boolean enable) {
3419        enableSimplifiedNetworkSettings(getDefaultSubscription(), enable);
3420    }
3421
3422    /**
3423     * Set whether Android should display a simplified Mobile Network Settings UI.
3424     * The setting won't be persisted during power cycle.
3425     * <p>
3426     * Requires Permission:
3427     *   {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}
3428     * Or the calling app has carrier privileges. @see #hasCarrierPrivileges
3429     *
3430     * @param subId for which the simplified UI should be enabled or disabled.
3431     * @param enable true means enabling the simplified UI.
3432     * @hide
3433     */
3434    public void enableSimplifiedNetworkSettings(long subId, boolean enable) {
3435        try {
3436            getITelephony().enableSimplifiedNetworkSettings(subId, enable);
3437        } catch (RemoteException ex) {
3438        } catch (NullPointerException ex) {
3439        }
3440    }
3441
3442    /**
3443     * Get whether a simplified Mobile Network Settings UI is enabled.
3444     * <p>
3445     * Requires Permission:
3446     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3447     *
3448     * @return true if the simplified UI is enabled.
3449     * @hide
3450     */
3451    public boolean getSimplifiedNetworkSettingsEnabled() {
3452        return getSimplifiedNetworkSettingsEnabled(getDefaultSubscription());
3453    }
3454
3455    /**
3456     * Get whether a simplified Mobile Network Settings UI is enabled.
3457     * <p>
3458     * Requires Permission:
3459     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3460     *
3461     * @param subId for which the simplified UI should be enabled or disabled.
3462     * @return true if the simplified UI is enabled.
3463     * @hide
3464     */
3465    public boolean getSimplifiedNetworkSettingsEnabled(long subId) {
3466        try {
3467            return getITelephony().getSimplifiedNetworkSettingsEnabled(subId);
3468        } catch (RemoteException ex) {
3469        } catch (NullPointerException ex) {
3470        }
3471        return false;
3472    }
3473
3474    /**
3475     * Returns the result and response from RIL for oem request
3476     *
3477     * @param oemReq the data is sent to ril.
3478     * @param oemResp the respose data from RIL.
3479     * @return negative value request was not handled or get error
3480     *         0 request was handled succesfully, but no response data
3481     *         positive value success, data length of response
3482     * @hide
3483     */
3484    public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3485        try {
3486            return getITelephony().invokeOemRilRequestRaw(oemReq, oemResp);
3487        } catch (RemoteException ex) {
3488        } catch (NullPointerException ex) {
3489        }
3490        return -1;
3491    }
3492}
3493