Clean up the KEY_ROUTINE from the Settings
Fix: 258603978 Test: make RunSettingsRoboTests Change-Id: I65033ca18953b57317af64418bb0b18d48eaacd8
This commit is contained in:
@@ -22,6 +22,7 @@ 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 android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settingslib.fuelgauge.BatterySaverUtils;
|
import com.android.settingslib.fuelgauge.BatterySaverUtils;
|
||||||
|
|
||||||
@@ -36,9 +37,9 @@ import com.android.settingslib.fuelgauge.BatterySaverUtils;
|
|||||||
* See {@link Settings.Global#AUTOMATIC_POWER_SAVE_MODE} for more details.
|
* See {@link Settings.Global#AUTOMATIC_POWER_SAVE_MODE} for more details.
|
||||||
*/
|
*/
|
||||||
public class BatterySaverScheduleRadioButtonsController {
|
public class BatterySaverScheduleRadioButtonsController {
|
||||||
|
private static final String TAG = "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_PERCENTAGE = "key_battery_saver_percentage";
|
public static final String KEY_PERCENTAGE = "key_battery_saver_percentage";
|
||||||
public static final int TRIGGER_LEVEL_MIN = 10;
|
public static final int TRIGGER_LEVEL_MIN = 10;
|
||||||
|
|
||||||
@@ -53,20 +54,17 @@ public class BatterySaverScheduleRadioButtonsController {
|
|||||||
|
|
||||||
public String getDefaultKey() {
|
public String getDefaultKey() {
|
||||||
final ContentResolver resolver = mContext.getContentResolver();
|
final ContentResolver resolver = mContext.getContentResolver();
|
||||||
// Note: this can also be obtained via PowerManager.getPowerSaveModeTrigger()
|
|
||||||
final int mode = Settings.Global.getInt(resolver, Global.AUTOMATIC_POWER_SAVE_MODE,
|
final int mode = Settings.Global.getInt(resolver, Global.AUTOMATIC_POWER_SAVE_MODE,
|
||||||
PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
|
PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
|
||||||
// if mode is "dynamic" we are in routine mode, percentage with non-zero threshold is
|
|
||||||
// percentage mode, otherwise it is no schedule mode
|
|
||||||
if (mode == PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE) {
|
if (mode == PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE) {
|
||||||
final int threshold =
|
final int threshold =
|
||||||
Settings.Global.getInt(resolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
|
Settings.Global.getInt(resolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
|
||||||
if (threshold <= 0) {
|
return threshold <= 0 ? KEY_NO_SCHEDULE : KEY_PERCENTAGE;
|
||||||
return KEY_NO_SCHEDULE;
|
|
||||||
}
|
|
||||||
return KEY_PERCENTAGE;
|
|
||||||
}
|
}
|
||||||
return KEY_ROUTINE;
|
// Convert the legacy routine mode into none.
|
||||||
|
BatterySaverUtils.revertScheduleToNoneIfNeeded(mContext);
|
||||||
|
Log.w(TAG, "Found the legacy routine mode and set into none");
|
||||||
|
return KEY_NO_SCHEDULE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setDefaultKey(String key) {
|
public boolean setDefaultKey(String key) {
|
||||||
@@ -89,12 +87,6 @@ public class BatterySaverScheduleRadioButtonsController {
|
|||||||
confirmationExtras.putInt(BatterySaverUtils.EXTRA_POWER_SAVE_MODE_TRIGGER_LEVEL,
|
confirmationExtras.putInt(BatterySaverUtils.EXTRA_POWER_SAVE_MODE_TRIGGER_LEVEL,
|
||||||
triggerLevel);
|
triggerLevel);
|
||||||
break;
|
break;
|
||||||
case KEY_ROUTINE:
|
|
||||||
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;
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Not a valid key for " + this.getClass().getSimpleName());
|
"Not a valid key for " + this.getClass().getSimpleName());
|
||||||
|
@@ -52,7 +52,7 @@ public class BatterySaverScheduleRadioButtonsControllerTest {
|
|||||||
Settings.Global.putInt(mResolver, Global.AUTOMATIC_POWER_SAVE_MODE,
|
Settings.Global.putInt(mResolver, Global.AUTOMATIC_POWER_SAVE_MODE,
|
||||||
PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC);
|
PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC);
|
||||||
assertThat(mController.getDefaultKey())
|
assertThat(mController.getDefaultKey())
|
||||||
.isEqualTo(BatterySaverScheduleRadioButtonsController.KEY_ROUTINE);
|
.isEqualTo(BatterySaverScheduleRadioButtonsController.KEY_NO_SCHEDULE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -73,14 +73,6 @@ public class BatterySaverScheduleRadioButtonsControllerTest {
|
|||||||
.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);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setDefaultKey_percentage_shouldSuppressNotification() {
|
public void setDefaultKey_percentage_shouldSuppressNotification() {
|
||||||
@@ -95,17 +87,4 @@ public class BatterySaverScheduleRadioButtonsControllerTest {
|
|||||||
Secure.SUPPRESS_AUTO_BATTERY_SAVER_SUGGESTION, 0);
|
Secure.SUPPRESS_AUTO_BATTERY_SAVER_SUGGESTION, 0);
|
||||||
assertThat(result).isEqualTo(1);
|
assertThat(result).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setDefaultKey_routine_shouldSuppressNotification() {
|
|
||||||
Secure.putInt(
|
|
||||||
mContext.getContentResolver(), Secure.LOW_POWER_WARNING_ACKNOWLEDGED, 1);
|
|
||||||
Settings.Global.putInt(mResolver, Global.AUTOMATIC_POWER_SAVE_MODE,
|
|
||||||
PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC);
|
|
||||||
mController.setDefaultKey(BatterySaverScheduleRadioButtonsController.KEY_ROUTINE);
|
|
||||||
|
|
||||||
final int result = Settings.Secure.getInt(mResolver,
|
|
||||||
Secure.SUPPRESS_AUTO_BATTERY_SAVER_SUGGESTION, 0);
|
|
||||||
assertThat(result).isEqualTo(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user