diff options
author | 2015-07-03 16:47:23 +0000 | |
---|---|---|
committer | 2015-07-03 16:47:23 +0000 | |
commit | 37d33d3da1627d57ab8daca2951f48739afbcbfb (patch) | |
tree | 8461bb8ed67f4a26f95dce86b99cd440cce7b5de /java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java | |
parent | 2c2065a56aa9c4e2971e6fc8ee0b8d0d059695b7 (diff) | |
parent | 8ed9bccaf2f670fd34689771d37c4e064da25b57 (diff) | |
download | latinime-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/BinaryDictionaryFileDumper.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java | 39 |
1 files changed, 13 insertions, 26 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java index 4b242c5f5..bc62f3ae3 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java @@ -29,7 +29,6 @@ import android.util.Log; import com.android.inputmethod.dictionarypack.DictionaryPackConstants; import com.android.inputmethod.dictionarypack.MD5Calculator; -import com.android.inputmethod.latin.common.FileUtils; import com.android.inputmethod.latin.define.DecoderSpecificConstants; import com.android.inputmethod.latin.utils.DictionaryInfoUtils; import com.android.inputmethod.latin.utils.DictionaryInfoUtils.DictionaryInfo; @@ -221,11 +220,11 @@ public final class BinaryDictionaryFileDumper { } /** - * Stages a word list the id of which is passed as an argument. This will write the file + * Caches a word list the id of which is passed as an argument. This will write the file * to the cache file name designated by its id and locale, overwriting it if already present * and creating it (and its containing directory) if necessary. */ - private static void installWordListToStaging(final String wordlistId, final String locale, + private static void cacheWordList(final String wordlistId, final String locale, final String rawChecksum, final ContentProviderClient providerClient, final Context context) { final int COMPRESSED_CRYPTED_COMPRESSED = 0; @@ -247,7 +246,7 @@ public final class BinaryDictionaryFileDumper { return; } final String finalFileName = - DictionaryInfoUtils.getStagingFileName(wordlistId, locale, context); + DictionaryInfoUtils.getCacheFileName(wordlistId, locale, context); String tempFileName; try { tempFileName = BinaryDictionaryGetter.getTempFileName(wordlistId, context); @@ -321,21 +320,23 @@ public final class BinaryDictionaryFileDumper { } } - // move the output file to the final staging file. final File finalFile = new File(finalFileName); - FileUtils.renameTo(outputFile, finalFile); - + finalFile.delete(); + if (!outputFile.renameTo(finalFile)) { + throw new IOException("Can't move the file to its final name"); + } wordListUriBuilder.appendQueryParameter(QUERY_PARAMETER_DELETE_RESULT, QUERY_PARAMETER_SUCCESS); if (0 >= providerClient.delete(wordListUriBuilder.build(), null, null)) { Log.e(TAG, "Could not have the dictionary pack delete a word list"); } - Log.d(TAG, "Successfully copied file for wordlist ID " + wordlistId); + BinaryDictionaryGetter.removeFilesWithIdExcept(context, wordlistId, finalFile); + Log.e(TAG, "Successfully copied file for wordlist ID " + wordlistId); // Success! Close files (through the finally{} clause) and return. return; } catch (Exception e) { if (DEBUG) { - Log.e(TAG, "Can't open word list in mode " + mode, e); + Log.i(TAG, "Can't open word list in mode " + mode, e); } if (null != outputFile) { // This may or may not fail. The file may not have been created if the @@ -402,7 +403,7 @@ public final class BinaryDictionaryFileDumper { } /** - * Queries a content provider for word list data for some locale and stage the returned files + * Queries a content provider for word list data for some locale and cache the returned files * * This will query a content provider for word list data for a given locale, and copy the * files locally so that they can be mmap'ed. This may overwrite previously cached word lists @@ -410,7 +411,7 @@ public final class BinaryDictionaryFileDumper { * @throw FileNotFoundException if the provider returns non-existent data. * @throw IOException if the provider-returned data could not be read. */ - public static void installDictToStagingFromContentProvider(final Locale locale, + public static void cacheWordListsFromContentProvider(final Locale locale, final Context context, final boolean hasDefaultWordList) { final ContentProviderClient providerClient; try { @@ -428,8 +429,7 @@ public final class BinaryDictionaryFileDumper { final List<WordListInfo> idList = getWordListWordListInfos(locale, context, hasDefaultWordList); for (WordListInfo id : idList) { - installWordListToStaging(id.mId, id.mLocale, id.mRawChecksum, providerClient, - context); + cacheWordList(id.mId, id.mLocale, id.mRawChecksum, providerClient, context); } } finally { providerClient.release(); @@ -437,19 +437,6 @@ public final class BinaryDictionaryFileDumper { } /** - * Downloads the dictionary if it was never requested/used. - * - * @param locale locale to download - * @param context the context for resources and providers. - * @param hasDefaultWordList whether the default wordlist exists in the resources. - */ - public static void downloadDictIfNeverRequested(final Locale locale, - final Context context, final boolean hasDefaultWordList) { - Log.d("inamul_tag", "BinaryDictionaryFileDumper.downloadDictIfNeverRequested()"); - getWordListWordListInfos(locale, context, hasDefaultWordList); - } - - /** * Copies the data in an input stream to a target file if the magic number matches. * * If the magic number does not match the expected value, this method throws an |