android.accounts.IAccountManagerResponse

Here are the examples of the java api android.accounts.IAccountManagerResponse taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

23 Examples 7

19 Source : VAccountManagerService.java
with GNU General Public License v3.0
from codehz

@Override
public void removeAccount(final int userId, IAccountManagerResponse response, final Account account, boolean expectActivityLaunch) {
    if (response == null)
        throw new IllegalArgumentException("response is null");
    if (account == null)
        throw new IllegalArgumentException("account is null");
    AuthenticatorInfo info = this.getAuthenticatorInfo(account.type);
    if (info == null) {
        try {
            response.onError(ERROR_CODE_BAD_ARGUMENTS, "account.type does not exist");
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        return;
    }
    // FIXME: Cancel Notification
    new Session(response, userId, info, expectActivityLaunch, true, account.name) {

        @Override
        protected String toDebugString(long now) {
            return super.toDebugString(now) + ", removeAccount" + ", account " + account;
        }

        @Override
        public void run() throws RemoteException {
            mAuthenticator.getAccountRemovalAllowed(this, account);
        }

        @Override
        public void onResult(Bundle result) throws RemoteException {
            if (result != null && result.containsKey(AccountManager.KEY_BOOLEAN_RESULT) && !result.containsKey(AccountManager.KEY_INTENT)) {
                final boolean removalAllowed = result.getBoolean(AccountManager.KEY_BOOLEAN_RESULT);
                if (removalAllowed) {
                    removeAccountInternal(userId, account);
                }
                IAccountManagerResponse response = getResponseAndClose();
                if (response != null) {
                    Log.v(TAG, getClreplaced().getSimpleName() + " calling onResult() on response " + response);
                    Bundle result2 = new Bundle();
                    result2.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, removalAllowed);
                    try {
                        response.onResult(result2);
                    } catch (RemoteException e) {
                        e.printStackTrace();
                    }
                }
            }
            super.onResult(result);
        }
    }.bind();
}

19 Source : VAccountManagerService.java
with GNU General Public License v3.0
from codehz

@Override
public void hasFeatures(int userId, IAccountManagerResponse response, final Account account, final String[] features) {
    if (response == null)
        throw new IllegalArgumentException("response is null");
    if (account == null)
        throw new IllegalArgumentException("account is null");
    if (features == null)
        throw new IllegalArgumentException("features is null");
    AuthenticatorInfo info = this.getAuthenticatorInfo(account.type);
    if (info == null) {
        try {
            response.onError(ERROR_CODE_BAD_ARGUMENTS, "account.type does not exist");
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        return;
    }
    new Session(response, userId, info, false, true, account.name) {

        @Override
        public void run() throws RemoteException {
            try {
                mAuthenticator.hasFeatures(this, account, features);
            } catch (RemoteException e) {
                onError(AccountManager.ERROR_CODE_REMOTE_EXCEPTION, "remote exception");
            }
        }

        @Override
        public void onResult(Bundle result) throws RemoteException {
            IAccountManagerResponse response = getResponseAndClose();
            if (response != null) {
                try {
                    if (result == null) {
                        response.onError(AccountManager.ERROR_CODE_INVALID_RESPONSE, "null bundle");
                        return;
                    }
                    Log.v(TAG, getClreplaced().getSimpleName() + " calling onResult() on response " + response);
                    final Bundle newResult = new Bundle();
                    newResult.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, result.getBoolean(AccountManager.KEY_BOOLEAN_RESULT, false));
                    response.onResult(newResult);
                } catch (RemoteException e) {
                    // if the caller is dead then there is no one to care about remote exceptions
                    Log.v(TAG, "failure while notifying response", e);
                }
            }
        }
    }.bind();
}

19 Source : VAccountManagerService.java
with GNU General Public License v3.0
from codehz

