Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e303d2cf authored by Mike LeBeau's avatar Mike LeBeau
Browse files

Send a special respond to the cursor in SuggestionsAdapter to tell it to

close itself directly because it may not happen correctly for some cursors
currently. This fixes http://b/2036290, which is being caused by
http://b/2015069 which we are not fixing for Donut, so this is a hack around
that for the time being.
parent 40c10bf4
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -74,6 +74,14 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
    private int mIconName2Col;
    private int mBackgroundColorCol;
    
    // The extra used to tell a cursor to close itself. This is a hack, see the description by
    // its use later in this file.
    private static final String EXTRA_CURSOR_RESPOND_CLOSE_CURSOR = "cursor_respond_close_cursor";

    // The bundle which contains {EXTRA_CURSOR_RESPOND_CLOSE_CURSOR=true}, just cached once
    // so we don't bother recreating it a bunch.
    private final Bundle mCursorRespondCloseCursorBundle;

    // This value is stored in SuggestionsAdapter by the SearchDialog to indicate whether
    // a particular list item should be selected upon the next call to notifyDataSetChanged.
    // This is used to indicate the index of the "More results..." list item so that when
@@ -130,6 +138,10 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
            }
        };
        
        // Create this once because we'll reuse it a bunch.
        mCursorRespondCloseCursorBundle = new Bundle();
        mCursorRespondCloseCursorBundle.putBoolean(EXTRA_CURSOR_RESPOND_CLOSE_CURSOR, true);

        // delay 500ms when deleting
        getFilter().setDelayer(new Filter.Delayer() {

@@ -195,7 +207,21 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
        if (DBG) Log.d(LOG_TAG, "changeCursor(" + c + ")");

        try {
            Cursor oldCursor = getCursor();
            super.changeCursor(c);
            
            // We send a special respond to the cursor to tell it to close itself directly because
            // it may not happen correctly for some cursors currently. This was originally
            // included as a fix to http://b/2036290, in which the search dialog was holding
            // on to references to the web search provider unnecessarily. This is being caused by
            // the fact that the cursor is not being correctly closed in
            // BulkCursorToCursorAdapter#close, which remains unfixed (see http://b/2015069).
            //
            // TODO: Remove this hack once http://b/2015069 is fixed.
            if (oldCursor != null && oldCursor != c) {
                oldCursor.respond(mCursorRespondCloseCursorBundle);
            }
            
            if (c != null) {
                mFormatCol = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_FORMAT);
                mText1Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1);