Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b243a996 authored by Kweku Adams's avatar Kweku Adams
Browse files

Automatically turning off battery saver at a high percentage.

This introduces a setting that turns off sticky Battery Saver above a
certain threshold and disables Battery Saver if it was enabled due to
the sticky setting.

Bug: 112232746
Test: atest com.android.server.power.batterysaver.BatterySaverStateMachineTest
Test: atest android.provider.SettingsBackupTest
Change-Id: Ib9a9fd627a56529404b41fbabedf8bb4a372074e
parent cdfa6ed8
Loading
Loading
Loading
Loading
+31 −1
Original line number Diff line number Diff line
@@ -12052,6 +12052,31 @@ public final class Settings {
        @TestApi
        public static final String LOW_POWER_MODE_STICKY = "low_power_sticky";
        /**
         * When a device is unplugged from a changer (or is rebooted), do not re-activate battery
         * saver even if {@link #LOW_POWER_MODE_STICKY} is 1, if the battery level is equal to or
         * above this threshold.
         *
         * @hide
         */
        public static final String LOW_POWER_MODE_STICKY_AUTO_DISABLE_LEVEL =
                "low_power_sticky_auto_disable_level";
        private static final Validator LOW_POWER_MODE_STICKY_AUTO_DISABLE_LEVEL_VALIDATOR =
                new SettingsValidators.InclusiveIntegerRangeValidator(0, 100);
        /**
         * Whether sticky battery saver should be deactivated once the battery level has reached the
         * threshold specified by {@link #LOW_POWER_MODE_STICKY_AUTO_DISABLE_LEVEL}.
         *
         * @hide
         */
        public static final String LOW_POWER_MODE_STICKY_AUTO_DISABLE_ENABLED =
                "low_power_sticky_auto_disable_enabled";
        private static final Validator LOW_POWER_MODE_STICKY_AUTO_DISABLE_ENABLED_VALIDATOR =
                new SettingsValidators.DiscreteValueValidator(new String[] {"0", "1"});
        /**
         * Battery level [1-100] at which low power mode automatically turns on.
         * Pre-Q If 0, it will not automatically turn on. Q and newer it will only automatically
@@ -12064,7 +12089,6 @@ public final class Settings {
         */
        public static final String LOW_POWER_MODE_TRIGGER_LEVEL = "low_power_trigger_level";
        private static final Validator LOW_POWER_MODE_TRIGGER_LEVEL_VALIDATOR =
                new SettingsValidators.InclusiveIntegerRangeValidator(0, 100);
@@ -13055,6 +13079,8 @@ public final class Settings {
            ENCODED_SURROUND_OUTPUT,
            ENCODED_SURROUND_OUTPUT_ENABLED_FORMATS,
            LOW_POWER_MODE_TRIGGER_LEVEL,
            LOW_POWER_MODE_STICKY_AUTO_DISABLE_ENABLED,
            LOW_POWER_MODE_STICKY_AUTO_DISABLE_LEVEL,
            BLUETOOTH_ON,
            PRIVATE_DNS_MODE,
            PRIVATE_DNS_SPECIFIER,
@@ -13093,6 +13119,10 @@ public final class Settings {
            VALIDATORS.put(ENCODED_SURROUND_OUTPUT, ENCODED_SURROUND_OUTPUT_VALIDATOR);
            VALIDATORS.put(ENCODED_SURROUND_OUTPUT_ENABLED_FORMATS,
                    ENCODED_SURROUND_OUTPUT_ENABLED_FORMATS_VALIDATOR);
            VALIDATORS.put(LOW_POWER_MODE_STICKY_AUTO_DISABLE_LEVEL,
                    LOW_POWER_MODE_STICKY_AUTO_DISABLE_LEVEL_VALIDATOR);
            VALIDATORS.put(LOW_POWER_MODE_STICKY_AUTO_DISABLE_ENABLED,
                    LOW_POWER_MODE_STICKY_AUTO_DISABLE_ENABLED_VALIDATOR);
            VALIDATORS.put(LOW_POWER_MODE_TRIGGER_LEVEL, LOW_POWER_MODE_TRIGGER_LEVEL_VALIDATOR);
            VALIDATORS.put(LOW_POWER_MODE_TRIGGER_LEVEL_MAX,
                    LOW_POWER_MODE_TRIGGER_LEVEL_VALIDATOR);
+10 −0
Original line number Diff line number Diff line
@@ -528,6 +528,16 @@ message GlobalSettingsProto {
        // Whether automatic battery saver mode is controlled via percentage,
        // {@link #DYNAMIC_POWER_SAVINGS_ENABLED} or disabled.
        optional SettingProto automatic_power_saver_mode = 4 [ (android.privacy).dest = DEST_AUTOMATIC];
        // If 1, battery saver (low_power_mode) will be re-activated after the device is
        // unplugged from a charger or rebooted.
        optional SettingProto sticky_enabled = 5;
        // Whether sticky battery saver should be deactivated once the battery level has reached the
        // threshold specified by sticky_disable_level.
        optional SettingProto sticky_auto_disable_enabled = 6;
        // When a device is unplugged from a changer (or is rebooted), do not re-activate battery
        // saver even if {@link #LOW_POWER_MODE_STICKY} is 1, if the battery level is equal to or
        // above this threshold.
        optional SettingProto sticky_auto_disable_level = 7;
    }
    optional LowPowerMode low_power_mode = 70;

+8 −0
Original line number Diff line number Diff line
@@ -350,4 +350,12 @@ message BatterySaverStateMachineProto {
    // The value of Global.LOW_POWER_MODE_TRIGGER_LEVEL. This is a cached value, so it could
    // be slightly different from what's in GlobalSettingsProto.LowPowerMode.
    optional int32 setting_battery_saver_trigger_threshold = 11;

    // The value of Global.LOW_POWER_MODE_STICKY_AUTO_DISABLE_ENABLED. This is a cached value, so
    // it could be slightly different from what's in GlobalSettingsProto.LowPowerMode.
    optional bool setting_battery_saver_sticky_auto_disable_enabled = 12;

    // The value of Global.LOW_POWER_MODE_STICKY_AUTO_DISABLE_LEVEL. This is a cached value, so it
    // could be slightly different from what's in GlobalSettingsProto.LowPowerMode.
    optional int32 setting_battery_saver_sticky_auto_disable_threshold = 13;
}
+15 −7
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.providers.settings;
import android.annotation.NonNull;
import android.os.UserHandle;
import android.provider.Settings;
import android.provider.Settings.Global;
import android.providers.settings.GlobalSettingsProto;
import android.providers.settings.SecureSettingsProto;
import android.providers.settings.SettingProto;
@@ -397,7 +396,7 @@ class SettingsProtoDumpUtil {
        p.end(certPinToken);

        dumpSetting(s, p,
                Global.CHAINED_BATTERY_ATTRIBUTION_ENABLED,
                Settings.Global.CHAINED_BATTERY_ATTRIBUTION_ENABLED,
                GlobalSettingsProto.CHAINED_BATTERY_ATTRIBUTION_ENABLED);
        dumpSetting(s, p,
                Settings.Global.COMPATIBILITY_MODE,
@@ -734,7 +733,7 @@ class SettingsProtoDumpUtil {
                Settings.Global.HEADS_UP_NOTIFICATIONS_ENABLED,
                GlobalSettingsProto.HEADS_UP_NOTIFICATIONS_ENABLED);
        dumpSetting(s, p,
                Global.HIDDEN_API_BLACKLIST_EXEMPTIONS,
                Settings.Global.HIDDEN_API_BLACKLIST_EXEMPTIONS,
                GlobalSettingsProto.HIDDEN_API_BLACKLIST_EXEMPTIONS);

        final long inetCondToken = p.start(GlobalSettingsProto.INET_CONDITION);
@@ -829,6 +828,15 @@ class SettingsProtoDumpUtil {
        dumpSetting(s, p,
                Settings.Global.AUTOMATIC_POWER_SAVER_MODE,
                GlobalSettingsProto.LowPowerMode.AUTOMATIC_POWER_SAVER_MODE);
        dumpSetting(s, p,
                Settings.Global.LOW_POWER_MODE_STICKY,
                GlobalSettingsProto.LowPowerMode.STICKY_ENABLED);
        dumpSetting(s, p,
                Settings.Global.LOW_POWER_MODE_STICKY_AUTO_DISABLE_ENABLED,
                GlobalSettingsProto.LowPowerMode.STICKY_AUTO_DISABLE_ENABLED);
        dumpSetting(s, p,
                Settings.Global.LOW_POWER_MODE_STICKY_AUTO_DISABLE_LEVEL,
                GlobalSettingsProto.LowPowerMode.STICKY_AUTO_DISABLE_LEVEL);
        p.end(lpmToken);

        dumpSetting(s, p,
@@ -879,7 +887,7 @@ class SettingsProtoDumpUtil {
        p.end(multiSimToken);

        dumpSetting(s, p,
                Global.NATIVE_FLAGS_HEALTH_CHECK_ENABLED,
                Settings.Global.NATIVE_FLAGS_HEALTH_CHECK_ENABLED,
                GlobalSettingsProto.NATIVE_FLAGS_HEALTH_CHECK_ENABLED);

        final long netstatsToken = p.start(GlobalSettingsProto.NETSTATS);
@@ -1259,10 +1267,10 @@ class SettingsProtoDumpUtil {

        final long soundTriggerToken = p.start(GlobalSettingsProto.SOUND_TRIGGER);
        dumpSetting(s, p,
                Global.MAX_SOUND_TRIGGER_DETECTION_SERVICE_OPS_PER_DAY,
                Settings.Global.MAX_SOUND_TRIGGER_DETECTION_SERVICE_OPS_PER_DAY,
                GlobalSettingsProto.SoundTrigger.MAX_SOUND_TRIGGER_DETECTION_SERVICE_OPS_PER_DAY);
        dumpSetting(s, p,
                Global.SOUND_TRIGGER_DETECTION_SERVICE_OP_TIMEOUT,
                Settings.Global.SOUND_TRIGGER_DETECTION_SERVICE_OP_TIMEOUT,
                GlobalSettingsProto.SoundTrigger.DETECTION_SERVICE_OP_TIMEOUT_MS);
        p.end(soundTriggerToken);

@@ -1558,7 +1566,7 @@ class SettingsProtoDumpUtil {
                GlobalSettingsProto.ZRAM_ENABLED);

        dumpSetting(s, p,
                Global.APP_OPS_CONSTANTS,
                Settings.Global.APP_OPS_CONSTANTS,
                GlobalSettingsProto.APP_OPS_CONSTANTS);

        p.end(token);
+1 −0
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ public class BatterySaverController implements BatterySaverPolicyListener {
    public static final int REASON_SETTING_CHANGED = 8;
    public static final int REASON_DYNAMIC_POWER_SAVINGS_AUTOMATIC_ON = 9;
    public static final int REASON_DYNAMIC_POWER_SAVINGS_AUTOMATIC_OFF = 10;
    public static final int REASON_STICKY_RESTORE_OFF = 13;

    /**
     * Plugin interface. All methods are guaranteed to be called on the same (handler) thread.
Loading