From 418c85f139a966c41b802863d25cf02c500baf98 Mon Sep 17 00:00:00 2001 From: Mill Chen Date: Sat, 30 May 2020 01:31:58 +0800 Subject: [PATCH] Suppress battery saver suggestion notification When users turn on battery saver manually more than 3 times, the "Tap to schedule Battery Saver" notification will suggest users to enable scheduling battery saver. But this notification is still shown if users have already turned on scheduling battery saver, which is caused by no mechanism to suppress this notification. Solution: Adding a mechanism to suppress battery saver suggestion if users scheduled battery saver. Bug: 147862112 Test: robotests Change-Id: I8290d76dac09104e64fb98b8a9f4d783a8177d7c --- ...rySaverScheduleRadioButtonsController.java | 7 ++++- ...verScheduleRadioButtonsControllerTest.java | 30 ++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleRadioButtonsController.java b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleRadioButtonsController.java index 2cf2b6df7e6..737fb0f8d2f 100644 --- a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleRadioButtonsController.java +++ b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleRadioButtonsController.java @@ -22,6 +22,7 @@ import android.os.PowerManager; import android.provider.Settings; import android.provider.Settings.Global; import android.text.TextUtils; + import com.android.settingslib.fuelgauge.BatterySaverUtils; /** @@ -72,7 +73,7 @@ public class BatterySaverScheduleRadioButtonsController { if (key == null) { return false; } - + final ContentResolver resolver = mContext.getContentResolver(); int mode = PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE; int triggerLevel = 0; @@ -112,6 +113,10 @@ public class BatterySaverScheduleRadioButtonsController { if (mode != PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC) { Settings.Global.putInt(resolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, triggerLevel); } + // Suppress battery saver suggestion notification if enabling scheduling battery saver. + if (mode == PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC || triggerLevel != 0) { + BatterySaverUtils.suppressAutoBatterySaver(mContext); + } mSeekBarController.updateSeekBar(); return true; } diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleRadioButtonsControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleRadioButtonsControllerTest.java index 8654a4e5a7b..2919edc406c 100644 --- a/tests/robotests/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleRadioButtonsControllerTest.java +++ b/tests/robotests/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleRadioButtonsControllerTest.java @@ -8,6 +8,7 @@ import android.os.PowerManager; import android.provider.Settings; import android.provider.Settings.Global; import android.provider.Settings.Secure; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -59,9 +60,36 @@ public class BatterySaverScheduleRadioButtonsControllerTest { @Test public void setDefaultKey_any_defaultsToNoScheduleIfWarningNotSeen() { Secure.putString( - mContext.getContentResolver(), Secure.LOW_POWER_WARNING_ACKNOWLEDGED, "null"); + mContext.getContentResolver(), Secure.LOW_POWER_WARNING_ACKNOWLEDGED, "null"); mController.setDefaultKey(BatterySaverScheduleRadioButtonsController.KEY_ROUTINE); assertThat(mController.getDefaultKey()) .isEqualTo(BatterySaverScheduleRadioButtonsController.KEY_NO_SCHEDULE); } + + @Test + public void setDefaultKey_percentage_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_PERCENTAGE); + Settings.Global.putInt(mResolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 5); + mController.setDefaultKey(BatterySaverScheduleRadioButtonsController.KEY_PERCENTAGE); + + final int result = Settings.Secure.getInt(mResolver, + Secure.SUPPRESS_AUTO_BATTERY_SAVER_SUGGESTION, 0); + 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); + } }