Search in sources :

Example 1 with AccountManagerCallback

use of android.accounts.AccountManagerCallback in project XPrivacy by M66B.

the class XAccountManager method before.

@Override
@SuppressWarnings("unchecked")
protected void before(XParam param) throws Throwable {
    switch(mMethod) {
        case addOnAccountsUpdatedListener:
            if (param.args.length > 0 && param.args[0] != null)
                if (isRestricted(param)) {
                    int uid = Binder.getCallingUid();
                    OnAccountsUpdateListener listener = (OnAccountsUpdateListener) param.args[0];
                    XOnAccountsUpdateListener xListener;
                    synchronized (mListener) {
                        xListener = mListener.get(listener);
                        if (xListener == null) {
                            xListener = new XOnAccountsUpdateListener(listener, uid);
                            mListener.put(listener, xListener);
                            Util.log(this, Log.WARN, "Added count=" + mListener.size() + " uid=" + uid);
                        }
                    }
                    param.args[0] = xListener;
                }
            break;
        case blockingGetAuthToken:
        case getAccounts:
        case getAccountsByType:
        case getAccountsByTypeForPackage:
            // Do nothing
            break;
        case getAccountsByTypeAndFeatures:
            if (param.args.length > 2 && param.args[2] != null)
                if (isRestrictedExtra(param, (String) param.args[0])) {
                    AccountManagerCallback<Account[]> callback = (AccountManagerCallback<Account[]>) param.args[2];
                    param.args[2] = new XAccountManagerCallbackAccount(callback, Binder.getCallingUid());
                }
            break;
        case getAuthenticatorTypes:
            // Do nothing
            break;
        case getAuthToken:
            if (param.args.length > 0) {
                Account account = (Account) param.args[0];
                for (int i = 1; i < param.args.length; i++) if (param.args[i] instanceof AccountManagerCallback<?>)
                    if (isRestrictedExtra(param, account == null ? null : account.name)) {
                        AccountManagerCallback<Bundle> callback = (AccountManagerCallback<Bundle>) param.args[i];
                        param.args[i] = new XAccountManagerCallbackBundle(callback, Binder.getCallingUid());
                    }
            }
            break;
        case getAuthTokenByFeatures:
            if (param.args.length > 0)
                for (int i = 1; i < param.args.length; i++) if (param.args[i] instanceof AccountManagerCallback<?>)
                    if (isRestrictedExtra(param, (String) param.args[0])) {
                        AccountManagerCallback<Bundle> callback = (AccountManagerCallback<Bundle>) param.args[i];
                        param.args[i] = new XAccountManagerCallbackBundle(callback, Binder.getCallingUid());
                    }
            break;
        case hasFeatures:
            if (param.args.length > 0) {
                Account account = (Account) param.args[0];
                for (int i = 1; i < param.args.length; i++) if (param.args[i] instanceof AccountManagerCallback<?>)
                    if (isRestrictedExtra(param, account == null ? null : account.name)) {
                        AccountManagerCallback<Boolean> callback = (AccountManagerCallback<Boolean>) param.args[i];
                        param.args[i] = new XAccountManagerCallbackBoolean(callback);
                    }
            }
            break;
        case removeOnAccountsUpdatedListener:
            if (param.args.length > 0 && param.args[0] != null)
                synchronized (mListener) {
                    OnAccountsUpdateListener listener = (OnAccountsUpdateListener) param.args[0];
                    XOnAccountsUpdateListener xListener = mListener.get(listener);
                    if (xListener != null) {
                        param.args[0] = xListener;
                        Util.log(this, Log.WARN, "Removed count=" + mListener.size() + " uid=" + Binder.getCallingUid());
                    }
                }
            break;
        case Srv_getAccounts:
        case Srv_getAccountsAsUser:
        case Srv_getAccountsForPackage:
            // Do nothing
            break;
        case Srv_getAccountsByFeatures:
            if (param.args.length > 1 && (param.args[1] == null || param.args[1] instanceof String)) {
                if (isRestrictedExtra(param, (String) param.args[1]))
                    param.setResult(null);
            } else {
                if (isRestricted(param))
                    param.setResult(null);
            }
            break;
        case Srv_getSharedAccountsAsUser:
            // Do nothing
            break;
    }
}
Also used : Account(android.accounts.Account) AccountManagerCallback(android.accounts.AccountManagerCallback) Bundle(android.os.Bundle) OnAccountsUpdateListener(android.accounts.OnAccountsUpdateListener)

Example 2 with AccountManagerCallback

use of android.accounts.AccountManagerCallback in project android-delicious by lexs.

the class ContainerActivity method logout.

