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

Commit 8adf58b6 authored by Salvador Martinez's avatar Salvador Martinez
Browse files

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
parent 93f07e20
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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>
+1 −0
Original line number Diff line number Diff line
@@ -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" />
+19 −0
Original line number Diff line number Diff line
@@ -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);
        }
    }
}