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 Detail

      • DeviceUserManager

        DeviceUserManager(Context context)
    • 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 0
        search - 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 0
        search - 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.

      • 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 user
        onBoarded - By default, this user will also be marked as 'onboarded' if this parameter is not provided
        userSwitchCallback - The callback function which needs to know both the current and the previous users.
      • 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.
      • 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.
      • 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

      • 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.