Package org.robolectric.shadows
Class ShadowSubscriptionManager
java.lang.Object
org.robolectric.shadows.ShadowSubscriptionManager
@Implements(value=android.telephony.SubscriptionManager.class,
minSdk=22)
public class ShadowSubscriptionManager
extends Object
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Builder class to create instance ofSubscriptionInfo
. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
Adds a listener to a local list of listeners.protected void
addOnSubscriptionsChangedListener
(Executor executor, SubscriptionManager.OnSubscriptionsChangedListener listener) Adds a listener to a local list of listeners.void
Clears the local cache of roaming subscription Ids used byisNetworkRoaming(int)
.static void
Removes all mappings between subscription IDs and phone IDs from the map used bygetPhoneId(int)
.protected static int
Returns value set withsetActiveDataSubscriptionId(int)
.protected int[]
Returns subscription Ids that were set viasetActiveSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>)
.protected SubscriptionInfo
getActiveSubscriptionInfo
(int subId) Returns subscription that were set viasetActiveSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>)
if it can find one with the specified id or null if none found.protected int
Returns the size of the list ofSubscriptionInfo
that were set viasetActiveSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>)
.protected int
protected SubscriptionInfo
getActiveSubscriptionInfoForSimSlotIndex
(int slotIndex) Returns subscription that were set viasetActiveSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>)
if it can find one with the specified slot index or null if none found.protected List<SubscriptionInfo>
Returns the active list ofSubscriptionInfo
that were set viasetActiveSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>)
.protected List<SubscriptionInfo>
Returns the available list ofSubscriptionInfo
that were set viasetAvailableSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>)
.protected static int
protected static int
Returns value set withsetDefaultDataSubscriptionId(int)
.protected static int
protected static int
Returns value set withsetDefaultSmsSubscriptionId(int)
.protected static int
protected static int
Returns value set withsetDefaultSubscriptionId(int)
.protected static int
protected static int
Returns value set withsetDefaultVoiceSubscriptionId(int)
.protected static int
getPhoneId
(int subId) Uses the map of subscription IDs to phone IDs managed byputPhoneId(int,int)
andremovePhoneId(int)
to return the phone ID for a given subscription ID.protected String
getPhoneNumber
(int subscriptionId) Returns the phone number for the givensubscriptionId
, or an empty string if not available.protected String
getPhoneNumber
(int subscriptionId, int source) Returns the phone number for the givensubscriptionId
, or an empty string if not available.boolean
Check if a listener exists in theShadowSubscriptionManager.listeners
.protected boolean
isNetworkRoaming
(int simSubscriptionId) Uses the local cache of roaming sim subscription Ids managed bysetNetworkRoamingStatus(int, boolean)
to return subscription Ids marked as roaming.static void
putPhoneId
(int subId, int phoneId) Adds a subscription ID-phone ID mapping to the map used bygetPhoneId(int)
.protected void
Removes a listener from a local list of listeners.static Integer
removePhoneId
(int subId) Removes a subscription ID-phone ID mapping from the map used bygetPhoneId(int)
.static void
reset()
static void
setActiveDataSubscriptionId
(int activeDataSubscriptionId) Sets the value that will be returned bygetActiveDataSubscriptionId()
.void
Sets the active list ofSubscriptionInfo
.void
setActiveSubscriptionInfos
(SubscriptionInfo... infos) Sets the active list ofSubscriptionInfo
.void
Sets the active list ofSubscriptionInfo
.void
Sets the active list ofSubscriptionInfo
.static void
setDefaultDataSubscriptionId
(int defaultDataSubscriptionId) static void
setDefaultSmsSubscriptionId
(int defaultSmsSubscriptionId) static void
setDefaultSubscriptionId
(int defaultSubscriptionId) Sets the value that will be returned bygetDefaultSubscriptionId()
.static void
setDefaultVoiceSubscriptionId
(int defaultVoiceSubscriptionId) void
setNetworkRoamingStatus
(int simSubscriptionId, boolean isNetworkRoaming) If isNetworkRoaming is set, it will mark the provided sim subscriptionId as roaming in a local cache.void
setPhoneNumber
(int subscriptionId, String phoneNumber) Sets the phone number returned bygetPhoneNumber(int)
.void
setReadPhoneNumbersPermission
(boolean readPhoneNumbersPermission) When set to false methods requiringandroid.Manifest.permission.READ_PHONE_NUMBERS
permission will throw aSecurityException
.void
setReadPhoneStatePermission
(boolean readPhoneStatePermission) When set to false methods requiringandroid.Manifest.permission.READ_PHONE_STATE
permission will throw aSecurityException
.
-
Field Details
-
INVALID_PHONE_INDEX
public static final int INVALID_PHONE_INDEX
-
-
Constructor Details
-
ShadowSubscriptionManager
public ShadowSubscriptionManager()
-
-
Method Details
-
getActiveDataSubscriptionId
Returns value set withsetActiveDataSubscriptionId(int)
. -
getDefaultSubscriptionId
Returns value set withsetDefaultSubscriptionId(int)
. -
getDefaultDataSubscriptionId
Returns value set withsetDefaultDataSubscriptionId(int)
. -
getDefaultSmsSubscriptionId
Returns value set withsetDefaultSmsSubscriptionId(int)
. -
getDefaultVoiceSubscriptionId
Returns value set withsetDefaultVoiceSubscriptionId(int)
. -
getDefaultSubId
-
getDefaultVoiceSubId
-
getDefaultSmsSubId
-
getDefaultDataSubId
-
setActiveDataSubscriptionId
public static void setActiveDataSubscriptionId(int activeDataSubscriptionId) Sets the value that will be returned bygetActiveDataSubscriptionId()
. -
setDefaultSubscriptionId
public static void setDefaultSubscriptionId(int defaultSubscriptionId) Sets the value that will be returned bygetDefaultSubscriptionId()
. -
setDefaultDataSubscriptionId
public static void setDefaultDataSubscriptionId(int defaultDataSubscriptionId) -
setDefaultSmsSubscriptionId
public static void setDefaultSmsSubscriptionId(int defaultSmsSubscriptionId) -
setDefaultVoiceSubscriptionId
public static void setDefaultVoiceSubscriptionId(int defaultVoiceSubscriptionId) -
getActiveSubscriptionInfoList
Returns the active list ofSubscriptionInfo
that were set viasetActiveSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>)
. -
getAvailableSubscriptionInfoList
Returns the available list ofSubscriptionInfo
that were set viasetAvailableSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>)
. -
getActiveSubscriptionInfoCount
Returns the size of the list ofSubscriptionInfo
that were set viasetActiveSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>)
. If no list was set, returns 0. -
getActiveSubscriptionInfo
Returns subscription that were set viasetActiveSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>)
if it can find one with the specified id or null if none found.An exception will be thrown if the READ_PHONE_STATE permission has not been granted.
-
getActiveSubscriptionInfoCountMax
- Returns:
- the maximum number of active subscriptions that will be returned by
getActiveSubscriptionInfoList()
and the value returned bygetActiveSubscriptionInfoCount()
.
-
getActiveSubscriptionInfoForSimSlotIndex
@Implementation(minSdk=24) protected SubscriptionInfo getActiveSubscriptionInfoForSimSlotIndex(int slotIndex) Returns subscription that were set viasetActiveSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>)
if it can find one with the specified slot index or null if none found. -
setActiveSubscriptionInfoList
Sets the active list ofSubscriptionInfo
. This call internally triggersSubscriptionManager.OnSubscriptionsChangedListener.onSubscriptionsChanged()
to all the listeners.- Parameters:
list
- - The subscription info list, can be null.
-
setAvailableSubscriptionInfoList
Sets the active list ofSubscriptionInfo
. This call internally triggersSubscriptionManager.OnSubscriptionsChangedListener.onSubscriptionsChanged()
to all the listeners.- Parameters:
list
- - The subscription info list, can be null.
-
setActiveSubscriptionInfos
Sets the active list ofSubscriptionInfo
. This call internally triggersSubscriptionManager.OnSubscriptionsChangedListener.onSubscriptionsChanged()
to all the listeners. -
setAvailableSubscriptionInfos
Sets the active list ofSubscriptionInfo
. This call internally triggersSubscriptionManager.OnSubscriptionsChangedListener.onSubscriptionsChanged()
to all the listeners. -
addOnSubscriptionsChangedListener
@Implementation(minSdk=22) protected void addOnSubscriptionsChangedListener(SubscriptionManager.OnSubscriptionsChangedListener listener) Adds a listener to a local list of listeners. Will be triggered bysetActiveSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>)
when the local list ofSubscriptionInfo
is updated. -
addOnSubscriptionsChangedListener
@Implementation(minSdk=30) protected void addOnSubscriptionsChangedListener(Executor executor, SubscriptionManager.OnSubscriptionsChangedListener listener) Adds a listener to a local list of listeners. Will be triggered bysetActiveSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>)
when the local list ofSubscriptionInfo
is updated. -
removeOnSubscriptionsChangedListener
@Implementation(minSdk=22) protected void removeOnSubscriptionsChangedListener(SubscriptionManager.OnSubscriptionsChangedListener listener) Removes a listener from a local list of listeners. Will be triggered bysetActiveSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>)
when the local list ofSubscriptionInfo
is updated. -
hasOnSubscriptionsChangedListener
public boolean hasOnSubscriptionsChangedListener(SubscriptionManager.OnSubscriptionsChangedListener listener) Check if a listener exists in theShadowSubscriptionManager.listeners
.- Parameters:
listener
- The listener to check.- Returns:
- boolean True if the listener already added, otherwise false.
-
getActiveSubscriptionIdList
Returns subscription Ids that were set viasetActiveSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>)
. -
clearNetworkRoamingStatus
public void clearNetworkRoamingStatus()Clears the local cache of roaming subscription Ids used byisNetworkRoaming(int)
. -
setNetworkRoamingStatus
public void setNetworkRoamingStatus(int simSubscriptionId, boolean isNetworkRoaming) If isNetworkRoaming is set, it will mark the provided sim subscriptionId as roaming in a local cache. If isNetworkRoaming is unset it will remove the subscriptionId from the local cache. The local cache is used to provide roaming status returned byisNetworkRoaming(int)
. -
isNetworkRoaming
Uses the local cache of roaming sim subscription Ids managed bysetNetworkRoamingStatus(int, boolean)
to return subscription Ids marked as roaming. Otherwise subscription Ids will be considered as non-roaming if they are not in the cache. -
putPhoneId
public static void putPhoneId(int subId, int phoneId) Adds a subscription ID-phone ID mapping to the map used bygetPhoneId(int)
. -
removePhoneId
Removes a subscription ID-phone ID mapping from the map used bygetPhoneId(int)
.- Returns:
- the previous phone ID associated with the subscription ID, or null if there was no mapping for the subscription ID
-
clearPhoneIds
public static void clearPhoneIds()Removes all mappings between subscription IDs and phone IDs from the map used bygetPhoneId(int)
. -
getPhoneId
Uses the map of subscription IDs to phone IDs managed byputPhoneId(int,int)
andremovePhoneId(int)
to return the phone ID for a given subscription ID. -
setReadPhoneStatePermission
public void setReadPhoneStatePermission(boolean readPhoneStatePermission) When set to false methods requiringandroid.Manifest.permission.READ_PHONE_STATE
permission will throw aSecurityException
. By default it's set to true for backwards compatibility. -
setReadPhoneNumbersPermission
public void setReadPhoneNumbersPermission(boolean readPhoneNumbersPermission) When set to false methods requiringandroid.Manifest.permission.READ_PHONE_NUMBERS
permission will throw aSecurityException
. By default it's set to true for backwards compatibility. -
getPhoneNumber
Returns the phone number for the givensubscriptionId
, or an empty string if not available.The phone number can be set by
setPhoneNumber(int, String)
An exception will be thrown if the READ_PHONE_NUMBERS permission has not been granted.
-
getPhoneNumber
Returns the phone number for the givensubscriptionId
, or an empty string if not available.source
is ignored and will return the same asgetPhoneNumber(int)
.The phone number can be set by
setPhoneNumber(int, String)
-
setPhoneNumber
Sets the phone number returned bygetPhoneNumber(int)
. -
reset
-