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
This commit is contained in:
@@ -28,7 +28,6 @@ import android.content.pm.ActivityInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.graphics.drawable.Animatable;
|
import android.graphics.drawable.Animatable;
|
||||||
@@ -322,14 +321,12 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
|
|||||||
if (!globalSearch && mSearchable == null) {
|
if (!globalSearch && mSearchable == null) {
|
||||||
globalSearch = true;
|
globalSearch = true;
|
||||||
mSearchable = searchManager.getSearchableInfo(componentName, globalSearch);
|
mSearchable = searchManager.getSearchableInfo(componentName, globalSearch);
|
||||||
|
}
|
||||||
|
|
||||||
// If we still get back null (i.e., there's not even a searchable info available
|
// If there's not even a searchable info available for global search, then really give up.
|
||||||
// for global search), then really give up.
|
if (mSearchable == null) {
|
||||||
if (mSearchable == null) {
|
Log.w(LOG_TAG, "No global search provider.");
|
||||||
// Unfortunately, we can't log here. it would be logspam every time the user
|
return false;
|
||||||
// clicks the "search" key on a non-search app.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mLaunchComponent = componentName;
|
mLaunchComponent = componentName;
|
||||||
@@ -702,6 +699,9 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
|
|||||||
@Override
|
@Override
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
if (DBG) Log.d(LOG_TAG, "onKeyDown(" + keyCode + "," + 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.
|
// handle back key to go back to previous searchable, etc.
|
||||||
if (handleBackKey(keyCode, event)) {
|
if (handleBackKey(keyCode, event)) {
|
||||||
@@ -738,6 +738,9 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
|
|||||||
if (DBG_LOG_TIMING) {
|
if (DBG_LOG_TIMING) {
|
||||||
dbgLogTiming("onTextChanged()");
|
dbgLogTiming("onTextChanged()");
|
||||||
}
|
}
|
||||||
|
if (mSearchable == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
updateWidgetState();
|
updateWidgetState();
|
||||||
if (!mSearchAutoComplete.isPerformingCompletion()) {
|
if (!mSearchAutoComplete.isPerformingCompletion()) {
|
||||||
// The user changed the query, remember it.
|
// The user changed the query, remember it.
|
||||||
@@ -1563,6 +1566,9 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
|
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
|
||||||
|
if (mSearchDialog.mSearchable == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
|
if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||||
if (mSearchDialog.backToPreviousComponent()) {
|
if (mSearchDialog.backToPreviousComponent()) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user