private void refreshUsingAccountManager(String token, String name) throws TokenRefreshException { if (accountManager == null) throw new TokenRefreshException("account manager is null"); invalidateToken(token); try { Bundle bundle = getAuthToken(new Account(name, GOOGLE_TYPE)); if (bundle != null) { String newToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); if (!isEmpty(newToken)) { authPreferences.setOauth2Token(name, newToken, null); } else { throw new TokenRefreshException("no new token obtained"); } } else { throw new TokenRefreshException("no bundle received from accountmanager"); } } catch (AccountsException e) { Log.w(TAG, e); throw new TokenRefreshException(e); } catch (IOException e) { Log.w(TAG, e); throw new TokenRefreshException(e); } }