Search in sources :

Example 6 with Account

use of android.accounts.Account in project android_frameworks_base by ParanoidAndroid.

the class KeyguardAccountView method asyncCheckPassword.

private void asyncCheckPassword() {
    mCallback.userActivity(AWAKE_POKE_MILLIS);
    final String login = mLogin.getText().toString();
    final String password = mPassword.getText().toString();
    Account account = findIntendedAccount(login);
    if (account == null) {
        postOnCheckPasswordResult(false);
        return;
    }
    getProgressDialog().show();
    Bundle options = new Bundle();
    options.putString(AccountManager.KEY_PASSWORD, password);
    AccountManager.get(mContext).confirmCredentialsAsUser(account, options, null, /* activity */
    new AccountManagerCallback<Bundle>() {

        public void run(AccountManagerFuture<Bundle> future) {
            try {
                mCallback.userActivity(AWAKE_POKE_MILLIS);
                final Bundle result = future.getResult();
                final boolean verified = result.getBoolean(AccountManager.KEY_BOOLEAN_RESULT);
                postOnCheckPasswordResult(verified);
            } catch (OperationCanceledException e) {
                postOnCheckPasswordResult(false);
            } catch (IOException e) {
                postOnCheckPasswordResult(false);
            } catch (AuthenticatorException e) {
                postOnCheckPasswordResult(false);
            } finally {
                mLogin.post(new Runnable() {

                    public void run() {
                        getProgressDialog().hide();
                    }
                });
            }
        }
    }, null, /* handler */
    new UserHandle(mLockPatternUtils.getCurrentUser()));
}
Also used : Account(android.accounts.Account) Bundle(android.os.Bundle) OperationCanceledException(android.accounts.OperationCanceledException) UserHandle(android.os.UserHandle) AuthenticatorException(android.accounts.AuthenticatorException) IOException(java.io.IOException)

Example 7 with Account

use of android.accounts.Account in project android_frameworks_base by ParanoidAndroid.

the class AccountManagerService method getAccountsByFeatures.

public void getAccountsByFeatures(IAccountManagerResponse response, String type, String[] features) {
    if (Log.isLoggable(TAG, Log.VERBOSE)) {
        Log.v(TAG, "getAccounts: accountType " + type + ", response " + response + ", features " + stringArrayToString(features) + ", caller's uid " + Binder.getCallingUid() + ", pid " + Binder.getCallingPid());
    }
    if (response == null)
        throw new IllegalArgumentException("response is null");
    if (type == null)
        throw new IllegalArgumentException("accountType is null");
    checkReadAccountsPermission();
    UserAccounts userAccounts = getUserAccountsForCaller();
    int callingUid = Binder.getCallingUid();
    long identityToken = clearCallingIdentity();
    try {
        if (features == null || features.length == 0) {
            Account[] accounts;
            synchronized (userAccounts.cacheLock) {
                accounts = getAccountsFromCacheLocked(userAccounts, type, callingUid, null);
            }
            Bundle result = new Bundle();
            result.putParcelableArray(AccountManager.KEY_ACCOUNTS, accounts);
            onResult(response, result);
            return;
        }
        new GetAccountsByTypeAndFeatureSession(userAccounts, response, type, features, callingUid).bind();
    } finally {
        restoreCallingIdentity(identityToken);
    }
}
Also used : Account(android.accounts.Account) Bundle(android.os.Bundle)

Example 8 with Account

use of android.accounts.Account in project android_frameworks_base by ParanoidAndroid.

the class AccountManagerService method getAuthToken.

