Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dbf3e29f authored by Steve McKay's avatar Steve McKay Committed by Android (Google) Code Review
Browse files

Merge changes from topic 'ArcPagingBackport' into arc-apps

* changes:
  Make Sorting/paging honor ENABLE_OMC_FEATURES flag
  Test/Demo paging support in DocsUI.
  Don't sort pre-sorted results.
parents 7465b4db f208d845
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.Context;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.Handler;
import android.os.OperationCanceledException;
@@ -31,6 +32,7 @@ import android.provider.DocumentsContract.Document;
import android.util.Log;

import com.android.documentsui.archives.ArchivesProvider;
import com.android.documentsui.base.DebugFlags;
import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.FilteringCursorWrapper;
import com.android.documentsui.base.RootInfo;
@@ -97,8 +99,21 @@ public class DirectoryLoader extends AsyncTaskLoader<DirectoryResult> {
                ArchivesProvider.acquireArchive(client, mUri);
            }
            result.client = client;

            if (Shared.ENABLE_OMC_API_FEATURES) {
                Bundle queryArgs = new Bundle();
                mModel.addQuerySortArgs(queryArgs);

                // TODO: At some point we don't want forced flags to override real paging...
                // and that point is when we have real paging.
                DebugFlags.addForcedPagingArgs(queryArgs);

                cursor = client.query(mUri, null, queryArgs, mSignal);
            } else {
                cursor = client.query(
                        mUri, null, null, null, mModel.getDocumentSortQuery(), mSignal);
            }

            if (cursor == null) {
                throw new RemoteException("Provider returned null");
            }
+13 −6
Original line number Diff line number Diff line
@@ -35,15 +35,16 @@ import android.util.Log;

import com.android.documentsui.base.FilteringCursorWrapper;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.base.Shared;
import com.android.documentsui.base.State;
import com.android.documentsui.roots.RootCursorWrapper;
import com.android.documentsui.roots.RootsAccess;
import com.android.internal.annotations.GuardedBy;

import libcore.io.IoUtils;

import com.google.common.util.concurrent.AbstractFuture;

import libcore.io.IoUtils;

