Skip to content

Commit f78da99

Browse files
author
The Android Automerger
committed
Revert "Clean up CursorWindow lifetime."
This reverts commit 7ce7452.
1 parent 8f2eb43 commit f78da99

File tree

10 files changed

+582
-186
lines changed

10 files changed

+582
-186
lines changed

core/java/android/database/AbstractCursor.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ public byte[] getBlob(int column) {
6464
/* Methods that may optionally be implemented by subclasses */
6565

6666
/**
67-
* If the cursor is backed by a {@link CursorWindow}, returns a pre-filled
68-
* window with the contents of the cursor, otherwise null.
69-
*
70-
* @return The pre-filled window that backs this cursor, or null if none.
67+
* returns a pre-filled window, return NULL if no such window
7168
*/
7269
public CursorWindow getWindow() {
7370
return null;

core/java/android/database/AbstractWindowedCursor.java

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,8 @@
1818

1919
/**
2020
* A base class for Cursors that store their data in {@link CursorWindow}s.
21-
* <p>
22-
* Subclasses are responsible for filling the cursor window with data during
23-
* {@link #onMove(int, int)}, allocating a new cursor window if necessary.
24-
* During {@link #requery()}, the existing cursor window should be cleared and
25-
* filled with new data.
26-
* </p><p>
27-
* If the contents of the cursor change or become invalid, the old window must be closed
28-
* (because it is owned by the cursor) and set to null.
29-
* </p>
3021
*/
3122
public abstract class AbstractWindowedCursor extends AbstractCursor {
32-
/**
33-
* The cursor window owned by this cursor.
34-
*/
35-
protected CursorWindow mWindow;
36-
3723
@Override
3824
public byte[] getBlob(int columnIndex) {
3925
checkPosition();
@@ -140,44 +126,25 @@ protected void checkPosition() {
140126
public CursorWindow getWindow() {
141127
return mWindow;
142128
}
143-
129+
144130
/**
145-
* Sets a new cursor window for the cursor to use.
146-
* <p>
147-
* The cursor takes ownership of the provided cursor window; the cursor window
148-
* will be closed when the cursor is closed or when the cursor adopts a new
149-
* cursor window.
150-
* </p><p>
151-
* If the cursor previously had a cursor window, then it is closed when the
152-
* new cursor window is assigned.
153-
* </p>
154-
*
155-
* @param window The new cursor window, typically a remote cursor window.
131+
* Set a new cursor window to cursor, usually set a remote cursor window
132+
* @param window cursor window
156133
*/
157134
public void setWindow(CursorWindow window) {
158-
if (window != mWindow) {
159-
closeWindow();
160-
mWindow = window;
135+
if (mWindow != null) {
136+
mWindow.close();
161137
}
138+
mWindow = window;
162139
}
163-
164-
/**
165-
* Returns true if the cursor has an associated cursor window.
166-
*
167-
* @return True if the cursor has an associated cursor window.
168-
*/
140+
169141
public boolean hasWindow() {
170142
return mWindow != null;
171143
}
172144

173145
/**
174-
* Closes the cursor window and sets {@link #mWindow} to null.
175-
* @hide
146+
* This needs be updated in {@link #onMove} by subclasses, and
147+
* needs to be set to NULL when the contents of the cursor change.
176148
*/
177-
protected void closeWindow() {
178-
if (mWindow != null) {
179-
mWindow.close();
180-
mWindow = null;
181-
}
182-
}
149+
protected CursorWindow mWindow;
183150
}

core/java/android/database/BulkCursorToCursorAdaptor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ public boolean requery() {
154154
false /* the window will be accessed across processes */));
155155
if (mCount != -1) {
156156
mPos = -1;
157-
closeWindow();
157+
if (mWindow != null) {
158+
mWindow.close();
159+
mWindow = null;
160+
}
158161

159162
// super.requery() will call onChanged. Do it here instead of relying on the
160163
// observer from the far side so that observers can see a correct value for mCount

core/java/android/database/CursorWindow.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,8 @@ private CursorWindow(Parcel source) {
105105
}
106106

107107
@Override
108-
protected void finalize() throws Throwable {
109-
try {
110-
dispose();
111-
} finally {
112-
super.finalize();
113-
}
108+
protected void finalize() {
109+
dispose();
114110
}
115111

116112
private void dispose() {
@@ -149,25 +145,21 @@ public void clear() {
149145

150146
/**
151147
* Gets the start position of this cursor window.
152-
* <p>
153-
* The start position is the zero-based index of the first row that this window contains
148+
* The start position is the index of the first row that this window contains
154149
* relative to the entire result set of the {@link Cursor}.
155-
* </p>
156150
*
157-
* @return The zero-based start position.
151+
* @return The start position.
158152
*/
159153
public int getStartPosition() {
160154
return mStartPos;
161155
}
162156

163157
/**
164158
* Sets the start position of this cursor window.
165-
* <p>
166-
* The start position is the zero-based index of the first row that this window contains
159+
* The start position is the index of the first row that this window contains
167160
* relative to the entire result set of the {@link Cursor}.
168-
* </p>
169161
*
170-
* @param pos The new zero-based start position.
162+
* @param pos The new start position.
171163
*/
172164
public void setStartPosition(int pos) {
173165
mStartPos = pos;

core/java/android/database/CursorWrapper.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ public CursorWrapper(Cursor cursor) {
3333
}
3434

3535
/**
36-
* Gets the underlying cursor that is wrapped by this instance.
37-
*
38-
* @return The wrapped cursor.
36+
* @return the wrapped cursor
3937
*/
4038
public Cursor getWrappedCursor() {
4139
return mCursor;

0 commit comments

Comments
 (0)