Bug 1854739 - Catch crash when migrating pref_key_search_widget_installed

fenix/119.0
Roger Yang 8 months ago committed by mergify[bot]
parent 4eebd93103
commit e6aefd2a11

@ -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()
assertFalse(settings.searchWidgetInstalled)
}
}

Loading…
Cancel
Save