1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-12-25 16:47:55 +01: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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 138 additions and 142 deletions

View File

@ -19,7 +19,7 @@
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType> <AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
<NuGetPackageImportStamp> <NuGetPackageImportStamp>
</NuGetPackageImportStamp> </NuGetPackageImportStamp>
<AndroidLinkSkip>Xamarin.GooglePlayServices.Base;Xamarin.GooglePlayServices.Basement;Xamarin.GooglePlayServices.Measurement;Xamarin.GooglePlayServices.Gcm;BitwardenAndroid;BitwardenApp;BitwardenCore;Xamarin.Android.Net;Xamarin.Android.Net.OldAndroidSSLSocketFactory;LiteDB</AndroidLinkSkip> <AndroidLinkSkip>Xamarin.GooglePlayServices.Base;Xamarin.GooglePlayServices.Basement;Xamarin.GooglePlayServices.Measurement;Xamarin.GooglePlayServices.Gcm;BitwardenAndroid;BitwardenApp;BitwardenCore;Xamarin.Android.Net;Xamarin.Android.Net.OldAndroidSSLSocketFactory;LiteDB;Microsoft.AppCenter.Crashes</AndroidLinkSkip>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
@ -140,7 +140,7 @@
<Compile Include="Tiles\GeneratorTileService.cs" /> <Compile Include="Tiles\GeneratorTileService.cs" />
<Compile Include="Tiles\MyVaultTileService.cs" /> <Compile Include="Tiles\MyVaultTileService.cs" />
<Compile Include="Utilities\AndroidHelpers.cs" /> <Compile Include="Utilities\AndroidHelpers.cs" />
<Compile Include="Utilities\HockeyAppCrashManagerListener.cs" /> <Compile Include="Utilities\AppCenterHelper.cs" />
<Compile Include="Utilities\StaticStore.cs" /> <Compile Include="Utilities\StaticStore.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -79,8 +79,8 @@ namespace Bit.Droid
} }
#if !FDROID #if !FDROID
var hockeyAppListener = new HockeyAppCrashManagerListener(_appIdService, _userService); var appCenterHelper = new AppCenterHelper(_appIdService, _userService);
var hockeyAppTask = hockeyAppListener.InitAsync(this); var appCenterTask = appCenterHelper.InitAsync();
#endif #endif
Xamarin.Essentials.Platform.Init(this, savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState);

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

View File

@ -108,8 +108,8 @@ echo "########################################"
$xml=New-Object XML; $xml=New-Object XML;
$xml.Load($appPath); $xml.Load($appPath);
$hockeyNode=$xml.SelectSingleNode("/Project/ItemGroup/PackageReference[@Include='HockeySDK.Xamarin']"); $appCenterNode=$xml.SelectSingleNode("/Project/ItemGroup/PackageReference[@Include='Microsoft.AppCenter.Crashes']");
$hockeyNode.ParentNode.RemoveChild($hockeyNode); $appCenterNode.ParentNode.RemoveChild($appCenterNode);
$xml.Save($appPath); $xml.Save($appPath);

View File

@ -13,7 +13,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="HockeySDK.Xamarin" Version="5.2.0" /> <PackageReference Include="Microsoft.AppCenter.Crashes" Version="3.1.0" />
<PackageReference Include="Plugin.Fingerprint" Version="2.1.1" /> <PackageReference Include="Plugin.Fingerprint" Version="2.1.1" />
<PackageReference Include="Xamarin.Essentials" Version="1.5.1" /> <PackageReference Include="Xamarin.Essentials" Version="1.5.1" />
<PackageReference Include="Xamarin.FFImageLoading.Forms" Version="2.4.11.982" /> <PackageReference Include="Xamarin.FFImageLoading.Forms" Version="2.4.11.982" />

View File

