diff options
| author | 2011-06-14 07:05:42 -0700 | |
|---|---|---|
| committer | 2011-06-14 07:05:42 -0700 | |
| commit | 9a67f2618444e0373dcbac0f3cc36e900105f18c (patch) | |
| tree | 49f64cbce83808dd8e3d095da594148facf74151 | |
| parent | 3f0363bb4b9fab9799ac308dd48baf8830e30647 (diff) | |
| parent | 0e20fe5bab7dc3aff488d133961acfe0239f5240 (diff) | |
Merge "A few TTS bug fixes"
| -rwxr-xr-x | core/java/android/speech/tts/TextToSpeech.java | 7 | ||||
| -rw-r--r-- | core/java/android/speech/tts/TtsEngines.java | 36 |
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 990d49359345..6823b73ba057 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 e8d74eb32893..715894f71406 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) { |