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

Commit 10fb2246 authored by John Spurlock's avatar John Spurlock
Browse files

Disable screensavers if below first battery warning level.

Don't activate on sleep if below the threshold, and quit any currently
running dream when the threshold is reached.

Bug:6999949
Change-Id: I961b350d24ee6f95e502228aaa57312b0ffbadc1
parent 21b53df7
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -204,6 +204,11 @@ public class BatteryService extends Binder {
        return mBatteryLevel;
    }

    // true if battery level is below the first warning threshold
    public final boolean isBatteryLow() {
        return mBatteryPresent && mBatteryLevel <= mLowBatteryWarningLevel;
    }

    void systemReady() {
        // check our power situation now that it is safe to display the shutdown dialog.
        shutdownIfNoPower();
+9 −6
Original line number Diff line number Diff line
@@ -1137,7 +1137,7 @@ public final class PowerManagerService extends IPowerManager.Stub
     */
    private void updateDreamLocked(int dirty) {
        if ((dirty & (DIRTY_WAKEFULNESS | DIRTY_SETTINGS
                | DIRTY_IS_POWERED | DIRTY_STAY_ON)) != 0) {
                | DIRTY_IS_POWERED | DIRTY_STAY_ON | DIRTY_BATTERY_STATE)) != 0) {
            scheduleSandmanLocked();
        }
    }
@@ -1163,13 +1163,13 @@ public final class PowerManagerService extends IPowerManager.Stub
        boolean startDreaming = false;
        synchronized (mLock) {
            mSandmanScheduled = false;

            boolean canDream = canDreamLocked();
            if (DEBUG_SPEW) {
                Log.d(TAG, "handleSandman: canDream=" + canDreamLocked()
                Log.d(TAG, "handleSandman: canDream=" + canDream
                        + ", mWakefulness=" + wakefulnessToString(mWakefulness));
            }

            if (canDreamLocked() && mWakefulness == WAKEFULNESS_NAPPING) {
            if (canDream && mWakefulness == WAKEFULNESS_NAPPING) {
                startDreaming = true;
            }
        }
@@ -1253,8 +1253,11 @@ public final class PowerManagerService extends IPowerManager.Stub
     * assuming there has been no recent user activity and no wake locks are held.
     */
    private boolean canDreamLocked() {
        return mIsPowered && mDreamsSupportedConfig
                && mDreamsEnabledSetting && mDreamsActivateOnSleepSetting;
        return mIsPowered
                && mDreamsSupportedConfig
                && mDreamsEnabledSetting
                && mDreamsActivateOnSleepSetting
                && !mBatteryService.isBatteryLow();
    }

    /**