aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
diff options
context:
space:
mode:
authorBaligh Uddin <baligh@google.com>2015-07-03 16:47:23 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-07-03 16:47:23 +0000
commit37d33d3da1627d57ab8daca2951f48739afbcbfb (patch)
tree8461bb8ed67f4a26f95dce86b99cd440cce7b5de /java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
parent2c2065a56aa9c4e2971e6fc8ee0b8d0d059695b7 (diff)
parent8ed9bccaf2f670fd34689771d37c4e064da25b57 (diff)
downloadlatinime-37d33d3da1627d57ab8daca2951f48739afbcbfb.tar.gz
latinime-37d33d3da1627d57ab8daca2951f48739afbcbfb.tar.xz
latinime-37d33d3da1627d57ab8daca2951f48739afbcbfb.zip
am 8ed9bcca: am 91886a31: am baec6ce1: Revert reset to ub-latinimegoogle-fava-release
* commit '8ed9bccaf2f670fd34689771d37c4e064da25b57': (240 commits) Don't prompt before downloading. Add some more logging. Why not. Load metadata.json from resources on DB reset. Small optimization to eliminate a >0 check in RichInputConnection. Extend laggy connection timeout for initial load. Fix breakage in tests. LatinIME portion of StatsUtil change. Workaround for preserving responsiveness on a slow InputConnection. Do not decorate committed spans. Do not force downloads on package replace. Fix the previous downloads logic to not missing any downloads. Detection and logging of slow input connections. Clear/remove all the scheduled downloads in Download Manager Disable download notifications. Cleanup before fixing getTextAfterCursor(). Do not restrict downloads to WiFi networks. Import translations. DO NOT MERGE Revert "Remove "Personal dictionary" link from settings." Import translations. DO NOT MERGE Import translations. DO NOT MERGE ...
Diffstat (limited to 'java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java')
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java49
1 files changed, 38 insertions, 11 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
index 60016371b..5f2a112ba 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
@@ -195,6 +195,39 @@ 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.
@@ -241,18 +274,12 @@ final public class BinaryDictionaryGetter {
*/
public static ArrayList<AssetFileAddress> getDictionaryFiles(final Locale locale,
final Context context, boolean notifyDictionaryPackForUpdates) {
- if (notifyDictionaryPackForUpdates) {
- 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 boolean hasDefaultWordList = DictionaryInfoUtils.isDictionaryAvailable(
+ context, locale);
+ if (notifyDictionaryPackForUpdates) {
+ BinaryDictionaryFileDumper.cacheWordListsFromContentProvider(locale, context,
+ hasDefaultWordList);
}
final File[] cachedWordLists = getCachedWordLists(locale.toString(), context);
final String mainDictId = DictionaryInfoUtils.getMainDictId(locale);