Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash loop detection support #178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Binary file modified Android/lib/arm64-v8a/libbacktrace-native.so
Binary file not shown.
Binary file modified Android/lib/arm64-v8a/libcrashpad_handler.so
Binary file not shown.
Binary file modified Android/lib/arm64-v8a/libnative-lib.so
Binary file not shown.
Binary file modified Android/lib/armeabi-v7a/libbacktrace-native.so
Binary file not shown.
Binary file modified Android/lib/armeabi-v7a/libcrashpad_handler.so
Binary file not shown.
Binary file modified Android/lib/armeabi-v7a/libnative-lib.so
Binary file not shown.
Binary file modified Android/lib/x86/libbacktrace-native.so
Binary file not shown.
Binary file modified Android/lib/x86/libnative-lib.so
Binary file not shown.
13 changes: 12 additions & 1 deletion Runtime/BacktraceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -566,6 +576,7 @@ public void Refresh()
}
_nativeClient = NativeClientFactory.CreateNativeClient(Configuration, name, _breadcrumbs, scopedAttributes, nativeAttachments);
AttributeProvider.AddDynamicAttributeProvider(_nativeClient);
_crashDetector = new CrashDetector(_nativeClient as INativeCrashDetector);
}
}

Expand Down Expand Up @@ -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;
Expand Down
33 changes: 33 additions & 0 deletions Runtime/Model/CrashDetector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using Backtrace.Unity.Runtime.Native;

namespace Backtrace.Unity.Model
{
/// <summary>
/// Backtrace Crash loop detector. This detector allows to detect possible
/// crash loops during the startup in the game.
/// </summary>
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();
}
}
}
11 changes: 11 additions & 0 deletions Runtime/Model/CrashDetector.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions Runtime/Model/ICrashDetector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Backtrace.Unity.Model.Attributes;

namespace Backtrace.Unity.Model
{
/// <summary>
/// Backtrace Crash loop detector. This detector allows to detect possible
/// crash loops during the startup in the game.
/// </summary>
public interface ICrashDetector
{
/// <summary>
/// Enable crash loop detection to prevent infinity loop of crashes.
/// </summary>
bool EnableCrashLoopDetection();

/// <summary>
/// Determines if the safe mode is required.
/// </summary>
bool IsSafeModeRequired();

/// <summary>
/// Returns information how many time in a row does the application crash.
/// </summary>
int ConsecutiveCrashesCount();
}
}
11 changes: 11 additions & 0 deletions Runtime/Model/ICrashDetector.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 25 additions & 1 deletion Runtime/Native/Android/NativeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@ namespace Backtrace.Unity.Runtime.Native.Android
/// <summary>
/// Android native client
/// </summary>
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);

Expand Down Expand Up @@ -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();
}

/// <summary>
/// Setup Android ANR support and set callback function when ANR happened.
/// </summary>
Expand Down
25 changes: 25 additions & 0 deletions Runtime/Native/INativeCrashDetector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Backtrace.Unity.Model.Attributes;

namespace Backtrace.Unity.Runtime.Native
{
/// <summary>
/// Backtrace native client crash detector interface
/// </summary>
internal interface INativeCrashDetector
{
/// <summary>
/// Enable crash loop detection to prevent infinity loop of crashes.
/// </summary>
bool EnableCrashLoopDetection();

/// <summary>
/// Determines if the safe mode is required.
/// </summary>
bool IsSafeModeRequired();

/// <summary>
/// Returns information how many time in a row does the application crash.
/// </summary>
int ConsecutiveCrashesCount();
}
}
11 changes: 11 additions & 0 deletions Runtime/Native/INativeCrashDetector.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.