Class DeviceUserManager
-
- All Implemented Interfaces:
public final class DeviceUserManager
Represents 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 Unit
openStore()
Opens the store if not opened yet final DeviceUser
createUser(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 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. final List<DeviceUser>
getAllUsers(Integer pageSize, Integer pageNo, String search)
Retrieves all local user list. final Boolean
haveOtherOnBoardedUsers(DeviceUser user)
Checks whether there are other users already 'onBoarded'. final DeviceUser
getCurrentUser()
Retrieves the current user. final DeviceUser
primaryUser()
Retrieves the very first user onboarded, 'null' is no user exists. final Unit
removeAllUsersExceptPrimary()
Deletes all users except the primary user. final DeviceUser
findUserById(String id)
Finds a user by the given id. final Unit
deleteUserById(String id)
Deletes a user identified the given id. final Unit
makeCurrent(DeviceUser user, Boolean onBoarded, SuspendFunction2<DeviceUser, DeviceUser, Unit> userSwitchCallback)
Makes the given user as the current active user. final Unit
setOnBoarded(DeviceUser user, Boolean onBoarded)
Sets the onBoarded status for the given user. final Unit
reset()
Deletes the database. final Unit
saveUserPasscodeHistory(String userId, String passcodeHash)
Saves the user passcode history. final Unit
deleteUserPasscodeHistory(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 Boolean
isStoreOpen()
Checks whether the store is opened or not. final Unit
closeStore()
Closes the database. -
-
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. The primary user must be the current user to call this, otherwise, exception will be thrown.
-
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.
-
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.
-
-
-
-