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

Commit e654d58d authored by Rupesh Bansal's avatar Rupesh Bansal
Browse files

Cleanup offload controls doze autobrightness flag

Bug: 327392714
Flag: EXEMPT flag deletion
Test: EXEMPT flag deletion
Change-Id: Ie4da0790a84419770f7c831b5c6ec057e7796bc2
parent 7fd1b808
Loading
Loading
Loading
Loading
+5 −13
Original line number Diff line number Diff line
@@ -333,7 +333,7 @@ public class AutomaticBrightnessController {
            int ambientLightHorizonLong, float userLux, float userNits,
            DisplayManagerFlags displayManagerFlags) {
        mInjector = injector;
        mClock = injector.createClock(displayManagerFlags.offloadControlsDozeAutoBrightness());
        mClock = injector.createClock();
        mContext = context;
        mCallbacks = callbacks;
        mSensorManager = sensorManager;
@@ -1402,8 +1402,7 @@ public class AutomaticBrightnessController {
        public void onSensorChanged(SensorEvent event) {
            if (mLightSensorEnabled) {
                // The time received from the sensor is in nano seconds, hence changing it to ms
                final long time = (mDisplayManagerFlags.offloadControlsDozeAutoBrightness())
                        ? TimeUnit.NANOSECONDS.toMillis(event.timestamp) : mClock.uptimeMillis();
                final long time = TimeUnit.NANOSECONDS.toMillis(event.timestamp);
                final float lux = event.values[0];
                handleLightSensorEvent(time, lux);
            }
@@ -1616,20 +1615,13 @@ public class AutomaticBrightnessController {
    }

    private static class RealClock implements Clock {
        private final boolean mOffloadControlsDozeBrightness;

        RealClock(boolean offloadControlsDozeBrightness) {
            mOffloadControlsDozeBrightness = offloadControlsDozeBrightness;
        }

        @Override
        public long uptimeMillis() {
            return SystemClock.uptimeMillis();
        }

        public long getSensorEventScaleTime() {
            return (mOffloadControlsDozeBrightness)
                    ? SystemClock.elapsedRealtime() : uptimeMillis();
            return SystemClock.elapsedRealtime();
        }
    }

@@ -1638,8 +1630,8 @@ public class AutomaticBrightnessController {
            return BackgroundThread.getHandler();
        }

        Clock createClock(boolean offloadControlsDozeBrightness) {
            return new RealClock(offloadControlsDozeBrightness);
        Clock createClock() {
            return new RealClock();
        }
    }
}
+1 −2
Original line number Diff line number Diff line
@@ -291,8 +291,7 @@ public class DisplayBrightnessStrategySelector {
    void setAllowAutoBrightnessWhileDozing(
            DisplayManagerInternal.DisplayOffloadSession displayOffloadSession) {
        mAllowAutoBrightnessWhileDozing = mAllowAutoBrightnessWhileDozingConfig;
        if (mDisplayManagerFlags.offloadControlsDozeAutoBrightness()
                && mDisplayManagerFlags.isDisplayOffloadEnabled()
        if (mDisplayManagerFlags.isDisplayOffloadEnabled()
                && displayOffloadSession != null) {
            mAllowAutoBrightnessWhileDozing &= displayOffloadSession.allowAutoBrightnessInDoze();
        }
+0 −13
Original line number Diff line number Diff line
@@ -156,11 +156,6 @@ public class DisplayManagerFlags {
            Flags.FLAG_DOZE_BRIGHTNESS_FLOAT,
            Flags::dozeBrightnessFloat);

    private final FlagState mOffloadControlsDozeAutoBrightness = new FlagState(
            Flags.FLAG_OFFLOAD_CONTROLS_DOZE_AUTO_BRIGHTNESS,
            Flags::offloadControlsDozeAutoBrightness
    );

    private final FlagState mPeakRefreshRatePhysicalLimit = new FlagState(
            Flags.FLAG_ENABLE_PEAK_REFRESH_RATE_PHYSICAL_LIMIT,
            Flags::enablePeakRefreshRatePhysicalLimit
@@ -440,13 +435,6 @@ public class DisplayManagerFlags {
        return mDozeBrightnessFloat.isEnabled();
    }

    /**
     * @return Whether DisplayOffload should control auto-brightness in doze
     */
    public boolean offloadControlsDozeAutoBrightness() {
        return mOffloadControlsDozeAutoBrightness.isEnabled();
    }

    public boolean isPeakRefreshRatePhysicalLimitEnabled() {
        return mPeakRefreshRatePhysicalLimit.isEnabled();
    }
@@ -647,7 +635,6 @@ public class DisplayManagerFlags {
        pw.println(" " + mResolutionBackupRestore);
        pw.println(" " + mUseFusionProxSensor);
        pw.println(" " + mDozeBrightnessFloat);
        pw.println(" " + mOffloadControlsDozeAutoBrightness);
        pw.println(" " + mPeakRefreshRatePhysicalLimit);
        pw.println(" " + mIgnoreAppPreferredRefreshRate);
        pw.println(" " + mSynthetic60hzModes);
+0 −11
Original line number Diff line number Diff line
@@ -254,17 +254,6 @@ flag {
    is_fixed_read_only: true
}

flag {
    name: "offload_controls_doze_auto_brightness"
    namespace: "display_manager"
    description: "Allows the registered DisplayOffloader to control if auto-brightness is used in doze"
    bug: "327392714"
    is_fixed_read_only: true
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "enable_peak_refresh_rate_physical_limit"
    namespace: "display_manager"
+70 −37
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ public class AutomaticBrightnessControllerTest {
                    }

                    @Override
                    AutomaticBrightnessController.Clock createClock(boolean isEnabled) {
                    AutomaticBrightnessController.Clock createClock() {
                        return new AutomaticBrightnessController.Clock() {
                            @Override
                            public long uptimeMillis() {
@@ -618,39 +618,46 @@ public class AutomaticBrightnessControllerTest {
        long increment = 500;
        // set autobrightness to low
        // t = 0
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 0));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 0,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));

        // t = 500
        mClock.fastForward(increment);
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 0));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 0,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));

        // t = 1000
        mClock.fastForward(increment);
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 0));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 0,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertEquals(0.0f, mController.getAmbientLux(), EPSILON);

        // t = 1500
        mClock.fastForward(increment);
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 0));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 0,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertEquals(0.0f, mController.getAmbientLux(), EPSILON);

        // t = 2000
        // ensure that our reading is at 0.
        mClock.fastForward(increment);
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 0));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 0,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertEquals(0.0f, mController.getAmbientLux(), EPSILON);

        // t = 2500
        // first 10000 lux sensor event reading
        mClock.fastForward(increment);
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 10000));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 10000,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertTrue(mController.getAmbientLux() > 0.0f);
        assertTrue(mController.getAmbientLux() < 10000.0f);

        // t = 3000
        // lux reading should still not yet be 10000.
        mClock.fastForward(increment);
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 10000));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 10000,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertTrue(mController.getAmbientLux() > 0.0f);
        assertTrue(mController.getAmbientLux() < 10000.0f);

