1
0
mirror of https://github.com/bitwarden/mobile synced 2026-01-02 00:23:15 +00:00

Created anonymous app id for google analytics.

This commit is contained in:
Kyle Spearrin
2016-08-06 19:03:48 -04:00
parent a267bf9cf7
commit 98ceaba5f5
4 changed files with 22 additions and 19 deletions

View File

@@ -3,5 +3,6 @@
public interface IAppIdService
{
string AppId { get; }
string AnonymousAppId { get; }
}
}

View File

@@ -6,34 +6,36 @@ namespace Bit.App.Services
public class AppIdService : IAppIdService
{
private const string AppIdKey = "appId";
private const string AnonymousAppIdKey = "anonymousAppId";
private readonly ISecureStorageService _secureStorageService;
private Guid? _appId;
private Guid? _anonymousAppId;
public AppIdService(ISecureStorageService secureStorageService)
{
_secureStorageService = secureStorageService;
}
public string AppId
public string AppId => GetAppId(AppIdKey, ref _appId);
public string AnonymousAppId => GetAppId(AnonymousAppIdKey, ref _anonymousAppId);
private string GetAppId(string key, ref Guid? appId)
{
get
if(appId.HasValue)
{
if(_appId.HasValue)
{
return _appId.Value.ToString();
}
var appIdBytes = _secureStorageService.Retrieve(AppIdKey);
if(appIdBytes != null)
{
_appId = new Guid(appIdBytes);
return _appId.Value.ToString();
}
_appId = Guid.NewGuid();
_secureStorageService.Store(AppIdKey, _appId.Value.ToByteArray());
return _appId.Value.ToString();
return appId.Value.ToString();
}
var appIdBytes = _secureStorageService.Retrieve(key);
if(appIdBytes != null)
{
appId = new Guid(appIdBytes);
return appId.Value.ToString();
}
appId = Guid.NewGuid();
_secureStorageService.Store(key, appId.Value.ToByteArray());
return appId.Value.ToString();
}
}
}