public class UserAccountManager
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
EXTRA_USER_SWITCH_TYPE
Represents how the current user has been switched to, as found in an intent sent to a
android.content.BroadcastReceiver
filtering USER_SWITCH_INTENT_ACTION . |
static java.lang.String |
USER_SWITCH_INTENT_ACTION |
static int |
USER_SWITCH_TYPE_DEFAULT
A switch has occurred between two authenticated users.
|
static int |
USER_SWITCH_TYPE_FIRST_LOGIN
The first user has logged in and is being switched to.
|
static int |
USER_SWITCH_TYPE_LOGIN
An additional user has logged in and is being switched to.
|
static int |
USER_SWITCH_TYPE_LOGOUT
A user has a logged out and another authenticated user is being switched to.
|
Modifier | Constructor and Description |
---|---|
protected |
UserAccountManager()
Protected constructor.
|
Modifier and Type | Method and Description |
---|---|
Account |
buildAccount(UserAccount userAccount)
Builds an Account object from the user account passed in.
|
UserAccount |
buildUserAccount(Account account)
Builds a UserAccount object from the saved account.
|
void |
clearCachedCurrentUser()
Get rid of cached current user account
|
Bundle |
createAccount(UserAccount userAccount)
Create AccountManager Account from the given UserAccount
|
boolean |
doesUserAccountExist(UserAccount account)
Returns whether the specified user account exists or not.
|
java.util.List<UserAccount> |
getAuthenticatedUsers()
Returns a list of authenticated users.
|
UserAccount |
getCachedCurrentUser()
Returns a cached value of the current user.
|
Account |
getCurrentAccount()
Returns the current user logged in.
|
UserAccount |
getCurrentUser()
Returns the current user logged in.
|
static UserAccountManager |
getInstance()
Returns a singleton instance of this class.
|
java.lang.String |
getStoredOrgId()
Returns the stored org ID.
|
java.lang.String |
getStoredUserId()
Returns the stored user ID.
|
UserAccount |
getUserFromOrgAndUserId(java.lang.String orgId,
java.lang.String userId)
Retrieves a stored user account from org ID and user ID.
|
void |
refreshToken(UserAccount userAccount)
Attempts to refresh the access token for this user by making an API call
to the "/token" endpoint.
|
void |
sendUserSwitchIntent(int userSwitchType,
Bundle extras)
Broadcasts an intent that a user switch has occurred.
|
void |
signoutCurrentUser(Activity frontActivity)
Logs the current user out.
|
void |
signoutCurrentUser(Activity frontActivity,
boolean showLoginPage)
Logs the current user out.
|
void |
signoutCurrentUser(Activity frontActivity,
boolean showLoginPage,
OAuth2.LogoutReason reason)
Logs the current user out.
|
void |
signoutUser(UserAccount userAccount,
Activity frontActivity)
Logs the specified user out.
|
void |
signoutUser(UserAccount userAccount,
Activity frontActivity,
boolean showLoginPage)
Logs the specified user out.
|
void |
signoutUser(UserAccount userAccount,
Activity frontActivity,
boolean showLoginPage,
OAuth2.LogoutReason reason)
Logs the specified user out.
|
void |
storeCurrentUserInfo(java.lang.String userId,
java.lang.String orgId)
Stores the current active user's user ID and org ID in a shared preference file.
|
void |
switchToNewUser()
Kicks off the login flow to switch to a new user.
|
void |
switchToNewUser(java.lang.String jwt,
java.lang.String url)
Kicks off the login flow to switch to a new user with jwt.
|
void |
switchToUser(UserAccount user)
Switches to the specified user account.
|
void |
switchToUser(UserAccount user,
int userSwitchType,
Bundle extras)
Switches to the specified user account.
|
Bundle |
updateAccount(Account account,
UserAccount userAccount)
Update AccountManager Account for the given UserAccount
|
public static final java.lang.String USER_SWITCH_INTENT_ACTION
public static final java.lang.String EXTRA_USER_SWITCH_TYPE
android.content.BroadcastReceiver
filtering USER_SWITCH_INTENT_ACTION
. User switching including logging in, logging out and switching between authenticated
users. For backwards compatibility, the case where the last user has logged out is not included, as this currently does not
send a broadcast.public static final int USER_SWITCH_TYPE_DEFAULT
Use this constant with EXTRA_USER_SWITCH_TYPE
.
public static final int USER_SWITCH_TYPE_FIRST_LOGIN
Use this constant with EXTRA_USER_SWITCH_TYPE
.
public static final int USER_SWITCH_TYPE_LOGIN
Use this constant with EXTRA_USER_SWITCH_TYPE
.
public static final int USER_SWITCH_TYPE_LOGOUT
Use this constant with EXTRA_USER_SWITCH_TYPE
.
public static UserAccountManager getInstance()
public void storeCurrentUserInfo(java.lang.String userId, java.lang.String orgId)
userId
- User ID.orgId
- Org ID.public java.lang.String getStoredUserId()
public java.lang.String getStoredOrgId()
public UserAccount getCurrentUser()
public UserAccount getCachedCurrentUser()
public void clearCachedCurrentUser()
public Account getCurrentAccount()
public java.util.List<UserAccount> getAuthenticatedUsers()
public boolean doesUserAccountExist(UserAccount account)
account
- User account.public void switchToUser(UserAccount user)
user
- User account to switch to.public void switchToUser(UserAccount user, int userSwitchType, Bundle extras)
user
- the user account to switch touserSwitchType
- a USER_SWITCH_TYPE
constantextras
- a optional Bundle of extras to pass additional
information during user switchswitchToUser(UserAccount)
public void switchToNewUser()
public void switchToNewUser(java.lang.String jwt, java.lang.String url)
jwt
- JWT.url
- Instance/My domain URL.public void signoutCurrentUser(Activity frontActivity)
frontActivity
- Front activity.public void signoutCurrentUser(Activity frontActivity, boolean showLoginPage)
frontActivity
- Front activity.showLoginPage
- True - if the login page should be shown, False - otherwise.public void signoutCurrentUser(Activity frontActivity, boolean showLoginPage, OAuth2.LogoutReason reason)
frontActivity
- Front activity.showLoginPage
- True - if the login page should be shown, False - otherwise.reason
- The reason for the logout.public void signoutUser(UserAccount userAccount, Activity frontActivity)
userAccount
- User account.frontActivity
- Front activity.public void signoutUser(UserAccount userAccount, Activity frontActivity, boolean showLoginPage)
userAccount
- User account.frontActivity
- Front activity.showLoginPage
- True - if the login page should be shown, False - otherwise.public void signoutUser(UserAccount userAccount, Activity frontActivity, boolean showLoginPage, OAuth2.LogoutReason reason)
userAccount
- User account.frontActivity
- Front activity.showLoginPage
- True - if the login page should be shown, False - otherwise.reason
- The reason for the logout.public Bundle createAccount(UserAccount userAccount)
userAccount
- UserAccount object.public Bundle updateAccount(Account account, UserAccount userAccount)
account
- Account object to update.userAccount
- UserAccount object.public UserAccount buildUserAccount(Account account)
account
- Account object.public Account buildAccount(UserAccount userAccount)
userAccount
- UserAccount object.public final void sendUserSwitchIntent(int userSwitchType, Bundle extras)
userSwitchType
- A USER_SWITCH_TYPE
constant.extras
- An optional Bundle of extras to add to the broadcast intent.public UserAccount getUserFromOrgAndUserId(java.lang.String orgId, java.lang.String userId)
orgId
- Org ID.userId
- User ID.public void refreshToken(UserAccount userAccount)
userAccount
- User account whose token should be refreshed. Use 'null' for current user.