Search in sources :

Example 56 with RowBuilder

use of android.database.MatrixCursor.RowBuilder in project android_frameworks_base by DirtyUnicorns.

the class BugreportStorageProvider method queryDocument.

@Override
public Cursor queryDocument(String documentId, String[] projection) throws FileNotFoundException {
    if (mArchiveHelper.isArchivedDocument(documentId)) {
        return mArchiveHelper.queryDocument(documentId, projection);
    }
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    if (DOC_ID_ROOT.equals(documentId)) {
        final RowBuilder row = result.newRow();
        row.add(Document.COLUMN_DOCUMENT_ID, documentId);
        row.add(Document.COLUMN_MIME_TYPE, Document.MIME_TYPE_DIR);
        row.add(Document.COLUMN_DISPLAY_NAME, mRoot.getName());
        row.add(Document.COLUMN_LAST_MODIFIED, mRoot.lastModified());
        row.add(Document.COLUMN_FLAGS, Document.FLAG_DIR_PREFERS_LAST_MODIFIED);
    } else {
        addFileRow(result, getFileForDocId(documentId));
    }
    return result;
}
Also used : RowBuilder(android.database.MatrixCursor.RowBuilder) MatrixCursor(android.database.MatrixCursor)

Example 57 with RowBuilder

use of android.database.MatrixCursor.RowBuilder in project android_frameworks_base by DirtyUnicorns.

the class ExternalStorageProvider method queryRoots.

@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
    synchronized (mRootsLock) {
        for (RootInfo root : mRoots.values()) {
            final RowBuilder row = result.newRow();
            row.add(Root.COLUMN_ROOT_ID, root.rootId);
            row.add(Root.COLUMN_FLAGS, root.flags);
            row.add(Root.COLUMN_TITLE, root.title);
            row.add(Root.COLUMN_DOCUMENT_ID, root.docId);
            row.add(Root.COLUMN_AVAILABLE_BYTES, root.reportAvailableBytes ? root.path.getFreeSpace() : -1);
        }
    }
    return result;
}
Also used : RowBuilder(android.database.MatrixCursor.RowBuilder) MatrixCursor(android.database.MatrixCursor)

Example 58 with RowBuilder

use of android.database.MatrixCursor.RowBuilder in project android_frameworks_base by DirtyUnicorns.

the class MtpDatabase method queryRoots.

/**
     * Queries roots information.
     * @param columnNames Column names defined in {@link android.provider.DocumentsContract.Root}.
     * @return Database cursor.
     */
Cursor queryRoots(Resources resources, String[] columnNames) {
    final String selection = COLUMN_ROW_STATE + " IN (?, ?) AND " + COLUMN_DOCUMENT_TYPE + " = ?";
    final Cursor deviceCursor = mDatabase.query(TABLE_DOCUMENTS, strings(COLUMN_DEVICE_ID), selection, strings(ROW_STATE_VALID, ROW_STATE_INVALIDATED, DOCUMENT_TYPE_DEVICE), COLUMN_DEVICE_ID, null, null, null);
    try {
        final SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
        builder.setTables(JOIN_ROOTS);
        builder.setProjectionMap(COLUMN_MAP_ROOTS);
        final MatrixCursor result = new MatrixCursor(columnNames);
        final ContentValues values = new ContentValues();
        while (deviceCursor.moveToNext()) {
            final int deviceId = deviceCursor.getInt(0);
            final Cursor storageCursor = builder.query(mDatabase, columnNames, selection + " AND " + COLUMN_DEVICE_ID + " = ?", strings(ROW_STATE_VALID, ROW_STATE_INVALIDATED, DOCUMENT_TYPE_STORAGE, deviceId), null, null, null);
            try {
                values.clear();
                try (final Cursor deviceRoot = builder.query(mDatabase, columnNames, selection + " AND " + COLUMN_DEVICE_ID + " = ?", strings(ROW_STATE_VALID, ROW_STATE_INVALIDATED, DOCUMENT_TYPE_DEVICE, deviceId), null, null, null)) {
                    deviceRoot.moveToNext();
                    DatabaseUtils.cursorRowToContentValues(deviceRoot, values);
                }
                if (storageCursor.getCount() != 0) {
                    long capacityBytes = 0;
                    long availableBytes = 0;
                    final int capacityIndex = storageCursor.getColumnIndex(Root.COLUMN_CAPACITY_BYTES);
                    final int availableIndex = storageCursor.getColumnIndex(Root.COLUMN_AVAILABLE_BYTES);
                    while (storageCursor.moveToNext()) {
                        // don't calculate corresponding values.
                        if (capacityIndex != -1) {
                            capacityBytes += storageCursor.getLong(capacityIndex);
                        }
                        if (availableIndex != -1) {
                            availableBytes += storageCursor.getLong(availableIndex);
                        }
                    }
                    values.put(Root.COLUMN_CAPACITY_BYTES, capacityBytes);
                    values.put(Root.COLUMN_AVAILABLE_BYTES, availableBytes);
                } else {
                    values.putNull(Root.COLUMN_CAPACITY_BYTES);
                    values.putNull(Root.COLUMN_AVAILABLE_BYTES);
                }
                if (storageCursor.getCount() == 1 && values.containsKey(Root.COLUMN_TITLE)) {
                    storageCursor.moveToFirst();
                    // Add storage name to device name if we have only 1 storage.
                    values.put(Root.COLUMN_TITLE, resources.getString(R.string.root_name, values.getAsString(Root.COLUMN_TITLE), storageCursor.getString(storageCursor.getColumnIndex(Root.COLUMN_TITLE))));
                }
            } finally {
                storageCursor.close();
            }
            final RowBuilder row = result.newRow();
            for (final String key : values.keySet()) {
                row.add(key, values.get(key));
            }
        }
        return result;
    } finally {
        deviceCursor.close();
    }
}
Also used : ContentValues(android.content.ContentValues) RowBuilder(android.database.MatrixCursor.RowBuilder) Cursor(android.database.Cursor) MatrixCursor(android.database.MatrixCursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder) MatrixCursor(android.database.MatrixCursor)

