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,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: