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

Commit 9f05ad0a authored by Silvia Vinyes's avatar Silvia Vinyes
Browse files

Correct Brightness event values.

BrightnessEvent should have the settings value (independent of whether
it is applied, since the information is available in the flags or
irrelevant).

Logging should have -1 for the non-applied settings.

Test: atest BrightnessEventTest
Bug: 236234158

Change-Id: I1e65707d55e78105c1f78f76bfd9fc17bca4b074
parent cc9f88ae
Loading
Loading
Loading
Loading
+14 −13
Original line number Diff line number Diff line
@@ -1645,11 +1645,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        mTempBrightnessEvent.setHbmMax(mHbmController.getCurrentBrightnessMax());
        mTempBrightnessEvent.setHbmMode(mHbmController.getHighBrightnessMode());
        mTempBrightnessEvent.setFlags(mTempBrightnessEvent.getFlags()
                | (mIsRbcActive ? BrightnessEvent.FLAG_RBC : 0));
        mTempBrightnessEvent.setRbcStrength((mCdsi != null && mCdsi.isReduceBrightColorsActivated())
                | (mIsRbcActive ? BrightnessEvent.FLAG_RBC : 0)
                | (mPowerRequest.lowPowerMode ? BrightnessEvent.FLAG_LOW_POWER_MODE : 0));
        mTempBrightnessEvent.setRbcStrength(mCdsi != null
                ? mCdsi.getReduceBrightColorsStrength() : -1);
        mTempBrightnessEvent.setPowerFactor(
                mPowerRequest.lowPowerMode ? mPowerRequest.screenLowPowerBrightnessFactor : 1.0f);
        mTempBrightnessEvent.setPowerFactor(mPowerRequest.screenLowPowerBrightnessFactor);
        // Temporary is what we use during slider interactions. We avoid logging those so that
        // we don't spam logcat when the slider is being used.
        boolean tempToTempTransition =
@@ -1662,10 +1662,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
            mTempBrightnessEvent.setInitialBrightness(lastBrightness);
            mTempBrightnessEvent.setFastAmbientLux(
                    mAutomaticBrightnessController == null
                        ? -1 : mAutomaticBrightnessController.getFastAmbientLux());
                        ? -1f : mAutomaticBrightnessController.getFastAmbientLux());
            mTempBrightnessEvent.setSlowAmbientLux(
                    mAutomaticBrightnessController == null
                        ? -1 : mAutomaticBrightnessController.getSlowAmbientLux());
                        ? -1f : mAutomaticBrightnessController.getSlowAmbientLux());
            mTempBrightnessEvent.setAutomaticBrightnessEnabled(mPowerRequest.useAutoBrightness);
            mLastBrightnessEvent.copyFrom(mTempBrightnessEvent);
            BrightnessEvent newEvent = new BrightnessEvent(mTempBrightnessEvent);
@@ -2769,12 +2769,13 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    }

    private void logManualBrightnessEvent(BrightnessEvent event) {
        float hbmMaxNits =
        float appliedLowPowerMode = event.isLowPowerModeSet() ? event.getPowerFactor() : -1f;
        int appliedRbcStrength  = event.isRbcEnabled() ? event.getRbcStrength() : -1;
        float appliedHbmMaxNits =
                event.getHbmMode() == BrightnessInfo.HIGH_BRIGHTNESS_MODE_OFF
                ? -1f : convertToNits(event.getHbmMax());

        // thermalCapNits set to -1 if not currently capping max brightness
        float thermalCapNits =
        float appliedThermalCapNits =
                event.getThermalMax() == PowerManager.BRIGHTNESS_MAX
                ? -1f : convertToNits(event.getThermalMax());

@@ -2784,10 +2785,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                event.getSlowAmbientLux(),
                event.getPhysicalDisplayId(),
                event.isShortTermModelActive(),
                event.getPowerFactor(),
                event.getRbcStrength(),
                hbmMaxNits,
                thermalCapNits,
                appliedLowPowerMode,
                appliedRbcStrength,
                appliedHbmMaxNits,
                appliedThermalCapNits,
                event.isAutomaticBrightnessEnabled(),
                FrameworkStatsLog.DISPLAY_BRIGHTNESS_CHANGED__REASON__REASON_MANUAL);
    }
