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

Commit f3be60a6 authored by Steve McKay's avatar Steve McKay
Browse files

Update PageViewCursor to correctly load window.

Bug: 36485764
Test: CTS updated and passing.
Change-Id: I2b615d97fdaedef441065889ce3a2988b718795c
parent a7353961
Loading
Loading
Loading
Loading
+43 −6
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import static com.android.internal.util.Preconditions.checkArgument;

import android.annotation.Nullable;
import android.content.ContentResolver;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.util.MathUtils;
@@ -33,22 +34,24 @@ import com.android.internal.util.ArrayUtils;
 *
 * @hide
 */
public final class PageViewCursor extends CrossProcessCursorWrapper {
public final class PageViewCursor extends CursorWrapper implements CrossProcessCursor {

    /**
     * An extra added to results that are auto-paged using the wrapper.
     * An in internal extra added to results that are auto-paged using the wrapper.
     */
    public static final String EXTRA_AUTO_PAGED = "android.content.extra.AUTO_PAGED";

    private static final String TAG = "PageViewCursor";
    private static final boolean DEBUG = false;
    private static final boolean VERBOSE = false;
    private static final boolean DEBUG = Build.IS_DEBUGGABLE;
    private static final boolean VERBOSE = Build.IS_DEBUGGABLE && Log.isLoggable(TAG, Log.VERBOSE);

    private final int mOffset;  // aka first index
    private final int mCount;
    private final Bundle mExtras;

    private @Nullable CursorWindow mWindow;
    private int mPos = -1;
    private int mWindowFillCount = 0;

    /**
     * @see PageViewCursor#wrap(Cursor, Bundle)
@@ -195,6 +198,33 @@ public final class PageViewCursor extends CrossProcessCursorWrapper {
        return mCount;
    }

    @Override
    public boolean getWantsAllOnMoveCalls() {
        return false;  // we want bulk cursor adapter to lift data into a CursorWindow.
    }

    @Override
    public CursorWindow getWindow() {
        assert(mPos == -1 || mPos == 0);
        if (mWindow == null) {
           mWindow = new CursorWindow("PageViewCursorWindow");
           fillWindow(0, mWindow);
        }

        return mWindow;
    }

    @Override
    public void fillWindow(int position, CursorWindow window) {
        assert(window == mWindow);

        if (mWindowFillCount++ > 0) {
            Log.w(TAG, "Re-filling window on paged cursor! Reduce ContentResolver.QUERY_ARG_LIMIT");
        }

        DatabaseUtils.cursorFillWindow(this, position, window);
    }

    /**
     * Wraps the cursor such that it will honor paging args (if present), AND if the cursor
     * does not report paging size.
@@ -209,12 +239,19 @@ public final class PageViewCursor extends CrossProcessCursorWrapper {
                || queryArgs.containsKey(ContentResolver.QUERY_ARG_LIMIT));

        if (!hasPagingArgs) {
            if (VERBOSE) Log.d(TAG, "No-wrap: No paging args in request.");
            if (VERBOSE) Log.v(TAG, "No-wrap: No paging args in request.");
            return cursor;
        }

        if (hasPagedResponseDetails(cursor.getExtras())) {
            if (VERBOSE) Log.d(TAG, "No-wrap. Cursor has paging details.");
            if (VERBOSE) Log.v(TAG, "No-wrap. Cursor has paging details.");
            return cursor;
        }

        // Cursors that want all calls aren't compatible with our way
        // of doing business. TODO: Cover this case in CTS.
        if (cursor.getWantsAllOnMoveCalls()) {
            Log.w(TAG, "Unable to wrap cursor that wants to hear about move calls.");
            return cursor;
        }

+8 −7
Original line number Diff line number Diff line
@@ -19,15 +19,9 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import android.annotation.Nullable;
import android.content.ContentResolver;
import android.os.Bundle;
import android.support.test.runner.AndroidJUnit4;
import android.util.Log;
import android.util.MathUtils;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils;

import org.junit.Before;
import org.junit.Test;
@@ -259,11 +253,18 @@ public class PageViewCursorTest {
    }

    @Test
    public void testPagingMarker() {
    public void testAutoPagedExtra() {
        mCursor = new PageViewCursor(mDelegate, 5, 100);
        assertTrue(mCursor.getExtras().getBoolean(PageViewCursor.EXTRA_AUTO_PAGED));
    }

    @Test
    public void testGetWindow() {
        mCursor = new PageViewCursor(mDelegate, 5, 5);
        CursorWindow window = mCursor.getWindow();
        assertEquals(5, window.getNumRows());
    }

    @Test
    public void testWrap() {
        Bundle queryArgs = new Bundle();