Search in sources :

Example 86 with Cursor

use of android.database.Cursor in project platform_frameworks_base by android.

the class ModelTest method testSort_sizes.

// Tests sorting by item size.
public void testSort_sizes() {
    DirectoryResult r = new DirectoryResult();
    r.cursor = cursor;
    r.sortOrder = State.SORT_ORDER_SIZE;
    model.update(r);
    BitSet seen = new BitSet(ITEM_COUNT);
    int previousSize = Integer.MAX_VALUE;
    for (String id : model.getModelIds()) {
        Cursor c = model.getItem(id);
        seen.set(c.getPosition());
        // Check sort order - descending numerical
        int size = DocumentInfo.getCursorInt(c, Document.COLUMN_SIZE);
        assertTrue(previousSize >= size);
        previousSize = size;
    }
    // Check that all items were accounted for.
    assertEquals(ITEM_COUNT, seen.cardinality());
}
Also used : DirectoryResult(com.android.documentsui.DirectoryResult) BitSet(java.util.BitSet) MergeCursor(android.database.MergeCursor) MatrixCursor(android.database.MatrixCursor) Cursor(android.database.Cursor)

Example 87 with Cursor

use of android.database.Cursor in project platform_frameworks_base by android.

the class LockSettingsStorage method readKeyValue.

public String readKeyValue(String key, String defaultValue, int userId) {
    int version;
    synchronized (mCache) {
        if (mCache.hasKeyValue(key, userId)) {
            return mCache.peekKeyValue(key, defaultValue, userId);
        }
        version = mCache.getVersion();
    }
    Cursor cursor;
    Object result = DEFAULT;
    SQLiteDatabase db = mOpenHelper.getReadableDatabase();
    if ((cursor = db.query(TABLE, COLUMNS_FOR_QUERY, COLUMN_USERID + "=? AND " + COLUMN_KEY + "=?", new String[] { Integer.toString(userId), key }, null, null, null)) != null) {
        if (cursor.moveToFirst()) {
            result = cursor.getString(0);
        }
        cursor.close();
    }
    mCache.putKeyValueIfUnchanged(key, result, userId, version);
    return result == DEFAULT ? defaultValue : (String) result;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor)

Example 88 with Cursor

use of android.database.Cursor in project platform_frameworks_base by android.

the class LockSettingsStorage method prefetchUser.

public void prefetchUser(int userId) {
    int version;
    synchronized (mCache) {
        if (mCache.isFetched(userId)) {
            return;
        }
        mCache.setFetched(userId);
        version = mCache.getVersion();
    }
    Cursor cursor;
    SQLiteDatabase db = mOpenHelper.getReadableDatabase();
    if ((cursor = db.query(TABLE, COLUMNS_FOR_PREFETCH, COLUMN_USERID + "=?", new String[] { Integer.toString(userId) }, null, null, null)) != null) {
        while (cursor.moveToNext()) {
            String key = cursor.getString(0);
            String value = cursor.getString(1);
            mCache.putKeyValueIfUnchanged(key, value, userId, version);
        }
        cursor.close();
    }
    // Populate cache by reading the password and pattern files.
    readPasswordHash(userId);
    readPatternHash(userId);
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor)

Example 89 with Cursor

use of android.database.Cursor in project platform_frameworks_base by android.

the class SyncStorageEngine method readAndDeleteLegacyAccountInfoLocked.

/**
     * Load sync engine state from the old syncmanager database, and then
     * erase it.  Note that we don't deal with pending operations, active
     * sync, or history.
     */
