SIGN IN SIGN UP

android_hardware_smoke_test: Improve reliability (#191374)

Issue https://github.com/flutter/flutter/issues/191348 shows that the
detection and retry behavior introduced in PR
https://github.com/flutter/flutter/pull/190110 did not solve the issue.

Previously, engine cache cleanup was placed solely in `@AfterClass
tearDownClass()`. When a test run failed mid-suite on attempt 1, JUnit
aborted before `@AfterClass` could run. When attempt 2 launched,
`MainActivity` retrieved the corrupted engine from cache, guaranteeing
that subsequent attempts failed with blank screenshots, which matches
what we see in the run history.

To fix this, we move cache cleanup to `MainActivity.evictEngineCache()`.
`FlutterActivityTest.kt` invokes this cleanup during class teardown and
whenever an `EglInitializationException` or `BlankScreenshotException`
occurs, ensuring any retry starts with a clean engine instance.

We also reduce the retry cap in `run_android_hardware_smoke_tests.dart`
from 3 attempts to 2 to avoid 30-minute LUCI timeouts on broken
emulators, which we saw some of in tryjobs.

I think this should be an infrastructure failure. So if an unrecoverable
EGL collapse occurs across both attempts, the runner logs an
infrastructure failure and exits with code 2 (`INFRA_FAILURE`)

We also saw some logs which suggest HWUI repeatedly attempted 10-bit
color format negotiation (`101010-2`), which fails on SwiftShader CPU
drivers. This could contribute to an increased rate of EGL errors, so
`MainActivity.onCreate()` now explicitly locks the window pixel format
to `PixelFormat.RGBA_8888`.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
A
Andy Wolff committed
e47e13183189da1fec78b6969f9ddafc6baa6b90
Parent: 247215b
Committed by GitHub <noreply@github.com> on 8/20/2026, 10:49:20 PM