some additional safety, so we show at least a working keyboard in case dictionary or native library loading fails

This commit is contained in:
Helium314 2025-06-01 17:03:16 +02:00
parent 07ea14ea16
commit f81f6a7f7d
3 changed files with 30 additions and 19 deletions

View file

@ -70,7 +70,12 @@ public class ProximityInfo {
return; return;
} }
computeNearestNeighbors(); computeNearestNeighbors();
mNativeProximityInfo = createNativeProximityInfo(touchPositionCorrection); try {
mNativeProximityInfo = createNativeProximityInfo(touchPositionCorrection);
} catch (Throwable e) {
Log.e(TAG, "could not create proximity info", e);
mNativeProximityInfo = 0;
}
} }
private long mNativeProximityInfo; private long mNativeProximityInfo;

View file

@ -31,10 +31,7 @@ import helium314.keyboard.latin.utils.locale
import helium314.keyboard.latin.utils.prefs import helium314.keyboard.latin.utils.prefs
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.io.File import java.io.File
import java.io.IOException import java.io.IOException
import java.util.Locale import java.util.Locale
@ -231,23 +228,27 @@ class DictionaryFacilitatorImpl : DictionaryFacilitator {
val latchForWaitingLoadingMainDictionary = CountDownLatch(1) val latchForWaitingLoadingMainDictionary = CountDownLatch(1)
mLatchForWaitingLoadingMainDictionaries = latchForWaitingLoadingMainDictionary mLatchForWaitingLoadingMainDictionaries = latchForWaitingLoadingMainDictionary
scope.launch { scope.launch {
val dictGroupsWithNewMainDict = locales.mapNotNull { try {
val dictionaryGroup = findDictionaryGroupWithLocale(dictionaryGroups, it) val dictGroupsWithNewMainDict = locales.mapNotNull {
if (dictionaryGroup == null) { val dictionaryGroup = findDictionaryGroupWithLocale(dictionaryGroups, it)
Log.w(TAG, "Expected a dictionary group for $it but none found") if (dictionaryGroup == null) {
return@mapNotNull null // This should never happen Log.w(TAG, "Expected a dictionary group for $it but none found")
return@mapNotNull null // This should never happen
}
if (dictionaryGroup.getDict(Dictionary.TYPE_MAIN)?.isInitialized == true) null
else dictionaryGroup to DictionaryFactory.createMainDictionaryCollection(context, it)
} }
if (dictionaryGroup.getDict(Dictionary.TYPE_MAIN)?.isInitialized == true) null synchronized(this) {
else dictionaryGroup to DictionaryFactory.createMainDictionaryCollection(context, it) dictGroupsWithNewMainDict.forEach { (dictGroup, mainDict) ->
} dictGroup.setMainDict(mainDict)
synchronized(this) { }
dictGroupsWithNewMainDict.forEach { (dictGroup, mainDict) ->
dictGroup.setMainDict(mainDict)
} }
}
listener?.onUpdateMainDictionaryAvailability(hasAtLeastOneInitializedMainDictionary()) listener?.onUpdateMainDictionaryAvailability(hasAtLeastOneInitializedMainDictionary())
latchForWaitingLoadingMainDictionary.countDown() latchForWaitingLoadingMainDictionary.countDown()
} catch (e: Throwable) {
Log.e(TAG, "could not initialize main dictionaries for $locales", e)
}
} }
} }

View file

@ -755,9 +755,14 @@ public class LatinIME extends InputMethodService implements
// TODO: make sure the current settings always have the right locales, and read from them. // TODO: make sure the current settings always have the right locales, and read from them.
private void resetDictionaryFacilitator(@NonNull final Locale locale) { private void resetDictionaryFacilitator(@NonNull final Locale locale) {
final SettingsValues settingsValues = mSettings.getCurrent(); final SettingsValues settingsValues = mSettings.getCurrent();
mDictionaryFacilitator.resetDictionaries(this, locale, try {
mDictionaryFacilitator.resetDictionaries(this, locale,
settingsValues.mUseContactsDictionary, settingsValues.mUseAppsDictionary, settingsValues.mUseContactsDictionary, settingsValues.mUseAppsDictionary,
settingsValues.mUsePersonalizedDicts, false, "", this); settingsValues.mUsePersonalizedDicts, false, "", this);
} catch (Throwable e) {
// this should not happen, but in case it does we at least want to show a keyboard
Log.e(TAG, "Could not reset dictionary facilitator, please fix ASAP", e);
}
mInputLogic.mSuggest.setAutoCorrectionThreshold(settingsValues.mAutoCorrectionThreshold); mInputLogic.mSuggest.setAutoCorrectionThreshold(settingsValues.mAutoCorrectionThreshold);
} }