Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2521edec authored by Jean Chalard's avatar Jean Chalard
Browse files

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
parent 8f794c72
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -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<DictionaryInfo> dictList,
+6 −0
Original line number Diff line number Diff line
@@ -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() {