public void getAuthToken(IAccountManagerResponse response, final Account account, final String authTokenType, final boolean notifyOnAuthFailure, final boolean expectActivityLaunch, Bundle loginOptionsIn) {
    if (Log.isLoggable(TAG, Log.VERBOSE)) {
        Log.v(TAG, "getAuthToken: " + account + ", response " + response + ", authTokenType " + authTokenType + ", notifyOnAuthFailure " + notifyOnAuthFailure + ", expectActivityLaunch " + expectActivityLaunch + ", caller's uid " + Binder.getCallingUid() + ", pid " + Binder.getCallingPid());
    }
    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");
    checkBinderPermission(Manifest.permission.USE_CREDENTIALS);
    final UserAccounts accounts = getUserAccountsForCaller();
    final RegisteredServicesCache.ServiceInfo<AuthenticatorDescription> authenticatorInfo;
    authenticatorInfo = mAuthenticatorCache.getServiceInfo(AuthenticatorDescription.newKey(account.type), accounts.userId);
    final boolean customTokens = authenticatorInfo != null && authenticatorInfo.type.customTokens;
    // restricted account.
    if (!ArrayUtils.contains(getAccounts((String) null), account)) {
        throw new IllegalArgumentException("no such account");
    }
    // skip the check if customTokens
    final int callerUid = Binder.getCallingUid();
    final boolean permissionGranted = customTokens || permissionIsGranted(account, authTokenType, callerUid);
    final Bundle loginOptions = (loginOptionsIn == null) ? new Bundle() : loginOptionsIn;
    // let authenticator know the identity of the caller
    loginOptions.putInt(AccountManager.KEY_CALLER_UID, callerUid);
    loginOptions.putInt(AccountManager.KEY_CALLER_PID, Binder.getCallingPid());
    if (notifyOnAuthFailure) {
        loginOptions.putBoolean(AccountManager.KEY_NOTIFY_ON_FAILURE, true);
    }
    long identityToken = clearCallingIdentity();
    try {
        // route of starting a Session
        if (!customTokens && permissionGranted) {
            String authToken = readAuthTokenInternal(accounts, account, authTokenType);
            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(accounts, response, account.type, expectActivityLaunch, false) {

            /* stripAuthTokenFromResult */
            protected String toDebugString(long now) {
                if (loginOptions != null)
                    loginOptions.keySet();
                return super.toDebugString(now) + ", getAuthToken" + ", " + account + ", authTokenType " + authTokenType + ", loginOptions " + loginOptions + ", notifyOnAuthFailure " + notifyOnAuthFailure;
            }

            public void run() throws RemoteException {
                // "grant permission" intent instead of the "getAuthToken" intent.
                if (!permissionGranted) {
                    mAuthenticator.getAuthTokenLabel(this, authTokenType);
                } else {
                    mAuthenticator.getAuthToken(this, account, authTokenType, loginOptions);
                }
            }

            public void onResult(Bundle result) {
                if (result != null) {
                    if (result.containsKey(AccountManager.KEY_AUTH_TOKEN_LABEL)) {
                        Intent intent = newGrantCredentialsPermissionIntent(account, callerUid, new AccountAuthenticatorResponse(this), authTokenType, result.getString(AccountManager.KEY_AUTH_TOKEN_LABEL));
                        Bundle bundle = new Bundle();
                        bundle.putParcelable(AccountManager.KEY_INTENT, intent);
                        onResult(bundle);
                        return;
                    }
                    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) {
                            saveAuthTokenToDatabase(mAccounts, new Account(name, type), authTokenType, authToken);
                        }
                    }
                    Intent intent = result.getParcelable(AccountManager.KEY_INTENT);
                    if (intent != null && notifyOnAuthFailure && !customTokens) {
                        doNotification(mAccounts, account, result.getString(AccountManager.KEY_AUTH_FAILED_MESSAGE), intent, accounts.userId);
                    }
                }
                super.onResult(result);
            }
        }.bind();
    } finally {
        restoreCallingIdentity(identityToken);
    }
}
Also used : Account(android.accounts.Account) Bundle(android.os.Bundle) IAccountAuthenticatorResponse(android.accounts.IAccountAuthenticatorResponse) AccountAuthenticatorResponse(android.accounts.AccountAuthenticatorResponse) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) AuthenticatorDescription(android.accounts.AuthenticatorDescription) RemoteException(android.os.RemoteException) RegisteredServicesCache(android.content.pm.RegisteredServicesCache)

Example 9 with Account

use of android.accounts.Account in project android_frameworks_base by ParanoidAndroid.

the class AccountManagerService method getAccounts.

private AccountAndUser[] getAccounts(int[] userIds) {
    final ArrayList<AccountAndUser> runningAccounts = Lists.newArrayList();
    synchronized (mUsers) {
        for (int userId : userIds) {
            UserAccounts userAccounts = getUserAccounts(userId);
            if (userAccounts == null)
                continue;
            synchronized (userAccounts.cacheLock) {
                Account[] accounts = getAccountsFromCacheLocked(userAccounts, null, Binder.getCallingUid(), null);
                for (int a = 0; a < accounts.length; a++) {
                    runningAccounts.add(new AccountAndUser(accounts[a], userId));
                }
            }
        }
    }
    AccountAndUser[] accountsArray = new AccountAndUser[runningAccounts.size()];
    return runningAccounts.toArray(accountsArray);
}
Also used : Account(android.accounts.Account) AccountAndUser(android.accounts.AccountAndUser)

Example 10 with Account

use of android.accounts.Account in project android_frameworks_base by ParanoidAndroid.

the class AccountManagerService method getSharedAccountsAsUser.

@Override
public Account[] getSharedAccountsAsUser(int userId) {
    userId = handleIncomingUser(userId);
    UserAccounts accounts = getUserAccounts(userId);
    ArrayList<Account> accountList = new ArrayList<Account>();
    Cursor cursor = null;
    try {
        cursor = accounts.openHelper.getReadableDatabase().query(TABLE_SHARED_ACCOUNTS, new String[] { ACCOUNTS_NAME, ACCOUNTS_TYPE }, null, null, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            int nameIndex = cursor.getColumnIndex(ACCOUNTS_NAME);
            int typeIndex = cursor.getColumnIndex(ACCOUNTS_TYPE);
            do {
                accountList.add(new Account(cursor.getString(nameIndex), cursor.getString(typeIndex)));
            } while (cursor.moveToNext());
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    Account[] accountArray = new Account[accountList.size()];
    accountList.toArray(accountArray);
    return accountArray;
}
Also used : Account(android.accounts.Account) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Aggregations

Account (android.accounts.Account)548 Bundle (android.os.Bundle)108 AccountManager (android.accounts.AccountManager)78 Test (org.junit.Test)53 ArrayList (java.util.ArrayList)49 Intent (android.content.Intent)40 File (java.io.File)37 Cursor (android.database.Cursor)31 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)29 PersistableBundle (android.os.PersistableBundle)27 UserInfo (android.content.pm.UserInfo)22 MockContentResolver (android.test.mock.MockContentResolver)22 HashMap (java.util.HashMap)20 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)20 RemoteException (android.os.RemoteException)19 FileOutputStream (java.io.FileOutputStream)19 IOException (java.io.IOException)19 SmallTest (android.test.suitebuilder.annotation.SmallTest)18 HashSet (java.util.HashSet)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16