diff --git a/CHANGELOG.md b/CHANGELOG.md index 61f72fdd0d..20b0bffb91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Fixes +- On mobile devices, the SDK no longer throws a `FormatException` when trying to report native events ([#3485](https://github.com/getsentry/sentry-dotnet/pull/3485)) - Race condition in `SentryMessageHandler` ([#3477](https://github.com/getsentry/sentry-dotnet/pull/3477)) - Decrease runtime diagnostics circular buffer when profiling, reducing memory usage ([#3491](https://github.com/getsentry/sentry-dotnet/pull/3491)) diff --git a/src/Sentry/Protocol/Device.cs b/src/Sentry/Protocol/Device.cs index 83ef566ed4..a2486af5d0 100644 --- a/src/Sentry/Protocol/Device.cs +++ b/src/Sentry/Protocol/Device.cs @@ -426,7 +426,18 @@ public static Device FromJson(JsonElement json) var model = json.GetPropertyOrNull("model")?.GetString(); var modelId = json.GetPropertyOrNull("model_id")?.GetString(); var architecture = json.GetPropertyOrNull("arch")?.GetString(); - var batteryLevel = json.GetPropertyOrNull("battery_level")?.GetInt16(); + + // TODO: For next major: Remove this and change batteryLevel from short to float + // The Java and Cocoa SDK report the battery as `float` + // Cocoa https://github.com/getsentry/sentry-cocoa/blob/e773cad622b86735f1673368414009475e4119fd/Sources/Sentry/include/SentryUIDeviceWrapper.h#L18 + // Java https://github.com/getsentry/sentry-java/blob/25f1ca4e1636a801c17c1662f0145f888550bce8/sentry/src/main/java/io/sentry/protocol/Device.java#L231-L233 + short? batteryLevel = null; + var batteryProperty = json.GetPropertyOrNull("battery_level"); + if (batteryProperty.HasValue) + { + batteryLevel = (short)batteryProperty.Value.GetDouble(); + } + var isCharging = json.GetPropertyOrNull("charging")?.GetBoolean(); var isOnline = json.GetPropertyOrNull("online")?.GetBoolean(); var orientation = json.GetPropertyOrNull("orientation")?.GetString()?.ParseEnum();