Merge "Fix the issue of increasing brightness with KEYCODE_BRIGHTNESS_DOWN event" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
4c30ffa634
@@ -3096,18 +3096,21 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
|||||||
}
|
}
|
||||||
int screenDisplayId = displayId < 0 ? DEFAULT_DISPLAY : displayId;
|
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 linearBrightness = mDisplayManager.getBrightness(screenDisplayId);
|
||||||
|
|
||||||
float gammaBrightness = BrightnessUtils.convertLinearToGamma(linearBrightness);
|
float gammaBrightness = BrightnessUtils.convertLinearToGamma(linearBrightness);
|
||||||
float adjustedGammaBrightness =
|
float adjustedGammaBrightness =
|
||||||
gammaBrightness + 1f / BRIGHTNESS_STEPS * direction;
|
gammaBrightness + 1f / BRIGHTNESS_STEPS * direction;
|
||||||
|
adjustedGammaBrightness = MathUtils.constrain(adjustedGammaBrightness, 0f,
|
||||||
|
1f);
|
||||||
float adjustedLinearBrightness = BrightnessUtils.convertGammaToLinear(
|
float adjustedLinearBrightness = BrightnessUtils.convertGammaToLinear(
|
||||||
adjustedGammaBrightness);
|
adjustedGammaBrightness);
|
||||||
|
adjustedLinearBrightness = MathUtils.constrain(adjustedLinearBrightness,
|
||||||
adjustedLinearBrightness = MathUtils.constrain(adjustedLinearBrightness, 0f,
|
minLinearBrightness, maxLinearBrightness);
|
||||||
1f);
|
|
||||||
|
|
||||||
mDisplayManager.setBrightness(screenDisplayId, adjustedLinearBrightness);
|
mDisplayManager.setBrightness(screenDisplayId, adjustedLinearBrightness);
|
||||||
|
|
||||||
startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
|
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_ALT_LEFT;
|
||||||
import static android.view.KeyEvent.KEYCODE_B;
|
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_C;
|
||||||
import static android.view.KeyEvent.KEYCODE_CTRL_LEFT;
|
import static android.view.KeyEvent.KEYCODE_CTRL_LEFT;
|
||||||
import static android.view.KeyEvent.KEYCODE_E;
|
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);
|
sendKeyCombination(new int[]{KEYCODE_META_LEFT, KEYCODE_ENTER}, 0);
|
||||||
mPhoneWindowManager.assertGoToHomescreen();
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ import com.android.server.wm.WindowManagerInternal.AppTransitionListener;
|
|||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.mockito.AdditionalMatchers;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockSettings;
|
import org.mockito.MockSettings;
|
||||||
@@ -339,6 +340,20 @@ class TestPhoneWindowManager {
|
|||||||
setPhoneCallIsInProgress();
|
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() {
|
void setPhoneCallIsInProgress() {
|
||||||
// Let device has an ongoing phone call.
|
// Let device has an ongoing phone call.
|
||||||
doReturn(false).when(mTelecomManager).isRinging();
|
doReturn(false).when(mTelecomManager).isRinging();
|
||||||
|
|||||||
Reference in New Issue
Block a user