Update BS warning to follow through on action
The BS warning only had support for following through when a user wanted to toggle battery saver. This also makes it so that if the warning is shown for routines it will finish whatever action it interrupted once confirmed. Test: robotests pass, manual verification Bug: 129696128 Change-Id: I2c34ed678b19d95f3c7d1094ab8f79cc0c23252e
This commit is contained in:
@@ -17,6 +17,7 @@ package com.android.settings.fuelgauge.batterysaver;
|
|||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
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;
|
||||||
@@ -38,6 +39,7 @@ public class BatterySaverScheduleRadioButtonsController {
|
|||||||
public static final String KEY_NO_SCHEDULE = "key_battery_saver_no_schedule";
|
public static final String KEY_NO_SCHEDULE = "key_battery_saver_no_schedule";
|
||||||
public static final String KEY_ROUTINE = "key_battery_saver_routine";
|
public static final String KEY_ROUTINE = "key_battery_saver_routine";
|
||||||
public static final String KEY_PERCENTAGE = "key_battery_saver_percentage";
|
public static final String KEY_PERCENTAGE = "key_battery_saver_percentage";
|
||||||
|
public static final int TRIGGER_LEVEL_MIN = 5;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private BatterySaverScheduleSeekBarController mSeekBarController;
|
private BatterySaverScheduleSeekBarController mSeekBarController;
|
||||||
@@ -67,30 +69,43 @@ public class BatterySaverScheduleRadioButtonsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean setDefaultKey(String key) {
|
public boolean setDefaultKey(String key) {
|
||||||
final ContentResolver resolver = mContext.getContentResolver();
|
if (key == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ContentResolver resolver = mContext.getContentResolver();
|
||||||
int mode = PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE;
|
int mode = PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE;
|
||||||
int triggerLevel = 0;
|
int triggerLevel = 0;
|
||||||
if (!TextUtils.equals(key, KEY_NO_SCHEDULE)
|
final Bundle confirmationExtras = new Bundle(3);
|
||||||
&& BatterySaverUtils.maybeShowBatterySaverConfirmation(
|
|
||||||
mContext, true /* confirmOnly */)) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case KEY_NO_SCHEDULE:
|
case KEY_NO_SCHEDULE:
|
||||||
break;
|
break;
|
||||||
case KEY_PERCENTAGE:
|
case KEY_PERCENTAGE:
|
||||||
triggerLevel = 5;
|
triggerLevel = TRIGGER_LEVEL_MIN;
|
||||||
|
confirmationExtras.putBoolean(BatterySaverUtils.EXTRA_CONFIRM_TEXT_ONLY, true);
|
||||||
|
confirmationExtras.putInt(BatterySaverUtils.EXTRA_POWER_SAVE_MODE_TRIGGER,
|
||||||
|
PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
|
||||||
|
confirmationExtras.putInt(BatterySaverUtils.EXTRA_POWER_SAVE_MODE_TRIGGER_LEVEL,
|
||||||
|
triggerLevel);
|
||||||
break;
|
break;
|
||||||
case KEY_ROUTINE:
|
case KEY_ROUTINE:
|
||||||
mode = PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC;
|
mode = PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC;
|
||||||
|
confirmationExtras.putBoolean(BatterySaverUtils.EXTRA_CONFIRM_TEXT_ONLY, true);
|
||||||
|
confirmationExtras.putInt(BatterySaverUtils.EXTRA_POWER_SAVE_MODE_TRIGGER,
|
||||||
|
PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Not a valid key for " + this.getClass().getSimpleName());
|
"Not a valid key for " + this.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!TextUtils.equals(key, KEY_NO_SCHEDULE)
|
||||||
|
&& BatterySaverUtils.maybeShowBatterySaverConfirmation(
|
||||||
|
mContext, confirmationExtras)) {
|
||||||
|
// reset this if we need to show the confirmation message
|
||||||
|
mode = PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE;
|
||||||
|
triggerLevel = 0;
|
||||||
|
}
|
||||||
// Trigger level is intentionally left alone when going between dynamic and percentage modes
|
// 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.
|
// 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);
|
Settings.Global.putInt(resolver, Global.AUTOMATIC_POWER_SAVE_MODE, mode);
|
||||||
|
Reference in New Issue
Block a user