Skip to content
Closed
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
2 changes: 2 additions & 0 deletions src/Mono.Android/Android.App/SyncContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Android.OS;
using Android.Runtime;

using LogLevel = Android.Runtime.LogLevel;

namespace Android.App {

internal class SyncContext : SynchronizationContext {
Expand Down
50 changes: 8 additions & 42 deletions src/Mono.Android/Android.Runtime/UncaughtExceptionHandler.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
using System;
using System.Reflection;

namespace Android.Runtime {

sealed class UncaughtExceptionHandler : Java.Lang.Object, Java.Lang.Thread.IUncaughtExceptionHandler {

Action<Exception> mono_unhandled_exception;

Action<AppDomain, UnhandledExceptionEventArgs> AppDomain_DoUnhandledException;

Java.Lang.Thread.IUncaughtExceptionHandler defaultHandler;

public UncaughtExceptionHandler (Java.Lang.Thread.IUncaughtExceptionHandler defaultHandler)
Expand All @@ -22,48 +17,19 @@ internal Java.Lang.Thread.IUncaughtExceptionHandler DefaultHandler {

public void UncaughtException (Java.Lang.Thread thread, Java.Lang.Throwable ex)
{
System.Diagnostics.Debugger.Mono_UnhandledException (ex);

try {
Initialize ();
} catch (Exception e) {
Android.Runtime.AndroidEnvironment.FailFast ($"Unable to initialize UncaughtExceptionHandler. Nested exception caught: {e}");
var jltp = ex as JavaProxyThrowable;
Exception innerException = jltp?.InnerException;
var args = new UnhandledExceptionEventArgs (innerException ?? ex, isTerminating: true);
AppDomain.CurrentDomain.DoUnhandledException (args);
}

mono_unhandled_exception (ex);
if (AppDomain_DoUnhandledException != null) {
try {
var jltp = ex as JavaProxyThrowable;
Exception innerException = jltp?.InnerException;
var args = new UnhandledExceptionEventArgs (innerException ?? ex, isTerminating: true);
AppDomain_DoUnhandledException (AppDomain.CurrentDomain, args);
}
catch (Exception e) {
Logger.Log (LogLevel.Error, "monodroid", "Exception thrown while raising AppDomain.UnhandledException event: " + e.ToString ());
}
catch (Exception e) {
Logger.Log (LogLevel.Error, "monodroid", "Exception thrown while raising AppDomain.UnhandledException event: " + e.ToString ());
}
if (defaultHandler != null)
defaultHandler.UncaughtException (thread, ex);
}

void Initialize ()
{
if (mono_unhandled_exception == null) {
var mono_UnhandledException = typeof (System.Diagnostics.Debugger)
.GetMethod ("Mono_UnhandledException", BindingFlags.NonPublic | BindingFlags.Static);
mono_unhandled_exception = (Action<Exception>) Delegate.CreateDelegate (typeof(Action<Exception>), mono_UnhandledException);
}

if (AppDomain_DoUnhandledException == null) {
var ad_due = typeof (AppDomain)
.GetMethod ("DoUnhandledException",
bindingAttr: BindingFlags.NonPublic | BindingFlags.Instance,
binder: null,
types: new []{typeof (UnhandledExceptionEventArgs)},
modifiers: null);
if (ad_due != null) {
AppDomain_DoUnhandledException = (Action<AppDomain, UnhandledExceptionEventArgs>) Delegate.CreateDelegate (
typeof (Action<AppDomain, UnhandledExceptionEventArgs>), ad_due);
}
}
}
}
}
2 changes: 2 additions & 0 deletions src/Mono.Android/Java.Interop/TypeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

using Android.Runtime;

using LogLevel = Android.Runtime.LogLevel;

namespace Java.Interop {

static class TypeManagerMapDictionaries
Expand Down
2 changes: 2 additions & 0 deletions src/Mono.Android/Java.Lang/Object.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

using Android.Runtime;

using LogLevel = Android.Runtime.LogLevel;

namespace Java.Lang {

[DataContract]
Expand Down
2 changes: 2 additions & 0 deletions src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using Java.Security.Cert;
using Javax.Net.Ssl;

using LogLevel = Android.Runtime.LogLevel;

namespace Xamarin.Android.Net
{
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Mono.Android/Xamarin.Android.Net/AuthModuleDigest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

using Java.Net;

using LogLevel = Android.Runtime.LogLevel;

namespace Xamarin.Android.Net
{
sealed class AuthModuleDigest : IAndroidAuthenticationModule
Expand Down