Example 59 with RowBuilder

use of android.database.MatrixCursor.RowBuilder in project android_frameworks_base by crdroidandroid.

the class MtpDatabase method queryRoots.

/**
     * Queries roots information.
     * @param columnNames Column names defined in {@link android.provider.DocumentsContract.Root}.
     * @return Database cursor.
     */
Cursor queryRoots(Resources resources, String[] columnNames) {
    final String selection = COLUMN_ROW_STATE + " IN (?, ?) AND " + COLUMN_DOCUMENT_TYPE + " = ?";
    final Cursor deviceCursor = mDatabase.query(TABLE_DOCUMENTS, strings(COLUMN_DEVICE_ID), selection, strings(ROW_STATE_VALID, ROW_STATE_INVALIDATED, DOCUMENT_TYPE_DEVICE), COLUMN_DEVICE_ID, null, null, null);
    try {
        final SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
        builder.setTables(JOIN_ROOTS);
        builder.setProjectionMap(COLUMN_MAP_ROOTS);
        final MatrixCursor result = new MatrixCursor(columnNames);
        final ContentValues values = new ContentValues();
        while (deviceCursor.moveToNext()) {
            final int deviceId = deviceCursor.getInt(0);
            final Cursor storageCursor = builder.query(mDatabase, columnNames, selection + " AND " + COLUMN_DEVICE_ID + " = ?", strings(ROW_STATE_VALID, ROW_STATE_INVALIDATED, DOCUMENT_TYPE_STORAGE, deviceId), null, null, null);
            try {
                values.clear();
                try (final Cursor deviceRoot = builder.query(mDatabase, columnNames, selection + " AND " + COLUMN_DEVICE_ID + " = ?", strings(ROW_STATE_VALID, ROW_STATE_INVALIDATED, DOCUMENT_TYPE_DEVICE, deviceId), null, null, null)) {
                    deviceRoot.moveToNext();
                    DatabaseUtils.cursorRowToContentValues(deviceRoot, values);
                }
                if (storageCursor.getCount() != 0) {
                    long capacityBytes = 0;
                    long availableBytes = 0;
                    final int capacityIndex = storageCursor.getColumnIndex(Root.COLUMN_CAPACITY_BYTES);
                    final int availableIndex = storageCursor.getColumnIndex(Root.COLUMN_AVAILABLE_BYTES);
                    while (storageCursor.moveToNext()) {
                        // don't calculate corresponding values.
                        if (capacityIndex != -1) {
                            capacityBytes += storageCursor.getLong(capacityIndex);
                        }
                        if (availableIndex != -1) {
                            availableBytes += storageCursor.getLong(availableIndex);
                        }
                    }
                    values.put(Root.COLUMN_CAPACITY_BYTES, capacityBytes);
                    values.put(Root.COLUMN_AVAILABLE_BYTES, availableBytes);
                } else {
                    values.putNull(Root.COLUMN_CAPACITY_BYTES);
                    values.putNull(Root.COLUMN_AVAILABLE_BYTES);
                }
                if (storageCursor.getCount() == 1 && values.containsKey(Root.COLUMN_TITLE)) {
                    storageCursor.moveToFirst();
                    // Add storage name to device name if we have only 1 storage.
                    values.put(Root.COLUMN_TITLE, resources.getString(R.string.root_name, values.getAsString(Root.COLUMN_TITLE), storageCursor.getString(storageCursor.getColumnIndex(Root.COLUMN_TITLE))));
                }
            } finally {
                storageCursor.close();
            }
            final RowBuilder row = result.newRow();
            for (final String key : values.keySet()) {
                row.add(key, values.get(key));
            }
        }
        return result;
    } finally {
        deviceCursor.close();
    }
}
Also used : ContentValues(android.content.ContentValues) RowBuilder(android.database.MatrixCursor.RowBuilder) Cursor(android.database.Cursor) MatrixCursor(android.database.MatrixCursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder) MatrixCursor(android.database.MatrixCursor)

Example 60 with RowBuilder

use of android.database.MatrixCursor.RowBuilder in project android_frameworks_base by crdroidandroid.

the class StressProvider method includeDocument.

private void includeDocument(MatrixCursor result, StubDocument document) {
    final RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, document.id);
    row.add(Document.COLUMN_DISPLAY_NAME, document.id);
    row.add(Document.COLUMN_SIZE, document.size);
    row.add(Document.COLUMN_MIME_TYPE, document.mimeType);
    row.add(Document.COLUMN_FLAGS, document.thumbnail != -1 ? Document.FLAG_SUPPORTS_THUMBNAIL : 0);
    row.add(Document.COLUMN_LAST_MODIFIED, document.lastModified);
}
Also used : RowBuilder(android.database.MatrixCursor.RowBuilder)

Aggregations

RowBuilder (android.database.MatrixCursor.RowBuilder)60 MatrixCursor (android.database.MatrixCursor)30 ContentValues (android.content.ContentValues)5 Cursor (android.database.Cursor)5 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)5 Point (android.graphics.Point)5 Uri (android.net.Uri)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5