am fcf671be: Fix EBADF in TTS synthesizeToFile method.
* commit 'fcf671be890f9fb49067c5f86b182bf8b8e7b9c0': Fix EBADF in TTS synthesizeToFile method.
This commit is contained in:
committed by
Android Git Automerger
commit
e634d787e4
@@ -36,6 +36,7 @@ import android.util.Log;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
@@ -656,19 +657,18 @@ public abstract class TextToSpeechService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
private class SynthesisToFileSpeechDescriptorItem extends SynthesisSpeechItem {
|
||||
private final FileDescriptor mFileDescriptor;
|
||||
private class SynthesisToFileOutputStreamSpeechItem extends SynthesisSpeechItem {
|
||||
private final FileOutputStream mFileOutputStream;
|
||||
|
||||
public SynthesisToFileSpeechDescriptorItem(Object callerIdentity, int callerUid,
|
||||
int callerPid, Bundle params, String text, FileDescriptor fileDescriptor) {
|
||||
int callerPid, Bundle params, String text, FileOutputStream fileOutputStream) {
|
||||
super(callerIdentity, callerUid, callerPid, params, text);
|
||||
mFileDescriptor = fileDescriptor;
|
||||
mFileOutputStream = fileOutputStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractSynthesisCallback createSynthesisCallback() {
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(mFileDescriptor);
|
||||
return new FileSynthesisCallback(fileOutputStream.getChannel());
|
||||
return new FileSynthesisCallback(mFileOutputStream.getChannel());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -680,6 +680,11 @@ public abstract class TextToSpeechService extends Service {
|
||||
} else {
|
||||
dispatchOnError();
|
||||
}
|
||||
try {
|
||||
mFileOutputStream.close();
|
||||
} catch(IOException e) {
|
||||
Log.w(TAG, "Failed to close output file", e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
}
|
||||
@@ -805,9 +810,9 @@ public abstract class TextToSpeechService extends Service {
|
||||
return TextToSpeech.ERROR;
|
||||
}
|
||||
|
||||
SpeechItem item = new SynthesisToFileSpeechDescriptorItem(caller, Binder.getCallingUid(),
|
||||
Binder.getCallingPid(), params, text,
|
||||
fileDescriptor.getFileDescriptor());
|
||||
SpeechItem item = new SynthesisToFileOutputStreamSpeechItem(caller,
|
||||
Binder.getCallingUid(), Binder.getCallingPid(), params, text,
|
||||
new ParcelFileDescriptor.AutoCloseOutputStream(fileDescriptor));
|
||||
return mSynthHandler.enqueueSpeechItem(TextToSpeech.QUEUE_ADD, item);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user