private void readAndDeleteLegacyAccountInfoLocked() {
    // Look for old database to initialize from.
    File file = mContext.getDatabasePath("syncmanager.db");
    if (!file.exists()) {
        return;
    }
    String path = file.getPath();
    SQLiteDatabase db = null;
    try {
        db = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READONLY);
    } catch (SQLiteException e) {
    }
    if (db != null) {
        final boolean hasType = db.getVersion() >= 11;
        // Copy in all of the status information, as well as accounts.
        if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
            Slog.v(TAG_FILE, "Reading legacy sync accounts db");
        }
        SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
        qb.setTables("stats, status");
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("_id", "status._id as _id");
        map.put("account", "stats.account as account");
        if (hasType) {
            map.put("account_type", "stats.account_type as account_type");
        }
        map.put("authority", "stats.authority as authority");
        map.put("totalElapsedTime", "totalElapsedTime");
        map.put("numSyncs", "numSyncs");
        map.put("numSourceLocal", "numSourceLocal");
        map.put("numSourcePoll", "numSourcePoll");
        map.put("numSourceServer", "numSourceServer");
        map.put("numSourceUser", "numSourceUser");
        map.put("lastSuccessSource", "lastSuccessSource");
        map.put("lastSuccessTime", "lastSuccessTime");
        map.put("lastFailureSource", "lastFailureSource");
        map.put("lastFailureTime", "lastFailureTime");
        map.put("lastFailureMesg", "lastFailureMesg");
        map.put("pending", "pending");
        qb.setProjectionMap(map);
        qb.appendWhere("stats._id = status.stats_id");
        Cursor c = qb.query(db, null, null, null, null, null, null);
        while (c.moveToNext()) {
            String accountName = c.getString(c.getColumnIndex("account"));
            String accountType = hasType ? c.getString(c.getColumnIndex("account_type")) : null;
            if (accountType == null) {
                accountType = "com.google";
            }
            String authorityName = c.getString(c.getColumnIndex("authority"));
            AuthorityInfo authority = this.getOrCreateAuthorityLocked(new EndPoint(new Account(accountName, accountType), authorityName, 0), -1, false);
            if (authority != null) {
                int i = mSyncStatus.size();
                boolean found = false;
                SyncStatusInfo st = null;
                while (i > 0) {
                    i--;
                    st = mSyncStatus.valueAt(i);
                    if (st.authorityId == authority.ident) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    st = new SyncStatusInfo(authority.ident);
                    mSyncStatus.put(authority.ident, st);
                }
                st.totalElapsedTime = getLongColumn(c, "totalElapsedTime");
                st.numSyncs = getIntColumn(c, "numSyncs");
                st.numSourceLocal = getIntColumn(c, "numSourceLocal");
                st.numSourcePoll = getIntColumn(c, "numSourcePoll");
                st.numSourceServer = getIntColumn(c, "numSourceServer");
                st.numSourceUser = getIntColumn(c, "numSourceUser");
                st.numSourcePeriodic = 0;
                st.lastSuccessSource = getIntColumn(c, "lastSuccessSource");
                st.lastSuccessTime = getLongColumn(c, "lastSuccessTime");
                st.lastFailureSource = getIntColumn(c, "lastFailureSource");
                st.lastFailureTime = getLongColumn(c, "lastFailureTime");
                st.lastFailureMesg = c.getString(c.getColumnIndex("lastFailureMesg"));
                st.pending = getIntColumn(c, "pending") != 0;
            }
        }
        c.close();
        // Retrieve the settings.
        qb = new SQLiteQueryBuilder();
        qb.setTables("settings");
        c = qb.query(db, null, null, null, null, null, null);
        while (c.moveToNext()) {
            String name = c.getString(c.getColumnIndex("name"));
            String value = c.getString(c.getColumnIndex("value"));
            if (name == null)
                continue;
            if (name.equals("listen_for_tickles")) {
                setMasterSyncAutomatically(value == null || Boolean.parseBoolean(value), 0);
            } else if (name.startsWith("sync_provider_")) {
                String provider = name.substring("sync_provider_".length(), name.length());
                int i = mAuthorities.size();
                while (i > 0) {
                    i--;
                    AuthorityInfo authority = mAuthorities.valueAt(i);
                    if (authority.target.provider.equals(provider)) {
                        authority.enabled = value == null || Boolean.parseBoolean(value);
                        authority.syncable = 1;
                    }
                }
            }
        }
        c.close();
        db.close();
        (new File(path)).delete();
    }
}
Also used : Account(android.accounts.Account) HashMap(java.util.HashMap) SyncStatusInfo(android.content.SyncStatusInfo) SQLiteException(android.database.sqlite.SQLiteException) Cursor(android.database.Cursor) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) File(java.io.File) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder)

