From 0ce5c2dca6289692054b5412f84bce0a3acd9f1c Mon Sep 17 00:00:00 2001 From: Fiona Campbell Date: Fri, 12 May 2023 17:19:15 +0000 Subject: [PATCH] BrightnessChangeEvent works for increasing brightness BrightnessChangeEvents were only sending when decreasing the brightness. Due to two issues: 1) brightness adjustment was being clamped to 0-1 instead of -1 to +1. (meaning buggy conditions were met when 0.0 == 0.0) 2) the brightness reason that was being read was the old reason, rather than the temporary (new) reason (meaning we were not sending change events correctly). Bug: 282005647 Test: adb shell dumpsys | grep BrightnessChangeEvent Change-Id: I2ada97469b68baee695e06db0c8a0cdbbab1027f --- .../server/display/DisplayPowerController2.java | 10 +--------- .../server/display/brightness/BrightnessUtils.java | 7 +++++++ .../strategy/AutomaticBrightnessStrategy.java | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/services/core/java/com/android/server/display/DisplayPowerController2.java b/services/core/java/com/android/server/display/DisplayPowerController2.java index d95601fcacf2d..1674141881807 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController2.java +++ b/services/core/java/com/android/server/display/DisplayPowerController2.java @@ -1454,7 +1454,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal // Skip the animation when the screen is off or suspended. boolean brightnessAdjusted = false; final boolean brightnessIsTemporary = - (mBrightnessReason.getReason() == BrightnessReason.REASON_TEMPORARY) + (mBrightnessReasonTemp.getReason() == BrightnessReason.REASON_TEMPORARY) || mAutomaticBrightnessStrategy .isTemporaryAutoBrightnessAdjustmentApplied(); if (!mPendingScreenOff) { @@ -2159,11 +2159,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal }, mClock.uptimeMillis()); } - private float getAutoBrightnessAdjustmentSetting() { - final float adj = Settings.System.getFloatForUser(mContext.getContentResolver(), - Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ, 0.0f, UserHandle.USER_CURRENT); - return Float.isNaN(adj) ? 0.0f : clampAutoBrightnessAdjustment(adj); - } @Override public float getScreenBrightnessSetting() { @@ -2436,9 +2431,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal } } - private static float clampAutoBrightnessAdjustment(float value) { - return MathUtils.constrain(value, -1.0f, 1.0f); - } private void noteScreenState(int screenState) { // Log screen state change with display id diff --git a/services/core/java/com/android/server/display/brightness/BrightnessUtils.java b/services/core/java/com/android/server/display/brightness/BrightnessUtils.java index 169cc4aa1c2d9..3fae22434751b 100644 --- a/services/core/java/com/android/server/display/brightness/BrightnessUtils.java +++ b/services/core/java/com/android/server/display/brightness/BrightnessUtils.java @@ -41,6 +41,13 @@ public final class BrightnessUtils { PowerManager.BRIGHTNESS_MAX); } + /** + * Clamps the brightness value in the maximum and the minimum brightness adjustment range + */ + public static float clampBrightnessAdjustment(float value) { + return MathUtils.constrain(value, -1.0f, 1.0f); + } + /** * A utility to construct the DisplayBrightnessState */ diff --git a/services/core/java/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategy.java b/services/core/java/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategy.java index 95cbf9835e0f0..0e885dcd1738b 100644 --- a/services/core/java/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategy.java +++ b/services/core/java/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategy.java @@ -202,7 +202,7 @@ public class AutomaticBrightnessStrategy { final float adj = Settings.System.getFloatForUser(mContext.getContentResolver(), Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ, 0.0f, UserHandle.USER_CURRENT); mPendingAutoBrightnessAdjustment = Float.isNaN(adj) ? Float.NaN - : BrightnessUtils.clampAbsoluteBrightness(adj); + : BrightnessUtils.clampBrightnessAdjustment(adj); if (userSwitch) { processPendingAutoBrightnessAdjustments(); } @@ -402,6 +402,6 @@ public class AutomaticBrightnessStrategy { private float getAutoBrightnessAdjustmentSetting() { final float adj = Settings.System.getFloatForUser(mContext.getContentResolver(), Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ, 0.0f, UserHandle.USER_CURRENT); - return Float.isNaN(adj) ? 0.0f : BrightnessUtils.clampAbsoluteBrightness(adj); + return Float.isNaN(adj) ? 0.0f : BrightnessUtils.clampBrightnessAdjustment(adj); } }