Fix the issue of increasing brightness with KEYCODE_BRIGHTNESS_DOWN event
An issue was identified where the KEYCODE_BRIGHTNESS_DOWN keycode event would lead to increase in the brightness in the low brightness conditions. This is happening because we do not constrain the brightness in a range of 0 to 1 while in the gamma scale. Bug: 271389272 Test: Manually verified the updated behaviour Change-Id: I93aea21c621b070b476d6e965970c72ca43b87a7
This commit is contained in:
@@ -3091,18 +3091,21 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
}
|
||||
int screenDisplayId = displayId < 0 ? DEFAULT_DISPLAY : displayId;
|
||||
|
||||
float minLinearBrightness = mPowerManager.getBrightnessConstraint(
|
||||
PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM);
|
||||
float maxLinearBrightness = mPowerManager.getBrightnessConstraint(
|
||||
PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MAXIMUM);
|
||||
float linearBrightness = mDisplayManager.getBrightness(screenDisplayId);
|
||||
|
||||
float gammaBrightness = BrightnessUtils.convertLinearToGamma(linearBrightness);
|
||||
float adjustedGammaBrightness =
|
||||
gammaBrightness + 1f / BRIGHTNESS_STEPS * direction;
|
||||
|
||||
adjustedGammaBrightness = MathUtils.constrain(adjustedGammaBrightness, 0f,
|
||||
1f);
|
||||
float adjustedLinearBrightness = BrightnessUtils.convertGammaToLinear(
|
||||
adjustedGammaBrightness);
|
||||
|
||||
adjustedLinearBrightness = MathUtils.constrain(adjustedLinearBrightness, 0f,
|
||||
1f);
|
||||
|
||||
adjustedLinearBrightness = MathUtils.constrain(adjustedLinearBrightness,
|
||||
minLinearBrightness, maxLinearBrightness);
|
||||
mDisplayManager.setBrightness(screenDisplayId, adjustedLinearBrightness);
|
||||
|
||||
startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.android.server.policy;
|
||||
|
||||
import static android.view.KeyEvent.KEYCODE_ALT_LEFT;
|
||||
import static android.view.KeyEvent.KEYCODE_B;
|
||||
import static android.view.KeyEvent.KEYCODE_BRIGHTNESS_DOWN;
|
||||
import static android.view.KeyEvent.KEYCODE_C;
|
||||
import static android.view.KeyEvent.KEYCODE_CTRL_LEFT;
|
||||
import static android.view.KeyEvent.KEYCODE_E;
|
||||
@@ -186,4 +187,19 @@ public class ModifierShortcutTests extends ShortcutKeyTestBase {
|
||||
sendKeyCombination(new int[]{KEYCODE_META_LEFT, KEYCODE_ENTER}, 0);
|
||||
mPhoneWindowManager.assertGoToHomescreen();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a KEYCODE_BRIGHTNESS_DOWN event and validates the brightness is decreased as expected;
|
||||
*/
|
||||
@Test
|
||||
public void testKeyCodeBrightnessDown() {
|
||||
float[] currentBrightness = new float[]{0.1f, 0.05f, 0.0f};
|
||||
float[] newBrightness = new float[]{0.065738f, 0.0275134f, 0.0f};
|
||||
|
||||
for (int i = 0; i < currentBrightness.length; i++) {
|
||||
mPhoneWindowManager.prepareBrightnessDecrease(currentBrightness[i]);
|
||||
sendKey(KEYCODE_BRIGHTNESS_DOWN);
|
||||
mPhoneWindowManager.verifyNewBrightness(newBrightness[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,6 +88,7 @@ import com.android.server.wm.WindowManagerInternal.AppTransitionListener;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.mockito.AdditionalMatchers;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockSettings;
|
||||
@@ -330,6 +331,20 @@ class TestPhoneWindowManager {
|
||||
setPhoneCallIsInProgress();
|
||||
}
|
||||
|
||||
void prepareBrightnessDecrease(float currentBrightness) {
|
||||
doReturn(0.0f).when(mPowerManager)
|
||||
.getBrightnessConstraint(PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM);
|
||||
doReturn(1.0f).when(mPowerManager)
|
||||
.getBrightnessConstraint(PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MAXIMUM);
|
||||
doReturn(currentBrightness).when(mDisplayManager)
|
||||
.getBrightness(0);
|
||||
}
|
||||
|
||||
void verifyNewBrightness(float newBrightness) {
|
||||
verify(mDisplayManager).setBrightness(Mockito.eq(0),
|
||||
AdditionalMatchers.eq(newBrightness, 0.001f));
|
||||
}
|
||||
|
||||
void setPhoneCallIsInProgress() {
|
||||
// Let device has an ongoing phone call.
|
||||
doReturn(false).when(mTelecomManager).isRinging();
|
||||
|
||||
Reference in New Issue
Block a user