public class SingleUserAccountManager<A extends UserAccount> extends UserAccountManager<A>
UserAccountManager implementation that can be used for Android applications that allow
only one account to be created for a user.UserAccountManager.AccountWatcher<A extends UserAccount>ERROR_CREATE_ACCOUNT, ERROR_DELETE_ACCOUNT, mAccountType, mContext, mManager, PERMISSION_AUTHENTICATE_ACCOUNTS, PERMISSION_GET_ACCOUNTS, PERMISSION_MANAGE_ACCOUNTS| Constructor and Description |
|---|
SingleUserAccountManager(Context context,
String accountType)
Creates a new instance of SingleUserAccountManager for the specified accountType.
|
| Modifier and Type | Method and Description |
|---|---|
protected Account |
acquireAccount()
Called to acquire current single account.
|
boolean |
clearAccountPassword()
Clears the password for the current single account (if created).
|
Account |
getAccount()
Returns the current account if it is created.
|
String |
getAccountData(String key)
Returns the single data for the current single account (if created) stored under the specified
key.
|
Bundle |
getAccountDataBundle(String... keys)
Returns the bundle with data for the current single account (if created).
|
String |
getAccountPassword()
Returns the password for the current single account (if created).
|
boolean |
invalidateAccountAuthToken(String authToken)
Invalidates the specified authToken for the current single account (if created).
|
boolean |
isAccountAuthenticated(String authTokenType)
Checks whether the current single account (if created) is authenticated or not.
|
boolean |
isAccountCreated()
Checks whether there is account created or not.
|
String |
peekAccountAuthToken(String authTokenType)
Returns the authentication token for the current single account (if created) stored for the
specified authTokenType.
|
boolean |
setAccountAuthToken(String authTokenType,
String authToken)
Sets an authentication token for the current single account (if created) with the specified
authTokenType.
|
boolean |
setAccountData(String key,
String value)
Sets a single data value for the current single account (if created) with the
specified key.
|
boolean |
setAccountDataBundle(Bundle dataBundle)
Sets a bundle with data for the current single account (if created).
|
boolean |
setAccountPassword(String password)
Sets a password for the current single account (if created).
|
clearAccountPassword, createAccount, createAccountAsync, deleteAccount, deleteAccountAsync, findAccountForUser, getAccountData, getAccountDataBundle, getAccountPassword, invalidateAccountAuthToken, isAccountAuthenticated, onCreateAccount, onDeleteAccount, peekAccountAuthToken, registerWatcher, setAccountAuthToken, setAccountData, setAccountDataBundle, setAccountPassword, unregisterWatcherpublic SingleUserAccountManager(@NonNull Context context, @NonNull String accountType)
context - Context used to access AccountManager.accountType - The desired account type that will be managed by the new user account manager.public boolean isAccountCreated()
This method requires the caller to hold UserAccountManager.PERMISSION_GET_ACCOUNTS permission.
True if there is account created at this time, false otherwise.getAccount()@Nullable public Account getAccount()
Note, that default implementation of this method assumes that there can be only one account created for this Android application. If there are multiple accounts created this method will pick the first one.
This method requires the caller to hold UserAccountManager.PERMISSION_GET_ACCOUNTS permission.
null if there is no account created yet.isAccountCreated()public boolean setAccountAuthToken(@NonNull String authTokenType, @Nullable String authToken)
This method requires the caller to hold UserAccountManager.PERMISSION_GET_ACCOUNTS along with
UserAccountManager.PERMISSION_AUTHENTICATE_ACCOUNTS permissions.
authTokenType - Type of the authentication token to be stored used as key.authToken - The desired authentication token to be stored.True if authentication token for the account has been updated, false
if there is no account created at this time for which to update its token.peekAccountAuthToken(String),
isAccountAuthenticated(String),
UserAccountManager.setAccountAuthToken(Account, String, String)public boolean isAccountAuthenticated(@NonNull String authTokenType)
This method requires the caller to hold UserAccountManager.PERMISSION_GET_ACCOUNTS along with
UserAccountManager.PERMISSION_AUTHENTICATE_ACCOUNTS permissions.
authTokenType - Type of the authentication token used to resolve whether the account is
authenticated or not.True if there is stored valid authentication token for the account with the
specified token type, false if there is no account created at this time or there has
not been stored token with the specified token type yet.setAccountAuthToken(String, String),
UserAccountManager.isAccountAuthenticated(Account, String)@Nullable public String peekAccountAuthToken(@NonNull String authTokenType)
This method requires the caller to hold UserAccountManager.PERMISSION_GET_ACCOUNTS along with
UserAccountManager.PERMISSION_AUTHENTICATE_ACCOUNTS permissions.
authTokenType - Type of the requested authentication token to peek for the account.null if there is no account created at this time or
there has not been stored token for the requested type yet or the token has been invalidated.setAccountAuthToken(String, String),
invalidateAccountAuthToken(String),
UserAccountManager.peekAccountAuthToken(Account, String)public boolean invalidateAccountAuthToken(@NonNull String authToken)
This method requires the caller to hold UserAccountManager.PERMISSION_GET_ACCOUNTS along with
UserAccountManager.PERMISSION_MANAGE_ACCOUNTS permissions.
authToken - The token that should be invalidated for the account.True if authentication token for the account has been invalidated, false
if there is not account created at this time for which to invalidate its token.peekAccountAuthToken(String),
UserAccountManager.invalidateAccountAuthToken(Account, String)public boolean setAccountPassword(@Nullable String password)
This method requires the caller to hold UserAccountManager.PERMISSION_GET_ACCOUNTS along with
UserAccountManager.PERMISSION_AUTHENTICATE_ACCOUNTS permissions.
password - The desired password to be stored for the account. May be null to
clear the current one.True if password for the account has been updated, false if there is
no account created at this time for which to update its password.getAccountPassword(),
clearAccountPassword(),
UserAccountManager.setAccountPassword(Account, String)@Nullable public String getAccountPassword()
This method requires the caller to hold UserAccountManager.PERMISSION_GET_ACCOUNTS along with
UserAccountManager.PERMISSION_AUTHENTICATE_ACCOUNTS permissions.
null if there is no account created at this time or
there has not been stored any password for the account yet.setAccountPassword(String),
clearAccountPassword(),
UserAccountManager.getAccountPassword(Account)public boolean clearAccountPassword()
This method requires the caller to hold UserAccountManager.PERMISSION_GET_ACCOUNTS along with
UserAccountManager.PERMISSION_AUTHENTICATE_ACCOUNTS permissions.
True if password for the account has been cleared, false if there is
no account created at this time for which to clear its password.setAccountPassword(String),
getAccountPassword(),
UserAccountManager.clearAccountPassword(Account)public boolean setAccountData(@NonNull String key, @Nullable String value)
This method requires the caller to hold UserAccountManager.PERMISSION_GET_ACCOUNTS along with
UserAccountManager.PERMISSION_AUTHENTICATE_ACCOUNTS permissions.
key - The key under which will be the desired value stored for the account.value - The desired data value to be stored.True if data for the account has been updated, false if there is no
account created at this time for which to update its data.getAccountData(String),
setAccountDataBundle(Bundle),
UserAccountManager.setAccountData(Account, String, String)@Nullable public String getAccountData(@NonNull String key)
This method requires the caller to hold UserAccountManager.PERMISSION_GET_ACCOUNTS along with
UserAccountManager.PERMISSION_AUTHENTICATE_ACCOUNTS permissions.
key - The key for which to obtain the requested account data.null if there is no account created at this time or
there are no data stored for the requested key.setAccountData(String, String),
UserAccountManager.getAccountData(Account, String)public boolean setAccountDataBundle(@NonNull Bundle dataBundle)
This method requires the caller to hold UserAccountManager.PERMISSION_GET_ACCOUNTS along with
UserAccountManager.PERMISSION_AUTHENTICATE_ACCOUNTS permissions.
dataBundle - Bundle with the desired data for the account.True if data bundle for the account has been updated, false if there
is no account created at this time for which to update its data bundle.getAccountDataBundle(String...),
UserAccountManager.setAccountDataBundle(Account, Bundle)@Nullable public Bundle getAccountDataBundle(@NonNull String... keys)
This method requires the caller to hold UserAccountManager.PERMISSION_GET_ACCOUNTS along with
UserAccountManager.PERMISSION_AUTHENTICATE_ACCOUNTS permissions.
keys - Set of keys for which to obtain the desired data.null if there is no account
created at this time.setAccountDataBundle(Bundle),
setAccountData(String, String),
UserAccountManager.getAccountDataBundle(Account, String...)@Nullable protected Account acquireAccount()
Note, that default implementation of this method assumes that there can be only one account created for this Android application. If there are multiple accounts created this method will pick the first one.
This method requires the caller to hold UserAccountManager.PERMISSION_GET_ACCOUNTS permission.
null if there is no account created yet.AccountManager.getAccountsByType(String)