From 026dd4761e70b1230b72b85e2d504fa9686cf065 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 28 May 2019 23:14:02 -0400 Subject: [PATCH] hockeyapp --- src/Android/Android.csproj | 1 + src/Android/MainActivity.cs | 11 ++++ .../HockeyAppCrashManagerListener.cs | 65 +++++++++++++++++++ src/Android/ci-build-apks.ps1 | 20 +++--- src/App/App.csproj | 3 +- 5 files changed, 89 insertions(+), 11 deletions(-) create mode 100644 src/Android/Utilities/HockeyAppCrashManagerListener.cs diff --git a/src/Android/Android.csproj b/src/Android/Android.csproj index d1226b869..738908b25 100644 --- a/src/Android/Android.csproj +++ b/src/Android/Android.csproj @@ -139,6 +139,7 @@ + diff --git a/src/Android/MainActivity.cs b/src/Android/MainActivity.cs index bc5fecb76..70f24bd67 100644 --- a/src/Android/MainActivity.cs +++ b/src/Android/MainActivity.cs @@ -30,8 +30,11 @@ namespace Bit.Droid private IDeviceActionService _deviceActionService; private IMessagingService _messagingService; private IBroadcasterService _broadcasterService; + private IUserService _userService; + private IAppIdService _appIdService; private PendingIntent _lockAlarmPendingIntent; private AppOptions _appOptions; + private const string HockeyAppId = "d3834185b4a643479047b86c65293d42"; private Java.Util.Regex.Pattern _otpPattern = Java.Util.Regex.Pattern.Compile("^.*?([cbdefghijklnrtuv]{32,64})$"); @@ -47,6 +50,8 @@ namespace Bit.Droid _deviceActionService = ServiceContainer.Resolve("deviceActionService"); _messagingService = ServiceContainer.Resolve("messagingService"); _broadcasterService = ServiceContainer.Resolve("broadcasterService"); + _userService = ServiceContainer.Resolve("userService"); + _appIdService = ServiceContainer.Resolve("appIdService"); TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; @@ -57,6 +62,12 @@ namespace Bit.Droid Window.AddFlags(Android.Views.WindowManagerFlags.Secure); } +#if !FDROID + var hockeyAppListener = new HockeyAppCrashManagerListener(_appIdService, _userService); + var hockeyAppTask = hockeyAppListener.InitAsync(); + HockeyApp.Android.CrashManager.Register(this, HockeyAppId, hockeyAppListener); +#endif + Xamarin.Essentials.Platform.Init(this, savedInstanceState); Xamarin.Forms.Forms.Init(this, savedInstanceState); _appOptions = GetOptions(); diff --git a/src/Android/Utilities/HockeyAppCrashManagerListener.cs b/src/Android/Utilities/HockeyAppCrashManagerListener.cs new file mode 100644 index 000000000..0fdcc4408 --- /dev/null +++ b/src/Android/Utilities/HockeyAppCrashManagerListener.cs @@ -0,0 +1,65 @@ +#if !FDROID +using HockeyApp.Android; +using Bit.App.Abstractions; +using Newtonsoft.Json; +using Android.Runtime; +using Bit.Core.Abstractions; +using System.Threading.Tasks; + +namespace Bit.Droid.Utilities +{ + public class HockeyAppCrashManagerListener : CrashManagerListener + { + 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() + { + _userId = await _userService.GetUserIdAsync(); + _appId = await _appIdService.GetAppIdAsync(); + } + + 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 diff --git a/src/Android/ci-build-apks.ps1 b/src/Android/ci-build-apks.ps1 index 0cdc942e6..bfd871d57 100644 --- a/src/Android/ci-build-apks.ps1 +++ b/src/Android/ci-build-apks.ps1 @@ -56,16 +56,16 @@ $firebaseNode.ParentNode.RemoveChild($firebaseNode); $xml.Save($androidPath); -#echo "##### Uninstall from App.csproj" -# -#$xml=New-Object XML; -#$xml.Load($appPath); -# -#$hockeyNode=$xml.SelectSingleNode("/Project/ItemGroup/PackageReference[@Include='HockeySDK.Xamarin']"); -#$hockeyNode.ParentNode.RemoveChild($hockeyNode); -# -#$xml.Save($appPath); -# +echo "##### Uninstall from App.csproj" + +$xml=New-Object XML; +$xml.Load($appPath); + +$hockeyNode=$xml.SelectSingleNode("/Project/ItemGroup/PackageReference[@Include='HockeySDK.Xamarin']"); +$hockeyNode.ParentNode.RemoveChild($hockeyNode); + +$xml.Save($appPath); + echo "##### Restore NuGet" $nugetPath = $($rootPath + "\nuget.exe"); diff --git a/src/App/App.csproj b/src/App/App.csproj index f2d2ffb83..212cd358b 100644 --- a/src/App/App.csproj +++ b/src/App/App.csproj @@ -13,10 +13,11 @@ + - +