Class ShadowTelephonyManager


  • @Implements(value=android.telephony.TelephonyManager.class,
                looseSignatures=true)
    public class ShadowTelephonyManager
    extends java.lang.Object
    • Field Detail

      • realTelephonyManager

        @RealObject
        protected android.telephony.TelephonyManager realTelephonyManager
    • Constructor Detail

      • ShadowTelephonyManager

        public ShadowTelephonyManager()
    • Method Detail

      • listen

        @Implementation
        protected void listen​(android.telephony.PhoneStateListener listener,
                              int flags)
      • getListener

        @Deprecated
        public android.telephony.PhoneStateListener getListener()
        Deprecated.
        Avoid using.
        Returns the most recent listener passed to #listen().
        Returns:
        Phone state listener.
      • getEventFlags

        @Deprecated
        public int getEventFlags()
        Deprecated.
        Avoid using.
        Returns the most recent flags passed to #listen().
        Returns:
        Event flags.
      • getCallState

        @Implementation
        protected int getCallState()
        Call state may be specified via setCallState(int).
      • setCallState

        public void setCallState​(int callState)
        Sets the current call state to the desired state and updates any listeners.
      • setCallState

        public void setCallState​(int callState,
                                 java.lang.String incomingPhoneNumber)
        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

        @Implementation
        protected int getDataState()
        Data state may be specified via setDataState(int). If no override is set, this defaults to TelephonyManager.DATA_DISCONNECTED.
      • setDataState

        public void setDataState​(int dataState)
        Sets the data state returned by getDataState().
      • getDeviceId

        @Implementation
        protected java.lang.String getDeviceId()
      • setDeviceId

        public void setDeviceId​(java.lang.String newDeviceId)
      • setNetworkOperatorName

        public void setNetworkOperatorName​(java.lang.String networkOperatorName)
      • getImei

        @Implementation(minSdk=21)
        protected java.lang.String getImei()
      • getImei

        @Implementation(minSdk=26)
        protected java.lang.String getImei​(int slotIndex)
      • setImei

        public void setImei​(java.lang.String imei)
        Set the IMEI returned by getImei().
      • setImei

        public void setImei​(int slotIndex,
                            java.lang.String imei)
        Set the IMEI returned by getImei(int).
      • getMeid

        @Implementation(minSdk=26)
        protected java.lang.String getMeid()
      • getMeid

        @Implementation(minSdk=26)
        protected java.lang.String getMeid​(int slotIndex)
      • setMeid

        public void setMeid​(java.lang.String meid)
        Set the MEID returned by getMeid().
      • setMeid

        public void setMeid​(int slotIndex,
                            java.lang.String meid)
        Set the MEID returned by getMeid(int).
      • getNetworkOperatorName

        @Implementation
        protected java.lang.String getNetworkOperatorName()
      • setNetworkCountryIso

        public void setNetworkCountryIso​(java.lang.String networkCountryIso)
      • getNetworkCountryIso

        @Implementation
        protected java.lang.String getNetworkCountryIso()
      • setSimLocale

        public void setSimLocale​(java.util.Locale simLocale)
        Sets the sim locale returned by getSimLocale().
      • setNetworkOperator

        public void setNetworkOperator​(java.lang.String networkOperator)
      • getNetworkOperator

        @Implementation
        protected java.lang.String getNetworkOperator()
      • getSimOperator

        @Implementation
        protected java.lang.String getSimOperator()
      • setSimOperator

        public void setSimOperator​(java.lang.String simOperator)
      • getSimOperatorName

        @Implementation
        protected java.lang.String getSimOperatorName()
      • setSimOperatorName

        public void setSimOperatorName​(java.lang.String simOperatorName)
      • getSimSerialNumber

        @Implementation
        protected java.lang.String getSimSerialNumber()
      • setSimSerialNumber

        public void setSimSerialNumber​(java.lang.String simSerialNumber)
        sets the serial number that will be returned by getSimSerialNumber().
      • getSimCountryIso

        @Implementation
        protected java.lang.String getSimCountryIso()
      • getSimCountryIso

        @Implementation(minSdk=24)
        @HiddenApi
        protected java.lang.String getSimCountryIso​(int subId)
      • setSimCountryIso

        public void setSimCountryIso​(java.lang.String simCountryIso)
      • setSimCountryIso

        public void setSimCountryIso​(int subId,
                                     java.lang.String simCountryIso)
        Sets the simCountryIso for the given subId.
      • resetSimCountryIsos

        public void resetSimCountryIsos()
        Clears subId to simCountryIso mapping and resets to default state.
      • getSimState

        @Implementation
        protected int 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 given slotIndex.
      • getSimState

        @Implementation(minSdk=26)
        protected int getSimState​(int slotIndex)
      • setUiccSlotsInfo

        public void setUiccSlotsInfo​(java.lang.Object uiccSlotsInfos)
        Sets the UICC slots information returned by getUiccSlotsInfo().
      • getUiccSlotsInfo

        @Implementation(minSdk=28)
        @HiddenApi
        protected java.lang.Object getUiccSlotsInfo()
        Returns the UICC slots information set by setUiccSlotsInfo(java.lang.Object).
      • resetSimStates

        public void resetSimStates()
        Clears slotIndex to state mapping and resets to default state.
      • setReadPhoneStatePermission

        public void setReadPhoneStatePermission​(boolean readPhoneStatePermission)
      • getPhoneType

        @Implementation
        protected int getPhoneType()
      • setPhoneType

        public void setPhoneType​(int phoneType)
      • getLine1Number

        @Implementation
        protected java.lang.String getLine1Number()
      • setLine1Number

        public void setLine1Number​(java.lang.String line1Number)
      • getNetworkType

        @Implementation
        protected int getNetworkType()
      • setNetworkType

        @Deprecated
        public void setNetworkType​(int networkType)
        Deprecated.
        TelephonyManager.getNetworkType() was replaced with TelephonyManager.getDataNetworkType() in Android N, and has been deprecated in Android R. Use instead.
      • getDataNetworkType

        @Implementation(minSdk=24)
        protected int getDataNetworkType()
        Returns whatever value was set by the last call to setDataNetworkType(int), defaulting to TelephonyManager.NETWORK_TYPE_UNKNOWN if it was never called.
      • setDataNetworkType

        public void setDataNetworkType​(int dataNetworkType)
        Sets the value to be returned by calls to getDataNetworkType(). This should correspond to one of the NETWORK_TYPE_* constants defined on TelephonyManager, but this is not enforced.
      • getVoiceNetworkType

        @Implementation(minSdk=24)
        protected int getVoiceNetworkType()
        Returns whatever value was set by the last call to setVoiceNetworkType(int), defaulting to TelephonyManager.NETWORK_TYPE_UNKNOWN if it was never called.
      • setVoiceNetworkType

        public void setVoiceNetworkType​(int voiceNetworkType)
        Sets the value to be returned by calls to getVoiceNetworkType(). This should correspond to one of the NETWORK_TYPE_* constants defined on TelephonyManager, but this is not enforced.
      • getAllCellInfo

        @Implementation(minSdk=17)
        protected java.util.List<android.telephony.CellInfo> getAllCellInfo()
      • setAllCellInfo

        public void setAllCellInfo​(java.util.List<android.telephony.CellInfo> allCellInfo)
      • requestCellInfoUpdate

        @Implementation(minSdk=29)
        protected void requestCellInfoUpdate​(java.lang.Object cellInfoExecutor,
                                             java.lang.Object cellInfoCallback)
        Returns the value set by setCallbackCellInfos(java.util.List<android.telephony.CellInfo>), defaulting to calling the real TelephonyManager.NETWORK_TYPE_UNKNOWN if it was never called.
      • setRequestCellInfoUpdateErrorValues

        public void setRequestCellInfoUpdateErrorValues​(int errorCode,
                                                        java.lang.Throwable detail)
        Sets the values to be returned by a presumed error condition in requestCellInfoUpdate(java.lang.Object,java.lang.Object). These values will persist until cleared: to clear, set (0, null) using this method.
      • getCellLocation

        @Implementation
        protected android.telephony.CellLocation getCellLocation()
      • setCellLocation

        public void setCellLocation​(android.telephony.CellLocation cellLocation)
      • getGroupIdLevel1

        @Implementation(minSdk=18)
        protected java.lang.String getGroupIdLevel1()
      • setGroupIdLevel1

        public void setGroupIdLevel1​(java.lang.String groupIdLevel1)
      • initListener

        protected void initListener​(android.telephony.PhoneStateListener listener,
                                    int flags)
      • getListenersForFlags

        protected java.lang.Iterable<android.telephony.PhoneStateListener> getListenersForFlags​(int flags)
      • isSmsCapable

        @Implementation
        protected boolean isSmsCapable()
        Returns:
        true by default, or the value specified via setIsSmsCapable(boolean)
      • setIsSmsCapable

        public void setIsSmsCapable​(boolean isSmsCapable)
        Sets the value returned by TelephonyManager.isSmsCapable().
      • getCarrierConfig

        @Implementation(minSdk=26)
        protected android.os.PersistableBundle getCarrierConfig()
        Returns a new empty PersistableBundle by default, or the value specified via setCarrierConfig(PersistableBundle).
      • setCarrierConfig

        public void setCarrierConfig​(android.os.PersistableBundle carrierConfig)
        Sets the value returned by TelephonyManager.getCarrierConfig().
        Parameters:
        carrierConfig -
      • getVoiceMailNumber

        @Implementation
        protected java.lang.String getVoiceMailNumber()
        Returns null by default, or the value specified via setVoiceMailNumber(String).
      • setVoiceMailNumber

        public void setVoiceMailNumber​(java.lang.String voiceMailNumber)
        Sets the value returned by TelephonyManager.getVoiceMailNumber().
      • getVoiceMailAlphaTag

        @Implementation
        protected java.lang.String getVoiceMailAlphaTag()
        Returns null by default or the value specified via setVoiceMailAlphaTag(String).
      • setVoiceMailAlphaTag

        public void setVoiceMailAlphaTag​(java.lang.String voiceMailAlphaTag)
        Sets the value returned by TelephonyManager.getVoiceMailAlphaTag().
      • getPhoneCount

        @Implementation(minSdk=23)
        protected int getPhoneCount()
        Returns 1 by default or the value specified via setPhoneCount(int).
      • setPhoneCount

        public void setPhoneCount​(int phoneCount)
        Sets the value returned by TelephonyManager.getPhoneCount().
      • getDeviceId

        @Implementation(minSdk=23)
        protected java.lang.String getDeviceId​(int slot)
        Returns null by default or the value specified via setDeviceId(int, String).
      • setDeviceId

        public void setDeviceId​(int slot,
                                java.lang.String deviceId)
        Sets the value returned by TelephonyManager.getDeviceId(int).
      • isVoiceCapable

        @Implementation(minSdk=22)
        protected boolean isVoiceCapable()
        Returns true by default or the value specified via setVoiceCapable(boolean).
      • setVoiceCapable

        public void setVoiceCapable​(boolean voiceCapable)
        Sets the value returned by isVoiceCapable().
      • setVoicemailVibrationEnabled

        @Implementation(minSdk=26)
        protected void setVoicemailVibrationEnabled​(android.telecom.PhoneAccountHandle handle,
                                                    boolean isEnabled)
        Sets the value returned by TelephonyManager.isVoicemailVibrationEnabled(PhoneAccountHandle).
      • getVoicemailRingtoneUri

        @Implementation(minSdk=24)
        protected android.net.Uri getVoicemailRingtoneUri​(android.telecom.PhoneAccountHandle handle)
        Returns null by default or the value specified via setVoicemailRingtoneUri(PhoneAccountHandle, Uri).
      • setVoicemailRingtoneUri

        @Implementation(minSdk=26)
        protected void setVoicemailRingtoneUri​(android.telecom.PhoneAccountHandle handle,
                                               android.net.Uri uri)
        Sets the value returned by TelephonyManager.getVoicemailRingtoneUri(PhoneAccountHandle).
      • setTelephonyManagerForHandle

        public void setTelephonyManagerForHandle​(android.telecom.PhoneAccountHandle handle,
                                                 android.telephony.TelephonyManager telephonyManager)
        Sets the value returned by TelephonyManager.createForPhoneAccountHandle(PhoneAccountHandle).
      • setTelephonyManagerForSubscriptionId

        public void setTelephonyManagerForSubscriptionId​(int subscriptionId,
                                                         android.telephony.TelephonyManager telephonyManager)
        Sets the value returned by TelephonyManager.createForSubscriptionId(int).
      • getServiceState

        @Implementation(minSdk=26)
        protected android.telephony.ServiceState getServiceState()
        Returns null by default or the value specified via setServiceState(ServiceState)
      • setServiceState

        public void setServiceState​(android.telephony.ServiceState serviceState)
        Sets the value returned by TelephonyManager.getServiceState().
      • isNetworkRoaming

        @Implementation
        protected boolean isNetworkRoaming()
        Returns false by default or the value specified via setIsNetworkRoaming(boolean)
      • setIsNetworkRoaming

        public void setIsNetworkRoaming​(boolean isNetworkRoaming)
        Sets the value returned by TelephonyManager.isNetworkRoaming().
      • getCurrentPhoneType

        @Implementation(minSdk=23)
        @HiddenApi
        protected int getCurrentPhoneType​(int subId)
      • setCurrentPhoneType

        public void setCurrentPhoneType​(int subId,
                                        int phoneType)
        Sets the phone type for the given subId.
      • clearPhoneTypes

        public void clearPhoneTypes()
        Removes all subId to phoneType mappings.
      • getCarrierPackageNamesForIntentAndPhone

        @Implementation(minSdk=23)
        @HiddenApi
        protected java.util.List<java.lang.String> getCarrierPackageNamesForIntentAndPhone​(android.content.Intent intent,
                                                                                           int phoneId)
      • getCarrierPackageNamesForIntent

        @Implementation(minSdk=21)
        @HiddenApi
        protected java.util.List<java.lang.String> getCarrierPackageNamesForIntent​(android.content.Intent intent)
      • setCarrierPackageNamesForPhone

        public void setCarrierPackageNamesForPhone​(int phoneId,
                                                   java.util.List<java.lang.String> packages)
        Sets the packages for the given phoneId.
      • getCarrierIdFromSimMccMnc

        @Implementation(minSdk=29)
        protected int getCarrierIdFromSimMccMnc()
      • setCarrierIdFromSimMccMnc

        public void setCarrierIdFromSimMccMnc​(int carrierIdFromSimMccMnc)
        Sets the value to be returned by getCarrierIdFromSimMccMnc().
      • getSimCarrierId

        @Implementation(minSdk=28)
        protected int getSimCarrierId()
      • setSimCarrierId

        public void setSimCarrierId​(int simCarrierId)
        Sets the value to be returned by getSimCarrierId().
      • getSubscriberId

        @Implementation
        protected java.lang.String getSubscriberId()
      • setSubscriberId

        public void setSubscriberId​(java.lang.String subscriberId)
        Sets the value to be returned by getSubscriberId().
      • setVisualVoicemailPackageName

        public void setVisualVoicemailPackageName​(java.lang.String visualVoicemailPackageName)
        Sets the value to be returned by getVisualVoicemailPackageName().
      • getSignalStrength

        @Implementation(minSdk=28)
        protected android.telephony.SignalStrength getSignalStrength()
      • setSignalStrength

        public void setSignalStrength​(android.telephony.SignalStrength signalStrength)
        Sets the value to be returned by getSignalStrength()
      • isEmergencyNumber

        @Implementation(minSdk=29)
        protected boolean isEmergencyNumber​(java.lang.String number)
        Cribbed from PhoneNumberUtils.isEmergencyNumberInternal(java.lang.String, boolean). TODO(b/122324733) need better implementation
      • isPotentialEmergencyNumber

        @Implementation(minSdk=29)
        protected boolean isPotentialEmergencyNumber​(java.lang.String number)
      • isDataEnabled

        @Implementation(minSdk=26)
        protected boolean isDataEnabled()
        Implementation for TelephonyManager.isDataEnabled().
        Returns:
        False by default, unless set with TelephonyManager.setDataEnabled(boolean).
      • setDataEnabled

        @Implementation(minSdk=26)
        public void setDataEnabled​(boolean enabled)
        Implementation for TelephonyManager.setDataEnabled(boolean). Marked as public in order to allow it to be used as a test API.
      • isRttSupported

        @Implementation(minSdk=29)
        protected boolean isRttSupported()
        Implementation for TelephonyManager.isRttSupported().
        Returns:
        False by default, unless set with setRttSupported(boolean).
      • setRttSupported

        public void setRttSupported​(boolean isRttSupported)
        Sets the value to be returned by isRttSupported()
      • sendDialerSpecialCode

        @Implementation(minSdk=26)
        public void sendDialerSpecialCode​(java.lang.String inputCode)
        Implementation for TelephonyManager.sendDialerSpecialCode(String).
        Parameters:
        inputCode - special code to be sent.
      • getSentDialerSpecialCodes

        public java.util.List<java.lang.String> getSentDialerSpecialCodes()
        Returns immutable list of special codes sent using TelephonyManager.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 by isHearingAidCompatibilitySupported().
      • isHearingAidCompatibilitySupported

        @Implementation(minSdk=23)
        protected boolean isHearingAidCompatibilitySupported()
        Implementation for TelephonyManager.isHearingAidCompatibilitySupported().
        Returns:
        False by default, unless set with setHearingAidCompatibilitySupported(boolean).