Skip to content

Commit 7a2f6f3

Browse files
narayankAndroid (Google) Code Review
authored andcommitted
Merge "Widen permissions on synthesized files." into ics-mr1
2 parents ce6578a + 563fd3a commit 7a2f6f3

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

core/java/android/speech/tts/FileSynthesisCallback.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
package android.speech.tts;
1717

1818
import android.media.AudioFormat;
19+
import android.os.FileUtils;
1920
import android.util.Log;
2021

2122
import java.io.File;
22-
import java.io.FileOutputStream;
2323
import java.io.IOException;
2424
import java.io.RandomAccessFile;
2525
import java.nio.ByteBuffer;
@@ -63,7 +63,7 @@ void stop() {
6363
* Must be called while holding the monitor on {@link #mStateLock}.
6464
*/
6565
private void cleanUp() {
66-
closeFile();
66+
closeFileAndWidenPermissions();
6767
if (mFile != null) {
6868
mFileName.delete();
6969
}
@@ -72,7 +72,7 @@ private void cleanUp() {
7272
/**
7373
* Must be called while holding the monitor on {@link #mStateLock}.
7474
*/
75-
private void closeFile() {
75+
private void closeFileAndWidenPermissions() {
7676
try {
7777
if (mFile != null) {
7878
mFile.close();
@@ -81,6 +81,18 @@ private void closeFile() {
8181
} catch (IOException ex) {
8282
Log.e(TAG, "Failed to close " + mFileName + ": " + ex);
8383
}
84+
85+
try {
86+
// Make the written file readable and writeable by everyone.
87+
// This allows the app that requested synthesis to read the file.
88+
//
89+
// Note that the directory this file was written must have already
90+
// been world writeable in order it to have been
91+
// written to in the first place.
92+
FileUtils.setPermissions(mFileName.getAbsolutePath(), 0666, -1, -1); //-rw-rw-rw
93+
} catch (SecurityException se) {
94+
Log.e(TAG, "Security exception setting rw permissions on : " + mFileName);
95+
}
8496
}
8597

8698
@Override
@@ -168,7 +180,7 @@ public int done() {
168180
int dataLength = (int) (mFile.length() - WAV_HEADER_LENGTH);
169181
mFile.write(
170182
makeWavHeader(mSampleRateInHz, mAudioFormat, mChannelCount, dataLength));
171-
closeFile();
183+
closeFileAndWidenPermissions();
172184
mDone = true;
173185
return TextToSpeech.SUCCESS;
174186
} catch (IOException ex) {

0 commit comments

Comments
 (0)