app center;增加發送ping的秒
This commit is contained in:
1 parent
1bd1ffdb5a
commit
d754ff3b15
719 files changed
+34172
-2875
No files matched your search
@@ -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
|
||||
+13
@@ -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:
|
||||
Reference in new issue
Block a user