Made node recycling approach a bit more surgical to appease older versions of Android, and adjusted anchor position offset for older versions of Android (#711)

This commit is contained in:
Matt Portune 2020-01-29 07:23:49 -05:00 committed by GitHub
parent 34e32403b0
commit 9a66b9003f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 21 deletions

View File

@ -253,6 +253,7 @@ namespace Bit.Droid.Accessibility
if(dispose)
{
n?.Recycle();
n?.Dispose();
}
return nodes;
}
@ -291,7 +292,6 @@ namespace Bit.Droid.Accessibility
if(usernameEditText != null)
{
isUsernameEditText = IsSameNode(usernameEditText, e.Source);
usernameEditText.Recycle();
}
allEditTexts.Dispose();
@ -370,7 +370,12 @@ namespace Bit.Droid.Accessibility
var anchorViewRectTop = anchorViewRect.Top;
anchorViewRect.Dispose();
var calculatedTop = rootRectHeight - anchorViewRectTop - GetNavigationBarHeight();
int calculatedTop = rootRectHeight - anchorViewRectTop;
if((int)Build.VERSION.SdkInt >= 24)
{
calculatedTop -= GetNavigationBarHeight();
}
return new Point(anchorViewRectLeft, calculatedTop);
}
@ -385,6 +390,10 @@ namespace Bit.Droid.Accessibility
{
return new Point(-1, -1);
}
if(!anchorNode.Focused)
{
return null;
}
// node.VisibleToUser doesn't always give us exactly what we want, so attempt to tighten up the range
// of visibility

View File

@ -75,32 +75,27 @@ namespace Bit.Droid.Accessibility
if(e.Source == null || e.PackageName == BitwardenPackage)
{
CancelOverlayPrompt();
e.Recycle();
break;
}
root = RootInActiveWindow;
if(root == null || root.PackageName != e.PackageName)
{
e.Recycle();
break;
}
var isKnownBroswer = AccessibilityHelpers.SupportedBrowsers.ContainsKey(root.PackageName);
if(e.EventType == EventTypes.ViewClicked && isKnownBroswer)
{
e.Recycle();
break;
}
if(!(e.Source?.Password ?? false) && !AccessibilityHelpers.IsUsernameEditText(root, e))
{
CancelOverlayPrompt();
e.Recycle();
break;
}
if(ScanAndAutofill(root, e))
{
CancelOverlayPrompt();
e.Recycle();
}
else
{
@ -111,36 +106,27 @@ namespace Bit.Droid.Accessibility
case EventTypes.WindowStateChanged:
if(AccessibilityHelpers.LastCredentials == null)
{
e.Recycle();
break;
}
if(e.PackageName == BitwardenPackage)
{
CancelOverlayPrompt();
e.Recycle();
break;
}
root = RootInActiveWindow;
if(root == null || root.PackageName != e.PackageName)
{
e.Recycle();
break;
}
if(ScanAndAutofill(root, e))
{
CancelOverlayPrompt();
}
e.Recycle();
break;
default:
break;
}
if(root != null)
{
root.Recycle();
}
}
// Suppress exceptions so that service doesn't crash.
catch(Exception ex)
@ -211,7 +197,6 @@ namespace Bit.Droid.Accessibility
{
System.Diagnostics.Debug.WriteLine(">>> Overlay Permission not granted");
Toast.MakeText(this, AppResources.AccessibilityOverlayPermissionAlert, ToastLength.Long).Show();
e.Recycle();
return;
}
@ -222,14 +207,12 @@ namespace Bit.Droid.Accessibility
if(Java.Lang.JavaSystem.CurrentTimeMillis() - _lastAutoFillTime < 1000)
{
e.Recycle();
return;
}
var uri = AccessibilityHelpers.GetUri(root);
if(string.IsNullOrWhiteSpace(uri))
{
e.Recycle();
return;
}
@ -301,7 +284,6 @@ namespace Bit.Droid.Accessibility
windows = Windows;
}
var anchorPosition = AccessibilityHelpers.GetOverlayAnchorPosition(_anchorNode, root, windows);
root.Recycle();
if(anchorPosition == null)
{

View File

@ -10,8 +10,9 @@ namespace Bit.Droid.Accessibility
{
foreach(var item in this)
{
item.Recycle();
item.Dispose();
}
}
}
}
}