protected string GetAllText(AccessibilityNodeInfo node) { if (node == null) { return("{ }"); } StringBuilder log = new StringBuilder("{"); log.Append($"\"id\" : \"{node.ViewIdResourceName}\", \"text\" : \"{node.Text}\", \"children\" : ["); for (int i = 0; i < node.ChildCount - 1; ++i) { string child = GetAllText(node.GetChild(i)); log.Append(child).Append(","); } if (node.ChildCount != 0) { string child = GetAllText(node.GetChild(node.ChildCount - 1)); log.Append(child); } return(log.Append("] }").ToString()); }
private NodeList GetWindowNodes(AccessibilityNodeInfo n, AccessibilityEvent e, Func <AccessibilityNodeInfo, bool> condition, bool disposeIfUnused, NodeList nodes = null) { if (nodes == null) { nodes = new NodeList(); } if (n != null) { var dispose = disposeIfUnused; if (n.WindowId == e.WindowId && !(n.ViewIdResourceName?.StartsWith(SystemUiPackage) ?? false) && condition(n)) { dispose = false; nodes.Add(n); } for (var i = 0; i < n.ChildCount; i++) { GetWindowNodes(n.GetChild(i), e, condition, true, nodes); } if (dispose) { n.Dispose(); } } return(nodes); }
protected bool Back(AccessibilityNodeInfo root) { AccessibilityNodeInfo toolbar = root.FindAccessibilityNodeInfosByViewId(TOOLBAR_ID).FirstOrDefault(); if (toolbar == null || toolbar.ChildCount < TOOLBAR_CHILDREN_MIN_COUNT) { return(false); } AccessibilityNodeInfo backButton = toolbar.GetChild(TOOLBAR_BACK_BUTTON_NUM); return(Click(backButton)); }
public static NodeList GetWindowNodes(AccessibilityNodeInfo n, AccessibilityEvent e, Func <AccessibilityNodeInfo, bool> condition, bool disposeIfUnused, NodeList nodes = null, int recursionDepth = 0) { if (nodes == null) { nodes = new NodeList(); } var dispose = disposeIfUnused; if (n != null && recursionDepth < 100) { var add = n.WindowId == e.WindowId && !(n.ViewIdResourceName?.StartsWith(SystemUiPackage) ?? false) && condition(n); if (add) { dispose = false; nodes.Add(n); } for (var i = 0; i < n.ChildCount; i++) { var childNode = n.GetChild(i); if (childNode == null) { continue; } else if (i > 100) { Android.Util.Log.Info(BitwardenTag, "Too many child iterations."); break; } else if (childNode.GetHashCode() == n.GetHashCode()) { Android.Util.Log.Info(BitwardenTag, "Child node is the same as parent for some reason."); } else { GetWindowNodes(childNode, e, condition, true, nodes, recursionDepth++); } } } if (dispose) { n?.Recycle(); n?.Dispose(); } return(nodes); }
private IEnumerable <AccessibilityNodeInfo> GetNodeOrChildren(AccessibilityNodeInfo n, Func <AccessibilityNodeInfo, bool> p) { if (n != null) { if (p(n)) { yield return(n); } for (int i = 0; i < n.ChildCount; i++) { foreach (var x in GetNodeOrChildren(n.GetChild(i), p)) { yield return(x); } } } }
private IEnumerable <AccessibilityNodeInfo> GetWindowNodes(AccessibilityNodeInfo n, AccessibilityEvent e, Func <AccessibilityNodeInfo, bool> p) { if (n != null) { if (n.WindowId == e.WindowId && !(n.ViewIdResourceName?.StartsWith(SystemUiPackage) ?? false) && p(n)) { yield return(n); } for (int i = 0; i < n.ChildCount; i++) { foreach (var node in GetWindowNodes(n.GetChild(i), e, p)) { yield return(node); } } } }
public override async void ProcessEvent(AccessibilityEvent e) { try { DateTime start = DateTime.Now; if (BotService.StateService.StateInfo.Paused) { await Notifier.NotifyMessage("Scanning skipped due to: 'bot paused'"); return; } try { BotService.ConstraintsService.CheckInvariantConstraintsPassed(); } catch (ConstraintNotPassedException ex) { await Notifier.NotifyMessage($"Scanning skipped due to: '{ex.Reason}'"); return; } AccessibilityNodeInfo root = GetRoot(e.Source); AccessibilityNodeInfo list = root.FindAccessibilityNodeInfosByViewId(ORDER_LIST_ID).FirstOrDefault(); if (list == null || list.ChildCount == 0) { await Notifier.NotifyMessage("Scanning skipped due to: 'no orders listed'"); return; } for (int i = 0; i < list.ChildCount; ++i) { AccessibilityNodeInfo child = list.GetChild(i); AccessibilityNodeInfo statusView = child.FindAccessibilityNodeInfosByViewId(ORDER_STATUS_ID).FirstOrDefault(); if (statusView != null && statusView.Text != STATUS_AVAILABLE) { continue; } AccessibilityNodeInfo fromView = child.FindAccessibilityNodeInfosByViewId(ORDER_FROM_ID).FirstOrDefault(); AccessibilityNodeInfo toView = child.FindAccessibilityNodeInfosByViewId(ORDER_TO_ID).FirstOrDefault(); AccessibilityNodeInfo gainView = child.FindAccessibilityNodeInfosByViewId(ORDER_GAIN_ID).FirstOrDefault(); if (fromView == null || toView == null || gainView == null) { continue; } Order order = new Order( BotService.StateService.StateInfo.IdCounter + i, fromView.Text, toView.Text, (int)Convert.ToDouble(gainView.Text) ); AccessibilityNodeInfo deliveryTypeView = child.FindAccessibilityNodeInfosByViewId(ORDER_DELIVERY_TYPE_ID).FirstOrDefault(); if (deliveryTypeView != null && !string.IsNullOrEmpty(deliveryTypeView.Text)) { order.Modifiers.Add(deliveryTypeView.Text); } AccessibilityNodeInfo typeView = child.FindAccessibilityNodeInfosByViewId(ORDER_TYPE_ID).FirstOrDefault(); if (typeView != null && !string.IsNullOrEmpty(typeView.Text)) { order.Modifiers.Add(typeView.Text); } AccessibilityNodeInfo fromTimeNode = child.FindAccessibilityNodeInfosByViewId(ORDER_TAKE_TIME_ID).FirstOrDefault(); if (fromTimeNode != null && !string.IsNullOrEmpty(fromTimeNode.Text)) { (DateTime min, DateTime max)? takeTime = GetPeriodFromText(fromTimeNode.Text, TAKE_TIME_REGEX); if (takeTime.HasValue) { order.MinTakeTime = takeTime.Value.min; order.MaxTakeTime = takeTime.Value.max; } } AccessibilityNodeInfo toTimeNode = child.FindAccessibilityNodeInfosByViewId(ORDER_DELIVER_TIME_ID).FirstOrDefault(); if (toTimeNode != null && !string.IsNullOrEmpty(toTimeNode.Text)) { (DateTime min, DateTime max)? deliverTime = GetPeriodFromText(toTimeNode.Text, DELIVER_TIME_REGEX); if (deliverTime.HasValue) { order.MinDeliverTime = deliverTime.Value.min; order.MaxDeliverTime = deliverTime.Value.max; } } if (BotService.BadOrdersService.OrdersBlackList.Contains(order)) { continue; } if (!BotService.FilterService.Assert(order)) { continue; } try { BotService.ConstraintsService.PreOpenCheckOrderPassesConstraints(order); } catch (ConstraintNotPassedException ex) { continue; } ScreenReader.EventProcessor = DependencyHolder.Dependencies.Resolve <OrderPageEventProcessor>(); ++BotService.StateService.StateInfo.IdCounter; BotService.StateService.StateInfo.DiscoveredOrder = order; BotService.StateService.Save(); Click(child); break; } TimeSpan duration = DateTime.Now - start; await Notifier.NotifyMessage($"Scanning took {duration.TotalMilliseconds} ms ({list.ChildCount} orders)"); //ScreenReader.GesturesToPerform.Enqueue(UpdateGestureService.Gesture); } catch (Exception ex) { await NotifyException(ex); } }