@ -1230,7 +1230,11 @@ class Settings(private val appContext: Context) : PreferencesHolder {
*/
fun migrateSearchWidgetInstalledPrefIfNeeded() {
val oldKey = "pref_key_search_widget_installed"
val installedCount = preferences.getInt(oldKey, 0)
val installedCount = try {
preferences.getInt(oldKey, 0)
} catch (e: ClassCastException) {
0
}
if (installedCount > 0) {
setSearchWidgetInstalled(true)
@ -995,4 +995,13 @@ class SettingsTest {
assertEquals(expectedDefaultValue, settings.preferences.getInt(oldPrefKey, expectedDefaultValue))
assertFalse(settings.searchWidgetInstalled)
@Test
fun `GIVEN previously stored pref_key_search_widget_installed value is Boolean WHEN calling migrateSearchWidgetInstalledIfNeeded THEN crash should not happen`() {
val oldPrefKey = "pref_key_search_widget_installed"
settings.preferences.edit().putBoolean(oldPrefKey, false).apply()
settings.migrateSearchWidgetInstalledPrefIfNeeded()