Flip the preference for sticky battery saver

Instead of toggled on being to keep battery saver on, the UX
writers would like to make toggled on be turn battery saver off
automatically. Also turns the controller into a
TogglePreferenceController, because those exist apparently.

Test: visual inspection, tests pass
Fixes: 126938839
Change-Id: Iffac536d0b1956d4534ca1b5fa5c6440c4d3a3ff
This commit is contained in:
Salvador Martinez
2019-03-22 13:42:39 -07:00
parent 12256ca49f
commit d12d722099
4 changed files with 49 additions and 34 deletions

View File

@@ -16,11 +16,11 @@
package com.android.settings.fuelgauge.batterysaver;
import static com.android.settings.fuelgauge.batterysaver.BatterySaverStickyPreferenceController.LOW_POWER_STICKY_AUTO_DISABLE_ENABLED;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.provider.Settings;
import android.provider.Settings.Global;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -43,21 +43,21 @@ public class BatterySaverStickyPreferenceControllerTest {
private int getAutoDisableSetting() {
return Settings.Global.getInt(mContext.getContentResolver(),
LOW_POWER_STICKY_AUTO_DISABLE_ENABLED,
Global.LOW_POWER_MODE_STICKY_AUTO_DISABLE_ENABLED,
1);
}
@Test
public void testOnPreferenceChange_turnOnKeepActive_autoDisableOff() {
mController.onPreferenceChange(null, true);
final int isOn = getAutoDisableSetting();
assertThat(isOn).isEqualTo(0);
}
@Test
public void testOnPreferenceChange_TurnOffKeepActive_autoDisableOff() {
mController.onPreferenceChange(null, false);
public void testOnPreferenceChange_turnOnAutoOff_autoDisableOn() {
mController.setChecked(true);
final int isOn = getAutoDisableSetting();
assertThat(isOn).isEqualTo(1);
}
@Test
public void testOnPreferenceChange_TurnOffAutoOff_autoDisableOff() {
mController.setChecked(false);
final int isOn = getAutoDisableSetting();
assertThat(isOn).isEqualTo(0);
}
}