Use secure storage for app id so that it will persist over reinstalls. Use separate app identifier for extension in hockeyapp.

This commit is contained in:
Kyle Spearrin 2016-07-27 18:46:55 -04:00
parent e742fca0e4
commit 9ef840412a
6 changed files with 40 additions and 19 deletions

View file

@ -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<string>(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();
}
}
}

View file

@ -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);
}
}
}

View file

@ -41,6 +41,10 @@
<HintPath>..\..\packages\HockeySDK.Xamarin.4.1.0-beta3\lib\Xamarin.iOS10\HockeySDK.iOSBindings.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Plugin.Settings, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xam.Plugins.Settings.2.1.0\lib\Xamarin.iOS10\Plugin.Settings.dll</HintPath>
<Private>True</Private>

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="HockeySDK.Xamarin" version="4.1.0-beta3" targetFramework="xamarinios10" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="xamarinios10" />
<package id="sqlite-net-pcl" version="1.1.2" targetFramework="xamarinios10" />
<package id="SQLitePCL.bundle_green" version="0.9.2" targetFramework="xamarinios10" />
<package id="SQLitePCL.raw" version="0.9.2" targetFramework="xamarinios10" />

View file

@ -46,10 +46,13 @@ namespace Bit.iOS.Extension
if(!_setupHockeyApp)
{
var crashManagerDelegate = new HockeyAppCrashManagerDelegate(Resolver.Resolve<IAppIdService>());
var appIdService = Resolver.Resolve<IAppIdService>();
var crashManagerDelegate = new HockeyAppCrashManagerDelegate(
appIdService, Resolver.Resolve<IAuthService>());
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;

View file

@ -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<IAppIdService>());
var appIdService = Resolver.Resolve<IAppIdService>();
var crashManagerDelegate = new HockeyAppCrashManagerDelegate(
appIdService, Resolver.Resolve<IAuthService>());
var manager = BITHockeyManager.SharedHockeyManager;
manager.Configure("51f96ae568ba45f699a18ad9f63046c3", crashManagerDelegate);
manager.CrashManager.CrashManagerStatus = BITCrashManagerStatus.AutoSend;
manager.UserId = appIdService.AppId;
manager.StartManager();
manager.Authenticator.AuthenticateInstallation();