use of android.database.Cursor in project platform_frameworks_base by android.
the class CalendarTracker method meetsAttendee.
private boolean meetsAttendee(EventInfo filter, int eventId, String email) {
final long start = System.currentTimeMillis();
String selection = ATTENDEE_SELECTION;
String[] selectionArgs = { Integer.toString(eventId), email };
if (DEBUG_ATTENDEES) {
selection = null;
selectionArgs = null;
}
final Cursor cursor = mUserContext.getContentResolver().query(Attendees.CONTENT_URI, ATTENDEE_PROJECTION, selection, selectionArgs, null);
try {
if (cursor.getCount() == 0) {
if (DEBUG)
Log.d(TAG, "No attendees found");
return true;
}
boolean rt = false;
while (cursor.moveToNext()) {
final long rowEventId = cursor.getLong(0);
final String rowEmail = cursor.getString(1);
final int status = cursor.getInt(2);
final boolean meetsReply = meetsReply(filter.reply, status);
if (DEBUG)
Log.d(TAG, (DEBUG_ATTENDEES ? String.format("rowEventId=%s, rowEmail=%s, ", rowEventId, rowEmail) : "") + String.format("status=%s, meetsReply=%s", attendeeStatusToString(status), meetsReply));
final boolean eventMeets = rowEventId == eventId && Objects.equals(rowEmail, email) && meetsReply;
rt |= eventMeets;
}
return rt;
} finally {
cursor.close();
if (DEBUG)
Log.d(TAG, "meetsAttendee took " + (System.currentTimeMillis() - start));
}
}
use of android.database.Cursor in project platform_frameworks_base by android.
the class GnssLocationProvider method getApnIpType.
private int getApnIpType(String apn) {
ensureInHandlerThread();
if (apn == null) {
return APN_INVALID;
}
String selection = String.format("current = 1 and apn = '%s' and carrier_enabled = 1", apn);
Cursor cursor = null;
try {
cursor = mContext.getContentResolver().query(Carriers.CONTENT_URI, new String[] { Carriers.PROTOCOL }, selection, null, Carriers.DEFAULT_SORT_ORDER);
if (null != cursor && cursor.moveToFirst()) {
return translateToApnIpType(cursor.getString(0), apn);
} else {
Log.e(TAG, "No entry found in query for APN: " + apn);
}
} catch (Exception e) {
Log.e(TAG, "Error encountered on APN query for: " + apn, e);
} finally {
if (cursor != null) {
cursor.close();
}
}
return APN_INVALID;
}
use of android.database.Cursor in project platform_frameworks_base by android.
the class CopyJob method copyDirectoryHelper.
/**
* Handles recursion into a directory and copying its contents. Note that in linux terms, this
* does the equivalent of "cp src/* dst", not "cp -r src dst".
*
* @param srcDir Info of the directory to copy from. The routine will copy the directory's
* contents, not the directory itself.
* @param destDir Info of the directory to copy to. Must be created beforehand.
* @throws ResourceException
*/
private void copyDirectoryHelper(DocumentInfo srcDir, DocumentInfo destDir) throws ResourceException {
// Recurse into directories. Copy children into the new subdirectory.
final String[] queryColumns = new String[] { Document.COLUMN_DISPLAY_NAME, Document.COLUMN_DOCUMENT_ID, Document.COLUMN_MIME_TYPE, Document.COLUMN_SIZE, Document.COLUMN_FLAGS };
Cursor cursor = null;
boolean success = true;
// Iterate over srcs in the directory; copy to the destination directory.
final Uri queryUri = buildChildDocumentsUri(srcDir.authority, srcDir.documentId);
try {
try {
cursor = getClient(srcDir).query(queryUri, queryColumns, null, null, null);
} catch (RemoteException | RuntimeException e) {
throw new ResourceException("Failed to query children of %s due to an exception.", srcDir.derivedUri, e);
}
DocumentInfo src;
while (cursor.moveToNext() && !isCanceled()) {
try {
src = DocumentInfo.fromCursor(cursor, srcDir.authority);
processDocument(src, srcDir, destDir);
} catch (RuntimeException e) {
Log.e(TAG, "Failed to recursively process a file %s due to an exception.".format(srcDir.derivedUri.toString()), e);
success = false;
}
}
} catch (RuntimeException e) {
Log.e(TAG, "Failed to copy a file %s to %s. ".format(srcDir.derivedUri.toString(), destDir.derivedUri.toString()), e);
success = false;
} finally {
IoUtils.closeQuietly(cursor);
}
if (!success) {
throw new RuntimeException("Some files failed to copy during a recursive " + "directory copy.");
}
}
use of android.database.Cursor in project platform_frameworks_base by android.
the class DocumentsAdapter method isDirectory.
boolean isDirectory(Model model, int position) {
String modelId = getModelIds().get(position);
Cursor cursor = model.getItem(modelId);
return isDirectory(cursor);
}
use of android.database.Cursor in project platform_frameworks_base by android.
the class Model method getDocuments.
List<DocumentInfo> getDocuments(Selection items) {
final int size = (items != null) ? items.size() : 0;
final List<DocumentInfo> docs = new ArrayList<>(size);
for (String modelId : items.getAll()) {
final Cursor cursor = getItem(modelId);
if (cursor == null) {
Log.w(TAG, "Skipping document. Unabled to obtain cursor for modelId: " + modelId);
continue;
}
docs.add(DocumentInfo.fromDirectoryCursor(cursor));
}
return docs;
}
Aggregations