Merge "Update battery saver schedule to show warning"
This commit is contained in:
committed by
Android (Google) Code Review
commit
db1c8a5fed
@@ -20,6 +20,8 @@ import android.content.Context;
|
|||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.provider.Settings.Global;
|
import android.provider.Settings.Global;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import com.android.settingslib.fuelgauge.BatterySaverUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Responds to user actions in the Settings > Battery > Set a Schedule Screen
|
* Responds to user actions in the Settings > Battery > Set a Schedule Screen
|
||||||
@@ -66,24 +68,34 @@ public class BatterySaverScheduleRadioButtonsController {
|
|||||||
|
|
||||||
public boolean setDefaultKey(String key) {
|
public boolean setDefaultKey(String key) {
|
||||||
final ContentResolver resolver = mContext.getContentResolver();
|
final ContentResolver resolver = mContext.getContentResolver();
|
||||||
switch(key) {
|
|
||||||
case KEY_NO_SCHEDULE:
|
int mode = PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE;
|
||||||
Settings.Global.putInt(resolver, Global.AUTOMATIC_POWER_SAVE_MODE,
|
int triggerLevel = 0;
|
||||||
PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
|
if (!TextUtils.equals(key, KEY_NO_SCHEDULE)
|
||||||
Settings.Global.putInt(resolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
|
&& BatterySaverUtils.maybeShowBatterySaverConfirmation(
|
||||||
break;
|
mContext, true /* confirmOnly */)) {
|
||||||
case KEY_PERCENTAGE:
|
return true;
|
||||||
Settings.Global.putInt(resolver, Global.AUTOMATIC_POWER_SAVE_MODE,
|
} else {
|
||||||
PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
|
switch (key) {
|
||||||
Settings.Global.putInt(resolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 5);
|
case KEY_NO_SCHEDULE:
|
||||||
break;
|
break;
|
||||||
case KEY_ROUTINE:
|
case KEY_PERCENTAGE:
|
||||||
Settings.Global.putInt(resolver, Global.AUTOMATIC_POWER_SAVE_MODE,
|
triggerLevel = 5;
|
||||||
PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC);
|
break;
|
||||||
break;
|
case KEY_ROUTINE:
|
||||||
default:
|
mode = PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC;
|
||||||
throw new IllegalStateException(
|
break;
|
||||||
"Not a valid key for " + this.getClass().getSimpleName());
|
default:
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Not a valid key for " + this.getClass().getSimpleName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trigger level is intentionally left alone when going between dynamic and percentage modes
|
||||||
|
// so that a users percentage based schedule is preserved when they toggle between the two.
|
||||||
|
Settings.Global.putInt(resolver, Global.AUTOMATIC_POWER_SAVE_MODE, mode);
|
||||||
|
if (mode != PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC) {
|
||||||
|
Settings.Global.putInt(resolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, triggerLevel);
|
||||||
}
|
}
|
||||||
mSeekBarController.updateSeekBar();
|
mSeekBarController.updateSeekBar();
|
||||||
return true;
|
return true;
|
||||||
|
@@ -7,6 +7,7 @@ import android.content.Context;
|
|||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.provider.Settings.Global;
|
import android.provider.Settings.Global;
|
||||||
|
import android.provider.Settings.Secure;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -54,4 +55,13 @@ public class BatterySaverScheduleRadioButtonsControllerTest {
|
|||||||
assertThat(mController.getDefaultKey())
|
assertThat(mController.getDefaultKey())
|
||||||
.isEqualTo(BatterySaverScheduleRadioButtonsController.KEY_NO_SCHEDULE);
|
.isEqualTo(BatterySaverScheduleRadioButtonsController.KEY_NO_SCHEDULE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setDefaultKey_any_defaultsToNoScheduleIfWarningNotSeen() {
|
||||||
|
Secure.putString(
|
||||||
|
mContext.getContentResolver(), Secure.LOW_POWER_WARNING_ACKNOWLEDGED, "null");
|
||||||
|
mController.setDefaultKey(BatterySaverScheduleRadioButtonsController.KEY_ROUTINE);
|
||||||
|
assertThat(mController.getDefaultKey())
|
||||||
|
.isEqualTo(BatterySaverScheduleRadioButtonsController.KEY_NO_SCHEDULE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user