Create preference to allow user to toggle sticky battery saver

This adds the toggle that makes it so that battery saver turns
off automatically at high battery percentages or not.

Test: robotests
Bug: 112232746
Change-Id: I0df879a43e5390bc671c47e780bbbb466a3e9353
This commit is contained in:
Salvador Martinez
2019-03-04 11:15:12 -08:00
parent f9df7394ca
commit 6db5eb6cd0
4 changed files with 120 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
package com.android.settings.fuelgauge.batterysaver;
import android.content.Context;
import android.provider.Settings;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.PreferenceControllerMixin;
public class BatterySaverStickyPreferenceController extends BasePreferenceController implements
PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
public static final String LOW_POWER_STICKY_AUTO_DISABLE_ENABLED =
"low_power_sticky_auto_disable_enabled";
public BatterySaverStickyPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
@Override
public void updateState(Preference preference) {
int setting = Settings.System.getInt(mContext.getContentResolver(),
LOW_POWER_STICKY_AUTO_DISABLE_ENABLED, 1);
((SwitchPreference) preference).setChecked(setting == 0);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean keepActive = (Boolean) newValue;
Settings.System.putInt(mContext.getContentResolver(),
LOW_POWER_STICKY_AUTO_DISABLE_ENABLED,
keepActive ? 0 : 1);
return true;
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
}