@ -15,7 +15,7 @@ namespace Bit.iOS.Autofill
public partial class CredentialProviderViewController : ASCredentialProviderViewController public partial class CredentialProviderViewController : ASCredentialProviderViewController
{ {
private Context _context; private Context _context;
private bool _initedHockeyApp; private bool _initedAppCenter;
public CredentialProviderViewController(IntPtr handle) public CredentialProviderViewController(IntPtr handle)
: base(handle) : base(handle)
@ -270,10 +270,10 @@ namespace Bit.iOS.Autofill
iOSCoreHelpers.RegisterLocalServices(); iOSCoreHelpers.RegisterLocalServices();
var deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService"); var deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
ServiceContainer.Init(deviceActionService.DeviceUserAgent); ServiceContainer.Init(deviceActionService.DeviceUserAgent);
if (!_initedHockeyApp) if (!_initedAppCenter)
{ {
iOSCoreHelpers.RegisterHockeyApp(); iOSCoreHelpers.RegisterAppCenter();
_initedHockeyApp = true; _initedAppCenter = true;
} }
iOSCoreHelpers.Bootstrap(); iOSCoreHelpers.Bootstrap();
iOSCoreHelpers.AppearanceAdjustments(deviceActionService); iOSCoreHelpers.AppearanceAdjustments(deviceActionService);

View File

@ -252,8 +252,8 @@
<BundleResource Include="Resources\logo_white%403x.png" /> <BundleResource Include="Resources\logo_white%403x.png" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="HockeySDK.Xamarin"> <PackageReference Include="Microsoft.AppCenter.Crashes">
<Version>5.2.0</Version> <Version>3.1.0</Version>
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.AppExtension.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.AppExtension.CSharp.targets" />

View File

@ -0,0 +1,56 @@
using Bit.Core.Abstractions;
using System.Threading.Tasks;
using Microsoft.AppCenter;
using Microsoft.AppCenter.Crashes;
using Newtonsoft.Json;
namespace Bit.iOS.Core.Utilities
{
public class AppCenterHelper
{
private const string AppSecret = "51f96ae5-68ba-45f6-99a1-8ad9f63046c3";
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);
}
}
}
}

View File

@ -1,48 +0,0 @@
using Bit.Core.Abstractions;
using HockeyApp.iOS;
using Newtonsoft.Json;
using System.Threading.Tasks;
namespace Bit.iOS.Core.Utilities
{
public class HockeyAppCrashManagerDelegate : BITCrashManagerDelegate
{
private const string HockeyAppId = "51f96ae568ba45f699a18ad9f63046c3";
private readonly IAppIdService _appIdService;
private readonly IUserService _userService;
private string _userId;
private string _appId;
public HockeyAppCrashManagerDelegate(
IAppIdService appIdService,
IUserService userService)
{
_appIdService = appIdService;
_userService = userService;
}
public async Task InitAsync()
{
_userId = await _userService.GetUserIdAsync();
_appId = await _appIdService.GetAppIdAsync();
var manager = BITHockeyManager.SharedHockeyManager;
manager.Configure(HockeyAppId, this);
manager.CrashManager.CrashManagerStatus = BITCrashManagerStatus.AutoSend;
manager.UserId = _userId;
manager.Authenticator.AuthenticateInstallation();
manager.DisableMetricsManager = manager.DisableFeedbackManager = manager.DisableUpdateManager = true;
manager.StartManager();
}
public override string ApplicationLogForCrashManager(BITCrashManager crashManager)
{
return JsonConvert.SerializeObject(new
{
AppId = _appId,
UserId = _userId
}, Formatting.Indented);
}
}
}

View File

