diff --git a/src/App/Services/AppIdService.cs b/src/App/Services/AppIdService.cs index 16f589a62..8ae0218eb 100644 --- a/src/App/Services/AppIdService.cs +++ b/src/App/Services/AppIdService.cs @@ -1,38 +1,38 @@ using System; using Bit.App.Abstractions; -using Plugin.Settings.Abstractions; namespace Bit.App.Services { public class AppIdService : IAppIdService { private const string AppIdKey = "appId"; - private readonly ISettings _settings; - private string _appId; + private readonly ISecureStorageService _secureStorageService; + private Guid? _appId; - public AppIdService(ISettings settings) + public AppIdService(ISecureStorageService secureStorageService) { - _settings = settings; + _secureStorageService = secureStorageService; } public string AppId { get { - if(!string.IsNullOrWhiteSpace(_appId)) + if(_appId.HasValue) { - return _appId; + return _appId.Value.ToString(); } - _appId = _settings.GetValueOrDefault(AppIdKey); - if(!string.IsNullOrWhiteSpace(_appId)) + var appIdBytes = _secureStorageService.Retrieve(AppIdKey); + if(appIdBytes != null) { - return _appId; + _appId = new Guid(appIdBytes); + return _appId.Value.ToString(); } - _appId = Guid.NewGuid().ToString(); - _settings.AddOrUpdateValue(AppIdKey, _appId); - return _appId; + _appId = Guid.NewGuid(); + _secureStorageService.Store(AppIdKey, _appId.Value.ToByteArray()); + return _appId.Value.ToString(); } } } diff --git a/src/iOS.Core/HockeyAppCrashManagerDelegate.cs b/src/iOS.Core/HockeyAppCrashManagerDelegate.cs index c5173f5e3..4016f5ce8 100644 --- a/src/iOS.Core/HockeyAppCrashManagerDelegate.cs +++ b/src/iOS.Core/HockeyAppCrashManagerDelegate.cs @@ -1,20 +1,31 @@ using Bit.App.Abstractions; using HockeyApp.iOS; +using Newtonsoft.Json; + namespace Bit.iOS.Core { public class HockeyAppCrashManagerDelegate : BITCrashManagerDelegate { private readonly IAppIdService _appIdService; + private readonly IAuthService _authService; public HockeyAppCrashManagerDelegate( - IAppIdService appIdService) + IAppIdService appIdService, + IAuthService authService) { _appIdService = appIdService; + _authService = authService; } public override string ApplicationLogForCrashManager(BITCrashManager crashManager) { - return $"AppId:{_appIdService.AppId}"; + var log = new + { + AppId = _appIdService.AppId, + UserId = _authService.UserId + }; + + return JsonConvert.SerializeObject(log, Formatting.Indented); } } } diff --git a/src/iOS.Core/iOS.Core.csproj b/src/iOS.Core/iOS.Core.csproj index bece2739b..1c713cf93 100644 --- a/src/iOS.Core/iOS.Core.csproj +++ b/src/iOS.Core/iOS.Core.csproj @@ -41,6 +41,10 @@ ..\..\packages\HockeySDK.Xamarin.4.1.0-beta3\lib\Xamarin.iOS10\HockeySDK.iOSBindings.dll True + + ..\..\packages\Newtonsoft.Json.9.0.1\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.Json.dll + True + ..\..\packages\Xam.Plugins.Settings.2.1.0\lib\Xamarin.iOS10\Plugin.Settings.dll True diff --git a/src/iOS.Core/packages.config b/src/iOS.Core/packages.config index 9d1d5758c..993d561f9 100644 --- a/src/iOS.Core/packages.config +++ b/src/iOS.Core/packages.config @@ -1,6 +1,7 @@  + diff --git a/src/iOS.Extension/LoadingViewController.cs b/src/iOS.Extension/LoadingViewController.cs index 1f94b3fec..be696ba13 100644 --- a/src/iOS.Extension/LoadingViewController.cs +++ b/src/iOS.Extension/LoadingViewController.cs @@ -46,10 +46,13 @@ namespace Bit.iOS.Extension if(!_setupHockeyApp) { - var crashManagerDelegate = new HockeyAppCrashManagerDelegate(Resolver.Resolve()); + var appIdService = Resolver.Resolve(); + var crashManagerDelegate = new HockeyAppCrashManagerDelegate( + appIdService, Resolver.Resolve()); var manager = HockeyApp.iOS.BITHockeyManager.SharedHockeyManager; - manager.Configure("51f96ae568ba45f699a18ad9f63046c3", crashManagerDelegate); + manager.Configure("bff5b1d2b6554472b91555a0d4704d4c", crashManagerDelegate); manager.CrashManager.CrashManagerStatus = HockeyApp.iOS.BITCrashManagerStatus.AutoSend; + manager.UserId = appIdService.AppId; manager.StartManager(); manager.Authenticator.AuthenticateInstallation(); _setupHockeyApp = true; diff --git a/src/iOS/AppDelegate.cs b/src/iOS/AppDelegate.cs index 8f362130f..5b4d32911 100644 --- a/src/iOS/AppDelegate.cs +++ b/src/iOS/AppDelegate.cs @@ -18,7 +18,6 @@ using Plugin.Fingerprint.Abstractions; using Plugin.Settings.Abstractions; using System.Diagnostics; using Xamarin.Forms; -using Bit.App; using Bit.iOS.Core.Services; using PushNotification.Plugin; using Plugin.DeviceInfo; @@ -44,10 +43,13 @@ namespace Bit.iOS SetIoc(); } - var crashManagerDelegate = new HockeyAppCrashManagerDelegate(Resolver.Resolve()); + var appIdService = Resolver.Resolve(); + var crashManagerDelegate = new HockeyAppCrashManagerDelegate( + appIdService, Resolver.Resolve()); var manager = BITHockeyManager.SharedHockeyManager; manager.Configure("51f96ae568ba45f699a18ad9f63046c3", crashManagerDelegate); manager.CrashManager.CrashManagerStatus = BITCrashManagerStatus.AutoSend; + manager.UserId = appIdService.AppId; manager.StartManager(); manager.Authenticator.AuthenticateInstallation();