@Override
public void editProperties(int userId, IAccountManagerResponse response, final String accountType, final boolean expectActivityLaunch) {
    if (response == null)
        throw new IllegalArgumentException("response is null");
    if (accountType == null)
        throw new IllegalArgumentException("accountType is null");
    AuthenticatorInfo info = this.getAuthenticatorInfo(accountType);
    if (info == null) {
        try {
            response.onError(ERROR_CODE_BAD_ARGUMENTS, "account.type does not exist");
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        return;
    }
    new Session(response, userId, info, expectActivityLaunch, true, null) {

        @Override
        public void run() throws RemoteException {
            mAuthenticator.editProperties(this, mAuthenticatorInfo.desc.type);
        }

        @Override
        protected String toDebugString(long now) {
            return super.toDebugString(now) + ", editProperties" + ", accountType " + accountType;
        }
    }.bind();
}

19 Source : VAccountManagerService.java
with GNU General Public License v3.0
from codehz

@Override
public void getAuthTokenLabel(int userId, IAccountManagerResponse response, final String accountType, final String authTokenType) {
    if (accountType == null)
        throw new IllegalArgumentException("accountType is null");
    if (authTokenType == null)
        throw new IllegalArgumentException("authTokenType is null");
    AuthenticatorInfo info = getAuthenticatorInfo(accountType);
    if (info == null) {
        try {
            response.onError(ERROR_CODE_BAD_ARGUMENTS, "account.type does not exist");
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        return;
    }
    new Session(response, userId, info, false, false, null) {

        @Override
        public void run() throws RemoteException {
            mAuthenticator.getAuthTokenLabel(this, authTokenType);
        }

        @Override
        public void onResult(Bundle result) throws RemoteException {
            if (result != null) {
                String label = result.getString(AccountManager.KEY_AUTH_TOKEN_LABEL);
                Bundle bundle = new Bundle();
                bundle.putString(AccountManager.KEY_AUTH_TOKEN_LABEL, label);
                super.onResult(bundle);
            } else {
                super.onResult(null);
            }
        }
    }.bind();
}

18 Source : VAccountManagerService.java
with GNU General Public License v3.0
from codehz

@Override
public void updateCredentials(int userId, final IAccountManagerResponse response, final Account account, final String authTokenType, final boolean expectActivityLaunch, final Bundle loginOptions) {
    if (response == null)
        throw new IllegalArgumentException("response is null");
    if (account == null)
        throw new IllegalArgumentException("account is null");
    if (authTokenType == null)
        throw new IllegalArgumentException("authTokenType is null");
    AuthenticatorInfo info = this.getAuthenticatorInfo(account.type);
    if (info == null) {
        try {
            response.onError(ERROR_CODE_BAD_ARGUMENTS, "account.type does not exist");
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        return;
    }
    new Session(response, userId, info, expectActivityLaunch, false, account.name) {

        @Override
        public void run() throws RemoteException {
            mAuthenticator.updateCredentials(this, account, authTokenType, loginOptions);
        }

        @Override
        protected String toDebugString(long now) {
            if (loginOptions != null)
                loginOptions.keySet();
            return super.toDebugString(now) + ", updateCredentials" + ", " + account + ", authTokenType " + authTokenType + ", loginOptions " + loginOptions;
        }
    }.bind();
}

18 Source : VAccountManagerService.java
with GNU General Public License v3.0
from codehz

private void onResult(IAccountManagerResponse response, Bundle result) {
    try {
        response.onResult(result);
    } catch (RemoteException e) {
        // if the caller is dead then there is no one to care about remote
        // exceptions
        e.printStackTrace();
    }
}

18 Source : VAccountManagerService.java
with GNU General Public License v3.0
from codehz

@Override
public void getAccountsByFeatures(int userId, IAccountManagerResponse response, String type, String[] features) {
    if (response == null)
        throw new IllegalArgumentException("response is null");
    if (type == null)
        throw new IllegalArgumentException("accountType is null");
    AuthenticatorInfo info = getAuthenticatorInfo(type);
    if (info == null) {
        Bundle bundle = new Bundle();
        bundle.putParcelableArray(AccountManager.KEY_ACCOUNTS, new Account[0]);
        try {
            response.onResult(bundle);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        return;
    }
    if (features == null || features.length == 0) {
        Bundle bundle = new Bundle();
        bundle.putParcelableArray(AccountManager.KEY_ACCOUNTS, getAccounts(userId, type));
        try {
            response.onResult(bundle);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    } else {
        new GetAccountsByTypeAndFeatureSession(response, userId, info, features).bind();
    }
}

18 Source : VAccountManagerService.java
with GNU General Public License v3.0
from codehz

@Override
public void addAccount(int userId, final IAccountManagerResponse response, final String accountType, final String authTokenType, final String[] requiredFeatures, final boolean expectActivityLaunch, final Bundle optionsIn) {
    if (response == null)
        throw new IllegalArgumentException("response is null");
    if (accountType == null)
        throw new IllegalArgumentException("accountType is null");
    AuthenticatorInfo info = getAuthenticatorInfo(accountType);
    if (info == null) {
        try {
            response.onError(ERROR_CODE_BAD_ARGUMENTS, "account.type does not exist");
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        return;
    }
    new Session(response, userId, info, expectActivityLaunch, true, null, false, true) {

        @Override
        public void run() throws RemoteException {
            mAuthenticator.addAccount(this, mAuthenticatorInfo.desc.type, authTokenType, requiredFeatures, optionsIn);
        }

        @Override
        protected String toDebugString(long now) {
            return super.toDebugString(now) + ", addAccount" + ", accountType " + accountType + ", requiredFeatures " + (requiredFeatures != null ? TextUtils.join(",", requiredFeatures) : null);
        }
    }.bind();
}

18 Source : VAccountManagerService.java
with GNU General Public License v3.0
from codehz

public void confirmCredentials(int userId, IAccountManagerResponse response, final Account account, final Bundle options, final boolean expectActivityLaunch) {
    if (response == null)
        throw new IllegalArgumentException("response is null");
    if (account == null)
        throw new IllegalArgumentException("account is null");
    AuthenticatorInfo info = getAuthenticatorInfo(account.type);
    if (info == null) {
        try {
            response.onError(ERROR_CODE_BAD_ARGUMENTS, "account.type does not exist");
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        return;
    }
    new Session(response, userId, info, expectActivityLaunch, true, account.name, true, true) {

        @Override
        public void run() throws RemoteException {
            mAuthenticator.confirmCredentials(this, account, options);
        }
    }.bind();
}

18 Source : VAccountManager.java
with GNU General Public License v3.0
from codehz

public void editProperties(IAccountManagerResponse response, String accountType, boolean expectActivityLaunch) {
    try {
        getRemote().editProperties(VUserHandle.myUserId(), response, accountType, expectActivityLaunch);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

18 Source : VAccountManager.java
with GNU General Public License v3.0
from codehz

public void getAccountsByFeatures(IAccountManagerResponse response, String type, String[] features) {
    try {
        getRemote().getAccountsByFeatures(VUserHandle.myUserId(), response, type, features);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

18 Source : VAccountManager.java
with GNU General Public License v3.0
from codehz

public void getAuthTokenLabel(IAccountManagerResponse response, String accountType, String authTokenType) {
    try {
        getRemote().getAuthTokenLabel(VUserHandle.myUserId(), response, accountType, authTokenType);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

18 Source : VAccountManager.java
with GNU General Public License v3.0
from android-hacker

public void addAccount(int userId, IAccountManagerResponse response, String accountType, String authTokenType, String[] requiredFeatures, boolean expectActivityLaunch, Bundle optionsIn) {
    try {
        getRemote().addAccount(userId, response, accountType, authTokenType, requiredFeatures, expectActivityLaunch, optionsIn);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

17 Source : VAccountManagerService.java
with GNU General Public License v3.0
from codehz

@Override
public void renameAccount(int userId, IAccountManagerResponse response, Account accountToRename, String newName) {
    if (accountToRename == null)
        throw new IllegalArgumentException("account is null");
    Account resultingAccount = renameAccountInternal(userId, accountToRename, newName);
    Bundle result = new Bundle();
    result.putString(AccountManager.KEY_ACCOUNT_NAME, resultingAccount.name);
    result.putString(AccountManager.KEY_ACCOUNT_TYPE, resultingAccount.type);
    try {
        response.onResult(result);
    } catch (RemoteException e) {
        Log.w(TAG, e.getMessage());
    }
}

17 Source : VAccountManagerService.java
with GNU General Public License v3.0
from codehz

@Override
public final void getAuthToken(final int userId, final IAccountManagerResponse response, final Account account, final String authTokenType, final boolean notifyOnAuthFailure, boolean expectActivityLaunch, final Bundle loginOptions) {
    if (response == null) {
        throw new IllegalArgumentException("response is null");
    }
    try {
        if (account == null) {
            VLog.w(TAG, "getAuthToken called with null account");
            response.onError(ERROR_CODE_BAD_ARGUMENTS, "account is null");
            return;
        }
        if (authTokenType == null) {
            VLog.w(TAG, "getAuthToken called with null authTokenType");
            response.onError(ERROR_CODE_BAD_ARGUMENTS, "authTokenType is null");
            return;
        }
    } catch (RemoteException e) {
        e.printStackTrace();
        return;
    }
    AuthenticatorInfo info = getAuthenticatorInfo(account.type);
    if (info == null) {
        try {
            response.onError(ERROR_CODE_BAD_ARGUMENTS, "account.type does not exist");
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        return;
    }
    // Get the calling package. We will use it for the purpose of caching.
    final String callerPkg = loginOptions.getString(AccountManagerCompat.KEY_ANDROID_PACKAGE_NAME);
    final boolean customTokens = info.desc.customTokens;
    loginOptions.putInt(AccountManager.KEY_CALLER_UID, VBinder.getCallingUid());
    loginOptions.putInt(AccountManager.KEY_CALLER_PID, Binder.getCallingPid());
    if (notifyOnAuthFailure) {
        loginOptions.putBoolean(AccountManagerCompat.KEY_NOTIFY_ON_FAILURE, true);
    }
    if (!customTokens) {
        VAccount vAccount;
        synchronized (accountsByUserId) {
            vAccount = getAccount(userId, account);
        }
        String authToken = vAccount != null ? vAccount.authTokens.get(authTokenType) : null;
        if (authToken != null) {
            Bundle result = new Bundle();
            result.putString(AccountManager.KEY_AUTHTOKEN, authToken);
            result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
            result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type);
            onResult(response, result);
            return;
        }
    }
    if (customTokens) {
        String authToken = getCustomAuthToken(userId, account, authTokenType, callerPkg);
        if (authToken != null) {
            Bundle result = new Bundle();
            result.putString(AccountManager.KEY_AUTHTOKEN, authToken);
            result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
            result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type);
            onResult(response, result);
            return;
        }
    }
    new Session(response, userId, info, expectActivityLaunch, false, account.name) {

        @Override
        protected String toDebugString(long now) {
            return super.toDebugString(now) + ", getAuthToken" + ", " + account + ", authTokenType " + authTokenType + ", loginOptions " + loginOptions + ", notifyOnAuthFailure " + notifyOnAuthFailure;
        }

        @Override
        public void run() throws RemoteException {
            mAuthenticator.getAuthToken(this, account, authTokenType, loginOptions);
        }

        @Override
        public void onResult(Bundle result) throws RemoteException {
            if (result != null) {
                String authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
                if (authToken != null) {
                    String name = result.getString(AccountManager.KEY_ACCOUNT_NAME);
                    String type = result.getString(AccountManager.KEY_ACCOUNT_TYPE);
                    if (TextUtils.isEmpty(type) || TextUtils.isEmpty(name)) {
                        onError(AccountManager.ERROR_CODE_INVALID_RESPONSE, "the type and name should not be empty");
                        return;
                    }
                    if (!customTokens) {
                        synchronized (accountsByUserId) {
                            VAccount account = getAccount(userId, name, type);
                            if (account == null) {
                                List<VAccount> accounts = accountsByUserId.get(userId);
                                if (accounts == null) {
                                    accounts = new ArrayList<>();
                                    accountsByUserId.put(userId, accounts);
                                }
                                account = new VAccount(userId, new Account(name, type));
                                accounts.add(account);
                                serializeAllAccounts();
                            }
                        }
                    }
                    long expiryMillis = result.getLong(AccountManagerCompat.KEY_CUSTOM_TOKEN_EXPIRY, 0L);
                    if (customTokens && expiryMillis > System.currentTimeMillis()) {
                        AuthTokenRecord record = new AuthTokenRecord(userId, account, authTokenType, callerPkg, authToken, expiryMillis);
                        synchronized (authTokenRecords) {
                            authTokenRecords.remove(record);
                            authTokenRecords.add(record);
                        }
                    }
                }
                Intent intent = result.getParcelable(AccountManager.KEY_INTENT);
                if (intent != null && notifyOnAuthFailure && !customTokens) {
                // TODO: send Signin error Notification
                }
            }
            super.onResult(result);
        }
    }.bind();
}

17 Source : VAccountManager.java
with GNU General Public License v3.0
from codehz

public void renameAccount(IAccountManagerResponse response, Account accountToRename, String newName) {
    try {
        getRemote().renameAccount(VUserHandle.myUserId(), response, accountToRename, newName);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

17 Source : VAccountManager.java
with GNU General Public License v3.0
from codehz

public void removeAccount(IAccountManagerResponse response, Account account, boolean expectActivityLaunch) {
    try {
        getRemote().removeAccount(VUserHandle.myUserId(), response, account, expectActivityLaunch);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

17 Source : VAccountManager.java
with GNU General Public License v3.0
from codehz

public void addAccount(IAccountManagerResponse response, String accountType, String authTokenType, String[] requiredFeatures, boolean expectActivityLaunch, Bundle optionsIn) {
    try {
        getRemote().addAccount(VUserHandle.myUserId(), response, accountType, authTokenType, requiredFeatures, expectActivityLaunch, optionsIn);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

17 Source : VAccountManager.java
with GNU General Public License v3.0
from codehz

public void hasFeatures(IAccountManagerResponse response, Account account, String[] features) {
    try {
        getRemote().hasFeatures(VUserHandle.myUserId(), response, account, features);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

16 Source : VAccountManager.java
with GNU General Public License v3.0
from codehz

public void updateCredentials(IAccountManagerResponse response, Account account, String authTokenType, boolean expectActivityLaunch, Bundle loginOptions) {
    try {
        getRemote().updateCredentials(VUserHandle.myUserId(), response, account, authTokenType, expectActivityLaunch, loginOptions);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

16 Source : VAccountManager.java
with GNU General Public License v3.0
from codehz

public void confirmCredentials(IAccountManagerResponse response, Account account, Bundle options, boolean expectActivityLaunch) {
    try {
        getRemote().confirmCredentials(VUserHandle.myUserId(), response, account, options, expectActivityLaunch);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

16 Source : VAccountManager.java
with GNU General Public License v3.0
from codehz

public void getAuthToken(IAccountManagerResponse response, Account account, String authTokenType, boolean notifyOnAuthFailure, boolean expectActivityLaunch, Bundle loginOptions) {
    try {
        getRemote().getAuthToken(VUserHandle.myUserId(), response, account, authTokenType, notifyOnAuthFailure, expectActivityLaunch, loginOptions);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

16 Source : AmsTask.java
with GNU General Public License v3.0
from android-hacker

public abstract clreplaced AmsTask extends FutureTask<Bundle> implements AccountManagerFuture<Bundle> {

    protected final IAccountManagerResponse mResponse;

    final Handler mHandler;

    final AccountManagerCallback<Bundle> mCallback;

    final Activity mActivity;

    public AmsTask(Activity activity, Handler handler, AccountManagerCallback<Bundle> callback) {
        super(new Callable<Bundle>() {

            @Override
            public Bundle call() throws Exception {
                throw new IllegalStateException("this should never be called");
            }
        });
        mHandler = handler;
        mCallback = callback;
        mActivity = activity;
        mResponse = new Response();
    }

    public final AccountManagerFuture<Bundle> start() {
        try {
            doWork();
        } catch (RemoteException e) {
            setException(e);
        }
        return this;
    }

    @Override
    protected void set(Bundle bundle) {
        // TODO: somehow a null is being set as the result of the Future. Log this
        // case to help debug where this is occurring. When this bug is fixed this
        // condition statement should be removed.
        if (bundle == null) {
            VLog.e("AccountManager", "the bundle must not be null", new Exception());
        }
        super.set(bundle);
    }

    public abstract void doWork() throws RemoteException;

    private Bundle internalGetResult(Long timeout, TimeUnit unit) throws OperationCanceledException, IOException, AuthenticatorException {
        try {
            if (timeout == null) {
                return get();
            } else {
                return get(timeout, unit);
            }
        } catch (CancellationException e) {
            throw new OperationCanceledException();
        } catch (TimeoutException e) {
        // fall through and cancel
        } catch (InterruptedException e) {
        // fall through and cancel
        } catch (ExecutionException e) {
            final Throwable cause = e.getCause();
            if (cause instanceof IOException) {
                throw (IOException) cause;
            } else if (cause instanceof UnsupportedOperationException) {
                throw new AuthenticatorException(cause);
            } else if (cause instanceof AuthenticatorException) {
                throw (AuthenticatorException) cause;
            } else if (cause instanceof RuntimeException) {
                throw (RuntimeException) cause;
            } else if (cause instanceof Error) {
                throw (Error) cause;
            } else {
                throw new IllegalStateException(cause);
            }
        } finally {
            cancel(true);
        }
        throw new OperationCanceledException();
    }

    @Override
    public Bundle getResult() throws OperationCanceledException, IOException, AuthenticatorException {
        return internalGetResult(null, null);
    }

    @Override
    public Bundle getResult(long timeout, TimeUnit unit) throws OperationCanceledException, IOException, AuthenticatorException {
        return internalGetResult(timeout, unit);
    }

    @Override
    protected void done() {
        if (mCallback != null) {
            postToHandler(mHandler, mCallback, this);
        }
    }

    /**
     * Handles the responses from the AccountManager
     */
    private clreplaced Response extends IAccountManagerResponse.Stub {

        @Override
        public void onResult(Bundle bundle) {
            Intent intent = bundle.getParcelable(KEY_INTENT);
            if (intent != null && mActivity != null) {
                // since the user provided an Activity we will silently start intents
                // that we see
                mActivity.startActivity(intent);
            // leave the Future running to wait for the real response to this request
            } else if (bundle.getBoolean("retry")) {
                try {
                    doWork();
                } catch (RemoteException e) {
                    throw new RuntimeException(e);
                }
            } else {
                set(bundle);
            }
        }

        @Override
        public void onError(int code, String message) {
            if (code == ERROR_CODE_CANCELED || code == ERROR_CODE_USER_RESTRICTED || code == ERROR_CODE_MANAGEMENT_DISABLED_FOR_ACCOUNT_TYPE) {
                // the authenticator indicated that this request was canceled or we were
                // forbidden to fulfill; cancel now
                cancel(true);
                return;
            }
            setException(convertErrorToException(code, message));
        }
    }

    private Exception convertErrorToException(int code, String message) {
        if (code == ERROR_CODE_NETWORK_ERROR) {
            return new IOException(message);
        }
        if (code == ERROR_CODE_UNSUPPORTED_OPERATION) {
            return new UnsupportedOperationException(message);
        }
        if (code == ERROR_CODE_INVALID_RESPONSE) {
            return new AuthenticatorException(message);
        }
        if (code == ERROR_CODE_BAD_ARGUMENTS) {
            return new IllegalArgumentException(message);
        }
        return new AuthenticatorException(message);
    }

    private void postToHandler(Handler handler, final AccountManagerCallback<Bundle> callback, final AccountManagerFuture<Bundle> future) {
        handler = handler == null ? VirtualRuntime.getUIHandler() : handler;
        handler.post(new Runnable() {

            @Override
            public void run() {
                callback.run(future);
            }
        });
    }
}