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

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

Clamp display brightness in AOD

AOD display brightness should respect user settings, otherwise screen can
get brighter after pressing the power button.

Test: manual
Test: runstest -x packages/SystemUI/tests/src/com/android/systemui/doze/DozeScreenBrightnessTest.java
Change-Id: I4f43202fe5c8e844655ec533d46d2d472502a33e
Fixes: 111080388
parent 3e2d62bd
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Handler;
import android.os.Trace;
import android.os.UserHandle;
import android.provider.Settings;

import com.android.internal.annotations.VisibleForTesting;

@@ -111,7 +113,7 @@ public class DozeScreenBrightness implements DozeMachine.Part, SensorEventListen
            int brightness = computeBrightness(mLastSensorValue);
            boolean brightnessReady = brightness > 0;
            if (brightnessReady) {
                mDozeService.setDozeScreenBrightness(brightness);
                mDozeService.setDozeScreenBrightness(clampToUserSetting(brightness));
            }

            int scrimOpacity = -1;
@@ -150,10 +152,17 @@ public class DozeScreenBrightness implements DozeMachine.Part, SensorEventListen
    }

    private void resetBrightnessToDefault() {
        mDozeService.setDozeScreenBrightness(mDefaultDozeBrightness);
        mDozeService.setDozeScreenBrightness(clampToUserSetting(mDefaultDozeBrightness));
        mDozeHost.setAodDimmingScrim(0f);
    }

    private int clampToUserSetting(int brightness) {
        int userSetting = Settings.System.getIntForUser(mContext.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS, Integer.MAX_VALUE,
                UserHandle.USER_CURRENT);
        return Math.min(brightness, userSetting);
    }

    private void setLightSensorEnabled(boolean enabled) {
        if (enabled && !mRegistered && mLightSensor != null) {
            // Wait until we get an event from the sensor until indicating ready.
+16 −0
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import android.os.PowerManager;
import android.os.UserHandle;
import android.provider.Settings;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;

@@ -60,6 +62,9 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {

    @Before
    public void setUp() throws Exception {
        Settings.System.putIntForUser(mContext.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS, DEFAULT_BRIGHTNESS,
                UserHandle.USER_CURRENT);
        mServiceFake = new DozeServiceFake();
        mHostFake = new DozeHostFake();
        mSensorManager = new FakeSensorManager(mContext);
@@ -87,6 +92,17 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {
        assertEquals(3, mServiceFake.screenBrightness);
    }

    @Test
    public void testAod_usesLightSensorRespectingUserSetting() throws Exception {
        int maxBrightness = 3;
        Settings.System.putIntForUser(mContext.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS, maxBrightness,
                UserHandle.USER_CURRENT);

        mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
        assertEquals(maxBrightness, mServiceFake.screenBrightness);
    }

    @Test
    public void testPausingAod_doesntPauseLightSensor() throws Exception {
        mScreen.transitionTo(UNINITIALIZED, INITIALIZED);