Loading core/java/android/provider/Settings.java +8 −0 Original line number Original line Diff line number Diff line Loading @@ -7800,6 +7800,14 @@ public final class Settings { public static final String LOW_POWER_WARNING_ACKNOWLEDGED = public static final String LOW_POWER_WARNING_ACKNOWLEDGED = "low_power_warning_acknowledged"; "low_power_warning_acknowledged"; /** * 0 (default) Auto battery saver suggestion has not been suppressed. 1) it has been * suppressed. * @hide */ public static final String SUPPRESS_AUTO_BATTERY_SAVER_SUGGESTION = "suppress_auto_battery_saver_suggestion"; /** /** * This are the settings to be backed up. * This are the settings to be backed up. * * Loading core/res/res/values/config.xml +3 −0 Original line number Original line Diff line number Diff line Loading @@ -1095,6 +1095,9 @@ <!-- Display low battery warning when battery level dips to this value --> <!-- Display low battery warning when battery level dips to this value --> <integer name="config_lowBatteryWarningLevel">15</integer> <integer name="config_lowBatteryWarningLevel">15</integer> <!-- The default suggested battery % at which we enable battery saver automatically. --> <integer name="config_lowBatteryAutoTriggerDefaultLevel">15</integer> <!-- Close low battery warning when battery level reaches the lowBatteryWarningLevel <!-- Close low battery warning when battery level reaches the lowBatteryWarningLevel plus this --> plus this --> <integer name="config_lowBatteryCloseWarningBump">5</integer> <integer name="config_lowBatteryCloseWarningBump">5</integer> Loading core/res/res/values/symbols.xml +2 −0 Original line number Original line Diff line number Diff line Loading @@ -3315,4 +3315,6 @@ <java-symbol type="string" name="notification_app_name_system" /> <java-symbol type="string" name="notification_app_name_system" /> <java-symbol type="string" name="notification_app_name_settings" /> <java-symbol type="string" name="notification_app_name_settings" /> <java-symbol type="integer" name="config_lowBatteryAutoTriggerDefaultLevel" /> </resources> </resources> core/tests/coretests/src/android/provider/SettingsBackupTest.java +2 −1 Original line number Original line Diff line number Diff line Loading @@ -586,7 +586,8 @@ public class SettingsBackupTest { Settings.Secure.PARENTAL_CONTROL_REDIRECT_URL, Settings.Secure.PARENTAL_CONTROL_REDIRECT_URL, Settings.Secure.BLUETOOTH_ON_WHILE_DRIVING, Settings.Secure.BLUETOOTH_ON_WHILE_DRIVING, Settings.Secure.LOW_POWER_MANUAL_ACTIVATION_COUNT, Settings.Secure.LOW_POWER_MANUAL_ACTIVATION_COUNT, Settings.Secure.LOW_POWER_WARNING_ACKNOWLEDGED); Settings.Secure.LOW_POWER_WARNING_ACKNOWLEDGED, Settings.Secure.SUPPRESS_AUTO_BATTERY_SAVER_SUGGESTION); @Test @Test public void systemSettingsBackedUpOrBlacklisted() { public void systemSettingsBackedUpOrBlacklisted() { Loading packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatterySaverUtils.java +54 −8 Original line number Original line Diff line number Diff line Loading @@ -20,7 +20,9 @@ import android.content.ContentResolver; import android.content.Context; import android.content.Context; import android.content.Intent; import android.content.Intent; import android.os.PowerManager; import android.os.PowerManager; import android.provider.Settings.Global; import android.provider.Settings.Secure; import android.provider.Settings.Secure; import android.support.annotation.VisibleForTesting; import android.util.Log; import android.util.Log; /** /** Loading @@ -34,9 +36,26 @@ public class BatterySaverUtils { private static final boolean DEBUG = false; private static final boolean DEBUG = false; // Broadcast action for SystemUI to show the battery saver confirmation dialog. private static final String SYSUI_PACKAGE = "com.android.systemui"; /** Broadcast action for SystemUI to show the battery saver confirmation dialog. */ public static final String ACTION_SHOW_START_SAVER_CONFIRMATION = "PNW.startSaverConfirmation"; public static final String ACTION_SHOW_START_SAVER_CONFIRMATION = "PNW.startSaverConfirmation"; /** * Broadcast action for SystemUI to show the notification that suggests turning on * automatic battery saver. */ 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; /** /** * Enable / disable battery saver by user request. * Enable / disable battery saver by user request. * - If it's the first time and needFirstTimeWarning, show the first time dialog. * - If it's the first time and needFirstTimeWarning, show the first time dialog. Loading @@ -62,11 +81,17 @@ public class BatterySaverUtils { if (context.getSystemService(PowerManager.class).setPowerSaveMode(enable)) { if (context.getSystemService(PowerManager.class).setPowerSaveMode(enable)) { if (enable) { if (enable) { Secure.putInt(cr, Secure.LOW_POWER_MANUAL_ACTIVATION_COUNT, final int count = Secure.getInt(cr, Secure.LOW_POWER_MANUAL_ACTIVATION_COUNT, 0) + 1); Secure.getInt(cr, Secure.LOW_POWER_MANUAL_ACTIVATION_COUNT, 0) + 1; Secure.putInt(cr, Secure.LOW_POWER_MANUAL_ACTIVATION_COUNT, count); // TODO If enabling, and the count is between 4 and 8 (inclusive), then if ((count >= AUTO_SAVER_SUGGESTION_START_NTH) // show the "battery saver schedule suggestion" notification. && (count <= AUTO_SAVER_SUGGESTION_END_NTH) && Global.getInt(cr, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0) == 0 && Secure.getInt(cr, Secure.SUPPRESS_AUTO_BATTERY_SAVER_SUGGESTION, 0) == 0) { showAutoBatterySaverSuggestion(context); } } } return true; return true; Loading @@ -79,13 +104,34 @@ public class BatterySaverUtils { Secure.LOW_POWER_WARNING_ACKNOWLEDGED, 0) != 0) { Secure.LOW_POWER_WARNING_ACKNOWLEDGED, 0) != 0) { return false; // Already shown. return false; // Already shown. } } final Intent i = new Intent(ACTION_SHOW_START_SAVER_CONFIRMATION); context.sendBroadcast(getSystemUiBroadcast(ACTION_SHOW_START_SAVER_CONFIRMATION)); context.sendBroadcast(i); return true; return true; } } private static void showAutoBatterySaverSuggestion(Context context) { context.sendBroadcast(getSystemUiBroadcast(ACTION_SHOW_AUTO_SAVER_SUGGESTION)); } private static Intent getSystemUiBroadcast(String action) { final Intent i = new Intent(action); i.setFlags(Intent.FLAG_RECEIVER_FOREGROUND); i.setPackage(SYSUI_PACKAGE); return i; } private static void setBatterySaverConfirmationAcknowledged(Context context) { private static void setBatterySaverConfirmationAcknowledged(Context context) { Secure.putInt(context.getContentResolver(), Secure.LOW_POWER_WARNING_ACKNOWLEDGED, 1); Secure.putInt(context.getContentResolver(), Secure.LOW_POWER_WARNING_ACKNOWLEDGED, 1); } } public static void suppressAutoBatterySaver(Context context) { Secure.putInt(context.getContentResolver(), Secure.SUPPRESS_AUTO_BATTERY_SAVER_SUGGESTION, 1); } public static void scheduleAutoBatterySaver(Context context, int level) { if (Global.getInt(context.getContentResolver(), Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0) == 0) { Global.putInt(context.getContentResolver(), Global.LOW_POWER_MODE_TRIGGER_LEVEL, level); } } } } Loading
core/java/android/provider/Settings.java +8 −0 Original line number Original line Diff line number Diff line Loading @@ -7800,6 +7800,14 @@ public final class Settings { public static final String LOW_POWER_WARNING_ACKNOWLEDGED = public static final String LOW_POWER_WARNING_ACKNOWLEDGED = "low_power_warning_acknowledged"; "low_power_warning_acknowledged"; /** * 0 (default) Auto battery saver suggestion has not been suppressed. 1) it has been * suppressed. * @hide */ public static final String SUPPRESS_AUTO_BATTERY_SAVER_SUGGESTION = "suppress_auto_battery_saver_suggestion"; /** /** * This are the settings to be backed up. * This are the settings to be backed up. * * Loading
core/res/res/values/config.xml +3 −0 Original line number Original line Diff line number Diff line Loading @@ -1095,6 +1095,9 @@ <!-- Display low battery warning when battery level dips to this value --> <!-- Display low battery warning when battery level dips to this value --> <integer name="config_lowBatteryWarningLevel">15</integer> <integer name="config_lowBatteryWarningLevel">15</integer> <!-- The default suggested battery % at which we enable battery saver automatically. --> <integer name="config_lowBatteryAutoTriggerDefaultLevel">15</integer> <!-- Close low battery warning when battery level reaches the lowBatteryWarningLevel <!-- Close low battery warning when battery level reaches the lowBatteryWarningLevel plus this --> plus this --> <integer name="config_lowBatteryCloseWarningBump">5</integer> <integer name="config_lowBatteryCloseWarningBump">5</integer> Loading
core/res/res/values/symbols.xml +2 −0 Original line number Original line Diff line number Diff line Loading @@ -3315,4 +3315,6 @@ <java-symbol type="string" name="notification_app_name_system" /> <java-symbol type="string" name="notification_app_name_system" /> <java-symbol type="string" name="notification_app_name_settings" /> <java-symbol type="string" name="notification_app_name_settings" /> <java-symbol type="integer" name="config_lowBatteryAutoTriggerDefaultLevel" /> </resources> </resources>
core/tests/coretests/src/android/provider/SettingsBackupTest.java +2 −1 Original line number Original line Diff line number Diff line Loading @@ -586,7 +586,8 @@ public class SettingsBackupTest { Settings.Secure.PARENTAL_CONTROL_REDIRECT_URL, Settings.Secure.PARENTAL_CONTROL_REDIRECT_URL, Settings.Secure.BLUETOOTH_ON_WHILE_DRIVING, Settings.Secure.BLUETOOTH_ON_WHILE_DRIVING, Settings.Secure.LOW_POWER_MANUAL_ACTIVATION_COUNT, Settings.Secure.LOW_POWER_MANUAL_ACTIVATION_COUNT, Settings.Secure.LOW_POWER_WARNING_ACKNOWLEDGED); Settings.Secure.LOW_POWER_WARNING_ACKNOWLEDGED, Settings.Secure.SUPPRESS_AUTO_BATTERY_SAVER_SUGGESTION); @Test @Test public void systemSettingsBackedUpOrBlacklisted() { public void systemSettingsBackedUpOrBlacklisted() { Loading
packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatterySaverUtils.java +54 −8 Original line number Original line Diff line number Diff line Loading @@ -20,7 +20,9 @@ import android.content.ContentResolver; import android.content.Context; import android.content.Context; import android.content.Intent; import android.content.Intent; import android.os.PowerManager; import android.os.PowerManager; import android.provider.Settings.Global; import android.provider.Settings.Secure; import android.provider.Settings.Secure; import android.support.annotation.VisibleForTesting; import android.util.Log; import android.util.Log; /** /** Loading @@ -34,9 +36,26 @@ public class BatterySaverUtils { private static final boolean DEBUG = false; private static final boolean DEBUG = false; // Broadcast action for SystemUI to show the battery saver confirmation dialog. private static final String SYSUI_PACKAGE = "com.android.systemui"; /** Broadcast action for SystemUI to show the battery saver confirmation dialog. */ public static final String ACTION_SHOW_START_SAVER_CONFIRMATION = "PNW.startSaverConfirmation"; public static final String ACTION_SHOW_START_SAVER_CONFIRMATION = "PNW.startSaverConfirmation"; /** * Broadcast action for SystemUI to show the notification that suggests turning on * automatic battery saver. */ 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; /** /** * Enable / disable battery saver by user request. * Enable / disable battery saver by user request. * - If it's the first time and needFirstTimeWarning, show the first time dialog. * - If it's the first time and needFirstTimeWarning, show the first time dialog. Loading @@ -62,11 +81,17 @@ public class BatterySaverUtils { if (context.getSystemService(PowerManager.class).setPowerSaveMode(enable)) { if (context.getSystemService(PowerManager.class).setPowerSaveMode(enable)) { if (enable) { if (enable) { Secure.putInt(cr, Secure.LOW_POWER_MANUAL_ACTIVATION_COUNT, final int count = Secure.getInt(cr, Secure.LOW_POWER_MANUAL_ACTIVATION_COUNT, 0) + 1); Secure.getInt(cr, Secure.LOW_POWER_MANUAL_ACTIVATION_COUNT, 0) + 1; Secure.putInt(cr, Secure.LOW_POWER_MANUAL_ACTIVATION_COUNT, count); // TODO If enabling, and the count is between 4 and 8 (inclusive), then if ((count >= AUTO_SAVER_SUGGESTION_START_NTH) // show the "battery saver schedule suggestion" notification. && (count <= AUTO_SAVER_SUGGESTION_END_NTH) && Global.getInt(cr, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0) == 0 && Secure.getInt(cr, Secure.SUPPRESS_AUTO_BATTERY_SAVER_SUGGESTION, 0) == 0) { showAutoBatterySaverSuggestion(context); } } } return true; return true; Loading @@ -79,13 +104,34 @@ public class BatterySaverUtils { Secure.LOW_POWER_WARNING_ACKNOWLEDGED, 0) != 0) { Secure.LOW_POWER_WARNING_ACKNOWLEDGED, 0) != 0) { return false; // Already shown. return false; // Already shown. } } final Intent i = new Intent(ACTION_SHOW_START_SAVER_CONFIRMATION); context.sendBroadcast(getSystemUiBroadcast(ACTION_SHOW_START_SAVER_CONFIRMATION)); context.sendBroadcast(i); return true; return true; } } private static void showAutoBatterySaverSuggestion(Context context) { context.sendBroadcast(getSystemUiBroadcast(ACTION_SHOW_AUTO_SAVER_SUGGESTION)); } private static Intent getSystemUiBroadcast(String action) { final Intent i = new Intent(action); i.setFlags(Intent.FLAG_RECEIVER_FOREGROUND); i.setPackage(SYSUI_PACKAGE); return i; } private static void setBatterySaverConfirmationAcknowledged(Context context) { private static void setBatterySaverConfirmationAcknowledged(Context context) { Secure.putInt(context.getContentResolver(), Secure.LOW_POWER_WARNING_ACKNOWLEDGED, 1); Secure.putInt(context.getContentResolver(), Secure.LOW_POWER_WARNING_ACKNOWLEDGED, 1); } } public static void suppressAutoBatterySaver(Context context) { Secure.putInt(context.getContentResolver(), Secure.SUPPRESS_AUTO_BATTERY_SAVER_SUGGESTION, 1); } public static void scheduleAutoBatterySaver(Context context, int level) { if (Global.getInt(context.getContentResolver(), Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0) == 0) { Global.putInt(context.getContentResolver(), Global.LOW_POWER_MODE_TRIGGER_LEVEL, level); } } } }