summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Salvador Martinez <dehboxturtle@google.com> 2018-12-13 15:20:42 -0800
committer Salvador Martinez <dehboxturtle@google.com> 2018-12-14 15:14:33 -0800
commit8adf58b66acadebb6ef409fa3bfeb7056ba3ced6 (patch)
treebf34a717132109daaedd6e43d2627594b065a990
parent93f07e207ab3534251c851dbfbfe242a5c72a0d6 (diff)
Add util for reverting schedule mode
This is needed for keeping people in a good state in case they uninstall the app that provides the signal for routine automatic battery saver mode Test: in sibling CL Bug: 111450127 Change-Id: I0ecc59cc8b8275be1f1211207ad523f45b86175e
-rw-r--r--core/res/res/values/config.xml4
-rw-r--r--core/res/res/values/symbols.xml1
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatterySaverUtils.java19
3 files changed, 24 insertions, 0 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 97a21a55f67f..98b206940687 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -1165,6 +1165,10 @@
<!-- The default suggested battery % at which we enable battery saver automatically. -->
<integer name="config_lowBatteryAutoTriggerDefaultLevel">15</integer>
+ <!-- The app which will handle routine based automatic battery saver, if empty the UI for
+ routine based battery saver will be hidden -->
+ <string name="config_batterySaverScheduleProvider"></string>
+
<!-- Close low battery warning when battery level reaches the lowBatteryWarningLevel
plus this -->
<integer name="config_lowBatteryCloseWarningBump">5</integer>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 161e41681486..4cf019023b0e 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -3459,6 +3459,7 @@
<java-symbol type="integer" name="config_lowBatteryAutoTriggerDefaultLevel" />
<java-symbol type="bool" name="config_batterySaverStickyBehaviourDisabled" />
<java-symbol type="integer" name="config_dynamicPowerSavingsDefaultDisableThreshold" />
+ <java-symbol type="string" name="config_batterySaverScheduleProvider" />
<!-- For car devices -->
<java-symbol type="string" name="car_loading_profile" />
diff --git a/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatterySaverUtils.java b/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatterySaverUtils.java
index f7b16f8b18db..c8c05a0f0bb6 100644
--- a/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatterySaverUtils.java
+++ b/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatterySaverUtils.java
@@ -22,6 +22,7 @@ import android.content.Intent;
import android.os.PowerManager;
import android.provider.Settings.Global;
import android.provider.Settings.Secure;
+import android.text.TextUtils;
import android.util.KeyValueListParser;
import android.util.Log;
import android.util.Slog;
@@ -176,4 +177,22 @@ public class BatterySaverUtils {
setAutoBatterySaverTriggerLevel(context, level);
}
}
+
+ /**
+ * Reverts battery saver schedule mode to none if we are in a bad state where routine mode
+ * is selected but no app is configured to actually provide the signal.
+ * @param context a valid context
+ */
+ public static void revertScheduleToNoneIfNeeded(Context context) {
+ ContentResolver resolver = context.getContentResolver();
+ final int currentMode = Global.getInt(resolver, Global.AUTOMATIC_POWER_SAVER_MODE,
+ PowerManager.POWER_SAVER_MODE_PERCENTAGE);
+ boolean providerConfigured = !TextUtils.isEmpty(context.getString(
+ com.android.internal.R.string.config_batterySaverScheduleProvider));
+ if (currentMode == PowerManager.POWER_SAVER_MODE_DYNAMIC && !providerConfigured) {
+ Global.putInt(resolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
+ Global.putInt(resolver, Global.AUTOMATIC_POWER_SAVER_MODE,
+ PowerManager.POWER_SAVER_MODE_PERCENTAGE);
+ }
+ }
}