Search in sources :

Example 46 with RowBuilder

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

the class TestDocumentsProvider method includeFile.

private static void includeFile(MatrixCursor result, String docId, int flags) {
    final RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, docId);
    row.add(Document.COLUMN_DISPLAY_NAME, docId);
    row.add(Document.COLUMN_LAST_MODIFIED, System.currentTimeMillis());
    row.add(Document.COLUMN_FLAGS, flags);
    if (MY_DOC_ID.equals(docId)) {
        row.add(Document.COLUMN_MIME_TYPE, Document.MIME_TYPE_DIR);
        row.add(Document.COLUMN_FLAGS, Document.FLAG_DIR_SUPPORTS_CREATE);
    } else if (MY_DOC_NULL.equals(docId)) {
    // No MIME type
    } else {
        row.add(Document.COLUMN_MIME_TYPE, "application/octet-stream");
    }
}
Also used : RowBuilder(android.database.MatrixCursor.RowBuilder)

Example 47 with RowBuilder

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

the class BugreportStorageProvider method addFileRow.

private void addFileRow(MatrixCursor result, File file) {
    String mimeType = getTypeForName(file.getName());
    int flags = Document.FLAG_SUPPORTS_DELETE;
    if (mArchiveHelper.isSupportedArchiveType(mimeType)) {
        flags |= Document.FLAG_ARCHIVE;
    }
    final RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, getDocIdForFile(file));
    row.add(Document.COLUMN_MIME_TYPE, mimeType);
    row.add(Document.COLUMN_DISPLAY_NAME, file.getName());
    row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified());
    row.add(Document.COLUMN_FLAGS, flags);
    row.add(Document.COLUMN_SIZE, file.length());
}
Also used : RowBuilder(android.database.MatrixCursor.RowBuilder)

Example 48 with RowBuilder

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

the class BugreportStorageProvider method queryRoots.

@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
    final RowBuilder row = result.newRow();
    row.add(Root.COLUMN_ROOT_ID, DOC_ID_ROOT);
    row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED);
    row.add(Root.COLUMN_ICON, android.R.mipmap.sym_def_app_icon);
    row.add(Root.COLUMN_TITLE, getContext().getString(R.string.bugreport_storage_title));
    row.add(Root.COLUMN_DOCUMENT_ID, DOC_ID_ROOT);
    return result;
}
Also used : RowBuilder(android.database.MatrixCursor.RowBuilder) MatrixCursor(android.database.MatrixCursor)

Example 49 with RowBuilder

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

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 50 with RowBuilder

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

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)

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