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

Commit b82f5ac3 authored by Greg Kaiser's avatar Greg Kaiser
Browse files

BouncyBall: Consider NORMAL frame rate for testing

When we figure out what frame rate we're going to need from the
system at a minimum for the test, we now also consider
Display.FRAME_RATE_CATEGORY_NORMAL.

It's possible, when running in a large test suite, that the device
gets into a heated state from previous tests, and launches our app
below this NORMAL frame rate due to thermal considerations.  Rather
than test at this lower frame rate, we want to make sure we're
testing what the user would typically get as the frame rate.

Bug: 442631412
Test: Ran on a couple devices, although neither triggered the new logging statement
Flag: EXEMPT TEST_ONLY
Change-Id: I422afca5d1f21b5ffe02528eb63d34915a1de5f2
parent bb4aa207
Loading
Loading
Loading
Loading
+22 −11
Original line number Diff line number Diff line
@@ -46,10 +46,11 @@ public class BouncyBallActivity extends AppCompatActivity {

    private static final String LOG_TAG = "BouncyBall";

    // The app needs to run at at least this frame rate to be a valid test.
    // If the system defaults us to a higher frame rate, we'll test with that,
    // but we need to at least meet this rate.
    private static final float MINIMUM_FRAME_RATE = 60.0f;
    // This is the bare minimum the app needs to run at for us to consider
    // this a valid test.  We'll generally use the maximum of
    // getSuggestedFrameRate() and the rate the system launches us at.  But
    // if that maximum is less than this minimum, we'll use this minimum.
    private static final float MINIMUM_TEST_FRAME_RATE = 60.0f;

    // This test measures sustained frame rate, so it's safe to ignore
    // frame drops around the start time.
@@ -197,17 +198,27 @@ public class BouncyBallActivity extends AppCompatActivity {
        Display display = getDisplay();
        Display.Mode currentMode = display.getMode();
        mDisplayId = display.getDisplayId();
        // TODO(b/442635053): Allow switching between NORMAL and HIGH here,
        //     so we can also test against the HIGH rate.
        float minimumFrameRate =
                display.getSuggestedFrameRate(Display.FRAME_RATE_CATEGORY_NORMAL);
        if (minimumFrameRate < MINIMUM_TEST_FRAME_RATE) {
            Log.w(LOG_TAG, "getSuggestedFrameRate (" + minimumFrameRate
                    + "Hz) is below our testing minimum (" + MINIMUM_TEST_FRAME_RATE
                    + "Hz); using the latter for our minimum.");
            minimumFrameRate = MINIMUM_TEST_FRAME_RATE;
        }
        setFrameRate(currentMode.getRefreshRate());
        if (mFrameRate >= MINIMUM_FRAME_RATE) {
        if (mFrameRate >= minimumFrameRate) {
            // The default frame rate is sufficient for our testing.
            return;
        }

        String minRateStr = MINIMUM_FRAME_RATE + "Hz";
        String minRateStr = minimumFrameRate + "Hz";
        // Using a Warning here, because this seems unexpected that a device
        // defaults to running at below 60Hz.
        Log.w(LOG_TAG, "Default frame rate (" + mFrameRate
                  + "Hz) is below the acceptable minimum (" + minRateStr + ")");
        // defaults to running at below this rate.
        Log.w(LOG_TAG, "App launched with frame rate (" + mFrameRate
                  + "Hz), below the acceptable/expected minimum (" + minRateStr + ")");

        // If available at our current resolution, use 60Hz.  If not, use the
        // lowest refresh rate above 60Hz which is available.  Otherwise, throw
@@ -221,13 +232,13 @@ public class BouncyBallActivity extends AppCompatActivity {
                continue;
            }
            float rate = mode.getRefreshRate();
            if (rate == MINIMUM_FRAME_RATE) {
            if (rate == minimumFrameRate) {
                // This is exactly what we were hoping for, so we can stop
                // looking.
                preferredRate = rate;
                break;
            }
            if ((rate > MINIMUM_FRAME_RATE) && (rate < preferredRate)) {
            if ((rate > minimumFrameRate) && (rate < preferredRate)) {
                // This is the best rate we've seen so far in terms of being
                // closest to our desired rate without being under it.
                preferredRate = rate;