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

Commit 6a8ce5e4 authored by Greg Kaiser's avatar Greg Kaiser
Browse files

BouncyBall: Allow install on release/older devices

This app is focused towards testing and qualifying devices currently
under development built against the latest API.

However, this is also a useful tool for released devices and (mildly)
older releases.

This app does take advantage of a few APIs introduced in API level 36.
We put in workarounds for those so this app can be used on older APIs.
But we draw the line at API level 30 (Android 11 release), when the
Config.getDisplay() API was introduced.

Bug: 441133956
Test: Successfully installed and ran (automated and manually) this app on a release device on API level 35; still able to run and test on devices under development
Flag: EXEMPT TEST_ONLY
Change-Id: I0aa147ea9183f1d3e9a7204f88b076719d313c71
parent 01c50545
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -12,5 +12,13 @@ android_app {
    manifest: "app/src/main/AndroidManifest.xml",
    srcs: ["app/src/main/java/**/*.java"],
    resource_dirs: ["app/src/main/res"],
    // We want to build against the latest APIs in the tree
    sdk_version: "current",
    // We set a specific target version so this can be installed on released
    // devices for testing.
    target_sdk_version: "36",
    // Our focus is on testing more recent devices.  So we limit how far back
    // this goes.  Specifically, we only allow going back to Android 11, where
    // Context.getDisplay() was introduced.
    min_sdk_version: "30",
}
+28 −7
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.test.bouncyball;

import android.app.Activity;
import android.hardware.display.DisplayManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Trace;
import android.util.Log;
@@ -103,7 +104,14 @@ public class BouncyBallActivity extends Activity {
                    if (displayId != mDisplayId) {
                        return;
                    }
                    setFrameRate(getDisplay().getMode().getRefreshRate());
                    float frameRate = getDisplay().getMode().getRefreshRate();
                    if (frameRate == mFrameRate) {
                        // On devices with API level < 36, we might get this
                        // called for other reasons (like brightness changing).
                        // We ignore anything but frame rate changes.
                        return;
                    }
                    setFrameRate(frameRate);
                    Log.i(LOG_TAG, "Using frame rate " + mFrameRate + "Hz");
                }
            };
@@ -171,9 +179,17 @@ public class BouncyBallActivity extends Activity {
        setContentView(R.layout.activity_bouncy_ball);

        DisplayManager manager = getSystemService(DisplayManager.class);
        if (Build.VERSION.SDK_INT >= 36) {
            // We prefer this newer API, introduced at API level 36.
            manager.registerDisplayListener(Executors.newSingleThreadExecutor(),
                                            DisplayManager.EVENT_TYPE_DISPLAY_REFRESH_RATE,
                                            mDisplayListener);
        } else {
            // We don't need a separate Handler because our listener logic is
            // cheap, and for valid tests only gets invoked before we're looking
            // for dropped frames.
            manager.registerDisplayListener(mDisplayListener, null);
        }

        initFrameRate();
        mChoreographer = Choreographer.getInstance();
@@ -197,10 +213,15 @@ public class BouncyBallActivity extends Activity {
        Display display = getDisplay();
        Display.Mode currentMode = display.getMode();
        mDisplayId = display.getDisplayId();
        float minimumFrameRate = MINIMUM_TEST_FRAME_RATE;
        if (Build.VERSION.SDK_INT >= 36) {
            // This API wasn't introduced until API level 36, so for testing
            // on older devices, we'll just stick with our MINIMUM.
            // TODO(b/442635053): Allow switching between NORMAL and HIGH here,
            //     so we can also test against the HIGH rate.
        float minimumFrameRate =
            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