Skip to content
Snippets Groups Projects
Commit a995bf40 authored by Jean Chalard's avatar Jean Chalard
Browse files

Put temp files within app files

Bug: 8715614
Change-Id: I307d83923070994525cf0d27aad403e881a89314
parent 30f0f3a9
No related branches found
No related tags found
No related merge requests found
...@@ -72,10 +72,16 @@ final class BinaryDictionaryGetter { ...@@ -72,10 +72,16 @@ final class BinaryDictionaryGetter {
public static String getTempFileName(final String id, final Context context) public static String getTempFileName(final String id, final Context context)
throws IOException { throws IOException {
final String safeId = DictionaryInfoUtils.replaceFileNameDangerousCharacters(id); final String safeId = DictionaryInfoUtils.replaceFileNameDangerousCharacters(id);
final File directory = new File(DictionaryInfoUtils.getWordListTempDirectory(context));
if (!directory.exists()) {
if (!directory.mkdirs()) {
Log.e(TAG, "Could not create the temporary directory");
}
}
// If the first argument is less than three chars, createTempFile throws a // If the first argument is less than three chars, createTempFile throws a
// RuntimeException. We don't really care about what name we get, so just // RuntimeException. We don't really care about what name we get, so just
// put a three-chars prefix makes us safe. // put a three-chars prefix makes us safe.
return File.createTempFile("xxx" + safeId, null).getAbsolutePath(); return File.createTempFile("xxx" + safeId, null, directory).getAbsolutePath();
} }
/** /**
......
...@@ -128,6 +128,13 @@ public class DictionaryInfoUtils { ...@@ -128,6 +128,13 @@ public class DictionaryInfoUtils {
return context.getFilesDir() + File.separator + "dicts"; return context.getFilesDir() + File.separator + "dicts";
} }
/**
* Helper method to get the top level temp directory.
*/
public static String getWordListTempDirectory(final Context context) {
return context.getFilesDir() + File.separator + "tmp";
}
/** /**
* Reverse escaping done by replaceFileNameDangerousCharacters. * Reverse escaping done by replaceFileNameDangerousCharacters.
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment