Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixes

- When targeting Android, the SDK now syncs `AppStartTime` and `AppBuildType` to the native layer ([#2557](https://github.com/getsentry/sentry-unity/pull/2557))
- When targeting Switch, the SDK will no longer cause the build to fail when native libraries are missing but log a warning instead ([#2541](https://github.com/getsentry/sentry-unity/pull/2541))
- The SDK no longer wrongly disables the org slug field based on assumed the auth-tolken type ([#2537](https://github.com/getsentry/sentry-unity/pull/2537))

Expand Down
7 changes: 4 additions & 3 deletions src/Sentry.Unity.Android/NativeContextWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ protected override void WriteScope(
string? UnityRenderingThreadingMode
)
{
// We're only setting the missing contexts, the rest is configured by sentry-java. We could also sync
// the "unity" context, but it doesn't seem so useful and the effort to do is larger because there's no
// class for it in Java - not sure how we could add a generic context object in Java...
_sentryJava.WriteScope(
AppStartTime,
AppBuildType,
GpuId,
GpuName,
GpuVendorName,
Expand All @@ -67,6 +66,8 @@ protected override void WriteScope(
GpuMultiThreadedRendering,
GpuGraphicsShaderLevel);

CWUtil.WriteApp(AppStartTime, AppBuildType);

CWUtil.WriteGpu(
GpuId,
GpuName,
Expand Down
9 changes: 9 additions & 0 deletions src/Sentry.Unity.Android/SentryJava.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ internal interface ISentryJava
public bool? CrashedLastRun();
public void Close();
public void WriteScope(
string? AppStartTime,
string? AppBuildType,
int? GpuId,
string? GpuName,
string? GpuVendorName,
Expand Down Expand Up @@ -212,6 +214,8 @@ public void Init(SentryUnityOptions options)
}

public void WriteScope(
string? AppStartTime,
string? AppBuildType,
int? GpuId,
string? GpuName,
string? GpuVendorName,
Expand All @@ -230,6 +234,10 @@ public void WriteScope(
{
RunJniSafe(() =>
{
using var app = new AndroidJavaObject("io.sentry.protocol.App");
app.SetIfNotNull("appStartTime", AppStartTime);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String set on likely Date-typed Java field via JNI

Medium Severity

The appStartTime field on io.sentry.protocol.App in the sentry-java SDK is typically a Date type, but SetIfNotNull("appStartTime", AppStartTime) passes an ISO 8601 string. Since no valueClass is provided, SetIfNotNull calls javaObject.Set(property, value!) directly, which uses a String JNI signature. If the actual field type is Date, this would either fail at JNI field resolution (crashing the entire RunJniSafe lambda, which also prevents GPU context from syncing — a regression) or silently corrupt the field causing a ClassCastException during serialization. The buildType field is fine since it's a String in Java.

Fix in Cursor Fix in Web

app.SetIfNotNull("buildType", AppBuildType);

using var gpu = new AndroidJavaObject("io.sentry.protocol.Gpu");
gpu.SetIfNotNull("name", GpuName);
gpu.SetIfNotNull("id", GpuId);
Expand All @@ -244,6 +252,7 @@ public void WriteScope(
sentry.CallStatic("configureScope", new ScopeCallback(scope =>
{
using var contexts = scope.Call<AndroidJavaObject>("getContexts");
contexts.Call("setApp", app);
contexts.Call("setGpu", gpu);
}));
});
Expand Down
6 changes: 0 additions & 6 deletions test/IntegrationTest/CommonTestCases.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,6 @@ $CommonTestCases = @(
}
@{ Name = "Contains app context"; TestBlock = {
param($TestSetup, $TestType, $SentryEvent, $RunResult)

if ($TestType -eq "crash-capture") {
Set-ItResult -Skipped -Because "app context is not synced to sentry-native on Android"
return
}

$SentryEvent.contexts.app | Should -Not -BeNullOrEmpty
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/Sentry.Unity.Android.Tests/TestSentryJava.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public void Init(SentryUnityOptions options) { }
public void Close() { }

public void WriteScope(
string? AppStartTime,
string? AppBuildType,
int? GpuId,
string? GpuName,
string? GpuVendorName,
Expand Down
Loading