Close Cursors when finished with them.

Change-Id: Idf284f59b05b3f5b3565f7374899927a70f3ca07
diff --git a/src/com/android/browser/BrowserDownloadPage.java b/src/com/android/browser/BrowserDownloadPage.java
index c56991e..6a5ef28 100644
--- a/src/com/android/browser/BrowserDownloadPage.java
+++ b/src/com/android/browser/BrowserDownloadPage.java
@@ -31,6 +31,7 @@
 import android.os.Bundle;
 import android.os.Handler;
 import android.provider.Downloads;
+import android.util.Log;
 import android.view.ContextMenu;
 import android.view.ContextMenu.ContextMenuInfo;
 import android.view.LayoutInflater;
@@ -63,6 +64,7 @@
     // will be reopened on this View.
     private View                    mSelectedView;
 
+    private final static String LOGTAG = "BrowserDownloadPage";
     @Override 
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
@@ -252,25 +254,31 @@
 
         @Override
         public void onChange(boolean selfChange) {
-            Cursor cursor = getContentResolver().query(mTrack,
-                    new String[] { Downloads.Impl.COLUMN_STATUS }, null, null,
-                    null);
-            if (cursor.moveToFirst() && Downloads.Impl.isStatusSuccess(
-                    cursor.getInt(0))) {
-                // Do this right away, so we get no more updates.
-                getContentResolver().unregisterContentObserver(
-                        mContentObserver);
-                // Post a runnable in case this ContentObserver gets notified
-                // before the one that updates the ListView.
-                mListView.post(new Runnable() {
-                    public void run() {
-                        // Close the context menu, reopen with up to date data.
-                        closeContextMenu();
-                        openContextMenu(mSelectedView);
-                    }
-                });
+            Cursor cursor = null;
+            try {
+                cursor = getContentResolver().query(mTrack,
+                        new String[] { Downloads.Impl.COLUMN_STATUS }, null, null,
+                        null);
+                if (cursor.moveToFirst() && Downloads.Impl.isStatusSuccess(
+                        cursor.getInt(0))) {
+                    // Do this right away, so we get no more updates.
+                    getContentResolver().unregisterContentObserver(
+                            mContentObserver);
+                    // Post a runnable in case this ContentObserver gets notified
+                    // before the one that updates the ListView.
+                    mListView.post(new Runnable() {
+                        public void run() {
+                            // Close the context menu, reopen with up to date data.
+                            closeContextMenu();
+                            openContextMenu(mSelectedView);
+                        }
+                    });
+                }
+            } catch (IllegalStateException e) {
+                Log.e(LOGTAG, "onChange", e);
+            } finally {
+                if (cursor != null) cursor.close();
             }
-            cursor.deactivate();
         }
     }