Rename battery saver schedule mode apis
The APIs that back these settings got renamed so this CL just refactors all the calls to use the new names. Test: robotests still pass Bug: 126944845 Change-Id: I2975c7c79998823058db2c0ced2e5cf02216a106
This commit is contained in:
@@ -90,10 +90,10 @@ public class BatterySaverController extends BasePreferenceController
|
|||||||
final int percent = Settings.Global.getInt(resolver,
|
final int percent = Settings.Global.getInt(resolver,
|
||||||
Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
|
Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
|
||||||
final int mode = Settings.Global.getInt(resolver,
|
final int mode = Settings.Global.getInt(resolver,
|
||||||
Global.AUTOMATIC_POWER_SAVER_MODE, PowerManager.POWER_SAVER_MODE_PERCENTAGE);
|
Global.AUTOMATIC_POWER_SAVE_MODE, PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
|
||||||
if (isPowerSaveOn) {
|
if (isPowerSaveOn) {
|
||||||
return mContext.getString(R.string.battery_saver_on_summary);
|
return mContext.getString(R.string.battery_saver_on_summary);
|
||||||
} else if (mode == PowerManager.POWER_SAVER_MODE_PERCENTAGE) {
|
} else if (mode == PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE) {
|
||||||
if (percent != 0) {
|
if (percent != 0) {
|
||||||
return mContext.getString(R.string.battery_saver_off_scheduled_summary,
|
return mContext.getString(R.string.battery_saver_off_scheduled_summary,
|
||||||
Utils.formatPercentage(percent));
|
Utils.formatPercentage(percent));
|
||||||
|
@@ -61,9 +61,9 @@ public class BatterySaverSchedulePreferenceController extends BasePreferenceCont
|
|||||||
@Override
|
@Override
|
||||||
public CharSequence getSummary() {
|
public CharSequence getSummary() {
|
||||||
final ContentResolver resolver = mContext.getContentResolver();
|
final ContentResolver resolver = mContext.getContentResolver();
|
||||||
final int mode = Settings.Global.getInt(resolver, Global.AUTOMATIC_POWER_SAVER_MODE,
|
final int mode = Settings.Global.getInt(resolver, Global.AUTOMATIC_POWER_SAVE_MODE,
|
||||||
PowerManager.POWER_SAVER_MODE_PERCENTAGE);
|
PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
|
||||||
if (mode == PowerManager.POWER_SAVER_MODE_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) {
|
if (threshold <= 0) {
|
||||||
|
@@ -29,7 +29,7 @@ import android.provider.Settings.Global;
|
|||||||
*
|
*
|
||||||
* Will call the appropriate power manager APIs and modify the correct settings to enable
|
* Will call the appropriate power manager APIs and modify the correct settings to enable
|
||||||
* users to control their automatic battery saver toggling preferences.
|
* users to control their automatic battery saver toggling preferences.
|
||||||
* See {@link Settings.Global#AUTOMATIC_POWER_SAVER_MODE} for more details.
|
* See {@link Settings.Global#AUTOMATIC_POWER_SAVE_MODE} for more details.
|
||||||
*/
|
*/
|
||||||
public class BatterySaverScheduleRadioButtonsController {
|
public class BatterySaverScheduleRadioButtonsController {
|
||||||
|
|
||||||
@@ -48,12 +48,12 @@ 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.getPowerSaveMode()
|
// Note: this can also be obtained via PowerManager.getPowerSaveModeTrigger()
|
||||||
final int mode = Settings.Global.getInt(resolver, Global.AUTOMATIC_POWER_SAVER_MODE,
|
final int mode = Settings.Global.getInt(resolver, Global.AUTOMATIC_POWER_SAVE_MODE,
|
||||||
PowerManager.POWER_SAVER_MODE_PERCENTAGE);
|
PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
|
||||||
// if mode is "dynamic" we are in routine mode, percentage with non-zero threshold is
|
// if mode is "dynamic" we are in routine mode, percentage with non-zero threshold is
|
||||||
// percentage mode, otherwise it is no schedule mode
|
// percentage mode, otherwise it is no schedule mode
|
||||||
if (mode == PowerManager.POWER_SAVER_MODE_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) {
|
if (threshold <= 0) {
|
||||||
@@ -68,18 +68,18 @@ public class BatterySaverScheduleRadioButtonsController {
|
|||||||
final ContentResolver resolver = mContext.getContentResolver();
|
final ContentResolver resolver = mContext.getContentResolver();
|
||||||
switch(key) {
|
switch(key) {
|
||||||
case KEY_NO_SCHEDULE:
|
case KEY_NO_SCHEDULE:
|
||||||
Settings.Global.putInt(resolver, Global.AUTOMATIC_POWER_SAVER_MODE,
|
Settings.Global.putInt(resolver, Global.AUTOMATIC_POWER_SAVE_MODE,
|
||||||
PowerManager.POWER_SAVER_MODE_PERCENTAGE);
|
PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
|
||||||
Settings.Global.putInt(resolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
|
Settings.Global.putInt(resolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
|
||||||
break;
|
break;
|
||||||
case KEY_PERCENTAGE:
|
case KEY_PERCENTAGE:
|
||||||
Settings.Global.putInt(resolver, Global.AUTOMATIC_POWER_SAVER_MODE,
|
Settings.Global.putInt(resolver, Global.AUTOMATIC_POWER_SAVE_MODE,
|
||||||
PowerManager.POWER_SAVER_MODE_PERCENTAGE);
|
PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
|
||||||
Settings.Global.putInt(resolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 5);
|
Settings.Global.putInt(resolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 5);
|
||||||
break;
|
break;
|
||||||
case KEY_ROUTINE:
|
case KEY_ROUTINE:
|
||||||
Settings.Global.putInt(resolver, Global.AUTOMATIC_POWER_SAVER_MODE,
|
Settings.Global.putInt(resolver, Global.AUTOMATIC_POWER_SAVE_MODE,
|
||||||
PowerManager.POWER_SAVER_MODE_DYNAMIC);
|
PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
|
@@ -39,7 +39,7 @@ import com.android.settings.widget.SeekBarPreference;
|
|||||||
*
|
*
|
||||||
* Will call the appropriate power manager APIs and modify the correct settings to enable
|
* Will call the appropriate power manager APIs and modify the correct settings to enable
|
||||||
* users to control their automatic battery saver toggling preferences.
|
* users to control their automatic battery saver toggling preferences.
|
||||||
* See {@link Settings.Global#AUTOMATIC_POWER_SAVER_MODE} for more details.
|
* See {@link Settings.Global#AUTOMATIC_POWER_SAVE_MODE} for more details.
|
||||||
*/
|
*/
|
||||||
public class BatterySaverScheduleSeekBarController implements
|
public class BatterySaverScheduleSeekBarController implements
|
||||||
OnPreferenceChangeListener {
|
OnPreferenceChangeListener {
|
||||||
@@ -76,12 +76,12 @@ public class BatterySaverScheduleSeekBarController implements
|
|||||||
|
|
||||||
public void updateSeekBar() {
|
public void updateSeekBar() {
|
||||||
final ContentResolver resolver = mContext.getContentResolver();
|
final ContentResolver resolver = mContext.getContentResolver();
|
||||||
// Note: this can also be obtained via PowerManager.getPowerSaveMode()
|
// Note: this can also be obtained via PowerManager.getPowerSaveModeTrigger()
|
||||||
final int mode = Settings.Global.getInt(resolver, Global.AUTOMATIC_POWER_SAVER_MODE,
|
final int mode = Settings.Global.getInt(resolver, Global.AUTOMATIC_POWER_SAVE_MODE,
|
||||||
PowerManager.POWER_SAVER_MODE_PERCENTAGE);
|
PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
|
||||||
// if mode is "dynamic" we are in routine mode, percentage with non-zero threshold is
|
// if mode is "dynamic" we are in routine mode, percentage with non-zero threshold is
|
||||||
// percentage mode, otherwise it is no schedule mode
|
// percentage mode, otherwise it is no schedule mode
|
||||||
if (mode == PowerManager.POWER_SAVER_MODE_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) {
|
if (threshold <= 0) {
|
||||||
|
@@ -62,7 +62,7 @@ public class BatterySaverSchedulePreferenceControllerTest {
|
|||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
Settings.Global.putInt(mContext.getContentResolver(),
|
||||||
Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
|
Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
Settings.Global.putInt(mContext.getContentResolver(),
|
||||||
Global.AUTOMATIC_POWER_SAVER_MODE, PowerManager.POWER_SAVER_MODE_PERCENTAGE);
|
Global.AUTOMATIC_POWER_SAVE_MODE, PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ public class BatterySaverSchedulePreferenceControllerTest {
|
|||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
Settings.Global.putInt(mContext.getContentResolver(),
|
||||||
Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, TRIGGER_LEVEL);
|
Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, TRIGGER_LEVEL);
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
Settings.Global.putInt(mContext.getContentResolver(),
|
||||||
Global.AUTOMATIC_POWER_SAVER_MODE, PowerManager.POWER_SAVER_MODE_PERCENTAGE);
|
Global.AUTOMATIC_POWER_SAVE_MODE, PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ public class BatterySaverSchedulePreferenceControllerTest {
|
|||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
Settings.Global.putInt(mContext.getContentResolver(),
|
||||||
Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, TRIGGER_LEVEL);
|
Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, TRIGGER_LEVEL);
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
Settings.Global.putInt(mContext.getContentResolver(),
|
||||||
Global.AUTOMATIC_POWER_SAVER_MODE, PowerManager.POWER_SAVER_MODE_DYNAMIC);
|
Global.AUTOMATIC_POWER_SAVE_MODE, PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
@@ -31,16 +31,16 @@ public class BatterySaverScheduleRadioButtonsControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDefaultKey_routine_returnsCorrectValue() {
|
public void getDefaultKey_routine_returnsCorrectValue() {
|
||||||
Settings.Global.putInt(mResolver, Global.AUTOMATIC_POWER_SAVER_MODE,
|
Settings.Global.putInt(mResolver, Global.AUTOMATIC_POWER_SAVE_MODE,
|
||||||
PowerManager.POWER_SAVER_MODE_DYNAMIC);
|
PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC);
|
||||||
assertThat(mController.getDefaultKey())
|
assertThat(mController.getDefaultKey())
|
||||||
.isEqualTo(BatterySaverScheduleRadioButtonsController.KEY_ROUTINE);
|
.isEqualTo(BatterySaverScheduleRadioButtonsController.KEY_ROUTINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDefaultKey_automatic_returnsCorrectValue() {
|
public void getDefaultKey_automatic_returnsCorrectValue() {
|
||||||
Settings.Global.putInt(mResolver, Global.AUTOMATIC_POWER_SAVER_MODE,
|
Settings.Global.putInt(mResolver, Global.AUTOMATIC_POWER_SAVE_MODE,
|
||||||
PowerManager.POWER_SAVER_MODE_PERCENTAGE);
|
PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
|
||||||
Settings.Global.putInt(mResolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 5);
|
Settings.Global.putInt(mResolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 5);
|
||||||
assertThat(mController.getDefaultKey())
|
assertThat(mController.getDefaultKey())
|
||||||
.isEqualTo(BatterySaverScheduleRadioButtonsController.KEY_PERCENTAGE);
|
.isEqualTo(BatterySaverScheduleRadioButtonsController.KEY_PERCENTAGE);
|
||||||
@@ -48,8 +48,8 @@ public class BatterySaverScheduleRadioButtonsControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDefaultKey_none_returnsCorrectValue() {
|
public void getDefaultKey_none_returnsCorrectValue() {
|
||||||
Settings.Global.putInt(mResolver, Global.AUTOMATIC_POWER_SAVER_MODE,
|
Settings.Global.putInt(mResolver, Global.AUTOMATIC_POWER_SAVE_MODE,
|
||||||
PowerManager.POWER_SAVER_MODE_PERCENTAGE);
|
PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
|
||||||
Settings.Global.putInt(mResolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
|
Settings.Global.putInt(mResolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
|
||||||
assertThat(mController.getDefaultKey())
|
assertThat(mController.getDefaultKey())
|
||||||
.isEqualTo(BatterySaverScheduleRadioButtonsController.KEY_NO_SCHEDULE);
|
.isEqualTo(BatterySaverScheduleRadioButtonsController.KEY_NO_SCHEDULE);
|
||||||
|
@@ -39,16 +39,16 @@ public class BatterySaverScheduleSeekBarControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateSeekBar_routineMode_hasCorrectProperties() {
|
public void updateSeekBar_routineMode_hasCorrectProperties() {
|
||||||
Settings.Global.putInt(mResolver, Global.AUTOMATIC_POWER_SAVER_MODE,
|
Settings.Global.putInt(mResolver, Global.AUTOMATIC_POWER_SAVE_MODE,
|
||||||
PowerManager.POWER_SAVER_MODE_DYNAMIC);
|
PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC);
|
||||||
mController.updateSeekBar();
|
mController.updateSeekBar();
|
||||||
assertThat(mController.mSeekBarPreference.isVisible()).isFalse();
|
assertThat(mController.mSeekBarPreference.isVisible()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateSeekBar_percentageMode_hasCorrectProperties() {
|
public void updateSeekBar_percentageMode_hasCorrectProperties() {
|
||||||
Settings.Global.putInt(mResolver, Global.AUTOMATIC_POWER_SAVER_MODE,
|
Settings.Global.putInt(mResolver, Global.AUTOMATIC_POWER_SAVE_MODE,
|
||||||
PowerManager.POWER_SAVER_MODE_PERCENTAGE);
|
PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
|
||||||
Settings.Global.putInt(mResolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 5);
|
Settings.Global.putInt(mResolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 5);
|
||||||
mController.updateSeekBar();
|
mController.updateSeekBar();
|
||||||
assertThat(mController.mSeekBarPreference.isVisible()).isTrue();
|
assertThat(mController.mSeekBarPreference.isVisible()).isTrue();
|
||||||
@@ -56,8 +56,8 @@ public class BatterySaverScheduleSeekBarControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateSeekBar_noneMode_hasCorrectProperties() {
|
public void updateSeekBar_noneMode_hasCorrectProperties() {
|
||||||
Settings.Global.putInt(mResolver, Global.AUTOMATIC_POWER_SAVER_MODE,
|
Settings.Global.putInt(mResolver, Global.AUTOMATIC_POWER_SAVE_MODE,
|
||||||
PowerManager.POWER_SAVER_MODE_PERCENTAGE);
|
PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
|
||||||
Settings.Global.putInt(mResolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
|
Settings.Global.putInt(mResolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
|
||||||
mController.updateSeekBar();
|
mController.updateSeekBar();
|
||||||
assertThat(mController.mSeekBarPreference.isVisible()).isFalse();
|
assertThat(mController.mSeekBarPreference.isVisible()).isFalse();
|
||||||
|
Reference in New Issue
Block a user