+20 −3
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.os.PowerManager;
import android.os.SystemClock;
import android.util.TimeUtils;

import com.android.internal.annotations.VisibleForTesting;

/**
 * Represents a particular brightness change event.
 */
@@ -29,7 +31,8 @@ public final class BrightnessEvent {
    public static final int FLAG_INVALID_LUX = 0x2;
    public static final int FLAG_DOZE_SCALE = 0x4;
    public static final int FLAG_USER_SET = 0x8;
    public static final int FLAG_IDLE_CURVE = 0x16;
    public static final int FLAG_IDLE_CURVE = 0x10;
    public static final int FLAG_LOW_POWER_MODE = 0x20;

    private BrightnessReason mReason = new BrightnessReason();
    private int mDisplayId;
@@ -317,6 +320,10 @@ public final class BrightnessEvent {
        this.mRbcStrength = mRbcStrength;
    }

    public boolean isRbcEnabled() {
        return (mFlags & FLAG_RBC) != 0;
    }

    public float getThermalMax() {
        return mThermalMax;
    }
@@ -333,6 +340,10 @@ public final class BrightnessEvent {
        this.mPowerFactor = mPowerFactor;
    }

    public boolean isLowPowerModeSet() {
        return (mFlags & FLAG_LOW_POWER_MODE) != 0;
    }

    public int getFlags() {
        return mFlags;
    }
@@ -361,11 +372,17 @@ public final class BrightnessEvent {
        this.mAutomaticBrightnessEnabled = mAutomaticBrightnessEnabled;
    }

    private String flagsToString() {
    /**
     * A utility to stringify flags from a BrightnessEvent
     * @return Stringified flags from BrightnessEvent
     */
    @VisibleForTesting
    public String flagsToString() {
        return ((mFlags & FLAG_USER_SET) != 0 ? "user_set " : "")
                + ((mFlags & FLAG_RBC) != 0 ? "rbc " : "")
                + ((mFlags & FLAG_INVALID_LUX) != 0 ? "invalid_lux " : "")
                + ((mFlags & FLAG_DOZE_SCALE) != 0 ? "doze_scale " : "")
                + ((mFlags & FLAG_IDLE_CURVE) != 0 ? "idle_curve " : "");
                + ((mFlags & FLAG_IDLE_CURVE) != 0 ? "idle_curve " : "")
                + ((mFlags & FLAG_LOW_POWER_MODE) != 0 ? "low_power_mode " : "");
    }
}
+21 −2
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ public final class BrightnessEventTest {
        BrightnessEvent secondBrightnessEvent = new BrightnessEvent(1);
        secondBrightnessEvent.copyFrom(mBrightnessEvent);
        secondBrightnessEvent.setTime(0);
        assertEquals(secondBrightnessEvent.equalsMainData(mBrightnessEvent), true);
        assertEquals(true, secondBrightnessEvent.equalsMainData(mBrightnessEvent));
    }

    @Test
@@ -74,9 +74,28 @@ public final class BrightnessEventTest {
                + " preBrt=NaN, lux=100.0, fastLux=90.0, slowLux=85.0, preLux=150.0, hbmMax=0.62,"
                + " hbmMode=off, rbcStrength=-1, thrmMax=0.65, powerFactor=0.2, flags=, reason=doze"
                + " [ low_pwr ], autoBrightness=true";
        assertEquals(actualString, expectedString);
        assertEquals(expectedString, actualString);
    }

    @Test
    public void testFlagsToString() {
        mBrightnessEvent.reset();
        mBrightnessEvent.setFlags(mBrightnessEvent.getFlags() | BrightnessEvent.FLAG_IDLE_CURVE);
        String actualString = mBrightnessEvent.flagsToString();
        String expectedString = "idle_curve ";
        assertEquals(expectedString, actualString);
    }

    @Test
    public void testFlagsToString_multipleFlags() {
        mBrightnessEvent.reset();
        mBrightnessEvent.setFlags(mBrightnessEvent.getFlags()
                    | BrightnessEvent.FLAG_IDLE_CURVE
                    | BrightnessEvent.FLAG_LOW_POWER_MODE);
        String actualString = mBrightnessEvent.flagsToString();
        String expectedString = "idle_curve low_power_mode ";
        assertEquals(expectedString, actualString);
    }


    private BrightnessReason getReason(int reason, int modifier) {