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

Commit ee716fa2 authored by Bjorn Bringert's avatar Bjorn Bringert
Browse files

Make sure SearchDialog.mSearchable != null in key handlers

This change adds checking that the searchdialog is initialized
properly to a few key event listeners where it was missing
before.

Also makes sure that the search dialog is not shown if the
global search is requested but the global search provider
cannot be found.

Should fix http://b/issue?id=1982128
"Device rebooting after search results"
where SearchDialog.onKeyDown() threw an NPE
parent c93af6dc
Loading
Loading
Loading
Loading
+17 −11
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.drawable.Animatable;
@@ -322,15 +321,13 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
        if (!globalSearch && mSearchable == null) {
            globalSearch = true;
            mSearchable = searchManager.getSearchableInfo(componentName, globalSearch);
        }

            // If we still get back null (i.e., there's not even a searchable info available
            // for global search), then really give up.
        // If there's not even a searchable info available for global search, then really give up.
        if (mSearchable == null) {
                // Unfortunately, we can't log here.  it would be logspam every time the user
                // clicks the "search" key on a non-search app.
            Log.w(LOG_TAG, "No global search provider.");
            return false;
        }
        }

        mLaunchComponent = componentName;
        mAppSearchData = appSearchData;
@@ -702,6 +699,9 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (DBG) Log.d(LOG_TAG, "onKeyDown(" + keyCode + "," + event + ")");
        if (mSearchable == null) {
            return false;
        }

        // handle back key to go back to previous searchable, etc.
        if (handleBackKey(keyCode, event)) {
@@ -738,6 +738,9 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
            if (DBG_LOG_TIMING) {
                dbgLogTiming("onTextChanged()");
            }
            if (mSearchable == null) {
                return;
            }
            updateWidgetState();
            if (!mSearchAutoComplete.isPerformingCompletion()) {
                // The user changed the query, remember it.
@@ -1563,6 +1566,9 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
         */
        @Override
        public boolean onKeyPreIme(int keyCode, KeyEvent event) {
            if (mSearchDialog.mSearchable == null) {
                return false;
            }
            if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
                if (mSearchDialog.backToPreviousComponent()) {
                    return true;