From 2521edec09373b2810093462c89221a2aca9e369 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 22 Feb 2013 20:49:48 -0800 Subject: [PATCH] Fix a bug with the passed dictionary id We used to make the dictionary that we passed to the dictionary pack as an initial value based on the locale. This is wrong - it should be read from the dictionary. This change fixes that. Bug: 7005813 Change-Id: Ib08ed31dd9c216f6f7b9c6c3174ca514bf96e06f --- .../inputmethod/latin/DictionaryInfoUtils.java | 11 +++++------ .../inputmethod/latin/makedict/FormatSpec.java | 6 ++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/DictionaryInfoUtils.java b/java/src/com/android/inputmethod/latin/DictionaryInfoUtils.java index d2a946bf5..28234659d 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryInfoUtils.java +++ b/java/src/com/android/inputmethod/latin/DictionaryInfoUtils.java @@ -41,8 +41,6 @@ public class DictionaryInfoUtils { private static final String RESOURCE_PACKAGE_NAME = DictionaryInfoUtils.class.getPackage().getName(); private static final String DEFAULT_MAIN_DICT = "main"; - private static final String ID_CATEGORY_SEPARATOR = - BinaryDictionaryGetter.ID_CATEGORY_SEPARATOR; private static final String MAIN_DICT_PREFIX = "main_"; // 6 digits - unicode is limited to 21 bits private static final int MAX_HEX_DIGITS_FOR_CODEPOINT = 6; @@ -58,12 +56,12 @@ public class DictionaryInfoUtils { public final AssetFileAddress mFileAddress; public final int mVersion; public final String mId; - public DictionaryInfo(final Locale locale, final AssetFileAddress fileAddress, - final int version) { + public DictionaryInfo(final String id, final Locale locale, + final AssetFileAddress fileAddress, final int version) { + mId = id; mLocale = locale; mFileAddress = fileAddress; mVersion = version; - mId = DEFAULT_MAIN_DICT + ID_CATEGORY_SEPARATOR + mLocale; } public ContentValues toContentValues() { final ContentValues values = new ContentValues(); @@ -283,9 +281,10 @@ public class DictionaryInfoUtils { final AssetFileAddress fileAddress) { final FileHeader header = BinaryDictIOUtils.getDictionaryFileHeaderOrNull( new File(fileAddress.mFilename), fileAddress.mOffset, fileAddress.mLength); + final String id = header.getId(); final Locale locale = LocaleUtils.constructLocaleFromString(header.getLocaleString()); final String version = header.getVersion(); - return new DictionaryInfo(locale, fileAddress, Integer.parseInt(version)); + return new DictionaryInfo(id, locale, fileAddress, Integer.parseInt(version)); } private static void addOrUpdateDictInfo(final ArrayList dictList, diff --git a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java index 83acca874..60ba66e27 100644 --- a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java +++ b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java @@ -258,6 +258,7 @@ public final class FormatSpec { public final FormatOptions mFormatOptions; private static final String DICTIONARY_VERSION_ATTRIBUTE = "version"; private static final String DICTIONARY_LOCALE_ATTRIBUTE = "locale"; + private static final String DICTIONARY_ID_ATTRIBUTE = "dictionary"; public FileHeader(final int headerSize, final DictionaryOptions dictionaryOptions, final FormatOptions formatOptions) { mHeaderSize = headerSize; @@ -274,6 +275,11 @@ public final class FormatSpec { public String getVersion() { return mDictionaryOptions.mAttributes.get(FileHeader.DICTIONARY_VERSION_ATTRIBUTE); } + + // Helper method to get the dictionary ID as a String + public String getId() { + return mDictionaryOptions.mAttributes.get(FileHeader.DICTIONARY_ID_ATTRIBUTE); + } } private FormatSpec() {