Class ShadowSubscriptionManager
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classBuilder class to create instance ofSubscriptionInfo.
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidAdds a listener to a local list of listeners.protected voidaddOnSubscriptionsChangedListener(Executor executor, SubscriptionManager.OnSubscriptionsChangedListener listener) Adds a listener to a local list of listeners.voidClears the local cache of roaming subscription Ids used byisNetworkRoaming(int).static voidRemoves all mappings between subscription IDs and phone IDs from the map used bygetPhoneId(int).protected List<SubscriptionInfo>Returns the accessible list ofSubscriptionInfothat were set viasetAccessibleSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>).protected static intReturns value set withsetActiveDataSubscriptionId(int).protected int[]Returns subscription Ids that were set viasetActiveSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>).protected SubscriptionInfogetActiveSubscriptionInfo(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 intReturns the size of the list ofSubscriptionInfothat were set viasetActiveSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>).protected intprotected SubscriptionInfogetActiveSubscriptionInfoForSimSlotIndex(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 ofSubscriptionInfothat were set viasetActiveSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>).protected List<SubscriptionInfo>Returns the available list ofSubscriptionInfothat were set viasetAvailableSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>).protected static intprotected static intReturns value set withsetDefaultDataSubscriptionId(int).protected static intprotected static intReturns value set withsetDefaultSmsSubscriptionId(int).protected static intprotected static intReturns value set withsetDefaultSubscriptionId(int).protected static intprotected static intReturns value set withsetDefaultVoiceSubscriptionId(int).protected static intgetPhoneId(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 StringgetPhoneNumber(int subscriptionId) Returns the phone number for the givensubscriptionId, or an empty string if not available.protected StringgetPhoneNumber(int subscriptionId, int source) Returns the phone number for the givensubscriptionId, or an empty string if not available.booleanCheck if a listener exists in theShadowSubscriptionManager.listeners.protected booleanisNetworkRoaming(int simSubscriptionId) Uses the local cache of roaming sim subscription Ids managed bysetNetworkRoamingStatus(int, boolean)to return subscription Ids marked as roaming.static voidputPhoneId(int subId, int phoneId) Adds a subscription ID-phone ID mapping to the map used bygetPhoneId(int).protected voidRemoves a listener from a local list of listeners.static IntegerremovePhoneId(int subId) Removes a subscription ID-phone ID mapping from the map used bygetPhoneId(int).static voidreset()voidSets the accessible list ofSubscriptionInfo.voidSets the accessible list ofSubscriptionInfo.static voidsetActiveDataSubscriptionId(int activeDataSubscriptionId) Sets the value that will be returned bygetActiveDataSubscriptionId().voidSets the active list ofSubscriptionInfo.voidsetActiveSubscriptionInfos(SubscriptionInfo... infos) Sets the active list ofSubscriptionInfo.voidSets the available list ofSubscriptionInfo.voidSets the available list ofSubscriptionInfo.static voidsetDefaultDataSubscriptionId(int defaultDataSubscriptionId) static voidsetDefaultSmsSubscriptionId(int defaultSmsSubscriptionId) static voidsetDefaultSubscriptionId(int defaultSubscriptionId) Sets the value that will be returned bygetDefaultSubscriptionId().static voidsetDefaultVoiceSubscriptionId(int defaultVoiceSubscriptionId) voidsetNetworkRoamingStatus(int simSubscriptionId, boolean isNetworkRoaming) If isNetworkRoaming is set, it will mark the provided sim subscriptionId as roaming in a local cache.voidsetPhoneNumber(int subscriptionId, String phoneNumber) Sets the phone number returned bygetPhoneNumber(int).voidsetReadPhoneNumbersPermission(boolean readPhoneNumbersPermission) When set to false methods requiringandroid.Manifest.permission.READ_PHONE_NUMBERSpermission will throw aSecurityException.voidsetReadPhoneStatePermission(boolean readPhoneStatePermission) When set to false methods requiringandroid.Manifest.permission.READ_PHONE_STATEpermission will throw aSecurityException.
- 
Field Details- 
INVALID_PHONE_INDEXpublic static final int INVALID_PHONE_INDEX
 
- 
- 
Constructor Details- 
ShadowSubscriptionManagerpublic ShadowSubscriptionManager()
 
- 
- 
Method Details- 
getActiveDataSubscriptionIdReturns value set withsetActiveDataSubscriptionId(int).
- 
getDefaultSubscriptionIdReturns value set withsetDefaultSubscriptionId(int).
- 
getDefaultDataSubscriptionIdReturns value set withsetDefaultDataSubscriptionId(int).
- 
getDefaultSmsSubscriptionIdReturns value set withsetDefaultSmsSubscriptionId(int).
- 
getDefaultVoiceSubscriptionIdReturns value set withsetDefaultVoiceSubscriptionId(int).
- 
getDefaultSubId
- 
getDefaultVoiceSubId
- 
getDefaultSmsSubId
- 
getDefaultDataSubId
- 
setActiveDataSubscriptionIdpublic static void setActiveDataSubscriptionId(int activeDataSubscriptionId) Sets the value that will be returned bygetActiveDataSubscriptionId().
- 
setDefaultSubscriptionIdpublic static void setDefaultSubscriptionId(int defaultSubscriptionId) Sets the value that will be returned bygetDefaultSubscriptionId().
- 
setDefaultDataSubscriptionIdpublic static void setDefaultDataSubscriptionId(int defaultDataSubscriptionId) 
- 
setDefaultSmsSubscriptionIdpublic static void setDefaultSmsSubscriptionId(int defaultSmsSubscriptionId) 
- 
setDefaultVoiceSubscriptionIdpublic static void setDefaultVoiceSubscriptionId(int defaultVoiceSubscriptionId) 
- 
getActiveSubscriptionInfoListReturns the active list ofSubscriptionInfothat were set viasetActiveSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>).
- 
getAccessibleSubscriptionInfoListReturns the accessible list ofSubscriptionInfothat were set viasetAccessibleSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>).
- 
getAvailableSubscriptionInfoListReturns the available list ofSubscriptionInfothat were set viasetAvailableSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>).
- 
getActiveSubscriptionInfoCountReturns the size of the list ofSubscriptionInfothat were set viasetActiveSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>). If no list was set, returns 0.
- 
getActiveSubscriptionInfoReturns 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.
- 
setActiveSubscriptionInfoListSets 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.
 
