Use existing respond hack to close GlobalSearch cursor

Before, when using Quick Search Box, this showed up in the log:

W/SuggestionCursor( 1013): received unexpectd respond: no DialogCursorProtocol.METHOD specified.

And a while later, this:

W/SuggestionCursor( 1013): SuggestionCursor finalized without being closed. Someone is leaking.

This latter warning is because of http://b/issue?id=2015069, where cross-process Cursor.close()
doesn't actually close the target cursor. The first warning is because
GlobalSearch.SuggestionCursor does not handle EXTRA_CURSOR_RESPOND_CLOSE_CURSOR
as sent by SuggestionsAdapter, which is a work-around for http://b/issue?id=2015069.

This change modified GlobalSearch.SuggestionCursor to close itself when
This will reduce some memory and thread life drag in GlobalSearch.

Fixes http://b/issue?id=2085248

Change-Id: If9cf3482dcacf245bd18cda5bb2871ff825ccf65
diff --git a/src/com/android/globalsearch/ b/src/com/android/globalsearch/
index 9768b16..4445359 100644
--- a/src/com/android/globalsearch/
+++ b/src/com/android/globalsearch/
@@ -48,6 +48,11 @@
     private static final String TAG = SuggestionCursor.class.getSimpleName();
+    // The extra used to tell a cursor to close itself. This is a hack to work around
+    // the fact that cross-process cursors currently don't get closed by Cursor.close(),
+    // http://b/issue?id=2015069
+    private static final String EXTRA_CURSOR_RESPOND_CLOSE_CURSOR = "cursor_respond_close_cursor";
     // the same as the string in suggestActionMsgColumn in res/xml/searchable.xml
     private static final String SUGGEST_COLUMN_ACTION_MSG_CALL = "suggest_action_msg_call";
@@ -177,6 +182,13 @@
     public Bundle respond(Bundle extras) {
         if (DBG) Log.d(TAG, "respond(" + extras + ")");
+        // Hack to work around http://b/issue?id=2015069,
+        // "CursorToBulkCursorAdaptor.close() does not call mCursor.close()"
+        if (extras.getBoolean(EXTRA_CURSOR_RESPOND_CLOSE_CURSOR)) {
+            close();
+            return Bundle.EMPTY;
+        }
         final int method = extras.getInt(SearchManager.DialogCursorProtocol.METHOD, -1);
         if (method == -1) {