From a0d9c82921022347e44d416bb57810331e35e446 Mon Sep 17 00:00:00 2001 From: Mohammadinamul Sheik Date: Mon, 4 May 2015 11:57:31 -0700 Subject: Make the DictionaryService stage the downloaded files Bug: 20641948 Change-Id: I6639c995b12c033bc30241cd219201dd483ee516 --- .../inputmethod/latin/BinaryDictionaryGetter.java | 49 +++++----------------- 1 file changed, 11 insertions(+), 38 deletions(-) (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 5f2a112ba..60016371b 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java @@ -195,39 +195,6 @@ final public class BinaryDictionaryGetter { return result; } - /** - * Remove all files with the passed id, except the passed file. - * - * If a dictionary with a given ID has a metadata change that causes it to change - * path, we need to remove the old version. The only way to do this is to check all - * installed files for a matching ID in a different directory. - */ - public static void removeFilesWithIdExcept(final Context context, final String id, - final File fileToKeep) { - try { - final File canonicalFileToKeep = fileToKeep.getCanonicalFile(); - final File[] directoryList = DictionaryInfoUtils.getCachedDirectoryList(context); - if (null == directoryList) return; - for (File directory : directoryList) { - // There is one directory per locale. See #getCachedDirectoryList - if (!directory.isDirectory()) continue; - final File[] wordLists = directory.listFiles(); - if (null == wordLists) continue; - for (File wordList : wordLists) { - final String fileId = - DictionaryInfoUtils.getWordListIdFromFileName(wordList.getName()); - if (fileId.equals(id)) { - if (!canonicalFileToKeep.equals(wordList.getCanonicalFile())) { - wordList.delete(); - } - } - } - } - } catch (java.io.IOException e) { - Log.e(TAG, "IOException trying to cleanup files", e); - } - } - // ## HACK ## we prevent usage of a dictionary before version 18. The reason for this is, since // those do not include whitelist entries, the new code with an old version of the dictionary // would lose whitelist functionality. @@ -274,12 +241,18 @@ final public class BinaryDictionaryGetter { */ public static ArrayList getDictionaryFiles(final Locale locale, final Context context, boolean notifyDictionaryPackForUpdates) { - - final boolean hasDefaultWordList = DictionaryInfoUtils.isDictionaryAvailable( - context, locale); if (notifyDictionaryPackForUpdates) { - BinaryDictionaryFileDumper.cacheWordListsFromContentProvider(locale, context, - hasDefaultWordList); + final boolean hasDefaultWordList = DictionaryInfoUtils.isDictionaryAvailable( + context, locale); + // It makes sure that the first time keyboard comes up and the dictionaries are reset, + // the DB is populated with the appropriate values for each locale. Helps in downloading + // the dictionaries when the user enables and switches new languages before the + // DictionaryService runs. + BinaryDictionaryFileDumper.downloadDictIfNeverRequested( + locale, context, hasDefaultWordList); + + // Move a staging files to the cache ddirectories if any. + DictionaryInfoUtils.moveStagingFilesIfExists(context); } final File[] cachedWordLists = getCachedWordLists(locale.toString(), context); final String mainDictId = DictionaryInfoUtils.getMainDictId(locale); -- cgit v1.2.3-83-g751a