From 416bf2a05848fb8e009f2e19e831d3d871e5e2e4 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Wed, 15 Jan 2025 18:57:31 +0100 Subject: [PATCH] more timeouts --- .../Scripts/SentryOptionConfiguration.cs | 55 +------------------ src/Sentry.Unity.Android/SentryJava.cs | 12 ++-- .../SentryNativeAndroid.cs | 10 +++- .../TestSentryJava.cs | 4 +- 4 files changed, 15 insertions(+), 66 deletions(-) diff --git a/samples/unity-of-bugs/Assets/Scripts/SentryOptionConfiguration.cs b/samples/unity-of-bugs/Assets/Scripts/SentryOptionConfiguration.cs index f2e55ba92..863144aaf 100644 --- a/samples/unity-of-bugs/Assets/Scripts/SentryOptionConfiguration.cs +++ b/samples/unity-of-bugs/Assets/Scripts/SentryOptionConfiguration.cs @@ -8,59 +8,6 @@ public override void Configure(SentryUnityOptions options) { // Here you can programmatically modify the Sentry option properties used for the SDK's initialization -#if UNITY_ANDROID || UNITY_IOS - // NOTE! - // On Android and iOS, ALL options configured here will be "baked" into the exported project - // during the build process. - // Changes to the options at runtime will not affect the native SDKs (Java, C/C++, Objective-C) - // and only apply to the C# layer. - - /* - * Sentry Unity SDK - Hybrid Architecture - * ====================================== - * - * Build Time Runtime - * ┌─────────────────────────┐ ┌─────────────────────────┐ - * │ Unity Editor │ │ Game Startup │ - * └──────────┬──────────────┘ └───────────┬─────────────┘ - * │ │ - * ▼ ▼ - * ┌────────────────────────────────────────────────────────────┐ - * │ Options Configuration │ - * │ (This Method) │ - * └─────────────────────────────┬──────────────────────────────┘ - * │ - * ┌───────────────────────────────────┐ - * │ Options used for Init │ - * ▼ ▼ - * ┌──────────────────────────┐ ┌──────────────────────┐ - * │ Native SDK │ │ Unity C# SDK │ - * │ Android & iOS │ │ Initialization │ - * │ ┌────────────────────┐ │ └──────────────────────┘ - * │ │ Options "Baked in" │ │ - * │ └────────────────────┘ │ - * │ The configure call made │ - * │ for this part ran on │ - * │ your build-machine │ - * └──────────────────────────┘ - * │ - * ▼ - * ┌──────────────────────────┐ - * │ Native SDK │ - * │ Android & iOS │ - * └──────────────────────────┘ - */ - - // Works as expected and will enable all debug logging - // options.Debug = true; - - // Will NOT work as expected. - // This will run twice. - // 1. Once during the build, being baked into the native SDKs - // 2. And a second time every time when the game starts - // options.Release = ComputeVersion(); -#endif - Debug.Log("OptionConfigure started."); // Making sure the SDK is not already initialized during tests @@ -83,7 +30,7 @@ public override void Configure(SentryUnityOptions options) return sentryEvent; }); - options.IosNativeInitializationType = NativeInitializationType.BuildTime; + options.AndroidNativeInitializationType = NativeInitializationType.Runtime; Debug.Log("OptionConfigure finished."); } diff --git a/src/Sentry.Unity.Android/SentryJava.cs b/src/Sentry.Unity.Android/SentryJava.cs index 6f047f586..679be6d71 100644 --- a/src/Sentry.Unity.Android/SentryJava.cs +++ b/src/Sentry.Unity.Android/SentryJava.cs @@ -8,8 +8,8 @@ namespace Sentry.Unity.Android; internal interface ISentryJava { - public bool IsEnabled(IJniExecutor jniExecutor); - public bool Init(IJniExecutor jniExecutor, SentryUnityOptions options, TimeSpan timeout); + public bool IsEnabled(IJniExecutor jniExecutor, TimeSpan timeout); + public void Init(IJniExecutor jniExecutor, SentryUnityOptions options, TimeSpan timeout); public string? GetInstallationId(IJniExecutor jniExecutor); public bool? CrashedLastRun(IJniExecutor jniExecutor); public void Close(IJniExecutor jniExecutor); @@ -45,16 +45,16 @@ internal class SentryJava : ISentryJava { private static AndroidJavaObject GetSentryJava() => new AndroidJavaClass("io.sentry.Sentry"); - public bool IsEnabled(IJniExecutor jniExecutor) + public bool IsEnabled(IJniExecutor jniExecutor, TimeSpan timeout) { return jniExecutor.Run(() => { using var sentry = GetSentryJava(); return sentry.CallStatic("isEnabled"); - }); + }, timeout); } - public bool Init(IJniExecutor jniExecutor, SentryUnityOptions options, TimeSpan timeout) + public void Init(IJniExecutor jniExecutor, SentryUnityOptions options, TimeSpan timeout) { jniExecutor.Run(() => { @@ -97,8 +97,6 @@ public bool Init(IJniExecutor jniExecutor, SentryUnityOptions options, TimeSpan androidOptions.Call("setEnableScopePersistence", false); }, options.DiagnosticLogger)); }, timeout); - - return IsEnabled(jniExecutor); } internal class AndroidOptionsConfiguration : AndroidJavaProxy diff --git a/src/Sentry.Unity.Android/SentryNativeAndroid.cs b/src/Sentry.Unity.Android/SentryNativeAndroid.cs index 77fcbbc67..1c6b2e705 100644 --- a/src/Sentry.Unity.Android/SentryNativeAndroid.cs +++ b/src/Sentry.Unity.Android/SentryNativeAndroid.cs @@ -43,16 +43,20 @@ public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentry options.DiagnosticLogger?.LogDebug("Checking whether the Android SDK has already been initialized"); - if (SentryJava.IsEnabled(JniExecutor)) + if (SentryJava.IsEnabled(JniExecutor, TimeSpan.FromMilliseconds(200))) { options.DiagnosticLogger?.LogDebug("The Android SDK is already initialized"); } else { - options.DiagnosticLogger?.LogDebug("Initializing the Android SDK"); + options.DiagnosticLogger?.LogInfo("Initializing the Android SDK"); // Local testing had Init at an average of about 25ms. - if (!SentryJava.Init(JniExecutor, options, TimeSpan.FromMilliseconds(200))) + SentryJava.Init(JniExecutor, options, TimeSpan.FromMilliseconds(200)); + + options.DiagnosticLogger?.LogDebug("Validating Android SDK initialization"); + + if (!SentryJava.IsEnabled(JniExecutor, TimeSpan.FromMilliseconds(200))) { options.DiagnosticLogger?.LogError("Failed to initialize Android Native Support"); return; diff --git a/test/Sentry.Unity.Android.Tests/TestSentryJava.cs b/test/Sentry.Unity.Android.Tests/TestSentryJava.cs index 6df74c584..16cb0fd97 100644 --- a/test/Sentry.Unity.Android.Tests/TestSentryJava.cs +++ b/test/Sentry.Unity.Android.Tests/TestSentryJava.cs @@ -10,9 +10,9 @@ internal class TestSentryJava : ISentryJava public string? InstallationId { get; set; } public bool? IsCrashedLastRun { get; set; } - public bool IsEnabled(IJniExecutor jniExecutor) => Enabled; + public bool IsEnabled(IJniExecutor jniExecutor, TimeSpan timeout) => Enabled; - public bool Init(IJniExecutor jniExecutor, SentryUnityOptions options, TimeSpan timeout) => InitSuccessful; + public void Init(IJniExecutor jniExecutor, SentryUnityOptions options, TimeSpan timeout) { } public string? GetInstallationId(IJniExecutor jniExecutor) => InstallationId;