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

Commit 9417b938 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Tidy Up BrightnessEvent" into main

parents bd1db13d 35209be1
Loading
Loading
Loading
Loading
+22 −15
Original line number Diff line number Diff line
@@ -129,9 +129,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    private static final String SCREEN_ON_BLOCKED_TRACE_NAME = "Screen on blocked";
    private static final String SCREEN_OFF_BLOCKED_TRACE_NAME = "Screen off blocked";

    private static final String TAG = "DisplayPowerController2";
    private static final String TAG = "DisplayPowerController";
    // To enable these logs, run:
    // 'adb shell setprop persist.log.tag.DisplayPowerController2 DEBUG && adb reboot'
    // 'adb shell setprop persist.log.tag.DisplayPowerController DEBUG && adb reboot'
    private static final boolean DEBUG = DebugUtils.isDebuggable(TAG);
    private static final String SCREEN_ON_BLOCKED_BY_DISPLAYOFFLOAD_TRACE_NAME =
            "Screen on blocked by displayoffload";
@@ -263,6 +263,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call

    // The unique ID of the primary display device currently tied to this logical display
    private String mUniqueDisplayId;
    private String mPhysicalDisplayName;

    // Tracker for brightness changes.
    @Nullable
@@ -371,10 +372,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    // If the last recorded screen state was dozing or not.
    private boolean mDozing;

    private boolean mAppliedDimming;

    private boolean mAppliedThrottling;

    // Reason for which the brightness was last changed. See {@link BrightnessReason} for more
    // information.
    // At the time of this writing, this value is changed within updatePowerState() only, which is
@@ -483,7 +480,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    // DPCs following the brightness of this DPC. This is used in concurrent displays mode - there
    // is one lead display, the additional displays follow the brightness value of the lead display.
    @GuardedBy("mLock")
    private SparseArray<DisplayPowerControllerInterface> mDisplayBrightnessFollowers =
    private final SparseArray<DisplayPowerControllerInterface> mDisplayBrightnessFollowers =
            new SparseArray();

    private boolean mBootCompleted;
@@ -525,8 +522,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        mThermalBrightnessThrottlingDataId =
                logicalDisplay.getDisplayInfoLocked().thermalBrightnessThrottlingDataId;
        mDisplayDevice = mLogicalDisplay.getPrimaryDisplayDeviceLocked();
        mUniqueDisplayId = logicalDisplay.getPrimaryDisplayDeviceLocked().getUniqueId();
        mUniqueDisplayId = mDisplayDevice.getUniqueId();
        mDisplayStatsId = mUniqueDisplayId.hashCode();
        mPhysicalDisplayName = mDisplayDevice.getNameLocked();

        mLastBrightnessEvent = new BrightnessEvent(mDisplayId);
        mTempBrightnessEvent = new BrightnessEvent(mDisplayId);
@@ -544,8 +542,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        mBrightnessTracker = brightnessTracker;
        mOnBrightnessChangeRunnable = onBrightnessChangeRunnable;

        PowerManager pm = context.getSystemService(PowerManager.class);

        final Resources resources = context.getResources();

        // DOZE AND DIM SETTINGS
@@ -840,6 +836,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        }

        final String uniqueId = device.getUniqueId();
        final String displayName = device.getNameLocked();
        final DisplayDeviceConfig config = device.getDisplayDeviceConfig();
        final IBinder token = device.getDisplayTokenLocked();
        final DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
@@ -866,6 +863,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                changed = true;
                mDisplayDevice = device;
                mUniqueDisplayId = uniqueId;
                mPhysicalDisplayName = displayName;
                mDisplayStatsId = mUniqueDisplayId.hashCode();
                mDisplayDeviceConfig = config;
                mThermalBrightnessThrottlingDataId = thermalBrightnessThrottlingDataId;
