Skip to content

Commit 3014ea3

Browse files
author
The Android Automerger
committed
Revert "Use ashmem for CursorWindows."
This reverts commit 0cde89f.
1 parent a062bd3 commit 3014ea3

13 files changed

+805
-683
lines changed

core/java/android/content/ContentProviderNative.java

Lines changed: 59 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,21 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
108108
String sortOrder = data.readString();
109109
IContentObserver observer = IContentObserver.Stub.asInterface(
110110
data.readStrongBinder());
111+
CursorWindow window = CursorWindow.CREATOR.createFromParcel(data);
111112

112113
Cursor cursor = query(url, projection, selection, selectionArgs, sortOrder);
113114
if (cursor != null) {
114115
CursorToBulkCursorAdaptor adaptor = new CursorToBulkCursorAdaptor(
115-
cursor, observer, getProviderName());
116+
cursor, observer, getProviderName(), window);
116117
final IBinder binder = adaptor.asBinder();
117118
final int count = adaptor.count();
118119
final int index = BulkCursorToCursorAdaptor.findRowIdColumnIndex(
119120
adaptor.getColumnNames());
120-
final boolean wantsAllOnMoveCalls = adaptor.getWantsAllOnMoveCalls();
121121

122122
reply.writeNoException();
123123
reply.writeStrongBinder(binder);
124124
reply.writeInt(count);
125125
reply.writeInt(index);
126-
reply.writeInt(wantsAllOnMoveCalls ? 1 : 0);
127126
} else {
128127
reply.writeNoException();
129128
reply.writeStrongBinder(null);
@@ -325,58 +324,67 @@ public IBinder asBinder()
325324

326325
public Cursor query(Uri url, String[] projection, String selection,
327326
String[] selectionArgs, String sortOrder) throws RemoteException {
328-
BulkCursorToCursorAdaptor adaptor = new BulkCursorToCursorAdaptor();
329-
Parcel data = Parcel.obtain();
330-
Parcel reply = Parcel.obtain();
327+
CursorWindow window = new CursorWindow(false /* window will be used remotely */);
331328
try {
332-
data.writeInterfaceToken(IContentProvider.descriptor);
333-
334-
url.writeToParcel(data, 0);
335-
int length = 0;
336-
if (projection != null) {
337-
length = projection.length;
338-
}
339-
data.writeInt(length);
340-
for (int i = 0; i < length; i++) {
341-
data.writeString(projection[i]);
342-
}
343-
data.writeString(selection);
344-
if (selectionArgs != null) {
345-
length = selectionArgs.length;
346-
} else {
347-
length = 0;
348-
}
349-
data.writeInt(length);
350-
for (int i = 0; i < length; i++) {
351-
data.writeString(selectionArgs[i]);
352-
}
353-
data.writeString(sortOrder);
354-
data.writeStrongBinder(adaptor.getObserver().asBinder());
355-
356-
mRemote.transact(IContentProvider.QUERY_TRANSACTION, data, reply, 0);
357-
358-
DatabaseUtils.readExceptionFromParcel(reply);
359-
360-
IBulkCursor bulkCursor = BulkCursorNative.asInterface(reply.readStrongBinder());
361-
if (bulkCursor != null) {
362-
int rowCount = reply.readInt();
363-
int idColumnPosition = reply.readInt();
364-
boolean wantsAllOnMoveCalls = reply.readInt() != 0;
365-
adaptor.initialize(bulkCursor, rowCount, idColumnPosition, wantsAllOnMoveCalls);
366-
} else {
329+
BulkCursorToCursorAdaptor adaptor = new BulkCursorToCursorAdaptor();
330+
Parcel data = Parcel.obtain();
331+
Parcel reply = Parcel.obtain();
332+
try {
333+
data.writeInterfaceToken(IContentProvider.descriptor);
334+
335+
url.writeToParcel(data, 0);
336+
int length = 0;
337+
if (projection != null) {
338+
length = projection.length;
339+
}
340+
data.writeInt(length);
341+
for (int i = 0; i < length; i++) {
342+
data.writeString(projection[i]);
343+
}
344+
data.writeString(selection);
345+
if (selectionArgs != null) {
346+
length = selectionArgs.length;
347+
} else {
348+
length = 0;
349+
}
350+
data.writeInt(length);
351+
for (int i = 0; i < length; i++) {
352+
data.writeString(selectionArgs[i]);
353+
}
354+
data.writeString(sortOrder);
355+
data.writeStrongBinder(adaptor.getObserver().asBinder());
356+
window.writeToParcel(data, 0);
357+
358+
mRemote.transact(IContentProvider.QUERY_TRANSACTION, data, reply, 0);
359+
360+
DatabaseUtils.readExceptionFromParcel(reply);
361+
362+
IBulkCursor bulkCursor = BulkCursorNative.asInterface(reply.readStrongBinder());
363+
if (bulkCursor != null) {
364+
int rowCount = reply.readInt();
365+
int idColumnPosition = reply.readInt();
366+
adaptor.initialize(bulkCursor, rowCount, idColumnPosition);
367+
} else {
368+
adaptor.close();
369+
adaptor = null;
370+
}
371+
return adaptor;
372+
} catch (RemoteException ex) {
373+
adaptor.close();
374+
throw ex;
375+
} catch (RuntimeException ex) {
367376
adaptor.close();
368-
adaptor = null;
377+
throw ex;
378+
} finally {
379+
data.recycle();
380+
reply.recycle();
369381
}
370-
return adaptor;
371-
} catch (RemoteException ex) {
372-
adaptor.close();
373-
throw ex;
374-
} catch (RuntimeException ex) {
375-
adaptor.close();
376-
throw ex;
377382
} finally {
378-
data.recycle();
379-
reply.recycle();
383+
// We close the window now because the cursor adaptor does not
384+
// take ownership of the window until the first call to onMove.
385+
// The adaptor will obtain a fresh reference to the window when
386+
// it is filled.
387+
window.close();
380388
}
381389
}
382390

core/java/android/database/AbstractWindowedCursor.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,12 @@ protected void closeWindow() {
189189
/**
190190
* If there is a window, clear it.
191191
* Otherwise, creates a local window.
192-
*
193-
* @param name The window name.
194192
* @hide
195193
*/
196-
protected void clearOrCreateLocalWindow(String name) {
194+
protected void clearOrCreateLocalWindow() {
197195
if (mWindow == null) {
198196
// If there isn't a window set already it will only be accessed locally
199-
mWindow = new CursorWindow(name, true /* the window is local only */);
197+
mWindow = new CursorWindow(true /* the window is local only */);
200198
} else {
201199
mWindow.clear();
202200
}

core/java/android/database/BulkCursorNative.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
109109
case REQUERY_TRANSACTION: {
110110
data.enforceInterface(IBulkCursor.descriptor);
111111
IContentObserver observer =
112-
IContentObserver.Stub.asInterface(data.readStrongBinder());
113-
int count = requery(observer);
112+
IContentObserver.Stub.asInterface(data.readStrongBinder());
113+
CursorWindow window = CursorWindow.CREATOR.createFromParcel(data);
114+
int count = requery(observer, window);
114115
reply.writeNoException();
115116
reply.writeInt(count);
116117
reply.writeBundle(getExtras());
@@ -293,12 +294,13 @@ public void close() throws RemoteException
293294
}
294295
}
295296

296-
public int requery(IContentObserver observer) throws RemoteException {
297+
public int requery(IContentObserver observer, CursorWindow window) throws RemoteException {
297298
Parcel data = Parcel.obtain();
298299
Parcel reply = Parcel.obtain();
299300
try {
300301
data.writeInterfaceToken(IBulkCursor.descriptor);
301302
data.writeStrongInterface(observer);
303+
window.writeToParcel(data, 0);
302304

303305
boolean result = mRemote.transact(REQUERY_TRANSACTION, data, reply, 0);
304306
DatabaseUtils.readExceptionFromParcel(reply);

core/java/android/database/BulkCursorToCursorAdaptor.java

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ public final class BulkCursorToCursorAdaptor extends AbstractWindowedCursor {
3838
* Initializes the adaptor.
3939
* Must be called before first use.
4040
*/
41-
public void initialize(IBulkCursor bulkCursor, int count, int idIndex,
42-
boolean wantsAllOnMoveCalls) {
41+
public void initialize(IBulkCursor bulkCursor, int count, int idIndex) {
4342
mBulkCursor = bulkCursor;
4443
mColumns = null; // lazily retrieved
4544
mCount = count;
4645
mRowIdColumnIndex = idIndex;
47-
mWantsAllOnMoveCalls = wantsAllOnMoveCalls;
4846
}
4947

5048
/**
@@ -88,12 +86,15 @@ public boolean onMove(int oldPosition, int newPosition) {
8886

8987
try {
9088
// Make sure we have the proper window
91-
if (mWindow == null
92-
|| newPosition < mWindow.getStartPosition()
93-
|| newPosition >= mWindow.getStartPosition() + mWindow.getNumRows()) {
89+
if (mWindow != null) {
90+
if (newPosition < mWindow.getStartPosition() ||
91+
newPosition >= (mWindow.getStartPosition() + mWindow.getNumRows())) {
92+
setWindow(mBulkCursor.getWindow(newPosition));
93+
} else if (mWantsAllOnMoveCalls) {
94+
mBulkCursor.onMove(newPosition);
95+
}
96+
} else {
9497
setWindow(mBulkCursor.getWindow(newPosition));
95-
} else if (mWantsAllOnMoveCalls) {
96-
mBulkCursor.onMove(newPosition);
9798
}
9899
} catch (RemoteException ex) {
99100
// We tried to get a window and failed
@@ -144,19 +145,25 @@ public boolean requery() {
144145
throwIfCursorIsClosed();
145146

146147
try {
147-
mCount = mBulkCursor.requery(getObserver());
148-
if (mCount != -1) {
149-
mPos = -1;
150-
closeWindow();
151-
152-
// super.requery() will call onChanged. Do it here instead of relying on the
153-
// observer from the far side so that observers can see a correct value for mCount
154-
// when responding to onChanged.
155-
super.requery();
156-
return true;
157-
} else {
158-
deactivate();
159-
return false;
148+
CursorWindow newWindow = new CursorWindow(false /* create a remote window */);
149+
try {
150+
mCount = mBulkCursor.requery(getObserver(), newWindow);
151+
if (mCount != -1) {
152+
mPos = -1;
153+
closeWindow();
154+
155+
// super.requery() will call onChanged. Do it here instead of relying on the
156+
// observer from the far side so that observers can see a correct value for mCount
157+
// when responding to onChanged.
158+
super.requery();
159+
return true;
160+
} else {
161+
deactivate();
162+
return false;
163+
}
164+
} finally {
165+
// Don't take ownership of the window until the next call to onMove.
166+
newWindow.close();
160167
}
161168
} catch (Exception ex) {
162169
Log.e(TAG, "Unable to requery because the remote process exception " + ex.getMessage());

0 commit comments

Comments
 (0)