Add workaround for android emulator as crash on Android emulation is still presented (#3310)

This commit is contained in:
Tetiana Gubanova
2025-03-20 14:44:57 +02:00
committed by GitHub
parent 92e9a46c1d
commit 52b9e3270f
8 changed files with 62 additions and 5 deletions

View File

@@ -13,6 +13,27 @@
#include "android_renderer_backend.hpp"
#include "map_renderer_runnable.hpp"
#if MLN_RENDER_BACKEND_OPENGL
#include <sys/system_properties.h>
namespace {
std::string androidSysProp(const char* key) {
assert(strlen(key) < PROP_NAME_MAX);
if (__system_property_find(key) == nullptr) {
return "";
}
char prop[PROP_VALUE_MAX + 1];
__system_property_get(key, prop);
return prop;
}
bool inEmulator() {
return androidSysProp("ro.kernel.qemu") == "1" || androidSysProp("ro.boot.qemu") == "1" ||
androidSysProp("ro.hardware.egl") == "emulation";
}
} // namespace
#endif
namespace mbgl {
namespace android {
@@ -232,6 +253,14 @@ void MapRenderer::onSurfaceCreated(JNIEnv& env, const jni::Object<AndroidSurface
renderer = std::make_unique<Renderer>(backend->getImpl(), pixelRatio, localIdeographFontFamily);
rendererRef = std::make_unique<ActorRef<Renderer>>(*renderer, mailboxData.getMailbox());
#if MLN_RENDER_BACKEND_OPENGL
// If we're running the emulator with the OpenGL backend, we're going to crash eventually,
// unless we enable this mitigation.
if (inEmulator()) {
renderer->enableAndroidEmulatorGoldfishMitigation(true);
}
#endif
backend->setSwapBehavior(swapBehaviorFlush ? gfx::Renderable::SwapBehaviour::Flush
: gfx::Renderable::SwapBehaviour::NoFlush);