app center;增加發送ping的秒

This commit is contained in:
Caiyanpeng committed 2021-11-12 16:21:13 +08:00
1 parent 1bd1ffdb5a
commit d754ff3b15
719 files changed
+34172 -2875

No files matched your search

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: ed62715457ca14579a585b5e97cda35f
folderAsset: yes
timeCreated: 1512409292
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,111 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_ANDROID && !UNITY_EDITOR
using UnityEngine;
using System.Collections.Generic;
namespace Microsoft.AppCenter.Unity.Crashes.Internal
{
public class CrashesDelegate : AndroidJavaProxy
{
public static event Crashes.SendingErrorReportHandler SendingErrorReport;
public static event Crashes.SentErrorReportHandler SentErrorReport;
public static event Crashes.FailedToSendErrorReportHandler FailedToSendErrorReport;
internal static Crashes.GetErrorAttachmentsHandler GetErrorAttachmentsHandler;
private static Crashes.UserConfirmationHandler shouldAwaitUserConfirmationHandler = null;
private static Crashes.ShouldProcessErrorReportHandler shouldProcessErrorReportHandler = null;
private static readonly CrashesDelegate instance = new CrashesDelegate();
private CrashesDelegate() : base("com.microsoft.appcenter.crashes.CrashesListener")
{
}
public static void SetDelegate()
{
var crashes = new AndroidJavaClass("com.microsoft.appcenter.crashes.Crashes");
crashes.CallStatic("setListener", instance);
}
public void onBeforeSending(AndroidJavaObject report)
{
var handlers = SendingErrorReport;
if (handlers != null)
{
var errorReport = JavaObjectsConverter.ConvertErrorReport(report);
handlers.Invoke(errorReport);
}
}
public void onSendingFailed(AndroidJavaObject report, AndroidJavaObject exception)
{
var handlers = FailedToSendErrorReport;
if (handlers != null)
{
var errorReport = JavaObjectsConverter.ConvertErrorReport(report);
var exceptionStackTrace = exception.Call<string>("getStackTrace");
var failCause = JavaObjectsConverter.ConvertException(exceptionStackTrace);
handlers.Invoke(errorReport, failCause);
}
}
public void onSendingSucceeded(AndroidJavaObject report)
{
var handlers = SentErrorReport;
if (handlers != null)
{
var errorReport = JavaObjectsConverter.ConvertErrorReport(report);
handlers.Invoke(errorReport);
}
}
public bool shouldProcess(AndroidJavaObject report)
{
var handler = shouldProcessErrorReportHandler;
if (handler != null)
{
return handler.Invoke(JavaObjectsConverter.ConvertErrorReport(report));
}
return true;
}
public bool shouldAwaitUserConfirmation()
{
var handler = shouldAwaitUserConfirmationHandler;
if (handler != null)
{
return handler.Invoke();
}
return false;
}
public AndroidJavaObject getErrorAttachments(AndroidJavaObject report)
{
if (GetErrorAttachmentsHandler != null)
{
var logs = GetErrorAttachmentsHandler(JavaObjectsConverter.ConvertErrorReport(report));
return JavaObjectsConverter.ToJavaAttachments(logs);
}
else
{
return null;
}
}
public static void SetShouldAwaitUserConfirmationHandler(Crashes.UserConfirmationHandler handler)
{
shouldAwaitUserConfirmationHandler = handler;
}
public static void SetShouldProcessErrorReportHandler(Crashes.ShouldProcessErrorReportHandler handler)
{
shouldProcessErrorReportHandler = handler;
}
public static void SetGetErrorAttachmentsHandler(Crashes.GetErrorAttachmentsHandler handler)
{
GetErrorAttachmentsHandler = handler;
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: fefa4412922e24dc7b45c8977d40ceb3
timeCreated: 1497991554
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,138 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_ANDROID && !UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.Threading;
using Assets.AppCenter.Plugins.Android.Utility;
using Microsoft.AppCenter.Unity.Internal;
using Microsoft.AppCenter.Unity.Internal.Utility;
using UnityEngine;
namespace Microsoft.AppCenter.Unity.Crashes.Internal
{
class CrashesInternal
{
private static AndroidJavaClass _crashes = new AndroidJavaClass("com.microsoft.appcenter.crashes.Crashes");
private static AndroidJavaClass _wrapperSdkExceptionManager = new AndroidJavaClass("com.microsoft.appcenter.crashes.WrapperSdkExceptionManager");
public static void AddNativeType(List<IntPtr> nativeTypes)
{
nativeTypes.Add(AndroidJNI.FindClass("com/microsoft/appcenter/crashes/Crashes"));
}
public static string TrackException(AndroidJavaObject exception, IDictionary<string, string> properties, ErrorAttachmentLog[] attachments)
{
var javaProperties = JavaStringMapHelper.ConvertToJava(properties);
var javaAttachments = JavaObjectsConverter.ToJavaAttachments(attachments);
return _wrapperSdkExceptionManager.CallStatic<string>("trackException", exception, javaProperties, javaAttachments);
}
public static AppCenterTask<bool> HasReceivedMemoryWarningInLastSessionAsync()
{
var future = _crashes.CallStatic<AndroidJavaObject>("hasReceivedMemoryWarningInLastSession");
return new AppCenterTask<bool>(future);
}
public static AppCenterTask SetEnabledAsync(bool isEnabled)
{
var future = _crashes.CallStatic<AndroidJavaObject>("setEnabled", isEnabled);
return new AppCenterTask(future);
}
public static AppCenterTask<bool> IsEnabledAsync()
{
var future = _crashes.CallStatic<AndroidJavaObject>("isEnabled");
return new AppCenterTask<bool>(future);
}
public static void GenerateTestCrash()
{
// The call to the "generateTestCrash" method from native SDK wouldn't work in this
// case because it just throws an exception which Unity automatically catches and logs,
// without crashing the application
// _crashes.CallStatic("generateTestCrash");
if (Debug.isDebugBuild)
{
new Thread(() =>
{
AndroidJNI.FindClass("Test/crash/generated/by/SDK");
}).Start();
}
}
public static AppCenterTask<bool> HasCrashedInLastSessionAsync()
{
var future = _crashes.CallStatic<AndroidJavaObject>("hasCrashedInLastSession");
return new AppCenterTask<bool>(future);
}
public static AppCenterTask<ErrorReport> GetLastSessionCrashReportAsync()
{
var future = _crashes.CallStatic<AndroidJavaObject>("getLastSessionCrashReport");
var javaTask = new AppCenterTask<AndroidJavaObject>(future);
var errorReportTask = new AppCenterTask<ErrorReport>();
javaTask.ContinueWith(t =>
{
var errorReport = JavaObjectsConverter.ConvertErrorReport(t.Result);
errorReportTask.SetResult(errorReport);
});
return errorReportTask;
}
public static void DisableMachExceptionHandler()
{
}
public static void SetUserConfirmationHandler(Crashes.UserConfirmationHandler handler)
{
CrashesDelegate.SetShouldAwaitUserConfirmationHandler(handler);
}
public static void NotifyWithUserConfirmation(Crashes.ConfirmationResult answer)
{
_crashes.CallStatic("notifyUserConfirmation", ToJavaConfirmationResult(answer));
}
public static AppCenterTask<string> GetMinidumpDirectoryAsync()
{
var future = _crashes.CallStatic<AndroidJavaObject>("getMinidumpDirectory");
return new AppCenterTask<string>(future);
}
public static void StartCrashes()
{
AppCenterInternal.Start(AppCenter.Crashes);
}
public static ErrorReport BuildHandledErrorReport(string errorReportId)
{
var nativeErrorReport = _wrapperSdkExceptionManager.CallStatic<AndroidJavaObject>("buildHandledErrorReport", AndroidUtility.GetAndroidContext(), errorReportId);
return JavaObjectsConverter.ConvertErrorReport(nativeErrorReport);
}
public static void SendErrorAttachments(string errorReportId, ErrorAttachmentLog[] attachments)
{
var nativeAttachments = JavaObjectsConverter.ToJavaAttachments(attachments);
_wrapperSdkExceptionManager.CallStatic("sendErrorAttachments", errorReportId, nativeAttachments);
}
private static int ToJavaConfirmationResult(Crashes.ConfirmationResult answer)
{
// Java values: SEND=0, DONT_SEND=1, ALWAYS_SEND=2
// Crashes.ConfirmationResult values: SEND=1, DONT_SEND=0, ALWAYS_SEND=2
switch (answer)
{
case Crashes.ConfirmationResult.Send:
return _crashes.GetStatic<int>("SEND");
case Crashes.ConfirmationResult.AlwaysSend:
return _crashes.GetStatic<int>("ALWAYS_SEND");
default:
return _crashes.GetStatic<int>("DONT_SEND");
}
}
}
}
#endif
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 49eed83874f5847fb8be3cc3ec315730
timeCreated: 1512519361
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,96 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_ANDROID
using Microsoft.AppCenter.Unity;
using Microsoft.AppCenter.Unity.Crashes;
using Microsoft.AppCenter.Unity.Crashes.Models;
using Microsoft.AppCenter.Unity.Internal.Utility;
using UnityEngine;
public class JavaObjectsConverter
{
private static readonly AndroidJavaClass _errorAttachmentLogClass = new AndroidJavaClass("com.microsoft.appcenter.crashes.ingestion.models.ErrorAttachmentLog");
public static ErrorReport ConvertErrorReport(AndroidJavaObject errorReport)
{
if (errorReport == null)
{
return null;
}
try
{
var id = errorReport.Call<string>("getId");
var threadName = errorReport.Call<string>("getThreadName");
var startTime = JavaDateHelper.DateTimeConvert(errorReport.Call<AndroidJavaObject>("getAppStartTime"));
var errorTime = JavaDateHelper.DateTimeConvert(errorReport.Call<AndroidJavaObject>("getAppErrorTime"));
var exception = ConvertException(errorReport.Call<string>("getStackTrace"));
var device = ConvertDevice(errorReport.Call<AndroidJavaObject>("getDevice"));
return new ErrorReport(id, startTime, errorTime, exception, device, threadName);
}
catch (System.Exception e)
{
Debug.LogErrorFormat("Failed to convert error report Java object to .Net object: {0}", e.ToString());
return null;
}
}
public static Exception ConvertException(string stackTrace)
{
return new Exception(null, stackTrace);
}
private static Device ConvertDevice(AndroidJavaObject device)
{
return new Device(
device.Call<string>("getSdkName"),
device.Call<string>("getSdkVersion"),
device.Call<string>("getModel"),
device.Call<string>("getOemName"),
device.Call<string>("getOsName"),
device.Call<string>("getOsVersion"),
device.Call<string>("getOsBuild"),
GetIntValue(device, "getOsApiLevel"),
device.Call<string>("getLocale"),
GetIntValue(device, "getTimeZoneOffset"),
device.Call<string>("getScreenSize"),
device.Call<string>("getAppVersion"),
device.Call<string>("getCarrierName"),
device.Call<string>("getCarrierCountry"),
device.Call<string>("getAppBuild"),
device.Call<string>("getAppNamespace"));
}
private static int GetIntValue(AndroidJavaObject javaObject, string getterName)
{
var integer = javaObject.Call<AndroidJavaObject>(getterName);
return integer.Call<int>("intValue");
}
internal static AndroidJavaObject ToJavaAttachments(ErrorAttachmentLog[] attachments)
{
if (attachments == null)
{
return null;
}
var javaList = new AndroidJavaObject("java.util.ArrayList", attachments.Length);
foreach (var errorAttachmentLog in attachments)
{
if (errorAttachmentLog != null)
{
AndroidJavaObject nativeLog = null;
if (errorAttachmentLog.Type == ErrorAttachmentLog.AttachmentType.Text)
{
nativeLog = _errorAttachmentLogClass.CallStatic<AndroidJavaObject>("attachmentWithText", errorAttachmentLog.Text, errorAttachmentLog.FileName);
}
else
{
nativeLog = _errorAttachmentLogClass.CallStatic<AndroidJavaObject>("attachmentWithBinary", errorAttachmentLog.Data, errorAttachmentLog.FileName, errorAttachmentLog.ContentType);
}
javaList.Call<bool>("add", nativeLog);
}
}
return javaList;
}
}
#endif
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9322587201ec4ad48af11a58d953e826
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,44 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_ANDROID && !UNITY_EDITOR
using UnityEngine;
namespace Microsoft.AppCenter.Unity.Crashes.Internal
{
class WrapperExceptionInternal
{
public static AndroidJavaObject Create()
{
return new AndroidJavaObject("com.microsoft.appcenter.crashes.ingestion.models.Exception");
}
public static void SetType(AndroidJavaObject exception, string type)
{
exception.Call("setType", type);
}
public static void SetMessage(AndroidJavaObject exception, string message)
{
exception.Call("setMessage", message);
}
public static void SetStacktrace(AndroidJavaObject exception, string stacktrace)
{
exception.Call("setStackTrace", stacktrace);
}
public static void SetInnerException(AndroidJavaObject exception, AndroidJavaObject innerException)
{
var javaList = new AndroidJavaObject("java.util.LinkedList");
javaList.Call("addLast", innerException);
exception.Call("setInnerExceptions", javaList);
}
public static void SetWrapperSdkName(AndroidJavaObject exception, string sdkName)
{
exception.Call("setWrapperSdkName", sdkName);
}
}
}
#endif
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: b4325894391be49838145922ef28e7ca
timeCreated: 1512582941
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 5e6188b3d234f4b888dbe6e8b27c6cc6
folderAsset: yes
timeCreated: 1512409292
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,47 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if (!UNITY_IOS && !UNITY_ANDROID && !UNITY_WSA_10_0) || UNITY_EDITOR
namespace Microsoft.AppCenter.Unity.Crashes.Internal
{
class CrashesDelegate
{
#pragma warning disable 0067
public static event Crashes.SendingErrorReportHandler SendingErrorReport;
public static event Crashes.SentErrorReportHandler SentErrorReport;
public static event Crashes.FailedToSendErrorReportHandler FailedToSendErrorReport;
#pragma warning restore 0067
#pragma warning disable 0649
internal static Crashes.GetErrorAttachmentsHandler GetErrorAttachmentsHandler;
#pragma warning restore 0649
public static void SetDelegate()
{
}
public static void SetShouldProcessErrorReportHandler(Crashes.ShouldProcessErrorReportHandler handler)
{
}
public static void SetGetErrorAttachmentsHandler(Crashes.GetErrorAttachmentsHandler handler)
{
}
public static void SetSentErrorReportHandler(Crashes.SentErrorReportHandler handler)
{
}
public static void SetFailedToSendErrorReportHandler(Crashes.FailedToSendErrorReportHandler handler)
{
}
public static void SetShouldAwaitUserConfirmationHandler(Crashes.UserConfirmationHandler handler)
{
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cf531b4631aed4bf18e9e07c9783f0d9
timeCreated: 1497905875
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,93 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if (!UNITY_IOS && !UNITY_ANDROID && !UNITY_WSA_10_0) || UNITY_EDITOR
using System.Collections.Generic;
using Microsoft.AppCenter.Unity.Crashes.Models;
using Microsoft.AppCenter.Unity.Crashes;
namespace Microsoft.AppCenter.Unity.Crashes.Internal
{
#if UNITY_IOS
using NativeType = System.IntPtr;
using RawType = System.IntPtr;
#elif UNITY_ANDROID
using NativeType = System.IntPtr;
using RawType = UnityEngine.AndroidJavaObject;
#else
using NativeType = System.Type;
using RawType = System.Object;
#endif
class CrashesInternal
{
public static void AddNativeType(List<NativeType> nativeTypes)
{
}
public static string TrackException(RawType exception, IDictionary<string, string> properties, ErrorAttachmentLog[] attachments)
{
return "";
}
public static AppCenterTask<bool> HasReceivedMemoryWarningInLastSessionAsync()
{
return AppCenterTask<bool>.FromCompleted(false);
}
public static AppCenterTask SetEnabledAsync(bool enabled)
{
return AppCenterTask.FromCompleted();
}
public static AppCenterTask<bool> IsEnabledAsync()
{
return AppCenterTask<bool>.FromCompleted(false);
}
public static AppCenterTask<string> GetMinidumpDirectoryAsync()
{
return AppCenterTask<string>.FromCompleted("");
}
public static void GenerateTestCrash()
{
}
public static AppCenterTask<bool> HasCrashedInLastSessionAsync()
{
return AppCenterTask<bool>.FromCompleted(false);
}
public static void DisableMachExceptionHandler()
{
}
public static AppCenterTask<ErrorReport> GetLastSessionCrashReportAsync()
{
return AppCenterTask<ErrorReport>.FromCompleted(null);
}
public static void SetUserConfirmationHandler(Crashes.UserConfirmationHandler handler)
{
}
public static void NotifyWithUserConfirmation(Crashes.ConfirmationResult answer)
{
}
public static void StartCrashes()
{
}
public static ErrorReport BuildHandledErrorReport(string errorReportId)
{
return null;
}
public static void SendErrorAttachments(string errorReportId, ErrorAttachmentLog[] attachments)
{
}
}
}
#endif
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 4c3f231fe8edd4d63807d60f84840df7
timeCreated: 1512519361
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if (!UNITY_IOS && !UNITY_ANDROID && !UNITY_WSA_10_0) || UNITY_EDITOR
using Microsoft.AppCenter.Unity.Crashes.Internal;
using System;
namespace Microsoft.AppCenter.Unity.Crashes
{
#if UNITY_IOS
using RawType = System.IntPtr;
#elif UNITY_ANDROID
using RawType = UnityEngine.AndroidJavaObject;
#else
using RawType = System.Object;
#endif
public class WrapperExceptionInternal
{
public static RawType Create()
{
return default(RawType);
}
public static void SetType(RawType exception, string type)
{
}
public static void SetMessage(RawType exception, string message)
{
}
public static void SetStacktrace(RawType exception, string stacktrace)
{
}
public static void SetInnerException(RawType exception, RawType innerException)
{
}
public static void SetWrapperSdkName(RawType exception, string sdkName)
{
}
}
}
#endif
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 40951c1d8e9b542f0a086a579d880ce8
timeCreated: 1512582941
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 357e82d836da8a546ab138a7d10dc0b0
folderAsset: yes
timeCreated: 1499796409
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
namespace Microsoft.AppCenter.Unity.Crashes
{
public class ErrorAttachmentLog
{
public string Text { get; private set; }
public byte[] Data { get; private set; }
public string FileName { get; private set; }
public string ContentType { get; private set; }
public AttachmentType Type { get; private set; }
public static ErrorAttachmentLog AttachmentWithText(string text, string fileName)
{
return new ErrorAttachmentLog
{
Text = text,
FileName = fileName,
Type = AttachmentType.Text
};
}
public static ErrorAttachmentLog AttachmentWithBinary(byte[] data, string fileName, string contentType)
{
return new ErrorAttachmentLog
{
Data = data,
FileName = fileName,
ContentType = contentType,
Type = AttachmentType.Binary
};
}
public enum AttachmentType { Text, Binary }
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 77bffd8d50b4648c4b9b1ae1553c31fe
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,102 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
namespace Microsoft.AppCenter.Unity.Crashes
{
public class ErrorReport
{
public ErrorReport(string id, DateTimeOffset appStartTime, DateTimeOffset appErrorTime, Models.Exception exception, Device device, string threadName)
{
Id = id;
AppStartTime = appStartTime;
AppErrorTime = appErrorTime;
Exception = exception;
Device = device;
ThreadName = threadName;
IsCrash = true;
}
public ErrorReport(string id, DateTimeOffset appStartTime, DateTimeOffset appErrorTime, Models.Exception exception, int processId, string reporterKey,
string reporterSignal, bool isAppKill, Device device)
{
Id = id;
AppStartTime = appStartTime;
AppErrorTime = appErrorTime;
Exception = exception;
ProcessId = processId;
ReporterKey = reporterKey;
ReporterSignal = reporterSignal;
IsAppKill = isAppKill;
Device = device;
IsCrash = true;
}
/// <summary>
/// Gets the report identifier.
/// </summary>
/// <value>UUID for the report.</value>
public string Id { get; private set; }
/// <summary>
/// Gets the app start time.
/// </summary>
/// <value>Date and time the app started</value>
public DateTimeOffset AppStartTime { get; private set; }
/// <summary>
/// Gets the app error time.
/// </summary>
/// <value>Date and time the error occured</value>
public DateTimeOffset AppErrorTime { get; private set; }
/// <summary>
/// Gets the device that the crashed app was being run on.
/// </summary>
/// <value>Device information at the crash time.</value>
public Device Device { get; private set; }
/// <summary>
/// Gets the model exception associated with the error.
/// </summary>
/// <value>The exception.</value>
public Models.Exception Exception { get; private set; }
/// <summary>
/// Gets the thread name.
/// </summary>
/// <value>The thread name.</value>
public string ThreadName { get; private set; }
/// <summary>
/// Gets the process identifier.
/// </summary>
/// <value>Process Id.</value>
public int ProcessId { get; private set; }
/// <summary>
/// Gets the reporter key.
/// </summary>
/// <value>Reporter Key.</value>
public string ReporterKey { get; private set; }
/// <summary>
/// Gets the reporter signal.
/// </summary>
/// <value>Reporter Signal.</value>
public string ReporterSignal { get; private set; }
/// <summary>
/// True if the details represent an app kill instead of a crash.
/// </summary>
/// <value>True if the details represent an app kill instead of a crash.</value>
public bool IsAppKill { get; private set; }
/// <summary>
/// Indicates whether this error report reprents a true app crash.
/// </summary>
/// <value>True if the unhandled error actually resulted in app termination.</value>
public bool IsCrash { get; internal set; }
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: bced6ecefb6eb43a9b879a75795ac5b6
timeCreated: 1500410905
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
namespace Microsoft.AppCenter.Unity.Crashes.Models
{
public class Exception
{
public string Message { get; private set; }
public string StackTrace { get; private set; }
public Exception(string message, string stackTrace)
{
Message = message;
StackTrace = stackTrace;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 83ddd846fbadea1458aa9f6fc7e86522
timeCreated: 1499796418
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 2436e86c33df74be3a2e9e83ce80fc51
folderAsset: yes
timeCreated: 1512409292
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,407 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using Microsoft.AppCenter.Unity.Crashes.Internal;
using Microsoft.AppCenter.Unity.Internal.Utils;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;
namespace Microsoft.AppCenter.Unity.Crashes
{
#if UNITY_IOS || UNITY_ANDROID
using RawType = System.IntPtr;
#else
using RawType = System.Type;
#endif
public class Crashes
{
// Used by App Center Unity Editor Extensions: https://github.com/Microsoft/AppCenter-SDK-Unity-Extension
public const string CrashesSDKVersion = "4.3.0";
private static bool _reportUnhandledExceptions = false;
private static bool _enableErrorAttachmentsCallbacks = false;
private static readonly object _objectLock = new object();
#if !UNITY_WSA_10_0
private static Queue<Exception> _unhandledExceptions = new Queue<Exception>();
#endif
public static void PrepareEventHandlers()
{
AppCenterBehavior.InitializingServices += Initialize;
AppCenterBehavior.InitializedAppCenterAndServices += HandleAppCenterInitialized;
}
public static void Initialize()
{
CrashesDelegate.SetDelegate();
}
public static void AddNativeType(List<RawType> nativeTypes)
{
CrashesInternal.AddNativeType(nativeTypes);
}
public static void TrackError(Exception exception, IDictionary<string, string> properties = null, params ErrorAttachmentLog[] attachments)
{
if (exception != null)
{
var exceptionWrapper = CreateWrapperException(exception);
CrashesInternal.TrackException(exceptionWrapper.GetRawObject(), properties, attachments);
}
}
public static void OnHandleLog(string logString, string stackTrace, LogType type)
{
if (LogType.Assert == type || LogType.Exception == type || LogType.Error == type)
{
var exception = CreateWrapperException(logString, stackTrace, type);
var errorReportId = CrashesInternal.TrackException(exception.GetRawObject(), null, null);
if (_enableErrorAttachmentsCallbacks)
{
SendErrorAttachments(errorReportId);
}
}
}
#if !UNITY_WSA_10_0
public static void OnHandleUnresolvedException(object sender, UnhandledExceptionEventArgs args)
{
if (args == null || args.ExceptionObject == null)
{
return;
}
var exception = args.ExceptionObject as Exception;
if (exception != null)
{
Debug.Log("Unhandled exception: " + exception.ToString());
#if UNITY_IOS && !UNITY_EDITOR
TrackErrorWithAttachments(exception);
#else
lock (_unhandledExceptions)
{
_unhandledExceptions.Enqueue(exception);
}
UnityCoroutineHelper.StartCoroutine(SendUnhandledExceptionReports);
#endif
}
}
#endif
public static AppCenterTask<string> GetMinidumpDirectoryAsync()
{
return CrashesInternal.GetMinidumpDirectoryAsync();
}
public static AppCenterTask<bool> HasReceivedMemoryWarningInLastSessionAsync()
{
return CrashesInternal.HasReceivedMemoryWarningInLastSessionAsync();
}
public static AppCenterTask<bool> IsEnabledAsync()
{
return CrashesInternal.IsEnabledAsync();
}
public static AppCenterTask SetEnabledAsync(bool enabled)
{
return CrashesInternal.SetEnabledAsync(enabled);
}
public static void GenerateTestCrash()
{
CrashesInternal.GenerateTestCrash();
}
public static AppCenterTask<bool> HasCrashedInLastSessionAsync()
{
return CrashesInternal.HasCrashedInLastSessionAsync();
}
public static void DisableMachExceptionHandler()
{
CrashesInternal.DisableMachExceptionHandler();
}
public static AppCenterTask<ErrorReport> GetLastSessionCrashReportAsync()
{
return CrashesInternal.GetLastSessionCrashReportAsync();
}
/// <summary>
/// Report unhandled exceptions, automatically captured by Unity, as handled errors
/// </summary>
/// <param name="enabled">Specify true to enable reporting of unhandled exceptions, automatically captured by Unity, as handled errors; otherwise, false.</param>
/// <param name="enableAttachmentsCallback">Specify true to enable a callback that gives the app an opportunity to augment crash reports with additional attachments.</param>
public static void ReportUnhandledExceptions(bool enabled, bool enableAttachmentsCallback = false)
{
if (!enabled && enableAttachmentsCallback)
{
Debug.LogWarning("Cannot enable attachments callbacks without enabling unhandled exception reporting.");
}
else
{
_enableErrorAttachmentsCallbacks = enableAttachmentsCallback;
}
if (_reportUnhandledExceptions == enabled)
{
return;
}
_reportUnhandledExceptions = enabled;
if (enabled)
{
SubscribeToUnhandledExceptions();
}
else
{
UnsubscribeFromUnhandledExceptions();
}
}
public static bool IsReportingUnhandledExceptions()
{
return _reportUnhandledExceptions;
}
#if ENABLE_IL2CPP
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
#endif
public delegate bool UserConfirmationHandler();
public static UserConfirmationHandler ShouldAwaitUserConfirmation
{
set
{
CrashesInternal.SetUserConfirmationHandler(value);
}
}
public enum ConfirmationResult { DontSend, Send, AlwaysSend };
public static void NotifyUserConfirmation(ConfirmationResult answer)
{
CrashesInternal.NotifyWithUserConfirmation(answer);
}
#if ENABLE_IL2CPP
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
#endif
public delegate bool ShouldProcessErrorReportHandler(ErrorReport errorReport);
public static ShouldProcessErrorReportHandler ShouldProcessErrorReport
{
set
{
CrashesDelegate.SetShouldProcessErrorReportHandler(value);
}
}
#if ENABLE_IL2CPP
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
#endif
public delegate ErrorAttachmentLog[] GetErrorAttachmentsHandler(ErrorReport errorReport);
public static GetErrorAttachmentsHandler GetErrorAttachments
{
set
{
CrashesDelegate.SetGetErrorAttachmentsHandler(value);
}
}
#if ENABLE_IL2CPP
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
#endif
public delegate void SendingErrorReportHandler(ErrorReport errorReport);
public static event SendingErrorReportHandler SendingErrorReport
{
add
{
lock (_objectLock)
{
CrashesDelegate.SendingErrorReport += value;
}
}
remove
{
lock (_objectLock)
{
CrashesDelegate.SendingErrorReport -= value;
}
}
}
#if ENABLE_IL2CPP
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
#endif
public delegate void SentErrorReportHandler(ErrorReport errorReport);
public static event SentErrorReportHandler SentErrorReport
{
add
{
lock (_objectLock)
{
CrashesDelegate.SentErrorReport += value;
}
}
remove
{
lock (_objectLock)
{
CrashesDelegate.SentErrorReport -= value;
}
}
}
#if ENABLE_IL2CPP
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
#endif
public delegate void FailedToSendErrorReportHandler(ErrorReport errorReport, Models.Exception exception);
public static event FailedToSendErrorReportHandler FailedToSendErrorReport
{
add
{
lock (_objectLock)
{
CrashesDelegate.FailedToSendErrorReport += value;
}
}
remove
{
lock (_objectLock)
{
CrashesDelegate.FailedToSendErrorReport -= value;
}
}
}
public static void StartCrashes()
{
CrashesInternal.StartCrashes();
}
private static void SubscribeToUnhandledExceptions()
{
#if !UNITY_EDITOR && !UNITY_WSA_10_0
Application.logMessageReceived += OnHandleLog;
System.AppDomain.CurrentDomain.UnhandledException += OnHandleUnresolvedException;
#endif
}
private static void UnsubscribeFromUnhandledExceptions()
{
#if !UNITY_EDITOR && !UNITY_WSA_10_0
Application.logMessageReceived -= OnHandleLog;
System.AppDomain.CurrentDomain.UnhandledException -= OnHandleUnresolvedException;
#endif
}
private static void HandleAppCenterInitialized()
{
if (_reportUnhandledExceptions)
{
SubscribeToUnhandledExceptions();
}
}
#if !UNITY_WSA_10_0
private static IEnumerator SendUnhandledExceptionReports()
{
yield return null; // ensure that code is executed in main thread
while (true)
{
Exception exception = null;
lock (_unhandledExceptions)
{
if (_unhandledExceptions.Count > 0)
{
exception = _unhandledExceptions.Dequeue();
}
else
{
yield break;
}
}
if (exception != null)
{
TrackErrorWithAttachments(exception);
}
yield return null; // report remaining exceptions on next frames
}
}
#endif
private static void TrackErrorWithAttachments(Exception exception)
{
var exceptionWrapper = CreateWrapperException(exception);
var errorId = CrashesInternal.TrackException(exceptionWrapper.GetRawObject(), null, null);
// If the main thread is not crashed, attachments should be sent.
if (_enableErrorAttachmentsCallbacks)
{
SendErrorAttachments(errorId);
}
}
private static WrapperException CreateWrapperException(Exception exception)
{
var exceptionWrapper = new WrapperException();
exceptionWrapper.SetWrapperSdkName(GetExceptionWrapperSdkName());
exceptionWrapper.SetStacktrace(exception.StackTrace);
exceptionWrapper.SetMessage(exception.Message);
exceptionWrapper.SetType(exception.GetType().ToString());
if (exception.InnerException != null)
{
var innerExceptionWrapper = CreateWrapperException(exception.InnerException).GetRawObject();
exceptionWrapper.SetInnerException(innerExceptionWrapper);
}
return exceptionWrapper;
}
private static WrapperException CreateWrapperException(string logString, string stackTrace, LogType type)
{
var exception = new WrapperException();
exception.SetWrapperSdkName(GetExceptionWrapperSdkName());
string sanitizedLogString = logString.Replace("\n", " ");
exception.SetMessage(sanitizedLogString);
exception.SetType(type.ToString());
string[] stacktraceLines = stackTrace.Split('\n');
string stackTraceString = "";
foreach (string line in stacktraceLines)
{
if (line.Length > 0)
{
stackTraceString += "at " + line + "\n";
}
}
exception.SetStacktrace(stackTraceString);
return exception;
}
private static string GetExceptionWrapperSdkName()
{
//return WrapperSdk.Name;
return "appcenter.xamarin"; // fix stack traces are not showing up in the portal UI
}
private static void SendErrorAttachments(string errorReportId)
{
// Send attachments for error report.
var errorReport = CrashesInternal.BuildHandledErrorReport(errorReportId);
errorReport.IsCrash = false;
var attachments = CrashesDelegate.GetErrorAttachmentsHandler == null ? null : CrashesDelegate.GetErrorAttachmentsHandler(errorReport);
CrashesInternal.SendErrorAttachments(errorReportId, attachments);
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: b845273fb230f4d4087e0795f0588549
timeCreated: 1512519361
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,56 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using Microsoft.AppCenter.Unity.Crashes.Internal;
using System;
namespace Microsoft.AppCenter.Unity.Crashes
{
#if UNITY_IOS
using RawType = System.IntPtr;
#elif UNITY_ANDROID
using RawType = UnityEngine.AndroidJavaObject;
#else
using RawType = System.Object;
#endif
public class WrapperException
{
private readonly RawType _rawObject;
internal RawType GetRawObject()
{
return _rawObject;
}
public WrapperException()
{
_rawObject = WrapperExceptionInternal.Create();
}
public void SetType(string type)
{
WrapperExceptionInternal.SetType(_rawObject, type);
}
public void SetMessage(string message)
{
WrapperExceptionInternal.SetMessage(_rawObject, message);
}
public void SetStacktrace(string stacktrace)
{
WrapperExceptionInternal.SetStacktrace(_rawObject, stacktrace);
}
public void SetInnerException(RawType innerException)
{
WrapperExceptionInternal.SetInnerException(_rawObject, innerException);
}
public void SetWrapperSdkName(string sdkName)
{
WrapperExceptionInternal.SetWrapperSdkName(_rawObject, sdkName);
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 4c021f5e331994d7993f15f25519448d
timeCreated: 1512582941
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: b647c68cd69ba475581d0ec0af39e4ba
folderAsset: yes
timeCreated: 1512467976
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,43 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_WSA_10_0 && !UNITY_EDITOR
namespace Microsoft.AppCenter.Unity.Crashes.Internal
{
public class CrashesDelegate
{
#pragma warning disable 0067
public static event Crashes.SendingErrorReportHandler SendingErrorReport;
public static event Crashes.SentErrorReportHandler SentErrorReport;
public static event Crashes.FailedToSendErrorReportHandler FailedToSendErrorReport;
#pragma warning restore 0067
#pragma warning disable 0649
internal static Crashes.GetErrorAttachmentsHandler GetErrorAttachmentsHandler;
#pragma warning restore 0649
public static void SetDelegate()
{
}
public static void SetShouldProcessErrorReportHandler(Crashes.ShouldProcessErrorReportHandler handler)
{
}
public static void SetGetErrorAttachmentsHandler(Crashes.GetErrorAttachmentsHandler handler)
{
}
public static void SetSentErrorReportHandler(Crashes.SentErrorReportHandler handler)
{
}
public static void SetFailedToSendErrorReportHandler(Crashes.FailedToSendErrorReportHandler handler)
{
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 58a05f18710714e42872b326eb0cfc2d
timeCreated: 1497991554
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,88 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_WSA_10_0 && !UNITY_EDITOR
using Microsoft.AppCenter.Unity.Crashes.Models;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AppCenter.Unity.Crashes;
namespace Microsoft.AppCenter.Unity.Crashes.Internal
{
class CrashesInternal
{
public static void AddNativeType(List<Type> nativeTypes)
{
}
public static string TrackException(object exception, IDictionary<string, string> properties, ErrorAttachmentLog[] attachments)
{
return "";
}
public static AppCenterTask<bool> HasReceivedMemoryWarningInLastSessionAsync()
{
return AppCenterTask<bool>.FromCompleted(false);
}
public static AppCenterTask SetEnabledAsync(bool enabled)
{
return AppCenterTask.FromCompleted();
}
public static AppCenterTask<bool> IsEnabledAsync()
{
return AppCenterTask<bool>.FromCompleted(false);
}
public static void GenerateTestCrash()
{
}
public static AppCenterTask<bool> HasCrashedInLastSessionAsync()
{
return AppCenterTask<bool>.FromCompleted(false);
}
public static AppCenterTask<ErrorReport> GetLastSessionCrashReportAsync()
{
return AppCenterTask<ErrorReport>.FromCompleted(null);
}
public static void DisableMachExceptionHandler()
{
}
private class Crashes
{
}
public static void SetUserConfirmationHandler(Unity.Crashes.Crashes.UserConfirmationHandler handler)
{
}
public static void NotifyWithUserConfirmation(Unity.Crashes.Crashes.ConfirmationResult answer)
{
}
public static void StartCrashes()
{
}
public static ErrorReport BuildHandledErrorReport(string errorReportId)
{
return null;
}
public static void SendErrorAttachments(string errorReportId, ErrorAttachmentLog[] attachments)
{
}
public static AppCenterTask<string> GetMinidumpDirectoryAsync()
{
return AppCenterTask<string>.FromCompleted("");
}
}
}
#endif
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 6fcc6fa30cf3e4471a73d26c3405be12
timeCreated: 1512519361
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_WSA_10_0 && !UNITY_EDITOR
using System;
using System.Runtime.InteropServices;
namespace Microsoft.AppCenter.Unity.Crashes.Internal
{
class WrapperExceptionInternal
{
public static object Create()
{
return new object();
}
public static void SetType(object exception, string type)
{
}
public static void SetMessage(object exception, string message)
{
}
public static void SetStacktrace(object exception, string stacktrace)
{
}
public static void SetInnerException(object exception, object innerException)
{
}
public static void SetWrapperSdkName(object exception, string sdkName)
{
}
}
}
#endif
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 3e9e782b8a7114f62b08d96b94bae9bd
timeCreated: 1512582940
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 3d0c42fb4423a4c9d9177718ffb37314
folderAsset: yes
timeCreated: 1512409292
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,151 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_IOS && !UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using AOT;
using Microsoft.AppCenter.Unity.Crashes;
using Microsoft.AppCenter.Unity.Internal.Utility;
namespace Microsoft.AppCenter.Unity.Crashes.Internal
{
public class CrashesDelegate
{
static CrashesDelegate()
{
app_center_unity_crashes_delegate_set_should_process_error_report_delegate(ShouldProcessErrorReportNativeFunc);
app_center_unity_crashes_delegate_set_get_error_attachments_delegate(GetErrorAttachmentsNativeFunc);
app_center_unity_crashes_delegate_set_sending_error_report_delegate(SendingErrorReportNativeFunc);
app_center_unity_crashes_delegate_set_sent_error_report_delegate(SentErrorReportNativeFunc);
app_center_unity_crashes_delegate_set_failed_to_send_error_report_delegate(FailedToSendErrorReportNativeFunc);
}
public static void SetDelegate()
{
app_center_unity_crashes_set_delegate();
}
#if ENABLE_IL2CPP
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
#endif
public delegate bool NativeShouldProcessErrorReportDelegate(IntPtr report);
private static Crashes.ShouldProcessErrorReportHandler shouldProcessReportHandler;
[MonoPInvokeCallback(typeof(NativeShouldProcessErrorReportDelegate))]
public static bool ShouldProcessErrorReportNativeFunc(IntPtr report)
{
if (shouldProcessReportHandler != null)
{
ErrorReport errorReport = CrashesInternal.GetErrorReportFromIntPtr(report);
return shouldProcessReportHandler(errorReport);
}
else
{
return true;
}
}
public static void SetShouldProcessErrorReportHandler(Crashes.ShouldProcessErrorReportHandler handler)
{
shouldProcessReportHandler = handler;
}
#if ENABLE_IL2CPP
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
#endif
public delegate IntPtr NativeGetErrorAttachmentsDelegate(IntPtr report);
internal static Crashes.GetErrorAttachmentsHandler GetErrorAttachmentsHandler;
[MonoPInvokeCallback(typeof(NativeGetErrorAttachmentsDelegate))]
public static IntPtr GetErrorAttachmentsNativeFunc(IntPtr report)
{
if (GetErrorAttachmentsHandler == null)
{
return IntPtr.Zero;
}
var errorReport = CrashesInternal.GetErrorReportFromIntPtr(report);
var logs = GetErrorAttachmentsHandler(errorReport);
return NativeObjectsConverter.ToNativeAttachments(logs);
}
public static void SetGetErrorAttachmentsHandler(Crashes.GetErrorAttachmentsHandler handler)
{
GetErrorAttachmentsHandler = handler;
}
#if ENABLE_IL2CPP
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
#endif
public delegate void NativeSendingErrorReportDelegate(IntPtr report);
public static event Crashes.SendingErrorReportHandler SendingErrorReport;
[MonoPInvokeCallback(typeof(NativeSendingErrorReportDelegate))]
public static void SendingErrorReportNativeFunc(IntPtr report)
{
if (SendingErrorReport != null)
{
ErrorReport errorReport = CrashesInternal.GetErrorReportFromIntPtr(report);
SendingErrorReport(errorReport);
}
}
#if ENABLE_IL2CPP
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
#endif
public delegate void NativeSentErrorReportDelegate(IntPtr report);
public static event Crashes.SentErrorReportHandler SentErrorReport;
[MonoPInvokeCallback(typeof(NativeSentErrorReportDelegate))]
public static void SentErrorReportNativeFunc(IntPtr report)
{
if (SentErrorReport != null)
{
ErrorReport errorReport = CrashesInternal.GetErrorReportFromIntPtr(report);
SentErrorReport(errorReport);
}
}
#if ENABLE_IL2CPP
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
#endif
public delegate void NativeFailedToSendErrorReportDelegate(IntPtr report, IntPtr error);
public static event Crashes.FailedToSendErrorReportHandler FailedToSendErrorReport;
[MonoPInvokeCallback(typeof(NativeFailedToSendErrorReportDelegate))]
public static void FailedToSendErrorReportNativeFunc(IntPtr report, IntPtr error)
{
if (FailedToSendErrorReport != null)
{
var errorReport = CrashesInternal.GetErrorReportFromIntPtr(report);
var exception = NSErrorHelper.Convert(error);
FailedToSendErrorReport(errorReport, exception);
}
}
#region External
[DllImport("__Internal")]
private static extern void app_center_unity_crashes_set_delegate();
[DllImport("__Internal")]
private static extern void app_center_unity_crashes_delegate_set_should_process_error_report_delegate(NativeShouldProcessErrorReportDelegate functionPtr);
[DllImport("__Internal")]
private static extern void app_center_unity_crashes_delegate_set_get_error_attachments_delegate(NativeGetErrorAttachmentsDelegate functionPtr);
[DllImport("__Internal")]
private static extern void app_center_unity_crashes_delegate_set_sending_error_report_delegate(NativeSendingErrorReportDelegate functionPtr);
[DllImport("__Internal")]
private static extern void app_center_unity_crashes_delegate_set_sent_error_report_delegate(NativeSentErrorReportDelegate functionPtr);
[DllImport("__Internal")]
private static extern void app_center_unity_crashes_delegate_set_failed_to_send_error_report_delegate(NativeFailedToSendErrorReportDelegate functionPtr);
#endregion
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 2513223aa4b5240f4b429182fbd581d8
timeCreated: 1497901125
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,214 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_IOS && !UNITY_EDITOR
using AOT;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace Microsoft.AppCenter.Unity.Crashes.Internal
{
class CrashesInternal
{
public static void AddNativeType(List<IntPtr> nativeTypes)
{
nativeTypes.Add(appcenter_unity_crashes_get_type());
}
public static string TrackException(IntPtr exception, IDictionary<string, string> properties, ErrorAttachmentLog[] attachments)
{
var keys = properties == null ? null : properties.Keys.ToArray();
var values = properties == null ? null : properties.Values.ToArray();
var propertyCount = properties == null ? 0 : properties.Count;
var nativeAttachments = NativeObjectsConverter.ToNativeAttachments(attachments);
return appcenter_unity_crashes_track_exception_with_properties_with_attachments(exception, keys, values, propertyCount, nativeAttachments);
}
public static AppCenterTask SetEnabledAsync(bool isEnabled)
{
appcenter_unity_crashes_set_enabled(isEnabled);
return AppCenterTask.FromCompleted();
}
public static AppCenterTask<bool> IsEnabledAsync()
{
var isEnabled = appcenter_unity_crashes_is_enabled();
return AppCenterTask<bool>.FromCompleted(isEnabled);
}
public static void GenerateTestCrash()
{
appcenter_unity_crashes_generate_test_crash();
}
public static AppCenterTask<bool> HasCrashedInLastSessionAsync()
{
var hasCrashedInLastSession = appcenter_unity_crashes_has_crashed_in_last_session();
return AppCenterTask<bool>.FromCompleted(hasCrashedInLastSession);
}
public static void DisableMachExceptionHandler()
{
appcenter_unity_crashes_disable_mach_exception_handler();
}
public static AppCenterTask<ErrorReport> GetLastSessionCrashReportAsync()
{
var errorReportPtr = appcenter_unity_crashes_last_session_crash_report();
var errorReport = GetErrorReportFromIntPtr(errorReportPtr);
return AppCenterTask<ErrorReport>.FromCompleted(errorReport);
}
public static void SetUserConfirmationHandler(Crashes.UserConfirmationHandler handler)
{
appcenter_unity_crashes_set_user_confirmation_handler(handler);
}
public static void NotifyWithUserConfirmation(Crashes.ConfirmationResult answer)
{
appcenter_unity_crashes_notify_with_user_confirmation((int)answer);
}
public static void StartCrashes()
{
appcenter_unity_start_crashes();
}
public static ErrorReport GetErrorReportFromIntPtr(IntPtr errorReportPtr)
{
if (errorReportPtr == IntPtr.Zero)
{
return null;
}
var procId = app_center_unity_crashes_error_report_app_process_identifier(errorReportPtr);
var identifier = app_center_unity_crashes_error_report_incident_identifier(errorReportPtr);
var exceptionName = app_center_unity_crashes_error_report_exception_name(errorReportPtr);
var reporterKey = app_center_unity_crashes_error_report_reporter_key(errorReportPtr);
var reporterSignal = app_center_unity_crashes_error_report_signal(errorReportPtr);
var exceptionReason = app_center_unity_crashes_error_report_exception_reason(errorReportPtr);
var startTime = app_center_unity_crashes_error_report_app_start_time(errorReportPtr);
DateTimeOffset dtoStart = DateTimeOffset.UtcNow;
if (startTime != null)
{
dtoStart = DateTimeOffset.Parse(startTime);
}
var errorTime = app_center_unity_crashes_error_report_app_error_time(errorReportPtr);
DateTimeOffset dtoError = DateTimeOffset.UtcNow;
if (errorTime != null)
{
dtoError = DateTimeOffset.Parse(errorTime);
}
var isAppKill = app_center_unity_crashes_error_report_is_app_kill(errorReportPtr);
var exception = new Models.Exception(exceptionName + ": " + exceptionReason, "");
var device = GetDevice(errorReportPtr);
return new ErrorReport(identifier, dtoStart, dtoError, exception, procId, reporterKey, reporterSignal, isAppKill, device);
}
public static AppCenterTask<string> GetMinidumpDirectoryAsync()
{
return AppCenterTask<string>.FromCompleted("");
}
public static AppCenterTask<bool> HasReceivedMemoryWarningInLastSessionAsync()
{
var hadWarning = appcenter_unity_crashes_has_received_memory_warning_in_last_session();
return AppCenterTask<bool>.FromCompleted(hadWarning);
}
public static ErrorReport BuildHandledErrorReport(string errorId)
{
var nativeErrorReport = appcenter_unity_crashes_build_handled_error_report(errorId);
return GetErrorReportFromIntPtr(nativeErrorReport);
}
public static void SendErrorAttachments(string errorReportId, ErrorAttachmentLog[] attachments)
{
var nativeAttachments = NativeObjectsConverter.ToNativeAttachments(attachments);
appcenter_unity_crashes_send_error_attachments(errorReportId, nativeAttachments);
}
private static Device GetDevice(IntPtr errorReportPtr)
{
var device = app_center_unity_crashes_error_report_device(errorReportPtr);
return DeviceHelper.Convert(device);
}
#region External
[DllImport("__Internal")]
private static extern IntPtr appcenter_unity_crashes_get_type();
[DllImport("__Internal")]
private static extern bool appcenter_unity_crashes_has_received_memory_warning_in_last_session();
[DllImport("__Internal")]
private static extern string appcenter_unity_crashes_track_exception_with_properties_with_attachments(IntPtr exception, string[] propertyKeys, string[] propertyValues, int propertyCount, IntPtr attachments);
[DllImport("__Internal")]
private static extern void appcenter_unity_crashes_set_enabled(bool isEnabled);
[DllImport("__Internal")]
private static extern bool appcenter_unity_crashes_is_enabled();
[DllImport("__Internal")]
private static extern void appcenter_unity_crashes_generate_test_crash();
[DllImport("__Internal")]
private static extern bool appcenter_unity_crashes_has_crashed_in_last_session();
[DllImport("__Internal")]
private static extern void appcenter_unity_crashes_disable_mach_exception_handler();
[DllImport("__Internal")]
private static extern IntPtr appcenter_unity_crashes_last_session_crash_report();
[DllImport("__Internal")]
private static extern void appcenter_unity_crashes_set_user_confirmation_handler(Crashes.UserConfirmationHandler handler);
[DllImport("__Internal")]
private static extern void appcenter_unity_crashes_notify_with_user_confirmation(int code);
[DllImport("__Internal")]
private static extern string app_center_unity_crashes_error_report_exception_name(IntPtr errorReport);
[DllImport("__Internal")]
private static extern int app_center_unity_crashes_error_report_app_process_identifier(IntPtr errorReport);
[DllImport("__Internal")]
private static extern string app_center_unity_crashes_error_report_incident_identifier(IntPtr errorReport);
[DllImport("__Internal")]
private static extern string app_center_unity_crashes_error_report_reporter_key(IntPtr errorReport);
[DllImport("__Internal")]
private static extern string app_center_unity_crashes_error_report_signal(IntPtr errorReport);
[DllImport("__Internal")]
private static extern string app_center_unity_crashes_error_report_exception_reason(IntPtr errorReport);
[DllImport("__Internal")]
private static extern string app_center_unity_crashes_error_report_app_start_time(IntPtr errorReport);
[DllImport("__Internal")]
private static extern string app_center_unity_crashes_error_report_app_error_time(IntPtr errorReport);
[DllImport("__Internal")]
private static extern bool app_center_unity_crashes_error_report_is_app_kill(IntPtr errorReport);
[DllImport("__Internal")]
private static extern IntPtr app_center_unity_crashes_error_report_device(IntPtr errorReport);
[DllImport("__Internal")]
private static extern void appcenter_unity_start_crashes();
[DllImport("__Internal")]
private static extern void appcenter_unity_crashes_send_error_attachments(string errorReportId, IntPtr attachments);
[DllImport("__Internal")]
private static extern IntPtr appcenter_unity_crashes_build_handled_error_report(string errorId);
#endregion
}
}
#endif
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: e4d1e0d5c8ec2496ead8e892600d04c2
timeCreated: 1512519361
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,55 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_IOS
using System;
using System.Runtime.InteropServices;
namespace Microsoft.AppCenter.Unity.Crashes.Internal
{
public static class NativeObjectsConverter
{
public static IntPtr ToNativeAttachments(ErrorAttachmentLog[] logs)
{
if (logs == null)
{
return IntPtr.Zero;
}
var nativeArray = app_center_unity_crashes_create_error_attachments_array(logs.Length);
foreach (var errorAttachmentLog in logs)
{
if (errorAttachmentLog != null)
{
IntPtr nativeLog;
if (errorAttachmentLog.Type == ErrorAttachmentLog.AttachmentType.Text)
{
nativeLog = app_center_unity_crashes_create_error_attachment_log_text(errorAttachmentLog.Text, errorAttachmentLog.FileName);
}
else
{
nativeLog = app_center_unity_crashes_create_error_attachment_log_binary(errorAttachmentLog.Data, errorAttachmentLog.Data.Length, errorAttachmentLog.FileName, errorAttachmentLog.ContentType);
}
appcenter_unity_crashes_add_error_attachment(nativeArray, nativeLog);
}
}
return nativeArray;
}
#region External
[DllImport("__Internal")]
private static extern IntPtr app_center_unity_crashes_create_error_attachments_array(int capacity);
[DllImport("__Internal")]
private static extern IntPtr app_center_unity_crashes_create_error_attachment_log_text(string text, string fileName);
[DllImport("__Internal")]
private static extern IntPtr app_center_unity_crashes_create_error_attachment_log_binary(byte[] data, int size, string fileName, string contentType);
[DllImport("__Internal")]
private static extern void appcenter_unity_crashes_add_error_attachment(IntPtr attachments, IntPtr attachment);
#endregion
}
}
#endif
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 694cd3e96a3aa488883efce542ee8494
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,65 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#if UNITY_IOS && !UNITY_EDITOR
using System;
using System.Runtime.InteropServices;
namespace Microsoft.AppCenter.Unity.Crashes.Internal
{
class WrapperExceptionInternal
{
public static IntPtr Create()
{
return appcenter_unity_exception_create();
}
public static void SetType(IntPtr exception, string type)
{
appcenter_unity_exception_set_type(exception, type);
}
public static void SetMessage(IntPtr exception, string message)
{
appcenter_unity_exception_set_message(exception, message);
}
public static void SetStacktrace(IntPtr exception, string stacktrace)
{
appcenter_unity_exception_set_stacktrace(exception, stacktrace);
}
public static void SetInnerException(IntPtr exception, IntPtr innerExcetion)
{
appcenter_unity_exception_set_inner_exception(exception, innerExcetion);
}
public static void SetWrapperSdkName(IntPtr exception, string sdkName)
{
appcenter_unity_exception_set_wrapper_sdk_name(exception, sdkName);
}
#region External
[DllImport("__Internal")]
private static extern IntPtr appcenter_unity_exception_create();
[DllImport("__Internal")]
private static extern void appcenter_unity_exception_set_type(IntPtr exception, string type);
[DllImport("__Internal")]
private static extern void appcenter_unity_exception_set_message(IntPtr exception, string message);
[DllImport("__Internal")]
private static extern void appcenter_unity_exception_set_stacktrace(IntPtr exception, string stacktrace);
[DllImport("__Internal")]
private static extern void appcenter_unity_exception_set_inner_exception(IntPtr exception, IntPtr innerExcetion);
[DllImport("__Internal")]
private static extern void appcenter_unity_exception_set_wrapper_sdk_name(IntPtr exception, string key);
#endregion
}
}
#endif
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: aa953c3d4660b4b119f048d2681fb463
timeCreated: 1512582941
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: