Search in sources :

Example 66 with SQLiteDatabase

use of android.database.sqlite.SQLiteDatabase in project platform_frameworks_base by android.

the class AccountManagerService method updateLastAuthenticatedTime.

private boolean updateLastAuthenticatedTime(Account account) {
    final UserAccounts accounts = getUserAccountsForCaller();
    synchronized (accounts.cacheLock) {
        final ContentValues values = new ContentValues();
        values.put(ACCOUNTS_LAST_AUTHENTICATE_TIME_EPOCH_MILLIS, System.currentTimeMillis());
        final SQLiteDatabase db = accounts.openHelper.getWritableDatabase();
        int i = db.update(TABLE_ACCOUNTS, values, ACCOUNTS_NAME + "=? AND " + ACCOUNTS_TYPE + "=?", new String[] { account.name, account.type });
        if (i > 0) {
            return true;
        }
    }
    return false;
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 67 with SQLiteDatabase

use of android.database.sqlite.SQLiteDatabase in project platform_frameworks_base by android.

the class AccountManagerService method addSharedAccountAsUser.

private boolean addSharedAccountAsUser(Account account, int userId) {
    userId = handleIncomingUser(userId);
    UserAccounts accounts = getUserAccounts(userId);
    SQLiteDatabase db = accounts.openHelper.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(ACCOUNTS_NAME, account.name);
    values.put(ACCOUNTS_TYPE, account.type);
    db.delete(TABLE_SHARED_ACCOUNTS, ACCOUNTS_NAME + "=? AND " + ACCOUNTS_TYPE + "=?", new String[] { account.name, account.type });
    long accountId = db.insert(TABLE_SHARED_ACCOUNTS, ACCOUNTS_NAME, values);
    if (accountId < 0) {
        Log.w(TAG, "insertAccountIntoDatabase: " + account + ", skipping the DB insert failed");
        return false;
    }
    logRecord(db, DebugDbHelper.ACTION_ACCOUNT_ADD, TABLE_SHARED_ACCOUNTS, accountId, accounts);
    return true;
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 68 with SQLiteDatabase

use of android.database.sqlite.SQLiteDatabase in project platform_frameworks_base by android.

the class AccountManagerService method revokeAppPermission.

/**
     * Don't allow callers with the given uid permission to get credentials for
     * account/authTokenType.
     * <p>
     * Although this is public it can only be accessed via the AccountManagerService object
     * which is in the system. This means we don't need to protect it with permissions.
     * @hide
     */
private void revokeAppPermission(Account account, String authTokenType, int uid) {
    if (account == null || authTokenType == null) {
        Log.e(TAG, "revokeAppPermission: called with invalid arguments", new Exception());
        return;
    }
    UserAccounts accounts = getUserAccounts(UserHandle.getUserId(uid));
    synchronized (accounts.cacheLock) {
        final SQLiteDatabase db = accounts.openHelper.getWritableDatabase();
        db.beginTransaction();
        try {
            long accountId = getAccountIdLocked(db, account);
            if (accountId >= 0) {
                db.delete(TABLE_GRANTS, GRANTS_ACCOUNTS_ID + "=? AND " + GRANTS_AUTH_TOKEN_TYPE + "=? AND " + GRANTS_GRANTEE_UID + "=?", new String[] { String.valueOf(accountId), authTokenType, String.valueOf(uid) });
                db.setTransactionSuccessful();
            }
        } finally {
            db.endTransaction();
        }
        cancelNotification(getCredentialPermissionNotificationId(account, authTokenType, uid), new UserHandle(accounts.userId));
    }
    // Listeners are a final CopyOnWriteArrayList, hence no lock needed.
    for (AccountManagerInternal.OnAppPermissionChangeListener listener : mAppPermissionChangeListeners) {
        mMessageHandler.post(() -> listener.onAppPermissionChanged(account, uid));
    }
}
Also used : AccountManagerInternal(android.accounts.AccountManagerInternal) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) UserHandle(android.os.UserHandle) GeneralSecurityException(java.security.GeneralSecurityException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 69 with SQLiteDatabase

use of android.database.sqlite.SQLiteDatabase in project platform_frameworks_base by android.

the class AccountManagerService method syncDeCeAccountsLocked.

private void syncDeCeAccountsLocked(UserAccounts accounts) {
    Preconditions.checkState(Thread.holdsLock(mUsers), "mUsers lock must be held");
    final SQLiteDatabase db = accounts.openHelper.getReadableDatabaseUserIsUnlocked();
    List<Account> accountsToRemove = CeDatabaseHelper.findCeAccountsNotInDe(db);
    if (!accountsToRemove.isEmpty()) {
        Slog.i(TAG, "Accounts " + accountsToRemove + " were previously deleted while user " + accounts.userId + " was locked. Removing accounts from CE tables");
        logRecord(accounts, DebugDbHelper.ACTION_SYNC_DE_CE_ACCOUNTS, TABLE_ACCOUNTS);
        for (Account account : accountsToRemove) {
            removeAccountInternal(accounts, account, Process.myUid());
        }
    }
}
Also used : Account(android.accounts.Account) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 70 with SQLiteDatabase

use of android.database.sqlite.SQLiteDatabase in project platform_frameworks_base by android.

the class AccountManagerService method invalidateAuthToken.

@Override
public void invalidateAuthToken(String accountType, String authToken) {
    int callerUid = Binder.getCallingUid();
    if (Log.isLoggable(TAG, Log.VERBOSE)) {
        Log.v(TAG, "invalidateAuthToken: accountType " + accountType + ", caller's uid " + callerUid + ", pid " + Binder.getCallingPid());
    }
    if (accountType == null)
        throw new IllegalArgumentException("accountType is null");
    if (authToken == null)
        throw new IllegalArgumentException("authToken is null");
    int userId = UserHandle.getCallingUserId();
    long identityToken = clearCallingIdentity();
    try {
        UserAccounts accounts = getUserAccounts(userId);
        synchronized (accounts.cacheLock) {
            final SQLiteDatabase db = accounts.openHelper.getWritableDatabaseUserIsUnlocked();
            db.beginTransaction();
            try {
                invalidateAuthTokenLocked(accounts, db, accountType, authToken);
                invalidateCustomTokenLocked(accounts, accountType, authToken);
                db.setTransactionSuccessful();
            } finally {
                db.endTransaction();
            }
        }
    } finally {
        restoreCallingIdentity(identityToken);
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Aggregations

SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1658 Cursor (android.database.Cursor)527 ContentValues (android.content.ContentValues)350 ArrayList (java.util.ArrayList)111 File (java.io.File)65 Test (org.junit.Test)59 SQLiteException (android.database.sqlite.SQLiteException)48 SQLException (android.database.SQLException)44 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)44 Uri (android.net.Uri)44 IOException (java.io.IOException)43 ServiceStatus (com.vodafone360.people.service.ServiceStatus)42 SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)38 RemoteException (android.os.RemoteException)36 Pair (android.util.Pair)31 MediumTest (android.test.suitebuilder.annotation.MediumTest)30 Account (android.accounts.Account)29 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)25 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)22 HashMap (java.util.HashMap)21