1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-26 05:03:39 +00:00

Conversion of HockeyApp to AppCenter for crash reporting (#810)

* Conversion of HockeyApp to AppCenter for crash reporting

* Corrected older-style nuget package definition
This commit is contained in:
Matt Portune
2020-04-02 09:02:38 -04:00
committed by GitHub
parent 915e8cf072
commit 4d3d8b643a
15 changed files with 138 additions and 142 deletions

View File

@@ -0,0 +1,58 @@
#if !FDROID
using Bit.Core.Abstractions;
using System.Threading.Tasks;
using Microsoft.AppCenter;
using Microsoft.AppCenter.Crashes;
using Newtonsoft.Json;
namespace Bit.Droid.Utilities
{
public class AppCenterHelper
{
private const string AppSecret = "d3834185-b4a6-4347-9047-b86c65293d42";
private readonly IAppIdService _appIdService;
private readonly IUserService _userService;
private string _userId;
private string _appId;
public AppCenterHelper(
IAppIdService appIdService,
IUserService userService)
{
_appIdService = appIdService;
_userService = userService;
}
public async Task InitAsync()
{
_userId = await _userService.GetUserIdAsync();
_appId = await _appIdService.GetAppIdAsync();
AppCenter.Start(AppSecret, typeof(Crashes));
AppCenter.SetUserId(_userId);
Crashes.GetErrorAttachments = (ErrorReport report) =>
{
return new ErrorAttachmentLog[]
{
ErrorAttachmentLog.AttachmentWithText(Description, "crshdesc.txt"),
};
};
}
public string Description
{
get
{
return JsonConvert.SerializeObject(new
{
AppId = _appId,
UserId = _userId
}, Formatting.Indented);
}
}
}
}
#endif

View File

@@ -1,69 +0,0 @@
#if !FDROID
using HockeyApp.Android;
using Bit.App.Abstractions;
using Newtonsoft.Json;
using Android.Runtime;
using Bit.Core.Abstractions;
using System.Threading.Tasks;
using Android.Content;
namespace Bit.Droid.Utilities
{
public class HockeyAppCrashManagerListener : CrashManagerListener
{
private const string HockeyAppId = "d3834185b4a643479047b86c65293d42";
private readonly IAppIdService _appIdService;
private readonly IUserService _userService;
private string _userId;
private string _appId;
public HockeyAppCrashManagerListener()
{ }
public HockeyAppCrashManagerListener(System.IntPtr javaRef, JniHandleOwnership transfer)
: base(javaRef, transfer)
{ }
public HockeyAppCrashManagerListener(
IAppIdService appIdService,
IUserService userService)
{
_appIdService = appIdService;
_userService = userService;
}
public async Task InitAsync(Context context)
{
_userId = await _userService.GetUserIdAsync();
_appId = await _appIdService.GetAppIdAsync();
CrashManager.Register(context, HockeyAppId, this);
}
public override string Description
{
get
{
if (_userId != null && _appId != null)
{
return JsonConvert.SerializeObject(new
{
AppId = _appId,
UserId = _userId
}, Formatting.Indented);
}
else
{
return null;
}
}
}
public override bool ShouldAutoUploadCrashes()
{
return true;
}
}
}
#endif