diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e4fc23c7..946d39dc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/src/Sentry.Unity.Android/NativeContextWriter.cs b/src/Sentry.Unity.Android/NativeContextWriter.cs index 7a4162145..9f688adc3 100644 --- a/src/Sentry.Unity.Android/NativeContextWriter.cs +++ b/src/Sentry.Unity.Android/NativeContextWriter.cs @@ -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, @@ -67,6 +66,8 @@ protected override void WriteScope( GpuMultiThreadedRendering, GpuGraphicsShaderLevel); + CWUtil.WriteApp(AppStartTime, AppBuildType); + CWUtil.WriteGpu( GpuId, GpuName, diff --git a/src/Sentry.Unity.Android/SentryJava.cs b/src/Sentry.Unity.Android/SentryJava.cs index 883bdc2aa..91e7055b3 100644 --- a/src/Sentry.Unity.Android/SentryJava.cs +++ b/src/Sentry.Unity.Android/SentryJava.cs @@ -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, @@ -212,6 +214,8 @@ public void Init(SentryUnityOptions options) } public void WriteScope( + string? AppStartTime, + string? AppBuildType, int? GpuId, string? GpuName, string? GpuVendorName, @@ -230,6 +234,10 @@ public void WriteScope( { RunJniSafe(() => { + using var app = new AndroidJavaObject("io.sentry.protocol.App"); + app.SetIfNotNull("appStartTime", AppStartTime); + app.SetIfNotNull("buildType", AppBuildType); + using var gpu = new AndroidJavaObject("io.sentry.protocol.Gpu"); gpu.SetIfNotNull("name", GpuName); gpu.SetIfNotNull("id", GpuId); @@ -244,6 +252,7 @@ public void WriteScope( sentry.CallStatic("configureScope", new ScopeCallback(scope => { using var contexts = scope.Call("getContexts"); + contexts.Call("setApp", app); contexts.Call("setGpu", gpu); })); }); diff --git a/test/IntegrationTest/CommonTestCases.ps1 b/test/IntegrationTest/CommonTestCases.ps1 index db1245362..51099ffb8 100644 --- a/test/IntegrationTest/CommonTestCases.ps1 +++ b/test/IntegrationTest/CommonTestCases.ps1 @@ -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 } } diff --git a/test/Sentry.Unity.Android.Tests/TestSentryJava.cs b/test/Sentry.Unity.Android.Tests/TestSentryJava.cs index a5c44e1bb..08dbe299c 100644 --- a/test/Sentry.Unity.Android.Tests/TestSentryJava.cs +++ b/test/Sentry.Unity.Android.Tests/TestSentryJava.cs @@ -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,