From 1e13a02320aa165c22172d43b2b3c3cd8ad35cf7 Mon Sep 17 00:00:00 2001 From: Jean-Michel Trivi Date: Thu, 20 Jan 2011 17:25:48 -0800 Subject: [PATCH] Bug 3365937 notify TTS initialization listener of binding errors The creation of a TextToSpeech object causes the TTS service to start, and the initialization listener to be called when the service is connected. But the listener is never called when the service binding failed to be notified of this error. The fix consists in checking the result of the bind to service operation, and notify the listener in case of an error. More log was added in case speak() and synthesizeToFile() are called but the service is not known to have started. Change-Id: I7dcc1fa44be31fee3177ec6215fca3306377b934 --- .../java/android/speech/tts/TextToSpeech.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/core/java/android/speech/tts/TextToSpeech.java b/core/java/android/speech/tts/TextToSpeech.java index 841257f367701..757eaa6bd601e 100755 --- a/core/java/android/speech/tts/TextToSpeech.java +++ b/core/java/android/speech/tts/TextToSpeech.java @@ -464,10 +464,17 @@ public class TextToSpeech { Intent intent = new Intent("android.intent.action.START_TTS_SERVICE"); intent.addCategory("android.intent.category.TTS"); - mContext.bindService(intent, mServiceConnection, - Context.BIND_AUTO_CREATE); - // TODO handle case where the binding works (should always work) but - // the plugin fails + boolean bound = mContext.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE); + if (!bound) { + Log.e("TextToSpeech.java", "initTts() failed to bind to service"); + if (mInitListener != null) { + mInitListener.onInit(ERROR); + } + } else { + // initialization listener will be called inside ServiceConnection + Log.i("TextToSpeech.java", "initTts() successfully bound to service"); + } + // TODO handle plugin failures } @@ -717,8 +724,9 @@ public class TextToSpeech { { synchronized (mStartLock) { int result = ERROR; - Log.i("TTS received: ", text); + Log.i("TextToSpeech.java - speak", "speak text of length " + text.length()); if (!mStarted) { + Log.e("TextToSpeech.java - speak", "service isn't started"); return result; } try { @@ -1226,7 +1234,10 @@ public class TextToSpeech { String filename) { synchronized (mStartLock) { int result = ERROR; + Log.i("TextToSpeech.java - synthesizeToFile", "synthesizeToFile text of length " + + text.length()); if (!mStarted) { + Log.e("TextToSpeech.java - synthesizeToFile", "service isn't started"); return result; } try {