/** * Gets the auth token synchronously. * * <p>- Assumes that the account is a valid account. - Should not be called on the main thread. */ @Deprecated public String getAuthTokenFromBackground(Account account, String authTokenType) { AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(account, authTokenType, false, null, null); AtomicBoolean errorEncountered = new AtomicBoolean(false); return getAuthTokenInner(future, errorEncountered); }
private void getAuthTokenAsynchronously( @Nullable Activity activity, final Account account, final String authTokenType, final GetAuthTokenCallback callback, final AtomicInteger numTries, final AtomicBoolean errorEncountered, final ConnectionRetry retry) { AccountManagerFuture<Bundle> future; if (numTries.get() == 0 && activity != null) { future = mAccountManager.getAuthToken(account, authTokenType, null, activity, null, null); } else { future = mAccountManager.getAuthToken(account, authTokenType, false, null, null); } final AccountManagerFuture<Bundle> finalFuture = future; errorEncountered.set(false); // On ICS onPostExecute is never called when running an AsyncTask from a different thread // than the UI thread. if (ThreadUtils.runningOnUiThread()) { new AsyncTask<Void, Void, String>() { @Override public String doInBackground(Void... params) { return getAuthTokenInner(finalFuture, errorEncountered); } @Override public void onPostExecute(String authToken) { onGotAuthTokenResult( account, authTokenType, authToken, callback, numTries, errorEncountered, retry); } }.execute(); } else { String authToken = getAuthTokenInner(finalFuture, errorEncountered); onGotAuthTokenResult( account, authTokenType, authToken, callback, numTries, errorEncountered, retry); } }