Package org.robolectric.shadows
Class ShadowTelephonyManager
java.lang.Object
org.robolectric.shadows.ShadowTelephonyManager
@Implements(value=android.telephony.TelephonyManager.class, looseSignatures=true) public class ShadowTelephonyManager extends Object
-
Field Summary
Fields Modifier and Type Field Description protected TelephonyManager
realTelephonyManager
-
Constructor Summary
Constructors Constructor Description ShadowTelephonyManager()
-
Method Summary
Modifier and Type Method Description void
clearPhoneTypes()
Removes allsubId
tophoneType
mappings.protected TelephonyManager
createForPhoneAccountHandle(PhoneAccountHandle handle)
Returnsnull
by default or the value specified viasetTelephonyManagerForHandle(PhoneAccountHandle, TelephonyManager)
.protected TelephonyManager
createForSubscriptionId(int subId)
Returnsnull
by default or the value specified viasetTelephonyManagerForSubscriptionId(int, TelephonyManager)
static Object
createTelephonyDisplayInfo(int networkType, int overrideNetworkType)
Creates aTelephonyDisplayInfo
.protected List<CellInfo>
getAllCellInfo()
protected int
getCallState()
Call state may be specified viasetCallState(int)
.protected PersistableBundle
getCarrierConfig()
Returns a new emptyPersistableBundle
by default, or the value specified viasetCarrierConfig(PersistableBundle)
.protected int
getCarrierIdFromSimMccMnc()
protected List<String>
getCarrierPackageNamesForIntent(Intent intent)
protected List<String>
getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId)
protected CellLocation
getCellLocation()
protected int
getCurrentPhoneType(int subId)
protected int
getDataNetworkType()
Returns whatever value was set by the last call tosetDataNetworkType(int)
, defaulting toTelephonyManager.NETWORK_TYPE_UNKNOWN
if it was never called.protected int
getDataState()
Data state may be specified viasetDataState(int)
.protected String
getDeviceId()
protected String
getDeviceId(int slot)
Returnsnull
by default or the value specified viasetDeviceId(int, String)
.int
getEventFlags()
Deprecated.Avoid using.protected String
getGroupIdLevel1()
protected String
getImei()
protected String
getImei(int slotIndex)
protected String
getLine1Number()
PhoneStateListener
getListener()
Deprecated.Avoid using.protected Iterable<PhoneStateListener>
getListenersForFlags(int flags)
protected String
getMeid()
protected String
getMeid(int slotIndex)
protected String
getNetworkCountryIso()
protected String
getNetworkOperator()
protected String
getNetworkOperatorName()
protected int
getNetworkType()
protected int
getPhoneCount()
Returns 1 by default or the value specified viasetPhoneCount(int)
.protected int
getPhoneType()
List<String>
getSentDialerSpecialCodes()
Returns immutable list of special codes sent usingTelephonyManager.sendDialerSpecialCode(String)
.protected ServiceState
getServiceState()
Returnsnull
by default or the value specified viasetServiceState(ServiceState)
protected SignalStrength
getSignalStrength()
protected int
getSimCarrierId()
protected String
getSimCountryIso()
protected String
getSimCountryIso(int subId)
protected Locale
getSimLocale()
Returns sim locale set bysetSimLocale(java.util.Locale)
.protected String
getSimOperator()
protected String
getSimOperatorName()
protected String
getSimSerialNumber()
protected int
getSimState()
protected int
getSimState(int slotIndex)
protected String
getSubscriberId()
protected Object
getUiccSlotsInfo()
Returns the UICC slots information set bysetUiccSlotsInfo(java.lang.Object)
.protected String
getVisualVoicemailPackageName()
Returns the value set bysetVisualVoicemailPackageName(String)
.protected String
getVoiceMailAlphaTag()
Returnsnull
by default or the value specified viasetVoiceMailAlphaTag(String)
.protected String
getVoiceMailNumber()
Returnsnull
by default, or the value specified viasetVoiceMailNumber(String)
.protected Uri
getVoicemailRingtoneUri(PhoneAccountHandle handle)
Returnsnull
by default or the value specified viasetVoicemailRingtoneUri(PhoneAccountHandle, Uri)
.protected int
getVoiceNetworkType()
Returns whatever value was set by the last call tosetVoiceNetworkType(int)
, defaulting toTelephonyManager.NETWORK_TYPE_UNKNOWN
if it was never called.protected void
initListener(PhoneStateListener listener, int flags)
protected boolean
isDataConnectionAllowed()
protected boolean
isDataEnabled()
Implementation forTelephonyManager.isDataEnabled()
.protected boolean
isEmergencyNumber(String number)
Cribbed fromPhoneNumberUtils.isEmergencyNumberInternal(java.lang.String, boolean)
.protected boolean
isHearingAidCompatibilitySupported()
Implementation forTelephonyManager.isHearingAidCompatibilitySupported()
.protected boolean
isNetworkRoaming()
Returnsfalse
by default or the value specified viasetIsNetworkRoaming(boolean)
protected boolean
isPotentialEmergencyNumber(String number)
protected boolean
isRttSupported()
Implementation forTelephonyManager.isRttSupported()
.protected boolean
isSmsCapable()
protected boolean
isVoiceCapable()
Returnstrue
by default or the value specified viasetVoiceCapable(boolean)
.protected boolean
isVoicemailVibrationEnabled(PhoneAccountHandle handle)
Returnsnull
by default or the value specified viasetVoicemailVibrationEnabled(PhoneAccountHandle, boolean)
.protected void
listen(PhoneStateListener listener, int flags)
protected void
requestCellInfoUpdate(Object cellInfoExecutor, Object cellInfoCallback)
Returns the value set bysetCallbackCellInfos(java.util.List<android.telephony.CellInfo>)
, defaulting to calling the realTelephonyManager.NETWORK_TYPE_UNKNOWN
if it was never called.void
resetSimCountryIsos()
ClearssubId
to simCountryIso mapping and resets to default state.void
resetSimStates()
ClearsslotIndex
to state mapping and resets to default state.void
sendDialerSpecialCode(String inputCode)
Implementation forTelephonyManager.sendDialerSpecialCode(String)
.void
setAllCellInfo(List<CellInfo> allCellInfo)
void
setCallbackCellInfos(List<CellInfo> callbackCellInfos)
Sets the value to be returned by calls torequestCellInfoUpdate(java.lang.Object,java.lang.Object)
.void
setCallState(int callState)
Sets the current call state to the desired state and updates any listeners.void
setCallState(int callState, String incomingPhoneNumber)
Sets the current call state with the option to specify an incoming phone number for the CALL_STATE_RINGING state.void
setCarrierConfig(PersistableBundle carrierConfig)
Sets the value returned byTelephonyManager.getCarrierConfig()
.void
setCarrierIdFromSimMccMnc(int carrierIdFromSimMccMnc)
Sets the value to be returned bygetCarrierIdFromSimMccMnc()
.void
setCarrierPackageNamesForPhone(int phoneId, List<String> packages)
Sets thepackages
for the givenphoneId
.void
setCellLocation(CellLocation cellLocation)
void
setCurrentPhoneType(int subId, int phoneType)
Sets the phone type for the givensubId
.void
setDataEnabled(boolean enabled)
Implementation forTelephonyManager.setDataEnabled(boolean)
.void
setDataNetworkType(int dataNetworkType)
Sets the value to be returned by calls togetDataNetworkType()
.void
setDataState(int dataState)
Sets the data state returned bygetDataState()
.void
setDeviceId(int slot, String deviceId)
Sets the value returned byTelephonyManager.getDeviceId(int)
.void
setDeviceId(String newDeviceId)
void
setGroupIdLevel1(String groupIdLevel1)
void
setHearingAidCompatibilitySupported(boolean isSupported)
Sets the value to be returned byisHearingAidCompatibilitySupported()
.void
setImei(int slotIndex, String imei)
Set the IMEI returned bygetImei(int)
.void
setImei(String imei)
Set the IMEI returned by getImei().void
setIsDataConnectionAllowed(boolean isDataConnectionAllowed)
void
setIsNetworkRoaming(boolean isNetworkRoaming)
Sets the value returned byTelephonyManager.isNetworkRoaming()
.void
setIsSmsCapable(boolean isSmsCapable)
Sets the value returned byTelephonyManager.isSmsCapable()
.void
setLine1Number(String line1Number)
void
setMeid(int slotIndex, String meid)
Set the MEID returned bygetMeid(int)
.void
setMeid(String meid)
Set the MEID returned by getMeid().void
setNetworkCountryIso(String networkCountryIso)
void
setNetworkOperator(String networkOperator)
void
setNetworkOperatorName(String networkOperatorName)
void
setNetworkType(int networkType)
Deprecated.TelephonyManager.getNetworkType()
was replaced withTelephonyManager.getDataNetworkType()
in Android N, and has been deprecated in Android R.void
setPhoneCount(int phoneCount)
Sets the value returned byTelephonyManager.getPhoneCount()
.void
setPhoneType(int phoneType)
void
setReadPhoneStatePermission(boolean readPhoneStatePermission)
void
setRequestCellInfoUpdateErrorValues(int errorCode, Throwable detail)
Sets the values to be returned by a presumed error condition inrequestCellInfoUpdate(java.lang.Object,java.lang.Object)
.void
setRttSupported(boolean isRttSupported)
Sets the value to be returned byisRttSupported()
void
setServiceState(ServiceState serviceState)
Sets the value returned byTelephonyManager.getServiceState()
.void
setSignalStrength(SignalStrength signalStrength)
Sets the value to be returned bygetSignalStrength()
void
setSimCarrierId(int simCarrierId)
Sets the value to be returned bygetSimCarrierId()
.void
setSimCountryIso(int subId, String simCountryIso)
Sets thesimCountryIso
for the givensubId
.void
setSimCountryIso(String simCountryIso)
void
setSimLocale(Locale simLocale)
Sets the sim locale returned bygetSimLocale()
.void
setSimOperator(String simOperator)
void
setSimOperatorName(String simOperatorName)
void
setSimSerialNumber(String simSerialNumber)
sets the serial number that will be returned bygetSimSerialNumber()
.void
setSimState(int simState)
Sets the sim state of slot 0.void
setSimState(int slotIndex, int state)
Set the sim state for the givenslotIndex
.void
setSubscriberId(String subscriberId)
Sets the value to be returned bygetSubscriberId()
.void
setTelephonyDisplayInfo(Object telephonyDisplayInfo)
Sets the currentTelephonyDisplayInfo
, and notifies all thePhoneStateListener
s that were registered with thePhoneStateListener.LISTEN_DISPLAY_INFO_CHANGED
flag.void
setTelephonyManagerForHandle(PhoneAccountHandle handle, TelephonyManager telephonyManager)
Sets the value returned byTelephonyManager.createForPhoneAccountHandle(PhoneAccountHandle)
.void
setTelephonyManagerForSubscriptionId(int subscriptionId, TelephonyManager telephonyManager)
Sets the value returned byTelephonyManager.createForSubscriptionId(int)
.void
setUiccSlotsInfo(Object uiccSlotsInfos)
Sets the UICC slots information returned bygetUiccSlotsInfo()
.void
setVisualVoicemailPackageName(String visualVoicemailPackageName)
Sets the value to be returned bygetVisualVoicemailPackageName()
.void
setVoiceCapable(boolean voiceCapable)
Sets the value returned byisVoiceCapable()
.void
setVoiceMailAlphaTag(String voiceMailAlphaTag)
Sets the value returned byTelephonyManager.getVoiceMailAlphaTag()
.void
setVoiceMailNumber(String voiceMailNumber)
Sets the value returned byTelephonyManager.getVoiceMailNumber()
.protected void
setVoicemailRingtoneUri(PhoneAccountHandle handle, Uri uri)
Sets the value returned byTelephonyManager.getVoicemailRingtoneUri(PhoneAccountHandle)
.protected void
setVoicemailVibrationEnabled(PhoneAccountHandle handle, boolean isEnabled)
Sets the value returned byTelephonyManager.isVoicemailVibrationEnabled(PhoneAccountHandle)
.void
setVoiceNetworkType(int voiceNetworkType)
Sets the value to be returned by calls togetVoiceNetworkType()
.
-
Field Details
-
Constructor Details
-
ShadowTelephonyManager
public ShadowTelephonyManager()
-
-
Method Details
-
listen
-
getListener
Deprecated.Avoid using.Returns the most recent listener passed to #listen().- Returns:
- Phone state listener.
-
getEventFlags
Deprecated.Avoid using.Returns the most recent flags passed to #listen().- Returns:
- Event flags.
-
getCallState
Call state may be specified viasetCallState(int)
. -
setCallState
public void setCallState(int callState)Sets the current call state to the desired state and updates any listeners. -
setCallState
Sets the current call state with the option to specify an incoming phone number for the CALL_STATE_RINGING state. The incoming phone number will be ignored for all other cases. -
getDataState
Data state may be specified viasetDataState(int)
. If no override is set, this defaults toTelephonyManager.DATA_DISCONNECTED
. -
setDataState
public void setDataState(int dataState)Sets the data state returned bygetDataState()
. -
getDeviceId
-
setDeviceId
-
setNetworkOperatorName
-
getImei
-
getImei
-
setImei
Set the IMEI returned by getImei(). -
setImei
Set the IMEI returned bygetImei(int)
. -
getMeid
-
getMeid
-
setMeid
Set the MEID returned by getMeid(). -
setMeid
Set the MEID returned bygetMeid(int)
. -
getNetworkOperatorName
-
setNetworkCountryIso
-
getNetworkCountryIso
-
setSimLocale
Sets the sim locale returned bygetSimLocale()
. -
getSimLocale
Returns sim locale set bysetSimLocale(java.util.Locale)
. -
setNetworkOperator
-
getNetworkOperator
-
getSimOperator
-
setSimOperator
-
getSimOperatorName
-
setSimOperatorName
-
getSimSerialNumber
-
setSimSerialNumber
sets the serial number that will be returned bygetSimSerialNumber()
. -
getSimCountryIso
-
getSimCountryIso
-
setSimCountryIso
-
setSimCountryIso
Sets thesimCountryIso
for the givensubId
. -
resetSimCountryIsos
public void resetSimCountryIsos()ClearssubId
to simCountryIso mapping and resets to default state. -
getSimState
-
setSimState
public void setSimState(int simState)Sets the sim state of slot 0. -
setSimState
public void setSimState(int slotIndex, int state)Set the sim state for the givenslotIndex
. -
getSimState
-
setUiccSlotsInfo
Sets the UICC slots information returned bygetUiccSlotsInfo()
. -
getUiccSlotsInfo
Returns the UICC slots information set bysetUiccSlotsInfo(java.lang.Object)
. -
resetSimStates
public void resetSimStates()ClearsslotIndex
to state mapping and resets to default state. -
setReadPhoneStatePermission
public void setReadPhoneStatePermission(boolean readPhoneStatePermission) -
getPhoneType
-
setPhoneType
public void setPhoneType(int phoneType) -
getLine1Number
-
setLine1Number
-
getNetworkType
-
setNetworkType
Deprecated.TelephonyManager.getNetworkType()
was replaced withTelephonyManager.getDataNetworkType()
in Android N, and has been deprecated in Android R. Useinstead
. -
getDataNetworkType
Returns whatever value was set by the last call tosetDataNetworkType(int)
, defaulting toTelephonyManager.NETWORK_TYPE_UNKNOWN
if it was never called. -
setDataNetworkType
public void setDataNetworkType(int dataNetworkType)Sets the value to be returned by calls togetDataNetworkType()
. This should correspond to one of theNETWORK_TYPE_*
constants defined onTelephonyManager
, but this is not enforced. -
getVoiceNetworkType
Returns whatever value was set by the last call tosetVoiceNetworkType(int)
, defaulting toTelephonyManager.NETWORK_TYPE_UNKNOWN
if it was never called. -
setVoiceNetworkType
public void setVoiceNetworkType(int voiceNetworkType)Sets the value to be returned by calls togetVoiceNetworkType()
. This should correspond to one of theNETWORK_TYPE_*
constants defined onTelephonyManager
, but this is not enforced. -
getAllCellInfo
-
setAllCellInfo
-
requestCellInfoUpdate
@Implementation(minSdk=29) protected void requestCellInfoUpdate(Object cellInfoExecutor, Object cellInfoCallback)Returns the value set bysetCallbackCellInfos(java.util.List<android.telephony.CellInfo>)
, defaulting to calling the realTelephonyManager.NETWORK_TYPE_UNKNOWN
if it was never called. -
setCallbackCellInfos
Sets the value to be returned by calls torequestCellInfoUpdate(java.lang.Object,java.lang.Object)
. Note that it does not set the value to be returned by calls togetAllCellInfo()
; for that, seesetAllCellInfo(java.util.List<android.telephony.CellInfo>)
. -
setRequestCellInfoUpdateErrorValues
Sets the values to be returned by a presumed error condition inrequestCellInfoUpdate(java.lang.Object,java.lang.Object)
. These values will persist until cleared: to clear, set (0, null) using this method. -
getCellLocation
-
setCellLocation
-
getGroupIdLevel1
-
setGroupIdLevel1
-
initListener
-
getListenersForFlags
-
isSmsCapable
- Returns:
- true by default, or the value specified via
setIsSmsCapable(boolean)
-
setIsSmsCapable
public void setIsSmsCapable(boolean isSmsCapable)Sets the value returned byTelephonyManager.isSmsCapable()
. -
getCarrierConfig
Returns a new emptyPersistableBundle
by default, or the value specified viasetCarrierConfig(PersistableBundle)
. -
setCarrierConfig
Sets the value returned byTelephonyManager.getCarrierConfig()
.- Parameters:
carrierConfig
-
-
getVoiceMailNumber
Returnsnull
by default, or the value specified viasetVoiceMailNumber(String)
. -
setVoiceMailNumber
Sets the value returned byTelephonyManager.getVoiceMailNumber()
. -
getVoiceMailAlphaTag
Returnsnull
by default or the value specified viasetVoiceMailAlphaTag(String)
. -
setVoiceMailAlphaTag
Sets the value returned byTelephonyManager.getVoiceMailAlphaTag()
. -
getPhoneCount
Returns 1 by default or the value specified viasetPhoneCount(int)
. -
setPhoneCount
public void setPhoneCount(int phoneCount)Sets the value returned byTelephonyManager.getPhoneCount()
. -
getDeviceId
Returnsnull
by default or the value specified viasetDeviceId(int, String)
. -
setDeviceId
Sets the value returned byTelephonyManager.getDeviceId(int)
. -
isVoiceCapable
Returnstrue
by default or the value specified viasetVoiceCapable(boolean)
. -
setVoiceCapable
public void setVoiceCapable(boolean voiceCapable)Sets the value returned byisVoiceCapable()
. -
isVoicemailVibrationEnabled
@Implementation(minSdk=24) protected boolean isVoicemailVibrationEnabled(PhoneAccountHandle handle)Returnsnull
by default or the value specified viasetVoicemailVibrationEnabled(PhoneAccountHandle, boolean)
. -
setVoicemailVibrationEnabled
@Implementation(minSdk=26) protected void setVoicemailVibrationEnabled(PhoneAccountHandle handle, boolean isEnabled)Sets the value returned byTelephonyManager.isVoicemailVibrationEnabled(PhoneAccountHandle)
. -
getVoicemailRingtoneUri
Returnsnull
by default or the value specified viasetVoicemailRingtoneUri(PhoneAccountHandle, Uri)
. -
setVoicemailRingtoneUri
@Implementation(minSdk=26) protected void setVoicemailRingtoneUri(PhoneAccountHandle handle, Uri uri)Sets the value returned byTelephonyManager.getVoicemailRingtoneUri(PhoneAccountHandle)
. -
createForPhoneAccountHandle
@Implementation(minSdk=26) protected TelephonyManager createForPhoneAccountHandle(PhoneAccountHandle handle)Returnsnull
by default or the value specified viasetTelephonyManagerForHandle(PhoneAccountHandle, TelephonyManager)
. -
setTelephonyManagerForHandle
public void setTelephonyManagerForHandle(PhoneAccountHandle handle, TelephonyManager telephonyManager)Sets the value returned byTelephonyManager.createForPhoneAccountHandle(PhoneAccountHandle)
. -
createForSubscriptionId
Returnsnull
by default or the value specified viasetTelephonyManagerForSubscriptionId(int, TelephonyManager)
-
setTelephonyManagerForSubscriptionId
public void setTelephonyManagerForSubscriptionId(int subscriptionId, TelephonyManager telephonyManager)Sets the value returned byTelephonyManager.createForSubscriptionId(int)
. -
getServiceState
Returnsnull
by default or the value specified viasetServiceState(ServiceState)
-
setServiceState
Sets the value returned byTelephonyManager.getServiceState()
. -
isNetworkRoaming
Returnsfalse
by default or the value specified viasetIsNetworkRoaming(boolean)
-
setIsNetworkRoaming
public void setIsNetworkRoaming(boolean isNetworkRoaming)Sets the value returned byTelephonyManager.isNetworkRoaming()
. -
getCurrentPhoneType
-
setCurrentPhoneType
public void setCurrentPhoneType(int subId, int phoneType)Sets the phone type for the givensubId
. -
clearPhoneTypes
public void clearPhoneTypes()Removes allsubId
tophoneType
mappings. -
getCarrierPackageNamesForIntentAndPhone
@Implementation(minSdk=23) @HiddenApi protected List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) -
getCarrierPackageNamesForIntent
@Implementation(minSdk=21) @HiddenApi protected List<String> getCarrierPackageNamesForIntent(Intent intent) -
setCarrierPackageNamesForPhone
Sets thepackages
for the givenphoneId
. -
getCarrierIdFromSimMccMnc
-
setCarrierIdFromSimMccMnc
public void setCarrierIdFromSimMccMnc(int carrierIdFromSimMccMnc)Sets the value to be returned bygetCarrierIdFromSimMccMnc()
. -
getSimCarrierId
-
setSimCarrierId
public void setSimCarrierId(int simCarrierId)Sets the value to be returned bygetSimCarrierId()
. -
getSubscriberId
-
setSubscriberId
Sets the value to be returned bygetSubscriberId()
. -
getVisualVoicemailPackageName
Returns the value set bysetVisualVoicemailPackageName(String)
. -
setVisualVoicemailPackageName
Sets the value to be returned bygetVisualVoicemailPackageName()
. -
getSignalStrength
-
setSignalStrength
Sets the value to be returned bygetSignalStrength()
-
isEmergencyNumber
Cribbed fromPhoneNumberUtils.isEmergencyNumberInternal(java.lang.String, boolean)
. TODO(b/122324733) need better implementation -
isPotentialEmergencyNumber
-
isDataEnabled
Implementation forTelephonyManager.isDataEnabled()
.- Returns:
- False by default, unless set with
TelephonyManager.setDataEnabled(boolean)
.
-
setDataEnabled
Implementation forTelephonyManager.setDataEnabled(boolean)
. Marked as public in order to allow it to be used as a test API. -
isRttSupported
Implementation forTelephonyManager.isRttSupported()
.- Returns:
- False by default, unless set with
setRttSupported(boolean)
.
-
setRttSupported
public void setRttSupported(boolean isRttSupported)Sets the value to be returned byisRttSupported()
-
sendDialerSpecialCode
Implementation forTelephonyManager.sendDialerSpecialCode(String)
.- Parameters:
inputCode
- special code to be sent.
-
getSentDialerSpecialCodes
Returns immutable list of special codes sent usingTelephonyManager.sendDialerSpecialCode(String)
. Special codes contained in the list are in the order they were sent. -
setHearingAidCompatibilitySupported
public void setHearingAidCompatibilitySupported(boolean isSupported)Sets the value to be returned byisHearingAidCompatibilitySupported()
. -
isHearingAidCompatibilitySupported
Implementation forTelephonyManager.isHearingAidCompatibilitySupported()
.- Returns:
- False by default, unless set with
setHearingAidCompatibilitySupported(boolean)
.
-
createTelephonyDisplayInfo
Creates aTelephonyDisplayInfo
.- Parameters:
networkType
- The packet-switching cellular network type (seeAnnotation.NetworkType
)overrideNetworkType
- The override network type (seeAnnotation.OverrideNetworkType
)
-
setTelephonyDisplayInfo
Sets the currentTelephonyDisplayInfo
, and notifies all thePhoneStateListener
s that were registered with thePhoneStateListener.LISTEN_DISPLAY_INFO_CHANGED
flag.- Parameters:
telephonyDisplayInfo
- TheTelephonyDisplayInfo
to set. May not be null.- Throws:
NullPointerException
- if telephonyDisplayInfo is null.
-
isDataConnectionAllowed
-
setIsDataConnectionAllowed
public void setIsDataConnectionAllowed(boolean isDataConnectionAllowed)
-