diff --git a/Android/lib/arm64-v8a/libbacktrace-native.so b/Android/lib/arm64-v8a/libbacktrace-native.so index e58d5342..90fffb27 100644 Binary files a/Android/lib/arm64-v8a/libbacktrace-native.so and b/Android/lib/arm64-v8a/libbacktrace-native.so differ diff --git a/Android/lib/arm64-v8a/libcrashpad_handler.so b/Android/lib/arm64-v8a/libcrashpad_handler.so index 0b9ce551..067f6ade 100644 Binary files a/Android/lib/arm64-v8a/libcrashpad_handler.so and b/Android/lib/arm64-v8a/libcrashpad_handler.so differ diff --git a/Android/lib/arm64-v8a/libnative-lib.so b/Android/lib/arm64-v8a/libnative-lib.so index 08b40861..fdc01017 100644 Binary files a/Android/lib/arm64-v8a/libnative-lib.so and b/Android/lib/arm64-v8a/libnative-lib.so differ diff --git a/Android/lib/armeabi-v7a/libbacktrace-native.so b/Android/lib/armeabi-v7a/libbacktrace-native.so index 9054fecd..bf0048ba 100644 Binary files a/Android/lib/armeabi-v7a/libbacktrace-native.so and b/Android/lib/armeabi-v7a/libbacktrace-native.so differ diff --git a/Android/lib/armeabi-v7a/libcrashpad_handler.so b/Android/lib/armeabi-v7a/libcrashpad_handler.so index 24480571..216cea2a 100644 Binary files a/Android/lib/armeabi-v7a/libcrashpad_handler.so and b/Android/lib/armeabi-v7a/libcrashpad_handler.so differ diff --git a/Android/lib/armeabi-v7a/libnative-lib.so b/Android/lib/armeabi-v7a/libnative-lib.so index 284a23cf..99d4038c 100644 Binary files a/Android/lib/armeabi-v7a/libnative-lib.so and b/Android/lib/armeabi-v7a/libnative-lib.so differ diff --git a/Android/lib/x86/libbacktrace-native.so b/Android/lib/x86/libbacktrace-native.so index 5cb6b20f..1953fe49 100644 Binary files a/Android/lib/x86/libbacktrace-native.so and b/Android/lib/x86/libbacktrace-native.so differ diff --git a/Android/lib/x86/libnative-lib.so b/Android/lib/x86/libnative-lib.so index eb2d502d..2b1219ea 100644 Binary files a/Android/lib/x86/libnative-lib.so and b/Android/lib/x86/libnative-lib.so differ diff --git a/Runtime/BacktraceClient.cs b/Runtime/BacktraceClient.cs index cd3edb9e..b3bcc6c8 100644 --- a/Runtime/BacktraceClient.cs +++ b/Runtime/BacktraceClient.cs @@ -44,6 +44,16 @@ public IBacktraceBreadcrumbs Breadcrumbs } } + private CrashDetector _crashDetector; + + public ICrashDetector CrashDetection + { + get + { + return _crashDetector; + } + } + public bool Enabled { get; private set; } private AttributeProvider _attributeProvider; @@ -566,6 +576,7 @@ public void Refresh() } _nativeClient = NativeClientFactory.CreateNativeClient(Configuration, name, _breadcrumbs, scopedAttributes, nativeAttachments); AttributeProvider.AddDynamicAttributeProvider(_nativeClient); + _crashDetector = new CrashDetector(_nativeClient as INativeCrashDetector); } } @@ -598,7 +609,7 @@ private bool EnableMetrics(bool enableIfConfigurationIsDisabled = true) public bool EnableMetrics(string uniqueAttributeName = BacktraceMetrics.DefaultUniqueAttributeName) { var universeName = Configuration.GetUniverseName(); - if(string.IsNullOrEmpty(universeName)) + if (string.IsNullOrEmpty(universeName)) { Debug.LogWarning("Cannot initialize event aggregation - Unknown Backtrace URL."); return false; diff --git a/Runtime/Model/CrashDetector.cs b/Runtime/Model/CrashDetector.cs new file mode 100644 index 00000000..ffc5cd16 --- /dev/null +++ b/Runtime/Model/CrashDetector.cs @@ -0,0 +1,33 @@ +using System; +using Backtrace.Unity.Runtime.Native; + +namespace Backtrace.Unity.Model +{ + /// + /// Backtrace Crash loop detector. This detector allows to detect possible + /// crash loops during the startup in the game. + /// + public class CrashDetector : ICrashDetector + { + private readonly INativeCrashDetector _nativeCrashDetector; + internal CrashDetector(INativeCrashDetector nativeCrashDetector) + { + _nativeCrashDetector = nativeCrashDetector; + } + + public bool EnableCrashLoopDetection() + { + return _nativeCrashDetector.EnableCrashLoopDetection(); + } + + public bool IsSafeModeRequired() + { + return _nativeCrashDetector.IsSafeModeRequired(); + } + + public int ConsecutiveCrashesCount() + { + return _nativeCrashDetector.ConsecutiveCrashesCount(); + } + } +} \ No newline at end of file diff --git a/Runtime/Model/CrashDetector.cs.meta b/Runtime/Model/CrashDetector.cs.meta new file mode 100644 index 00000000..dfb284c4 --- /dev/null +++ b/Runtime/Model/CrashDetector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9b429e7bfb9b8494c91a49e32727f4fc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Model/ICrashDetector.cs b/Runtime/Model/ICrashDetector.cs new file mode 100644 index 00000000..0567d8ef --- /dev/null +++ b/Runtime/Model/ICrashDetector.cs @@ -0,0 +1,26 @@ +using Backtrace.Unity.Model.Attributes; + +namespace Backtrace.Unity.Model +{ + /// + /// Backtrace Crash loop detector. This detector allows to detect possible + /// crash loops during the startup in the game. + /// + public interface ICrashDetector + { + /// + /// Enable crash loop detection to prevent infinity loop of crashes. + /// + bool EnableCrashLoopDetection(); + + /// + /// Determines if the safe mode is required. + /// + bool IsSafeModeRequired(); + + /// + /// Returns information how many time in a row does the application crash. + /// + int ConsecutiveCrashesCount(); + } +} diff --git a/Runtime/Model/ICrashDetector.cs.meta b/Runtime/Model/ICrashDetector.cs.meta new file mode 100644 index 00000000..f83801b0 --- /dev/null +++ b/Runtime/Model/ICrashDetector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 96823a593859b44b5a2e25ae6fb22db2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Native/Android/NativeClient.cs b/Runtime/Native/Android/NativeClient.cs index 1c285d0f..40af6540 100644 --- a/Runtime/Native/Android/NativeClient.cs +++ b/Runtime/Native/Android/NativeClient.cs @@ -18,12 +18,21 @@ namespace Backtrace.Unity.Runtime.Native.Android /// /// Android native client /// - internal sealed class NativeClient : NativeClientBase, INativeClient + internal sealed class NativeClient : NativeClientBase, INativeClient, INativeCrashDetector { private const string CallbackMethodName = "OnAnrDetected"; [DllImport("backtrace-native")] private static extern bool Initialize(IntPtr submissionUrl, IntPtr databasePath, IntPtr handlerPath, IntPtr keys, IntPtr values, IntPtr attachments, bool enableClientSideUnwinding, int unwindingMode); + [DllImport("backtrace-native")] + private static extern bool EnableCrashLoopDetectionBackend(); + + [DllImport("backtrace-native")] + private static extern bool IsSafeModeRequiredBackend(); + + [DllImport("backtrace-native")] + private static extern int ConsecutiveCrashesCountBackend(); + [DllImport("backtrace-native")] private static extern bool AddAttribute(IntPtr key, IntPtr value); @@ -380,6 +389,21 @@ public void FinishUnhandledBackgroundException() _unhandledExceptionWatcher.Call("finish"); } + public bool EnableCrashLoopDetection() + { + return EnableCrashLoopDetectionBackend(); + } + + public bool IsSafeModeRequired() + { + return IsSafeModeRequiredBackend(); + } + + public int ConsecutiveCrashesCount() + { + return ConsecutiveCrashesCountBackend(); + } + /// /// Setup Android ANR support and set callback function when ANR happened. /// diff --git a/Runtime/Native/INativeCrashDetector.cs b/Runtime/Native/INativeCrashDetector.cs new file mode 100644 index 00000000..a6e47803 --- /dev/null +++ b/Runtime/Native/INativeCrashDetector.cs @@ -0,0 +1,25 @@ +using Backtrace.Unity.Model.Attributes; + +namespace Backtrace.Unity.Runtime.Native +{ + /// + /// Backtrace native client crash detector interface + /// + internal interface INativeCrashDetector + { + /// + /// Enable crash loop detection to prevent infinity loop of crashes. + /// + bool EnableCrashLoopDetection(); + + /// + /// Determines if the safe mode is required. + /// + bool IsSafeModeRequired(); + + /// + /// Returns information how many time in a row does the application crash. + /// + int ConsecutiveCrashesCount(); + } +} diff --git a/Runtime/Native/INativeCrashDetector.cs.meta b/Runtime/Native/INativeCrashDetector.cs.meta new file mode 100644 index 00000000..0abff4e4 --- /dev/null +++ b/Runtime/Native/INativeCrashDetector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d9f037debc1c64aa1b5eea0e0021cda6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: