Loading core/java/android/speech/tts/TextToSpeech.java +5 −2 Original line number Diff line number Diff line Loading @@ -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; } } Loading @@ -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; } Loading @@ -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; } } Loading core/java/android/speech/tts/TtsEngines.java +31 −5 Original line number Diff line number Diff line Loading @@ -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(); } /** Loading Loading @@ -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; } Loading @@ -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) { Loading Loading
core/java/android/speech/tts/TextToSpeech.java +5 −2 Original line number Diff line number Diff line Loading @@ -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; } } Loading @@ -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; } Loading @@ -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; } } Loading
core/java/android/speech/tts/TtsEngines.java +31 −5 Original line number Diff line number Diff line Loading @@ -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(); } /** Loading Loading @@ -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; } Loading @@ -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) { Loading