From 89f32beec5b38840bcba2da16ad68f05163a07d5 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 3 Feb 2018 09:21:27 -0500 Subject: [PATCH] throttle accessibility events --- src/Android/AutofillService.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Android/AutofillService.cs b/src/Android/AutofillService.cs index 8205ce811..369b88060 100644 --- a/src/Android/AutofillService.cs +++ b/src/Android/AutofillService.cs @@ -90,6 +90,9 @@ namespace Bit.Android private HashSet _launcherPackageNames = null; private DateTime? _lastLauncherSetBuilt = null; private TimeSpan _rebuildLauncherSpan = TimeSpan.FromHours(1); + private DateTime? _lastFocusEvent = null; + private DateTime? _lastWindowEvent = null; + private TimeSpan _eventSpan = TimeSpan.FromMilliseconds(500); public AutofillService() { @@ -114,6 +117,8 @@ namespace Bit.Android { return; } + + //global::Android.Util.Log.Info("bw_access", e.PackageName + " fired event " + e.EventType); var root = RootInActiveWindow; if(root == null || root.PackageName != e.PackageName) @@ -136,6 +141,12 @@ namespace Bit.Android break; } + if(_lastFocusEvent != null && (DateTime.Now - _lastFocusEvent.Value) < _eventSpan) + { + break; + } + _lastFocusEvent = DateTime.Now; + if(e.PackageName == BitwardenPackage) { CancelNotification(notificationManager); @@ -153,7 +164,14 @@ namespace Bit.Android { break; } - else if(_appSettings.AutofillPasswordField && AutofillActivity.LastCredentials == null) + + if(_lastWindowEvent != null && (DateTime.Now - _lastWindowEvent.Value) < _eventSpan) + { + break; + } + _lastWindowEvent = DateTime.Now; + + if(_appSettings.AutofillPasswordField && AutofillActivity.LastCredentials == null) { if(string.IsNullOrWhiteSpace(_lastNotificationUri)) {