Skip to content

Commit

Permalink
feat: call native & java sentry close() on Android app shutdown (if r…
Browse files Browse the repository at this point in the history
…eported...)
  • Loading branch information
vaind committed Mar 4, 2022
1 parent 378f30f commit 9ed8200
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Sentry.Unity.Android/SentryJava.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,11 @@ public static class SentryJava
return jo.CallStatic<AndroidJavaObject>("isCrashedLastRun")
?.Call<bool>("booleanValue");
}

public static void Close()
{
using var jo = new AndroidJavaObject("io.sentry.Sentry");
jo.CallStatic<AndroidJavaObject>("close");
}
}
}
5 changes: 5 additions & 0 deletions src/Sentry.Unity.Android/SentryNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace Sentry.Unity.Android
/// <see href="https://github.com/getsentry/sentry-native"/>
public static class SentryNative
{
public static void Close() => sentry_close();

/// <summary>
/// Re-installs the sentry-native backend essentially retaking the signal handlers.
/// </summary>
Expand All @@ -30,6 +32,9 @@ public static class SentryNative
[DllImport("sentry")]
private static extern void sentry_reinstall_backend();

[DllImport("sentry")]
private static extern void sentry_close();

// Testing
internal static Action ReinstallSentryNativeBackendStrategy = sentry_reinstall_backend;
}
Expand Down
8 changes: 8 additions & 0 deletions src/Sentry.Unity.Android/SentryNativeAndroid.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Sentry.Extensibility;
using Sentry.Unity.Integrations;

namespace Sentry.Unity.Android
{
Expand Down Expand Up @@ -44,6 +45,13 @@ public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentry
// So we register our backend once more to make sure user-defined data is available in the crash report.
SentryNative.ReinstallBackend();
}
ApplicationAdapter.Instance.Quitting += () =>
{
options.DiagnosticLogger?.LogDebug("Closing the sentry-java SDK");
SentryJava.Close();
options.DiagnosticLogger?.LogDebug("Closing the sentry-native SDK");
SentryNative.Close();
};
}
}
}
Expand Down

0 comments on commit 9ed8200

Please sign in to comment.