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

Commit 04263dc5 authored by Jeff Brown's avatar Jeff Brown Committed by Android (Google) Code Review
Browse files

Merge "AbstractWindowedCursor is not special."

parents d0085108 b4009c73
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()) {