From f9547f158ea05e9c0eaf3b55e296ad0cb1cf74e7 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 22 Jul 2019 15:50:59 -0400 Subject: [PATCH] log autofill events --- src/Android/Services/DeviceActionService.cs | 7 ++++++- .../CredentialProviderViewController.cs | 7 +++++-- src/iOS.Autofill/LoginAddViewController.cs | 2 +- src/iOS.Autofill/Utilities/AutofillHelpers.cs | 4 ++-- src/iOS.Core/Controllers/LoginAddViewController.cs | 4 ++-- src/iOS.Extension/LoadingViewController.cs | 13 +++++++++---- src/iOS.Extension/LockPasswordViewController.cs | 2 +- src/iOS.Extension/LoginAddViewController.cs | 6 +++--- src/iOS.Extension/LoginListViewController.cs | 6 +++--- src/iOS.Extension/SetupViewController.cs | 2 +- 10 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/Android/Services/DeviceActionService.cs b/src/Android/Services/DeviceActionService.cs index 297932d90..c1735885c 100644 --- a/src/Android/Services/DeviceActionService.cs +++ b/src/Android/Services/DeviceActionService.cs @@ -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); } } diff --git a/src/iOS.Autofill/CredentialProviderViewController.cs b/src/iOS.Autofill/CredentialProviderViewController.cs index 892620bce..0ba8d0cd3 100644 --- a/src/iOS.Autofill/CredentialProviderViewController.cs +++ b/src/iOS.Autofill/CredentialProviderViewController.cs @@ -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("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) diff --git a/src/iOS.Autofill/LoginAddViewController.cs b/src/iOS.Autofill/LoginAddViewController.cs index c697a3f7a..3d0f9e3c5 100644 --- a/src/iOS.Autofill/LoginAddViewController.cs +++ b/src/iOS.Autofill/LoginAddViewController.cs @@ -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 Success => id => { LoginListController?.DismissModal(); LoginSearchController?.DismissModal(); diff --git a/src/iOS.Autofill/Utilities/AutofillHelpers.cs b/src/iOS.Autofill/Utilities/AutofillHelpers.cs index 6671d4e33..79866cd09 100644 --- a/src/iOS.Autofill/Utilities/AutofillHelpers.cs +++ b/src/iOS.Autofill/Utilities/AutofillHelpers.cs @@ -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)) diff --git a/src/iOS.Core/Controllers/LoginAddViewController.cs b/src/iOS.Core/Controllers/LoginAddViewController.cs index 71f20122f..f0be3acf9 100644 --- a/src/iOS.Core/Controllers/LoginAddViewController.cs +++ b/src/iOS.Core/Controllers/LoginAddViewController.cs @@ -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 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) { diff --git a/src/iOS.Extension/LoadingViewController.cs b/src/iOS.Extension/LoadingViewController.cs index fda391415..0f356dbfa 100644 --- a/src/iOS.Extension/LoadingViewController.cs +++ b/src/iOS.Extension/LoadingViewController.cs @@ -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> 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("eventService"); + var task = eventService.CollectAsync(Bit.Core.Enums.EventType.Cipher_ClientAutofilled, id); + } NSRunLoop.Main.BeginInvokeOnMainThread(() => ExtensionContext?.CompleteRequest(returningItems, null)); } diff --git a/src/iOS.Extension/LockPasswordViewController.cs b/src/iOS.Extension/LockPasswordViewController.cs index 459a87247..5f8024453 100644 --- a/src/iOS.Extension/LockPasswordViewController.cs +++ b/src/iOS.Extension/LockPasswordViewController.cs @@ -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() { diff --git a/src/iOS.Extension/LoginAddViewController.cs b/src/iOS.Extension/LoginAddViewController.cs index dea6afe8f..6aa27b35e 100644 --- a/src/iOS.Extension/LoginAddViewController.cs +++ b/src/iOS.Extension/LoginAddViewController.cs @@ -25,7 +25,7 @@ namespace Bit.iOS.Extension CancelBarButton.TintColor = ThemeHelpers.NavBarTextColor; } - public override Action Success => () => + public override Action 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); } } diff --git a/src/iOS.Extension/LoginListViewController.cs b/src/iOS.Extension/LoginListViewController.cs index 99c65609f..6a1306108 100644 --- a/src/iOS.Extension/LoginListViewController.cs +++ b/src/iOS.Extension/LoginListViewController.cs @@ -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)) diff --git a/src/iOS.Extension/SetupViewController.cs b/src/iOS.Extension/SetupViewController.cs index 9eee2c2f9..cc0211d9b 100644 --- a/src/iOS.Extension/SetupViewController.cs +++ b/src/iOS.Extension/SetupViewController.cs @@ -36,7 +36,7 @@ namespace Bit.iOS.Extension partial void BackButton_Activated(UIBarButtonItem sender) { - LoadingController.CompleteRequest(null); + LoadingController.CompleteRequest(null, null); } } }