Package org.robolectric.shadows
Class ShadowAccountManager
- java.lang.Object
-
- org.robolectric.shadows.ShadowAccountManager
-
@Implements(android.accounts.AccountManager.class) public class ShadowAccountManager extends Object
-
-
Constructor Summary
Constructors Constructor Description ShadowAccountManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected 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
get(Context context)
Deprecated.This method will be removed in Robolectric 3.4 UseAccountManager.get(Context)
instead.protected Account[]
getAccounts()
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[]
getAuthenticatorTypes()
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)
Map<OnAccountsUpdateListener,Set<String>>
getListeners()
Bundle
getNextAddAccountOptions()
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)
Bundle
peekNextAddAccountOptions()
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
removeAllAccounts()
Removes all accounts that have been added.protected void
removeOnAccountsUpdatedListener(OnAccountsUpdateListener listener)
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
.,Handler)
-
-
-
Method Detail
-
__constructor__
@Implementation protected void __constructor__(Context context, IAccountManager service)
-
get
@Deprecated @Implementation protected static AccountManager get(Context context)
Deprecated.This method will be removed in Robolectric 3.4 UseAccountManager.get(Context)
instead.
-
getAccounts
@Implementation protected Account[] getAccounts()
-
getAccountsByType
@Implementation protected Account[] getAccountsByType(String type)
-
setAuthToken
@Implementation protected void setAuthToken(Account account, String tokenType, String authToken)
-
peekAuthToken
@Implementation protected String peekAuthToken(Account account, String tokenType)
-
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
@Implementation(minSdk=22) protected boolean removeAccountExplicitly(Account account)
-
removeAllAccounts
public void removeAllAccounts()
Removes all accounts that have been added.
-
getAuthenticatorTypes
@Implementation protected AuthenticatorDescription[] 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
@Implementation protected void removeOnAccountsUpdatedListener(OnAccountsUpdateListener listener)
-
getUserData
@Implementation protected String getUserData(Account account, String key)
-
setUserData
@Implementation protected void setUserData(Account account, String key, String value)
-
setPassword
@Implementation protected void setPassword(Account account, String password)
-
getPassword
@Implementation protected String getPassword(Account account)
-
invalidateAuthToken
@Implementation protected void invalidateAuthToken(String accountType, String authToken)
-
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
. The session bundle simply propagates the given,Handler) accountType
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
public void addAccount(Account account)
- Parameters:
account
- User account.
-
addAccount
public 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 #visibleToPackages- Parameters:
account
- User account.
-
getNextAddAccountOptions
public Bundle getNextAddAccountOptions()
Consumes and returns the nextaddAccountOptions
passed toaddAccount(android.accounts.Account)
.- Returns:
- the next
addAccountOptions
-
peekNextAddAccountOptions
public Bundle 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)
-
addAuthenticator
public void addAuthenticator(AuthenticatorDescription authenticator)
- Parameters:
authenticator
- System authenticator.
-
addAuthenticator
public void addAuthenticator(String type)
-
setPreviousAccountName
public void setPreviousAccountName(Account account, String previousName)
Sets the previous name for an account, which will be returned byAccountManager.getPreviousName(Account)
.- Parameters:
account
- User account.previousName
- Previous account name.
-
getPreviousName
@Implementation(minSdk=21) protected String getPreviousName(Account account)
- See Also:
setPreviousAccountName(Account, String)
-
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
public 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.- Parameters:
removeAccountIntent
- the intent to surface asAccountManager.KEY_INTENT
.
-
getListeners
public Map<OnAccountsUpdateListener,Set<String>> getListeners()
-
-