Class DeviceUserManager
-
- All Implemented Interfaces:
public final class DeviceUserManagerRepresents the device user manager to manage the user information saved on the device.
Most of the operations in this service will automatically open the store before the operation and close the store afterwards.
For getOnBoardedUsers, it will not close after the operation since it might be used in the paginated list and will be called multiple times.
To save system resources, closing the store after being used is recommended, and the right time to close the store might be, for example, after onboarding or restore flow.
-
-
Constructor Summary
Constructors Constructor Description DeviceUserManager(Context context)
-
Method Summary
Modifier and Type Method Description final UnitopenStore()Opens the store if not opened yet final DeviceUsercreateUser(User user)Creates a new user into the database, and return the user information final List<DeviceUser>getOnBoardedUsers(Integer pageSize, Integer pageNo, String search)Retrieves onBoarded local user list. final JobgetOnBoardedUsers(ServiceListener<List<DeviceUser>> listener, Integer pageSize, Integer pageNo, String search)Retrieves onBoarded local user list, and notifies the result with the given listener. final List<DeviceUser>getAllUsers(Integer pageSize, Integer pageNo, String search)Retrieves all local user list. final BooleanhaveOtherOnBoardedUsers(DeviceUser user)Checks whether there are other users already 'onBoarded'. final DeviceUsergetCurrentUser()Retrieves the current user. final DeviceUserprimaryUser()Retrieves the very first user onboarded, 'null' is no user exists. final UnitremoveAllUsersExceptPrimary()Deletes all users except the primary user. final DeviceUserfindUserById(String id)Finds a user by the given id. final UnitdeleteUserById(String id)Deletes a user identified the given id. final UnitmakeCurrent(DeviceUser user, Boolean onBoarded, SuspendFunction2<DeviceUser, DeviceUser, Unit> userSwitchCallback)Makes the given user as the current active user. final UnitsetOnBoarded(DeviceUser user, Boolean onBoarded)Sets the onBoarded status for the given user. final Unitreset()Deletes the database. final Unitclear(Boolean keepGlobalUserData)Clears all user data and the passcode history. final UnitsaveUserPasscodeHistory(String userId, String passcodeHash)Saves the user passcode history. final UnitdeleteUserPasscodeHistory(String userId)Deletes all the user passcode history. final List<String>getUserPasscodeHistory(String userId, Integer latestCount)Retrieves the latest latestCount passcode history, if latestCount is 0 or negative, returns an empty list, which means bypass the passcode history check. final BooleanisStoreOpen()Checks whether the store is opened or not. final UnitcloseStore()Closes the database. final OnboardingUserInfogetOnboardingUserInfo(String userId)Retrieves all the onboarding related info for the user identified by userId. final UnitdeleteOnboardingUserInfo(String userId)Removes all the user onboarding information from the store. final AppConfiggetAppConfig()Retrieves the current AppConfig final List<AppConfig>getAppConfigHistory()Returns the history of AppConfig final UnitsaveAppConfig(AppConfig appConfig)Saves the appConfig into the database, when it's 'null', remove the current one. final BooleangetEffectiveMultipleUserMode()Returns the effective multiple user mode of the current AppConfig. final UnitsetEffectiveMultipleUserMode(Boolean multi)Changes the effective multiple user mode. final UnitsaveArbitraryUserData(String userId, String key, Object value)Saves an arbitrary user data into the db. final StringgetArbitraryUserData(String userId, String key)Gets an arbitrary user data out of the db final StringgetGlobalArbitraryUserData(String key)Gets the global user data final UnitsaveGlobalArbitraryUserData(String key, Object value)Saves an arbitrary data for all users. final PasscodePolicygetPasscodePolicy(String userId)Retrieves the passcode policy of a user identified by userId. final UnitsetPasscodePolicy(String userId, PasscodePolicy policy)Saves the passcode policy for this user by userId. final IntegergetRetryLimit(String userId)Retrieves the retry limit left for this user by userId. final UnitsetRetryLimit(String userId, Integer left)Sets the retry limit left for the user. final BooleanisCurrentPasscodeDigital(String userId)Gets the data which says if the current passcode is digital or not. final UnitsetCurrentPasscodeDigital(String userId, Boolean isDigital)Sets if the current passcode is digital. final LonggetPasscodeCreateTime(String userId)Retrieves the passcode creation time, in millisecond. final UnitsetPasscodeCreateTime(String userId, Long crtTime)Sets the passcode creation time. final StringgetUsageStoreName(String userId)Retrieves the user usage store name. final UnitsetUsageStoreName(String userId, String storeName)Sets the usage store name for this user. -
-
Method Detail
-
openStore
final Unit openStore()
Opens the store if not opened yet
-
createUser
final DeviceUser createUser(User user)
Creates a new user into the database, and return the user information
-
getOnBoardedUsers
final List<DeviceUser> getOnBoardedUsers(Integer pageSize, Integer pageNo, String search)
Retrieves onBoarded local user list.
- Parameters:
pageSize- The load page size.pageNo- Which page to load, it starts from 0search- The filter string, it does a 'like' operation on 'name' attribute.- Returns:
onBoarded user list sorted by the latest update time in descending order.
-
getOnBoardedUsers
final Job getOnBoardedUsers(ServiceListener<List<DeviceUser>> listener, Integer pageSize, Integer pageNo, String search)
Retrieves onBoarded local user list, and notifies the result with the given listener.
- Parameters:
listener- The result listener.pageSize- The load page size.pageNo- Which page to load, it starts from 0search- The filter string, it does a 'like' operation on 'name' attribute.
-
getAllUsers
final List<DeviceUser> getAllUsers(Integer pageSize, Integer pageNo, String search)
Retrieves all local user list. By default only 20 users will be returned if no pageSize provided. pageNo starts from '0'. The returned list is sorted by the latest active user with descending order.
-
haveOtherOnBoardedUsers
final Boolean haveOtherOnBoardedUsers(DeviceUser user)
Checks whether there are other users already 'onBoarded'. This is usually been used when the current user forgets the passcode and restarting the app, then the app needs to decide which flow to use. If no users already onBoarded, it will go directly to the onboarding flow, otherwise, it should go into 'Sign In' step.
- Parameters:
user- The user to check again for 'others'.- Returns:
'true' to say there are other users onboarded before, false otherwise.
-
getCurrentUser
final DeviceUser getCurrentUser()
Retrieves the current user. It might return 'null' to indicate there is no user signed in this device before.
-
primaryUser
final DeviceUser primaryUser()
Retrieves the very first user onboarded, 'null' is no user exists.
- Returns:
The first user onboarded, null if no user exists.
-
removeAllUsersExceptPrimary
final Unit removeAllUsersExceptPrimary()
Deletes all users except the primary user.
-
findUserById
final DeviceUser findUserById(String id)
Finds a user by the given id.
-
deleteUserById
final Unit deleteUserById(String id)
Deletes a user identified the given id. This is mostly for single user mode when resetting a client.
-
makeCurrent
final Unit makeCurrent(DeviceUser user, Boolean onBoarded, SuspendFunction2<DeviceUser, DeviceUser, Unit> userSwitchCallback)
Makes the given user as the current active user. if userSwitchCallback is provided, both the current and previous active user will be notified.
- Parameters:
user- The user to be marked as the current active useronBoarded- By default, this user will also be marked as 'onboarded' if this parameter is not provideduserSwitchCallback- The callback function which needs to know both the current and the previous users.
-
setOnBoarded
final Unit setOnBoarded(DeviceUser user, Boolean onBoarded)
Sets the onBoarded status for the given user.
-
reset
final Unit reset()
Deletes the database.
-
clear
final Unit clear(Boolean keepGlobalUserData)
Clears all user data and the passcode history.
-
saveUserPasscodeHistory
final Unit saveUserPasscodeHistory(String userId, String passcodeHash)
Saves the user passcode history.
- Parameters:
userId- The user id.passcodeHash- The encrypted passcode.
-
deleteUserPasscodeHistory
final Unit deleteUserPasscodeHistory(String userId)
Deletes all the user passcode history.
-
getUserPasscodeHistory
final List<String> getUserPasscodeHistory(String userId, Integer latestCount)
Retrieves the latest latestCount passcode history, if latestCount is 0 or negative, returns an empty list, which means bypass the passcode history check.
-
isStoreOpen
final Boolean isStoreOpen()
Checks whether the store is opened or not.
-
closeStore
final Unit closeStore()
Closes the database.
-
getOnboardingUserInfo
final OnboardingUserInfo getOnboardingUserInfo(String userId)
Retrieves all the onboarding related info for the user identified by userId.
- Parameters:
userId- The user id.- Returns:
The onboarding information of this user if exists
-
deleteOnboardingUserInfo
final Unit deleteOnboardingUserInfo(String userId)
Removes all the user onboarding information from the store.
- Parameters:
userId- the user id.
-
getAppConfig
final AppConfig getAppConfig()
Retrieves the current AppConfig
- Returns:
The AppConfig if a user onboarded with this app.
-
getAppConfigHistory
final List<AppConfig> getAppConfigHistory()
Returns the history of AppConfig
-
saveAppConfig
final Unit saveAppConfig(AppConfig appConfig)
Saves the appConfig into the database, when it's 'null', remove the current one.
- Parameters:
appConfig- The AppConfig to save.
-
getEffectiveMultipleUserMode
final Boolean getEffectiveMultipleUserMode()
Returns the effective multiple user mode of the current AppConfig. The default value is the same as the one in AppConfig, but the user can choose to update it.
- Returns:
The effective multiple user mode, 'null' if no user onboarded.
-
setEffectiveMultipleUserMode
final Unit setEffectiveMultipleUserMode(Boolean multi)
Changes the effective multiple user mode.
- Parameters:
multi- the effective multiple user mode
-
saveArbitraryUserData
final Unit saveArbitraryUserData(String userId, String key, Object value)
Saves an arbitrary user data into the db.
-
getArbitraryUserData
final String getArbitraryUserData(String userId, String key)
Gets an arbitrary user data out of the db
-
getGlobalArbitraryUserData
final String getGlobalArbitraryUserData(String key)
Gets the global user data
-
saveGlobalArbitraryUserData
final Unit saveGlobalArbitraryUserData(String key, Object value)
Saves an arbitrary data for all users.
-
getPasscodePolicy
final PasscodePolicy getPasscodePolicy(String userId)
Retrieves the passcode policy of a user identified by userId.
- Parameters:
userId- the user id.- Returns:
the current passcode policy of this user, if exists.
-
setPasscodePolicy
final Unit setPasscodePolicy(String userId, PasscodePolicy policy)
Saves the passcode policy for this user by userId. This is usually called after authentication and the client policy retrieved from the mobile server.
- Parameters:
userId- the user id.policy- The passcode policy.
-
getRetryLimit
final Integer getRetryLimit(String userId)
Retrieves the retry limit left for this user by userId. When the user inputs incorrect passcode on the sign in screen, the retry limit will count down. When it's zero, the user will not be able to try again.
- Parameters:
userId- the user id.- Returns:
the retry limit left for the user, 'null' if not set before.
-
setRetryLimit
final Unit setRetryLimit(String userId, Integer left)
Sets the retry limit left for the user. Usually when set the passcode policy, the original retry limit is the one defined in the policy, then it will count down if incorrect passcode inputted.
- Parameters:
userId- the user id.left- the current retry limit left.
-
isCurrentPasscodeDigital
final Boolean isCurrentPasscodeDigital(String userId)
Gets the data which says if the current passcode is digital or not.
-
setCurrentPasscodeDigital
final Unit setCurrentPasscodeDigital(String userId, Boolean isDigital)
Sets if the current passcode is digital.
-
getPasscodeCreateTime
final Long getPasscodeCreateTime(String userId)
Retrieves the passcode creation time, in millisecond.
- Parameters:
userId- the user id.- Returns:
the passcode creation time, if exists.
-
setPasscodeCreateTime
final Unit setPasscodeCreateTime(String userId, Long crtTime)
Sets the passcode creation time.
- Parameters:
userId- the user id.crtTime- The creation time, in millisecond, the default one the current time millisecond.
-
getUsageStoreName
final String getUsageStoreName(String userId)
Retrieves the user usage store name.
- Parameters:
userId- the user id.- Returns:
the usage store name if exists.
-
setUsageStoreName
final Unit setUsageStoreName(String userId, String storeName)
Sets the usage store name for this user. This is usually be called when a user is authenticated, SDK will use a random UUID string as the storage name, and save it in the database.
- Parameters:
userId- the user id.storeName- The usage store name, default one is random UUID string.
-
-
-
-