@SuppressWarnings("deprecation") @Override public String getAuthToken() throws AuthFailureError { AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(mAccount, mAuthTokenType, mNotifyAuthFailure, null, null); Bundle result; try { result = future.getResult(); } catch (Exception e) { throw new AuthFailureError("Error while retrieving auth token", e); } String authToken = null; if (future.isDone() && !future.isCancelled()) { if (result.containsKey(AccountManager.KEY_INTENT)) { Intent intent = result.getParcelable(AccountManager.KEY_INTENT); throw new AuthFailureError(intent); } authToken = result.getString(AccountManager.KEY_AUTHTOKEN); } if (authToken == null) { throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType); } return authToken; }
public String getAuthToken() throws AuthFailureError { AccountManagerFuture<Bundle> future = this.mAccountManager.getAuthToken(this.mAccount, this.mAuthTokenType, this.mNotifyAuthFailure, null, null); try { Bundle result = (Bundle) future.getResult(); String authToken = null; if (future.isDone() && !future.isCancelled()) { if (result.containsKey("intent")) { throw new AuthFailureError((Intent) result.getParcelable("intent")); } authToken = result.getString("authtoken"); } if (authToken != null) { return authToken; } throw new AuthFailureError("Got null auth token for type: " + this.mAuthTokenType); } catch (Exception e) { throw new AuthFailureError("Error while retrieving auth token", e); } }
/** * Asks the user to add an account of a specified type. The authenticator * for this account type processes this request with the appropriate user * interface. If the user does elect to create a new account, the account * name is returned. * <p> * <p>This method may be called from any thread, but the returned * {@link AccountManagerFuture} must not be used on the main thread. * <p> * */ public AccountManagerFuture<Bundle> addAccount(final int userId, final String accountType, final String authTokenType, final String[] requiredFeatures, final Bundle addAccountOptions, final Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) { if (accountType == null) throw new IllegalArgumentException("accountType is null"); final Bundle optionsIn = new Bundle(); if (addAccountOptions != null) { optionsIn.putAll(addAccountOptions); } optionsIn.putString(KEY_ANDROID_PACKAGE_NAME, "android"); return new AmsTask(activity, handler, callback) { @Override public void doWork() throws RemoteException { addAccount(userId, mResponse, accountType, authTokenType, requiredFeatures, activity != null, optionsIn); } }.start(); }
private void invalidateAuthToken(final Account account, String authTokenType) { final AccountManagerFuture<Bundle> future = accountManager.getAuthToken(account, authTokenType, null, this, null, null); new Thread(new Runnable() { @Override public void run() { try { Bundle bnd = future.getResult(); final String authtoken = bnd.getString(AccountManager.KEY_AUTHTOKEN); accountManager.invalidateAuthToken(account.type, authtoken); Log.d("MainActivity", account.name + " invalidated"); } catch (Exception e) { e.printStackTrace(); showMessage(e.getMessage()); } } }).start(); }
@SuppressWarnings("deprecation") @Override public String getAuthToken() throws AuthFailureError { final AccountManager accountManager = AccountManager.get(mContext); AccountManagerFuture<Bundle> future = accountManager.getAuthToken(mAccount, mAuthTokenType, mNotifyAuthFailure, null, null); Bundle result; try { result = future.getResult(); } catch (Exception e) { throw new AuthFailureError("Error while retrieving auth token", e); } String authToken = null; if (future.isDone() && !future.isCancelled()) { if (result.containsKey(AccountManager.KEY_INTENT)) { Intent intent = result.getParcelable(AccountManager.KEY_INTENT); throw new AuthFailureError(intent); } authToken = result.getString(AccountManager.KEY_AUTHTOKEN); } if (authToken == null) { throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType); } return authToken; }
private void removeAccount(final Account account) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); sharedPreferences.edit().remove("queueName").apply(); ContentResolver.setIsSyncable(account, WEBINSTALL_SYNC_AUTHORITY, 0); ContentResolver.setSyncAutomatically(account, MyAccountActivity.WEBINSTALL_SYNC_AUTHORITY, false); if(Build.VERSION.SDK_INT>=8){ ContentResolver.removePeriodicSync(account, MyAccountActivity.WEBINSTALL_SYNC_AUTHORITY, new Bundle()); } mAccountManager.removeAccount(account, new AccountManagerCallback<Boolean>() { @Override public void run(AccountManagerFuture<Boolean> future) { addAccount(); finish(); } }, null); }
private void addAccount() { mAccountManager.addAccount(Aptoide.getConfiguration().getAccountType(), AptoideConfiguration.AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS, null, null, this, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { Bundle bnd = future.getResult(); if (bnd.containsKey(AccountManager.KEY_AUTHTOKEN)) { setContentView(R.layout.form_logout); } else { finish(); } } catch (Exception e) { e.printStackTrace(); } } }, null); }
private void addNewAccount() { mAccountManager.addAccount(EnlightnsAccountAuthenticator.ACCOUNT_TYPE, EnlightnsAccountAuthenticator.AUTH_TOKEN_TYPE, null, null, this, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { Bundle bnd = future.getResult(); showMessage(getString(R.string.successful_login_toast)); new GetUserRecordsTask().execute(); Log.d(TAG, "AddNewAccount Bundle is " + bnd); } catch (OperationCanceledException oce) { Log.d(TAG, "Operation cancelled, no account available, exiting...", oce); finish(); } catch (Exception e) { Log.w(TAG, "Exception", e); showMessage(getString(R.string.login_error)); } } }, null); }
@Override public String getAuthToken() throws AuthFailureError { final AccountManager accountManager = AccountManager.get(mContext); AccountManagerFuture<Bundle> future = accountManager.getAuthToken(mAccount, mAuthTokenType, mNotifyAuthFailure, null, null); Bundle result; try { result = future.getResult(); } catch (Exception e) { throw new AuthFailureError("Error while retrieving auth token", e); } String authToken = null; if (future.isDone() && !future.isCancelled()) { if (result.containsKey(AccountManager.KEY_INTENT)) { Intent intent = result.getParcelable(AccountManager.KEY_INTENT); throw new AuthFailureError(intent); } authToken = result.getString(AccountManager.KEY_AUTHTOKEN); } if (authToken == null) { throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType); } return authToken; }
/** * Remove account from Android system */ @SuppressWarnings("deprecation") public boolean removeAccount() { Log.d(getClass().getSimpleName(), "Removing account : " + account.name); AccountManager accountManager = AccountManager.get(context); // remove account AccountManagerFuture accountManagerFuture; if(android.os.Build.VERSION.SDK_INT < 23) { accountManagerFuture = accountManager.removeAccount(account, null, null); } else { accountManagerFuture = accountManager.removeAccount(account, null, null, null); } if (accountManagerFuture.isDone()) { try { accountManagerFuture.getResult(); return true; } catch (Exception e) { Log.e(getClass().getSimpleName(), "Problem while removing account!", e); return false; } } else { return false; } }
@Override public void run(AccountManagerFuture<Bundle> result) { try { Log.d(LOGTAG, "OnGMailTokenAcquired::run() begin"); GMailHandler myHandler = new GMailHandler(getFragmentManager(), ListManager.this); Bundle bundle = result.getResult(); final String oAuth2Token = bundle.getString(AccountManager.KEY_AUTHTOKEN); gmailImapReader = new Thread(new GMailImapReader(delayInMillis, accounts[getAccountIndex()].name, myHandler, oAuth2Token)); gmailImapReader.start(); gmailImapRemover = new Thread(new DeleteEmailViaImap(accounts[getAccountIndex()].name, oAuth2Token, emailsToBeRemoved)); gmailImapRemover.start(); gmailSmtpWriter = new Thread(new ShareByEmail(accounts[getAccountIndex()].name, oAuth2Token, emailsToSend)); gmailSmtpWriter.start(); Log.d(LOGTAG, "OnGMailTokenAcquired::run() end"); } catch (Exception e) { Log.d(LOGTAG, "OnTokenAcquired()", e); } }
@Override public void run(AccountManagerFuture<Bundle> result) { try { Bundle bundle; bundle = result.getResult(); Intent intent = (Intent) bundle.get(AccountManager.KEY_INTENT); if (intent != null) { this.parent.startActivity(intent); } else { this.auth_token = bundle .getString(AccountManager.KEY_AUTHTOKEN); this.loginUrl = this.loginUrl + "/_ah/login"; String request = "?continue=" + URLEncoder.encode("nowhere", "UTF-8") + "&auth=" + this.auth_token; URL url = new URL(this.loginUrl); Runnable runnable = new GetCookieRunnable(this.parent, url, request, this.localListener); new Thread(runnable).start(); } } catch (Exception e) { throw new RuntimeException(e); } }
private void fetchPioneerAccount() { String ACCOUNT_TYPE = "com.github.baoti"; String AUTH_TOKEN_TYPE = "pioneer"; accountManager.getAuthTokenByFeatures(ACCOUNT_TYPE, AUTH_TOKEN_TYPE, null, getView().getActivity(), null, null, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { Bundle result = future.getResult(); String name = result.getString(AccountManager.KEY_ACCOUNT_NAME); String type = result.getString(AccountManager.KEY_ACCOUNT_TYPE); String token = result.getString(AccountManager.KEY_AUTHTOKEN); toaster.show( String.format("Auth result - name: %s, type: %s, token: %s", name, type, token)); } catch (Exception e) { e.printStackTrace(); } } }, null); }
public final void run(AccountManagerFuture<Bundle> paramAccountManagerFuture) { try { if (this.a.i()) { Intent localIntent = (Intent)((Bundle)paramAccountManagerFuture.getResult()).getParcelable("intent"); gkl localgkl = this.b; bw localbw = this.a.h(); gko localgko = (gko)localbw.a("new.account.launcher"); if (localgko == null) { localgko = new gko(); localbw.a().a(localgko, "new.account.launcher").c(); } gkn localgkn = new gkn(localgkl, localgko, localIntent); efj.m().post(localgkn); } return; } catch (Exception localException) { throw new IllegalStateException(localException); } }