Show progress on device when Android render test is running (#4119)

This commit is contained in:
Bart Louwers
2026-02-23 23:01:38 +01:00
committed by GitHub
parent 4db40f41a9
commit 4fa52298e5
8 changed files with 96 additions and 15 deletions

View File

@@ -16,7 +16,7 @@ import org.junit.runner.RunWith;
public class NativeActivityTest {
@Rule
public ActivityTestRule<NativeActivity> mActivityTestRule = new ActivityTestRule<>(NativeActivity.class, false, false);
public ActivityTestRule<RenderTestActivity> mActivityTestRule = new ActivityTestRule<>(RenderTestActivity.class, false, false);
@Test(timeout = 600000L)
public void runRenderTests() throws Exception {

View File

@@ -13,7 +13,7 @@
android:debuggable="true"
tools:ignore="HardcodedDebugMode">
<activity android:name="android.app.NativeActivity"
<activity android:name="android.app.RenderTestActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:exported="true">

View File

@@ -0,0 +1,60 @@
package android.app;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.TextView;
public class RenderTestActivity extends NativeActivity {
private TextView progressTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
progressTextView = new TextView(this);
progressTextView.setText("Starting tests...");
progressTextView.setTextSize(18f);
progressTextView.setTextColor(0xFFFFFFFF);
progressTextView.setShadowLayer(2f, 1f, 1f, 0xFF000000);
progressTextView.setPadding(24, 24, 24, 24);
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_APPLICATION_PANEL,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
PixelFormat.TRANSLUCENT
);
params.gravity = Gravity.TOP | Gravity.START;
params.token = getWindow().getDecorView().getWindowToken();
getWindowManager().addView(progressTextView, params);
}
@Override
public void onDetachedFromWindow() {
if (progressTextView != null) {
getWindowManager().removeView(progressTextView);
}
super.onDetachedFromWindow();
}
/**
* Called from C++ via JNI to update the progress display.
*/
public void updateProgress(final int completed, final int total) {
runOnUiThread(() -> {
if (progressTextView != null) {
progressTextView.setText(completed + " / " + total + " tests complete");
}
});
}
}