summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2011-06-14 12:39:55 +0100
committerNarayan Kamath <narayan@google.com>2011-06-14 13:29:20 +0100
commit0e20fe5bab7dc3aff488d133961acfe0239f5240 (patch)
treeb5cc7930adcafcb9712161b75aa7fc64537f5ca1 /core/java
parent70832a3d77d90f09fb7ba27612c9cbec6a92abe6 (diff)
downloadframeworks_base-0e20fe5bab7dc3aff488d133961acfe0239f5240.zip
frameworks_base-0e20fe5bab7dc3aff488d133961acfe0239f5240.tar.gz
frameworks_base-0e20fe5bab7dc3aff488d133961acfe0239f5240.tar.bz2
A few TTS bug fixes
(a) ensure that onInit is called exactly once per call to initTts(). (b) TtsEngines should never return an engine that is not installed. Change-Id: Ic1ef63a9339e6d1050e3302445ca40d3ae481f61
Diffstat (limited to 'core/java')
-rwxr-xr-xcore/java/android/speech/tts/TextToSpeech.java7
-rw-r--r--core/java/android/speech/tts/TtsEngines.java36
2 files changed, 36 insertions, 7 deletions
diff --git a/core/java/android/speech/tts/TextToSpeech.java b/core/java/android/speech/tts/TextToSpeech.java
index 23fd96f..8923b46 100755
--- a/core/java/android/speech/tts/TextToSpeech.java
+++ b/core/java/android/speech/tts/TextToSpeech.java
@@ -505,12 +505,14 @@ public class TextToSpeech {
// Try requested engine
if (connectToEngine(engine)) {
+ mCurrentEngine = engine;
return SUCCESS;
}
// Fall back to user's default engine if different from the already tested one
if (!engine.equals(defaultEngine)) {
if (connectToEngine(defaultEngine)) {
+ mCurrentEngine = engine;
return SUCCESS;
}
}
@@ -520,10 +522,12 @@ public class TextToSpeech {
if (!defaultEngine.equals(highestRanked)
&& !engine.equals(highestRanked)) {
if (connectToEngine(highestRanked)) {
+ mCurrentEngine = engine;
return SUCCESS;
}
}
+ dispatchOnInit(ERROR);
return ERROR;
}
@@ -534,10 +538,9 @@ public class TextToSpeech {
boolean bound = mContext.bindService(intent, connection, Context.BIND_AUTO_CREATE);
if (!bound) {
Log.e(TAG, "Failed to bind to " + engine);
- dispatchOnInit(ERROR);
return false;
} else {
- mCurrentEngine = engine;
+ Log.i(TAG, "Sucessfully bound to " + engine);
return true;
}
}
diff --git a/core/java/android/speech/tts/TtsEngines.java b/core/java/android/speech/tts/TtsEngines.java
index e8d74eb..715894f 100644
--- a/core/java/android/speech/tts/TtsEngines.java
+++ b/core/java/android/speech/tts/TtsEngines.java
@@ -48,14 +48,14 @@ public class TtsEngines {
}
/**
- * @return the default TTS engine. If the user has set a default, that
- * value is returned else the highest ranked engine is returned,
- * as per {@link EngineInfoComparator}.
+ * @return the default TTS engine. If the user has set a default, and the engine
+ * is available on the device, the default is returned. Otherwise,
+ * the highest ranked engine is returned as per {@link EngineInfoComparator}.
*/
public String getDefaultEngine() {
String engine = Settings.Secure.getString(mContext.getContentResolver(),
Settings.Secure.TTS_DEFAULT_SYNTH);
- return engine != null ? engine : getHighestRankedEngineName();
+ return isEngineInstalled(engine) ? engine : getHighestRankedEngineName();
}
/**
@@ -124,7 +124,14 @@ public class TtsEngines {
public boolean isEngineEnabled(String engine) {
// System engines are enabled by default always.
EngineInfo info = getEngineInfo(engine);
- if (info != null && info.system) {
+ if (info == null) {
+ // The engine is not installed, and therefore cannot
+ // be enabled.
+ return false;
+ }
+
+ if (info.system) {
+ // All system engines are enabled by default.
return true;
}
@@ -141,6 +148,25 @@ public class TtsEngines {
return appInfo != null && (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
}
+ /**
+ * @return true if a given engine is installed on the system. Useful to deal
+ * with cases where an engine has been uninstalled by the user or removed
+ * for any other reason.
+ */
+ private boolean isEngineInstalled(String engine) {
+ if (engine == null) {
+ return false;
+ }
+
+ for (EngineInfo info : getEngines()) {
+ if (engine.equals(info.name)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
private EngineInfo getEngineInfo(ResolveInfo resolve, PackageManager pm) {
ServiceInfo service = resolve.serviceInfo;
if (service != null) {