log autofill events

This commit is contained in:
Kyle Spearrin 2019-07-22 15:50:59 -04:00
parent 0c75374c0f
commit f9547f158e
10 changed files with 33 additions and 20 deletions

View file

@ -36,6 +36,7 @@ namespace Bit.Droid.Services
private readonly IStorageService _storageService;
private readonly IMessagingService _messagingService;
private readonly IBroadcasterService _broadcasterService;
private readonly IEventService _eventService;
private ProgressDialog _progressDialog;
private bool _cameraPermissionsDenied;
private Toast _toast;
@ -43,11 +44,13 @@ namespace Bit.Droid.Services
public DeviceActionService(
IStorageService storageService,
IMessagingService messagingService,
IBroadcasterService broadcasterService)
IBroadcasterService broadcasterService,
IEventService eventService)
{
_storageService = storageService;
_messagingService = messagingService;
_broadcasterService = broadcasterService;
_eventService = eventService;
_broadcasterService.Subscribe(nameof(DeviceActionService), (message) =>
{
@ -463,6 +466,7 @@ namespace Bit.Droid.Services
replyIntent.PutExtra(AutofillManager.ExtraAuthenticationResult, dataset);
activity.SetResult(Result.Ok, replyIntent);
activity.Finish();
var eventTask = _eventService.CollectAsync(EventType.Cipher_ClientAutofilled, cipher.Id);
}
else
{
@ -488,6 +492,7 @@ namespace Bit.Droid.Services
}
activity.Finish();
_messagingService.Send("finishMainActivity");
var eventTask = _eventService.CollectAsync(EventType.Cipher_ClientAutofilled, cipher.Id);
}
}

View file

@ -102,7 +102,8 @@ namespace Bit.iOS.Autofill
CheckLock(() => PerformSegue("setupSegue", this));
}
public void CompleteRequest(string username = null, string password = null, string totp = null)
public void CompleteRequest(string id = null, string username = null,
string password = null, string totp = null)
{
ServiceContainer.Reset();
@ -125,6 +126,8 @@ namespace Bit.iOS.Autofill
UIPasteboard.General.String = totp;
}
var eventService = ServiceContainer.Resolve<IEventService>("eventService");
var task = eventService.CollectAsync(Bit.Core.Enums.EventType.Cipher_ClientAutofilled, id);
var cred = new ASPasswordCredential(username, password);
NSRunLoop.Main.BeginInvokeOnMainThread(() => ExtensionContext?.CompleteRequest(cred, null));
}
@ -207,7 +210,7 @@ namespace Bit.iOS.Autofill
}
}
CompleteRequest(decCipher.Login.Username, decCipher.Login.Password, totpCode);
CompleteRequest(decCipher.Id, decCipher.Login.Username, decCipher.Login.Password, totpCode);
}
private void CheckLock(Action notLockedAction)

View file

@ -17,7 +17,7 @@ namespace Bit.iOS.Autofill
public override UIBarButtonItem BaseCancelButton => CancelBarButton;
public override UIBarButtonItem BaseSaveButton => SaveBarButton;
public override Action Success => () =>
public override Action<string> Success => id =>
{
LoginListController?.DismissModal();
LoginSearchController?.DismissModal();

View file

@ -27,7 +27,7 @@ namespace Bit.iOS.Autofill.Utilities
var item = tableSource.Items.ElementAt(indexPath.Row);
if(item == null)
{
cpViewController.CompleteRequest(null);
cpViewController.CompleteRequest();
return;
}
@ -47,7 +47,7 @@ namespace Bit.iOS.Autofill.Utilities
totp = await totpService.GetCodeAsync(item.Totp);
}
}
cpViewController.CompleteRequest(item.Username, item.Password, totp);
cpViewController.CompleteRequest(item.Id, item.Username, item.Password, totp);
}
else if(!string.IsNullOrWhiteSpace(item.Username) || !string.IsNullOrWhiteSpace(item.Password) ||
!string.IsNullOrWhiteSpace(item.Totp))

View file

