From 0e5473caae596c08932e96eedd1cdb34adb60af7 Mon Sep 17 00:00:00 2001 From: erfanian Date: Thu, 25 Jan 2018 08:00:13 -0800 Subject: Reset invalid selected countries to the default value. In some cases, we may revoke countries or make them otherwise unavailable to assisted dialing. In this case, we reset the preference back the the default value, which is always the zeroth value. Bug: 72322367 Test: new unit test PiperOrigin-RevId: 183238476 Change-Id: Ib5cf200f6da04e332b6248b04057d5de0f64d01f --- .../ui/AssistedDialingSettingFragment.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'java/com/android') diff --git a/java/com/android/dialer/assisteddialing/ui/AssistedDialingSettingFragment.java b/java/com/android/dialer/assisteddialing/ui/AssistedDialingSettingFragment.java index 932cc6d6c..f1ea4c9dc 100644 --- a/java/com/android/dialer/assisteddialing/ui/AssistedDialingSettingFragment.java +++ b/java/com/android/dialer/assisteddialing/ui/AssistedDialingSettingFragment.java @@ -140,6 +140,28 @@ public class AssistedDialingSettingFragment extends PreferenceFragment { countryChooserPref.setEntries(newKeys.toArray(new CharSequence[newKeys.size()])); countryChooserPref.setEntryValues(newValues.toArray(new CharSequence[newValues.size()])); + + if (!newValues.contains(countryChooserPref.getValue())) { + ameliorateInvalidSelectedValue(countryChooserPref); + } + } + + /** + * Restore an invalid user selected value to the default value. + * + *

In the Assisted Dialing settings in Dialer, this state is possible when a user selected a + * country code, and then that country code was removed from our filtered list, typically via a + * change in the available countries provided by a server side flag. + * + * @param countryChooserPref The list preference to restore to default when an invalid value is + * detected. + */ + private void ameliorateInvalidSelectedValue(ListPreference countryChooserPref) { + // Reset the preference value to the default value. + countryChooserPref.setValue(countryChooserPref.getEntryValues()[0].toString()); + LogUtil.i( + "AssistedDialingSettingFragment.ameliorateInvalidSelectedValue", + "Reset the country chooser preference to the default value."); } private List buildDefaultCountryChooserKeysAndValues( -- cgit v1.2.3