@@ -659,45 +666,53 @@ public class AutomaticBrightnessControllerTest {
        // lux has been high (10000) for 1000ms.
        // lux reading should be 10000
        // short horizon (ambient lux) is high, long horizon is still not high
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 10000));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 10000,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertEquals(10000.0f, mController.getAmbientLux(), EPSILON);

        // t = 4000
        // stay high
        mClock.fastForward(increment);
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 10000));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 10000,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertEquals(10000.0f, mController.getAmbientLux(), EPSILON);

        // t = 4500
        Mockito.clearInvocations(mBrightnessMappingStrategy);
        mClock.fastForward(increment);
        // short horizon is high, long horizon is high too
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 10000));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 10000,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        verify(mBrightnessMappingStrategy, times(1)).getBrightness(10000, null, -1);
        assertEquals(10000.0f, mController.getAmbientLux(), EPSILON);

        // t = 5000
        mClock.fastForward(increment);
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 0));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 0,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertTrue(mController.getAmbientLux() > 0.0f);
        assertTrue(mController.getAmbientLux() < 10000.0f);

        // t = 5500
        mClock.fastForward(increment);
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 0));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 0,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertTrue(mController.getAmbientLux() > 0.0f);
        assertTrue(mController.getAmbientLux() < 10000.0f);

        // t = 6000
        mClock.fastForward(increment);
        // ambient lux goes to 0
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 0));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 0,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertEquals(0.0f, mController.getAmbientLux(), EPSILON);

        // only the values within the horizon should be kept
        assertArrayEquals(new float[] {10000, 10000, 0, 0, 0}, mController.getLastSensorValues(),
                EPSILON);
        assertArrayEquals(new long[] {4000, 4500, 5000, 5500, 6000},
        assertArrayEquals(new long[]{4000 + ANDROID_SLEEP_TIME, 4500 + ANDROID_SLEEP_TIME,
                5000 + ANDROID_SLEEP_TIME, 5500 + ANDROID_SLEEP_TIME,
                6000 + ANDROID_SLEEP_TIME},
                mController.getLastSensorTimestamps());
    }

@@ -793,7 +808,8 @@ public class AutomaticBrightnessControllerTest {
        for (int i = 0; i < 1000; i++) {
            lux += increment;
            mClock.fastForward(increment);
            listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, lux));
            listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, lux,
                    (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        }

        int valuesCount = (int) Math.ceil((double) AMBIENT_LIGHT_HORIZON_LONG / increment + 1);
