Class ShadowSubscriptionManager
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class to create instance ofSubscriptionInfo. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier 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 all list ofSubscriptionInfothat were set viasetAllSubscriptionInfoList(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.protected static intgetSlotIndex(int subscriptionId) protected static int[]getSubId(int slotIndex) Older form ofgetSubscriptionId(int)that was designed prior to mainstream multi-SIM support, so itsint[]return type ended up being an unused vestige from that older design.protected static intgetSubscriptionId(int slotIndex) Derives the subscription ID corresponding to an "active"SubscriptionInfofor the given SIM slot index.protected int[]getSubscriptionIds(int slotIndex) Older form ofgetSubscriptionId(int)that was designed prior to mainstream multi-SIM support, so itsint[]return type ended up being an unused vestige from that older design.booleanCheck if a listener exists in thelisteners.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 all list ofSubscriptionInfo.voidsetAllSubscriptionInfos(SubscriptionInfo... infos) Sets the all list ofSubscriptionInfo.voidSets the available list ofSubscriptionInfo.voidSets the available list ofSubscriptionInfo.static voidsetDefaultDataSubscriptionId(int defaultDataSubscriptionId) Sets the default data subscription and broadcastsTelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGEDstatic voidsetDefaultSmsSubscriptionId(int defaultSmsSubscriptionId) Sets the default SMS subscription and broadcastsSubscriptionManager.ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGEDstatic voidsetDefaultSubscriptionId(int defaultSubscriptionId) Sets the default subscription and broadcastsSubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGEDstatic voidsetDefaultVoiceSubscriptionId(int defaultVoiceSubscriptionId) Sets the default voice subscription and broadcastsTelephonyManager.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGEDvoidsetNetworkRoamingStatus(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 requiringManifest.permission.READ_PHONE_NUMBERSpermission will throw aSecurityException.voidsetReadPhoneStatePermission(boolean readPhoneStatePermission) When set to false methods requiringManifest.permission.READ_PHONE_STATEpermission will throw aSecurityException.
-
Field Details
-
INVALID_PHONE_INDEX
public static final int INVALID_PHONE_INDEX
-
-
Constructor Details
-
ShadowSubscriptionManager
public ShadowSubscriptionManager()
-
-
Method Details
-
getActiveDataSubscriptionId
@Implementation(minSdk=30) protected static int getActiveDataSubscriptionId()Returns value set withsetActiveDataSubscriptionId(int). -
getDefaultSubscriptionId
@Implementation(minSdk=24) protected static int getDefaultSubscriptionId()Returns value set withsetDefaultSubscriptionId(int). -
getDefaultDataSubscriptionId
@Implementation(minSdk=24) protected static int getDefaultDataSubscriptionId()Returns value set withsetDefaultDataSubscriptionId(int). -
getDefaultSmsSubscriptionId
@Implementation(minSdk=24) protected static int getDefaultSmsSubscriptionId()Returns value set withsetDefaultSmsSubscriptionId(int). -
getDefaultVoiceSubscriptionId
@Implementation(minSdk=24) protected static int getDefaultVoiceSubscriptionId()Returns value set withsetDefaultVoiceSubscriptionId(int). -
getDefaultSubId
@Implementation(maxSdk=23) @HiddenApi protected static int getDefaultSubId() -
getDefaultVoiceSubId
@Implementation(maxSdk=23) @HiddenApi protected static int getDefaultVoiceSubId() -
getDefaultSmsSubId
@Implementation(maxSdk=23) @HiddenApi protected static int getDefaultSmsSubId() -
getDefaultDataSubId
@Implementation(maxSdk=23) @HiddenApi protected static int 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 default subscription and broadcastsSubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED -
setDefaultDataSubscriptionId
public static void setDefaultDataSubscriptionId(int defaultDataSubscriptionId) Sets the default data subscription and broadcastsTelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED -
setDefaultSmsSubscriptionId
public static void setDefaultSmsSubscriptionId(int defaultSmsSubscriptionId) Sets the default SMS subscription and broadcastsSubscriptionManager.ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED -
setDefaultVoiceSubscriptionId
public static void setDefaultVoiceSubscriptionId(int defaultVoiceSubscriptionId) Sets the default voice subscription and broadcastsTelephonyManager.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED -
getActiveSubscriptionInfoList
Returns the active list ofSubscriptionInfothat were set viasetActiveSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>). -
getAllSubscriptionInfoList
Returns the all list ofSubscriptionInfothat were set viasetAllSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>). -
getAccessibleSubscriptionInfoList
Returns the accessible list ofSubscriptionInfothat were set viasetAccessibleSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>). -
getAvailableSubscriptionInfoList
Returns the available list ofSubscriptionInfothat were set viasetAvailableSubscriptionInfoList(java.util.List<android.telephony.SubscriptionInfo>). -
getActiveSubscriptionInfoCount
@Implementation protected int getActiveSubscriptionInfoCount()Returns the size of the list ofSubscriptionInfothat 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
@Implementation protected int 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.
-
setAllSubscriptionInfoList
Sets the all list ofSubscriptionInfo. This call internally triggersSubscriptionManager.OnSubscriptionsChangedListener.onSubscriptionsChanged()to all the listeners. -
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 withEuiccManager.- 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. -
setAllSubscriptionInfos
Sets the all list ofSubscriptionInfo. This call internally triggersSubscriptionManager.OnSubscriptionsChangedListener.onSubscriptionsChanged()to all the listeners. -
addOnSubscriptionsChangedListener
@Implementation 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 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. -
hasOnSubscriptionsChangedListener
public boolean hasOnSubscriptionsChangedListener(SubscriptionManager.OnSubscriptionsChangedListener listener) Check if a listener exists in thelisteners.- Parameters:
listener- The listener to check.- Returns:
- boolean True if the listener already added, otherwise false.
-
getActiveSubscriptionIdList
@Implementation @HiddenApi protected int[] 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
@Implementation 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. 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
@Implementation(maxSdk=28) @HiddenApi 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. -
getSubId
@Implementation @HiddenApi protected static int[] getSubId(int slotIndex) Older form ofgetSubscriptionId(int)that was designed prior to mainstream multi-SIM support, so itsint[]return type ended up being an unused vestige from that older design. -
getSubscriptionIds
@Implementation(minSdk=29) protected int[] getSubscriptionIds(int slotIndex) Older form ofgetSubscriptionId(int)that was designed prior to mainstream multi-SIM support, so itsint[]return type ended up being an unused vestige from that older design. -
getSubscriptionId
@Implementation(minSdk=34) protected static int getSubscriptionId(int slotIndex) Derives the subscription ID corresponding to an "active"SubscriptionInfofor the given SIM slot index. -
getSlotIndex
@Implementation(minSdk=26) protected static int getSlotIndex(int subscriptionId) -
setReadPhoneStatePermission
public void setReadPhoneStatePermission(boolean readPhoneStatePermission) When set to false methods requiringManifest.permission.READ_PHONE_STATEpermission will throw aSecurityException. By default it's set to true for backwards compatibility. -
setReadPhoneNumbersPermission
public void setReadPhoneNumbersPermission(boolean readPhoneNumbersPermission) When set to false methods requiringManifest.permission.READ_PHONE_NUMBERSpermission 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.sourceis 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
@Resetter public static void reset()
-