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