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