use of android.database.MatrixCursor in project platform_frameworks_base by android.
the class MusicProvider method getRootContainerCurser.
public MatrixCursor getRootContainerCurser() {
MatrixCursor matrixCursor = new MatrixCursor(BrowserService.MEDIA_CONTAINER_PROJECTION);
Uri.Builder pianoBuilder = new Uri.Builder();
pianoBuilder.authority(BrowserService.AUTHORITY);
pianoBuilder.appendPath(BrowserService.PIANO_BASE_PATH);
matrixCursor.addRow(new Object[] { pianoBuilder.build(), BrowserService.PIANO_BASE_PATH, "subtitle", null, 0 });
Uri.Builder voiceBuilder = new Uri.Builder();
voiceBuilder.authority(BrowserService.AUTHORITY);
voiceBuilder.appendPath(BrowserService.VOICE_BASE_PATH);
matrixCursor.addRow(new Object[] { voiceBuilder.build(), BrowserService.VOICE_BASE_PATH, "subtitle", null, 0 });
return matrixCursor;
}
use of android.database.MatrixCursor in project platform_frameworks_base by android.
the class StressProvider method queryChildDocuments.
@Override
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) throws FileNotFoundException {
final MatrixCursor result = new MatrixCursor(DEFAULT_DOCUMENT_PROJECTION);
final ArrayList<StubDocument> childDocuments = mChildDocuments.get(parentDocumentId);
if (childDocuments != null) {
for (StubDocument document : childDocuments) {
includeDocument(result, document);
}
}
return result;
}
use of android.database.MatrixCursor in project platform_frameworks_base by android.
the class MtpDocumentsProvider method createErrorCursor.
/**
* Creates empty cursor with specific error message.
*
* @param projection Column names.
* @param stringResId String resource ID of error message.
* @return Empty cursor with error message.
*/
private Cursor createErrorCursor(String[] projection, int stringResId) {
final Bundle bundle = new Bundle();
bundle.putString(DocumentsContract.EXTRA_ERROR, mResources.getString(stringResId));
final Cursor cursor = new MatrixCursor(projection);
cursor.setExtras(bundle);
return cursor;
}
use of android.database.MatrixCursor 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 in project platform_frameworks_base by android.
the class SettingsProvider method getAllGlobalSettings.
private Cursor getAllGlobalSettings(String[] projection) {
if (DEBUG) {
Slog.v(LOG_TAG, "getAllGlobalSettings()");
}
synchronized (mLock) {
// Get the settings.
SettingsState settingsState = mSettingsRegistry.getSettingsLocked(SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM);
List<String> names = settingsState.getSettingNamesLocked();
final int nameCount = names.size();
String[] normalizedProjection = normalizeProjection(projection);
MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount);
// Anyone can get the global settings, so no security checks.
for (int i = 0; i < nameCount; i++) {
String name = names.get(i);
Setting setting = settingsState.getSettingLocked(name);
appendSettingToCursor(result, setting);
}
return result;
}
}
Aggregations