Merge "Make battery saver suggestion configurable" into pi-dev
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index b7f6cde..b0367dc 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -11061,7 +11061,14 @@
*/
public static final String LOW_POWER_MODE_TRIGGER_LEVEL_MAX = "low_power_trigger_level_max";
- /**
+ /**
+ * See com.android.settingslib.fuelgauge.BatterySaverUtils.
+ * @hide
+ */
+ public static final String LOW_POWER_MODE_SUGGESTION_PARAMS =
+ "low_power_mode_suggestion_params";
+
+ /**
* If not 0, the activity manager will aggressively finish activities and
* processes as soon as they are no longer needed. If 0, the normal
* extended lifetime is used.
diff --git a/core/tests/coretests/src/android/provider/SettingsBackupTest.java b/core/tests/coretests/src/android/provider/SettingsBackupTest.java
index 4b9465d..dfc99f6 100644
--- a/core/tests/coretests/src/android/provider/SettingsBackupTest.java
+++ b/core/tests/coretests/src/android/provider/SettingsBackupTest.java
@@ -267,6 +267,7 @@
Settings.Global.LOW_POWER_MODE,
Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL_MAX,
Settings.Global.LOW_POWER_MODE_STICKY,
+ Settings.Global.LOW_POWER_MODE_SUGGESTION_PARAMS,
Settings.Global.LTE_SERVICE_FORCED,
Settings.Global.MAX_NOTIFICATION_ENQUEUE_RATE,
Settings.Global.MAX_SOUND_TRIGGER_DETECTION_SERVICE_OPS_PER_DAY,
diff --git a/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatterySaverUtils.java b/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatterySaverUtils.java
index 28833a3..835ff07 100644
--- a/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatterySaverUtils.java
+++ b/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatterySaverUtils.java
@@ -22,8 +22,9 @@
import android.os.PowerManager;
import android.provider.Settings.Global;
import android.provider.Settings.Secure;
-import android.support.annotation.VisibleForTesting;
+import android.util.KeyValueListParser;
import android.util.Log;
+import android.util.Slog;
/**
* Utilities related to battery saver.
@@ -48,13 +49,35 @@
public static final String ACTION_SHOW_AUTO_SAVER_SUGGESTION
= "PNW.autoSaverSuggestion";
- /**
- * We show the auto battery saver suggestion notification when the user manually enables
- * battery saver for the START_NTH time through the END_NTH time.
- * (We won't show it for END_NTH + 1 time and after.)
- */
- private static final int AUTO_SAVER_SUGGESTION_START_NTH = 4;
- private static final int AUTO_SAVER_SUGGESTION_END_NTH = 8;
+ private static class Parameters {
+ private final Context mContext;
+
+ /**
+ * We show the auto battery saver suggestion notification when the user manually enables
+ * battery saver for the START_NTH time through the END_NTH time.
+ * (We won't show it for END_NTH + 1 time and after.)
+ */
+ private static final int AUTO_SAVER_SUGGESTION_START_NTH = 4;
+ private static final int AUTO_SAVER_SUGGESTION_END_NTH = 8;
+
+ public final int startNth;
+ public final int endNth;
+
+ public Parameters(Context context) {
+ mContext = context;
+
+ final String newValue = Global.getString(mContext.getContentResolver(),
+ Global.LOW_POWER_MODE_SUGGESTION_PARAMS);
+ final KeyValueListParser parser = new KeyValueListParser(',');
+ try {
+ parser.setString(newValue);
+ } catch (IllegalArgumentException e) {
+ Slog.wtf(TAG, "Bad constants: " + newValue);
+ }
+ startNth = parser.getInt("start_nth", AUTO_SAVER_SUGGESTION_START_NTH);
+ endNth = parser.getInt("end_nth", AUTO_SAVER_SUGGESTION_END_NTH);
+ }
+ }
/**
* Enable / disable battery saver by user request.
@@ -85,8 +108,10 @@
Secure.getInt(cr, Secure.LOW_POWER_MANUAL_ACTIVATION_COUNT, 0) + 1;
Secure.putInt(cr, Secure.LOW_POWER_MANUAL_ACTIVATION_COUNT, count);
- if ((count >= AUTO_SAVER_SUGGESTION_START_NTH)
- && (count <= AUTO_SAVER_SUGGESTION_END_NTH)
+ final Parameters parameters = new Parameters(context);
+
+ if ((count >= parameters.startNth)
+ && (count <= parameters.endNth)
&& Global.getInt(cr, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0) == 0
&& Secure.getInt(cr,
Secure.SUPPRESS_AUTO_BATTERY_SAVER_SUGGESTION, 0) == 0) {