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

Commit b4009c73 authored by Jeff Brown's avatar Jeff Brown
Browse files

AbstractWindowedCursor is not special.

Use the CrossProcessCursor interface in the way it was intended
without introducing special cases for AbstractWindowedCursor.
This is possible now that we do not distinguish between local-only
and remotable CursorWindows so we don't need to provide a window
to the AbstractWindowedCursor for it to fill; it can provide one
for itself if it wants one.

This logic makes it possible to create CrossProcessCursor
implementations that perform just as well as AbstractWindowedCursors.

Change-Id: I764b25ee6311d28c50d1930705346b265faec86a
parent 80e7b80f
Loading
Loading
Loading
Loading
+27 −35
Original line number Diff line number Diff line
@@ -25,9 +25,9 @@ import android.util.Log;
/**
 * Wraps a BulkCursor around an existing Cursor making it remotable.
 * <p>
 * If the wrapped cursor is a {@link AbstractWindowedCursor} then it owns
 * the cursor window.  Otherwise, the adaptor takes ownership of the
 * cursor itself and ensures it gets closed as needed during deactivation
 * If the wrapped cursor returns non-null from {@link CrossProcessCursor#getWindow}
 * then it is assumed to own the window.  Otherwise, the adaptor provides a
 * window to be filled and ensures it gets closed as needed during deactivation
 * and requeries.
 * </p>
 *
@@ -48,12 +48,11 @@ public final class CursorToBulkCursorAdaptor extends BulkCursorNative
    private CrossProcessCursor mCursor;

    /**
     * The cursor window used by the cross process cursor.
     * This field is always null for abstract windowed cursors since they are responsible
     * for managing the lifetime of their window.
     * The cursor window that was filled by the cross process cursor in the
     * case where the cursor does not support getWindow.
     * This field is only ever non-null when the window has actually be filled.
     */
    private CursorWindow mWindowForNonWindowedCursor;
    private boolean mWindowForNonWindowedCursorWasFilled;
    private CursorWindow mFilledWindow;

    private static final class ContentObserverProxy extends ContentObserver {
        protected IContentObserver mRemote;
@@ -103,11 +102,10 @@ public final class CursorToBulkCursorAdaptor extends BulkCursorNative
        }
    }

    private void closeWindowForNonWindowedCursorLocked() {
        if (mWindowForNonWindowedCursor != null) {
            mWindowForNonWindowedCursor.close();
            mWindowForNonWindowedCursor = null;
            mWindowForNonWindowedCursorWasFilled = false;
    private void closeFilledWindowLocked() {
        if (mFilledWindow != null) {
            mFilledWindow.close();
            mFilledWindow = null;
        }
    }

@@ -118,7 +116,7 @@ public final class CursorToBulkCursorAdaptor extends BulkCursorNative
            mCursor = null;
        }

        closeWindowForNonWindowedCursorLocked();
        closeFilledWindowLocked();
    }

    private void throwIfCursorIsClosed() {
@@ -139,30 +137,24 @@ public final class CursorToBulkCursorAdaptor extends BulkCursorNative
        synchronized (mLock) {
            throwIfCursorIsClosed();

            CursorWindow window;
            if (mCursor instanceof AbstractWindowedCursor) {
                AbstractWindowedCursor windowedCursor = (AbstractWindowedCursor)mCursor;
                window = windowedCursor.getWindow();
                if (window == null) {
                    window = new CursorWindow(mProviderName);
                    windowedCursor.setWindow(window);
            if (!mCursor.moveToPosition(startPos)) {
                closeFilledWindowLocked();
                return null;
            }

                mCursor.moveToPosition(startPos);
            CursorWindow window = mCursor.getWindow();
            if (window != null) {
                closeFilledWindowLocked();
            } else {
                window = mWindowForNonWindowedCursor;
                window = mFilledWindow;
                if (window == null) {
                    window = new CursorWindow(mProviderName);
                    mWindowForNonWindowedCursor = window;
                }

                mCursor.moveToPosition(startPos);

                if (!mWindowForNonWindowedCursorWasFilled
                        || startPos < window.getStartPosition()
                    mFilledWindow = new CursorWindow(mProviderName);
                    window = mFilledWindow;
                    mCursor.fillWindow(startPos, window);
                } else if (startPos < window.getStartPosition()
                        || startPos >= window.getStartPosition() + window.getNumRows()) {
                    window.clear();
                    mCursor.fillWindow(startPos, window);
                    mWindowForNonWindowedCursorWasFilled = true;
                }
            }

@@ -211,7 +203,7 @@ public final class CursorToBulkCursorAdaptor extends BulkCursorNative
                mCursor.deactivate();
            }

            closeWindowForNonWindowedCursorLocked();
            closeFilledWindowLocked();
        }
    }

@@ -227,7 +219,7 @@ public final class CursorToBulkCursorAdaptor extends BulkCursorNative
        synchronized (mLock) {
            throwIfCursorIsClosed();

            closeWindowForNonWindowedCursorLocked();
            closeFilledWindowLocked();

            try {
                if (!mCursor.requery()) {