Search in sources :

Example 91 with Cursor

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));
    }
}
Also used : Cursor(android.database.Cursor)

Example 92 with Cursor

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;
}
Also used : Cursor(android.database.Cursor) RemoteException(android.os.RemoteException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 93 with Cursor

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.");
    }
}
Also used : DocumentInfo.getCursorString(com.android.documentsui.model.DocumentInfo.getCursorString) Cursor(android.database.Cursor) RemoteException(android.os.RemoteException) Uri(android.net.Uri) DocumentsContract.buildDocumentUri(android.provider.DocumentsContract.buildDocumentUri) DocumentsContract.buildChildDocumentsUri(android.provider.DocumentsContract.buildChildDocumentsUri) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 94 with Cursor

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);
}
Also used : DocumentInfo.getCursorString(com.android.documentsui.model.DocumentInfo.getCursorString) Cursor(android.database.Cursor)

Example 95 with 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;
}
Also used : ArrayList(java.util.ArrayList) DocumentInfo.getCursorString(com.android.documentsui.model.DocumentInfo.getCursorString) MergeCursor(android.database.MergeCursor) Cursor(android.database.Cursor) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Aggregations

Cursor (android.database.Cursor)4002 ArrayList (java.util.ArrayList)547 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)527 Uri (android.net.Uri)467 ContentValues (android.content.ContentValues)334 ContentResolver (android.content.ContentResolver)193 Test (org.junit.Test)183 RemoteException (android.os.RemoteException)182 File (java.io.File)170 IOException (java.io.IOException)159 MatrixCursor (android.database.MatrixCursor)154 Intent (android.content.Intent)140 SQLException (android.database.SQLException)126 MediumTest (android.test.suitebuilder.annotation.MediumTest)116 HashMap (java.util.HashMap)108 SQLiteException (android.database.sqlite.SQLiteException)94 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)93 SQLiteCursor (android.database.sqlite.SQLiteCursor)88 Query (android.app.DownloadManager.Query)76 MergeCursor (android.database.MergeCursor)75