@@ -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
0 commit comments