@@ -1552,10 +1550,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        // unthrottled (unclamped/ideal) and throttled brightness levels for subsequent operations.
        // Note throttling effectively changes the allowed brightness range, so, similarly to HBM,
        // we broadcast this change through setting.
        final float unthrottledBrightnessState = brightnessState;
        final float unthrottledBrightnessState = rawBrightnessState;
        DisplayBrightnessState clampedState = mBrightnessClamperController.clamp(mPowerRequest,
                brightnessState, slowChange, /* displayState= */ state);

        brightnessState = clampedState.getBrightness();
        slowChange = clampedState.isSlowChange();
        // faster rate wins, at this point customAnimationRate == -1, strategy does not control
@@ -1744,11 +1741,23 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        // brightness cap, RBC state, etc.
        mTempBrightnessEvent.setTime(System.currentTimeMillis());
        mTempBrightnessEvent.setBrightness(brightnessState);
        mTempBrightnessEvent.setNits(
                mDisplayBrightnessController.convertToAdjustedNits(brightnessState));
        final float hbmMax = mBrightnessRangeController.getCurrentBrightnessMax();
        final float clampedMax = Math.min(clampedState.getMaxBrightness(), hbmMax);
        final float brightnessOnAvailableScale = MathUtils.constrainedMap(0.0f, 1.0f,
                clampedState.getMinBrightness(), clampedMax,
                brightnessState);
        mTempBrightnessEvent.setPercent(Math.round(
                1000.0f * com.android.internal.display.BrightnessUtils.convertLinearToGamma(
                        brightnessOnAvailableScale) / 10)); // rounded to one dp
        mTempBrightnessEvent.setUnclampedBrightness(unthrottledBrightnessState);
        mTempBrightnessEvent.setPhysicalDisplayId(mUniqueDisplayId);
        mTempBrightnessEvent.setPhysicalDisplayName(mPhysicalDisplayName);
        mTempBrightnessEvent.setDisplayState(state);
        mTempBrightnessEvent.setDisplayPolicy(mPowerRequest.policy);
        mTempBrightnessEvent.setReason(mBrightnessReason);
        mTempBrightnessEvent.setHbmMax(mBrightnessRangeController.getCurrentBrightnessMax());
        mTempBrightnessEvent.setHbmMax(hbmMax);
        mTempBrightnessEvent.setHbmMode(mBrightnessRangeController.getHighBrightnessMode());
        mTempBrightnessEvent.setFlags(mTempBrightnessEvent.getFlags()
                | (mIsRbcActive ? BrightnessEvent.FLAG_RBC : 0)
@@ -2648,8 +2657,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        pw.println("Display Power Controller Thread State:");
        pw.println("  mPowerRequest=" + mPowerRequest);
        pw.println("  mBrightnessReason=" + mBrightnessReason);
        pw.println("  mAppliedDimming=" + mAppliedDimming);
        pw.println("  mAppliedThrottling=" + mAppliedThrottling);
        pw.println("  mDozing=" + mDozing);
        pw.println("  mSkipRampState=" + skipRampStateToString(mSkipRampState));
        pw.println("  mScreenOnBlockStartRealTime=" + mScreenOnBlockStartRealTime);
+71 −14
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import static android.hardware.display.DisplayManagerInternal.DisplayPowerReques
import static android.hardware.display.DisplayManagerInternal.DisplayPowerRequest.policyToString;

import static com.android.server.display.AutomaticBrightnessController.AUTO_BRIGHTNESS_MODE_DEFAULT;
import static com.android.server.display.BrightnessMappingStrategy.INVALID_LUX;
import static com.android.server.display.BrightnessMappingStrategy.INVALID_NITS;
import static com.android.server.display.config.DisplayBrightnessMappingConfig.autoBrightnessModeToString;

import android.hardware.display.BrightnessInfo;
@@ -48,13 +50,17 @@ public final class BrightnessEvent {
    private BrightnessReason mReason = new BrightnessReason();
    private int mDisplayId;
    private String mPhysicalDisplayId;
    private String mPhysicalDisplayName;
    private int mDisplayState;
    private int mDisplayPolicy;
    private long mTime;
    private float mLux;
    private float mNits;
    private float mPercent;
    private float mPreThresholdLux;
    private float mInitialBrightness;
    private float mBrightness;
    private float mUnclampedBrightness;
    private float mRecommendedBrightness;
    private float mPreThresholdBrightness;
    private int mHbmMode;
@@ -88,15 +94,19 @@ public final class BrightnessEvent {
        mReason.set(that.getReason());
        mDisplayId = that.getDisplayId();
        mPhysicalDisplayId = that.getPhysicalDisplayId();
        mPhysicalDisplayName = that.getPhysicalDisplayName();
        mDisplayState = that.mDisplayState;
        mDisplayPolicy = that.mDisplayPolicy;
        mTime = that.getTime();
        // Lux values
        mLux = that.getLux();
        mPreThresholdLux = that.getPreThresholdLux();
        mNits = that.getNits();
        mPercent = that.getPercent();
        // Brightness values
        mInitialBrightness = that.getInitialBrightness();
        mBrightness = that.getBrightness();
        mUnclampedBrightness = that.getUnclampedBrightness();
        mRecommendedBrightness = that.getRecommendedBrightness();
        mPreThresholdBrightness = that.getPreThresholdBrightness();
        // Different brightness modulations
@@ -121,14 +131,18 @@ public final class BrightnessEvent {
        mReason = new BrightnessReason();
        mTime = SystemClock.uptimeMillis();
        mPhysicalDisplayId = "";
        mPhysicalDisplayName = "";
        mDisplayState = Display.STATE_UNKNOWN;
        mDisplayPolicy = POLICY_OFF;
        // Lux values
        mLux = 0;
        mLux = INVALID_LUX;
        mPreThresholdLux = 0;
        mNits = INVALID_NITS;
        mPercent = -1f;
        // Brightness values
        mInitialBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
        mBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
        mUnclampedBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
        mRecommendedBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
        mPreThresholdBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
        // Different brightness modulations
@@ -160,13 +174,18 @@ public final class BrightnessEvent {
        return mReason.equals(that.mReason)
                && mDisplayId == that.mDisplayId
                && mPhysicalDisplayId.equals(that.mPhysicalDisplayId)
                && mPhysicalDisplayName.equals(that.mPhysicalDisplayName)
                && mDisplayState == that.mDisplayState
                && mDisplayPolicy == that.mDisplayPolicy
                && Float.floatToRawIntBits(mLux) == Float.floatToRawIntBits(that.mLux)
                && Float.floatToRawIntBits(mPreThresholdLux)
                == Float.floatToRawIntBits(that.mPreThresholdLux)
                && Float.floatToRawIntBits(mNits) == Float.floatToRawIntBits(that.mNits)
                && Float.floatToRawIntBits(mPercent) == Float.floatToRawIntBits(that.mPercent)
                && Float.floatToRawIntBits(mBrightness)
                == Float.floatToRawIntBits(that.mBrightness)
                && Float.floatToRawIntBits(mUnclampedBrightness)
                == Float.floatToRawIntBits(that.mUnclampedBrightness)
                && Float.floatToRawIntBits(mRecommendedBrightness)
                == Float.floatToRawIntBits(that.mRecommendedBrightness)
                && Float.floatToRawIntBits(mPreThresholdBrightness)
@@ -195,27 +214,34 @@ public final class BrightnessEvent {
    public String toString(boolean includeTime) {
        return (includeTime ? FORMAT.format(new Date(mTime)) + " - " : "")
                + "BrightnessEvent: "
                + "disp=" + mDisplayId
                + ", physDisp=" + mPhysicalDisplayId
                + ", displayState=" + Display.stateToString(mDisplayState)
                + ", displayPolicy=" + policyToString(mDisplayPolicy)
                + ", brt=" + mBrightness + ((mFlags & FLAG_USER_SET) != 0 ? "(user_set)" : "")
                + "brt=" + mBrightness + ((mFlags & FLAG_USER_SET) != 0 ? "(user_set)" : "") + " ("
                + mPercent + "%)"
                + ", nits= " + mNits
                + ", lux=" + mLux
                + ", reason=" + mReason.toString(mAdjustmentFlags)
                + ", strat=" + mDisplayBrightnessStrategyName
                + ", state=" + Display.stateToString(mDisplayState)
                + ", policy=" + policyToString(mDisplayPolicy)
                + ", flags=" + flagsToString()
                // Autobrightness
                + ", initBrt=" + mInitialBrightness
                + ", rcmdBrt=" + mRecommendedBrightness
                + ", preBrt=" + mPreThresholdBrightness
                + ", lux=" + mLux
                + ", preLux=" + mPreThresholdLux
                + ", wasShortTermModelActive=" + mWasShortTermModelActive
                + ", autoBrightness=" + mAutomaticBrightnessEnabled + " ("
                + autoBrightnessModeToString(mAutoBrightnessMode) + ")"
                // Throttling info
                + ", unclampedBrt=" + mUnclampedBrightness
                + ", hbmMax=" + mHbmMax
                + ", hbmMode=" + BrightnessInfo.hbmToString(mHbmMode)
                + ", rbcStrength=" + mRbcStrength
                + ", thrmMax=" + mThermalMax
                // Modifiers
                + ", rbcStrength=" + mRbcStrength
                + ", powerFactor=" + mPowerFactor
                + ", wasShortTermModelActive=" + mWasShortTermModelActive
                + ", flags=" + flagsToString()
                + ", reason=" + mReason.toString(mAdjustmentFlags)
                + ", autoBrightness=" + mAutomaticBrightnessEnabled
                + ", strategy=" + mDisplayBrightnessStrategyName
                + ", autoBrightnessMode=" + autoBrightnessModeToString(mAutoBrightnessMode);
                // Meta
                + ", physDisp=" + mPhysicalDisplayName + "(" + mPhysicalDisplayId + ")"
                + ", logicalId=" + mDisplayId;
    }

    @Override
@@ -255,6 +281,14 @@ public final class BrightnessEvent {
        this.mPhysicalDisplayId = mPhysicalDisplayId;
    }

    public String getPhysicalDisplayName() {
        return mPhysicalDisplayName;
    }

    public void setPhysicalDisplayName(String mPhysicalDisplayName) {
        this.mPhysicalDisplayName = mPhysicalDisplayName;
    }

    public void setDisplayState(int state) {
        mDisplayState = state;
    }
@@ -295,6 +329,29 @@ public final class BrightnessEvent {
        this.mBrightness = brightness;
    }

    public float getUnclampedBrightness() {
        return mUnclampedBrightness;
    }

    public void setUnclampedBrightness(float unclampedBrightness) {
        this.mUnclampedBrightness = unclampedBrightness;
    }

    public void setPercent(float percent) {
        this.mPercent = percent;
    }
    public float getPercent() {
        return mPercent;
    }

    public void setNits(float nits) {
        this.mNits = nits;
    }

    public float getNits() {
        return mNits;
    }

    public float getRecommendedBrightness() {
        return mRecommendedBrightness;
    }
+9 −0
Original line number Diff line number Diff line
@@ -2137,6 +2137,14 @@ public final class DisplayPowerControllerTest {
    private void setUpDisplay(int displayId, String uniqueId, LogicalDisplay logicalDisplayMock,
            DisplayDevice displayDeviceMock, DisplayDeviceConfig displayDeviceConfigMock,
            boolean isEnabled) {

        setUpDisplay(displayId, uniqueId, logicalDisplayMock, displayDeviceMock,
                displayDeviceConfigMock, isEnabled, "display_name");
    }

    private void setUpDisplay(int displayId, String uniqueId, LogicalDisplay logicalDisplayMock,
            DisplayDevice displayDeviceMock, DisplayDeviceConfig displayDeviceConfigMock,
            boolean isEnabled, String displayName) {
        DisplayInfo info = new DisplayInfo();
        DisplayDeviceInfo deviceInfo = new DisplayDeviceInfo();
        deviceInfo.uniqueId = uniqueId;
@@ -2148,6 +2156,7 @@ public final class DisplayPowerControllerTest {
        when(logicalDisplayMock.isInTransitionLocked()).thenReturn(false);
        when(displayDeviceMock.getDisplayDeviceInfoLocked()).thenReturn(deviceInfo);
        when(displayDeviceMock.getUniqueId()).thenReturn(uniqueId);
        when(displayDeviceMock.getNameLocked()).thenReturn(displayName);
        when(displayDeviceMock.getDisplayDeviceConfig()).thenReturn(displayDeviceConfigMock);
        when(displayDeviceConfigMock.getProximitySensor()).thenReturn(
                new SensorData(Sensor.STRING_TYPE_PROXIMITY, null));
+12 −7
Original line number Diff line number Diff line
@@ -43,10 +43,14 @@ public final class BrightnessEventTest {
        mBrightnessEvent = new BrightnessEvent(1);
        mBrightnessEvent.setReason(
                getReason(BrightnessReason.REASON_DOZE, BrightnessReason.MODIFIER_LOW_POWER));
        mBrightnessEvent.setPhysicalDisplayId("test");
        mBrightnessEvent.setPhysicalDisplayId("987654321");
        mBrightnessEvent.setPhysicalDisplayName("display_name");
        mBrightnessEvent.setDisplayState(Display.STATE_ON);
        mBrightnessEvent.setDisplayPolicy(POLICY_BRIGHT);
        mBrightnessEvent.setLux(100.0f);
        mBrightnessEvent.setPercent(46.5f);
        mBrightnessEvent.setNits(893.8f);
        mBrightnessEvent.setUnclampedBrightness(0.65f);
        mBrightnessEvent.setPreThresholdLux(150.0f);
        mBrightnessEvent.setTime(System.currentTimeMillis());
        mBrightnessEvent.setInitialBrightness(25.0f);
@@ -77,12 +81,13 @@ public final class BrightnessEventTest {
    public void testToStringWorksAsExpected() {
        String actualString = mBrightnessEvent.toString(false);
        String expectedString =
                "BrightnessEvent: disp=1, physDisp=test, displayState=ON, displayPolicy=BRIGHT,"
                + " brt=0.6, initBrt=25.0, rcmdBrt=0.6, preBrt=NaN, lux=100.0, preLux=150.0,"
                + " hbmMax=0.62, hbmMode=off, rbcStrength=-1, thrmMax=0.65, powerFactor=0.2,"
                + " wasShortTermModelActive=true, flags=, reason=doze [ low_pwr ],"
                + " autoBrightness=true, strategy=" + DISPLAY_BRIGHTNESS_STRATEGY_NAME
                + ", autoBrightnessMode=idle";
                "BrightnessEvent: brt=0.6 (46.5%), nits= 893.8, lux=100.0, reason=doze [ "
                        + "low_pwr ], strat=strategy_name, state=ON, policy=BRIGHT, flags=, "
                        + "initBrt=25.0, rcmdBrt=0.6, preBrt=NaN, preLux=150.0, "
                        + "wasShortTermModelActive=true, autoBrightness=true (idle), "
                        + "unclampedBrt=0.65, hbmMax=0.62, hbmMode=off, thrmMax=0.65, "
                        + "rbcStrength=-1, powerFactor=0.2, physDisp=display_name(987654321), "
                        + "logicalId=1";
        assertEquals(expectedString, actualString);
    }