@ -9,7 +9,6 @@ using Bit.Core.Services;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Bit.iOS.Core.Services; using Bit.iOS.Core.Services;
using Foundation; using Foundation;
using HockeyApp.iOS;
using UIKit; using UIKit;
namespace Bit.iOS.Core.Utilities namespace Bit.iOS.Core.Utilities
@ -22,12 +21,12 @@ namespace Bit.iOS.Core.Utilities
public static string AppGroupId = "group.com.8bit.bitwarden"; public static string AppGroupId = "group.com.8bit.bitwarden";
public static string AccessGroup = "LTZ2PFU5D6.com.8bit.bitwarden"; public static string AccessGroup = "LTZ2PFU5D6.com.8bit.bitwarden";
public static void RegisterHockeyApp() public static void RegisterAppCenter()
{ {
var crashManagerDelegate = new HockeyAppCrashManagerDelegate( var appCenterHelper = new AppCenterHelper(
ServiceContainer.Resolve<IAppIdService>("appIdService"), ServiceContainer.Resolve<IAppIdService>("appIdService"),
ServiceContainer.Resolve<IUserService>("userService")); ServiceContainer.Resolve<IUserService>("userService"));
var task = crashManagerDelegate.InitAsync(); var appCenterTask = appCenterHelper.InitAsync();
} }
public static void RegisterLocalServices() public static void RegisterLocalServices()

View File

@ -91,7 +91,7 @@
<Compile Include="Services\DeviceActionService.cs" /> <Compile Include="Services\DeviceActionService.cs" />
<Compile Include="Utilities\ASHelpers.cs" /> <Compile Include="Utilities\ASHelpers.cs" />
<Compile Include="Utilities\Dialogs.cs" /> <Compile Include="Utilities\Dialogs.cs" />
<Compile Include="Utilities\HockeyAppCrashManagerDelegate.cs" /> <Compile Include="Utilities\AppCenterHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\CryptoPrimitiveService.cs" /> <Compile Include="Services\CryptoPrimitiveService.cs" />
<Compile Include="Services\KeyChainStorageService.cs" /> <Compile Include="Services\KeyChainStorageService.cs" />

View File

@ -19,7 +19,7 @@ namespace Bit.iOS.Extension
public partial class LoadingViewController : ExtendedUIViewController public partial class LoadingViewController : ExtendedUIViewController
{ {
private Context _context = new Context(); private Context _context = new Context();
private bool _initedHockeyApp; private bool _initedAppCenter;
public LoadingViewController(IntPtr handle) public LoadingViewController(IntPtr handle)
: base(handle) : base(handle)
@ -389,10 +389,10 @@ namespace Bit.iOS.Extension
iOSCoreHelpers.RegisterLocalServices(); iOSCoreHelpers.RegisterLocalServices();
var deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService"); var deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
ServiceContainer.Init(deviceActionService.DeviceUserAgent); ServiceContainer.Init(deviceActionService.DeviceUserAgent);
if (!_initedHockeyApp) if (!_initedAppCenter)
{ {
iOSCoreHelpers.RegisterHockeyApp(); iOSCoreHelpers.RegisterAppCenter();
_initedHockeyApp = true; _initedAppCenter = true;
} }
iOSCoreHelpers.Bootstrap(); iOSCoreHelpers.Bootstrap();
iOSCoreHelpers.AppearanceAdjustments(deviceActionService); iOSCoreHelpers.AppearanceAdjustments(deviceActionService);

View File

@ -227,8 +227,8 @@
<BundleResource Include="Resources\logo_white%403x.png" /> <BundleResource Include="Resources\logo_white%403x.png" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="HockeySDK.Xamarin"> <PackageReference Include="Microsoft.AppCenter.Crashes">
<Version>5.2.0</Version> <Version>3.1.0</Version>
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.AppExtension.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.AppExtension.CSharp.targets" />

View File

@ -276,7 +276,7 @@ namespace Bit.iOS
RegisterPush(); RegisterPush();
var deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService"); var deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
ServiceContainer.Init(deviceActionService.DeviceUserAgent); ServiceContainer.Init(deviceActionService.DeviceUserAgent);
iOSCoreHelpers.RegisterHockeyApp(); iOSCoreHelpers.RegisterAppCenter();
_pushHandler = new iOSPushNotificationHandler( _pushHandler = new iOSPushNotificationHandler(
ServiceContainer.Resolve<IPushNotificationListenerService>("pushNotificationListenerService")); ServiceContainer.Resolve<IPushNotificationListenerService>("pushNotificationListenerService"));
_nfcDelegate = new NFCReaderDelegate((success, message) => _nfcDelegate = new NFCReaderDelegate((success, message) =>