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