diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java index 867c18686..f4300c462 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java @@ -21,11 +21,12 @@ import android.content.SharedPreferences; import android.content.res.AssetFileDescriptor; import android.util.Log; +import com.android.inputmethod.latin.common.LocaleUtils; +import com.android.inputmethod.latin.define.DecoderSpecificConstants; import com.android.inputmethod.latin.makedict.DictionaryHeader; import com.android.inputmethod.latin.makedict.UnsupportedFormatException; import com.android.inputmethod.latin.utils.BinaryDictionaryUtils; import com.android.inputmethod.latin.utils.DictionaryInfoUtils; -import com.android.inputmethod.latin.utils.LocaleUtils; import java.io.File; import java.io.IOException; @@ -54,6 +55,9 @@ final public class BinaryDictionaryGetter { */ private static final String COMMON_PREFERENCES_NAME = "LatinImeDictPrefs"; + private static final boolean SHOULD_USE_DICT_VERSION = + DecoderSpecificConstants.SHOULD_USE_DICT_VERSION; + // Name of the category for the main dictionary public static final String MAIN_DICTIONARY_CATEGORY = "main"; public static final String ID_CATEGORY_SEPARATOR = ":"; @@ -87,10 +91,15 @@ final public class BinaryDictionaryGetter { */ public static AssetFileAddress loadFallbackResource(final Context context, final int fallbackResId) { - final AssetFileDescriptor afd = context.getResources().openRawResourceFd(fallbackResId); + AssetFileDescriptor afd = null; + try { + afd = context.getResources().openRawResourceFd(fallbackResId); + } catch (RuntimeException e) { + Log.e(TAG, "Resource not found: " + fallbackResId, e); + return null; + } if (afd == null) { - Log.e(TAG, "Found the resource but cannot read it. Is it compressed? resId=" - + fallbackResId); + Log.e(TAG, "Resource cannot be opened: " + fallbackResId); return null; } try { @@ -99,8 +108,7 @@ final public class BinaryDictionaryGetter { } finally { try { afd.close(); - } catch (IOException e) { - // Ignored + } catch (IOException ignored) { } } } @@ -121,12 +129,11 @@ final public class BinaryDictionaryGetter { // reason some dictionaries have been installed BUT the dictionary pack can't be // found anymore it's safer to actually supply installed dictionaries. return true; - } else { - // The default is true here for the same reasons as above. We got the dictionary - // pack but if we don't have any settings for it it means the user has never been - // to the settings yet. So by default, the main dictionaries should be on. - return mDictPreferences.getBoolean(dictId, true); } + // The default is true here for the same reasons as above. We got the dictionary + // pack but if we don't have any settings for it it means the user has never been + // to the settings yet. So by default, the main dictionaries should be on. + return mDictPreferences.getBoolean(dictId, true); } } @@ -224,7 +231,11 @@ final public class BinaryDictionaryGetter { // ## 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. - private static boolean hackCanUseDictionaryFile(final Locale locale, final File file) { + private static boolean hackCanUseDictionaryFile(final File file) { + if (!SHOULD_USE_DICT_VERSION) { + return true; + } + try { // Read the version of the file final DictionaryHeader header = BinaryDictionaryUtils.getHeader(file); @@ -264,7 +275,8 @@ final public class BinaryDictionaryGetter { public static ArrayList<AssetFileAddress> getDictionaryFiles(final Locale locale, final Context context) { - final boolean hasDefaultWordList = DictionaryFactory.isDictionaryAvailable(context, locale); + final boolean hasDefaultWordList = DictionaryInfoUtils.isDictionaryAvailable( + context, locale); BinaryDictionaryFileDumper.cacheWordListsFromContentProvider(locale, context, hasDefaultWordList); final File[] cachedWordLists = getCachedWordLists(locale.toString(), context); @@ -276,7 +288,7 @@ final public class BinaryDictionaryGetter { // cachedWordLists may not be null, see doc for getCachedDictionaryList for (final File f : cachedWordLists) { final String wordListId = DictionaryInfoUtils.getWordListIdFromFileName(f.getName()); - final boolean canUse = f.canRead() && hackCanUseDictionaryFile(locale, f); + final boolean canUse = f.canRead() && hackCanUseDictionaryFile(f); if (canUse && DictionaryInfoUtils.isMainWordListId(wordListId)) { foundMainDict = true; } @@ -285,7 +297,8 @@ final public class BinaryDictionaryGetter { final AssetFileAddress afa = AssetFileAddress.makeFromFileName(f.getPath()); if (null != afa) fileList.add(afa); } else { - Log.e(TAG, "Found a cached dictionary file but cannot read or use it"); + Log.e(TAG, "Found a cached dictionary file for " + locale.toString() + + " but cannot read or use it"); } } |