2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.telephony;
19 import android.annotation.SdkConstant;
20 import android.annotation.SdkConstant.SdkConstantType;
21 import android.content.Context;
22 import android.os.Bundle;
23 import android.os.RemoteException;
24 import android.os.ServiceManager;
25 import android.os.SystemProperties;
26 import android.telephony.Rlog;
28 import com.android.internal.telephony.IPhoneSubInfo;
29 import com.android.internal.telephony.ITelephony;
30 import com.android.internal.telephony.ITelephonyRegistry;
31 import com.android.internal.telephony.PhoneConstants;
32 import com.android.internal.telephony.RILConstants;
33 import com.android.internal.telephony.TelephonyProperties;
35 import java.io.FileInputStream;
36 import java.io.IOException;
37 import java.util.List;
38 import java.util.regex.Matcher;
39 import java.util.regex.Pattern;
42 * Provides access to information about the telephony services on
43 * the device. Applications can use the methods in this class to
44 * determine telephony services and states, as well as to access some
45 * types of subscriber information. Applications can also register
46 * a listener to receive notification of telephony state changes.
48 * You do not instantiate this class directly; instead, you retrieve
49 * a reference to an instance through
50 * {@link android.content.Context#getSystemService
51 * Context.getSystemService(Context.TELEPHONY_SERVICE)}.
53 * Note that access to some telephony information is
54 * permission-protected. Your application cannot access the protected
55 * information unless it has the appropriate permissions declared in
56 * its manifest file. Where permissions apply, they are noted in the
57 * the methods through which you access the protected information.
59 public class TelephonyManager {
60 private static final String TAG = "TelephonyManager";
62 private static ITelephonyRegistry sRegistry;
63 private final Context mContext;
66 public TelephonyManager(Context context) {
67 Context appContext = context.getApplicationContext();
68 if (appContext != null) {
69 mContext = appContext;
74 if (sRegistry == null) {
75 sRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService(
76 "telephony.registry"));
81 private TelephonyManager() {
85 private static TelephonyManager sInstance = new TelephonyManager();
88 /* @deprecated - use getSystemService as described above */
89 public static TelephonyManager getDefault() {
94 public static TelephonyManager from(Context context) {
95 return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
99 // Broadcast Intent actions
103 * Broadcast intent action indicating that the call state (cellular)
104 * on the device has changed.
107 * The {@link #EXTRA_STATE} extra indicates the new call state.
108 * If the new state is RINGING, a second extra
109 * {@link #EXTRA_INCOMING_NUMBER} provides the incoming phone number as
113 * Requires the READ_PHONE_STATE permission.
116 * This was a {@link android.content.Context#sendStickyBroadcast sticky}
117 * broadcast in version 1.0, but it is no longer sticky.
118 * Instead, use {@link #getCallState} to synchronously query the current call state.
121 * @see #EXTRA_INCOMING_NUMBER
124 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
125 public static final String ACTION_PHONE_STATE_CHANGED =
126 "android.intent.action.PHONE_STATE";
129 * The Phone app sends this intent when a user opts to respond-via-message during an incoming
130 * call. By default, the device's default SMS app consumes this message and sends a text message
131 * to the caller. A third party app can also provide this functionality by consuming this Intent
132 * with a {@link android.app.Service} and sending the message using its own messaging system.
133 * <p>The intent contains a URI (available from {@link android.content.Intent#getData})
134 * describing the recipient, using either the {@code sms:}, {@code smsto:}, {@code mms:},
135 * or {@code mmsto:} URI schema. Each of these URI schema carry the recipient information the
136 * same way: the path part of the URI contains the recipient's phone number or a comma-separated
137 * set of phone numbers if there are multiple recipients. For example, {@code
138 * smsto:2065551234}.</p>
140 * <p>The intent may also contain extras for the message text (in {@link
141 * android.content.Intent#EXTRA_TEXT}) and a message subject
142 * (in {@link android.content.Intent#EXTRA_SUBJECT}).</p>
144 * <p class="note"><strong>Note:</strong>
145 * The intent-filter that consumes this Intent needs to be in a {@link android.app.Service}
147 * permission {@link android.Manifest.permission#SEND_RESPOND_VIA_MESSAGE}.</p>
148 * <p>For example, the service that receives this intent can be declared in the manifest file
149 * with an intent filter like this:</p>
151 * <!-- Service that delivers SMS messages received from the phone "quick response" -->
152 * <service android:name=".HeadlessSmsSendService"
153 * android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
154 * android:exported="true" >
156 * <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
157 * <category android:name="android.intent.category.DEFAULT" />
158 * <data android:scheme="sms" />
159 * <data android:scheme="smsto" />
160 * <data android:scheme="mms" />
161 * <data android:scheme="mmsto" />
162 * </intent-filter>
163 * </service></pre>
167 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
168 public static final String ACTION_RESPOND_VIA_MESSAGE =
169 "android.intent.action.RESPOND_VIA_MESSAGE";
172 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast
173 * for a String containing the new call state.
175 * @see #EXTRA_STATE_IDLE
176 * @see #EXTRA_STATE_RINGING
177 * @see #EXTRA_STATE_OFFHOOK
181 * {@link android.content.Intent#getStringExtra(String)}.
183 public static final String EXTRA_STATE = PhoneConstants.STATE_KEY;
186 * Value used with {@link #EXTRA_STATE} corresponding to
187 * {@link #CALL_STATE_IDLE}.
189 public static final String EXTRA_STATE_IDLE = PhoneConstants.State.IDLE.toString();
192 * Value used with {@link #EXTRA_STATE} corresponding to
193 * {@link #CALL_STATE_RINGING}.
195 public static final String EXTRA_STATE_RINGING = PhoneConstants.State.RINGING.toString();
198 * Value used with {@link #EXTRA_STATE} corresponding to
199 * {@link #CALL_STATE_OFFHOOK}.
201 public static final String EXTRA_STATE_OFFHOOK = PhoneConstants.State.OFFHOOK.toString();
204 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast
205 * for a String containing the incoming phone number.
206 * Only valid when the new call state is RINGING.
210 * {@link android.content.Intent#getStringExtra(String)}.
212 public static final String EXTRA_INCOMING_NUMBER = "incoming_number";
222 * Returns the software version number for the device, for example,
223 * the IMEI/SV for GSM phones. Return null if the software version is
226 * <p>Requires Permission:
227 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
229 public String getDeviceSoftwareVersion() {
231 return getSubscriberInfo().getDeviceSvn();
232 } catch (RemoteException ex) {
234 } catch (NullPointerException ex) {
240 * Returns the unique device ID, for example, the IMEI for GSM and the MEID
241 * or ESN for CDMA phones. Return null if device ID is not available.
243 * <p>Requires Permission:
244 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
246 public String getDeviceId() {
248 return getSubscriberInfo().getDeviceId();
249 } catch (RemoteException ex) {
251 } catch (NullPointerException ex) {
257 * Returns the current location of the device.
259 * If there is only one radio in the device and that radio has an LTE connection,
260 * this method will return null. The implementation must not to try add LTE
261 * identifiers into the existing cdma/gsm classes.
263 * In the future this call will be deprecated.
265 * @return Current location of the device or null if not available.
267 * <p>Requires Permission:
268 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or
269 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION}.
271 public CellLocation getCellLocation() {
273 Bundle bundle = getITelephony().getCellLocation();
274 if (bundle.isEmpty()) return null;
275 CellLocation cl = CellLocation.newFromBundle(bundle);
279 } catch (RemoteException ex) {
281 } catch (NullPointerException ex) {
287 * Enables location update notifications. {@link PhoneStateListener#onCellLocationChanged
288 * PhoneStateListener.onCellLocationChanged} will be called on location updates.
290 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES
291 * CONTROL_LOCATION_UPDATES}
295 public void enableLocationUpdates() {
297 getITelephony().enableLocationUpdates();
298 } catch (RemoteException ex) {
299 } catch (NullPointerException ex) {
304 * Disables location update notifications. {@link PhoneStateListener#onCellLocationChanged
305 * PhoneStateListener.onCellLocationChanged} will be called on location updates.
307 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES
308 * CONTROL_LOCATION_UPDATES}
312 public void disableLocationUpdates() {
314 getITelephony().disableLocationUpdates();
315 } catch (RemoteException ex) {
316 } catch (NullPointerException ex) {
321 * Returns the neighboring cell information of the device. The getAllCellInfo is preferred
322 * and use this only if getAllCellInfo return nulls or an empty list.
324 * In the future this call will be deprecated.
326 * @return List of NeighboringCellInfo or null if info unavailable.
328 * <p>Requires Permission:
329 * (@link android.Manifest.permission#ACCESS_COARSE_UPDATES}
331 public List<NeighboringCellInfo> getNeighboringCellInfo() {
333 return getITelephony().getNeighboringCellInfo(mContext.getBasePackageName());
334 } catch (RemoteException ex) {
336 } catch (NullPointerException ex) {
341 /** No phone radio. */
342 public static final int PHONE_TYPE_NONE = PhoneConstants.PHONE_TYPE_NONE;
343 /** Phone radio is GSM. */
344 public static final int PHONE_TYPE_GSM = PhoneConstants.PHONE_TYPE_GSM;
345 /** Phone radio is CDMA. */
346 public static final int PHONE_TYPE_CDMA = PhoneConstants.PHONE_TYPE_CDMA;
347 /** Phone is via SIP. */
348 public static final int PHONE_TYPE_SIP = PhoneConstants.PHONE_TYPE_SIP;
351 * Returns the current phone type.
352 * TODO: This is a last minute change and hence hidden.
354 * @see #PHONE_TYPE_NONE
355 * @see #PHONE_TYPE_GSM
356 * @see #PHONE_TYPE_CDMA
357 * @see #PHONE_TYPE_SIP
361 public int getCurrentPhoneType() {
363 ITelephony telephony = getITelephony();
364 if (telephony != null) {
365 return telephony.getActivePhoneType();
367 // This can happen when the ITelephony interface is not up yet.
368 return getPhoneTypeFromProperty();
370 } catch (RemoteException ex) {
371 // This shouldn't happen in the normal case, as a backup we
372 // read from the system property.
373 return getPhoneTypeFromProperty();
374 } catch (NullPointerException ex) {
375 // This shouldn't happen in the normal case, as a backup we
376 // read from the system property.
377 return getPhoneTypeFromProperty();
382 * Returns a constant indicating the device phone type. This
383 * indicates the type of radio used to transmit voice calls.
385 * @see #PHONE_TYPE_NONE
386 * @see #PHONE_TYPE_GSM
387 * @see #PHONE_TYPE_CDMA
388 * @see #PHONE_TYPE_SIP
390 public int getPhoneType() {
391 if (!isVoiceCapable()) {
392 return PHONE_TYPE_NONE;
394 return getCurrentPhoneType();
397 private int getPhoneTypeFromProperty() {
399 SystemProperties.getInt(TelephonyProperties.CURRENT_ACTIVE_PHONE,
400 getPhoneTypeFromNetworkType());
404 private int getPhoneTypeFromNetworkType() {
405 // When the system property CURRENT_ACTIVE_PHONE, has not been set,
406 // use the system property for default network type.
407 // This is a fail safe, and can only happen at first boot.
408 int mode = SystemProperties.getInt("ro.telephony.default_network", -1);
410 return PHONE_TYPE_NONE;
411 return getPhoneType(mode);
415 * This function returns the type of the phone, depending
416 * on the network mode.
423 public static int getPhoneType(int networkMode) {
424 switch(networkMode) {
425 case RILConstants.NETWORK_MODE_CDMA:
426 case RILConstants.NETWORK_MODE_CDMA_NO_EVDO:
427 case RILConstants.NETWORK_MODE_EVDO_NO_CDMA:
428 return PhoneConstants.PHONE_TYPE_CDMA;
430 case RILConstants.NETWORK_MODE_WCDMA_PREF:
431 case RILConstants.NETWORK_MODE_GSM_ONLY:
432 case RILConstants.NETWORK_MODE_WCDMA_ONLY:
433 case RILConstants.NETWORK_MODE_GSM_UMTS:
434 case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA:
435 case RILConstants.NETWORK_MODE_LTE_WCDMA:
436 return PhoneConstants.PHONE_TYPE_GSM;
438 // Use CDMA Phone for the global mode including CDMA
439 case RILConstants.NETWORK_MODE_GLOBAL:
440 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO:
441 case RILConstants.NETWORK_MODE_LTE_CMDA_EVDO_GSM_WCDMA:
442 return PhoneConstants.PHONE_TYPE_CDMA;
444 case RILConstants.NETWORK_MODE_LTE_ONLY:
445 if (getLteOnCdmaModeStatic() == PhoneConstants.LTE_ON_CDMA_TRUE) {
446 return PhoneConstants.PHONE_TYPE_CDMA;
448 return PhoneConstants.PHONE_TYPE_GSM;
451 return PhoneConstants.PHONE_TYPE_GSM;
456 * The contents of the /proc/cmdline file
458 private static String getProcCmdLine()
461 FileInputStream is = null;
463 is = new FileInputStream("/proc/cmdline");
464 byte [] buffer = new byte[2048];
465 int count = is.read(buffer);
467 cmdline = new String(buffer, 0, count);
469 } catch (IOException e) {
470 Rlog.d(TAG, "No /proc/cmdline exception=" + e);
475 } catch (IOException e) {
479 Rlog.d(TAG, "/proc/cmdline=" + cmdline);
483 /** Kernel command line */
484 private static final String sKernelCmdLine = getProcCmdLine();
486 /** Pattern for selecting the product type from the kernel command line */
487 private static final Pattern sProductTypePattern =
488 Pattern.compile("\\sproduct_type\\s*=\\s*(\\w+)");
490 /** The ProductType used for LTE on CDMA devices */
491 private static final String sLteOnCdmaProductType =
492 SystemProperties.get(TelephonyProperties.PROPERTY_LTE_ON_CDMA_PRODUCT_TYPE, "");
495 * Return if the current radio is LTE on CDMA. This
496 * is a tri-state return value as for a period of time
497 * the mode may be unknown.
499 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE}
500 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE}
504 public static int getLteOnCdmaModeStatic() {
507 String productType = "";
509 curVal = SystemProperties.getInt(TelephonyProperties.PROPERTY_LTE_ON_CDMA_DEVICE,
510 PhoneConstants.LTE_ON_CDMA_UNKNOWN);
512 if (retVal == PhoneConstants.LTE_ON_CDMA_UNKNOWN) {
513 Matcher matcher = sProductTypePattern.matcher(sKernelCmdLine);
514 if (matcher.find()) {
515 productType = matcher.group(1);
516 if (sLteOnCdmaProductType.equals(productType)) {
517 retVal = PhoneConstants.LTE_ON_CDMA_TRUE;
519 retVal = PhoneConstants.LTE_ON_CDMA_FALSE;
522 retVal = PhoneConstants.LTE_ON_CDMA_FALSE;
526 Rlog.d(TAG, "getLteOnCdmaMode=" + retVal + " curVal=" + curVal +
527 " product_type='" + productType +
528 "' lteOnCdmaProductType='" + sLteOnCdmaProductType + "'");
539 * Returns the alphabetic name of current registered operator.
541 * Availability: Only when user is registered to a network. Result may be
542 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
543 * on a CDMA network).
545 public String getNetworkOperatorName() {
546 return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ALPHA);
550 * Returns the numeric name (MCC+MNC) of current registered operator.
552 * Availability: Only when user is registered to a network. Result may be
553 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
554 * on a CDMA network).
556 public String getNetworkOperator() {
557 return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC);
561 * Returns true if the device is considered roaming on the current
562 * network, for GSM purposes.
564 * Availability: Only when user registered to a network.
566 public boolean isNetworkRoaming() {
567 return "true".equals(SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ISROAMING));
571 * Returns the ISO country code equivalent of the current registered
572 * operator's MCC (Mobile Country Code).
574 * Availability: Only when user is registered to a network. Result may be
575 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
576 * on a CDMA network).
578 public String getNetworkCountryIso() {
579 return SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY);
582 /** Network type is unknown */
583 public static final int NETWORK_TYPE_UNKNOWN = 0;
584 /** Current network is GPRS */
585 public static final int NETWORK_TYPE_GPRS = 1;
586 /** Current network is EDGE */
587 public static final int NETWORK_TYPE_EDGE = 2;
588 /** Current network is UMTS */
589 public static final int NETWORK_TYPE_UMTS = 3;
590 /** Current network is CDMA: Either IS95A or IS95B*/
591 public static final int NETWORK_TYPE_CDMA = 4;
592 /** Current network is EVDO revision 0*/
593 public static final int NETWORK_TYPE_EVDO_0 = 5;
594 /** Current network is EVDO revision A*/
595 public static final int NETWORK_TYPE_EVDO_A = 6;
596 /** Current network is 1xRTT*/
597 public static final int NETWORK_TYPE_1xRTT = 7;
598 /** Current network is HSDPA */
599 public static final int NETWORK_TYPE_HSDPA = 8;
600 /** Current network is HSUPA */
601 public static final int NETWORK_TYPE_HSUPA = 9;
602 /** Current network is HSPA */
603 public static final int NETWORK_TYPE_HSPA = 10;
604 /** Current network is iDen */
605 public static final int NETWORK_TYPE_IDEN = 11;
606 /** Current network is EVDO revision B*/
607 public static final int NETWORK_TYPE_EVDO_B = 12;
608 /** Current network is LTE */
609 public static final int NETWORK_TYPE_LTE = 13;
610 /** Current network is eHRPD */
611 public static final int NETWORK_TYPE_EHRPD = 14;
612 /** Current network is HSPA+ */
613 public static final int NETWORK_TYPE_HSPAP = 15;
616 * @return the NETWORK_TYPE_xxxx for current data connection.
618 public int getNetworkType() {
619 return getDataNetworkType();
623 * Returns a constant indicating the radio technology (network type)
624 * currently in use on the device for data transmission.
625 * @return the network type
627 * @see #NETWORK_TYPE_UNKNOWN
628 * @see #NETWORK_TYPE_GPRS
629 * @see #NETWORK_TYPE_EDGE
630 * @see #NETWORK_TYPE_UMTS
631 * @see #NETWORK_TYPE_HSDPA
632 * @see #NETWORK_TYPE_HSUPA
633 * @see #NETWORK_TYPE_HSPA
634 * @see #NETWORK_TYPE_CDMA
635 * @see #NETWORK_TYPE_EVDO_0
636 * @see #NETWORK_TYPE_EVDO_A
637 * @see #NETWORK_TYPE_EVDO_B
638 * @see #NETWORK_TYPE_1xRTT
639 * @see #NETWORK_TYPE_IDEN
640 * @see #NETWORK_TYPE_LTE
641 * @see #NETWORK_TYPE_EHRPD
642 * @see #NETWORK_TYPE_HSPAP
646 public int getDataNetworkType() {
648 ITelephony telephony = getITelephony();
649 if (telephony != null) {
650 return telephony.getDataNetworkType();
652 // This can happen when the ITelephony interface is not up yet.
653 return NETWORK_TYPE_UNKNOWN;
655 } catch(RemoteException ex) {
656 // This shouldn't happen in the normal case
657 return NETWORK_TYPE_UNKNOWN;
658 } catch (NullPointerException ex) {
659 // This could happen before phone restarts due to crashing
660 return NETWORK_TYPE_UNKNOWN;
665 * Returns the NETWORK_TYPE_xxxx for voice
669 public int getVoiceNetworkType() {
671 ITelephony telephony = getITelephony();
672 if (telephony != null) {
673 return telephony.getVoiceNetworkType();
675 // This can happen when the ITelephony interface is not up yet.
676 return NETWORK_TYPE_UNKNOWN;
678 } catch(RemoteException ex) {
679 // This shouldn't happen in the normal case
680 return NETWORK_TYPE_UNKNOWN;
681 } catch (NullPointerException ex) {
682 // This could happen before phone restarts due to crashing
683 return NETWORK_TYPE_UNKNOWN;
687 /** Unknown network class. {@hide} */
688 public static final int NETWORK_CLASS_UNKNOWN = 0;
689 /** Class of broadly defined "2G" networks. {@hide} */
690 public static final int NETWORK_CLASS_2_G = 1;
691 /** Class of broadly defined "3G" networks. {@hide} */
692 public static final int NETWORK_CLASS_3_G = 2;
693 /** Class of broadly defined "4G" networks. {@hide} */
694 public static final int NETWORK_CLASS_4_G = 3;
697 * Return general class of network type, such as "3G" or "4G". In cases
698 * where classification is contentious, this method is conservative.
702 public static int getNetworkClass(int networkType) {
703 switch (networkType) {
704 case NETWORK_TYPE_GPRS:
705 case NETWORK_TYPE_EDGE:
706 case NETWORK_TYPE_CDMA:
707 case NETWORK_TYPE_1xRTT:
708 case NETWORK_TYPE_IDEN:
709 return NETWORK_CLASS_2_G;
710 case NETWORK_TYPE_UMTS:
711 case NETWORK_TYPE_EVDO_0:
712 case NETWORK_TYPE_EVDO_A:
713 case NETWORK_TYPE_HSDPA:
714 case NETWORK_TYPE_HSUPA:
715 case NETWORK_TYPE_HSPA:
716 case NETWORK_TYPE_EVDO_B:
717 case NETWORK_TYPE_EHRPD:
718 case NETWORK_TYPE_HSPAP:
719 return NETWORK_CLASS_3_G;
720 case NETWORK_TYPE_LTE:
721 return NETWORK_CLASS_4_G;
723 return NETWORK_CLASS_UNKNOWN;
728 * Returns a string representation of the radio technology (network type)
729 * currently in use on the device.
730 * @return the name of the radio technology
732 * @hide pending API council review
734 public String getNetworkTypeName() {
735 return getNetworkTypeName(getNetworkType());
739 public static String getNetworkTypeName(int type) {
741 case NETWORK_TYPE_GPRS:
743 case NETWORK_TYPE_EDGE:
745 case NETWORK_TYPE_UMTS:
747 case NETWORK_TYPE_HSDPA:
749 case NETWORK_TYPE_HSUPA:
751 case NETWORK_TYPE_HSPA:
753 case NETWORK_TYPE_CDMA:
755 case NETWORK_TYPE_EVDO_0:
756 return "CDMA - EvDo rev. 0";
757 case NETWORK_TYPE_EVDO_A:
758 return "CDMA - EvDo rev. A";
759 case NETWORK_TYPE_EVDO_B:
760 return "CDMA - EvDo rev. B";
761 case NETWORK_TYPE_1xRTT:
762 return "CDMA - 1xRTT";
763 case NETWORK_TYPE_LTE:
765 case NETWORK_TYPE_EHRPD:
766 return "CDMA - eHRPD";
767 case NETWORK_TYPE_IDEN:
769 case NETWORK_TYPE_HSPAP:
782 /** SIM card state: Unknown. Signifies that the SIM is in transition
783 * between states. For example, when the user inputs the SIM pin
784 * under PIN_REQUIRED state, a query for sim status returns
785 * this state before turning to SIM_STATE_READY. */
786 public static final int SIM_STATE_UNKNOWN = 0;
787 /** SIM card state: no SIM card is available in the device */
788 public static final int SIM_STATE_ABSENT = 1;
789 /** SIM card state: Locked: requires the user's SIM PIN to unlock */
790 public static final int SIM_STATE_PIN_REQUIRED = 2;
791 /** SIM card state: Locked: requires the user's SIM PUK to unlock */
792 public static final int SIM_STATE_PUK_REQUIRED = 3;
793 /** SIM card state: Locked: requries a network PIN to unlock */
794 public static final int SIM_STATE_NETWORK_LOCKED = 4;
795 /** SIM card state: Ready */
796 public static final int SIM_STATE_READY = 5;
799 * @return true if a ICC card is present
801 public boolean hasIccCard() {
803 return getITelephony().hasIccCard();
804 } catch (RemoteException ex) {
805 // Assume no ICC card if remote exception which shouldn't happen
807 } catch (NullPointerException ex) {
808 // This could happen before phone restarts due to crashing
814 * Returns a constant indicating the state of the
817 * @see #SIM_STATE_UNKNOWN
818 * @see #SIM_STATE_ABSENT
819 * @see #SIM_STATE_PIN_REQUIRED
820 * @see #SIM_STATE_PUK_REQUIRED
821 * @see #SIM_STATE_NETWORK_LOCKED
822 * @see #SIM_STATE_READY
824 public int getSimState() {
825 String prop = SystemProperties.get(TelephonyProperties.PROPERTY_SIM_STATE);
826 if ("ABSENT".equals(prop)) {
827 return SIM_STATE_ABSENT;
829 else if ("PIN_REQUIRED".equals(prop)) {
830 return SIM_STATE_PIN_REQUIRED;
832 else if ("PUK_REQUIRED".equals(prop)) {
833 return SIM_STATE_PUK_REQUIRED;
835 else if ("NETWORK_LOCKED".equals(prop)) {
836 return SIM_STATE_NETWORK_LOCKED;
838 else if ("READY".equals(prop)) {
839 return SIM_STATE_READY;
842 return SIM_STATE_UNKNOWN;
847 * Returns the MCC+MNC (mobile country code + mobile network code) of the
848 * provider of the SIM. 5 or 6 decimal digits.
850 * Availability: SIM state must be {@link #SIM_STATE_READY}
854 public String getSimOperator() {
855 return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC);
859 * Returns the Service Provider Name (SPN).
861 * Availability: SIM state must be {@link #SIM_STATE_READY}
865 public String getSimOperatorName() {
866 return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA);
870 * Returns the ISO country code equivalent for the SIM provider's country code.
872 public String getSimCountryIso() {
873 return SystemProperties.get(TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY);
877 * Returns the serial number of the SIM, if applicable. Return null if it is
880 * Requires Permission:
881 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
883 public String getSimSerialNumber() {
885 return getSubscriberInfo().getIccSerialNumber();
886 } catch (RemoteException ex) {
888 } catch (NullPointerException ex) {
889 // This could happen before phone restarts due to crashing
895 * Return if the current radio is LTE on CDMA. This
896 * is a tri-state return value as for a period of time
897 * the mode may be unknown.
899 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE}
900 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE}
904 public int getLteOnCdmaMode() {
906 return getITelephony().getLteOnCdmaMode();
907 } catch (RemoteException ex) {
908 // Assume no ICC card if remote exception which shouldn't happen
909 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
910 } catch (NullPointerException ex) {
911 // This could happen before phone restarts due to crashing
912 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
923 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone.
924 * Return null if it is unavailable.
926 * Requires Permission:
927 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
929 public String getSubscriberId() {
931 return getSubscriberInfo().getSubscriberId();
932 } catch (RemoteException ex) {
934 } catch (NullPointerException ex) {
935 // This could happen before phone restarts due to crashing
941 * Returns the Group Identifier Level1 for a GSM phone.
942 * Return null if it is unavailable.
944 * Requires Permission:
945 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
947 public String getGroupIdLevel1() {
949 return getSubscriberInfo().getGroupIdLevel1();
950 } catch (RemoteException ex) {
952 } catch (NullPointerException ex) {
953 // This could happen before phone restarts due to crashing
959 * Returns the phone number string for line 1, for example, the MSISDN
960 * for a GSM phone. Return null if it is unavailable.
962 * Requires Permission:
963 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
965 public String getLine1Number() {
967 return getSubscriberInfo().getLine1Number();
968 } catch (RemoteException ex) {
970 } catch (NullPointerException ex) {
971 // This could happen before phone restarts due to crashing
977 * Returns the alphabetic identifier associated with the line 1 number.
978 * Return null if it is unavailable.
980 * Requires Permission:
981 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
983 * nobody seems to call this.
985 public String getLine1AlphaTag() {
987 return getSubscriberInfo().getLine1AlphaTag();
988 } catch (RemoteException ex) {
990 } catch (NullPointerException ex) {
991 // This could happen before phone restarts due to crashing
997 * Returns the MSISDN string.
998 * for a GSM phone. Return null if it is unavailable.
1000 * Requires Permission:
1001 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1005 public String getMsisdn() {
1007 return getSubscriberInfo().getMsisdn();
1008 } catch (RemoteException ex) {
1010 } catch (NullPointerException ex) {
1011 // This could happen before phone restarts due to crashing
1017 * Returns the voice mail number. Return null if it is unavailable.
1019 * Requires Permission:
1020 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1022 public String getVoiceMailNumber() {
1024 return getSubscriberInfo().getVoiceMailNumber();
1025 } catch (RemoteException ex) {
1027 } catch (NullPointerException ex) {
1028 // This could happen before phone restarts due to crashing
1034 * Returns the complete voice mail number. Return null if it is unavailable.
1036 * Requires Permission:
1037 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED}
1041 public String getCompleteVoiceMailNumber() {
1043 return getSubscriberInfo().getCompleteVoiceMailNumber();
1044 } catch (RemoteException ex) {
1046 } catch (NullPointerException ex) {
1047 // This could happen before phone restarts due to crashing
1053 * Returns the voice mail count. Return 0 if unavailable.
1055 * Requires Permission:
1056 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1059 public int getVoiceMessageCount() {
1061 return getITelephony().getVoiceMessageCount();
1062 } catch (RemoteException ex) {
1064 } catch (NullPointerException ex) {
1065 // This could happen before phone restarts due to crashing
1071 * Retrieves the alphabetic identifier associated with the voice
1074 * Requires Permission:
1075 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
1077 public String getVoiceMailAlphaTag() {
1079 return getSubscriberInfo().getVoiceMailAlphaTag();
1080 } catch (RemoteException ex) {
1082 } catch (NullPointerException ex) {
1083 // This could happen before phone restarts due to crashing
1089 * Returns the IMS private user identity (IMPI) that was loaded from the ISIM.
1090 * @return the IMPI, or null if not present or not loaded
1093 public String getIsimImpi() {
1095 return getSubscriberInfo().getIsimImpi();
1096 } catch (RemoteException ex) {
1098 } catch (NullPointerException ex) {
1099 // This could happen before phone restarts due to crashing
1105 * Returns the IMS home network domain name that was loaded from the ISIM.
1106 * @return the IMS domain name, or null if not present or not loaded
1109 public String getIsimDomain() {
1111 return getSubscriberInfo().getIsimDomain();
1112 } catch (RemoteException ex) {
1114 } catch (NullPointerException ex) {
1115 // This could happen before phone restarts due to crashing
1121 * Returns the IMS public user identities (IMPU) that were loaded from the ISIM.
1122 * @return an array of IMPU strings, with one IMPU per string, or null if
1123 * not present or not loaded
1126 public String[] getIsimImpu() {
1128 return getSubscriberInfo().getIsimImpu();
1129 } catch (RemoteException ex) {
1131 } catch (NullPointerException ex) {
1132 // This could happen before phone restarts due to crashing
1137 private IPhoneSubInfo getSubscriberInfo() {
1138 // get it each time because that process crashes a lot
1139 return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo"));
1143 /** Device call state: No activity. */
1144 public static final int CALL_STATE_IDLE = 0;
1145 /** Device call state: Ringing. A new call arrived and is
1146 * ringing or waiting. In the latter case, another call is
1147 * already active. */
1148 public static final int CALL_STATE_RINGING = 1;
1149 /** Device call state: Off-hook. At least one call exists
1150 * that is dialing, active, or on hold, and no calls are ringing
1152 public static final int CALL_STATE_OFFHOOK = 2;
1155 * Returns a constant indicating the call state (cellular) on the device.
1157 public int getCallState() {
1159 return getITelephony().getCallState();
1160 } catch (RemoteException ex) {
1161 // the phone process is restarting.
1162 return CALL_STATE_IDLE;
1163 } catch (NullPointerException ex) {
1164 // the phone process is restarting.
1165 return CALL_STATE_IDLE;
1169 /** Data connection activity: No traffic. */
1170 public static final int DATA_ACTIVITY_NONE = 0x00000000;
1171 /** Data connection activity: Currently receiving IP PPP traffic. */
1172 public static final int DATA_ACTIVITY_IN = 0x00000001;
1173 /** Data connection activity: Currently sending IP PPP traffic. */
1174 public static final int DATA_ACTIVITY_OUT = 0x00000002;
1175 /** Data connection activity: Currently both sending and receiving
1176 * IP PPP traffic. */
1177 public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT;
1179 * Data connection is active, but physical link is down
1181 public static final int DATA_ACTIVITY_DORMANT = 0x00000004;
1184 * Returns a constant indicating the type of activity on a data connection
1187 * @see #DATA_ACTIVITY_NONE
1188 * @see #DATA_ACTIVITY_IN
1189 * @see #DATA_ACTIVITY_OUT
1190 * @see #DATA_ACTIVITY_INOUT
1191 * @see #DATA_ACTIVITY_DORMANT
1193 public int getDataActivity() {
1195 return getITelephony().getDataActivity();
1196 } catch (RemoteException ex) {
1197 // the phone process is restarting.
1198 return DATA_ACTIVITY_NONE;
1199 } catch (NullPointerException ex) {
1200 // the phone process is restarting.
1201 return DATA_ACTIVITY_NONE;
1205 /** Data connection state: Unknown. Used before we know the state.
1208 public static final int DATA_UNKNOWN = -1;
1209 /** Data connection state: Disconnected. IP traffic not available. */
1210 public static final int DATA_DISCONNECTED = 0;
1211 /** Data connection state: Currently setting up a data connection. */
1212 public static final int DATA_CONNECTING = 1;
1213 /** Data connection state: Connected. IP traffic should be available. */
1214 public static final int DATA_CONNECTED = 2;
1215 /** Data connection state: Suspended. The connection is up, but IP
1216 * traffic is temporarily unavailable. For example, in a 2G network,
1217 * data activity may be suspended when a voice call arrives. */
1218 public static final int DATA_SUSPENDED = 3;
1221 * Returns a constant indicating the current data connection state
1224 * @see #DATA_DISCONNECTED
1225 * @see #DATA_CONNECTING
1226 * @see #DATA_CONNECTED
1227 * @see #DATA_SUSPENDED
1229 public int getDataState() {
1231 return getITelephony().getDataState();
1232 } catch (RemoteException ex) {
1233 // the phone process is restarting.
1234 return DATA_DISCONNECTED;
1235 } catch (NullPointerException ex) {
1236 return DATA_DISCONNECTED;
1240 private ITelephony getITelephony() {
1241 return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE));
1246 // PhoneStateListener
1251 * Registers a listener object to receive notification of changes
1252 * in specified telephony states.
1254 * To register a listener, pass a {@link PhoneStateListener}
1255 * and specify at least one telephony state of interest in
1256 * the events argument.
1258 * At registration, and when a specified telephony state
1259 * changes, the telephony manager invokes the appropriate
1260 * callback method on the listener object and passes the
1261 * current (udpated) values.
1263 * To unregister a listener, pass the listener object and set the
1264 * events argument to
1265 * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0).
1267 * @param listener The {@link PhoneStateListener} object to register
1269 * @param events The telephony state(s) of interest to the listener,
1270 * as a bitwise-OR combination of {@link PhoneStateListener}
1273 public void listen(PhoneStateListener listener, int events) {
1274 String pkgForDebug = mContext != null ? mContext.getPackageName() : "<unknown>";
1276 Boolean notifyNow = true;
1277 sRegistry.listen(pkgForDebug, listener.callback, events, notifyNow);
1278 } catch (RemoteException ex) {
1279 // system process dead
1280 } catch (NullPointerException ex) {
1281 // system process dead
1286 * Returns the CDMA ERI icon index to display
1290 public int getCdmaEriIconIndex() {
1292 return getITelephony().getCdmaEriIconIndex();
1293 } catch (RemoteException ex) {
1294 // the phone process is restarting.
1296 } catch (NullPointerException ex) {
1302 * Returns the CDMA ERI icon mode,
1308 public int getCdmaEriIconMode() {
1310 return getITelephony().getCdmaEriIconMode();
1311 } catch (RemoteException ex) {
1312 // the phone process is restarting.
1314 } catch (NullPointerException ex) {
1320 * Returns the CDMA ERI text,
1324 public String getCdmaEriText() {
1326 return getITelephony().getCdmaEriText();
1327 } catch (RemoteException ex) {
1328 // the phone process is restarting.
1330 } catch (NullPointerException ex) {
1336 * @return true if the current device is "voice capable".
1338 * "Voice capable" means that this device supports circuit-switched
1339 * (i.e. voice) phone calls over the telephony network, and is allowed
1340 * to display the in-call UI while a cellular voice call is active.
1341 * This will be false on "data only" devices which can't make voice
1342 * calls and don't support any in-call UI.
1344 * Note: the meaning of this flag is subtly different from the
1345 * PackageManager.FEATURE_TELEPHONY system feature, which is available
1346 * on any device with a telephony radio, even if the device is
1349 * @hide pending API review
1351 public boolean isVoiceCapable() {
1352 if (mContext == null) return true;
1353 return mContext.getResources().getBoolean(
1354 com.android.internal.R.bool.config_voice_capable);
1358 * @return true if the current device supports sms service.
1360 * If true, this means that the device supports both sending and
1361 * receiving sms via the telephony network.
1363 * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are
1364 * disabled when device doesn't support sms.
1366 * @hide pending API review
1368 public boolean isSmsCapable() {
1369 if (mContext == null) return true;
1370 return mContext.getResources().getBoolean(
1371 com.android.internal.R.bool.config_sms_capable);
1375 * Returns all observed cell information from all radios on the
1376 * device including the primary and neighboring cells. This does
1377 * not cause or change the rate of PhoneStateListner#onCellInfoChanged.
1379 * The list can include one or more of {@link android.telephony.CellInfoGsm CellInfoGsm},
1380 * {@link android.telephony.CellInfoCdma CellInfoCdma},
1381 * {@link android.telephony.CellInfoLte CellInfoLte} and
1382 * {@link android.telephony.CellInfoWcdma CellInfoCdma} in any combination.
1383 * Specifically on devices with multiple radios it is typical to see instances of
1384 * one or more of any these in the list. In addition 0, 1 or more CellInfo
1385 * objects may return isRegistered() true.
1387 * This is preferred over using getCellLocation although for older
1388 * devices this may return null in which case getCellLocation should
1391 * @return List of CellInfo or null if info unavailable.
1393 * <p>Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}
1395 public List<CellInfo> getAllCellInfo() {
1397 return getITelephony().getAllCellInfo();
1398 } catch (RemoteException ex) {
1400 } catch (NullPointerException ex) {
1406 * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged
1407 * PhoneStateListener.onCellInfoChanged} will be invoked.
1409 * The default, 0, means invoke onCellInfoChanged when any of the reported
1410 * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue
1411 * A onCellInfoChanged.
1413 * @param rateInMillis the rate
1417 public void setCellInfoListRate(int rateInMillis) {
1419 getITelephony().setCellInfoListRate(rateInMillis);
1420 } catch (RemoteException ex) {
1421 } catch (NullPointerException ex) {