Example 90 with Cursor

use of android.database.Cursor in project platform_frameworks_base by android.

the class CalendarTracker method checkEvent.

public CheckEventResult checkEvent(EventInfo filter, long time) {
    final Uri.Builder uriBuilder = Instances.CONTENT_URI.buildUpon();
    ContentUris.appendId(uriBuilder, time);
    ContentUris.appendId(uriBuilder, time + EVENT_CHECK_LOOKAHEAD);
    final Uri uri = uriBuilder.build();
    final Cursor cursor = mUserContext.getContentResolver().query(uri, INSTANCE_PROJECTION, null, null, INSTANCE_ORDER_BY);
    final CheckEventResult result = new CheckEventResult();
    result.recheckAt = time + EVENT_CHECK_LOOKAHEAD;
    try {
        final ArraySet<Long> primaryCalendars = getPrimaryCalendars();
        while (cursor != null && cursor.moveToNext()) {
            final long begin = cursor.getLong(0);
            final long end = cursor.getLong(1);
            final String title = cursor.getString(2);
            final boolean calendarVisible = cursor.getInt(3) == 1;
            final int eventId = cursor.getInt(4);
            final String name = cursor.getString(5);
            final String owner = cursor.getString(6);
            final long calendarId = cursor.getLong(7);
            final int availability = cursor.getInt(8);
            final boolean calendarPrimary = primaryCalendars.contains(calendarId);
            if (DEBUG)
                Log.d(TAG, String.format("%s %s-%s v=%s a=%s eid=%s n=%s o=%s cid=%s p=%s", title, new Date(begin), new Date(end), calendarVisible, availabilityToString(availability), eventId, name, owner, calendarId, calendarPrimary));
            final boolean meetsTime = time >= begin && time < end;
            final boolean meetsCalendar = calendarVisible && calendarPrimary && (filter.calendar == null || Objects.equals(filter.calendar, owner) || Objects.equals(filter.calendar, name));
            final boolean meetsAvailability = availability != Instances.AVAILABILITY_FREE;
            if (meetsCalendar && meetsAvailability) {
                if (DEBUG)
                    Log.d(TAG, "  MEETS CALENDAR & AVAILABILITY");
                final boolean meetsAttendee = meetsAttendee(filter, eventId, owner);
                if (meetsAttendee) {
                    if (DEBUG)
                        Log.d(TAG, "    MEETS ATTENDEE");
                    if (meetsTime) {
                        if (DEBUG)
                            Log.d(TAG, "      MEETS TIME");
                        result.inEvent = true;
                    }
                    if (begin > time && begin < result.recheckAt) {
                        result.recheckAt = begin;
                    } else if (end > time && end < result.recheckAt) {
                        result.recheckAt = end;
                    }
                }
            }
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    return result;
}
Also used : Cursor(android.database.Cursor) Uri(android.net.Uri) Date(java.util.Date)

Aggregations

Cursor (android.database.Cursor)4002 ArrayList (java.util.ArrayList)547 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)527 Uri (android.net.Uri)467 ContentValues (android.content.ContentValues)334 ContentResolver (android.content.ContentResolver)193 Test (org.junit.Test)183 RemoteException (android.os.RemoteException)182 File (java.io.File)170 IOException (java.io.IOException)159 MatrixCursor (android.database.MatrixCursor)154 Intent (android.content.Intent)140 SQLException (android.database.SQLException)126 MediumTest (android.test.suitebuilder.annotation.MediumTest)116 HashMap (java.util.HashMap)108 SQLiteException (android.database.sqlite.SQLiteException)94 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)93 SQLiteCursor (android.database.sqlite.SQLiteCursor)88 Query (android.app.DownloadManager.Query)76 MergeCursor (android.database.MergeCursor)75