mirror of
https://github.com/bitwarden/android.git
synced 2025-01-06 00:07:54 +03:00
39 lines
976 B
C#
39 lines
976 B
C#
|
using Bit.Core.Abstractions;
|
|||
|
using System;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace Bit.Core.Services
|
|||
|
{
|
|||
|
public class AppIdService
|
|||
|
{
|
|||
|
private readonly IStorageService _storageService;
|
|||
|
|
|||
|
public AppIdService(IStorageService storageService)
|
|||
|
{
|
|||
|
_storageService = storageService;
|
|||
|
}
|
|||
|
|
|||
|
public Task<string> GetAppIdAsync()
|
|||
|
{
|
|||
|
return MakeAndGetAppIdAsync("appId");
|
|||
|
}
|
|||
|
|
|||
|
public Task<string> GetAnonymousAppIdAsync()
|
|||
|
{
|
|||
|
return MakeAndGetAppIdAsync("anonymousAppId");
|
|||
|
}
|
|||
|
|
|||
|
private async Task<string> MakeAndGetAppIdAsync(string key)
|
|||
|
{
|
|||
|
var existingId = await _storageService.GetAsync<string>(key);
|
|||
|
if(existingId != null)
|
|||
|
{
|
|||
|
return existingId;
|
|||
|
}
|
|||
|
var guid = Guid.NewGuid().ToString();
|
|||
|
await _storageService.SaveAsync(key, guid);
|
|||
|
return guid;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|