Changes to support bug 2750953.
Change-Id: I95060b46314f33597b5deefcaec529498ff5b97e
diff --git a/src/com/android/quicksearchbox/SearchWidgetProvider.java b/src/com/android/quicksearchbox/SearchWidgetProvider.java
index ca45aac..1b59658 100644
--- a/src/com/android/quicksearchbox/SearchWidgetProvider.java
+++ b/src/com/android/quicksearchbox/SearchWidgetProvider.java
@@ -32,7 +32,6 @@
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.net.Uri;
-import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.speech.RecognizerIntent;
@@ -188,8 +187,8 @@
private static Intent getVoiceSearchIntent(Context context, Corpus corpus,
Bundle widgetAppData) {
VoiceSearch voiceSearch = QsbApplication.get(context).getVoiceSearch();
- if (!voiceSearch.shouldShowVoiceSearch(corpus)) return null;
- if (corpus == null) {
+
+ if (corpus == null || !voiceSearch.isVoiceSearchAvailable()) {
return voiceSearch.createVoiceWebSearchIntent(widgetAppData);
} else {
return corpus.createVoiceSearchIntent(widgetAppData);
diff --git a/src/com/android/quicksearchbox/SearchableSources.java b/src/com/android/quicksearchbox/SearchableSources.java
index 3f94e77..5411d02 100644
--- a/src/com/android/quicksearchbox/SearchableSources.java
+++ b/src/com/android/quicksearchbox/SearchableSources.java
@@ -16,8 +16,6 @@
package com.android.quicksearchbox;
-import com.android.quicksearchbox.google.GoogleSource;
-
import android.app.SearchManager;
import android.app.SearchableInfo;
import android.content.ComponentName;
diff --git a/src/com/android/quicksearchbox/VoiceSearch.java b/src/com/android/quicksearchbox/VoiceSearch.java
index 2821e34..69d3a12 100644
--- a/src/com/android/quicksearchbox/VoiceSearch.java
+++ b/src/com/android/quicksearchbox/VoiceSearch.java
@@ -39,21 +39,27 @@
}
public boolean shouldShowVoiceSearch(Corpus corpus) {
- if (corpus != null && !corpus.voiceSearchEnabled()) {
- return false;
- }
- return isVoiceSearchAvailable();
+ return corpusSupportsVoiceSearch(corpus) && isVoiceSearchAvailable();
}
- private boolean isVoiceSearchAvailable() {
- Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
+ protected boolean corpusSupportsVoiceSearch(Corpus corpus) {
+ return (corpus == null || corpus.voiceSearchEnabled());
+ }
+
+ protected Intent createVoiceSearchIntent() {
+ return new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
+ }
+
+ public boolean isVoiceSearchAvailable() {
+ Intent intent = createVoiceSearchIntent();
ResolveInfo ri = mContext.getPackageManager().
resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
return ri != null;
}
public Intent createVoiceWebSearchIntent(Bundle appData) {
- Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
+ if (!isVoiceSearchAvailable()) return null;
+ Intent intent = createVoiceSearchIntent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);