Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tryget
  • Loading branch information
bitsandfoxes committed Aug 19, 2024
commit fe0ede1053e4f4267f65e55d01e1292c35b265a0
18 changes: 6 additions & 12 deletions src/Sentry/Protocol/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,9 @@ public static Device FromJson(JsonElement json)
// 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 batteryLevel = json.GetPropertyOrNull("battery_level")?.TryGetDouble(out var level) == true
? (short)level
: (short?)null;

var isCharging = json.GetPropertyOrNull("charging")?.GetBoolean();
var isOnline = json.GetPropertyOrNull("online")?.GetBoolean();
Expand All @@ -460,12 +457,9 @@ public static Device FromJson(JsonElement json)
// TODO: For next major: Remove this and change ProcessorFrequency from int to float
// The Java SDK reports the processorFrequency as `double`
// Java https://github.com/getsentry/sentry-java/blob/9762f09afa51944b40a9b77e116a55e54636e6c5/sentry/src/main/java/io/sentry/protocol/Device.java#L130
int? processorFrequency = null;
var processorFrequencyProperty = json.GetPropertyOrNull("processor_frequency");
if (processorFrequencyProperty.HasValue)
{
processorFrequency = (int)processorFrequencyProperty.Value.GetDouble();
}
var processorFrequency = json.GetPropertyOrNull("processor_frequency")?.TryGetDouble(out var frequency) == true
? (int)frequency
: (int?)null;

var deviceType = json.GetPropertyOrNull("device_type")?.GetString();
var batteryStatus = json.GetPropertyOrNull("battery_status")?.GetString();
Expand Down