Package org.robolectric.shadows
Class ShadowAccountManager
java.lang.Object
org.robolectric.shadows.ShadowAccountManager
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
__constructor__
(Context context, IAccountManager service) void
addAccount
(Account account) void
addAccount
(Account account, String... visibleToPackages) Adds an account to the AccountManager but whenAccountManager.getAccountsByTypeForPackage(String, String)
is called will be included if is in one of the #visibleToPackagesprotected AccountManagerFuture<Bundle>
addAccount
(String accountType, String authTokenType, String[] requiredFeatures, Bundle addAccountOptions, Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) protected boolean
addAccountExplicitly
(Account account, String password, Bundle userdata) void
addAuthenticator
(AuthenticatorDescription authenticator) void
addAuthenticator
(String type) protected void
addOnAccountsUpdatedListener
(OnAccountsUpdateListener listener, Handler handler, boolean updateImmediately) protected void
addOnAccountsUpdatedListener
(OnAccountsUpdateListener listener, Handler handler, boolean updateImmediately, String[] accountTypes) protected String
blockingGetAuthToken
(Account account, String authTokenType, boolean notifyAuthFailure) protected AccountManagerFuture<Bundle>
finishSession
(Bundle sessionBundle, Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) Returns sessionBundle as the result of finishSession.protected static AccountManager
protected Account[]
protected Account[]
getAccountsByType
(String type) protected AccountManagerFuture<Account[]>
getAccountsByTypeAndFeatures
(String type, String[] features, AccountManagerCallback<Account[]> callback, Handler handler) protected Account[]
getAccountsByTypeForPackage
(String type, String packageName) protected AuthenticatorDescription[]
protected AccountManagerFuture<Bundle>
getAuthToken
(Account account, String authTokenType, Bundle options, boolean notifyAuthFailure, AccountManagerCallback<Bundle> callback, Handler handler) protected AccountManagerFuture<Bundle>
getAuthToken
(Account account, String authTokenType, Bundle options, Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) Consumes and returns the nextaddAccountOptions
passed toaddAccount(android.accounts.Account)
.protected String
getPassword
(Account account) protected String
getPreviousName
(Account account) protected String
getUserData
(Account account, String key) protected AccountManagerFuture<Boolean>
hasFeatures
(Account account, String[] features, AccountManagerCallback<Boolean> callback, Handler handler) protected void
invalidateAuthToken
(String accountType, String authToken) protected String
peekAuthToken
(Account account, String tokenType) Returns the nextaddAccountOptions
passed toaddAccount(android.accounts.Account)
without consuming it.protected AccountManagerFuture<Boolean>
removeAccount
(Account account, AccountManagerCallback<Boolean> callback, Handler handler) The remove operation is posted to the givenhandler
, and will be executed according to theScheduler.IdleState
of the correspondingScheduler
.protected AccountManagerFuture<Bundle>
removeAccount
(Account account, Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) Removes the account unlesssetRemoveAccountIntent(android.content.Intent)
has been set.protected boolean
removeAccountExplicitly
(Account account) void
Removes all accounts that have been added.protected void
void
setAuthenticationErrorOnNextResponse
(boolean authenticationErrorOnNextResponse) Sets authenticator exception, which will be thrown bygetAccountsByTypeAndFeatures(java.lang.String, java.lang.String[], android.accounts.AccountManagerCallback<android.accounts.Account[]>, android.os.Handler)
.protected void
setAuthToken
(Account account, String tokenType, String authToken) void
setFeatures
(Account account, String[] accountFeatures) protected void
setPassword
(Account account, String password) void
setPreviousAccountName
(Account account, String previousName) Sets the previous name for an account, which will be returned byAccountManager.getPreviousName(Account)
.void
setRemoveAccountIntent
(Intent removeAccountIntent) Sets the intent to include in Bundle result fromremoveAccount(android.accounts.Account, android.accounts.AccountManagerCallback<java.lang.Boolean>, android.os.Handler)
if Activity is given.protected void
setUserData
(Account account, String key, String value) protected AccountManagerFuture<Bundle>
startAddAccountSession
(String accountType, String authTokenType, String[] requiredFeatures, Bundle options, Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) Returns a bundle that contains the account session bundle underAccountManager.KEY_ACCOUNT_SESSION_BUNDLE
to later be passed on toAccountManager.finishSession(Bundle,Activity,AccountManagerCallback<Bundle>,Handler)
.
-
Constructor Details
-
ShadowAccountManager
public ShadowAccountManager()
-
-
Method Details
-
__constructor__
-
get
-
getAccounts
-
getAccountsByType
-
setAuthToken
-
peekAuthToken
-
addAccountExplicitly
@Implementation protected boolean addAccountExplicitly(Account account, String password, Bundle userdata) -
blockingGetAuthToken
@Implementation protected String blockingGetAuthToken(Account account, String authTokenType, boolean notifyAuthFailure) -
removeAccount
@Implementation protected AccountManagerFuture<Boolean> removeAccount(Account account, AccountManagerCallback<Boolean> callback, Handler handler) The remove operation is posted to the givenhandler
, and will be executed according to theScheduler.IdleState
of the correspondingScheduler
. -
removeAccount
@Implementation(minSdk=22) protected AccountManagerFuture<Bundle> removeAccount(Account account, Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) Removes the account unlesssetRemoveAccountIntent(android.content.Intent)
has been set. If set, the future Bundle will include the Intent andAccountManager.KEY_BOOLEAN_RESULT
will be false. -
removeAccountExplicitly
-
removeAllAccounts
public void removeAllAccounts()Removes all accounts that have been added. -
getAuthenticatorTypes
-
addOnAccountsUpdatedListener
@Implementation protected void addOnAccountsUpdatedListener(OnAccountsUpdateListener listener, Handler handler, boolean updateImmediately) -
addOnAccountsUpdatedListener
@Implementation(minSdk=26) protected void addOnAccountsUpdatedListener(@Nullable OnAccountsUpdateListener listener, @Nullable Handler handler, boolean updateImmediately, @Nullable String[] accountTypes) -
removeOnAccountsUpdatedListener
-
getUserData
-
setUserData
-
setPassword
-
getPassword
-
invalidateAuthToken
-
startAddAccountSession
@Implementation(minSdk=26) protected AccountManagerFuture<Bundle> startAddAccountSession(String accountType, String authTokenType, String[] requiredFeatures, Bundle options, Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) Returns a bundle that contains the account session bundle underAccountManager.KEY_ACCOUNT_SESSION_BUNDLE
to later be passed on toAccountManager.finishSession(Bundle,Activity,AccountManagerCallback<Bundle>,Handler)
. The session bundle simply propagates the givenaccountType
so as not to be empty and is not encrypted as it would be in the real implementation. If an activity isn't provided, resulting bundle will only have a dummyIntent
underAccountManager.KEY_INTENT
.- Parameters:
accountType
- An authenticator must exist for the accountType, or elseAuthenticatorException
is thrown.authTokenType
- is ignored.requiredFeatures
- is ignored.options
- is ignored.activity
- if null, onlyAccountManager.KEY_INTENT
will be present in result.callback
- if not null, will be called with result bundle.handler
- is ignored.- Returns:
- future for bundle containing
AccountManager.KEY_ACCOUNT_SESSION_BUNDLE
if activity is provided, orAccountManager.KEY_INTENT
otherwise.
-
finishSession
@Implementation(minSdk=26) protected AccountManagerFuture<Bundle> finishSession(Bundle sessionBundle, Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) Returns sessionBundle as the result of finishSession.- Parameters:
sessionBundle
- is returned as the result bundle.activity
- is ignored.callback
- if not null, will be called with result bundle.handler
- is ignored.
-
addAccount
- Parameters:
account
- User account.
-
addAccount
Adds an account to the AccountManager but whenAccountManager.getAccountsByTypeForPackage(String, String)
is called will be included if is in one of the #visibleToPackages- Parameters:
account
- User account.
-
getNextAddAccountOptions
Consumes and returns the nextaddAccountOptions
passed toaddAccount(android.accounts.Account)
.- Returns:
- the next
addAccountOptions
-
peekNextAddAccountOptions
Returns the nextaddAccountOptions
passed toaddAccount(android.accounts.Account)
without consuming it.- Returns:
- the next
addAccountOptions
-
addAccount
@Implementation protected AccountManagerFuture<Bundle> addAccount(String accountType, String authTokenType, String[] requiredFeatures, Bundle addAccountOptions, Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) -
setFeatures
-
addAuthenticator
- Parameters:
authenticator
- System authenticator.
-
addAuthenticator
-
setPreviousAccountName
Sets the previous name for an account, which will be returned byAccountManager.getPreviousName(Account)
.- Parameters:
account
- User account.previousName
- Previous account name.
-
getPreviousName
- See Also:
-
getAuthToken
@Implementation protected AccountManagerFuture<Bundle> getAuthToken(Account account, String authTokenType, Bundle options, Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) -
getAuthToken
@Implementation protected AccountManagerFuture<Bundle> getAuthToken(Account account, String authTokenType, Bundle options, boolean notifyAuthFailure, AccountManagerCallback<Bundle> callback, Handler handler) -
hasFeatures
@Implementation protected AccountManagerFuture<Boolean> hasFeatures(Account account, String[] features, AccountManagerCallback<Boolean> callback, Handler handler) -
getAccountsByTypeAndFeatures
@Implementation protected AccountManagerFuture<Account[]> getAccountsByTypeAndFeatures(String type, String[] features, AccountManagerCallback<Account[]> callback, Handler handler) -
getAccountsByTypeForPackage
@Implementation(minSdk=18) protected Account[] getAccountsByTypeForPackage(String type, String packageName) -
setAuthenticationErrorOnNextResponse
public void setAuthenticationErrorOnNextResponse(boolean authenticationErrorOnNextResponse) Sets authenticator exception, which will be thrown bygetAccountsByTypeAndFeatures(java.lang.String, java.lang.String[], android.accounts.AccountManagerCallback<android.accounts.Account[]>, android.os.Handler)
.- Parameters:
authenticationErrorOnNextResponse
- to set flag that exception will be thrown on next response.
-
setRemoveAccountIntent
Sets the intent to include in Bundle result fromremoveAccount(android.accounts.Account, android.accounts.AccountManagerCallback<java.lang.Boolean>, android.os.Handler)
if Activity is given.- Parameters:
removeAccountIntent
- the intent to surface asAccountManager.KEY_INTENT
.
-
getListeners
-