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

Commit 1a67b761 authored by George Mount's avatar George Mount
Browse files

[VRR] Ensure frame rate is set to 0 when the value has been reset

Fixes: 338055879

When no views vote after the frame rate has been reset, the
frame rate should still be reset to 0.

Test: new test
Change-Id: I457de45cfa3cbf41558d988c130a6da02846291a
parent f0694c53
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -4262,6 +4262,10 @@ public final class ViewRootImpl implements ViewParent,
            mPreferredFrameRate = -1;
            mIsFrameRateConflicted = false;
            mFrameRateCategoryChangeReason = FRAME_RATE_CATEGORY_REASON_UNKNOWN;
        } else if (mPreferredFrameRate == 0) {
            // From MSG_FRAME_RATE_SETTING, where mPreferredFrameRate is set to 0
            setPreferredFrameRate(0);
            mPreferredFrameRate = -1;
        }
    }
+24 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import static org.junit.Assert.assertTrue;

import android.annotation.NonNull;
import android.app.Activity;
import android.app.Instrumentation;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
@@ -47,6 +48,7 @@ import android.widget.FrameLayout;

import androidx.test.annotation.UiThreadTest;
import androidx.test.filters.SmallTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;

@@ -537,6 +539,28 @@ public class ViewFrameRateTest {
        });
        waitForAfterDraw();
    }

    @Test
    @RequiresFlagsEnabled({FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY,
            FLAG_TOOLKIT_FRAME_RATE_VIEW_ENABLING_READ_ONLY
    })
    public void frameRateReset() throws Throwable {
        mMovingView.setRequestedFrameRate(120f);
        waitForFrameRateCategoryToSettle();
        mActivityRule.runOnUiThread(() -> mMovingView.setVisibility(View.INVISIBLE));

        final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();

        for (int i = 0; i < 120; i++) {
            mActivityRule.runOnUiThread(() -> {
                mMovingView.getParent().onDescendantInvalidated(mMovingView, mMovingView);
            });
            instrumentation.waitForIdleSync();
        }

        assertEquals(0f, mViewRoot.getLastPreferredFrameRate(), 0f);
    }

    private void runAfterDraw(@NonNull Runnable runnable) {
        Handler handler = new Handler(Looper.getMainLooper());
        mAfterDrawLatch = new CountDownLatch(1);