private void logout() {
    Log.d(TAG, "Removing account");
    AccountManager accountManager = AccountManager.get(this);
    Account[] accounts = accountManager.getAccountsByType(Constants.ACCOUNT_TYPE);
    Account account = accounts[0];
    // Callback to wait for the account to actually be removed
    AccountManagerCallback<Boolean> callback = new AccountManagerCallback<Boolean>() {

        @Override
        public void run(AccountManagerFuture<Boolean> future) {
            try {
                if (future.getResult()) {
                    checkAccount();
                } else {
                    // Could not remove account, should not happen
                    Log.e(TAG, "Could not remove account");
                }
            } catch (Exception e) {
                Log.e(TAG, "Error fetching remove account result", e);
            }
        }
    };
    accountManager.removeAccount(account, callback, null);
}
Also used : Account(android.accounts.Account) DeliciousAccount(se.alexanderblom.delicious.DeliciousAccount) AccountManagerCallback(android.accounts.AccountManagerCallback) AccountManager(android.accounts.AccountManager) AccountManagerFuture(android.accounts.AccountManagerFuture)

Example 3 with AccountManagerCallback

use of android.accounts.AccountManagerCallback in project android by owncloud.

the class RemoveAccountDialogFragment method onConfirmation.

/**
     * Performs the removal of the target account.
     */
@Override
public void onConfirmation(String callerTag) {
    Activity parentActivity = getActivity();
    AccountManager am = AccountManager.get(parentActivity);
    AccountManagerCallback<Boolean> callback = (AccountManagerCallback<Boolean>) parentActivity;
    am.removeAccount(mTargetAccount, callback, new Handler());
}
Also used : AccountManagerCallback(android.accounts.AccountManagerCallback) Activity(android.app.Activity) Handler(android.os.Handler) AccountManager(android.accounts.AccountManager)

Example 4 with AccountManagerCallback

use of android.accounts.AccountManagerCallback in project newsrob by marianokamp.

the class AccountManagementUtilsImplementation method getAuthToken.

public void getAuthToken(final Activity waitingActivity, Handler handler, final IAuthenticationCallback callback, String googleAccount) {
    PL.log("AMU.getAuthToken for " + googleAccount + ".", waitingActivity);
    AccountManager accountManager = AccountManager.get(waitingActivity);
    // find the selected account
    Account selectedAccount = findAccountByGoogleAccountId(waitingActivity, accountManager, googleAccount);
    if (selectedAccount == null)
        throw new RuntimeException("No account found for " + googleAccount + ".");
    final Account selAccount = selectedAccount;
    if (false)
        accountManager.getAuthTokenByFeatures(GOOGLE_ACCOUNT_TYPE, "reader", GOOGLE_ACCOUNT, waitingActivity, new Bundle(), null, new AccountManagerCallback<Bundle>() {

            public void run(android.accounts.AccountManagerFuture<Bundle> f) {
                try {
                    Bundle b = f.getResult();
                    for (String key : b.keySet()) System.out.println("key " + key + " value " + b.getByte(key));
                    String authToken = f.getResult().getString(AccountManager.KEY_AUTHTOKEN);
                    if (authToken == null)
                        throw new RuntimeException("AuthToken was null.");
                    callback.onAuthTokenReceived(selAccount.name, authToken);
                } catch (Exception e) {
                    e.printStackTrace();
                    if (e instanceof OperationCanceledException)
                        e = new Exception("Operation canceled by user.");
                    callback.onError(e);
                }
            }
        }, handler);
    if (true)
        accountManager.getAuthToken(selectedAccount, AUTH_TOKEN_TYPE_READER, null, waitingActivity, new AccountManagerCallback<Bundle>() {

            public void run(android.accounts.AccountManagerFuture<Bundle> f) {
                try {
                    String authToken = f.getResult().getString(AccountManager.KEY_AUTHTOKEN);
                    if (authToken == null)
                        throw new RuntimeException("AuthToken was null.");
                    PL.log("AMU.getAuthToken for " + selAccount.name + "received token=" + authToken.substring(0, 4) + "(2).", waitingActivity);
                    callback.onAuthTokenReceived(selAccount.name, authToken);
                } catch (Exception e) {
                    e.printStackTrace();
                    if (e instanceof OperationCanceledException)
                        e = new Exception("Operation canceled by user.");
                    callback.onError(e);
                }
            }
        }, handler);
}
Also used : Account(android.accounts.Account) AccountManagerCallback(android.accounts.AccountManagerCallback) Bundle(android.os.Bundle) OperationCanceledException(android.accounts.OperationCanceledException) AccountManager(android.accounts.AccountManager) OperationCanceledException(android.accounts.OperationCanceledException) IOException(java.io.IOException) AuthenticatorException(android.accounts.AuthenticatorException)

Aggregations

AccountManagerCallback (android.accounts.AccountManagerCallback)4 Account (android.accounts.Account)3 AccountManager (android.accounts.AccountManager)3 Bundle (android.os.Bundle)2 AccountManagerFuture (android.accounts.AccountManagerFuture)1 AuthenticatorException (android.accounts.AuthenticatorException)1 OnAccountsUpdateListener (android.accounts.OnAccountsUpdateListener)1 OperationCanceledException (android.accounts.OperationCanceledException)1 Activity (android.app.Activity)1 Handler (android.os.Handler)1 IOException (java.io.IOException)1 DeliciousAccount (se.alexanderblom.delicious.DeliciousAccount)1