From d2183654e03d589b120467f4e98da1b178ceeadb Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Sun, 9 Oct 2011 12:39:53 -0700 Subject: Fix ownership of CursorWindows across processes. Bug: 5332296 Ensure that there is always an owner for each CursorWindow and that references to each window are acquired/released appropriately at all times. Added synchronization to CursorToBulkCursorAdaptor to prevent the underlying Cursor and CursorWindow from being remotely accessed in ways that might violate invariants, resulting in leaks or other problems. Ensured that CursorToBulkCursorAdaptor promptly releases its references to the Cursor and CursorWindow when closed so they don't stick around longer than they should, even if the remote end hangs onto the IBulkCursor for some reason. CursorWindow respects Parcelable.FLAG_WRITE_RETURN_VALUE as an indication that one reference to the CursorWindow is being released. Correspondingly, CursorToBulkCursorAdaptor acquires a reference to the CursorWindow before returning it to the caller. This change also prevents races from resulting in the transfer of an invalid CursorWindow over the wire. Ensured that BulkCursorToCursorAdaptor promptly releases its reference to the IBulkCursor when closed and throws on attempts to access the cursor while closed. Modified ContentProviderNative to handle both parts of the wrapping and unwrapping of Cursors into IBulkCursors. This makes it a lot easier to ensure that the right things happen on both ends. Also, it turns out that the only caller of IContentProvider.bulkQuery was ContentProviderNative itself so there was no need to support bulkQuery on ContentProviderProxy and it was just getting in the way. Implement CloseGuard on CursorWindow. Change-Id: Ib3c8305d3cc62322f38a06698d404a2989bb6ef9 --- .../bridge/android/BridgeContentProvider.java | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'tools/layoutlib') diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContentProvider.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContentProvider.java index 3835378..c91a3bf 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContentProvider.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContentProvider.java @@ -23,9 +23,6 @@ import android.content.IContentProvider; import android.content.OperationApplicationException; import android.content.res.AssetFileDescriptor; import android.database.Cursor; -import android.database.CursorWindow; -import android.database.IBulkCursor; -import android.database.IContentObserver; import android.net.Uri; import android.os.Bundle; import android.os.IBinder; @@ -41,78 +38,84 @@ import java.util.ArrayList; * TODO: never return null when the method is not supposed to. Return fake data instead. */ public final class BridgeContentProvider implements IContentProvider { - + @Override public ContentProviderResult[] applyBatch(ArrayList arg0) throws RemoteException, OperationApplicationException { // TODO Auto-generated method stub return null; } + @Override public int bulkInsert(Uri arg0, ContentValues[] arg1) throws RemoteException { // TODO Auto-generated method stub return 0; } - public IBulkCursor bulkQuery(Uri arg0, String[] arg1, String arg2, String[] arg3, - String arg4, IContentObserver arg5, CursorWindow arg6) throws RemoteException { - // TODO Auto-generated method stub - return null; - } - + @Override public Bundle call(String arg0, String arg1, Bundle arg2) throws RemoteException { // TODO Auto-generated method stub return null; } + @Override public int delete(Uri arg0, String arg1, String[] arg2) throws RemoteException { // TODO Auto-generated method stub return 0; } + @Override public String getType(Uri arg0) throws RemoteException { // TODO Auto-generated method stub return null; } + @Override public Uri insert(Uri arg0, ContentValues arg1) throws RemoteException { // TODO Auto-generated method stub return null; } + @Override public AssetFileDescriptor openAssetFile(Uri arg0, String arg1) throws RemoteException, FileNotFoundException { // TODO Auto-generated method stub return null; } + @Override public ParcelFileDescriptor openFile(Uri arg0, String arg1) throws RemoteException, FileNotFoundException { // TODO Auto-generated method stub return null; } + @Override public Cursor query(Uri arg0, String[] arg1, String arg2, String[] arg3, String arg4) throws RemoteException { // TODO Auto-generated method stub return null; } + @Override public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) throws RemoteException { // TODO Auto-generated method stub return 0; } + @Override public IBinder asBinder() { // TODO Auto-generated method stub return null; } + @Override public String[] getStreamTypes(Uri arg0, String arg1) throws RemoteException { // TODO Auto-generated method stub return null; } + @Override public AssetFileDescriptor openTypedAssetFile(Uri arg0, String arg1, Bundle arg2) throws RemoteException, FileNotFoundException { // TODO Auto-generated method stub -- cgit v1.1