Search in sources :

Example 11 with Account

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

the class AccountManagerService method getCredentialPermissionNotificationId.

private Integer getCredentialPermissionNotificationId(Account account, String authTokenType, int uid) {
    Integer id;
    UserAccounts accounts = getUserAccounts(UserHandle.getUserId(uid));
    synchronized (accounts.credentialsPermissionNotificationIds) {
        final Pair<Pair<Account, String>, Integer> key = new Pair<Pair<Account, String>, Integer>(new Pair<Account, String>(account, authTokenType), uid);
        id = accounts.credentialsPermissionNotificationIds.get(key);
        if (id == null) {
            id = mNotificationIds.incrementAndGet();
            accounts.credentialsPermissionNotificationIds.put(key, id);
        }
    }
    return id;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Account(android.accounts.Account) Pair(android.util.Pair)

Example 12 with Account

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

the class AccountManagerService method dumpUser.

private void dumpUser(UserAccounts userAccounts, FileDescriptor fd, PrintWriter fout, String[] args, boolean isCheckinRequest) {
    synchronized (userAccounts.cacheLock) {
        final SQLiteDatabase db = userAccounts.openHelper.getReadableDatabase();
        if (isCheckinRequest) {
            // This is a checkin request. *Only* upload the account types and the count of each.
            Cursor cursor = db.query(TABLE_ACCOUNTS, ACCOUNT_TYPE_COUNT_PROJECTION, null, null, ACCOUNTS_TYPE, null, null);
            try {
                while (cursor.moveToNext()) {
                    // print type,count
                    fout.println(cursor.getString(0) + "," + cursor.getString(1));
                }
            } finally {
                if (cursor != null) {
                    cursor.close();
                }
            }
        } else {
            Account[] accounts = getAccountsFromCacheLocked(userAccounts, null, /* type */
            Process.myUid(), null);
            fout.println("Accounts: " + accounts.length);
            for (Account account : accounts) {
                fout.println("  " + account);
            }
            fout.println();
            synchronized (mSessions) {
                final long now = SystemClock.elapsedRealtime();
                fout.println("Active Sessions: " + mSessions.size());
                for (Session session : mSessions.values()) {
                    fout.println("  " + session.toDebugString(now));
                }
            }
            fout.println();
            mAuthenticatorCache.dump(fd, fout, args, userAccounts.userId);
        }
    }
}
Also used : Account(android.accounts.Account) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor)

Example 13 with Account

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

the class AccountManagerService method validateAccountsInternal.

/**
     * Validate internal set of accounts against installed authenticators for
     * given user. Clear cached authenticators before validating when requested.
     */
private void validateAccountsInternal(UserAccounts accounts, boolean invalidateAuthenticatorCache) {
    if (invalidateAuthenticatorCache) {
        mAuthenticatorCache.invalidateCache(accounts.userId);
    }
    final HashSet<AuthenticatorDescription> knownAuth = Sets.newHashSet();
    for (RegisteredServicesCache.ServiceInfo<AuthenticatorDescription> service : mAuthenticatorCache.getAllServices(accounts.userId)) {
        knownAuth.add(service.type);
    }
    synchronized (accounts.cacheLock) {
        final SQLiteDatabase db = accounts.openHelper.getWritableDatabase();
        boolean accountDeleted = false;
        Cursor cursor = db.query(TABLE_ACCOUNTS, new String[] { ACCOUNTS_ID, ACCOUNTS_TYPE, ACCOUNTS_NAME }, null, null, null, null, null);
        try {
            accounts.accountCache.clear();
            final HashMap<String, ArrayList<String>> accountNamesByType = new LinkedHashMap<String, ArrayList<String>>();
            while (cursor.moveToNext()) {
                final long accountId = cursor.getLong(0);
                final String accountType = cursor.getString(1);
                final String accountName = cursor.getString(2);
                if (!knownAuth.contains(AuthenticatorDescription.newKey(accountType))) {
                    Slog.w(TAG, "deleting account " + accountName + " because type " + accountType + " no longer has a registered authenticator");
                    db.delete(TABLE_ACCOUNTS, ACCOUNTS_ID + "=" + accountId, null);
                    accountDeleted = true;
                    final Account account = new Account(accountName, accountType);
                    accounts.userDataCache.remove(account);
                    accounts.authTokenCache.remove(account);
                } else {
                    ArrayList<String> accountNames = accountNamesByType.get(accountType);
                    if (accountNames == null) {
                        accountNames = new ArrayList<String>();
                        accountNamesByType.put(accountType, accountNames);
                    }
                    accountNames.add(accountName);
                }
            }
            for (Map.Entry<String, ArrayList<String>> cur : accountNamesByType.entrySet()) {
                final String accountType = cur.getKey();
                final ArrayList<String> accountNames = cur.getValue();
                final Account[] accountsForType = new Account[accountNames.size()];
                int i = 0;
                for (String accountName : accountNames) {
                    accountsForType[i] = new Account(accountName, accountType);
                    ++i;
                }
                accounts.accountCache.put(accountType, accountsForType);
            }
        } finally {
            cursor.close();
            if (accountDeleted) {
                sendAccountsChangedBroadcast(accounts.userId);
            }
        }
    }
}
Also used : Account(android.accounts.Account) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) LinkedHashMap(java.util.LinkedHashMap) AuthenticatorDescription(android.accounts.AuthenticatorDescription) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) RegisteredServicesCache(android.content.pm.RegisteredServicesCache)

Example 14 with Account

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

the class AccountManagerService method removeAccountFromCacheLocked.

private void removeAccountFromCacheLocked(UserAccounts accounts, Account account) {
    final Account[] oldAccountsForType = accounts.accountCache.get(account.type);
    if (oldAccountsForType != null) {
        ArrayList<Account> newAccountsList = new ArrayList<Account>();
        for (Account curAccount : oldAccountsForType) {
            if (!curAccount.equals(account)) {
                newAccountsList.add(curAccount);
            }
        }
        if (newAccountsList.isEmpty()) {
            accounts.accountCache.remove(account.type);
        } else {
            Account[] newAccountsForType = new Account[newAccountsList.size()];
            newAccountsForType = newAccountsList.toArray(newAccountsForType);
            accounts.accountCache.put(account.type, newAccountsForType);
        }
    }
    accounts.userDataCache.remove(account);
    accounts.authTokenCache.remove(account);
}
Also used : Account(android.accounts.Account) ArrayList(java.util.ArrayList)

Example 15 with Account

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

the class SyncManager method doDatabaseCleanup.

private void doDatabaseCleanup() {
    for (UserInfo user : mUserManager.getUsers(true)) {
        // Skip any partially created/removed users
        if (user.partial)
            continue;
        Account[] accountsForUser = AccountManagerService.getSingleton().getAccounts(user.id);
        mSyncStorageEngine.doDatabaseCleanup(accountsForUser, user.id);
    }
}
Also used : Account(android.accounts.Account) UserInfo(android.content.pm.UserInfo)

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