From e9285285c7a47b28a0b5b35c0583690c7efff608 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 30 Nov 2026 11:37:19 +0100 Subject: [PATCH 1/4] fix(android): OS context in crash daemon events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Inproc crashes are sent from the outbox by the Android SDK, which replaces the OS context. The crash daemon sends its events itself, so they reported `uname`, e.g. `Linux 6.1.162`. Report Android as the OS with the same values as the Android SDK: | Field | Before | After | Note | |------------------|---------------|-------------------|----------------------------| | `name` | `Linux` | `Android` | | | `version` | `6.1.162` | `17` | `ro.build.version.release` | | `build` | `android14-…` | `CP3A.261005.005` | `ro.build.display.id` | | `kernel_version` | | `6.1.162-…` | `uname` release | --- src/sentry_os.c | 30 ++++++++++++++++++++++++++++++ tests/unit/test_utils.c | 20 ++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/sentry_os.c b/src/sentry_os.c index 53831d3787..6bad9260a6 100644 --- a/src/sentry_os.c +++ b/src/sentry_os.c @@ -20,6 +20,9 @@ # include # include #endif +#ifdef SENTRY_PLATFORM_ANDROID +# include +#endif #if defined(SENTRY_PLATFORM_LINUX) || defined(SENTRY_PLATFORM_ANDROID) ssize_t @@ -1023,6 +1026,27 @@ static # endif // defined(SENTRY_PLATFORM_LINUX) +# if defined(SENTRY_PLATFORM_ANDROID) +// Android is reported as the OS itself, like the Android SDK does. +static bool +set_os_android(sentry_value_t os, const char *release) +{ + char version[PROP_VALUE_MAX]; + if (__system_property_get("ro.build.version.release", version) <= 0) { + return false; + } + sentry_value_set_by_key(os, "name", sentry_value_new_string("Android")); + sentry_value_set_by_key(os, "version", sentry_value_new_string(version)); + char build[PROP_VALUE_MAX]; + if (__system_property_get("ro.build.display.id", build) > 0) { + sentry_value_set_by_key(os, "build", sentry_value_new_string(build)); + } + sentry_value_set_by_key( + os, "kernel_version", sentry_value_new_string(release)); + return true; +} +# endif + sentry_value_t sentry__get_os_context(void) { @@ -1036,6 +1060,12 @@ sentry__get_os_context(void) goto fail; } +# if defined(SENTRY_PLATFORM_ANDROID) + if (set_os_android(os, uts.release)) { + return os; + } +# endif + if (!set_os_uname(os, uts.sysname, uts.release)) { goto fail; } diff --git a/tests/unit/test_utils.c b/tests/unit/test_utils.c index 85ce19e539..aea173d2b9 100644 --- a/tests/unit/test_utils.c +++ b/tests/unit/test_utils.c @@ -12,6 +12,11 @@ # include "sentry_unix_pageallocator.h" #endif +#ifdef SENTRY_PLATFORM_ANDROID +# include +# include +#endif + #ifdef SENTRY_PLATFORM_WINDOWS # define setenv(k, v, o) _putenv_s(k, v) # define unsetenv(k) _putenv_s(k, "") @@ -462,6 +467,21 @@ SENTRY_TEST(os) == SENTRY_VALUE_TYPE_STRING); #endif +#ifdef SENTRY_PLATFORM_ANDROID + char version[PROP_VALUE_MAX]; + TEST_ASSERT(__system_property_get("ro.build.version.release", version) > 0); + struct utsname uts; + TEST_ASSERT(uname(&uts) == 0); + TEST_CHECK_STRING_EQUAL( + sentry_value_as_string(sentry_value_get_by_key(os, "name")), "Android"); + TEST_CHECK_STRING_EQUAL( + sentry_value_as_string(sentry_value_get_by_key(os, "version")), + version); + TEST_CHECK_STRING_EQUAL( + sentry_value_as_string(sentry_value_get_by_key(os, "kernel_version")), + uts.release); +#endif + sentry_value_decref(os); } From 315ac260f7d82f354e2231b48aed36b84725e5ce Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 30 Nov 2026 12:05:47 +0100 Subject: [PATCH 2/4] fix(android): Device context in crash daemon events Inproc crashes are sent from the outbox by the Android SDK, which adds the device context. The crash daemon sends its events itself, so they had none. Add the same static fields as the Android SDK: | Field | Example | Source | |----------------|-------------------|---------------------------| | `manufacturer` | `Google` | `ro.product.manufacturer` | | `brand` | `google` | `ro.product.brand` | | `model` | `Pixel 8 Pro` | `ro.product.model` | | `model_id` | `CP3A.261005.005` | `ro.build.id` | | `family` | `Pixel` | first word of `model` | --- src/backends/native/sentry_crash_daemon.c | 48 +++++++++++++++++++++++ tests/test_integration_android.py | 29 +++++++++++--- 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/src/backends/native/sentry_crash_daemon.c b/src/backends/native/sentry_crash_daemon.c index 7d983e2db9..317f3a5d7e 100644 --- a/src/backends/native/sentry_crash_daemon.c +++ b/src/backends/native/sentry_crash_daemon.c @@ -55,6 +55,9 @@ # if defined(SENTRY_PLATFORM_LINUX) # include "unwinder/sentry_unwinder.h" # endif +# if defined(SENTRY_PLATFORM_ANDROID) +# include +# endif # if defined(SENTRY_PLATFORM_LINUX) || defined(SENTRY_PLATFORM_ANDROID) /** * Read one logical line of `/proc//maps`. A pathname longer than the @@ -4186,6 +4189,49 @@ ensure_device_arch(sentry_value_t event) } #endif +#if defined(SENTRY_PLATFORM_ANDROID) +static void +set_device_property(sentry_value_t device, const char *key, const char *name) +{ + char value[PROP_VALUE_MAX]; + if (__system_property_get(name, value) > 0) { + sentry_value_set_by_key(device, key, sentry_value_new_string(value)); + } +} + +// The Android SDK adds the device context only to the crashes it sends from +// the outbox, so synthesize the same static fields for the daemon's events. +static void +ensure_device_context(sentry_value_t event) +{ + sentry_value_t contexts = sentry_value_get_by_key(event, "contexts"); + if (sentry_value_is_null(contexts)) { + contexts = sentry_value_new_object(); + if (sentry_value_set_by_key(event, "contexts", contexts) != 0) { + return; + } + } + if (!sentry_value_is_null(sentry_value_get_by_key(contexts, "device"))) { + return; + } + sentry_value_t device = sentry_value_new_object(); + sentry_value_set_by_key(device, "type", sentry_value_new_string("device")); + set_device_property(device, "manufacturer", "ro.product.manufacturer"); + set_device_property(device, "brand", "ro.product.brand"); + set_device_property(device, "model", "ro.product.model"); + set_device_property(device, "model_id", "ro.build.id"); + const char *model + = sentry_value_as_string(sentry_value_get_by_key(device, "model")); + if (model[0] != '\0') { + const char *space = strchr(model, ' '); + sentry_value_set_by_key(device, "family", + sentry_value_new_string_n( + model, space ? (size_t)(space - model) : strlen(model))); + } + sentry_value_set_by_key(contexts, "device", device); +} +#endif + /** * Removes the crash envelope once the transport has sent or dumped the crash, * or renames it for a later send. Either way, it also removes the crash event, @@ -4328,6 +4374,8 @@ sentry__process_crash(const sentry_options_t *options, sentry_crash_ipc_t *ipc, } #if defined(SENTRY_PLATFORM_WINDOWS) ensure_device_arch(base); +#elif defined(SENTRY_PLATFORM_ANDROID) + ensure_device_context(base); #endif // Apply the app's current upload gate (user consent, offline mode) before diff --git a/tests/test_integration_android.py b/tests/test_integration_android.py index f38ec242c1..e676aa8a4a 100644 --- a/tests/test_integration_android.py +++ b/tests/test_integration_android.py @@ -2,7 +2,7 @@ import pytest -from . import adb, run +from . import Envelope, adb, run from .conditions import has_native, is_android, is_asan, is_tsan pytestmark = pytest.mark.skipif( @@ -18,13 +18,13 @@ def test_native_android(cmake): database_path = "/data/local/tmp/.sentry-native" - def find_minidumps(timeout=30 if is_asan or is_tsan else 10): + def find_run_files(pattern, timeout=30 if is_asan or is_tsan else 10): deadline = time.time() + timeout last_result = None while last_result is None or time.time() < deadline: last_result = adb( "shell", - f'for f in {database_path}/*.run/__sentry-crash.dmp; do [ -f "$f" ] && echo "$f"; done', + f'for f in {database_path}/*.run/{pattern}; do [ -f "$f" ] && echo "$f"; done', capture_output=True, text=True, check=False, @@ -47,16 +47,35 @@ def find_minidumps(timeout=30 if is_asan or is_tsan else 10): ) adb("shell", f"rm -rf {database_path}", check=True) - assert find_minidumps(timeout=0) == [] + assert find_run_files("__sentry-crash.dmp", timeout=0) == [] try: run(tmp_path, "sentry_test_integration", ["log", "crash"], expect_failure=True) - minidumps = find_minidumps() + minidumps = find_run_files("__sentry-crash.dmp") assert minidumps, "native backend should create a minidump on Android" local_minidump = tmp_path / "android.dmp" adb("pull", minidumps[0], str(local_minidump), check=True, capture_output=True) assert local_minidump.stat().st_size > 0 + + envelopes = find_run_files("*.envelope") + assert envelopes, "native backend should create a crash envelope on Android" + + local_envelope = tmp_path / "android.envelope" + adb("pull", envelopes[0], str(local_envelope), check=True, capture_output=True) + event = Envelope.deserialize(local_envelope.read_bytes()).get_event() + + def getprop(name): + return adb( + "shell", "getprop", name, capture_output=True, text=True, check=True + ).stdout.strip() + + device = event["contexts"]["device"] + assert device["manufacturer"] == getprop("ro.product.manufacturer") + assert device["brand"] == getprop("ro.product.brand") + assert device["model"] == getprop("ro.product.model") + assert device["model_id"] == getprop("ro.build.id") + assert device["family"] == device["model"].split(" ")[0] finally: adb("shell", f"rm -rf {database_path}", check=False) From 4f706f45eaeff07547fae9182cee8a80c0924ae8 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 30 Nov 2026 15:48:32 +0100 Subject: [PATCH 3/4] test(android): Verify OS and device contexts in E2E crashes --- tests/test_e2e_sentry.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_e2e_sentry.py b/tests/test_e2e_sentry.py index 7d46116a0e..0d45725322 100644 --- a/tests/test_e2e_sentry.py +++ b/tests/test_e2e_sentry.py @@ -1069,6 +1069,22 @@ def assert_android_native_event( assert event["release"]["version"] == "sentry-native-e2e" assert event["user"]["id"] == test_id + def getprop(name): + return adb( + "shell", "getprop", name, capture_output=True, text=True, check=True + ).stdout.strip() + + contexts = event["contexts"] + assert contexts["os"]["name"] == "Android" + assert contexts["os"]["version"] == getprop("ro.build.version.release") + assert contexts["os"]["build"] == getprop("ro.build.display.id") + assert contexts["os"]["kernel_version"] + assert contexts["device"]["manufacturer"] == getprop("ro.product.manufacturer") + assert contexts["device"]["brand"] == getprop("ro.product.brand") + assert contexts["device"]["model"] == getprop("ro.product.model") + assert contexts["device"]["model_id"] == getprop("ro.build.id") + assert contexts["device"]["family"] == contexts["device"]["model"].split(" ")[0] + exception = get_exception_from_event(event)["values"][0] mechanism = exception["mechanism"] assert mechanism["handled"] is False From 4aec0f5dd8602eeb3a5e7dc6d3c25044ca7e1018 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 30 Nov 2026 12:08:16 +0100 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0dead1378..b7ea253f08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Drop the outdated 1 GiB size limit for TUS attachment uploads. ([#2352](https://github.com/getsentry/sentry-native/pull/2352)) - Native: detect daemon startup failure to avoid a 10s stall in `sentry_init` on Windows and Linux. ([#2349](https://github.com/getsentry/sentry-native/pull/2349)) +- Native/Android: fix the OS and device contexts in out-of-process crashes. ([#2354](https://github.com/getsentry/sentry-native/pull/2354)) ## 1.0.0-beta.2