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

Commit d3b0e548 authored by arthurhung's avatar arthurhung
Browse files

Prevent divided by zero if animation is disable

Developer could disable window animation in developer options,
but it could lead to system crash because the transform values
may divid duration time which is set to zero.

Bug: 154894010
Test: disable animation, open simlated display, resize
Change-Id: I550c309d9f684e2a5a50b4d6812703dd20a179b5
parent d8759bb3
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -382,8 +382,8 @@ class Dimmer {


        @Override
        @Override
        public void apply(SurfaceControl.Transaction t, SurfaceControl sc, long currentPlayTime) {
        public void apply(SurfaceControl.Transaction t, SurfaceControl sc, long currentPlayTime) {
            float alpha = ((float) currentPlayTime / getDuration()) * (mToAlpha - mFromAlpha)
            final float fraction = getFraction(currentPlayTime);
                    + mFromAlpha;
            final float alpha = fraction * (mToAlpha - mFromAlpha) + mFromAlpha;
            t.setAlpha(sc, alpha);
            t.setAlpha(sc, alpha);
        }
        }


+10 −0
Original line number Original line Diff line number Diff line
@@ -130,6 +130,16 @@ class LocalAnimationAdapter implements AnimationAdapter {
         */
         */
        default boolean needsEarlyWakeup() { return false; }
        default boolean needsEarlyWakeup() { return false; }


        /**
         * @return The fraction of the animation, returns 1 if duration is 0.
         *
         * @param currentPlayTime The current play time.
         */
        default float getFraction(float currentPlayTime) {
            final float duration = getDuration();
            return duration > 0 ? currentPlayTime / duration : 1.0f;
        }

        void dump(PrintWriter pw, String prefix);
        void dump(PrintWriter pw, String prefix);


        default void dumpDebug(ProtoOutputStream proto, long fieldId) {
        default void dumpDebug(ProtoOutputStream proto, long fieldId) {
+2 −2
Original line number Original line Diff line number Diff line
@@ -646,8 +646,8 @@ class ScreenRotationAnimation {
                    @Override
                    @Override
                    public void apply(SurfaceControl.Transaction t, SurfaceControl leash,
                    public void apply(SurfaceControl.Transaction t, SurfaceControl leash,
                        long currentPlayTime) {
                        long currentPlayTime) {
                        float fraction = (float)currentPlayTime / (float)getDuration();
                        final float fraction = getFraction(currentPlayTime);
                        int color = (Integer) va.evaluate(fraction, startColor, endColor);
                        final int color = (Integer) va.evaluate(fraction, startColor, endColor);
                        Color middleColor = Color.valueOf(color);
                        Color middleColor = Color.valueOf(color);
                        rgbTmpFloat[0] = middleColor.red();
                        rgbTmpFloat[0] = middleColor.red();
                        rgbTmpFloat[1] = middleColor.green();
                        rgbTmpFloat[1] = middleColor.green();
+1 −1
Original line number Original line Diff line number Diff line
@@ -5595,7 +5595,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP


        @Override
        @Override
        public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) {
        public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) {
            final float fraction = (float) currentPlayTime / getDuration();
            final float fraction = getFraction(currentPlayTime);
            final float v = mInterpolator.getInterpolation(fraction);
            final float v = mInterpolator.getInterpolation(fraction);
            t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v,
            t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v,
                    mFrom.y + (mTo.y - mFrom.y) * v);
                    mFrom.y + (mTo.y - mFrom.y) * v);