2019-05-30 21:13:02 +03:00
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Bit.App.Pages;
|
2019-05-30 06:35:34 +03:00
|
|
|
|
using Bit.App.Resources;
|
2019-05-30 21:13:02 +03:00
|
|
|
|
using Bit.Core;
|
2019-05-30 06:35:34 +03:00
|
|
|
|
using Bit.Core.Abstractions;
|
|
|
|
|
using Bit.Core.Models.View;
|
|
|
|
|
using Bit.Core.Utilities;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Bit.App.Utilities
|
|
|
|
|
{
|
|
|
|
|
public static class AppHelpers
|
|
|
|
|
{
|
|
|
|
|
public static async Task<string> CipherListOptions(ContentPage page, CipherView cipher)
|
|
|
|
|
{
|
|
|
|
|
var platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
|
2019-07-13 00:29:40 +03:00
|
|
|
|
var eventService = ServiceContainer.Resolve<IEventService>("eventService");
|
2019-05-30 06:35:34 +03:00
|
|
|
|
var options = new List<string> { AppResources.View, AppResources.Edit };
|
|
|
|
|
if(cipher.Type == Core.Enums.CipherType.Login)
|
|
|
|
|
{
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(cipher.Login.Username))
|
|
|
|
|
{
|
|
|
|
|
options.Add(AppResources.CopyUsername);
|
|
|
|
|
}
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(cipher.Login.Password))
|
|
|
|
|
{
|
|
|
|
|
options.Add(AppResources.CopyPassword);
|
|
|
|
|
}
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(cipher.Login.Totp))
|
|
|
|
|
{
|
2019-06-13 15:44:07 +03:00
|
|
|
|
var userService = ServiceContainer.Resolve<IUserService>("userService");
|
|
|
|
|
var canAccessPremium = await userService.CanAccessPremiumAsync();
|
|
|
|
|
if(canAccessPremium || cipher.OrganizationUseTotp)
|
|
|
|
|
{
|
|
|
|
|
options.Add(AppResources.CopyTotp);
|
|
|
|
|
}
|
2019-05-30 06:35:34 +03:00
|
|
|
|
}
|
|
|
|
|
if(cipher.Login.CanLaunch)
|
|
|
|
|
{
|
|
|
|
|
options.Add(AppResources.Launch);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(cipher.Type == Core.Enums.CipherType.Card)
|
|
|
|
|
{
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(cipher.Card.Number))
|
|
|
|
|
{
|
|
|
|
|
options.Add(AppResources.CopyNumber);
|
|
|
|
|
}
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(cipher.Card.Code))
|
|
|
|
|
{
|
|
|
|
|
options.Add(AppResources.CopySecurityCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(cipher.Type == Core.Enums.CipherType.SecureNote)
|
|
|
|
|
{
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(cipher.Notes))
|
|
|
|
|
{
|
|
|
|
|
options.Add(AppResources.CopyNotes);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var selection = await page.DisplayActionSheet(cipher.Name, AppResources.Cancel, null, options.ToArray());
|
|
|
|
|
if(selection == AppResources.View)
|
|
|
|
|
{
|
|
|
|
|
await page.Navigation.PushModalAsync(new NavigationPage(new ViewPage(cipher.Id)));
|
|
|
|
|
}
|
|
|
|
|
else if(selection == AppResources.Edit)
|
|
|
|
|
{
|
|
|
|
|
await page.Navigation.PushModalAsync(new NavigationPage(new AddEditPage(cipher.Id)));
|
|
|
|
|
}
|
|
|
|
|
else if(selection == AppResources.CopyUsername)
|
|
|
|
|
{
|
|
|
|
|
await platformUtilsService.CopyToClipboardAsync(cipher.Login.Username);
|
2019-05-30 16:15:59 +03:00
|
|
|
|
platformUtilsService.ShowToast("info", null,
|
|
|
|
|
string.Format(AppResources.ValueHasBeenCopied, AppResources.Username));
|
2019-05-30 06:35:34 +03:00
|
|
|
|
}
|
|
|
|
|
else if(selection == AppResources.CopyPassword)
|
|
|
|
|
{
|
|
|
|
|
await platformUtilsService.CopyToClipboardAsync(cipher.Login.Password);
|
2019-05-30 16:15:59 +03:00
|
|
|
|
platformUtilsService.ShowToast("info", null,
|
|
|
|
|
string.Format(AppResources.ValueHasBeenCopied, AppResources.Password));
|
2019-07-13 00:29:40 +03:00
|
|
|
|
var task = eventService.CollectAsync(Core.Enums.EventType.Cipher_ClientCopiedPassword, cipher.Id);
|
2019-05-30 06:35:34 +03:00
|
|
|
|
}
|
|
|
|
|
else if(selection == AppResources.CopyTotp)
|
|
|
|
|
{
|
|
|
|
|
var totpService = ServiceContainer.Resolve<ITotpService>("totpService");
|
|
|
|
|
var totp = await totpService.GetCodeAsync(cipher.Login.Totp);
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(totp))
|
|
|
|
|
{
|
|
|
|
|
await platformUtilsService.CopyToClipboardAsync(totp);
|
2019-05-30 16:15:59 +03:00
|
|
|
|
platformUtilsService.ShowToast("info", null,
|
|
|
|
|
string.Format(AppResources.ValueHasBeenCopied, AppResources.VerificationCodeTotp));
|
2019-05-30 06:35:34 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(selection == AppResources.Launch)
|
|
|
|
|
{
|
|
|
|
|
platformUtilsService.LaunchUri(cipher.Login.LaunchUri);
|
|
|
|
|
}
|
|
|
|
|
else if(selection == AppResources.CopyNumber)
|
|
|
|
|
{
|
|
|
|
|
await platformUtilsService.CopyToClipboardAsync(cipher.Card.Number);
|
|
|
|
|
platformUtilsService.ShowToast("info", null,
|
|
|
|
|
string.Format(AppResources.ValueHasBeenCopied, AppResources.Number));
|
|
|
|
|
}
|
|
|
|
|
else if(selection == AppResources.CopySecurityCode)
|
|
|
|
|
{
|
|
|
|
|
await platformUtilsService.CopyToClipboardAsync(cipher.Card.Code);
|
|
|
|
|
platformUtilsService.ShowToast("info", null,
|
|
|
|
|
string.Format(AppResources.ValueHasBeenCopied, AppResources.SecurityCode));
|
2019-07-13 00:29:40 +03:00
|
|
|
|
var task = eventService.CollectAsync(Core.Enums.EventType.Cipher_ClientCopiedCardCode, cipher.Id);
|
2019-05-30 06:35:34 +03:00
|
|
|
|
}
|
|
|
|
|
else if(selection == AppResources.CopyNotes)
|
|
|
|
|
{
|
|
|
|
|
await platformUtilsService.CopyToClipboardAsync(cipher.Notes);
|
|
|
|
|
platformUtilsService.ShowToast("info", null,
|
|
|
|
|
string.Format(AppResources.ValueHasBeenCopied, AppResources.Notes));
|
|
|
|
|
}
|
|
|
|
|
return selection;
|
|
|
|
|
}
|
2019-05-30 21:13:02 +03:00
|
|
|
|
|
|
|
|
|
public static async Task<bool> PerformUpdateTasksAsync(ISyncService syncService,
|
|
|
|
|
IDeviceActionService deviceActionService, IStorageService storageService)
|
|
|
|
|
{
|
|
|
|
|
var currentBuild = deviceActionService.GetBuildNumber();
|
|
|
|
|
var lastBuild = await storageService.GetAsync<string>(Constants.LastBuildKey);
|
2019-10-06 04:36:47 +03:00
|
|
|
|
if(lastBuild == null)
|
2019-05-30 21:13:02 +03:00
|
|
|
|
{
|
2019-10-06 04:36:47 +03:00
|
|
|
|
// Installed
|
|
|
|
|
var currentLock = await storageService.GetAsync<int?>(Constants.LockOptionKey);
|
|
|
|
|
if(currentLock == null)
|
2019-05-30 22:11:22 +03:00
|
|
|
|
{
|
2019-10-06 04:36:47 +03:00
|
|
|
|
await storageService.SaveAsync(Constants.LockOptionKey, 15);
|
2019-05-30 22:11:22 +03:00
|
|
|
|
}
|
2019-05-30 21:13:02 +03:00
|
|
|
|
}
|
2019-10-06 04:36:47 +03:00
|
|
|
|
else if(lastBuild != currentBuild)
|
|
|
|
|
{
|
|
|
|
|
// Updated
|
|
|
|
|
var tasks = Task.Run(() => syncService.FullSyncAsync(true));
|
|
|
|
|
}
|
2019-05-30 21:13:02 +03:00
|
|
|
|
if(lastBuild != currentBuild)
|
|
|
|
|
{
|
|
|
|
|
await storageService.SaveAsync(Constants.LastBuildKey, currentBuild);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-05-30 06:35:34 +03:00
|
|
|
|
}
|
|
|
|
|
}
|