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

Commit 044b72b4 authored by Jian-Syuan (Shane) Wong's avatar Jian-Syuan (Shane) Wong Committed by Android (Google) Code Review
Browse files

Merge "Boost frame rate when an insect animation is running." into main

parents af240259 e09e0dbf
Loading
Loading
Loading
Loading
+17 −3
Original line number Diff line number Diff line
@@ -2182,9 +2182,15 @@ public final class ViewRootImpl implements ViewParent,
        }
    }

    void notifyInsetsAnimationRunningStateChanged(boolean running) {
    /**
     * Notify the when the running state of a insets animation changed.
     */
    @VisibleForTesting
    public void notifyInsetsAnimationRunningStateChanged(boolean running) {
        if (sToolkitSetFrameRateReadOnlyFlagValue) {
            mInsetsAnimationRunning = running;
        }
    }

    @Override
    public void requestLayout() {
@@ -11949,7 +11955,7 @@ public final class ViewRootImpl implements ViewParent,
            return;
        }

        int frameRateCategory = mIsFrameRateBoosting
        int frameRateCategory = mIsFrameRateBoosting || mInsetsAnimationRunning
                ? FRAME_RATE_CATEGORY_HIGH : preferredFrameRateCategory;

        try {
@@ -12062,6 +12068,14 @@ public final class ViewRootImpl implements ViewParent,
        return mPreferredFrameRateCategory;
    }

    /**
     * Get the value of mLastPreferredFrameRateCategory
     */
    @VisibleForTesting
    public int getLastPreferredFrameRateCategory() {
        return mLastPreferredFrameRateCategory;
    }

    /**
     * Get the value of mPreferredFrameRate
     */
+36 −0
Original line number Diff line number Diff line
@@ -628,6 +628,42 @@ public class ViewRootImplTest {
        });
    }

    /**
     * We should boost the frame rate if the value of mInsetsAnimationRunning is true.
     */
    @Test
    @RequiresFlagsEnabled(FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY)
    public void votePreferredFrameRate_insetsAnimation() {
        View view = new View(sContext);
        WindowManager.LayoutParams wmlp = new WindowManager.LayoutParams(TYPE_APPLICATION_OVERLAY);
        wmlp.token = new Binder(); // Set a fake token to bypass 'is your activity running' check

        sInstrumentation.runOnMainSync(() -> {
            WindowManager wm = sContext.getSystemService(WindowManager.class);
            Display display = wm.getDefaultDisplay();
            DisplayMetrics metrics = new DisplayMetrics();
            display.getMetrics(metrics);
            wmlp.width = (int) (metrics.widthPixels * 0.9);
            wmlp.height = (int) (metrics.heightPixels * 0.9);
            wm.addView(view, wmlp);
        });
        sInstrumentation.waitForIdleSync();

        ViewRootImpl viewRootImpl = view.getViewRootImpl();
        sInstrumentation.runOnMainSync(() -> {
            view.invalidate();
            assertEquals(viewRootImpl.getLastPreferredFrameRateCategory(),
                    FRAME_RATE_CATEGORY_NORMAL);
            viewRootImpl.notifyInsetsAnimationRunningStateChanged(true);
            view.invalidate();
        });
        sInstrumentation.waitForIdleSync();

        sInstrumentation.runOnMainSync(() -> {
            assertEquals(viewRootImpl.getLastPreferredFrameRateCategory(),
                    FRAME_RATE_CATEGORY_HIGH);
        });
    }

    @Test
    public void forceInvertOffDarkThemeOff_forceDarkModeDisabled() {