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

Commit ff67ed10 authored by Piotr Wilczyński's avatar Piotr Wilczyński Committed by Android (Google) Code Review
Browse files

Merge "Dump last n brightness short-term models" into main

parents 3997f56a 9c598fd2
Loading
Loading
Loading
Loading
+36 −7
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.content.res.TypedArray;
import android.hardware.display.BrightnessConfiguration;
import android.hardware.display.BrightnessCorrection;
import android.os.PowerManager;
import android.util.LongArray;
import android.util.MathUtils;
import android.util.Pair;
import android.util.Slog;
@@ -37,7 +38,11 @@ import com.android.server.display.utils.Plog;
import com.android.server.display.whitebalance.DisplayWhiteBalanceController;

import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Objects;

@@ -840,6 +845,13 @@ public abstract class BrightnessMappingStrategy {
        private final boolean mIsForIdleMode;
        private final DisplayWhiteBalanceController mDisplayWhiteBalanceController;

        // Previous short-term models and the times that they were computed stored for debugging
        // purposes
        private List<Spline> mPreviousBrightnessSplines = new ArrayList<>();
        private LongArray mBrightnessSplineChangeTimes = new LongArray();
        private static final int NO_OF_PREVIOUS_CONFIGS_TO_LOG = 5;
        private static final SimpleDateFormat FORMAT = new SimpleDateFormat("MM-dd HH:mm:ss.SSS");

        public PhysicalMappingStrategy(BrightnessConfiguration config, float[] nits,
                float[] brightness, float maxGamma, boolean isForIdleMode,
                DisplayWhiteBalanceController displayWhiteBalanceController) {
@@ -982,6 +994,13 @@ public abstract class BrightnessMappingStrategy {
            mUserLux = lux;
            mUserBrightness = brightness;
            computeSpline();

            if (mPreviousBrightnessSplines.size() == NO_OF_PREVIOUS_CONFIGS_TO_LOG) {
                mPreviousBrightnessSplines.remove(0);
                mBrightnessSplineChangeTimes.remove(0);
            }
            mPreviousBrightnessSplines.add(mBrightnessSpline);
            mBrightnessSplineChangeTimes.add(System.currentTimeMillis());
        }

        @Override
@@ -1042,7 +1061,16 @@ public abstract class BrightnessMappingStrategy {
            pw.println("  mDefaultConfig=" + mDefaultConfig);
            pw.println("  mBrightnessRangeAdjustmentApplied=" + mBrightnessRangeAdjustmentApplied);

            dumpConfigDiff(pw, hbmTransition);
            pw.println("  Previous short-term models (oldest to newest): ");
            for (int i = 0; i < mPreviousBrightnessSplines.size(); i++) {
                pw.println("  Computed at "
                        + FORMAT.format(new Date(mBrightnessSplineChangeTimes.get(i))) + ": ");
                dumpConfigDiff(pw, hbmTransition, mPreviousBrightnessSplines.get(i),
                        /* shortTermModelOnly= */ true);
            }

            pw.println("  Difference between current config and default: ");
            dumpConfigDiff(pw, hbmTransition, mBrightnessSpline, /* shortTermModelOnly= */ false);
        }

        @Override
@@ -1066,9 +1094,8 @@ public abstract class BrightnessMappingStrategy {
         *
         * @param pw The print-writer to write to.
         */
        private void dumpConfigDiff(PrintWriter pw, float hbmTransition) {
            pw.println("  Difference between current config and default: ");

        private void dumpConfigDiff(PrintWriter pw, float hbmTransition, Spline brightnessSpline,
                boolean shortTermModelOnly) {
            Pair<float[], float[]> currentCurve = mConfig.getCurve();
            Spline currSpline = Spline.createSpline(currentCurve.first, currentCurve.second);

@@ -1107,7 +1134,7 @@ public abstract class BrightnessMappingStrategy {

                float defaultNits = defaultSpline.interpolate(lux);
                float longTermNits = currSpline.interpolate(lux);
                float shortTermNits = mBrightnessSpline.interpolate(lux);
                float shortTermNits = brightnessSpline.interpolate(lux);
                float brightness = mAdjustedNitsToBrightnessSpline.interpolate(shortTermNits);

                String luxPrefix = (lux == mUserLux ? "^" : "");
@@ -1142,8 +1169,10 @@ public abstract class BrightnessMappingStrategy {
                // At 80 chars, start another row
                if (sbLux.length() > 80 || (i == luxes.length - 1)) {
                    pw.println(sbLux);
                    if (!shortTermModelOnly) {
                        pw.println(sbNits);
                        pw.println(sbLong);
                    }
                    pw.println(sbShort);
                    pw.println(sbBrightness);
                    pw.println(sbPercent);
+12 −8
Original line number Diff line number Diff line
@@ -267,7 +267,8 @@ public class AutomaticBrightnessControllerTest {
                /* shouldResetShortTermModel= */ true);

        // There should be a user data point added to the mapper.
        verify(mBrightnessMappingStrategy).addUserDataPoint(1000f, 0.5f);
        verify(mBrightnessMappingStrategy).addUserDataPoint(/* lux= */ 1000f,
                /* brightness= */ 0.5f);
    }

    @Test
@@ -295,7 +296,8 @@ public class AutomaticBrightnessControllerTest {
        mController.recalculateSplines(true, adjustments);
        verify(mBrightnessMappingStrategy).clearUserDataPoints();
        verify(mBrightnessMappingStrategy).recalculateSplines(true, adjustments);
        verify(mBrightnessMappingStrategy, times(2)).addUserDataPoint(currentLux, 0.5f);
        verify(mBrightnessMappingStrategy, times(2)).addUserDataPoint(currentLux,
                /* brightness= */ 0.5f);

        clearInvocations(mBrightnessMappingStrategy);

@@ -342,7 +344,7 @@ public class AutomaticBrightnessControllerTest {
        // Verify only happens on the first configure. (i.e. not again when switching back)
        // Intentionally using any() to ensure it's not called whatsoever.
        verify(mBrightnessMappingStrategy, times(1))
                .addUserDataPoint(123.0f, 0.5f);
                .addUserDataPoint(/* lux= */ 123.0f, /* brightness= */ 0.5f);
        verify(mBrightnessMappingStrategy, times(1))
                .addUserDataPoint(anyFloat(), anyFloat());
    }
@@ -385,7 +387,7 @@ public class AutomaticBrightnessControllerTest {
        // Verify that we add the data point once when the user sets it, and again when we return
        // interactive mode.
        verify(mBrightnessMappingStrategy, times(2))
                .addUserDataPoint(123.0f, 0.51f);
                .addUserDataPoint(/* lux= */ 123.0f, /* brightness= */ 0.51f);
    }

    @Test
@@ -428,7 +430,7 @@ public class AutomaticBrightnessControllerTest {
        // Verify only happens on the first configure. (i.e. not again when switching back)
        // Intentionally using any() to ensure it's not called whatsoever.
        verify(mBrightnessMappingStrategy, times(1))
                .addUserDataPoint(123.0f, 0.5f);
                .addUserDataPoint(/* lux= */ 123.0f, /* brightness= */ 0.5f);
        verify(mBrightnessMappingStrategy, times(1))
                .addUserDataPoint(anyFloat(), anyFloat());
    }
@@ -474,7 +476,7 @@ public class AutomaticBrightnessControllerTest {
        // Verify this happens on the first configure and again when switching back
        // Intentionally using any() to ensure it's not called any other times whatsoever.
        verify(mBrightnessMappingStrategy, times(2))
                .addUserDataPoint(123.0f, 0.5f);
                .addUserDataPoint(/* lux= */ 123.0f, /* brightness= */ 0.5f);
        verify(mBrightnessMappingStrategy, times(2))
                .addUserDataPoint(anyFloat(), anyFloat());
    }
@@ -533,7 +535,8 @@ public class AutomaticBrightnessControllerTest {
                /* shouldResetShortTermModel= */ true);

        // There should be a user data point added to the mapper.
        verify(mBrightnessMappingStrategy, times(1)).addUserDataPoint(1000f, 0.5f);
        verify(mBrightnessMappingStrategy, times(1)).addUserDataPoint(/* lux= */ 1000f,
                /* brightness= */ 0.5f);
        verify(mBrightnessMappingStrategy, times(2)).setBrightnessConfiguration(any());
        verify(mBrightnessMappingStrategy, times(3)).getBrightness(anyFloat(), any(), anyInt());

@@ -559,7 +562,8 @@ public class AutomaticBrightnessControllerTest {
                /* shouldResetShortTermModel= */ true);

        // Ensure we use the correct mapping strategy
        verify(mIdleBrightnessMappingStrategy, times(1)).addUserDataPoint(1000f, 0.5f);
        verify(mIdleBrightnessMappingStrategy, times(1)).addUserDataPoint(/* lux= */ 1000f,
                /* brightness= */ 0.5f);
    }

    @Test
+7 −7
Original line number Diff line number Diff line
@@ -445,7 +445,7 @@ public class BrightnessMappingStrategyTest {

        // Add a data point in the middle of the curve where the user has set the brightness max
        final int idx = LUX_LEVELS.length / 2;
        strategy.addUserDataPoint(LUX_LEVELS[idx], 1.0f);
        strategy.addUserDataPoint(LUX_LEVELS[idx], /* brightness= */ 1.0f);

        // Then make sure that all control points after the middle lux level are also set to max...
        for (int i = idx; i < LUX_LEVELS.length; i++) {
@@ -662,11 +662,11 @@ public class BrightnessMappingStrategyTest {
                GAMMA_CORRECTION_NITS);
        BrightnessMappingStrategy strategy = BrightnessMappingStrategy.create(resources, ddc,
                mMockDwbc);
        assertEquals(0.0f, strategy.getAutoBrightnessAdjustment(), 0.0001f /* tolerance */);
        strategy.addUserDataPoint(2500, 1.0f);
        assertEquals(+1.0f, strategy.getAutoBrightnessAdjustment(), 0.0001f /* tolerance */);
        strategy.addUserDataPoint(2500, 0.0f);
        assertEquals(-1.0f, strategy.getAutoBrightnessAdjustment(), 0.0001f /* tolerance */);
        assertEquals(0.0f, strategy.getAutoBrightnessAdjustment(), /* delta= */ 0.0001f);
        strategy.addUserDataPoint(/* lux= */ 2500, /* brightness= */ 1.0f);
        assertEquals(+1.0f, strategy.getAutoBrightnessAdjustment(), /* delta= */ 0.0001f);
        strategy.addUserDataPoint(/* lux= */ 2500, /* brightness= */ 0.0f);
        assertEquals(-1.0f, strategy.getAutoBrightnessAdjustment(), /* delta= */ 0.0001f);
    }

    @Test
@@ -701,7 +701,7 @@ public class BrightnessMappingStrategyTest {
        // Similarly, if we set a user data point at (x4, 1.0), the adjustment should be 1 - y4.
        adjustment = 1.0f - y4;
        gamma = (float) MathUtils.pow(MAXIMUM_GAMMA, -adjustment);
        strategy.addUserDataPoint(x4, 1.0f);
        strategy.addUserDataPoint(x4, /* brightness= */ 1.0f);
        assertEquals(MathUtils.pow(y0, gamma), strategy.getBrightness(x0), 0.0001f /* tolerance */);
        assertEquals(MathUtils.pow(y2, gamma), strategy.getBrightness(x2), 0.0001f /* tolerance */);
        assertEquals(1.0f, strategy.getBrightness(x4), 0.0001f /* tolerance */);