Made emulator check more thorough (#174731)

fixes https://github.com/flutter/flutter/issues/169931

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [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 `///`).
- [ ] 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.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[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

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
gaaclarke 2025-09-02 10:31:02 -07:00 committed by GitHub
parent 1d19f97833
commit 432cfa62ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,6 +11,8 @@
#include "flutter/impeller/base/validation.h"
#include "shell/platform/android/android_rendering_selector.h"
namespace fs = std::filesystem;
namespace flutter {
namespace {
@ -38,8 +40,27 @@ static constexpr const char* kBadSocs[] = {
"exynos9825" //
};
static bool IsDeviceEmulator(std::string_view product_model) {
return std::string(product_model).find("gphone") != std::string::npos;
static bool IsDeviceEmulator() {
char property[PROP_VALUE_MAX];
__system_property_get("ro.hardware", property);
std::string_view hardware_prop(property);
if (hardware_prop == "goldfish" || hardware_prop == "ranchu" ||
hardware_prop == "qemu") {
return true;
}
__system_property_get("ro.product.model", property);
std::string_view model_prop(property);
if (model_prop.find("gphone") != std::string::npos) {
return true;
}
if (::access("/dev/qemu_pipe", F_OK) == 0) {
return true;
}
return false;
}
static bool IsKnownBadSOC(std::string_view hardware) {
@ -64,15 +85,14 @@ GetActualRenderingAPIForImpeller(
// Even if this check returns true, Impeller may determine it cannot use
// Vulkan for some other reason, such as a missing required extension or
// feature. In these cases it will use OpenGLES.
char product_model[PROP_VALUE_MAX];
__system_property_get("ro.product.model", product_model);
if (IsDeviceEmulator(product_model)) {
if (IsDeviceEmulator()) {
// Avoid using Vulkan on known emulators.
return nullptr;
}
__system_property_get("ro.com.google.clientidbase", product_model);
if (strcmp(product_model, kAndroidHuawei) == 0) {
char property[PROP_VALUE_MAX];
__system_property_get("ro.com.google.clientidbase", property);
if (strcmp(property, kAndroidHuawei) == 0) {
// Avoid using Vulkan on Huawei as AHB imports do not
// consistently work.
return nullptr;
@ -85,8 +105,8 @@ GetActualRenderingAPIForImpeller(
return nullptr;
}
__system_property_get("ro.product.board", product_model);
if (IsKnownBadSOC(product_model)) {
__system_property_get("ro.product.board", property);
if (IsKnownBadSOC(property)) {
FML_LOG(INFO)
<< "Known bad Vulkan driver encountered, falling back to OpenGLES.";
return nullptr;