private void AdjustOverlayForScroll() { if (_overlayView == null || _anchorNode == null || AccessibilityHelpers.IsAutofillServicePromptVisible(Windows)) { CancelOverlayPrompt(); return; } var root = RootInActiveWindow; IEnumerable <AccessibilityWindowInfo> windows = null; if (Build.VERSION.SdkInt > BuildVersionCodes.Kitkat) { windows = Windows; } var anchorPosition = AccessibilityHelpers.GetOverlayAnchorPosition(this, _anchorNode, root, windows, _overlayViewHeight, _isOverlayAboveAnchor); if (anchorPosition == null) { CancelOverlayPrompt(); return; } else if (anchorPosition.X == -1 && anchorPosition.Y == -1) { if (_overlayView.Visibility != ViewStates.Gone) { _overlayView.Visibility = ViewStates.Gone; System.Diagnostics.Debug.WriteLine(">>> Accessibility Overlay View Hidden"); } return; } else if (anchorPosition.X == -1) { _isOverlayAboveAnchor = false; System.Diagnostics.Debug.WriteLine(">>> Accessibility Overlay View Below Anchor"); return; } else if (anchorPosition.Y == -1) { _isOverlayAboveAnchor = true; System.Diagnostics.Debug.WriteLine(">>> Accessibility Overlay View Above Anchor"); return; } else if (anchorPosition.X == _lastAnchorX && anchorPosition.Y == _lastAnchorY) { if (_overlayView.Visibility != ViewStates.Visible) { _overlayView.Visibility = ViewStates.Visible; } return; } var layoutParams = AccessibilityHelpers.GetOverlayLayoutParams(); layoutParams.X = anchorPosition.X; layoutParams.Y = anchorPosition.Y; _lastAnchorX = anchorPosition.X; _lastAnchorY = anchorPosition.Y; _windowManager.UpdateViewLayout(_overlayView, layoutParams); if (_overlayView.Visibility != ViewStates.Visible) { _overlayView.Visibility = ViewStates.Visible; } System.Diagnostics.Debug.WriteLine(">>> Accessibility Overlay View Updated to X:{0} Y:{1}", layoutParams.X, layoutParams.Y); }
private void OverlayPromptToAutofill(AccessibilityNodeInfo root, AccessibilityEvent e) { if (Java.Lang.JavaSystem.CurrentTimeMillis() - _lastAutoFillTime < 1000 || AccessibilityHelpers.IsAutofillServicePromptVisible(Windows)) { return; } if (!AccessibilityHelpers.OverlayPermitted()) { if (!AccessibilityHelpers.IsAutofillTileAdded) { // The user has the option of only using the autofill tile and leaving the overlay permission // disabled, so only show this toast if they're using accessibility without overlay permission and // have _not_ added the autofill tile System.Diagnostics.Debug.WriteLine(">>> Overlay Permission not granted"); Toast.MakeText(this, AppResources.AccessibilityOverlayPermissionAlert, ToastLength.Long).Show(); } return; } if (_overlayView != null || _anchorNode != null || _overlayAnchorObserverRunning) { CancelOverlayPrompt(); } var uri = AccessibilityHelpers.GetUri(root); var fillable = !string.IsNullOrWhiteSpace(uri); if (fillable) { if (_blacklistedUris != null && _blacklistedUris.Any()) { if (Uri.TryCreate(uri, UriKind.Absolute, out var parsedUri) && parsedUri.Scheme.StartsWith("http")) { fillable = !_blacklistedUris.Contains( string.Format("{0}://{1}", parsedUri.Scheme, parsedUri.Host)); } else { fillable = !_blacklistedUris.Contains(uri); } } } if (!fillable) { return; } var intent = new Intent(this, typeof(AccessibilityActivity)); intent.PutExtra("uri", uri); intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.SingleTop | ActivityFlags.ClearTop); _overlayView = AccessibilityHelpers.GetOverlayView(this); _overlayView.Measure(View.MeasureSpec.MakeMeasureSpec(0, 0), View.MeasureSpec.MakeMeasureSpec(0, 0)); _overlayViewHeight = _overlayView.MeasuredHeight; _overlayView.Click += (sender, eventArgs) => { CancelOverlayPrompt(); StartActivity(intent); }; var layoutParams = AccessibilityHelpers.GetOverlayLayoutParams(); var anchorPosition = AccessibilityHelpers.GetOverlayAnchorPosition(this, e.Source, _overlayViewHeight, _isOverlayAboveAnchor); layoutParams.X = anchorPosition.X; layoutParams.Y = anchorPosition.Y; if (_windowManager == null) { _windowManager = GetSystemService(WindowService).JavaCast <IWindowManager>(); } _anchorNode = e.Source; _lastAnchorX = anchorPosition.X; _lastAnchorY = anchorPosition.Y; _windowManager.AddView(_overlayView, layoutParams); System.Diagnostics.Debug.WriteLine(">>> Accessibility Overlay View Added at X:{0} Y:{1}", layoutParams.X, layoutParams.Y); StartOverlayAnchorObserver(); }