@ -42,7 +42,7 @@ namespace Bit.iOS.Core.Controllers
public abstract UINavigationItem BaseNavItem { get; }
public abstract UIBarButtonItem BaseCancelButton { get; }
public abstract UIBarButtonItem BaseSaveButton { get; }
public abstract Action Success { get; }
public abstract Action<string> Success { get; }
public override void ViewDidLoad()
{
@ -187,7 +187,7 @@ namespace Bit.iOS.Core.Controllers
{
await ASHelpers.ReplaceAllIdentities();
}
Success();
Success(cipherDomain.Id);
}
catch(ApiException e)
{

View file

@ -62,7 +62,7 @@ namespace Bit.iOS.Extension
{
var alert = Dialogs.CreateAlert(null, AppResources.MustLogInMainApp, AppResources.Ok, (a) =>
{
CompleteRequest(null);
CompleteRequest(null, null);
});
PresentViewController(alert, true, null);
return;
@ -131,7 +131,7 @@ namespace Bit.iOS.Extension
}
}
public void CompleteUsernamePasswordRequest(string username, string password,
public void CompleteUsernamePasswordRequest(string id, string username, string password,
List<Tuple<string, string>> fields, string totp)
{
NSDictionary itemData = null;
@ -172,10 +172,10 @@ namespace Bit.iOS.Extension
{
UIPasteboard.General.String = totp;
}
CompleteRequest(itemData);
CompleteRequest(id, itemData);
}
public void CompleteRequest(NSDictionary itemData)
public void CompleteRequest(string id, NSDictionary itemData)
{
ServiceContainer.Reset();
@ -183,6 +183,11 @@ namespace Bit.iOS.Extension
var resultsProvider = new NSItemProvider(itemData, UTType.PropertyList);
var resultsItem = new NSExtensionItem { Attachments = new NSItemProvider[] { resultsProvider } };
var returningItems = new NSExtensionItem[] { resultsItem };
if(!string.IsNullOrWhiteSpace(id) && itemData != null)
{
var eventService = ServiceContainer.Resolve<IEventService>("eventService");
var task = eventService.CollectAsync(Bit.Core.Enums.EventType.Cipher_ClientAutofilled, id);
}
NSRunLoop.Main.BeginInvokeOnMainThread(() => ExtensionContext?.CompleteRequest(returningItems, null));
}

View file

@ -15,7 +15,7 @@ namespace Bit.iOS.Extension
public override UIBarButtonItem BaseCancelButton => CancelButton;
public override UIBarButtonItem BaseSubmitButton => SubmitButton;
public override Action Success => () => LoadingController.DismissLockAndContinue();
public override Action Cancel => () => LoadingController.CompleteRequest(null);
public override Action Cancel => () => LoadingController.CompleteRequest(null, null);
public override void ViewDidLoad()
{

View file

@ -25,7 +25,7 @@ namespace Bit.iOS.Extension
CancelBarButton.TintColor = ThemeHelpers.NavBarTextColor;
}
public override Action Success => () =>
public override Action<string> Success => id =>
{
if(LoginListController != null)
{
@ -33,7 +33,7 @@ namespace Bit.iOS.Extension
}
else if(LoadingController != null)
{
LoadingController.CompleteUsernamePasswordRequest(UsernameCell.TextField.Text,
LoadingController.CompleteUsernamePasswordRequest(id, UsernameCell.TextField.Text,
PasswordCell.TextField.Text, null, null);
}
};
@ -46,7 +46,7 @@ namespace Bit.iOS.Extension
}
else
{
LoadingController.CompleteRequest(null);
LoadingController.CompleteRequest(null, null);
}
}

View file

@ -57,7 +57,7 @@ namespace Bit.iOS.Extension
partial void CancelBarButton_Activated(UIBarButtonItem sender)
{
LoadingController.CompleteRequest(null);
LoadingController.CompleteRequest(null, null);
}
partial void AddBarButton_Activated(UIBarButtonItem sender)
@ -110,7 +110,7 @@ namespace Bit.iOS.Extension
var item = Items.ElementAt(indexPath.Row);
if(item == null)
{
_controller.LoadingController.CompleteRequest(null);
_controller.LoadingController.CompleteRequest(null, null);
return;
}
@ -125,7 +125,7 @@ namespace Bit.iOS.Extension
totp = GetTotpAsync(item).GetAwaiter().GetResult();
}
_controller.LoadingController.CompleteUsernamePasswordRequest(
item.Username, item.Password, item.Fields, totp);
item.Id, item.Username, item.Password, item.Fields, totp);
}
else if(!string.IsNullOrWhiteSpace(item.Username) || !string.IsNullOrWhiteSpace(item.Password) ||
!string.IsNullOrWhiteSpace(item.Totp))

View file

@ -36,7 +36,7 @@ namespace Bit.iOS.Extension
partial void BackButton_Activated(UIBarButtonItem sender)
{
LoadingController.CompleteRequest(null);
LoadingController.CompleteRequest(null, null);
}
}
}