blob: 1433b2ac92809ca0f1951cd97c5003a570476905 [file] [log] [blame]
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.telephony;
import static android.content.Context.TELECOM_SERVICE;
import static com.android.internal.util.Preconditions.checkNotNull;
import android.Manifest;
import android.annotation.CallbackExecutor;
import android.annotation.IntDef;
import android.annotation.LongDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SuppressAutoDoc;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage;
import android.annotation.WorkerThread;
import android.app.ActivityThread;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkStats;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.BatteryStats;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.PersistableBundle;
import android.os.Process;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.os.WorkSource;
import android.provider.Settings.SettingNotFoundException;
import android.service.carrier.CarrierIdentifier;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telephony.VisualVoicemailService.VisualVoicemailTask;
import android.telephony.emergency.EmergencyNumber;
import android.telephony.emergency.EmergencyNumber.EmergencyServiceCategories;
import android.telephony.ims.aidl.IImsConfig;
import android.telephony.ims.aidl.IImsMmTelFeature;
import android.telephony.ims.aidl.IImsRcsFeature;
import android.telephony.ims.aidl.IImsRegistration;
import android.telephony.ims.feature.MmTelFeature;
import android.telephony.ims.stub.ImsRegistrationImplBase;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
import com.android.ims.internal.IImsServiceFeatureCallback;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telecom.ITelecomService;
import com.android.internal.telephony.CellNetworkScanResult;
import com.android.internal.telephony.INumberVerificationCallback;
import com.android.internal.telephony.IOns;
import com.android.internal.telephony.IPhoneSubInfo;
import com.android.internal.telephony.ITelephony;
import com.android.internal.telephony.ITelephonyRegistry;
import com.android.internal.telephony.OperatorInfo;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.RILConstants;
import com.android.internal.telephony.TelephonyProperties;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Provides access to information about the telephony services on
* the device. Applications can use the methods in this class to
* determine telephony services and states, as well as to access some
* types of subscriber information. Applications can also register
* a listener to receive notification of telephony state changes.
* <p>
* The returned TelephonyManager will use the default subscription for all calls.
* To call an API for a specific subscription, use {@link #createForSubscriptionId(int)}. e.g.
* <code>
* telephonyManager = defaultSubTelephonyManager.createForSubscriptionId(subId);
* </code>
* <p>
* Note that access to some telephony information is
* permission-protected. Your application cannot access the protected
* information unless it has the appropriate permissions declared in
* its manifest file. Where permissions apply, they are noted in the
* the methods through which you access the protected information.
*/
@SystemService(Context.TELEPHONY_SERVICE)
public class TelephonyManager {
private static final String TAG = "TelephonyManager";
/**
* The key to use when placing the result of {@link #requestModemActivityInfo(ResultReceiver)}
* into the ResultReceiver Bundle.
* @hide
*/
public static final String MODEM_ACTIVITY_RESULT_KEY =
BatteryStats.RESULT_RECEIVER_CONTROLLER_KEY;
/**
* The process name of the Phone app as well as many other apps that use this process name, such
* as settings and vendor components.
* @hide
*/
public static final String PHONE_PROCESS_NAME = "com.android.phone";
/**
* The allowed states of Wi-Fi calling.
*
* @hide
*/
public interface WifiCallingChoices {
/** Always use Wi-Fi calling */
static final int ALWAYS_USE = 0;
/** Ask the user whether to use Wi-Fi on every call */
static final int ASK_EVERY_TIME = 1;
/** Never use Wi-Fi calling */
static final int NEVER_USE = 2;
}
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = {"NETWORK_SELECTION_MODE_"},
value = {
NETWORK_SELECTION_MODE_UNKNOWN,
NETWORK_SELECTION_MODE_AUTO,
NETWORK_SELECTION_MODE_MANUAL})
public @interface NetworkSelectionMode {}
/** @hide */
public static final int NETWORK_SELECTION_MODE_UNKNOWN = 0;
/** @hide */
public static final int NETWORK_SELECTION_MODE_AUTO = 1;
/** @hide */
public static final int NETWORK_SELECTION_MODE_MANUAL = 2;
/** The otaspMode passed to PhoneStateListener#onOtaspChanged */
/** @hide */
static public final int OTASP_UNINITIALIZED = 0;
/** @hide */
static public final int OTASP_UNKNOWN = 1;
/** @hide */
static public final int OTASP_NEEDED = 2;
/** @hide */
static public final int OTASP_NOT_NEEDED = 3;
/* OtaUtil has conflict enum 4: OtaUtils.OTASP_FAILURE_SPC_RETRIES */
/** @hide */
static public final int OTASP_SIM_UNPROVISIONED = 5;
/** @hide */
static public final int KEY_TYPE_EPDG = 1;
/** @hide */
static public final int KEY_TYPE_WLAN = 2;
/**
* No Single Radio Voice Call Continuity (SRVCC) handover is active.
* See TS 23.216 for more information.
* @hide
*/
@SystemApi
public static final int SRVCC_STATE_HANDOVER_NONE = -1;
/**
* Single Radio Voice Call Continuity (SRVCC) handover has been started on the network.
* See TS 23.216 for more information.
* @hide
*/
@SystemApi
public static final int SRVCC_STATE_HANDOVER_STARTED = 0;
/**
* Ongoing Single Radio Voice Call Continuity (SRVCC) handover has successfully completed.
* See TS 23.216 for more information.
* @hide
*/
@SystemApi
public static final int SRVCC_STATE_HANDOVER_COMPLETED = 1;
/**
* Ongoing Single Radio Voice Call Continuity (SRVCC) handover has failed.
* See TS 23.216 for more information.
* @hide
*/
@SystemApi
public static final int SRVCC_STATE_HANDOVER_FAILED = 2;
/**
* Ongoing Single Radio Voice Call Continuity (SRVCC) handover has been canceled.
* See TS 23.216 for more information.
* @hide
*/
@SystemApi
public static final int SRVCC_STATE_HANDOVER_CANCELED = 3;
/**
* A UICC card identifier used if the device does not support the operation.
* For example, {@link #getCardIdForDefaultEuicc()} returns this value if the device has no
* eUICC, or the eUICC cannot be read.
*/
public static final int UNSUPPORTED_CARD_ID = -1;
/**
* A UICC card identifier used before the UICC card is loaded. See
* {@link #getCardIdForDefaultEuicc()} and {@link UiccCardInfo#getCardId()}.
* <p>
* Note that once the UICC card is loaded, the card ID may become {@link #UNSUPPORTED_CARD_ID}.
*/
public static final int UNINITIALIZED_CARD_ID = -2;
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = {"SRVCC_STATE_"},
value = {
SRVCC_STATE_HANDOVER_NONE,
SRVCC_STATE_HANDOVER_STARTED,
SRVCC_STATE_HANDOVER_COMPLETED,
SRVCC_STATE_HANDOVER_FAILED,
SRVCC_STATE_HANDOVER_CANCELED})
public @interface SrvccState {}
private final Context mContext;
private final int mSubId;
@UnsupportedAppUsage
private SubscriptionManager mSubscriptionManager;
private TelephonyScanManager mTelephonyScanManager;
private static String multiSimConfig =
SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG);
/** Enum indicating multisim variants
* DSDS - Dual SIM Dual Standby
* DSDA - Dual SIM Dual Active
* TSTS - Triple SIM Triple Standby
**/
/** @hide */
public enum MultiSimVariants {
@UnsupportedAppUsage
DSDS,
@UnsupportedAppUsage
DSDA,
@UnsupportedAppUsage
TSTS,
@UnsupportedAppUsage
UNKNOWN
};
/** @hide */
@UnsupportedAppUsage
public TelephonyManager(Context context) {
this(context, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID);
}
/** @hide */
@UnsupportedAppUsage
public TelephonyManager(Context context, int subId) {
mSubId = subId;
Context appContext = context.getApplicationContext();
if (appContext != null) {
mContext = appContext;
} else {
mContext = context;
}
mSubscriptionManager = SubscriptionManager.from(mContext);
}
/** @hide */
@UnsupportedAppUsage
private TelephonyManager() {
mContext = null;
mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
}
private static TelephonyManager sInstance = new TelephonyManager();
/** @hide
/* @deprecated - use getSystemService as described above */
@Deprecated
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public static TelephonyManager getDefault() {
return sInstance;
}
private String getOpPackageName() {
// For legacy reasons the TelephonyManager has API for getting
// a static instance with no context set preventing us from
// getting the op package name. As a workaround we do a best
// effort and get the context from the current activity thread.
if (mContext != null) {
return mContext.getOpPackageName();
}
return ActivityThread.currentOpPackageName();
}
private boolean isSystemProcess() {
return Process.myUid() == Process.SYSTEM_UID;
}
/**
* Returns the multi SIM variant
* Returns DSDS for Dual SIM Dual Standby
* Returns DSDA for Dual SIM Dual Active
* Returns TSTS for Triple SIM Triple Standby
* Returns UNKNOWN for others
*/
/** {@hide} */
@UnsupportedAppUsage
public MultiSimVariants getMultiSimConfiguration() {
String mSimConfig =
SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG);
if (mSimConfig.equals("dsds")) {
return MultiSimVariants.DSDS;
} else if (mSimConfig.equals("dsda")) {
return MultiSimVariants.DSDA;
} else if (mSimConfig.equals("tsts")) {
return MultiSimVariants.TSTS;
} else {
return MultiSimVariants.UNKNOWN;
}
}
/**
* Returns the number of phones available.
* Returns 0 if none of voice, sms, data is not supported
* Returns 1 for Single standby mode (Single SIM functionality)
* Returns 2 for Dual standby mode.(Dual SIM functionality)
* Returns 3 for Tri standby mode.(Tri SIM functionality)
*/
public int getPhoneCount() {
int phoneCount = 0;
// check for voice and data support, 0 if not supported
if (!isVoiceCapable() && !isSmsCapable()) {
ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(
Context.CONNECTIVITY_SERVICE);
if (cm != null) {
if (!cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)) {
return phoneCount;
}
}
}
phoneCount = 1;
try {
ITelephony telephony = getITelephony();
if (telephony != null) {
phoneCount = telephony.getNumOfActiveSims();
}
} catch (RemoteException ex) {
Rlog.e(TAG, "getNumOfActiveSims RemoteException", ex);
}
return phoneCount;
}
/** {@hide} */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public static TelephonyManager from(Context context) {
return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
}
/**
* Create a new TelephonyManager object pinned to the given subscription ID.
*
* @return a TelephonyManager that uses the given subId for all calls.
*/
public TelephonyManager createForSubscriptionId(int subId) {
// Don't reuse any TelephonyManager objects.
return new TelephonyManager(mContext, subId);
}
/**
* Create a new TelephonyManager object pinned to the subscription ID associated with the given
* phone account.
*
* @return a TelephonyManager that uses the given phone account for all calls, or {@code null}
* if the phone account does not correspond to a valid subscription ID.
*/
@Nullable
public TelephonyManager createForPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) {
int subId = getSubIdForPhoneAccountHandle(phoneAccountHandle);
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
return null;
}
return new TelephonyManager(mContext, subId);
}
/** {@hide} */
@UnsupportedAppUsage
public boolean isMultiSimEnabled() {
return (multiSimConfig.equals("dsds") || multiSimConfig.equals("dsda") ||
multiSimConfig.equals("tsts"));
}
//
// Broadcast Intent actions
//
/**
* Broadcast intent action indicating that the call state
* on the device has changed.
*
* <p>
* The {@link #EXTRA_STATE} extra indicates the new call state.
* If a receiving app has {@link android.Manifest.permission#READ_CALL_LOG} permission, a second
* extra {@link #EXTRA_INCOMING_NUMBER} provides the phone number for incoming and outgoing
* calls as a String.
* <p>
* If the receiving app has
* {@link android.Manifest.permission#READ_CALL_LOG} and
* {@link android.Manifest.permission#READ_PHONE_STATE} permission, it will receive the
* broadcast twice; one with the {@link #EXTRA_INCOMING_NUMBER} populated with the phone number,
* and another with it blank. Due to the nature of broadcasts, you cannot assume the order
* in which these broadcasts will arrive, however you are guaranteed to receive two in this
* case. Apps which are interested in the {@link #EXTRA_INCOMING_NUMBER} can ignore the
* broadcasts where {@link #EXTRA_INCOMING_NUMBER} is not present in the extras (e.g. where
* {@link Intent#hasExtra(String)} returns {@code false}).
* <p class="note">
* This was a {@link android.content.Context#sendStickyBroadcast sticky}
* broadcast in version 1.0, but it is no longer sticky.
* Instead, use {@link #getCallState} to synchronously query the current call state.
*
* @see #EXTRA_STATE
* @see #EXTRA_INCOMING_NUMBER
* @see #getCallState
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public static final String ACTION_PHONE_STATE_CHANGED =
"android.intent.action.PHONE_STATE";
/**
* The Phone app sends this intent when a user opts to respond-via-message during an incoming
* call. By default, the device's default SMS app consumes this message and sends a text message
* to the caller. A third party app can also provide this functionality by consuming this Intent
* with a {@link android.app.Service} and sending the message using its own messaging system.
* <p>The intent contains a URI (available from {@link android.content.Intent#getData})
* describing the recipient, using either the {@code sms:}, {@code smsto:}, {@code mms:},
* or {@code mmsto:} URI schema. Each of these URI schema carry the recipient information the
* same way: the path part of the URI contains the recipient's phone number or a comma-separated
* set of phone numbers if there are multiple recipients. For example, {@code
* smsto:2065551234}.</p>
*
* <p>The intent may also contain extras for the message text (in {@link
* android.content.Intent#EXTRA_TEXT}) and a message subject
* (in {@link android.content.Intent#EXTRA_SUBJECT}).</p>
*
* <p class="note"><strong>Note:</strong>
* The intent-filter that consumes this Intent needs to be in a {@link android.app.Service}
* that requires the
* permission {@link android.Manifest.permission#SEND_RESPOND_VIA_MESSAGE}.</p>
* <p>For example, the service that receives this intent can be declared in the manifest file
* with an intent filter like this:</p>
* <pre>
* &lt;!-- Service that delivers SMS messages received from the phone "quick response" -->
* &lt;service android:name=".HeadlessSmsSendService"
* android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
* android:exported="true" >
* &lt;intent-filter>
* &lt;action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
* &lt;category android:name="android.intent.category.DEFAULT" />
* &lt;data android:scheme="sms" />
* &lt;data android:scheme="smsto" />
* &lt;data android:scheme="mms" />
* &lt;data android:scheme="mmsto" />
* &lt;/intent-filter>
* &lt;/service></pre>
* <p>
* Output: nothing.
*/
@SdkConstant(SdkConstantType.SERVICE_ACTION)
public static final String ACTION_RESPOND_VIA_MESSAGE =
"android.intent.action.RESPOND_VIA_MESSAGE";
/**
* The emergency dialer may choose to present activities with intent filters for this
* action as emergency assistance buttons that launch the activity when clicked.
*
* @hide
*/
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
public static final String ACTION_EMERGENCY_ASSISTANCE =
"android.telephony.action.EMERGENCY_ASSISTANCE";
/**
* A boolean meta-data value indicating whether the voicemail settings should be hidden in the
* call settings page launched by
* {@link android.telecom.TelecomManager#ACTION_SHOW_CALL_SETTINGS}.
* Dialer implementations (see {@link android.telecom.TelecomManager#getDefaultDialerPackage()})
* which would also like to manage voicemail settings should set this meta-data to {@code true}
* in the manifest registration of their application.
*
* @see android.telecom.TelecomManager#ACTION_SHOW_CALL_SETTINGS
* @see #ACTION_CONFIGURE_VOICEMAIL
* @see #EXTRA_HIDE_PUBLIC_SETTINGS
*/
public static final String METADATA_HIDE_VOICEMAIL_SETTINGS_MENU =
"android.telephony.HIDE_VOICEMAIL_SETTINGS_MENU";
/**
* Open the voicemail settings activity to make changes to voicemail configuration.
*
* <p>
* The {@link #EXTRA_PHONE_ACCOUNT_HANDLE} extra indicates which {@link PhoneAccountHandle} to
* configure voicemail.
* The {@link #EXTRA_HIDE_PUBLIC_SETTINGS} hides settings the dialer will modify through public
* API if set.
*
* @see #EXTRA_PHONE_ACCOUNT_HANDLE
* @see #EXTRA_HIDE_PUBLIC_SETTINGS
*/
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
public static final String ACTION_CONFIGURE_VOICEMAIL =
"android.telephony.action.CONFIGURE_VOICEMAIL";
/**
* The boolean value indicating whether the voicemail settings activity launched by {@link
* #ACTION_CONFIGURE_VOICEMAIL} should hide settings accessible through public API. This is
* used by dialer implementations which provides their own voicemail settings UI, but still
* needs to expose device specific voicemail settings to the user.
*
* @see #ACTION_CONFIGURE_VOICEMAIL
* @see #METADATA_HIDE_VOICEMAIL_SETTINGS_MENU
*/
public static final String EXTRA_HIDE_PUBLIC_SETTINGS =
"android.telephony.extra.HIDE_PUBLIC_SETTINGS";
/**
* @hide
*/
public static final boolean EMERGENCY_ASSISTANCE_ENABLED = true;
/**
* The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast
* for a String containing the new call state.
*
* <p class="note">
* Retrieve with
* {@link android.content.Intent#getStringExtra(String)}.
*
* @see #EXTRA_STATE_IDLE
* @see #EXTRA_STATE_RINGING
* @see #EXTRA_STATE_OFFHOOK
*/
public static final String EXTRA_STATE = PhoneConstants.STATE_KEY;
/**
* Value used with {@link #EXTRA_STATE} corresponding to
* {@link #CALL_STATE_IDLE}.
*/
public static final String EXTRA_STATE_IDLE = PhoneConstants.State.IDLE.toString();
/**
* Value used with {@link #EXTRA_STATE} corresponding to
* {@link #CALL_STATE_RINGING}.
*/
public static final String EXTRA_STATE_RINGING = PhoneConstants.State.RINGING.toString();
/**
* Value used with {@link #EXTRA_STATE} corresponding to
* {@link #CALL_STATE_OFFHOOK}.
*/
public static final String EXTRA_STATE_OFFHOOK = PhoneConstants.State.OFFHOOK.toString();
/**
* Extra key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast
* for a String containing the incoming or outgoing phone number.
* <p>
* This extra is only populated for receivers of the {@link #ACTION_PHONE_STATE_CHANGED}
* broadcast which have been granted the {@link android.Manifest.permission#READ_CALL_LOG} and
* {@link android.Manifest.permission#READ_PHONE_STATE} permissions.
* <p>
* For incoming calls, the phone number is only guaranteed to be populated when the
* {@link #EXTRA_STATE} changes from {@link #EXTRA_STATE_IDLE} to {@link #EXTRA_STATE_RINGING}.
* If the incoming caller is from an unknown number, the extra will be populated with an empty
* string.
* For outgoing calls, the phone number is only guaranteed to be populated when the
* {@link #EXTRA_STATE} changes from {@link #EXTRA_STATE_IDLE} to {@link #EXTRA_STATE_OFFHOOK}.
* <p class="note">
* Retrieve with
* {@link android.content.Intent#getStringExtra(String)}.
*/
public static final String EXTRA_INCOMING_NUMBER = "incoming_number";
/**
* Broadcast intent action indicating that a precise call state
* (cellular) on the device has changed.
*
* <p>
* The {@link #EXTRA_RINGING_CALL_STATE} extra indicates the ringing call state.
* The {@link #EXTRA_FOREGROUND_CALL_STATE} extra indicates the foreground call state.
* The {@link #EXTRA_BACKGROUND_CALL_STATE} extra indicates the background call state.
*
* <p class="note">
* Requires the READ_PRECISE_PHONE_STATE permission.
*
* @see #EXTRA_RINGING_CALL_STATE
* @see #EXTRA_FOREGROUND_CALL_STATE
* @see #EXTRA_BACKGROUND_CALL_STATE
*
* <p class="note">
* Requires the READ_PRECISE_PHONE_STATE permission.
* @deprecated use {@link PhoneStateListener#LISTEN_PRECISE_CALL_STATE} instead
* @hide
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_PRECISE_CALL_STATE_CHANGED =
"android.intent.action.PRECISE_CALL_STATE";
/**
* Broadcast intent action indicating that call disconnect cause has changed.
*
* <p>
* The {@link #EXTRA_DISCONNECT_CAUSE} extra indicates the disconnect cause.
* The {@link #EXTRA_PRECISE_DISCONNECT_CAUSE} extra indicates the precise disconnect cause.
*
* <p class="note">
* Requires the READ_PRECISE_PHONE_STATE permission.
*
* @see #EXTRA_DISCONNECT_CAUSE
* @see #EXTRA_PRECISE_DISCONNECT_CAUSE
*
* @hide
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_CALL_DISCONNECT_CAUSE_CHANGED =
"android.intent.action.CALL_DISCONNECT_CAUSE";
/**
* The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast and
* {@link PhoneStateListener#onPreciseCallStateChanged(PreciseCallState)} for an integer
* containing the state of the current ringing call.
*
* @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID
* @see PreciseCallState#PRECISE_CALL_STATE_IDLE
* @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE
* @see PreciseCallState#PRECISE_CALL_STATE_HOLDING
* @see PreciseCallState#PRECISE_CALL_STATE_DIALING
* @see PreciseCallState#PRECISE_CALL_STATE_ALERTING
* @see PreciseCallState#PRECISE_CALL_STATE_INCOMING
* @see PreciseCallState#PRECISE_CALL_STATE_WAITING
* @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED
* @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING
*
* <p class="note">
* Retrieve with
* {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
*
* @hide
*/
public static final String EXTRA_RINGING_CALL_STATE = "ringing_state";
/**
* The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast and
* {@link PhoneStateListener#onPreciseCallStateChanged(PreciseCallState)} for an integer
* containing the state of the current foreground call.
*
* @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID
* @see PreciseCallState#PRECISE_CALL_STATE_IDLE
* @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE
* @see PreciseCallState#PRECISE_CALL_STATE_HOLDING
* @see PreciseCallState#PRECISE_CALL_STATE_DIALING
* @see PreciseCallState#PRECISE_CALL_STATE_ALERTING
* @see PreciseCallState#PRECISE_CALL_STATE_INCOMING
* @see PreciseCallState#PRECISE_CALL_STATE_WAITING
* @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED
* @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING
*
* <p class="note">
* Retrieve with
* {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
*
* @hide
*/
public static final String EXTRA_FOREGROUND_CALL_STATE = "foreground_state";
/**
* The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast and
* {@link PhoneStateListener#onPreciseCallStateChanged(PreciseCallState)} for an integer
* containing the state of the current background call.
*
* @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID
* @see PreciseCallState#PRECISE_CALL_STATE_IDLE
* @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE
* @see PreciseCallState#PRECISE_CALL_STATE_HOLDING
* @see PreciseCallState#PRECISE_CALL_STATE_DIALING
* @see PreciseCallState#PRECISE_CALL_STATE_ALERTING
* @see PreciseCallState#PRECISE_CALL_STATE_INCOMING
* @see PreciseCallState#PRECISE_CALL_STATE_WAITING
* @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED
* @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING
*
* <p class="note">
* Retrieve with
* {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
*
* @hide
*/
public static final String EXTRA_BACKGROUND_CALL_STATE = "background_state";
/**
* The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast and
* {@link PhoneStateListener#onPreciseCallStateChanged(PreciseCallState)} for an integer
* containing the disconnect cause.
*
* @see DisconnectCause
*
* <p class="note">
* Retrieve with
* {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
*
* @hide
*/
public static final String EXTRA_DISCONNECT_CAUSE = "disconnect_cause";
/**
* The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast and
* {@link PhoneStateListener#onPreciseCallStateChanged(PreciseCallState)} for an integer
* containing the disconnect cause provided by the RIL.
*
* @see PreciseDisconnectCause
*
* <p class="note">
* Retrieve with
* {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
*
* @hide
*/
public static final String EXTRA_PRECISE_DISCONNECT_CAUSE = "precise_disconnect_cause";
/**
* Broadcast intent action indicating a data connection has changed,
* providing precise information about the connection.
*
* <p>
* The {@link #EXTRA_DATA_STATE} extra indicates the connection state.
* The {@link #EXTRA_DATA_NETWORK_TYPE} extra indicates the connection network type.
* The {@link #EXTRA_DATA_APN_TYPE} extra indicates the APN type.
* The {@link #EXTRA_DATA_APN} extra indicates the APN.
* The {@link #EXTRA_DATA_IFACE_PROPERTIES} extra indicates the connection interface.
* The {@link #EXTRA_DATA_FAILURE_CAUSE} extra indicates the connection fail cause.
*
* <p class="note">
* Requires the READ_PRECISE_PHONE_STATE permission.
*
* @see #EXTRA_DATA_STATE
* @see #EXTRA_DATA_NETWORK_TYPE
* @see #EXTRA_DATA_APN_TYPE
* @see #EXTRA_DATA_APN
* @see #EXTRA_DATA_IFACE
* @see #EXTRA_DATA_FAILURE_CAUSE
* @hide
*
* @deprecated If the app is running in the background, it won't be able to receive this
* broadcast. Apps should use ConnectivityManager {@link #registerNetworkCallback(
* android.net.NetworkRequest, ConnectivityManager.NetworkCallback)} to listen for network
* changes.
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
@Deprecated
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
public static final String ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED =
"android.intent.action.PRECISE_DATA_CONNECTION_STATE_CHANGED";
/**
* The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
* for an integer containing the state of the current data connection.
*
* @see TelephonyManager#DATA_UNKNOWN
* @see TelephonyManager#DATA_DISCONNECTED
* @see TelephonyManager#DATA_CONNECTING
* @see TelephonyManager#DATA_CONNECTED
* @see TelephonyManager#DATA_SUSPENDED
*
* <p class="note">
* Retrieve with
* {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
*
* @hide
*/
public static final String EXTRA_DATA_STATE = PhoneConstants.STATE_KEY;
/**
* The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
* for an integer containing the network type.
*
* @see TelephonyManager#NETWORK_TYPE_UNKNOWN
* @see TelephonyManager#NETWORK_TYPE_GPRS
* @see TelephonyManager#NETWORK_TYPE_EDGE
* @see TelephonyManager#NETWORK_TYPE_UMTS
* @see TelephonyManager#NETWORK_TYPE_CDMA
* @see TelephonyManager#NETWORK_TYPE_EVDO_0
* @see TelephonyManager#NETWORK_TYPE_EVDO_A
* @see TelephonyManager#NETWORK_TYPE_1xRTT
* @see TelephonyManager#NETWORK_TYPE_HSDPA
* @see TelephonyManager#NETWORK_TYPE_HSUPA
* @see TelephonyManager#NETWORK_TYPE_HSPA
* @see TelephonyManager#NETWORK_TYPE_IDEN
* @see TelephonyManager#NETWORK_TYPE_EVDO_B
* @see TelephonyManager#NETWORK_TYPE_LTE
* @see TelephonyManager#NETWORK_TYPE_EHRPD
* @see TelephonyManager#NETWORK_TYPE_HSPAP
* @see TelephonyManager#NETWORK_TYPE_NR
*
* <p class="note">
* Retrieve with
* {@link android.content.Intent#getIntExtra(String name, int defaultValue)}.
*
* @hide
*/
public static final String EXTRA_DATA_NETWORK_TYPE = PhoneConstants.DATA_NETWORK_TYPE_KEY;
/**
* The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
* for an String containing the data APN type.
*
* <p class="note">
* Retrieve with
* {@link android.content.Intent#getStringExtra(String name)}.
*
* @hide
*/
public static final String EXTRA_DATA_APN_TYPE = PhoneConstants.DATA_APN_TYPE_KEY;
/**
* The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
* for an String containing the data APN.
*
* <p class="note">
* Retrieve with
* {@link android.content.Intent#getStringExtra(String name)}.
*
* @hide
*/
public static final String EXTRA_DATA_APN = PhoneConstants.DATA_APN_KEY;
/**
* The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
* for an String representation of the data interface.
*
* <p class="note">
* Retrieve with
* {@link android.content.Intent#getParcelableExtra(String name)}.
*
* @hide
*/
public static final String EXTRA_DATA_LINK_PROPERTIES_KEY = PhoneConstants.DATA_LINK_PROPERTIES_KEY;
/**
* The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast
* for the data connection fail cause.
*
* <p class="note">
* Retrieve with
* {@link android.content.Intent#getStringExtra(String name)}.
*
* @hide
*/
public static final String EXTRA_DATA_FAILURE_CAUSE = PhoneConstants.DATA_FAILURE_CAUSE_KEY;
/**
* Broadcast intent action for letting the default dialer to know to show voicemail
* notification.
*
* <p>
* The {@link #EXTRA_PHONE_ACCOUNT_HANDLE} extra indicates which {@link PhoneAccountHandle} the
* voicemail is received on.
* The {@link #EXTRA_NOTIFICATION_COUNT} extra indicates the total numbers of unheard
* voicemails.
* The {@link #EXTRA_VOICEMAIL_NUMBER} extra indicates the voicemail number if available.
* The {@link #EXTRA_CALL_VOICEMAIL_INTENT} extra is a {@link android.app.PendingIntent} that
* will call the voicemail number when sent. This extra will be empty if the voicemail number
* is not set, and {@link #EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT} will be set instead.
* The {@link #EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT} extra is a
* {@link android.app.PendingIntent} that will launch the voicemail settings. This extra is only
* available when the voicemail number is not set.
* The {@link #EXTRA_IS_REFRESH} extra indicates whether the notification is a refresh or a new
* notification.
*
* @see #EXTRA_PHONE_ACCOUNT_HANDLE
* @see #EXTRA_NOTIFICATION_COUNT
* @see #EXTRA_VOICEMAIL_NUMBER
* @see #EXTRA_CALL_VOICEMAIL_INTENT
* @see #EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT
* @see #EXTRA_IS_REFRESH
*/
public static final String ACTION_SHOW_VOICEMAIL_NOTIFICATION =
"android.telephony.action.SHOW_VOICEMAIL_NOTIFICATION";
/**
* The extra used with an {@link #ACTION_CONFIGURE_VOICEMAIL} and
* {@link #ACTION_SHOW_VOICEMAIL_NOTIFICATION} {@code Intent} to specify the
* {@link PhoneAccountHandle} the configuration or notification is for.
* <p class="note">
* Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
*/
public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
"android.telephony.extra.PHONE_ACCOUNT_HANDLE";
/**
* The number of voice messages associated with the notification.
*/
public static final String EXTRA_NOTIFICATION_COUNT =
"android.telephony.extra.NOTIFICATION_COUNT";
/**
* The voicemail number.
*/
public static final String EXTRA_VOICEMAIL_NUMBER =
"android.telephony.extra.VOICEMAIL_NUMBER";
/**
* The intent to call voicemail.
*/
public static final String EXTRA_CALL_VOICEMAIL_INTENT =
"android.telephony.extra.CALL_VOICEMAIL_INTENT";
/**
* The intent to launch voicemail settings.
*/
public static final String EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT =
"android.telephony.extra.LAUNCH_VOICEMAIL_SETTINGS_INTENT";
/**
* Boolean value representing whether the {@link
* TelephonyManager#ACTION_SHOW_VOICEMAIL_NOTIFICATION} is new or a refresh of an existing
* notification. Notification refresh happens after reboot or connectivity changes. The user has
* already been notified for the voicemail so it should not alert the user, and should not be
* shown again if the user has dismissed it.
*/
public static final String EXTRA_IS_REFRESH = "android.telephony.extra.IS_REFRESH";
/**
* {@link android.telecom.Connection} event used to indicate that an IMS call has be
* successfully handed over from WIFI to LTE.
* <p>
* Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}.
* The {@link Bundle} parameter is expected to be null when this connection event is used.
* @hide
*/
public static final String EVENT_HANDOVER_VIDEO_FROM_WIFI_TO_LTE =
"android.telephony.event.EVENT_HANDOVER_VIDEO_FROM_WIFI_TO_LTE";
/**
* {@link android.telecom.Connection} event used to indicate that an IMS call has be
* successfully handed over from LTE to WIFI.
* <p>
* Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}.
* The {@link Bundle} parameter is expected to be null when this connection event is used.
* @hide
*/
public static final String EVENT_HANDOVER_VIDEO_FROM_LTE_TO_WIFI =
"android.telephony.event.EVENT_HANDOVER_VIDEO_FROM_LTE_TO_WIFI";
/**
* {@link android.telecom.Connection} event used to indicate that an IMS call failed to be
* handed over from LTE to WIFI.
* <p>
* Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}.
* The {@link Bundle} parameter is expected to be null when this connection event is used.
* @hide
*/
public static final String EVENT_HANDOVER_TO_WIFI_FAILED =
"android.telephony.event.EVENT_HANDOVER_TO_WIFI_FAILED";
/**
* {@link android.telecom.Connection} event used to indicate that a video call was downgraded to
* audio because the data limit was reached.
* <p>
* Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}.
* The {@link Bundle} parameter is expected to be null when this connection event is used.
* @hide
*/
public static final String EVENT_DOWNGRADE_DATA_LIMIT_REACHED =
"android.telephony.event.EVENT_DOWNGRADE_DATA_LIMIT_REACHED";
/**
* {@link android.telecom.Connection} event used to indicate that a video call was downgraded to
* audio because the data was disabled.
* <p>
* Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}.
* The {@link Bundle} parameter is expected to be null when this connection event is used.
* @hide
*/
public static final String EVENT_DOWNGRADE_DATA_DISABLED =
"android.telephony.event.EVENT_DOWNGRADE_DATA_DISABLED";
/**
* {@link android.telecom.Connection} event used to indicate that the InCall UI should notify
* the user when an international call is placed while on WFC only.
* <p>
* Used when the carrier config value
* {@link CarrierConfigManager#KEY_NOTIFY_INTERNATIONAL_CALL_ON_WFC_BOOL} is true, the device
* is on WFC (VoLTE not available) and an international number is dialed.
* <p>
* Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}.
* The {@link Bundle} parameter is expected to be null when this connection event is used.
* @hide
*/
public static final String EVENT_NOTIFY_INTERNATIONAL_CALL_ON_WFC =
"android.telephony.event.EVENT_NOTIFY_INTERNATIONAL_CALL_ON_WFC";
/**
* {@link android.telecom.Connection} event used to indicate that an outgoing call has been
* forwarded to another number.
* <p>
* Sent in response to an IMS supplementary service notification indicating the call has been
* forwarded.
* <p>
* Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}.
* The {@link Bundle} parameter is expected to be null when this connection event is used.
* @hide
*/
public static final String EVENT_CALL_FORWARDED =
"android.telephony.event.EVENT_CALL_FORWARDED";
/**
* {@link android.telecom.Connection} event used to indicate that a supplementary service
* notification has been received.
* <p>
* Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}.
* The {@link Bundle} parameter is expected to include the following extras:
* <ul>
* <li>{@link #EXTRA_NOTIFICATION_TYPE} - the notification type.</li>
* <li>{@link #EXTRA_NOTIFICATION_CODE} - the notification code.</li>
* <li>{@link #EXTRA_NOTIFICATION_MESSAGE} - human-readable message associated with the
* supplementary service notification.</li>
* </ul>
* @hide
*/
public static final String EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION =
"android.telephony.event.EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION";
/**
* Integer extra key used with {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} which indicates
* the type of supplementary service notification which occurred.
* Will be either
* {@link com.android.internal.telephony.gsm.SuppServiceNotification#NOTIFICATION_TYPE_CODE_1}
* or
* {@link com.android.internal.telephony.gsm.SuppServiceNotification#NOTIFICATION_TYPE_CODE_2}
* <p>
* Set in the extras for the {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} connection event.
* @hide
*/
public static final String EXTRA_NOTIFICATION_TYPE =
"android.telephony.extra.NOTIFICATION_TYPE";
/**
* Integer extra key used with {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} which indicates
* the supplementary service notification which occurred.
* <p>
* Depending on the {@link #EXTRA_NOTIFICATION_TYPE}, the code will be one of the {@code CODE_*}
* codes defined in {@link com.android.internal.telephony.gsm.SuppServiceNotification}.
* <p>
* Set in the extras for the {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} connection event.
* @hide
*/
public static final String EXTRA_NOTIFICATION_CODE =
"android.telephony.extra.NOTIFICATION_CODE";
/**
* {@link CharSequence} extra key used with {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION}
* which contains a human-readable message which can be displayed to the user for the
* supplementary service notification.
* <p>
* Set in the extras for the {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} connection event.
* @hide
*/
public static final String EXTRA_NOTIFICATION_MESSAGE =
"android.telephony.extra.NOTIFICATION_MESSAGE";
/* Visual voicemail protocols */
/**
* The OMTP protocol.
*/
public static final String VVM_TYPE_OMTP = "vvm_type_omtp";
/**
* A flavor of OMTP protocol with a different mobile originated (MO) format
*/
public static final String VVM_TYPE_CVVM = "vvm_type_cvvm";
/**
* Key in bundle returned by {@link #getVisualVoicemailPackageName()}, indicating whether visual
* voicemail was enabled or disabled by the user. If the user never explicitly changed this
* setting, this key will not exist.
*
* @see #getVisualVoicemailSettings()
* @hide
*/
@SystemApi
public static final String EXTRA_VISUAL_VOICEMAIL_ENABLED_BY_USER_BOOL =
"android.telephony.extra.VISUAL_VOICEMAIL_ENABLED_BY_USER_BOOL";
/**
* Key in bundle returned by {@link #getVisualVoicemailPackageName()}, indicating the voicemail
* access PIN scrambled during the auto provisioning process. The user is expected to reset
* their PIN if this value is not {@code null}.
*
* @see #getVisualVoicemailSettings()
* @hide
*/
@SystemApi
public static final String EXTRA_VOICEMAIL_SCRAMBLED_PIN_STRING =
"android.telephony.extra.VOICEMAIL_SCRAMBLED_PIN_STRING";
/**
* @hide
*/
public static final String USSD_RESPONSE = "USSD_RESPONSE";
/**
* USSD return code success.
* @hide
*/
public static final int USSD_RETURN_SUCCESS = 100;
/**
* Failed code returned when the mobile network has failed to complete a USSD request.
* <p>
* Returned via {@link TelephonyManager.UssdResponseCallback#onReceiveUssdResponseFailed(
* TelephonyManager, String, int)}.
*/
public static final int USSD_RETURN_FAILURE = -1;
/**
* Failure code returned when a USSD request has failed to execute because the Telephony
* service is unavailable.
* <p>
* Returned via {@link TelephonyManager.UssdResponseCallback#onReceiveUssdResponseFailed(
* TelephonyManager, String, int)}.
*/
public static final int USSD_ERROR_SERVICE_UNAVAIL = -2;
/**
* Value for {@link CarrierConfigManager#KEY_CDMA_ROAMING_MODE_INT} which leaves the roaming
* mode set to the radio default or to the user's preference if they've indicated one.
*/
public static final int CDMA_ROAMING_MODE_RADIO_DEFAULT = -1;
/**
* Value for {@link CarrierConfigManager#KEY_CDMA_ROAMING_MODE_INT} which only permits
* connections on home networks.
*/
public static final int CDMA_ROAMING_MODE_HOME = 0;
/**
* Value for {@link CarrierConfigManager#KEY_CDMA_ROAMING_MODE_INT} which permits roaming on
* affiliated networks.
*/
public static final int CDMA_ROAMING_MODE_AFFILIATED = 1;
/**
* Value for {@link CarrierConfigManager#KEY_CDMA_ROAMING_MODE_INT} which permits roaming on
* any network.
*/
public static final int CDMA_ROAMING_MODE_ANY = 2;
/**
* An unknown carrier id. It could either be subscription unavailable or the subscription
* carrier cannot be recognized. Unrecognized carriers here means
* {@link #getSimOperator() MCC+MNC} cannot be identified.
*/
public static final int UNKNOWN_CARRIER_ID = -1;
/**
* An unknown carrier id list version.
* @hide
*/
@TestApi
public static final int UNKNOWN_CARRIER_ID_LIST_VERSION = -1;
/**
* Broadcast Action: The subscription carrier identity has changed.
* This intent could be sent on the following events:
* <ul>
* <li>Subscription absent. Carrier identity could change from a valid id to
* {@link TelephonyManager#UNKNOWN_CARRIER_ID}.</li>
* <li>Subscription loaded. Carrier identity could change from
* {@link TelephonyManager#UNKNOWN_CARRIER_ID} to a valid id.</li>
* <li>The subscription carrier is recognized after a remote update.</li>
* </ul>
* The intent will have the following extra values:
* <ul>
* <li>{@link #EXTRA_CARRIER_ID} The up-to-date carrier id of the current subscription id.
* </li>
* <li>{@link #EXTRA_CARRIER_NAME} The up-to-date carrier name of the current subscription.
* </li>
* <li>{@link #EXTRA_SUBSCRIPTION_ID} The subscription id associated with the changed carrier
* identity.
* </li>
* </ul>
* <p class="note">This is a protected intent that can only be sent by the system.
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED =
"android.telephony.action.SUBSCRIPTION_CARRIER_IDENTITY_CHANGED";
/**
* An int extra used with {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} which indicates
* the updated carrier id returned by {@link TelephonyManager#getSimCarrierId()}.
* <p>Will be {@link TelephonyManager#UNKNOWN_CARRIER_ID} if the subscription is unavailable or
* the carrier cannot be identified.
*/
public static final String EXTRA_CARRIER_ID = "android.telephony.extra.CARRIER_ID";
/**
* An string extra used with {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} which
* indicates the updated carrier name of the current subscription.
* @see TelephonyManager#getSimCarrierIdName()
* <p>Carrier name is a user-facing name of the carrier id {@link #EXTRA_CARRIER_ID},
* usually the brand name of the subsidiary (e.g. T-Mobile).
*/
public static final String EXTRA_CARRIER_NAME = "android.telephony.extra.CARRIER_NAME";
/**
* Broadcast Action: The subscription precise carrier identity has changed.
* The precise carrier id can be used to further differentiate a carrier by different
* networks, by prepaid v.s.postpaid or even by 4G v.s.3G plan. Each carrier has a unique
* carrier id returned by {@link #getSimCarrierId()} but could have multiple precise carrier id.
* e.g, {@link #getSimCarrierId()} will always return Tracfone (id 2022) for a Tracfone SIM,
* while {@link #getSimPreciseCarrierId()} can return Tracfone AT&T or Tracfone T-Mobile based
* on the current subscription IMSI. For carriers without any fine-grained ids, precise carrier
* id is same as carrier id.
*
* <p>Similar like {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED}, this intent will be
* sent on the event of {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} while its also
* possible to be sent without {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} when
* precise carrier id changes with the same carrier id.
* e.g, the same subscription switches to different IMSI could potentially change its
* precise carrier id while carrier id remains the same.
* @see #getSimPreciseCarrierId()
* @see #getSimCarrierId()
*
* The intent will have the following extra values:
* <ul>
* <li>{@link #EXTRA_PRECISE_CARRIER_ID} The up-to-date precise carrier id of the
* current subscription.
* </li>
* <li>{@link #EXTRA_PRECISE_CARRIER_NAME} The up-to-date name of the precise carrier id.
* </li>
* <li>{@link #EXTRA_SUBSCRIPTION_ID} The subscription id associated with the changed carrier
* identity.
* </li>
* </ul>
* <p class="note">This is a protected intent that can only be sent by the system.
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_SUBSCRIPTION_PRECISE_CARRIER_IDENTITY_CHANGED =
"android.telephony.action.SUBSCRIPTION_PRECISE_CARRIER_IDENTITY_CHANGED";
/**
* An int extra used with {@link #ACTION_SUBSCRIPTION_PRECISE_CARRIER_IDENTITY_CHANGED} which
* indicates the updated precise carrier id returned by
* {@link TelephonyManager#getSimPreciseCarrierId()}. Note, its possible precise carrier id
* changes while {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} remains the same
* e.g, when subscription switch to different IMSIs.
* <p>Will be {@link TelephonyManager#UNKNOWN_CARRIER_ID} if the subscription is unavailable or
* the carrier cannot be identified.
*/
public static final String EXTRA_PRECISE_CARRIER_ID =
"android.telephony.extra.PRECISE_CARRIER_ID";
/**
* An string extra used with {@link #ACTION_SUBSCRIPTION_PRECISE_CARRIER_IDENTITY_CHANGED} which
* indicates the updated precise carrier name returned by
* {@link TelephonyManager#getSimPreciseCarrierIdName()}.
* <p>it's a user-facing name of the precise carrier id {@link #EXTRA_PRECISE_CARRIER_ID}, e.g,
* Tracfone-AT&T.
*/
public static final String EXTRA_PRECISE_CARRIER_NAME =
"android.telephony.extra.PRECISE_CARRIER_NAME";
/**
* An int extra used with {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} to indicate the
* subscription which has changed.
*/
public static final String EXTRA_SUBSCRIPTION_ID = "android.telephony.extra.SUBSCRIPTION_ID";
/**
* Broadcast intent action indicating that when data stall recovery is attempted by Telephony,
* intended for report every data stall recovery step attempted.
*
* <p>
* The {@link #EXTRA_RECOVERY_ACTION} extra indicates the action associated with the data
* stall recovery.
* The phone id where the data stall recovery is attempted.
*
* <p class="note">
* Requires the READ_PHONE_STATE permission.
*
* <p class="note">
* This is a protected intent that can only be sent by the system.
*
* @see #EXTRA_RECOVERY_ACTION
*
* @hide
*/
// TODO(b/78370030) : Restrict this to system applications only
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public static final String ACTION_DATA_STALL_DETECTED =
"android.intent.action.DATA_STALL_DETECTED";
/**
* An int extra used with {@link #ACTION_DATA_STALL_DETECTED} to indicate the
* action associated with the data stall recovery.
*
* @see #ACTION_DATA_STALL_DETECTED
*
* @hide
*/
public static final String EXTRA_RECOVERY_ACTION = "recoveryAction";
/**
* The max value for the timeout passed in {@link #requestNumberVerification}.
* @hide
*/
@SystemApi
public static final long MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS = 60000;
/**
* Intent sent when an error occurs that debug tools should log and possibly take further
* action such as capturing vendor-specific logs.
*
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
public static final String ACTION_DEBUG_EVENT = "android.telephony.action.DEBUG_EVENT";
/**
* An arbitrary ParcelUuid which should be consistent for each occurrence of the same event.
*
* This field must be included in all events.
*
* @hide
*/
@SystemApi
public static final String EXTRA_DEBUG_EVENT_ID = "android.telephony.extra.DEBUG_EVENT_ID";
/**
* A freeform string description of the event.
*
* This field is optional for all events and as a guideline should not exceed 80 characters
* and should be as short as possible to convey the essence of the event.
*
* @hide
*/
@SystemApi
public static final String EXTRA_DEBUG_EVENT_DESCRIPTION =
"android.telephony.extra.DEBUG_EVENT_DESCRIPTION";
//
//
// Device Info
//
//
/**
* Returns the software version number for the device, for example,
* the IMEI/SV for GSM phones. Return null if the software version is
* not available.
*
* <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
* or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}).
*/
@SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public String getDeviceSoftwareVersion() {
return getDeviceSoftwareVersion(getSlotIndex());
}
/**
* Returns the software version number for the device, for example,
* the IMEI/SV for GSM phones. Return null if the software version is
* not available.
*
* @param slotIndex of which deviceID is returned
*/
/** {@hide} */
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
@UnsupportedAppUsage
public String getDeviceSoftwareVersion(int slotIndex) {
ITelephony telephony = getITelephony();
if (telephony == null) return null;
try {
return telephony.getDeviceSoftwareVersionForSlot(slotIndex, getOpPackageName());
} catch (RemoteException ex) {
return null;
} catch (NullPointerException ex) {
return null;
}
}
/**
* Returns the unique device ID, for example, the IMEI for GSM and the MEID
* or ESN for CDMA phones. Return null if device ID is not available.
*
* <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
* or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}).
*
* @deprecated Use (@link getImei} which returns IMEI for GSM or (@link getMeid} which returns
* MEID for CDMA.
*/
@Deprecated
@SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public String getDeviceId() {
try {
ITelephony telephony = getITelephony();
if (telephony == null)
return null;
return telephony.getDeviceId(mContext.getOpPackageName());
} catch (RemoteException ex) {
return null;
} catch (NullPointerException ex) {
return null;
}
}
/**
* Returns the unique device ID of a subscription, for example, the IMEI for
* GSM and the MEID for CDMA phones. Return null if device ID is not available.
*
* <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
* or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}).
*
* @param slotIndex of which deviceID is returned
*
* @deprecated Use (@link getImei} which returns IMEI for GSM or (@link getMeid} which returns
* MEID for CDMA.
*/
@Deprecated
@SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public String getDeviceId(int slotIndex) {
// FIXME this assumes phoneId == slotIndex
try {
IPhoneSubInfo info = getSubscriberInfo();
if (info == null)
return null;
return info.getDeviceIdForPhone(slotIndex, mContext.getOpPackageName());
} catch (RemoteException ex) {
return null;
} catch (NullPointerException ex) {
return null;
}
}
/**
* Returns the IMEI (International Mobile Equipment Identity). Return null if IMEI is not
* available.
*
* <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
* or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}).
*/
@SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public String getImei() {
return getImei(getSlotIndex());
}
/**
* Returns the IMEI (International Mobile Equipment Identity). Return null if IMEI is not
* available.
*
* <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
* or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}).
*
* @param slotIndex of which IMEI is returned
*/
@SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public String getImei(int slotIndex) {
ITelephony telephony = getITelephony();
if (telephony == null) return null;
try {
return telephony.getImeiForSlot(slotIndex, getOpPackageName());
} catch (RemoteException ex) {
return null;
} catch (NullPointerException ex) {
return null;
}
}
/**
* Returns the Type Allocation Code from the IMEI. Return null if Type Allocation Code is not
* available.
*/
public String getTypeAllocationCode() {
return getTypeAllocationCode(getSlotIndex());
}
/**
* Returns the Type Allocation Code from the IMEI. Return null if Type Allocation Code is not
* available.
*
* @param slotIndex of which Type Allocation Code is returned
*/
public String getTypeAllocationCode(int slotIndex) {
ITelephony telephony = getITelephony();
if (telephony == null) return null;
try {
return telephony.getTypeAllocationCodeForSlot(slotIndex);
} catch (RemoteException ex) {
return null;
} catch (NullPointerException ex) {
return null;
}
}
/**
* Returns the MEID (Mobile Equipment Identifier). Return null if MEID is not available.
*
* <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
* or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}).
*/
@SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public String getMeid() {
return getMeid(getSlotIndex());
}
/**
* Returns the MEID (Mobile Equipment Identifier). Return null if MEID is not available.
*
* <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
* or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}).
*
* @param slotIndex of which MEID is returned
*/
@SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public String getMeid(int slotIndex) {
ITelephony telephony = getITelephony();
if (telephony == null) return null;
try {
return telephony.getMeidForSlot(slotIndex, getOpPackageName());
} catch (RemoteException ex) {
return null;
} catch (NullPointerException ex) {
return null;
}
}
/**
* Returns the Manufacturer Code from the MEID. Return null if Manufacturer Code is not
* available.
*/
public String getManufacturerCode() {
return getManufacturerCode(getSlotIndex());
}
/**
* Returns the Manufacturer Code from the MEID. Return null if Manufacturer Code is not
* available.
*
* @param slotIndex of which Type Allocation Code is returned
*/
public String getManufacturerCode(int slotIndex) {
ITelephony telephony = getITelephony();
if (telephony == null) return null;
try {
return telephony.getManufacturerCodeForSlot(slotIndex);
} catch (RemoteException ex) {
return null;
} catch (NullPointerException ex) {
return null;
}
}
/**
* Returns the Network Access Identifier (NAI). Return null if NAI is not available.
*
* <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
* or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}).
*/
@SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public String getNai() {
return getNaiBySubscriberId(getSubId());
}
/**
* Returns the NAI. Return null if NAI is not available.
*
* @param slotIndex of which Nai is returned
*/
/** {@hide}*/
@UnsupportedAppUsage
public String getNai(int slotIndex) {
int[] subId = SubscriptionManager.getSubId(slotIndex);
if (subId == null) {
return null;
}
return getNaiBySubscriberId(subId[0]);
}
private String getNaiBySubscriberId(int subId) {
try {
IPhoneSubInfo info = getSubscriberInfo();
if (info == null)
return null;
String nai = info.getNaiForSubscriber(subId, mContext.getOpPackageName());
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Rlog.v(TAG, "Nai = " + nai);
}
return nai;
} catch (RemoteException ex) {
return null;
} catch (NullPointerException ex) {
return null;
}
}
/**
* Returns the current location of the device.
*<p>
* If there is only one radio in the device and that radio has an LTE connection,
* this method will return null. The implementation must not to try add LTE
* identifiers into the existing cdma/gsm classes.
*<p>
* @return Current location of the device or null if not available.
*
* @deprecated use {@link #getAllCellInfo} instead, which returns a superset of this API.
*/
@Deprecated
@RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION)
public CellLocation getCellLocation() {
try {
ITelephony telephony = getITelephony();
if (telephony == null) {
Rlog.d(TAG, "getCellLocation returning null because telephony is null");
return null;
}
Bundle bundle = telephony.getCellLocation(mContext.getOpPackageName());
if (bundle == null || bundle.isEmpty()) {
Rlog.d(TAG, "getCellLocation returning null because CellLocation is unavailable");
return null;
}
CellLocation cl = CellLocation.newFromBundle(bundle);
if (cl == null || cl.isEmpty()) {
Rlog.d(TAG, "getCellLocation returning null because CellLocation is empty or"
+ " phone type doesn't match CellLocation type");
return null;
}
return cl;
} catch (RemoteException ex) {
Rlog.d(TAG, "getCellLocation returning null due to RemoteException " + ex);
return null;
}
}
/**
* Enables location update notifications. {@link PhoneStateListener#onCellLocationChanged
* PhoneStateListener.onCellLocationChanged} will be called on location updates.
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.CONTROL_LOCATION_UPDATES)
public void enableLocationUpdates() {
enableLocationUpdates(getSubId());
}
/**
* Enables location update notifications for a subscription.
* {@link PhoneStateListener#onCellLocationChanged
* PhoneStateListener.onCellLocationChanged} will be called on location updates.
*
* @param subId for which the location updates are enabled
* @hide
*/
@RequiresPermission(android.Manifest.permission.CONTROL_LOCATION_UPDATES)
public void enableLocationUpdates(int subId) {
try {
ITelephony telephony = getITelephony();
if (telephony != null)
telephony.enableLocationUpdatesForSubscriber(subId);
} catch (RemoteException ex) {
} catch (NullPointerException ex) {
}
}
/**
* Disables location update notifications. {@link PhoneStateListener#onCellLocationChanged
* PhoneStateListener.onCellLocationChanged} will be called on location updates.
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.CONTROL_LOCATION_UPDATES)
public void disableLocationUpdates() {
disableLocationUpdates(getSubId());
}
/** @hide */
public void disableLocationUpdates(int subId) {
try {
ITelephony telephony = getITelephony();
if (telephony != null)
telephony.disableLocationUpdatesForSubscriber(subId);
} catch (RemoteException ex) {
} catch (NullPointerException ex) {
}
}
/**
* Returns the neighboring cell information of the device.
*
* @return List of NeighboringCellInfo or null if info unavailable.
*
* @removed
* @deprecated Use {@link #getAllCellInfo} which returns a superset of the information
* from NeighboringCellInfo, including LTE cell information.
*/
@Deprecated
@RequiresPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION)
public List<NeighboringCellInfo> getNeighboringCellInfo() {
try {
ITelephony telephony = getITelephony();
if (telephony == null)
return null;
return telephony.getNeighboringCellInfo(mContext.getOpPackageName());
} catch (RemoteException ex) {
return null;
} catch (NullPointerException ex) {
return null;
}
}
/** No phone radio. */
public static final int PHONE_TYPE_NONE = PhoneConstants.PHONE_TYPE_NONE;
/** Phone radio is GSM. */
public static final int PHONE_TYPE_GSM = PhoneConstants.PHONE_TYPE_GSM;
/** Phone radio is CDMA. */
public static final int PHONE_TYPE_CDMA = PhoneConstants.PHONE_TYPE_CDMA;
/** Phone is via SIP. */
public static final int PHONE_TYPE_SIP = PhoneConstants.PHONE_TYPE_SIP;
/**
* Returns the current phone type.
* TODO: This is a last minute change and hence hidden.
*
* @see #PHONE_TYPE_NONE
* @see #PHONE_TYPE_GSM
* @see #PHONE_TYPE_CDMA
* @see #PHONE_TYPE_SIP
*
* {@hide}
*/
@SystemApi
public int getCurrentPhoneType() {
return getCurrentPhoneType(getSubId());
}
/**
* Returns a constant indicating the device phone type for a subscription.
*
* @see #PHONE_TYPE_NONE
* @see #PHONE_TYPE_GSM
* @see #PHONE_TYPE_CDMA
*
* @param subId for which phone type is returned
* @hide
*/
@SystemApi
public int getCurrentPhoneType(int subId) {
int phoneId;
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
// if we don't have any sims, we don't have subscriptions, but we
// still may want to know what type of phone we've got.
phoneId = 0;
} else {
phoneId = SubscriptionManager.getPhoneId(subId);
}
return getCurrentPhoneTypeForSlot(phoneId);
}
/**
* See getCurrentPhoneType.
*
* @hide
*/
public int getCurrentPhoneTypeForSlot(int slotIndex) {
try{
ITelephony telephony = getITelephony();
if (telephony != null) {
return telephony.getActivePhoneTypeForSlot(slotIndex);
} else {
// This can happen when the ITelephony interface is not up yet.
return getPhoneTypeFromProperty(slotIndex);
}
} catch (RemoteException ex) {
// This shouldn't happen in the normal case, as a backup we
// read from the system property.
return getPhoneTypeFromProperty(slotIndex);
} catch (NullPointerException ex) {
// This shouldn't happen in the normal case, as a backup we
// read from the system property.
return getPhoneTypeFromProperty(slotIndex);
}
}
/**
* Returns a constant indicating the device phone type. This
* indicates the type of radio used to transmit voice calls.
*
* @see #PHONE_TYPE_NONE
* @see #PHONE_TYPE_GSM
* @see #PHONE_TYPE_CDMA
* @see #PHONE_TYPE_SIP
*/
public int getPhoneType() {
if (!isVoiceCapable()) {
return PHONE_TYPE_NONE;
}
return getCurrentPhoneType();
}
private int getPhoneTypeFromProperty() {
return getPhoneTypeFromProperty(getPhoneId());
}
/** {@hide} */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
private int getPhoneTypeFromProperty(int phoneId) {
String type = getTelephonyProperty(phoneId,
TelephonyProperties.CURRENT_ACTIVE_PHONE, null);
if (type == null || type.isEmpty()) {
return getPhoneTypeFromNetworkType(phoneId);
}
return Integer.parseInt(type);
}
private int getPhoneTypeFromNetworkType() {
return getPhoneTypeFromNetworkType(getPhoneId());
}
/** {@hide} */
private int getPhoneTypeFromNetworkType(int phoneId) {
// When the system property CURRENT_ACTIVE_PHONE, has not been set,
// use the system property for default network type.
// This is a fail safe, and can only happen at first boot.
String mode = getTelephonyProperty(phoneId, "ro.telephony.default_network", null);
if (mode != null && !mode.isEmpty()) {
return TelephonyManager.getPhoneType(Integer.parseInt(mode));
}
return TelephonyManager.PHONE_TYPE_NONE;
}
/**
* This function returns the type of the phone, depending
* on the network mode.
*
* @param networkMode
* @return Phone Type
*
* @hide
*/
@UnsupportedAppUsage
public static int getPhoneType(int networkMode) {
switch(networkMode) {
case RILConstants.NETWORK_MODE_CDMA:
case RILConstants.NETWORK_MODE_CDMA_NO_EVDO:
case RILConstants.NETWORK_MODE_EVDO_NO_CDMA:
return PhoneConstants.PHONE_TYPE_CDMA;
case RILConstants.NETWORK_MODE_WCDMA_PREF:
case RILConstants.NETWORK_MODE_GSM_ONLY:
case RILConstants.NETWORK_MODE_WCDMA_ONLY:
case RILConstants.NETWORK_MODE_GSM_UMTS:
case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA:
case RILConstants.NETWORK_MODE_LTE_WCDMA:
case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
case RILConstants.NETWORK_MODE_TDSCDMA_ONLY:
case RILConstants.NETWORK_MODE_TDSCDMA_WCDMA:
case RILConstants.NETWORK_MODE_LTE_TDSCDMA:
case RILConstants.NETWORK_MODE_TDSCDMA_GSM:
case RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM:
case RILConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA:
case RILConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA:
case RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA:
case RILConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
return PhoneConstants.PHONE_TYPE_GSM;
// Use CDMA Phone for the global mode including CDMA
case RILConstants.NETWORK_MODE_GLOBAL:
case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO:
case RILConstants.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
return PhoneConstants.PHONE_TYPE_CDMA;
case RILConstants.NETWORK_MODE_LTE_ONLY:
if (getLteOnCdmaModeStatic() == PhoneConstants.LTE_ON_CDMA_TRUE) {
return PhoneConstants.PHONE_TYPE_CDMA;
} else {
return PhoneConstants.PHONE_TYPE_GSM;
}
default:
return PhoneConstants.PHONE_TYPE_GSM;
}
}
/**
* The contents of the /proc/cmdline file
*/
@UnsupportedAppUsage
private static String getProcCmdLine()
{
String cmdline = "";
FileInputStream is = null;
try {
is = new FileInputStream("/proc/cmdline");
byte [] buffer = new byte[2048];
int count = is.read(buffer);
if (count > 0) {
cmdline = new String(buffer, 0, count);
}
} catch (IOException e) {
Rlog.d(TAG, "No /proc/cmdline exception=" + e);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
}
Rlog.d(TAG, "/proc/cmdline=" + cmdline);
return cmdline;
}
/** Kernel command line */
private static final String sKernelCmdLine = getProcCmdLine();
/** Pattern for selecting the product type from the kernel command line */
private static final Pattern sProductTypePattern =
Pattern.compile("\\sproduct_type\\s*=\\s*(\\w+)");
/** The ProductType used for LTE on CDMA devices */
private static final String sLteOnCdmaProductType =
SystemProperties.get(TelephonyProperties.PROPERTY_LTE_ON_CDMA_PRODUCT_TYPE, "");
/**
* Return if the current radio is LTE on CDMA. This
* is a tri-state return value as for a period of time
* the mode may be unknown.
*
* @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE}
* or {@link PhoneConstants#LTE_ON_CDMA_TRUE}
*
* @hide
*/
@UnsupportedAppUsage
public static int getLteOnCdmaModeStatic() {
int retVal;
int curVal;
String productType = "";
curVal = SystemProperties.getInt(TelephonyProperties.PROPERTY_LTE_ON_CDMA_DEVICE,
PhoneConstants.LTE_ON_CDMA_UNKNOWN);
retVal = curVal;
if (retVal == PhoneConstants.LTE_ON_CDMA_UNKNOWN) {
Matcher matcher = sProductTypePattern.matcher(sKernelCmdLine);
if (matcher.find()) {
productType = matcher.group(1);
if (sLteOnCdmaProductType.equals(productType)) {
retVal = PhoneConstants.LTE_ON_CDMA_TRUE;
} else {
retVal = PhoneConstants.LTE_ON_CDMA_FALSE;
}
} else {
retVal = PhoneConstants.LTE_ON_CDMA_FALSE;
}
}
Rlog.d(TAG, "getLteOnCdmaMode=" + retVal + " curVal=" + curVal +
" product_type='" + productType +
"' lteOnCdmaProductType='" + sLteOnCdmaProductType + "'");
return retVal;
}
//
//
// Current Network
//
//
/**
* Returns the alphabetic name of current registered operator.
* <p>
* Availability: Only when user is registered to a network. Result may be
* unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
* on a CDMA network).
*/
public String getNetworkOperatorName() {
return getNetworkOperatorName(getSubId());
}
/**
* Returns the alphabetic name of current registered operator
* for a particular subscription.
* <p>
* Availability: Only when user is registered to a network. Result may be
* unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
* on a CDMA network).
* @param subId
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public String getNetworkOperatorName(int subId) {
int phoneId = SubscriptionManager.getPhoneId(subId);
return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, "");
}
/**
* Returns the numeric name (MCC+MNC) of current registered operator.
* <p>
* Availability: Only when user is registered to a network. Result may be
* unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
* on a CDMA network).
*/
public String getNetworkOperator() {
return getNetworkOperatorForPhone(getPhoneId());
}
/**
* Returns the numeric name (MCC+MNC) of current registered operator
* for a particular subscription.
* <p>
* Availability: Only when user is registered to a network. Result may be
* unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
* on a CDMA network).
*
* @param subId
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public String getNetworkOperator(int subId) {
int phoneId = SubscriptionManager.getPhoneId(subId);
return getNetworkOperatorForPhone(phoneId);
}
/**
* Returns the numeric name (MCC+MNC) of current registered operator
* for a particular subscription.
* <p>
* Availability: Only when user is registered to a network. Result may be
* unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
* on a CDMA network).
*
* @param phoneId
* @hide
**/
@UnsupportedAppUsage
public String getNetworkOperatorForPhone(int phoneId) {
return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, "");
}
/**
* Returns the network specifier of the subscription ID pinned to the TelephonyManager. The
* network specifier is used by {@link
* android.net.NetworkRequest.Builder#setNetworkSpecifier(String)} to create a {@link
* android.net.NetworkRequest} that connects through the subscription.
*
* @see android.net.NetworkRequest.Builder#setNetworkSpecifier(String)
* @see #createForSubscriptionId(int)
* @see #createForPhoneAccountHandle(PhoneAccountHandle)
*/
public String getNetworkSpecifier() {
return String.valueOf(getSubId());
}
/**
* Returns the carrier config of the subscription ID pinned to the TelephonyManager. If an
* invalid subscription ID is pinned to the TelephonyManager, the returned config will contain
* default values.
*
* <p>This method may take several seconds to complete, so it should only be called from a
* worker thread.
*
* <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
* or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}).
*
* @see CarrierConfigManager#getConfigForSubId(int)
* @see #createForSubscriptionId(int)
* @see #createForPhoneAccountHandle(PhoneAccountHandle)
*/
@SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges
@WorkerThread
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public PersistableBundle getCarrierConfig() {
CarrierConfigManager carrierConfigManager = mContext
.getSystemService(CarrierConfigManager.class);
return carrierConfigManager.getConfigForSubId(getSubId());
}
/**
* Returns true if the device is considered roaming on the current
* network, for GSM purposes.
* <p>
* Availability: Only when user registered to a network.
*/
public boolean isNetworkRoaming() {
return isNetworkRoaming(getSubId());
}
/**
* Returns true if the device is considered roaming on the current
* network for a subscription.
* <p>
* Availability: Only when user registered to a network.
*
* @param subId
* @hide
*/
@UnsupportedAppUsage
public boolean isNetworkRoaming(int subId) {
int phoneId = SubscriptionManager.getPhoneId(subId);
return Boolean.parseBoolean(getTelephonyProperty(phoneId,
TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, null));
}
/**
* Returns the ISO country code equivalent of the MCC (Mobile Country Code) of the current
* registered operator or the cell nearby, if available.
* .
* <p>
* Note: Result may be unreliable on CDMA networks (use {@link #getPhoneType()} to determine
* if on a CDMA network).
*/
public String getNetworkCountryIso() {
return getNetworkCountryIsoForPhone(getPhoneId());
}
/**
* Returns the ISO country code equivalent of the MCC (Mobile Country Code) of the current
* registered operator or the cell nearby, if available.
* <p>
* Note: Result may be unreliable on CDMA networks (use {@link #getPhoneType()} to determine
* if on a CDMA network).
*
* @param subId for which Network CountryIso is returned
* @hide
*/
@UnsupportedAppUsage
public String getNetworkCountryIso(int subId) {
return getNetworkCountryIsoForPhone(getPhoneId(subId));
}
/**
* Returns the ISO country code equivalent of the current registered
* operator's MCC (Mobile Country Code) of a subscription.
* <p>
* Availability: Only when user is registered to a network. Result may be
* unreliable on CDMA networks (use {@link #getPhoneType()} to determine if
* on a CDMA network).
*
* @param phoneId for which Network CountryIso is returned
*/
/** {@hide} */
@UnsupportedAppUsage
public String getNetworkCountryIsoForPhone(int phoneId) {
try {
ITelephony telephony = getITelephony();
if (telephony == null) return "";
return telephony.getNetworkCountryIsoForPhone(phoneId);
} catch (RemoteException ex) {
return "";
}
}
/*
* When adding a network type to the list below, make sure to add the correct icon to
* MobileSignalController.mapIconSets().
* Do not add negative types.
*/
/** Network type is unknown */
public static final int NETWORK_TYPE_UNKNOWN = TelephonyProtoEnums.NETWORK_TYPE_UNKNOWN; // = 0.
/** Current network is GPRS */
public static final int NETWORK_TYPE_GPRS = TelephonyProtoEnums.NETWORK_TYPE_GPRS; // = 1.
/** Current network is EDGE */
public static final int NETWORK_TYPE_EDGE = TelephonyProtoEnums.NETWORK_TYPE_EDGE; // = 2.
/** Current network is UMTS */
public static final int NETWORK_TYPE_UMTS = TelephonyProtoEnums.NETWORK_TYPE_UMTS; // = 3.
/** Current network is CDMA: Either IS95A or IS95B*/
public static final int NETWORK_TYPE_CDMA = TelephonyProtoEnums.NETWORK_TYPE_CDMA; // = 4.
/** Current network is EVDO revision 0*/
public static final int NETWORK_TYPE_EVDO_0 = TelephonyProtoEnums.NETWORK_TYPE_EVDO_0; // = 5.
/** Current network is EVDO revision A*/
public static final int NETWORK_TYPE_EVDO_A = TelephonyProtoEnums.NETWORK_TYPE_EVDO_A; // = 6.
/** Current network is 1xRTT*/
public static final int NETWORK_TYPE_1xRTT = TelephonyProtoEnums.NETWORK_TYPE_1XRTT; // = 7.
/** Current network is HSDPA */
public static final int NETWORK_TYPE_HSDPA = TelephonyProtoEnums.NETWORK_TYPE_HSDPA; // = 8.
/** Current network is HSUPA */
public static final int NETWORK_TYPE_HSUPA = TelephonyProtoEnums.NETWORK_TYPE_HSUPA; // = 9.
/** Current network is HSPA */
public static final int NETWORK_TYPE_HSPA = TelephonyProtoEnums.NETWORK_TYPE_HSPA; // = 10.
/** Current network is iDen */
public static final int NETWORK_TYPE_IDEN = TelephonyProtoEnums.NETWORK_TYPE_IDEN; // = 11.
/** Current network is EVDO revision B*/
public static final int NETWORK_TYPE_EVDO_B = TelephonyProtoEnums.NETWORK_TYPE_EVDO_B; // = 12.
/** Current network is LTE */
public static final int NETWORK_TYPE_LTE = TelephonyProtoEnums.NETWORK_TYPE_LTE; // = 13.
/** Current network is eHRPD */
public static final int NETWORK_TYPE_EHRPD = TelephonyProtoEnums.NETWORK_TYPE_EHRPD; // = 14.
/** Current network is HSPA+ */
public static final int NETWORK_TYPE_HSPAP = TelephonyProtoEnums.NETWORK_TYPE_HSPAP; // = 15.
/** Current network is GSM */
public static final int NETWORK_TYPE_GSM = TelephonyProtoEnums.NETWORK_TYPE_GSM; // = 16.
/** Current network is TD_SCDMA */
public static final int NETWORK_TYPE_TD_SCDMA =
TelephonyProtoEnums.NETWORK_TYPE_TD_SCDMA; // = 17.
/** Current network is IWLAN */
public static final int NETWORK_TYPE_IWLAN = TelephonyProtoEnums.NETWORK_TYPE_IWLAN; // = 18.
/** Current network is LTE_CA {@hide} */
@UnsupportedAppUsage
public static final int NETWORK_TYPE_LTE_CA = TelephonyProtoEnums.NETWORK_TYPE_LTE_CA; // = 19.
/** Current network is NR(New Radio) 5G. */
public static final int NETWORK_TYPE_NR = TelephonyProtoEnums.NETWORK_TYPE_NR; // 20.
/** Max network type number. Update as new types are added. Don't add negative types. {@hide} */
public static final int MAX_NETWORK_TYPE = NETWORK_TYPE_NR;
/** @hide */
@IntDef({
NETWORK_TYPE_UNKNOWN,
NETWORK_TYPE_GPRS,
NETWORK_TYPE_EDGE,
NETWORK_TYPE_UMTS,
NETWORK_TYPE_CDMA,
NETWORK_TYPE_EVDO_0,
NETWORK_TYPE_EVDO_A,
NETWORK_TYPE_1xRTT,
NETWORK_TYPE_HSDPA,
NETWORK_TYPE_HSUPA,
NETWORK_TYPE_HSPA,
NETWORK_TYPE_IDEN,
NETWORK_TYPE_EVDO_B,
NETWORK_TYPE_LTE,
NETWORK_TYPE_EHRPD,
NETWORK_TYPE_HSPAP,
NETWORK_TYPE_GSM,
NETWORK_TYPE_TD_SCDMA,
NETWORK_TYPE_IWLAN,
NETWORK_TYPE_LTE_CA,
NETWORK_TYPE_NR,
})
@Retention(RetentionPolicy.SOURCE)
public @interface NetworkType{}
/**
* @return the NETWORK_TYPE_xxxx for current data connection.
*/
public @NetworkType int getNetworkType() {
try {
ITelephony telephony = getITelephony();
if (telephony != null) {
return telephony.getNetworkType();
} else {
// This can happen when the ITelephony interface is not up yet.
return NETWORK_TYPE_UNKNOWN;
}
} catch(RemoteException ex) {
// This shouldn't happen in the normal case
return NETWORK_TYPE_UNKNOWN;
} catch (NullPointerException ex) {
// This could happen before phone restarts due to crashing
return NETWORK_TYPE_UNKNOWN;
}
}
/**
* Returns a constant indicating the radio technology (network type)
* currently in use on the device for a subscription.
* @return the network type
*
* @param subId for which network type is returned
*
* @see #NETWORK_TYPE_UNKNOWN
* @see #NETWORK_TYPE_GPRS
* @see #NETWORK_TYPE_EDGE
* @see #NETWORK_TYPE_UMTS
* @see #NETWORK_TYPE_HSDPA
* @see #NETWORK_TYPE_HSUPA
* @see #NETWORK_TYPE_HSPA
* @see #NETWORK_TYPE_CDMA
* @see #NETWORK_TYPE_EVDO_0
* @see #NETWORK_TYPE_EVDO_A
* @see #NETWORK_TYPE_EVDO_B
* @see #NETWORK_TYPE_1xRTT
* @see #NETWORK_TYPE_IDEN
* @see #NETWORK_TYPE_LTE
* @see #NETWORK_TYPE_EHRPD
* @see #NETWORK_TYPE_HSPAP
* @see #NETWORK_TYPE_NR
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
@UnsupportedAppUsage
public int getNetworkType(int subId) {
try {
ITelephony telephony = getITelephony();
if (telephony != null) {
return telephony.getNetworkTypeForSubscriber(subId, getOpPackageName());
} else {
// This can happen when the ITelephony interface is not up yet.
return NETWORK_TYPE_UNKNOWN;
}
} catch (RemoteException ex) {
// This shouldn't happen in the normal case
return NETWORK_TYPE_UNKNOWN;
} catch (NullPointerException ex) {
// This could happen before phone restarts due to crashing
return NETWORK_TYPE_UNKNOWN;
}
}
/**
* Returns a constant indicating the radio technology (network type)
* currently in use on the device for data transmission.
*
* If this object has been created with {@link #createForSubscriptionId}, applies to the given
* subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()}
*
* <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
* or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}).
*
* @return the network type
*
* @see #NETWORK_TYPE_UNKNOWN
* @see #NETWORK_TYPE_GPRS
* @see #NETWORK_TYPE_EDGE
* @see #NETWORK_TYPE_UMTS
* @see #NETWORK_TYPE_HSDPA
* @see #NETWORK_TYPE_HSUPA
* @see #NETWORK_TYPE_HSPA
* @see #NETWORK_TYPE_CDMA
* @see #NETWORK_TYPE_EVDO_0
* @see #NETWORK_TYPE_EVDO_A
* @see #NETWORK_TYPE_EVDO_B
* @see #NETWORK_TYPE_1xRTT
* @see #NETWORK_TYPE_IDEN
* @see #NETWORK_TYPE_LTE
* @see #NETWORK_TYPE_EHRPD
* @see #NETWORK_TYPE_HSPAP
* @see #NETWORK_TYPE_NR
*/
@SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public @NetworkType int getDataNetworkType() {
return getDataNetworkType(getSubId(SubscriptionManager.getDefaultDataSubscriptionId()));
}
/**
* Returns a constant indicating the radio technology (network type)
* currently in use on the device for data transmission for a subscription
* @return the network type
*
* @param subId for which network type is returned
* @hide
*/
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public int getDataNetworkType(int subId) {
try{
ITelephony telephony = getITelephony();
if (telephony != null) {
return telephony.getDataNetworkTypeForSubscriber(subId, getOpPackageName());
} else {
// This can happen when the ITelephony interface is not up yet.
return NETWORK_TYPE_UNKNOWN;
}
} catch(RemoteException ex) {
// This shouldn't happen in the normal case
return NETWORK_TYPE_UNKNOWN;
} catch (NullPointerException ex) {
// This could happen before phone restarts due to crashing
return NETWORK_TYPE_UNKNOWN;
}
}
/**
* Returns the NETWORK_TYPE_xxxx for voice
*
* <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
* or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}).
*/
@SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public @NetworkType int getVoiceNetworkType() {
return getVoiceNetworkType(getSubId());
}
/**
* Returns the NETWORK_TYPE_xxxx for voice for a subId
* @hide
*/
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public int getVoiceNetworkType(int subId) {
try{
ITelephony telephony = getITelephony();
if (telephony != null) {
return telephony.getVoiceNetworkTypeForSubscriber(subId, getOpPackageName());
} else {
// This can happen when the ITelephony interface is not up yet.
return NETWORK_TYPE_UNKNOWN;
}
} catch(RemoteException ex) {
// This shouldn't happen in the normal case
return NETWORK_TYPE_UNKNOWN;
} catch (NullPointerException ex) {
// This could happen before phone restarts due to crashing
return NETWORK_TYPE_UNKNOWN;
}
}
/**
* Network Class Definitions.
* Do not change this order, it is used for sorting during emergency calling in
* {@link TelephonyConnectionService#getFirstPhoneForEmergencyCall()}. Any newer technologies
* should be added after the current definitions.
*/
/** Unknown network class. {@hide} */
public static final int NETWORK_CLASS_UNKNOWN = 0;
/** Class of broadly defined "2G" networks. {@hide} */
@UnsupportedAppUsage
public static final int NETWORK_CLASS_2_G = 1;
/** Class of broadly defined "3G" networks. {@hide} */
@UnsupportedAppUsage
public static final int NETWORK_CLASS_3_G = 2;
/** Class of broadly defined "4G" networks. {@hide} */
@UnsupportedAppUsage
public static final int NETWORK_CLASS_4_G = 3;
/**
* Return general class of network type, such as "3G" or "4G". In cases
* where classification is contentious, this method is conservative.
*
* @hide
*/
@UnsupportedAppUsage
public static int getNetworkClass(int networkType) {
switch (networkType) {
case NETWORK_TYPE_GPRS:
case NETWORK_TYPE_GSM:
case NETWORK_TYPE_EDGE:
case NETWORK_TYPE_CDMA:
case NETWORK_TYPE_1xRTT:
case NETWORK_TYPE_IDEN:
return NETWORK_CLASS_2_G;
case NETWORK_TYPE_UMTS:
case NETWORK_TYPE_EVDO_0:
case NETWORK_TYPE_EVDO_A:
case NETWORK_TYPE_HSDPA:
case NETWORK_TYPE_HSUPA:
case NETWORK_TYPE_HSPA:
case NETWORK_TYPE_EVDO_B:
case NETWORK_TYPE_EHRPD:
case NETWORK_TYPE_HSPAP:
case NETWORK_TYPE_TD_SCDMA:
return NETWORK_CLASS_3_G;
case NETWORK_TYPE_LTE:
case NETWORK_TYPE_IWLAN:
case NETWORK_TYPE_LTE_CA:
return NETWORK_CLASS_4_G;
default:
return NETWORK_CLASS_UNKNOWN;
}
}
/**
* Returns a string representation of the radio technology (network type)
* currently in use on the device.
* @return the name of the radio technology
*
* @hide pending API council review
*/
@UnsupportedAppUsage
public String getNetworkTypeName() {
return getNetworkTypeName(getNetworkType());
}
/**
* Returns a string representation of the radio technology (network type)
* currently in use on the device.
* @param subId for which network type is returned
* @return the name of the radio technology
*
*/
/** {@hide} */
@UnsupportedAppUsage
public static String getNetworkTypeName(int type) {
switch (type) {
case NETWORK_TYPE_GPRS:
return "GPRS";
case NETWORK_TYPE_EDGE:
return "EDGE";
case NETWORK_TYPE_UMTS:
return "UMTS";
case NETWORK_TYPE_HSDPA:
return "HSDPA";
case NETWORK_TYPE_HSUPA:
return "HSUPA";
case NETWORK_TYPE_HSPA:
return "HSPA";
case NETWORK_TYPE_CDMA:
return "CDMA";
case NETWORK_TYPE_EVDO_0:
return "CDMA - EvDo rev. 0";
case NETWORK_TYPE_EVDO_A:
return "CDMA - EvDo rev. A";
case NETWORK_TYPE_EVDO_B:
return "CDMA - EvDo rev. B";
case NETWORK_TYPE_1xRTT:
return "CDMA - 1xRTT";
case NETWORK_TYPE_LTE:
return "LTE";
case NETWORK_TYPE_EHRPD:
return "CDMA - eHRPD";
case NETWORK_TYPE_IDEN:
return "iDEN";
case NETWORK_TYPE_HSPAP:
return "HSPA+";
case NETWORK_TYPE_GSM:
return "GSM";
case NETWORK_TYPE_TD_SCDMA:
return "TD_SCDMA";
case NETWORK_TYPE_IWLAN:
return "IWLAN";
case NETWORK_TYPE_LTE_CA:
return "LTE_CA";
case NETWORK_TYPE_NR:
return "NR";
default:
return "UNKNOWN";
}
}
//
//
// SIM Card
//
//
/**
* SIM card state: Unknown. Signifies that the SIM is in transition
* between states. For example, when the user inputs the SIM pin
* under PIN_REQUIRED state, a query for sim status returns
* this state before turning to SIM_STATE_READY.
*
* These are the ordinal value of IccCardConstants.State.
*/
public static final int SIM_STATE_UNKNOWN = TelephonyProtoEnums.SIM_STATE_UNKNOWN; // 0
/** SIM card state: no SIM card is available in the device */
public static final int SIM_STATE_ABSENT = TelephonyProtoEnums.SIM_STATE_ABSENT; // 1
/** SIM card state: Locked: requires the user's SIM PIN to unlock */
public static final int SIM_STATE_PIN_REQUIRED =
TelephonyProtoEnums.SIM_STATE_PIN_REQUIRED; // 2
/** SIM card state: Locked: requires the user's SIM PUK to unlock */
public static final int SIM_STATE_PUK_REQUIRED =
TelephonyProtoEnums.SIM_STATE_PUK_REQUIRED; // 3
/** SIM card state: Locked: requires a network PIN to unlock */
public static final int SIM_STATE_NETWORK_LOCKED =
TelephonyProtoEnums.SIM_STATE_NETWORK_LOCKED; // 4
/** SIM card state: Ready */
public static final int SIM_STATE_READY = TelephonyProtoEnums.SIM_STATE_READY; // 5
/** SIM card state: SIM Card is NOT READY */
public static final int SIM_STATE_NOT_READY = TelephonyProtoEnums.SIM_STATE_NOT_READY; // 6
/** SIM card state: SIM Card Error, permanently disabled */
public static final int SIM_STATE_PERM_DISABLED =
TelephonyProtoEnums.SIM_STATE_PERM_DISABLED; // 7
/** SIM card state: SIM Card Error, present but faulty */
public static final int SIM_STATE_CARD_IO_ERROR =
TelephonyProtoEnums.SIM_STATE_CARD_IO_ERROR; // 8
/** SIM card state: SIM Card restricted, present but not usable due to
* carrier restrictions.
*/
public static final int SIM_STATE_CARD_RESTRICTED =
TelephonyProtoEnums.SIM_STATE_CARD_RESTRICTED; // 9
/**
* SIM card state: Loaded: SIM card applications have been loaded
* @hide
*/
@SystemApi
public static final int SIM_STATE_LOADED = TelephonyProtoEnums.SIM_STATE_LOADED; // 10
/**
* SIM card state: SIM Card is present
* @hide
*/
@SystemApi
public static final int SIM_STATE_PRESENT = TelephonyProtoEnums.SIM_STATE_PRESENT; // 11
/**
* Extra included in {@link #ACTION_SIM_CARD_STATE_CHANGED} and
* {@link #ACTION_SIM_APPLICATION_STATE_CHANGED} to indicate the card/application state.
*
* @hide
*/
@SystemApi
public static final String EXTRA_SIM_STATE = "android.telephony.extra.SIM_STATE";
/**
* Broadcast Action: The sim card state has changed.
* The intent will have the following extra values:</p>
* <dl>
* <dt>{@link #EXTRA_SIM_STATE}</dt>
* <dd>The sim card state. One of:
* <dl>
* <dt>{@link #SIM_STATE_ABSENT}</dt>
* <dd>SIM card not found</dd>
* <dt>{@link #SIM_STATE_CARD_IO_ERROR}</dt>
* <dd>SIM card IO error</dd>
* <dt>{@link #SIM_STATE_CARD_RESTRICTED}</dt>
* <dd>SIM card is restricted</dd>
* <dt>{@link #SIM_STATE_PRESENT}</dt>
* <dd>SIM card is present</dd>
* </dl>
* </dd>
* </dl>
*
* <p class="note">Requires the READ_PRIVILEGED_PHONE_STATE permission.
*
* <p class="note">The current state can also be queried using {@link #getSimCardState()}.
*
* <p class="note">This is a protected intent that can only be sent by the system.
* @hide
*/
@SystemApi
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_SIM_CARD_STATE_CHANGED =
"android.telephony.action.SIM_CARD_STATE_CHANGED";
/**
* Broadcast Action: The sim application state has changed.
* The intent will have the following extra values:</p>
* <dl>
* <dt>{@link #EXTRA_SIM_STATE}</dt>
* <dd>The sim application state. One of:
* <dl>
* <dt>{@link #SIM_STATE_NOT_READY}</dt>
* <dd>SIM card applications not ready</dd>
* <dt>{@link #SIM_STATE_PIN_REQUIRED}</dt>
* <dd>SIM card PIN locked</dd>
* <dt>{@link #SIM_STATE_PUK_REQUIRED}</dt>
* <dd>SIM card PUK locked</dd>
* <dt>{@link #SIM_STATE_NETWORK_LOCKED}</dt>
* <dd>SIM card network locked</dd>
* <dt>{@link #SIM_STATE_PERM_DISABLED}</dt>
* <dd>SIM card permanently disabled due to PUK failures</dd>
* <dt>{@link #SIM_STATE_LOADED}</dt>
* <dd>SIM card data loaded</dd>
* </dl>
* </dd>
* </dl>
*
* <p class="note">Requires the READ_PRIVILEGED_PHONE_STATE permission.
*
* <p class="note">The current state can also be queried using
* {@link #getSimApplicationState()}.
*
* <p class="note">This is a protected intent that can only be sent by the system.
* @hide
*/
@SystemApi
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_SIM_APPLICATION_STATE_CHANGED =
"android.telephony.action.SIM_APPLICATION_STATE_CHANGED";
/**
* Broadcast Action: Status of the SIM slots on the device has changed.
*
* <p class="note">Requires the READ_PRIVILEGED_PHONE_STATE permission.
*
* <p class="note">The status can be queried using
* {@link #getUiccSlotsInfo()}
*
* <p class="note">This is a protected intent that can only be sent by the system.
* @hide
*/
@SystemApi
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_SIM_SLOT_STATUS_CHANGED =
"android.telephony.action.SIM_SLOT_STATUS_CHANGED";
/**
* Broadcast Action: A debug code has been entered in the dialer.
* <p>
* This intent is broadcast by the system and OEM telephony apps may need to receive these
* broadcasts. And it requires the sender to be default dialer or has carrier privileges
* (see {@link #hasCarrierPrivileges}).
* <p>
* These "secret codes" are used to activate developer menus by dialing certain codes.
* And they are of the form {@code *#*#&lt;code&gt;#*#*}. The intent will have the data
* URI: {@code android_secret_code://&lt;code&gt;}. It is possible that a manifest
* receiver would be woken up even if it is not currently running.
* <p>
* It is supposed to replace {@link android.provider.Telephony.Sms.Intents#SECRET_CODE_ACTION}
* in the next Android version.
* Before that both of these two actions will be broadcast.
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_SECRET_CODE = "android.telephony.action.SECRET_CODE";
/**
* @return true if a ICC card is present
*/
public boolean hasIccCard() {
return hasIccCard(getSlotIndex());
}
/**
* @return true if a ICC card is present for a subscription
*
* @param slotIndex for which icc card presence is checked
*/
/** {@hide} */
// FIXME Input argument slotIndex should be of type int
@UnsupportedAppUsage
public boolean hasIccCard(int slotIndex) {
try {
ITelephony telephony = getITelephony();
if (telephony == null)
return false;
return telephony.hasIccCardUsingSlotIndex(slotIndex);
} catch (RemoteException ex) {
// Assume no ICC card if remote exception which shouldn't happen
return false;
} catch (NullPointerException ex) {
// This could happen before phone restarts due to crashing
return false;
}
}
/**
* Returns a constant indicating the state of the default SIM card.
*
* @see #SIM_STATE_UNKNOWN
* @see #SIM_STATE_ABSENT
* @see #SIM_STATE_PIN_REQUIRED
* @see #SIM_STATE_PUK_REQUIRED
* @see #SIM_STATE_NETWORK_LOCKED
* @see #SIM_STATE_READY
* @see #SIM_STATE_NOT_READY
* @see #SIM_STATE_PERM_DISABLED
* @see #SIM_STATE_CARD_IO_ERROR
* @see #SIM_STATE_CARD_RESTRICTED
*/
public int getSimState() {
int simState = getSimStateIncludingLoaded();
if (simState == SIM_STATE_LOADED) {
simState = SIM_STATE_READY;
}
return simState;
}
private int getSimStateIncludingLoaded() {
int slotIndex = getSlotIndex();
// slotIndex may be invalid due to sim being absent. In that case query all slots to get
// sim state
if (slotIndex < 0) {
// query for all slots and return absent if all sim states are absent, otherwise
// return unknown
for (int i = 0; i < getPhoneCount(); i++) {
int simState = getSimState(i);
if (simState != SIM_STATE_ABSENT) {
Rlog.d(TAG, "getSimState: default sim:" + slotIndex + ", sim state for " +
"slotIndex=" + i + " is " + simState + ", return state as unknown");
return SIM_STATE_UNKNOWN;
}
}
Rlog.d(TAG, "getSimState: default sim:" + slotIndex + ", all SIMs absent, return " +
"state as absent");
return SIM_STATE_ABSENT;
}
return SubscriptionManager.getSimStateForSlotIndex(slotIndex);
}
/**
* Returns a constant indicating the state of the default SIM card.
*
* @see #SIM_STATE_UNKNOWN
* @see #SIM_STATE_ABSENT
* @see #SIM_STATE_CARD_IO_ERROR
* @see #SIM_STATE_CARD_RESTRICTED
* @see #SIM_STATE_PRESENT
*
* @hide
*/
@SystemApi
public int getSimCardState() {
int simCardState = getSimState();
switch (simCardState) {
case SIM_STATE_UNKNOWN:
case SIM_STATE_ABSENT:
case SIM_STATE_CARD_IO_ERROR:
case SIM_STATE_CARD_RESTRICTED:
return simCardState;
default:
return SIM_STATE_PRESENT;
}
}
/**
* Returns a constant indicating the state of the card applications on the default SIM card.
*
* @see #SIM_STATE_UNKNOWN
* @see #SIM_STATE_PIN_REQUIRED
* @see #SIM_STATE_PUK_REQUIRED
* @see #SIM_STATE_NETWORK_LOCKED
* @see #SIM_STATE_NOT_READY
* @see #SIM_STATE_PERM_DISABLED
* @see #SIM_STATE_LOADED
*
* @hide
*/
@SystemApi
public int getSimApplicationState() {
int simApplicationState = getSimStateIncludingLoaded();
switch (simApplicationState) {
case SIM_STATE_UNKNOWN:
case SIM_STATE_ABSENT:
case SIM_STATE_CARD_IO_ERROR:
case SIM_STATE_CARD_RESTRICTED:
return SIM_STATE_UNKNOWN;
case SIM_STATE_READY:
// Ready is not a valid state anymore. The state that is broadcast goes from
// NOT_READY to either LOCKED or LOADED.
return SIM_STATE_NOT_READY;
default:
return simApplicationState;
}
}
/**
* Returns a constant indicating the state of the device SIM card in a slot.
*
* @param slotIndex
*
* @see #SIM_STATE_UNKNOWN
* @see #SIM_STATE_ABSENT
* @see #SIM_STATE_PIN_REQUIRED
* @see #SIM_STATE_PUK_REQUIRED
* @see #SIM_STATE_NETWORK_LOCKED
* @see #SIM_STATE_READY
* @see #SIM_STATE_NOT_READY
* @see #SIM_STATE_PERM_DISABLED
* @see #SIM_STATE_CARD_IO_ERROR
* @see #SIM_STATE_CARD_RESTRICTED
*/
public int getSimState(int slotIndex) {
int simState = SubscriptionManager.getSimStateForSlotIndex(slotIndex);
if (simState == SIM_STATE_LOADED) {
simState = SIM_STATE_READY;
}
return simState;
}
/**
* Returns the MCC+MNC (mobile country code + mobile network code) of the
* provider of the SIM. 5 or 6 decimal digits.
* <p>
* Availability: SIM state must be {@link #SIM_STATE_READY}
*
* @see #getSimState
*/
public String getSimOperator() {
return getSimOperatorNumeric();
}
/**
* Returns the MCC+MNC (mobile country code + mobile network code) of the
* provider of the SIM. 5 or 6 decimal digits.
* <p>
* Availability: SIM state must be {@link #SIM_STATE_READY}
*
* @see #getSimState
*
* @param subId for which SimOperator is returned
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public String getSimOperator(int subId) {
return getSimOperatorNumeric(subId);
}
/**
* Returns the MCC+MNC (mobile country code + mobile network code) of the
* provider of the SIM. 5 or 6 decimal digits.
* <p>
* Availability: SIM state must be {@link #SIM_STATE_READY}
*
* @see #getSimState
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public String getSimOperatorNumeric() {
int subId = mSubId;
if (!SubscriptionManager.isUsableSubIdValue(subId)) {
subId = SubscriptionManager.getDefaultDataSubscriptionId();
if (!SubscriptionManager.isUsableSubIdValue(subId)) {
subId = SubscriptionManager.getDefaultSmsSubscriptionId();
if (!SubscriptionManager.isUsableSubIdValue(subId)) {
subId = SubscriptionManager.getDefaultVoiceSubscriptionId();
if (!SubscriptionManager.isUsableSubIdValue(subId)) {
subId = SubscriptionManager.getDefaultSubscriptionId();
}
}
}
}
return getSimOperatorNumeric(subId);
}
/**
* Returns the MCC+MNC (mobile country code + mobile network code) of the
* provider of the SIM for a particular subscription. 5 or 6 decimal digits.
* <p>
* Availability: SIM state must be {@link #SIM_STATE_READY}
*
* @see #getSimState
*
* @param subId for which SimOperator is returned
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public String getSimOperatorNumeric(int subId) {
int phoneId = SubscriptionManager.getPhoneId(subId);
return getSimOperatorNumericForPhone(phoneId);
}
/**
* Returns the MCC+MNC (mobile country code + mobile network code) of the
* provider of the SIM for a particular subscription. 5 or 6 decimal digits.
* <p>
*
* @param phoneId for which SimOperator is returned
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public String getSimOperatorNumericForPhone(int phoneId) {
return getTelephonyProperty(phoneId,
TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, "");
}
/**
* Returns the Service Provider Name (SPN).
* <p>