Skip to content

Commit 9dd9e0c

Browse files
author
Craig Mautner
committed
Fix math errors causing black screen. DO NOT MERGE
Turning off animations in the Developer options creates a ValueAnimator duration scale of 0. This is used as the denominator in RampAnimator which, if the numerator is also 0, sets mAnimatedValue to NaN. Rounding NaN to the nearest int produces 0 which is then assigned to mScreenBrightness in DisplayPowerState. A copy mistake which assigned mTransitionAnimationScale as the default value for mAnimatorDurationScale in WindowManagerService is also fixed here. Bug 7515609 fixed. Change-Id: I39f8d0a7abdd5a1fe70d757fe95fbddaf7a0ed51
1 parent 7be52cb commit 9dd9e0c

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

services/java/com/android/server/power/RampAnimator.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,26 @@ public void run() {
102102
final long frameTimeNanos = mChoreographer.getFrameTimeNanos();
103103
final float timeDelta = (frameTimeNanos - mLastFrameTimeNanos)
104104
* 0.000000001f;
105-
final float amount = timeDelta * mRate / ValueAnimator.getDurationScale();
106105
mLastFrameTimeNanos = frameTimeNanos;
107106

108107
// Advance the animated value towards the target at the specified rate
109108
// and clamp to the target. This gives us the new current value but
110109
// we keep the animated value around to allow for fractional increments
111110
// towards the target.
112-
int oldCurrentValue = mCurrentValue;
113-
if (mTargetValue > mCurrentValue) {
114-
mAnimatedValue = Math.min(mAnimatedValue + amount, mTargetValue);
111+
final float scale = ValueAnimator.getDurationScale();
112+
if (scale == 0) {
113+
// Animation off.
114+
mAnimatedValue = mTargetValue;
115115
} else {
116-
mAnimatedValue = Math.max(mAnimatedValue - amount, mTargetValue);
116+
final float amount = timeDelta * mRate / scale;
117+
if (mTargetValue > mCurrentValue) {
118+
mAnimatedValue = Math.min(mAnimatedValue + amount, mTargetValue);
119+
} else {
120+
mAnimatedValue = Math.max(mAnimatedValue - amount, mTargetValue);
121+
}
117122
}
118-
mCurrentValue = (int)Math.round(mAnimatedValue);
123+
final int oldCurrentValue = mCurrentValue;
124+
mCurrentValue = Math.round(mAnimatedValue);
119125

120126
if (oldCurrentValue != mCurrentValue) {
121127
mProperty.setValue(mObject, mCurrentValue);

services/java/com/android/server/wm/WindowManagerService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ private WindowManagerService(Context context, PowerManagerService pm,
821821
mTransitionAnimationScale = Settings.Global.getFloat(context.getContentResolver(),
822822
Settings.Global.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
823823
setAnimatorDurationScale(Settings.Global.getFloat(context.getContentResolver(),
824-
Settings.Global.ANIMATOR_DURATION_SCALE, mTransitionAnimationScale));
824+
Settings.Global.ANIMATOR_DURATION_SCALE, mAnimatorDurationScale));
825825

826826
// Track changes to DevicePolicyManager state so we can enable/disable keyguard.
827827
IntentFilter filter = new IntentFilter();

0 commit comments

Comments
 (0)