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

Commit 794d5dce authored by Rupesh Bansal's avatar Rupesh Bansal
Browse files

Manual brightness working as expected with refactoring flag enabled

This fixes the issue where the manual brightness was stuck as zero no
matter where the slider was moved.

Bug: 333766700
Bug: 333613462
Test: atest android.display.cts.BrightnessTest
Change-Id: Id3742594014501992a92dd9bd4804a37934cf044
parent d3f6fd8c
Loading
Loading
Loading
Loading
+37 −32
Original line number Diff line number Diff line
@@ -1406,9 +1406,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
            }
            setBrightnessFromOffload(PowerManager.BRIGHTNESS_INVALID_FLOAT);
        }

        if (!mFlags.isRefactorDisplayPowerControllerEnabled()) {
            // AutomaticBrightnessStrategy has higher priority than OffloadBrightnessStrategy
        if (!mFlags.isRefactorDisplayPowerControllerEnabled() && (Float.isNaN(brightnessState)
                || mBrightnessReasonTemp.getReason() == BrightnessReason.REASON_OFFLOAD)) {
            if (Float.isNaN(brightnessState)
                    || mBrightnessReasonTemp.getReason() == BrightnessReason.REASON_OFFLOAD) {
                if (mAutomaticBrightnessStrategy.isAutoBrightnessEnabled()) {
                    brightnessState = mAutomaticBrightnessStrategy.getAutomaticScreenBrightness(
                            mTempBrightnessEvent);
@@ -1416,13 +1418,15 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                            || brightnessState == PowerManager.BRIGHTNESS_OFF_FLOAT) {
                        rawBrightnessState = mAutomaticBrightnessController
                                .getRawAutomaticScreenBrightness();
                    brightnessState = clampScreenBrightness(brightnessState);
                        // slowly adapt to auto-brightness
                    // TODO(b/253226419): slowChange should be decided by strategy.updateBrightness
                        // TODO(b/253226419): slowChange should be decided by
                        // strategy.updateBrightness
                        slowChange = mAutomaticBrightnessStrategy.hasAppliedAutoBrightness()
                            && !mAutomaticBrightnessStrategy.getAutoBrightnessAdjustmentChanged();
                                && !mAutomaticBrightnessStrategy
                                .getAutoBrightnessAdjustmentChanged();
                        brightnessAdjustmentFlags =
                            mAutomaticBrightnessStrategy.getAutoBrightnessAdjustmentReasonsFlags();
                                mAutomaticBrightnessStrategy
                                        .getAutoBrightnessAdjustmentReasonsFlags();
                        updateScreenBrightnessSetting = currentBrightnessSetting != brightnessState;
                        mAutomaticBrightnessStrategy.setAutoBrightnessApplied(true);
                        mBrightnessReasonTemp.setReason(BrightnessReason.REASON_AUTOMATIC);
@@ -1437,12 +1441,13 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                    }
                }
            } else {
            // Any non-auto-brightness values such as override or temporary should still be subject
            // to clamping so that they don't go beyond the current max as specified by Brightness
            // Range Controller.
            brightnessState = clampScreenBrightness(brightnessState);
                mAutomaticBrightnessStrategy.setAutoBrightnessApplied(false);
            }
        }

        if (!Float.isNaN(brightnessState)) {
            brightnessState = clampScreenBrightness(brightnessState);
        }

        // If there's an offload session, we need to set the initial doze brightness before
        // the offload session starts controlling the brightness.