-
-
Notifications
You must be signed in to change notification settings - Fork 56
fix: Android 5 attachment issues #1652
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
972e710
attachment issues
bitsandfoxes 8c4eba9
jni executor for detaching
bitsandfoxes 8c81872
.
bitsandfoxes f2c3fa1
Updated CHANGELOG.md
bitsandfoxes d579725
Merge branch 'main' into fix/android-no-bueno
bitsandfoxes fbeec2f
added reusable background worker as fallback for old android
bitsandfoxes 2a67c2d
Merge branch 'fix/android-no-bueno' of https://github.com/getsentry/s…
bitsandfoxes 295be7b
Format code
getsentry-bot 5470ec0
.
bitsandfoxes b00e3ac
Merge branch 'fix/android-no-bueno' of https://github.com/getsentry/s…
bitsandfoxes 46dca64
fixed platform dependency and tests
bitsandfoxes 1f922c1
properly detach
bitsandfoxes 31b7f7e
comment
bitsandfoxes bc09463
Format code
getsentry-bot 8b7fbf5
yeet complexity
bitsandfoxes 323b144
merge
bitsandfoxes 7be3763
don't touch .NET
bitsandfoxes 919a2cb
Format code
getsentry-bot c492499
worker cleanup
bitsandfoxes 32f6ae3
Create the JNI Executor only on a need to basis
bitsandfoxes deeff11
Create the JNI executor only on a need-to basis
bitsandfoxes e14bdbc
Update src/Sentry.Unity.Android/SentryNativeAndroid.cs
bitsandfoxes ce78387
Update src/Sentry.Unity.Android/SentryNativeAndroid.cs
bitsandfoxes 67aaa6b
Format code
getsentry-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.Threading; | ||
using UnityEngine; | ||
|
||
namespace Sentry.Unity.Android | ||
{ | ||
internal static class SentryJniExecutor | ||
{ | ||
public static TResult? Run<TResult>(Func<TResult?> jniOperation) | ||
{ | ||
TResult? result = default; | ||
Exception? exception = null; | ||
|
||
var thread = new Thread(() => | ||
{ | ||
if (AndroidJNI.AttachCurrentThread() != 0) | ||
{ | ||
exception = new InvalidOperationException("Failed to attach thread to JVM"); | ||
return; | ||
} | ||
|
||
try | ||
{ | ||
result = jniOperation(); | ||
} | ||
finally | ||
{ | ||
AndroidJNI.DetachCurrentThread(); | ||
} | ||
}); | ||
|
||
thread.Start(); | ||
thread.Join(); | ||
|
||
if (exception is not null) | ||
{ | ||
// Adding the Sentry logger tag ensures we don't send this error to Sentry. | ||
Debug.unityLogger.Log(LogType.Exception, UnityLogger.LogTag, $"Error during JNI execution: {exception}"); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public static void FireAndForget(Action jniOperation) | ||
{ | ||
Exception? exception = null; | ||
|
||
new Thread(() => | ||
{ | ||
if (AndroidJNI.AttachCurrentThread() != 0) | ||
{ | ||
exception = new InvalidOperationException("Failed to attach thread to JVM"); | ||
return; | ||
} | ||
|
||
try | ||
{ | ||
jniOperation(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
exception = ex; | ||
} | ||
finally | ||
{ | ||
AndroidJNI.DetachCurrentThread(); | ||
} | ||
}).Start(); | ||
|
||
if (exception is not null) | ||
{ | ||
// Adding the Sentry logger tag ensures we don't send this error to Sentry. | ||
Debug.unityLogger.Log(LogType.Exception, UnityLogger.LogTag, $"Error during JNI execution: {exception}"); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.