Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 86bd084c authored by Fred Quintana's avatar Fred Quintana
Browse files

do not use transactions for calls that just read the DB

parent 6817946f
Loading
Loading
Loading
Loading
+18 −37
Original line number Diff line number Diff line
@@ -287,15 +287,11 @@ public class AccountManagerService

    private String readUserDataFromDatabase(Account account, String key) {
        SQLiteDatabase db = mOpenHelper.getReadableDatabase();
        db.beginTransaction();
        try {
            long accountId = getAccountId(db, account);
            if (accountId < 0) {
                return null;
            }
        Cursor cursor = db.query(TABLE_EXTRAS, new String[]{EXTRAS_VALUE},
                    EXTRAS_ACCOUNTS_ID + "=" + accountId + " AND " + EXTRAS_KEY + "=?",
                    new String[]{key}, null, null, null);
                EXTRAS_ACCOUNTS_ID
                        + "=(select _id FROM accounts WHERE name=? AND type=?) AND "
                        + EXTRAS_KEY + "=?",
                new String[]{account.name, account.type, key}, null, null, null);
        try {
            if (cursor.moveToNext()) {
                return cursor.getString(0);
@@ -304,9 +300,6 @@ public class AccountManagerService
        } finally {
            cursor.close();
        }
        } finally {
            db.endTransaction();
        }
    }

    public AuthenticatorDescription[] getAuthenticatorTypes() {
@@ -530,15 +523,18 @@ public class AccountManagerService

    public String readAuthTokenFromDatabase(Account account, String authTokenType) {
        SQLiteDatabase db = mOpenHelper.getReadableDatabase();
        db.beginTransaction();
        Cursor cursor = db.query(TABLE_AUTHTOKENS, new String[]{AUTHTOKENS_AUTHTOKEN},
                AUTHTOKENS_ACCOUNTS_ID + "=(select _id FROM accounts WHERE name=? AND type=?) AND "
                        + AUTHTOKENS_TYPE + "=?",
                new String[]{account.name, account.type, authTokenType},
                null, null, null);
        try {
            long accountId = getAccountId(db, account);
            if (accountId < 0) {
                return null;
            if (cursor.moveToNext()) {
                return cursor.getString(0);
            }
            return getAuthToken(db, accountId, authTokenType);
            return null;
        } finally {
            db.endTransaction();
            cursor.close();
        }
    }

@@ -1069,21 +1065,6 @@ public class AccountManagerService
        }
    }

    private String getAuthToken(SQLiteDatabase db, long accountId, String authTokenType) {
        Cursor cursor = db.query(TABLE_AUTHTOKENS, new String[]{AUTHTOKENS_AUTHTOKEN},
                AUTHTOKENS_ACCOUNTS_ID + "=" + accountId + " AND " + AUTHTOKENS_TYPE + "=?",
                new String[]{authTokenType},
                null, null, null);
        try {
            if (cursor.moveToNext()) {
                return cursor.getString(0);
            }
            return null;
        } finally {
            cursor.close();
        }
    }

    private abstract class Session extends IAccountAuthenticatorResponse.Stub
            implements AuthenticatorBindHelper.Callback, IBinder.DeathRecipient {
        IAccountManagerResponse mResponse;