Class ShadowSubscriptionManager
-
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 List<SubscriptionInfo>
Returns the accessible list ofSubscriptionInfo
that were set viasetAccessibleSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>)
.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()
void
Sets the accessible list ofSubscriptionInfo
.void
Sets the accessible list ofSubscriptionInfo
.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 available list ofSubscriptionInfo
.void
Sets the available 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>)
. -
getAccessibleSubscriptionInfoList
Returns the accessible list ofSubscriptionInfo
that were set viasetAccessibleSubscriptionInfoList(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."Active" here means subscriptions which are currently mapped to a live modem stack in the device (i.e. the modem will attempt to use them to connect to nearby towers), and they are expected to have
SubscriptionInfo.getSimSlotIndex()
>= 0. A subscription being "active" in the device does NOT have any relation to a carrier's "activation" process for subscribers' SIMs.- Parameters:
list
- - The subscription info list, can be null.
-
setAccessibleSubscriptionInfoList
Sets the accessible list ofSubscriptionInfo
. This call internally triggersSubscriptionManager.OnSubscriptionsChangedListener.onSubscriptionsChanged()
to all the listeners."Accessible" here means subscriptions which are eSIM (
SubscriptionInfo.isEmbedded()
) and "owned" by the calling app, i.e. bySubscriptionManager.canManageSubscription(SubscriptionInfo)
. They may be active, or installed-but-inactive. This is generally intended to be called by carrier apps that directly manage their own eSIM profiles on the device in concert withandroid.telephony.EuiccManager
.- Parameters:
list
- - The subscription info list, can be null.
-
setAvailableSubscriptionInfoList
Sets the available list ofSubscriptionInfo
. This call internally triggersSubscriptionManager.OnSubscriptionsChangedListener.onSubscriptionsChanged()
to all the listeners."Available" here means all active subscriptions (see
setActiveSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>)
) combined with all installed-but-inactive eSIM subscriptions (similar tosetAccessibleSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>)
, but not filtered to one particular app's "ownership" rights for subscriptions). This is generally intended to be called by system components such as the eSIM LPA or Settings that allow the user to manage all subscriptions on the device through some system-provided user interface.- 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. -
setAccessibleSubscriptionInfos
Sets the accessible list ofSubscriptionInfo
. This call internally triggersSubscriptionManager.OnSubscriptionsChangedListener.onSubscriptionsChanged()
to all the listeners. -
setAvailableSubscriptionInfos
Sets the available 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
-