mirror of
https://github.com/bitwarden/android.git
synced 2025-01-12 19:27:37 +03:00
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:
parent
34e32403b0
commit
9a66b9003f
3 changed files with 13 additions and 21 deletions
|
@ -253,6 +253,7 @@ namespace Bit.Droid.Accessibility
|
||||||
if(dispose)
|
if(dispose)
|
||||||
{
|
{
|
||||||
n?.Recycle();
|
n?.Recycle();
|
||||||
|
n?.Dispose();
|
||||||
}
|
}
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
@ -291,7 +292,6 @@ namespace Bit.Droid.Accessibility
|
||||||
if(usernameEditText != null)
|
if(usernameEditText != null)
|
||||||
{
|
{
|
||||||
isUsernameEditText = IsSameNode(usernameEditText, e.Source);
|
isUsernameEditText = IsSameNode(usernameEditText, e.Source);
|
||||||
usernameEditText.Recycle();
|
|
||||||
}
|
}
|
||||||
allEditTexts.Dispose();
|
allEditTexts.Dispose();
|
||||||
|
|
||||||
|
@ -370,7 +370,12 @@ namespace Bit.Droid.Accessibility
|
||||||
var anchorViewRectTop = anchorViewRect.Top;
|
var anchorViewRectTop = anchorViewRect.Top;
|
||||||
anchorViewRect.Dispose();
|
anchorViewRect.Dispose();
|
||||||
|
|
||||||
var calculatedTop = rootRectHeight - anchorViewRectTop - GetNavigationBarHeight();
|
int calculatedTop = rootRectHeight - anchorViewRectTop;
|
||||||
|
if((int)Build.VERSION.SdkInt >= 24)
|
||||||
|
{
|
||||||
|
calculatedTop -= GetNavigationBarHeight();
|
||||||
|
}
|
||||||
|
|
||||||
return new Point(anchorViewRectLeft, calculatedTop);
|
return new Point(anchorViewRectLeft, calculatedTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,6 +390,10 @@ namespace Bit.Droid.Accessibility
|
||||||
{
|
{
|
||||||
return new Point(-1, -1);
|
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
|
// node.VisibleToUser doesn't always give us exactly what we want, so attempt to tighten up the range
|
||||||
// of visibility
|
// of visibility
|
||||||
|
|
|
@ -75,32 +75,27 @@ namespace Bit.Droid.Accessibility
|
||||||
if(e.Source == null || e.PackageName == BitwardenPackage)
|
if(e.Source == null || e.PackageName == BitwardenPackage)
|
||||||
{
|
{
|
||||||
CancelOverlayPrompt();
|
CancelOverlayPrompt();
|
||||||
e.Recycle();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
root = RootInActiveWindow;
|
root = RootInActiveWindow;
|
||||||
if(root == null || root.PackageName != e.PackageName)
|
if(root == null || root.PackageName != e.PackageName)
|
||||||
{
|
{
|
||||||
e.Recycle();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var isKnownBroswer = AccessibilityHelpers.SupportedBrowsers.ContainsKey(root.PackageName);
|
var isKnownBroswer = AccessibilityHelpers.SupportedBrowsers.ContainsKey(root.PackageName);
|
||||||
if(e.EventType == EventTypes.ViewClicked && isKnownBroswer)
|
if(e.EventType == EventTypes.ViewClicked && isKnownBroswer)
|
||||||
{
|
{
|
||||||
e.Recycle();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(!(e.Source?.Password ?? false) && !AccessibilityHelpers.IsUsernameEditText(root, e))
|
if(!(e.Source?.Password ?? false) && !AccessibilityHelpers.IsUsernameEditText(root, e))
|
||||||
{
|
{
|
||||||
CancelOverlayPrompt();
|
CancelOverlayPrompt();
|
||||||
e.Recycle();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(ScanAndAutofill(root, e))
|
if(ScanAndAutofill(root, e))
|
||||||
{
|
{
|
||||||
CancelOverlayPrompt();
|
CancelOverlayPrompt();
|
||||||
e.Recycle();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -111,36 +106,27 @@ namespace Bit.Droid.Accessibility
|
||||||
case EventTypes.WindowStateChanged:
|
case EventTypes.WindowStateChanged:
|
||||||
if(AccessibilityHelpers.LastCredentials == null)
|
if(AccessibilityHelpers.LastCredentials == null)
|
||||||
{
|
{
|
||||||
e.Recycle();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(e.PackageName == BitwardenPackage)
|
if(e.PackageName == BitwardenPackage)
|
||||||
{
|
{
|
||||||
CancelOverlayPrompt();
|
CancelOverlayPrompt();
|
||||||
e.Recycle();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
root = RootInActiveWindow;
|
root = RootInActiveWindow;
|
||||||
if(root == null || root.PackageName != e.PackageName)
|
if(root == null || root.PackageName != e.PackageName)
|
||||||
{
|
{
|
||||||
e.Recycle();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(ScanAndAutofill(root, e))
|
if(ScanAndAutofill(root, e))
|
||||||
{
|
{
|
||||||
CancelOverlayPrompt();
|
CancelOverlayPrompt();
|
||||||
}
|
}
|
||||||
e.Recycle();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(root != null)
|
|
||||||
{
|
|
||||||
root.Recycle();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Suppress exceptions so that service doesn't crash.
|
// Suppress exceptions so that service doesn't crash.
|
||||||
catch(Exception ex)
|
catch(Exception ex)
|
||||||
|
@ -211,7 +197,6 @@ namespace Bit.Droid.Accessibility
|
||||||
{
|
{
|
||||||
System.Diagnostics.Debug.WriteLine(">>> Overlay Permission not granted");
|
System.Diagnostics.Debug.WriteLine(">>> Overlay Permission not granted");
|
||||||
Toast.MakeText(this, AppResources.AccessibilityOverlayPermissionAlert, ToastLength.Long).Show();
|
Toast.MakeText(this, AppResources.AccessibilityOverlayPermissionAlert, ToastLength.Long).Show();
|
||||||
e.Recycle();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,14 +207,12 @@ namespace Bit.Droid.Accessibility
|
||||||
|
|
||||||
if(Java.Lang.JavaSystem.CurrentTimeMillis() - _lastAutoFillTime < 1000)
|
if(Java.Lang.JavaSystem.CurrentTimeMillis() - _lastAutoFillTime < 1000)
|
||||||
{
|
{
|
||||||
e.Recycle();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var uri = AccessibilityHelpers.GetUri(root);
|
var uri = AccessibilityHelpers.GetUri(root);
|
||||||
if(string.IsNullOrWhiteSpace(uri))
|
if(string.IsNullOrWhiteSpace(uri))
|
||||||
{
|
{
|
||||||
e.Recycle();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,7 +284,6 @@ namespace Bit.Droid.Accessibility
|
||||||
windows = Windows;
|
windows = Windows;
|
||||||
}
|
}
|
||||||
var anchorPosition = AccessibilityHelpers.GetOverlayAnchorPosition(_anchorNode, root, windows);
|
var anchorPosition = AccessibilityHelpers.GetOverlayAnchorPosition(_anchorNode, root, windows);
|
||||||
root.Recycle();
|
|
||||||
|
|
||||||
if(anchorPosition == null)
|
if(anchorPosition == null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,6 +10,7 @@ namespace Bit.Droid.Accessibility
|
||||||
{
|
{
|
||||||
foreach(var item in this)
|
foreach(var item in this)
|
||||||
{
|
{
|
||||||
|
item.Recycle();
|
||||||
item.Dispose();
|
item.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue