summaryrefslogtreecommitdiffstats
path: root/core/java/android/speech/tts
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2011-10-27 13:41:54 +0100
committerNarayan Kamath <narayan@google.com>2011-10-27 15:00:36 +0100
commit563fd3ae1b9d388f883b77b98a641a57bbdb6aed (patch)
tree85a429a55e6e2f3a8f8018f21daf337bd381022e /core/java/android/speech/tts
parent27812a8f14ca22f0a709320e5a41d200ac59b63b (diff)
downloadframeworks_base-563fd3ae1b9d388f883b77b98a641a57bbdb6aed.zip
frameworks_base-563fd3ae1b9d388f883b77b98a641a57bbdb6aed.tar.gz
frameworks_base-563fd3ae1b9d388f883b77b98a641a57bbdb6aed.tar.bz2
Widen permissions on synthesized files.
When synthesized files are written to app private data dirs, they are written with owner/grp set to the TTS engine and are inaccessible by the app itself. This is a reported regression from gingerbread behaviour. Note that the dir in which the engine writes files is itself already world writable. bug:5523587 Change-Id: I2cb26c6f3c3d9cb3cedd60fab32c99a85a27f4b1
Diffstat (limited to 'core/java/android/speech/tts')
-rw-r--r--core/java/android/speech/tts/FileSynthesisCallback.java20
1 files changed, 16 insertions, 4 deletions
diff --git a/core/java/android/speech/tts/FileSynthesisCallback.java b/core/java/android/speech/tts/FileSynthesisCallback.java
index 5808919..04c3377 100644
--- a/core/java/android/speech/tts/FileSynthesisCallback.java
+++ b/core/java/android/speech/tts/FileSynthesisCallback.java
@@ -16,10 +16,10 @@
package android.speech.tts;
import android.media.AudioFormat;
+import android.os.FileUtils;
import android.util.Log;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
@@ -63,7 +63,7 @@ class FileSynthesisCallback extends AbstractSynthesisCallback {
* Must be called while holding the monitor on {@link #mStateLock}.
*/
private void cleanUp() {
- closeFile();
+ closeFileAndWidenPermissions();
if (mFile != null) {
mFileName.delete();
}
@@ -72,7 +72,7 @@ class FileSynthesisCallback extends AbstractSynthesisCallback {
/**
* Must be called while holding the monitor on {@link #mStateLock}.
*/
- private void closeFile() {
+ private void closeFileAndWidenPermissions() {
try {
if (mFile != null) {
mFile.close();
@@ -81,6 +81,18 @@ class FileSynthesisCallback extends AbstractSynthesisCallback {
} catch (IOException ex) {
Log.e(TAG, "Failed to close " + mFileName + ": " + ex);
}
+
+ try {
+ // Make the written file readable and writeable by everyone.
+ // This allows the app that requested synthesis to read the file.
+ //
+ // Note that the directory this file was written must have already
+ // been world writeable in order it to have been
+ // written to in the first place.
+ FileUtils.setPermissions(mFileName.getAbsolutePath(), 0666, -1, -1); //-rw-rw-rw
+ } catch (SecurityException se) {
+ Log.e(TAG, "Security exception setting rw permissions on : " + mFileName);
+ }
}
@Override
@@ -168,7 +180,7 @@ class FileSynthesisCallback extends AbstractSynthesisCallback {
int dataLength = (int) (mFile.length() - WAV_HEADER_LENGTH);
mFile.write(
makeWavHeader(mSampleRateInHz, mAudioFormat, mChannelCount, dataLength));
- closeFile();
+ closeFileAndWidenPermissions();
mDone = true;
return TextToSpeech.SUCCESS;
} catch (IOException ex) {