From 66c90cd2ae49c49da8aeda5ab1d86bd9b76434c7 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 11 Oct 2012 16:08:25 +0900 Subject: Put temporary files under a separate directory. Bug: 7328003 Change-Id: Ibe5278ea209d149f87fd08785c77b17e3859948e --- .../android/inputmethod/latin/BinaryDictionaryGetter.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java') diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java index 201a10187..c747dc673 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java @@ -163,6 +163,18 @@ final class BinaryDictionaryGetter { return getCacheDirectoryForLocale(locale, context) + File.separator + fileName; } + /** + * Generates a unique temporary file name in the app cache directory. + * + * This is unique as long as it doesn't get called twice in the same millisecond by the same + * thread, which should be more than enough for our purposes. + */ + public static String getTempFileName(String id, Context context) { + final String fileName = replaceFileNameDangerousCharacters(id); + return context.getCacheDir() + File.separator + fileName + "." + + Thread.currentThread().getId() + "." + System.currentTimeMillis(); + } + /** * Returns a file address from a resource, or null if it cannot be opened. */ -- cgit v1.2.3-83-g751a