use of android.database.MatrixCursor.RowBuilder in project platform_frameworks_base by android.
the class StressProvider method includeRoot.
private void includeRoot(MatrixCursor result, StubRoot root) {
final RowBuilder row = result.newRow();
row.add(Root.COLUMN_ROOT_ID, root.id);
row.add(Root.COLUMN_FLAGS, 0);
row.add(Root.COLUMN_TITLE, root.id);
row.add(Root.COLUMN_DOCUMENT_ID, root.documentId);
}
use of android.database.MatrixCursor.RowBuilder in project platform_frameworks_base by android.
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();
}
}
use of android.database.MatrixCursor.RowBuilder in project platform_frameworks_base by android.
the class StubProvider method includeDocument.
private void includeDocument(MatrixCursor result, StubDocument document) {
final RowBuilder row = result.newRow();
row.add(Document.COLUMN_DOCUMENT_ID, document.documentId);
row.add(Document.COLUMN_DISPLAY_NAME, document.file.getName());
row.add(Document.COLUMN_SIZE, document.file.length());
row.add(Document.COLUMN_MIME_TYPE, document.mimeType);
row.add(Document.COLUMN_FLAGS, document.flags);
row.add(Document.COLUMN_LAST_MODIFIED, document.file.lastModified());
}
use of android.database.MatrixCursor.RowBuilder in project platform_frameworks_base by android.
the class ExternalStorageProvider method includeFile.
private void includeFile(MatrixCursor result, String docId, File file) throws FileNotFoundException {
if (docId == null) {
docId = getDocIdForFile(file);
} else {
file = getFileForDocId(docId);
}
int flags = 0;
if (file.canWrite()) {
if (file.isDirectory()) {
flags |= Document.FLAG_DIR_SUPPORTS_CREATE;
flags |= Document.FLAG_SUPPORTS_DELETE;
flags |= Document.FLAG_SUPPORTS_RENAME;
flags |= Document.FLAG_SUPPORTS_MOVE;
} else {
flags |= Document.FLAG_SUPPORTS_WRITE;
flags |= Document.FLAG_SUPPORTS_DELETE;
flags |= Document.FLAG_SUPPORTS_RENAME;
flags |= Document.FLAG_SUPPORTS_MOVE;
}
}
final String mimeType = getTypeForFile(file);
if (mArchiveHelper.isSupportedArchiveType(mimeType)) {
flags |= Document.FLAG_ARCHIVE;
}
final String displayName = file.getName();
if (mimeType.startsWith("image/")) {
flags |= Document.FLAG_SUPPORTS_THUMBNAIL;
}
final RowBuilder row = result.newRow();
row.add(Document.COLUMN_DOCUMENT_ID, docId);
row.add(Document.COLUMN_DISPLAY_NAME, displayName);
row.add(Document.COLUMN_SIZE, file.length());
row.add(Document.COLUMN_MIME_TYPE, mimeType);
row.add(Document.COLUMN_FLAGS, flags);
row.add(DocumentArchiveHelper.COLUMN_LOCAL_FILE_PATH, file.getPath());
// Only publish dates reasonably after epoch
long lastModified = file.lastModified();
if (lastModified > 31536000000L) {
row.add(Document.COLUMN_LAST_MODIFIED, lastModified);
}
}
use of android.database.MatrixCursor.RowBuilder in project platform_frameworks_base by android.
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;
}
Aggregations