@@ -807,17 +823,17 @@ public class AutomaticBrightnessControllerTest {
        long sensorTimestamp = mClock.now();
        for (int i = valuesCount - 1; i >= 1; i--) {
            assertEquals(lux, sensorValues[i], EPSILON);
            assertEquals(sensorTimestamp, sensorTimestamps[i]);
            assertEquals(sensorTimestamp + ANDROID_SLEEP_TIME, sensorTimestamps[i]);
            lux -= increment;
            sensorTimestamp -= increment;
        }
        assertEquals(lux, sensorValues[0], EPSILON);
        assertEquals(mClock.now() - AMBIENT_LIGHT_HORIZON_LONG, sensorTimestamps[0]);
        assertEquals(mClock.now() - AMBIENT_LIGHT_HORIZON_LONG + ANDROID_SLEEP_TIME,
                sensorTimestamps[0]);
    }

    @Test
    public void testAmbientLuxBuffers_prunedBeyondLongHorizonExceptLatestValue() throws Exception {
        when(mDisplayManagerFlags.offloadControlsDozeAutoBrightness()).thenReturn(true);
        ArgumentCaptor<SensorEventListener> listenerCaptor =
                ArgumentCaptor.forClass(SensorEventListener.class);
        verify(mSensorManager).registerListener(listenerCaptor.capture(), eq(mLightSensor),
@@ -867,7 +883,8 @@ public class AutomaticBrightnessControllerTest {
        for (int i = 0; i < 20; i++) {
            lux += increment1;
            mClock.fastForward(increment1);
            listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, lux));
            listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, lux,
                    (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        }

        int valuesCount = (int) Math.ceil((double) AMBIENT_LIGHT_HORIZON_LONG / increment1 + 1);
@@ -877,7 +894,8 @@ public class AutomaticBrightnessControllerTest {
        for (int i = 0; i < initialCapacity - valuesCount; i++) {
            lux += increment2;
            mClock.fastForward(increment2);
            listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, lux));
            listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, lux,
                    (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        }

        float[] sensorValues = mController.getLastSensorValues();
@@ -890,7 +908,7 @@ public class AutomaticBrightnessControllerTest {
        long sensorTimestamp = mClock.now();
        for (int i = initialCapacity - 1; i >= 1; i--) {
            assertEquals(lux, sensorValues[i], EPSILON);
            assertEquals(sensorTimestamp, sensorTimestamps[i]);
            assertEquals(sensorTimestamp + ANDROID_SLEEP_TIME, sensorTimestamps[i]);

            if (i >= valuesCount) {
                lux -= increment2;
@@ -901,7 +919,8 @@ public class AutomaticBrightnessControllerTest {
            }
        }
        assertEquals(lux, sensorValues[0], EPSILON);
        assertEquals(mClock.now() - AMBIENT_LIGHT_HORIZON_LONG, sensorTimestamps[0]);
        assertEquals(mClock.now() - AMBIENT_LIGHT_HORIZON_LONG + ANDROID_SLEEP_TIME,
                sensorTimestamps[0]);
    }

    @Test
@@ -951,25 +970,29 @@ public class AutomaticBrightnessControllerTest {

        // t = 0
        // Initial lux
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 500));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 500,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertEquals(500, mController.getAmbientLux(), EPSILON);

        // t = 1000
        // Lux isn't steady yet
        mClock.fastForward(1000);
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1200));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1200,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertEquals(500, mController.getAmbientLux(), EPSILON);

        // t = 1500
        // Lux isn't steady yet
        mClock.fastForward(500);
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1200));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1200,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertEquals(500, mController.getAmbientLux(), EPSILON);

        // t = 2500
        // Lux is steady now
        mClock.fastForward(1000);
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1200));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1200,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertEquals(1200, mController.getAmbientLux(), EPSILON);
    }

@@ -992,25 +1015,29 @@ public class AutomaticBrightnessControllerTest {

        // t = 0
        // Initial lux
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1200));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1200,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertEquals(1200, mController.getAmbientLux(), EPSILON);

        // t = 2000
        // Lux isn't steady yet
        mClock.fastForward(2000);
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 500));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 500,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertEquals(1200, mController.getAmbientLux(), EPSILON);

        // t = 2500
        // Lux isn't steady yet
        mClock.fastForward(500);
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 500));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 500,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertEquals(1200, mController.getAmbientLux(), EPSILON);

        // t = 4500
        // Lux is steady now
        mClock.fastForward(2000);
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 500));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 500,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertEquals(500, mController.getAmbientLux(), EPSILON);
    }

@@ -1031,19 +1058,22 @@ public class AutomaticBrightnessControllerTest {

        // t = 0
        // Initial lux
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 500));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 500,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertEquals(500, mController.getAmbientLux(), EPSILON);

        // t = 500
        // Lux isn't steady yet
        mClock.fastForward(500);
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1200));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1200,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertEquals(500, mController.getAmbientLux(), EPSILON);

        // t = 1500
        // Lux is steady now
        mClock.fastForward(1000);
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1200));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1200,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertEquals(1200, mController.getAmbientLux(), EPSILON);
    }

@@ -1068,19 +1098,22 @@ public class AutomaticBrightnessControllerTest {

        // t = 0
        // Initial lux
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1200));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1200,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertEquals(1200, mController.getAmbientLux(), EPSILON);

        // t = 1000
        // Lux isn't steady yet
        mClock.fastForward(1000);
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 500));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 500,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertEquals(1200, mController.getAmbientLux(), EPSILON);

        // t = 2500
        // Lux is steady now
        mClock.fastForward(1500);
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 500));
        listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 500,
                (mClock.now() + ANDROID_SLEEP_TIME) * NANO_SECONDS_MULTIPLIER));
        assertEquals(500, mController.getAmbientLux(), EPSILON);
    }

Loading