- 
setAccessibleSubscriptionInfoListSets 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.
 
- 
setAvailableSubscriptionInfoListSets 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.
 
- 
setActiveSubscriptionInfosSets the active list ofSubscriptionInfo. This call internally triggersSubscriptionManager.OnSubscriptionsChangedListener.onSubscriptionsChanged()to all the listeners.
- 
setAccessibleSubscriptionInfosSets the accessible list ofSubscriptionInfo. This call internally triggersSubscriptionManager.OnSubscriptionsChangedListener.onSubscriptionsChanged()to all the listeners.
- 
setAvailableSubscriptionInfosSets 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 ofSubscriptionInfois 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 ofSubscriptionInfois 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 ofSubscriptionInfois updated.
- 
hasOnSubscriptionsChangedListenerpublic 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.
 
- 
getActiveSubscriptionIdListReturns subscription Ids that were set viasetActiveSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>).
- 
clearNetworkRoamingStatuspublic void clearNetworkRoamingStatus()Clears the local cache of roaming subscription Ids used byisNetworkRoaming(int).
- 
setNetworkRoamingStatuspublic 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).
- 
isNetworkRoamingUses 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.
- 
putPhoneIdpublic static void putPhoneId(int subId, int phoneId) Adds a subscription ID-phone ID mapping to the map used bygetPhoneId(int).
- 
removePhoneIdRemoves 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
 
- 
clearPhoneIdspublic static void clearPhoneIds()Removes all mappings between subscription IDs and phone IDs from the map used bygetPhoneId(int).
- 
getPhoneIdUses the map of subscription IDs to phone IDs managed byputPhoneId(int,int)andremovePhoneId(int)to return the phone ID for a given subscription ID.
- 
setReadPhoneStatePermissionpublic void setReadPhoneStatePermission(boolean readPhoneStatePermission) When set to false methods requiringandroid.Manifest.permission.READ_PHONE_STATEpermission will throw aSecurityException. By default it's set to true for backwards compatibility.
- 
setReadPhoneNumbersPermissionpublic void setReadPhoneNumbersPermission(boolean readPhoneNumbersPermission) When set to false methods requiringandroid.Manifest.permission.READ_PHONE_NUMBERSpermission will throw aSecurityException. By default it's set to true for backwards compatibility.
- 
getPhoneNumberReturns 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. 
- 
getPhoneNumberReturns the phone number for the givensubscriptionId, or an empty string if not available.sourceis ignored and will return the same asgetPhoneNumber(int).The phone number can be set by setPhoneNumber(int, String)
- 
setPhoneNumberSets the phone number returned bygetPhoneNumber(int).
- 
reset
 
-