Fix a bug in show surface updates

- fix a bug that caused the master switch to unintentionally turn on
 the show surface updates preference

Bug: 34203528
Test: make RunSettingsRoboTests -j40
Change-Id: I307a801aa1a7c1606b3f5d55a0d1f2dbf1d60416
This commit is contained in:
jeffreyhuang
2017-09-28 18:08:47 -07:00
parent ae6c29d10f
commit 6da6ea878f
2 changed files with 19 additions and 3 deletions

View File

@@ -86,8 +86,12 @@ public class ShowSurfaceUpdatesPreferenceController extends DeveloperOptionsPref
@Override
protected void onDeveloperOptionsSwitchDisabled() {
writeShowUpdatesSetting(false);
mPreference.setChecked(false);
if (mPreference.isChecked()) {
// Writing false to the preference when the setting is already off will have a
// side effect of turning on the preference that we wish to avoid
writeShowUpdatesSetting(false);
mPreference.setChecked(false);
}
mPreference.setEnabled(false);
}

View File

@@ -24,6 +24,7 @@ import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -110,7 +111,18 @@ public class ShowSurfaceUpdatesPreferenceControllerTest {
}
@Test
public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() {
public void onDeveloperOptionsSwitchDisabled_preferenceUnchecked_shouldNotTurnOffPreference() {
when(mPreference.isChecked()).thenReturn(false);
mController.onDeveloperOptionsSwitchDisabled();
verify(mController, never()).writeShowUpdatesSetting(anyBoolean());
verify(mPreference, never()).setChecked(anyBoolean());
verify(mPreference).setEnabled(false);
}
@Test
public void onDeveloperOptionsSwitchDisabled_preferenceChecked_shouldTurnOffPreference() {
when(mPreference.isChecked()).thenReturn(true);
mController.onDeveloperOptionsSwitchDisabled();
verify(mController).writeShowUpdatesSetting(false);