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;
}
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;

View file

@ -31,10 +31,7 @@ import helium314.keyboard.latin.utils.locale
import helium314.keyboard.latin.utils.prefs
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.io.File
import java.io.IOException
import java.util.Locale
@ -231,23 +228,27 @@ class DictionaryFacilitatorImpl : DictionaryFacilitator {
val latchForWaitingLoadingMainDictionary = CountDownLatch(1)
mLatchForWaitingLoadingMainDictionaries = latchForWaitingLoadingMainDictionary
scope.launch {
val dictGroupsWithNewMainDict = locales.mapNotNull {
val dictionaryGroup = findDictionaryGroupWithLocale(dictionaryGroups, it)
if (dictionaryGroup == null) {
Log.w(TAG, "Expected a dictionary group for $it but none found")
return@mapNotNull null // This should never happen
try {
val dictGroupsWithNewMainDict = locales.mapNotNull {
val dictionaryGroup = findDictionaryGroupWithLocale(dictionaryGroups, it)
if (dictionaryGroup == null) {
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
else dictionaryGroup to DictionaryFactory.createMainDictionaryCollection(context, it)
}
synchronized(this) {
dictGroupsWithNewMainDict.forEach { (dictGroup, mainDict) ->
dictGroup.setMainDict(mainDict)
synchronized(this) {
dictGroupsWithNewMainDict.forEach { (dictGroup, mainDict) ->
dictGroup.setMainDict(mainDict)
}
}
}
listener?.onUpdateMainDictionaryAvailability(hasAtLeastOneInitializedMainDictionary())
latchForWaitingLoadingMainDictionary.countDown()
listener?.onUpdateMainDictionaryAvailability(hasAtLeastOneInitializedMainDictionary())
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.
private void resetDictionaryFacilitator(@NonNull final Locale locale) {
final SettingsValues settingsValues = mSettings.getCurrent();
mDictionaryFacilitator.resetDictionaries(this, locale,
try {
mDictionaryFacilitator.resetDictionaries(this, locale,
settingsValues.mUseContactsDictionary, settingsValues.mUseAppsDictionary,
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);
}