Search in sources :

Example 86 with MatrixCursor

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

the class StubProvider method queryDocument.

@Override
public Cursor queryDocument(String documentId, String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION);
    final StubDocument file = mStorage.get(documentId);
    if (file == null) {
        throw new FileNotFoundException();
    }
    includeDocument(result, file);
    return result;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) MatrixCursor(android.database.MatrixCursor)

Example 87 with MatrixCursor

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

the class StubProvider method queryRoots.

@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_ROOT_PROJECTION);
    for (Map.Entry<String, RootInfo> entry : mRoots.entrySet()) {
        final String id = entry.getKey();
        final RootInfo info = entry.getValue();
        final RowBuilder row = result.newRow();
        row.add(Root.COLUMN_ROOT_ID, id);
        row.add(Root.COLUMN_FLAGS, info.flags);
        row.add(Root.COLUMN_TITLE, id);
        row.add(Root.COLUMN_DOCUMENT_ID, info.document.documentId);
        row.add(Root.COLUMN_AVAILABLE_BYTES, info.getRemainingCapacity());
    }
    return result;
}
Also used : RowBuilder(android.database.MatrixCursor.RowBuilder) HashMap(java.util.HashMap) Map(java.util.Map) MatrixCursor(android.database.MatrixCursor)

Example 88 with MatrixCursor

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

the class SettingsProvider method packageSettingForQuery.

private static MatrixCursor packageSettingForQuery(Setting setting, String[] projection) {
    if (setting.isNull()) {
        return new MatrixCursor(projection, 0);
    }
    MatrixCursor cursor = new MatrixCursor(projection, 1);
    appendSettingToCursor(cursor, setting);
    return cursor;
}
Also used : MatrixCursor(android.database.MatrixCursor)

Example 89 with MatrixCursor

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

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;
    }
}
Also used : Setting(com.android.providers.settings.SettingsState.Setting) MatrixCursor(android.database.MatrixCursor)

Example 90 with MatrixCursor

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

the class RecentsLoader method loadInBackgroundLocked.

private DirectoryResult loadInBackgroundLocked() {
    if (mFirstPassLatch == null) {
        // First time through we kick off all the recent tasks, and wait
        // around to see if everyone finishes quickly.
        final Collection<RootInfo> roots = mRoots.getMatchingRootsBlocking(mState);
        for (RootInfo root : roots) {
            if (root.supportsRecents()) {
                mTasks.put(root, new RecentsTask(root.authority, root.rootId));
            }
        }
        mFirstPassLatch = new CountDownLatch(mTasks.size());
        for (RecentsTask task : mTasks.values()) {
            ProviderExecutor.forAuthority(task.authority).execute(task);
        }
        try {
            mFirstPassLatch.await(MAX_FIRST_PASS_WAIT_MILLIS, TimeUnit.MILLISECONDS);
            mFirstPassDone = true;
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    final long rejectBefore = System.currentTimeMillis() - REJECT_OLDER_THAN;
    // Collect all finished tasks
    boolean allDone = true;
    List<Cursor> cursors = new ArrayList<>();
    for (RecentsTask task : mTasks.values()) {
        if (task.isDone()) {
            try {
                final Cursor cursor = task.get();
                if (cursor == null)
                    continue;
                final FilteringCursorWrapper filtered = new FilteringCursorWrapper(cursor, mState.acceptMimes, RECENT_REJECT_MIMES, rejectBefore) {

                    @Override
                    public void close() {
                    // Ignored, since we manage cursor lifecycle internally
                    }
                };
                cursors.add(filtered);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            } catch (ExecutionException e) {
            // We already logged on other side
            } catch (Exception e) {
                Log.e(TAG, "Failed to query Recents for authority: " + task.authority + ". Skip this authority in Recents.", e);
            }
        } else {
            allDone = false;
        }
    }
    if (DEBUG) {
        Log.d(TAG, "Found " + cursors.size() + " of " + mTasks.size() + " recent queries done");
    }
    final DirectoryResult result = new DirectoryResult();
    result.sortOrder = SORT_ORDER_LAST_MODIFIED;
    final Cursor merged;
    if (cursors.size() > 0) {
        merged = new MergeCursor(cursors.toArray(new Cursor[cursors.size()]));
    } else {
        // Return something when nobody is ready
        merged = new MatrixCursor(new String[0]);
    }
    // Tell the UI if this is an in-progress result. When loading is complete, another update is
    // sent with EXTRA_LOADING set to false.
    Bundle extras = new Bundle();
    extras.putBoolean(DocumentsContract.EXTRA_LOADING, !allDone);
    merged.setExtras(extras);
    result.cursor = merged;
    return result;
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) MergeCursor(android.database.MergeCursor) CountDownLatch(java.util.concurrent.CountDownLatch) Cursor(android.database.Cursor) MergeCursor(android.database.MergeCursor) MatrixCursor(android.database.MatrixCursor) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) MatrixCursor(android.database.MatrixCursor) RootInfo(com.android.documentsui.model.RootInfo) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

MatrixCursor (android.database.MatrixCursor)259 Cursor (android.database.Cursor)37 DirectoryResult (com.android.documentsui.DirectoryResult)35 RowBuilder (android.database.MatrixCursor.RowBuilder)30 File (java.io.File)30 MergeCursor (android.database.MergeCursor)18 Uri (android.net.Uri)18 Test (org.junit.Test)17 Setting (com.android.providers.settings.SettingsState.Setting)15 FileNotFoundException (java.io.FileNotFoundException)15 ArrayList (java.util.ArrayList)13 Bundle (android.os.Bundle)10 BitSet (java.util.BitSet)10 Random (java.util.Random)10 IOException (java.io.IOException)7 LinkedList (java.util.LinkedList)7 ContentValues (android.content.ContentValues)6 HashSet (java.util.HashSet)6 Map (java.util.Map)6 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)5