From f682f9d6f5610d30a4217713ab15bcacbab48000 Mon Sep 17 00:00:00 2001
From: CarePackage17 <5157010+CarePackage17@users.noreply.github.com>
Date: Mon, 30 Jun 2025 19:17:50 +0200
Subject: [PATCH] Enable LinuxSampler to be used on Android (#37784)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This enables `background_hang_monitor` to work on Android. Relevant
Zulip thread: [#general > Android stack walking questions @
💬](https://servo.zulipchat.com/#narrow/channel/263398-general/topic/Android.20stack.20walking.20questions/near/526369883)
Testing: Manually tested on a Pixel 6a with Android 16 with following
page:
```html
Infinite Loop Test
Will it print? That is the question.
```
Fixes: #23136
---------
Signed-off-by: CarePackage17 <5157010+CarePackage17@users.noreply.github.com>
---
components/background_hang_monitor/Cargo.toml | 3 +++
components/background_hang_monitor/background_hang_monitor.rs | 3 ++-
components/background_hang_monitor/lib.rs | 2 ++
3 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/components/background_hang_monitor/Cargo.toml b/components/background_hang_monitor/Cargo.toml
index 9b389dba174..5046bd6dff8 100644
--- a/components/background_hang_monitor/Cargo.toml
+++ b/components/background_hang_monitor/Cargo.toml
@@ -29,5 +29,8 @@ mach2 = { version = "0.4", optional = true }
[target.'cfg(all(target_os = "linux", not(any(target_arch = "arm", target_arch = "aarch64", target_env = "ohos", target_env = "musl"))))'.dependencies]
nix = { workspace = true, features = ["signal"], optional = true }
+[target.'cfg(target_os = "android")'.dependencies]
+nix = { workspace = true, features = ["signal"], optional = true }
+
[features]
sampler = ["mach2", "nix"]
diff --git a/components/background_hang_monitor/background_hang_monitor.rs b/components/background_hang_monitor/background_hang_monitor.rs
index 6b9ae3b6172..68f4f39f3a4 100644
--- a/components/background_hang_monitor/background_hang_monitor.rs
+++ b/components/background_hang_monitor/background_hang_monitor.rs
@@ -97,6 +97,8 @@ impl BackgroundHangMonitorRegister for HangMonitorRegister {
let sampler = crate::sampler_windows::WindowsSampler::new_boxed();
#[cfg(all(feature = "sampler", target_os = "macos"))]
let sampler = crate::sampler_mac::MacOsSampler::new_boxed();
+ #[cfg(all(feature = "sampler", target_os = "android"))]
+ let sampler = crate::sampler_linux::LinuxSampler::new_boxed();
#[cfg(all(
feature = "sampler",
target_os = "linux",
@@ -110,7 +112,6 @@ impl BackgroundHangMonitorRegister for HangMonitorRegister {
let sampler = crate::sampler_linux::LinuxSampler::new_boxed();
#[cfg(any(
not(feature = "sampler"),
- target_os = "android",
all(
target_os = "linux",
any(
diff --git a/components/background_hang_monitor/lib.rs b/components/background_hang_monitor/lib.rs
index 8f594a7fc02..681815db090 100644
--- a/components/background_hang_monitor/lib.rs
+++ b/components/background_hang_monitor/lib.rs
@@ -17,6 +17,8 @@ mod sampler;
))
))]
mod sampler_linux;
+#[cfg(all(feature = "sampler", target_os = "android"))]
+mod sampler_linux;
#[cfg(all(feature = "sampler", target_os = "macos"))]
mod sampler_mac;
#[cfg(all(feature = "sampler", target_os = "windows"))]