public bool ScanAndAutofill(AccessibilityNodeInfo root, AccessibilityEvent e) { var filled = false; var passwordNodes = AccessibilityHelpers.GetWindowNodes(root, e, n => n.Password, false); if (passwordNodes.Count > 0) { var uri = AccessibilityHelpers.GetUri(root); if (uri != null && !uri.Contains(BitwardenWebsite)) { if (AccessibilityHelpers.NeedToAutofill(AccessibilityHelpers.LastCredentials, uri)) { AccessibilityHelpers.GetNodesAndFill(root, e, passwordNodes); filled = true; _lastAutoFillTime = Java.Lang.JavaSystem.CurrentTimeMillis(); } } AccessibilityHelpers.LastCredentials = null; } else if (AccessibilityHelpers.LastCredentials != null) { Task.Run(async() => { await Task.Delay(1000); AccessibilityHelpers.LastCredentials = null; }); } passwordNodes.Dispose(); return(filled); }
public bool ScanAndAutofill(AccessibilityNodeInfo root, AccessibilityEvent e) { var filled = false; var uri = AccessibilityHelpers.GetUri(root); if (uri != null && !uri.Contains(BitwardenWebsite) && AccessibilityHelpers.NeedToAutofill(AccessibilityHelpers.LastCredentials, uri)) { var allEditTexts = AccessibilityHelpers.GetWindowNodes(root, e, n => AccessibilityHelpers.EditText(n), false); var usernameEditText = AccessibilityHelpers.GetUsernameEditText(uri, allEditTexts); var passwordNodes = AccessibilityHelpers.GetWindowNodes(root, e, n => n.Password, false); if (usernameEditText != null || passwordNodes.Count > 0) { AccessibilityHelpers.FillCredentials(usernameEditText, passwordNodes); filled = true; _lastAutoFillTime = Java.Lang.JavaSystem.CurrentTimeMillis(); AccessibilityHelpers.LastCredentials = null; } allEditTexts.Dispose(); passwordNodes.Dispose(); } if (AccessibilityHelpers.LastCredentials != null) { Task.Run(async() => { await Task.Delay(1000); AccessibilityHelpers.LastCredentials = null; }); } return(filled); }
public bool ScanAndAutofill(AccessibilityNodeInfo root, AccessibilityEvent e, NotificationManager notificationManager, bool cancelNotification) { var passwordNodes = AccessibilityHelpers.GetWindowNodes(root, e, n => n.Password, false); if (passwordNodes.Count > 0) { var uri = AccessibilityHelpers.GetUri(root); if (uri != null && !uri.Contains(BitwardenWebsite)) { if (AccessibilityHelpers.NeedToAutofill(AccessibilityHelpers.LastCredentials, uri)) { AccessibilityHelpers.GetNodesAndFill(root, e, passwordNodes); } else { NotifyToAutofill(uri, notificationManager); cancelNotification = false; } } AccessibilityHelpers.LastCredentials = null; } else if (AccessibilityHelpers.LastCredentials != null) { Task.Run(async() => { await Task.Delay(1000); AccessibilityHelpers.LastCredentials = null; }); } passwordNodes.Dispose(); return(cancelNotification); }
public override void OnAccessibilityEvent(AccessibilityEvent e) { try { var powerManager = GetSystemService(PowerService) as PowerManager; if (Build.VERSION.SdkInt > BuildVersionCodes.KitkatWatch && !powerManager.IsInteractive) { return; } else if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop && !powerManager.IsScreenOn) { return; } if (SkipPackage(e?.PackageName)) { return; } var root = RootInActiveWindow; if (root == null || root.PackageName != e.PackageName) { return; } // AccessibilityHelpers.PrintTestData(root, e); LoadServices(); var settingsTask = LoadSettingsAsync(); var notificationManager = GetSystemService(NotificationService) as NotificationManager; var cancelNotification = true; switch (e.EventType) { case EventTypes.ViewFocused: if (e.Source == null || !e.Source.Password || !_settingAutofillPasswordField) { break; } if (e.PackageName == BitwardenPackage) { CancelNotification(notificationManager); break; } if (ScanAndAutofill(root, e, notificationManager, cancelNotification)) { CancelNotification(notificationManager); } break; case EventTypes.WindowContentChanged: case EventTypes.WindowStateChanged: if (_settingAutofillPasswordField && e.Source.Password) { break; } else if (_settingAutofillPasswordField && AccessibilityHelpers.LastCredentials == null) { if (string.IsNullOrWhiteSpace(_lastNotificationUri)) { CancelNotification(notificationManager); break; } var uri = AccessibilityHelpers.GetUri(root); if (uri != _lastNotificationUri) { CancelNotification(notificationManager); } else if (uri.StartsWith(Constants.AndroidAppProtocol)) { CancelNotification(notificationManager, 30000); } break; } if (e.PackageName == BitwardenPackage) { CancelNotification(notificationManager); break; } if (_settingAutofillPersistNotification) { var uri = AccessibilityHelpers.GetUri(root); if (uri != null && !uri.Contains(BitwardenWebsite)) { var needToFill = AccessibilityHelpers.NeedToAutofill( AccessibilityHelpers.LastCredentials, uri); if (needToFill) { var passwordNodes = AccessibilityHelpers.GetWindowNodes(root, e, n => n.Password, false); needToFill = passwordNodes.Any(); if (needToFill) { AccessibilityHelpers.GetNodesAndFill(root, e, passwordNodes); } passwordNodes.Dispose(); } if (!needToFill) { NotifyToAutofill(uri, notificationManager); cancelNotification = false; } } AccessibilityHelpers.LastCredentials = null; } else { cancelNotification = ScanAndAutofill(root, e, notificationManager, cancelNotification); } if (cancelNotification) { CancelNotification(notificationManager); } break; default: break; } notificationManager?.Dispose(); root.Dispose(); e.Dispose(); } // Suppress exceptions so that service doesn't crash. catch { } }