import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
@@ -326,11 +327,17 @@ public class RecentsLoader extends AsyncTaskLoader<DirectoryResult> {
                final Cursor[] res = new Cursor[rootIds.size()];
                mCursors = new Cursor[rootIds.size()];
                for (int i = 0; i < rootIds.size(); i++) {
                    final Uri uri = DocumentsContract.buildRecentDocumentsUri(authority,
                            rootIds.get(i));
                    final Uri uri =
                            DocumentsContract.buildRecentDocumentsUri(authority, rootIds.get(i));
                    try {
                        if (Shared.ENABLE_OMC_API_FEATURES) {
                            final Bundle queryArgs = new Bundle();
                            mState.sortModel.addQuerySortArgs(queryArgs);
                            res[i] = client.query(uri, null, queryArgs, null);
                        } else {
                            res[i] = client.query(
                                    uri, null, null, null, mState.sortModel.getDocumentSortQuery());
                        }
                        mCursors[i] = new RootCursorWrapper(authority, rootIds.get(i), res[i],
                                MAX_DOCS_FROM_ROOT);
                    } catch (Exception e) {
+26 −0
Original line number Diff line number Diff line
@@ -15,6 +15,11 @@
 */
package com.android.documentsui.base;

import android.content.ContentResolver;
import android.os.Bundle;

import com.android.documentsui.queries.DebugCommandProcessor;

import javax.annotation.Nullable;

/**
@@ -27,6 +32,8 @@ public final class DebugFlags {
    private static String mQvPackage;
    private static boolean sGestureScaleEnabled;
    private static boolean sDocumentDetailsEnabled;
    private static int sForcedPageOffset = -1;
    private static int sForcedPageLimit = -1;

    public static void setQuickViewer(@Nullable String qvPackage) {
        mQvPackage = qvPackage;
@@ -51,4 +58,23 @@ public final class DebugFlags {
    public static boolean getGestureScaleEnabled() {
        return sGestureScaleEnabled;
    }

    public static void setForcedPaging(int offset, int limit) {
        sForcedPageOffset = offset;
        sForcedPageLimit = limit;
    }

    public static boolean addForcedPagingArgs(Bundle queryArgs) {
        assert(Shared.ENABLE_OMC_API_FEATURES);
        boolean flagsAdded = false;
        if (sForcedPageOffset >= 0) {
            queryArgs.putInt(ContentResolver.QUERY_ARG_OFFSET, sForcedPageOffset);
            flagsAdded |= true;
        }
        if (sForcedPageLimit >= 0) {
            queryArgs.putInt(ContentResolver.QUERY_ARG_LIMIT, sForcedPageLimit);
            flagsAdded |= true;
        }
        return flagsAdded;
    }
}
+32 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.util.Log;
import com.android.documentsui.DocumentsApplication;
import com.android.documentsui.base.DebugFlags;
import com.android.documentsui.base.EventHandler;
import com.android.documentsui.base.Shared;

import java.util.ArrayList;
import java.util.List;
@@ -42,6 +43,7 @@ public final class DebugCommandProcessor implements EventHandler<String> {
            mCommands.add(DebugCommandProcessor::quickViewer);
            mCommands.add(DebugCommandProcessor::gestureScale);
            mCommands.add(DebugCommandProcessor::docDetails);
            mCommands.add(DebugCommandProcessor::forcePaging);
        }
    }

@@ -108,6 +110,36 @@ public final class DebugCommandProcessor implements EventHandler<String> {
        return false;
    }

    private static boolean forcePaging(String[] tokens) {
        if (!Shared.ENABLE_OMC_API_FEATURES) {
            Log.i(TAG, "Paging is disabled.");
            return false;
        }

        if ("page".equals(tokens[0])) {
            if (tokens.length >= 2) {
                try {
                    int offset = Integer.parseInt(tokens[1]);
                    int limit = (tokens.length == 3) ? Integer.parseInt(tokens[2]) : -1;
                    DebugFlags.setForcedPaging(offset, limit);
                    Log.i(TAG, "Set forced paging to offset: " + offset + ", limit: " + limit);
                    return true;
                } catch (NumberFormatException e) {
                    Log.w(TAG, "Command input does not contain valid numbers: "
                            + TextUtils.join(" ", tokens));
                    return false;
                }
            } else {
                Log.w(TAG, "Invalid command structure: " + TextUtils.join(" ", tokens));
            }
        } else if ("deqv".equals(tokens[0])) {
            Log.i(TAG, "Unset quick viewer");
            DebugFlags.setQuickViewer(null);
            return true;
        }
        return false;
    }

    private static final boolean asBool(String val) {
        if (val == null || val.equals("0")) {
            return false;
+61 −0
Original line number Diff line number Diff line
@@ -17,10 +17,14 @@
package com.android.documentsui.sorting;

import static com.android.documentsui.base.Shared.DEBUG;
import static com.android.documentsui.base.Shared.ENABLE_OMC_API_FEATURES;
import static com.android.documentsui.base.Shared.VERBOSE;

import android.annotation.IntDef;
import android.annotation.Nullable;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.provider.DocumentsContract.Document;
@@ -29,6 +33,7 @@ import android.util.SparseArray;
import android.view.View;

import com.android.documentsui.R;
import com.android.documentsui.base.Shared;
import com.android.documentsui.sorting.SortDimension.SortDirection;

import java.lang.annotation.Retention;
@@ -220,6 +225,15 @@ public class SortModel implements Parcelable {
    }

    public Cursor sortCursor(Cursor cursor) {
        if (ENABLE_OMC_API_FEATURES
                && cursor.getExtras().containsKey(ContentResolver.QUERY_ARG_SORT_COLUMNS)) {
            if (VERBOSE) Log.i(TAG, "Cursor is pre-sorted by provider. Skipping sort. Booya!");

            // TODO: assert that the contents of QUERY_ARG_SORT_COLUMNS
            // matches the sort dimension...once we're returning any pre-sorted results.
            return cursor;
        }

        if (mSortedDimension != null) {
            return new SortingCursorWrapper(cursor, mSortedDimension);
        } else {
@@ -227,7 +241,54 @@ public class SortModel implements Parcelable {
        }
    }

    public void addQuerySortArgs(Bundle queryArgs) {
        assert(Shared.ENABLE_OMC_API_FEATURES);

        final int id = getSortedDimensionId();
        switch (id) {
            case SORT_DIMENSION_ID_UNKNOWN:
                return;
            case SortModel.SORT_DIMENSION_ID_TITLE:
                queryArgs.putStringArray(
                        ContentResolver.QUERY_ARG_SORT_COLUMNS,
                        new String[]{ Document.COLUMN_DISPLAY_NAME });
                break;
            case SortModel.SORT_DIMENSION_ID_DATE:
                queryArgs.putStringArray(
                        ContentResolver.QUERY_ARG_SORT_COLUMNS,
                        new String[]{ Document.COLUMN_LAST_MODIFIED });
                break;
            case SortModel.SORT_DIMENSION_ID_SIZE:
                queryArgs.putStringArray(
                        ContentResolver.QUERY_ARG_SORT_COLUMNS,
                        new String[]{ Document.COLUMN_SIZE });
                break;
            default:
                throw new IllegalStateException(
                        "Unexpected sort dimension id: " + id);
        }

        final SortDimension dimension = getDimensionById(id);
        switch (dimension.getSortDirection()) {
            case SortDimension.SORT_DIRECTION_ASCENDING:
                queryArgs.putInt(
                        ContentResolver.QUERY_ARG_SORT_DIRECTION,
                        ContentResolver.QUERY_SORT_DIRECTION_ASCENDING);
                break;
            case SortDimension.SORT_DIRECTION_DESCENDING:
                queryArgs.putInt(
                        ContentResolver.QUERY_ARG_SORT_DIRECTION,
                        ContentResolver.QUERY_SORT_DIRECTION_DESCENDING);
                break;
            default:
                throw new IllegalStateException(
                        "Unexpected sort direction: " + dimension.getSortDirection());
        }
    }

    public @Nullable String getDocumentSortQuery() {
        assert(!Shared.ENABLE_OMC_API_FEATURES);

        final int id = getSortedDimensionId();
        final String columnName;
        switch (id) {
Loading