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

Commit 95174051 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Do not animate NSSL when in battery saver

Until now, we were only checking if the screen shold turn off on the
DozeMachine. This works but doesn't propagate the always-on state
properly to other parts of SysUI.

It's a better idea to hide the implementation detail under
DozeParameters, which is a singleton that's shared with other parts
of the system.

Test: manual
Test: atest DozeParametersTest
Fixes: 158771494
Change-Id: Ifd43b9b1ea247f4e869505f02d6716400de35091
parent 830f6a36
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -364,9 +364,6 @@ public class DozeMachine {
            Log.i(TAG, "Dropping pulse done because current state is already done: " + mState);
            return mState;
        }
        if (requestedState == State.DOZE_AOD && mBatteryController.isAodPowerSave()) {
            return State.DOZE;
        }
        if (requestedState == State.DOZE_REQUEST_PULSE && !mState.canPulse()) {
            Log.i(TAG, "Dropping pulse request because current state can't pulse: " + mState);
            return mState;
+1 −1
Original line number Diff line number Diff line
@@ -382,7 +382,7 @@ class NotificationWakeUpCoordinator @Inject constructor(
    }

    private fun shouldAnimateVisibility() =
            dozeParameters.getAlwaysOn() && !dozeParameters.getDisplayNeedsBlanking()
            dozeParameters.alwaysOn && !dozeParameters.displayNeedsBlanking

    interface WakeUpListener {
        /**
+5 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import com.android.systemui.R;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.doze.AlwaysOnDisplayPolicy;
import com.android.systemui.doze.DozeScreenState;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.tuner.TunerService;

import java.io.PrintWriter;
@@ -52,6 +53,7 @@ public class DozeParameters implements TunerService.Tunable,

    private final AlwaysOnDisplayPolicy mAlwaysOnPolicy;
    private final Resources mResources;
    private final BatteryController mBatteryController;

    private boolean mDozeAlwaysOn;
    private boolean mControlScreenOffAnimation;
@@ -62,10 +64,12 @@ public class DozeParameters implements TunerService.Tunable,
            AmbientDisplayConfiguration ambientDisplayConfiguration,
            AlwaysOnDisplayPolicy alwaysOnDisplayPolicy,
            PowerManager powerManager,
            BatteryController batteryController,
            TunerService tunerService) {
        mResources = resources;
        mAmbientDisplayConfiguration = ambientDisplayConfiguration;
        mAlwaysOnPolicy = alwaysOnDisplayPolicy;
        mBatteryController = batteryController;

        mControlScreenOffAnimation = !getDisplayNeedsBlanking();
        mPowerManager = powerManager;
@@ -164,7 +168,7 @@ public class DozeParameters implements TunerService.Tunable,
     * @return {@code true} if enabled and available.
     */
    public boolean getAlwaysOn() {
        return mDozeAlwaysOn;
        return mDozeAlwaysOn && !mBatteryController.isAodPowerSave();
    }

    /**
+28 −3
Original line number Diff line number Diff line
@@ -16,13 +16,18 @@

package com.android.systemui.statusbar.phone;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.res.Resources;
import android.hardware.display.AmbientDisplayConfiguration;
import android.os.PowerManager;
import android.provider.Settings;
import android.test.suitebuilder.annotation.SmallTest;

import androidx.test.runner.AndroidJUnit4;
@@ -30,6 +35,7 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.doze.AlwaysOnDisplayPolicy;
import com.android.systemui.doze.DozeScreenState;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.tuner.TunerService;

import org.junit.Assert;
@@ -50,6 +56,7 @@ public class DozeParametersTest extends SysuiTestCase {
    @Mock private AlwaysOnDisplayPolicy mAlwaysOnDisplayPolicy;
    @Mock private PowerManager mPowerManager;
    @Mock private TunerService mTunerService;
    @Mock private BatteryController mBatteryController;

    @Before
    public void setup() {
@@ -59,11 +66,12 @@ public class DozeParametersTest extends SysuiTestCase {
            mAmbientDisplayConfiguration,
            mAlwaysOnDisplayPolicy,
            mPowerManager,
            mBatteryController,
            mTunerService
        );
    }
    @Test
    public void test_setControlScreenOffAnimation_setsDozeAfterScreenOff_false() {
    public void testSetControlScreenOffAnimation_setsDozeAfterScreenOff_false() {
        mDozeParameters.setControlScreenOffAnimation(true);
        reset(mPowerManager);
        mDozeParameters.setControlScreenOffAnimation(false);
@@ -71,7 +79,7 @@ public class DozeParametersTest extends SysuiTestCase {
    }

    @Test
    public void test_setControlScreenOffAnimation_setsDozeAfterScreenOff_true() {
    public void testSetControlScreenOffAnimation_setsDozeAfterScreenOff_true() {
        mDozeParameters.setControlScreenOffAnimation(false);
        reset(mPowerManager);
        mDozeParameters.setControlScreenOffAnimation(true);
@@ -79,11 +87,28 @@ public class DozeParametersTest extends SysuiTestCase {
    }

    @Test
    public void test_getWallpaperAodDuration_when_shouldControlScreenOff() {
    public void testGetWallpaperAodDuration_when_shouldControlScreenOff() {
        mDozeParameters.setControlScreenOffAnimation(true);
        Assert.assertEquals(
                "wallpaper hides faster when controlling screen off",
                mDozeParameters.getWallpaperAodDuration(),
                DozeScreenState.ENTER_DOZE_HIDE_WALLPAPER_DELAY);
    }

    @Test
    public void testGetAlwaysOn() {
        when(mAmbientDisplayConfiguration.alwaysOnEnabled(anyInt())).thenReturn(true);
        mDozeParameters.onTuningChanged(Settings.Secure.DOZE_ALWAYS_ON, "1");

        assertThat(mDozeParameters.getAlwaysOn()).isTrue();
    }

    @Test
    public void testGetAlwaysOn_whenBatterySaver() {
        when(mBatteryController.isAodPowerSave()).thenReturn(true);
        when(mAmbientDisplayConfiguration.alwaysOnEnabled(anyInt())).thenReturn(true);
        mDozeParameters.onTuningChanged(Settings.Secure.DOZE_ALWAYS_ON, "1");

        assertThat(mDozeParameters.getAlwaysOn()).isFalse();
    }
}