Skip to content

Commit 1e13a02

Browse files
committed
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
1 parent 822d4ce commit 1e13a02

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

core/java/android/speech/tts/TextToSpeech.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,17 @@ public void onServiceDisconnected(ComponentName name) {
464464

465465
Intent intent = new Intent("android.intent.action.START_TTS_SERVICE");
466466
intent.addCategory("android.intent.category.TTS");
467-
mContext.bindService(intent, mServiceConnection,
468-
Context.BIND_AUTO_CREATE);
469-
// TODO handle case where the binding works (should always work) but
470-
// the plugin fails
467+
boolean bound = mContext.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE);
468+
if (!bound) {
469+
Log.e("TextToSpeech.java", "initTts() failed to bind to service");
470+
if (mInitListener != null) {
471+
mInitListener.onInit(ERROR);
472+
}
473+
} else {
474+
// initialization listener will be called inside ServiceConnection
475+
Log.i("TextToSpeech.java", "initTts() successfully bound to service");
476+
}
477+
// TODO handle plugin failures
471478
}
472479

473480

@@ -717,8 +724,9 @@ public int speak(String text, int queueMode, HashMap<String,String> params)
717724
{
718725
synchronized (mStartLock) {
719726
int result = ERROR;
720-
Log.i("TTS received: ", text);
727+
Log.i("TextToSpeech.java - speak", "speak text of length " + text.length());
721728
if (!mStarted) {
729+
Log.e("TextToSpeech.java - speak", "service isn't started");
722730
return result;
723731
}
724732
try {
@@ -1226,7 +1234,10 @@ public int synthesizeToFile(String text, HashMap<String,String> params,
12261234
String filename) {
12271235
synchronized (mStartLock) {
12281236
int result = ERROR;
1237+
Log.i("TextToSpeech.java - synthesizeToFile", "synthesizeToFile text of length "
1238+
+ text.length());
12291239
if (!mStarted) {
1240+
Log.e("TextToSpeech.java - synthesizeToFile", "service isn't started");
12301241
return result;
12311242
}
12321243
try {

0 commit comments

Comments
 (0)