From 6da6ea878f6b75d3b6c517dc36b51190f5e3c44a Mon Sep 17 00:00:00 2001 From: jeffreyhuang Date: Thu, 28 Sep 2017 18:08:47 -0700 Subject: [PATCH] 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 --- .../ShowSurfaceUpdatesPreferenceController.java | 8 ++++++-- ...ShowSurfaceUpdatesPreferenceControllerTest.java | 14 +++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/development/ShowSurfaceUpdatesPreferenceController.java b/src/com/android/settings/development/ShowSurfaceUpdatesPreferenceController.java index 5656aa00dbd..d546f0b21fa 100644 --- a/src/com/android/settings/development/ShowSurfaceUpdatesPreferenceController.java +++ b/src/com/android/settings/development/ShowSurfaceUpdatesPreferenceController.java @@ -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); } diff --git a/tests/robotests/src/com/android/settings/development/ShowSurfaceUpdatesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/ShowSurfaceUpdatesPreferenceControllerTest.java index c3a3a8297f2..57c4ae3cf42 100644 --- a/tests/robotests/src/com/android/settings/development/ShowSurfaceUpdatesPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/ShowSurfaceUpdatesPreferenceControllerTest.java @@ -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);