diff options
Diffstat (limited to 'src/main/java/com/android/volley/toolbox/AndroidAuthenticator.java')
-rw-r--r-- | src/main/java/com/android/volley/toolbox/AndroidAuthenticator.java | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/main/java/com/android/volley/toolbox/AndroidAuthenticator.java b/src/main/java/com/android/volley/toolbox/AndroidAuthenticator.java index 73468b9..72271fc 100644 --- a/src/main/java/com/android/volley/toolbox/AndroidAuthenticator.java +++ b/src/main/java/com/android/volley/toolbox/AndroidAuthenticator.java @@ -16,8 +16,6 @@ package com.android.volley.toolbox; -import com.android.volley.AuthFailureError; - import android.accounts.Account; import android.accounts.AccountManager; import android.accounts.AccountManagerFuture; @@ -25,10 +23,12 @@ import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.support.annotation.VisibleForTesting; +import com.android.volley.AuthFailureError; /** - * An Authenticator that uses {@link AccountManager} to get auth - * tokens of a specified type for a specified account. + * An Authenticator that uses {@link AccountManager} to get auth tokens of a specified type for a + * specified account. */ // TODO: Update this to account for runtime permissions @SuppressLint("MissingPermission") @@ -40,45 +40,46 @@ public class AndroidAuthenticator implements Authenticator { /** * Creates a new authenticator. + * * @param context Context for accessing AccountManager * @param account Account to authenticate as * @param authTokenType Auth token type passed to AccountManager */ public AndroidAuthenticator(Context context, Account account, String authTokenType) { - this(context, account, authTokenType, false); + this(context, account, authTokenType, /* notifyAuthFailure= */ false); } /** * Creates a new authenticator. + * * @param context Context for accessing AccountManager * @param account Account to authenticate as * @param authTokenType Auth token type passed to AccountManager * @param notifyAuthFailure Whether to raise a notification upon auth failure */ - public AndroidAuthenticator(Context context, Account account, String authTokenType, - boolean notifyAuthFailure) { + public AndroidAuthenticator( + Context context, Account account, String authTokenType, boolean notifyAuthFailure) { this(AccountManager.get(context), account, authTokenType, notifyAuthFailure); } - // Visible for testing. Allows injection of a mock AccountManager. - AndroidAuthenticator(AccountManager accountManager, Account account, - String authTokenType, boolean notifyAuthFailure) { + @VisibleForTesting + AndroidAuthenticator( + AccountManager accountManager, + Account account, + String authTokenType, + boolean notifyAuthFailure) { mAccountManager = accountManager; mAccount = account; mAuthTokenType = authTokenType; mNotifyAuthFailure = notifyAuthFailure; } - /** - * Returns the Account being used by this authenticator. - */ + /** Returns the Account being used by this authenticator. */ public Account getAccount() { return mAccount; } - /** - * Returns the Auth Token Type used by this authenticator. - */ + /** Returns the Auth Token Type used by this authenticator. */ public String getAuthTokenType() { return mAuthTokenType; } @@ -87,8 +88,13 @@ public class AndroidAuthenticator implements Authenticator { @SuppressWarnings("deprecation") @Override public String getAuthToken() throws AuthFailureError { - AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(mAccount, - mAuthTokenType, mNotifyAuthFailure, null, null); + AccountManagerFuture<Bundle> future = + mAccountManager.getAuthToken( + mAccount, + mAuthTokenType, + mNotifyAuthFailure, + /* callback= */ null, + /* handler= */ null); Bundle result; try { result = future.getResult(); |