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

Commit d96179e0 authored by John Spurlock's avatar John Spurlock
Browse files

Don't do ambient display when in power-conservation mode.

Finish SystemUI's doze dream early when we enter saver mode.

Bug:17164834
Change-Id: I79153be34da8c4b6447acf5dc9f93364906b2bab
parent 0df01172
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ public class DozeService extends DreamService {
    private PendingIntent mNotificationPulseIntent;
    private int mMultipulseCount;
    private int mNotificationPulseInterval;
    private boolean mPowerSaveActive;

    public DozeService() {
        if (DEBUG) Log.d(mTag, "new DozeService()");
@@ -94,6 +95,7 @@ public class DozeService extends DreamService {
        pw.print("  mNotificationLightOn: "); pw.println(mNotificationLightOn);
        pw.print("  mMultipulseCount: "); pw.println(mMultipulseCount);
        pw.print("  mNotificationPulseInterval: "); pw.println(mNotificationPulseInterval);
        pw.print("  mPowerSaveActive: "); pw.println(mPowerSaveActive);
    }

    @Override
@@ -141,7 +143,13 @@ public class DozeService extends DreamService {
    @Override
    public void onDreamingStarted() {
        super.onDreamingStarted();
        if (DEBUG) Log.d(mTag, "onDreamingStarted canDoze=" + canDoze());
        mPowerSaveActive = mHost != null && mHost.isPowerSaveActive();
        if (DEBUG) Log.d(mTag, "onDreamingStarted canDoze=" + canDoze() + " mPowerSaveActive="
                + mPowerSaveActive);
        if (mPowerSaveActive) {
            finishToSavePower();
            return;
        }
        mDreaming = true;
        listenForPulseSignals(true);
        requestDoze();
@@ -232,6 +240,11 @@ public class DozeService extends DreamService {
        }
    }

    private void finishToSavePower() {
        Log.w(mTag, "Exiting ambient mode due to low power battery saver");
        finish();
    }

    private void listenForPulseSignals(boolean listen) {
        if (DEBUG) Log.d(mTag, "listenForPulseSignals: " + listen);
        mSigMotionSensor.setListening(listen);
@@ -329,6 +342,14 @@ public class DozeService extends DreamService {
            mNotificationLightOn = on;
            rescheduleNotificationPulse();
        }

        @Override
        public void onPowerSaveChanged(boolean active) {
            mPowerSaveActive = active;
            if (mPowerSaveActive && mDreaming) {
                finishToSavePower();
            }
        }
    };

    public interface Host {
@@ -337,11 +358,13 @@ public class DozeService extends DreamService {
        void requestDoze(DozeService dozeService);
        void requestPulse(int pulses, boolean delayed, DozeService dozeService);
        void dozingStopped(DozeService dozeService);
        boolean isPowerSaveActive();

        public interface Callback {
            void onNewNotifications();
            void onBuzzBeepBlinked();
            void onNotificationLight(boolean on);
            void onPowerSaveChanged(boolean active);
        }
    }

+14 −0
Original line number Diff line number Diff line
@@ -752,6 +752,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
            @Override
            public void onPowerSaveChanged() {
                mHandler.post(mCheckBarModes);
                if (mDozeServiceHost != null) {
                    mDozeServiceHost.firePowerSaveChanged(mBatteryController.isPowerSave());
                }
            }
            @Override
            public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
@@ -3920,6 +3923,12 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,

        private DozeService mCurrentDozeService;

        public void firePowerSaveChanged(boolean active) {
            for (Callback callback : mCallbacks) {
                callback.onPowerSaveChanged(active);
            }
        }

        public void fireBuzzBeepBlinked() {
            for (Callback callback : mCallbacks) {
                callback.onBuzzBeepBlinked();
@@ -3970,6 +3979,11 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
            mHandler.obtainMessage(H.DOZING_STOPPED, dozeService).sendToTarget();
        }

        @Override
        public boolean isPowerSaveActive() {
            return mBatteryController != null && mBatteryController.isPowerSave();
        }

        private void handleRequestDoze(DozeService dozeService) {
            mCurrentDozeService = dozeService;
            if (!mDozing) {