private void AdjustOverlayForScroll(AccessibilityNodeInfo root, AccessibilityEvent e) { if (_overlayView == null || _anchorViewHash <= 0) { return; } var anchorPosition = AccessibilityHelpers.GetOverlayAnchorPosition(_anchorViewHash, root, e); if (anchorPosition == null) { return; } if (anchorPosition.X == _lastAnchorX && anchorPosition.Y == _lastAnchorY) { return; } var layoutParams = AccessibilityHelpers.GetOverlayLayoutParams(); layoutParams.X = anchorPosition.X; layoutParams.Y = anchorPosition.Y; _windowManager.UpdateViewLayout(_overlayView, layoutParams); _lastAnchorX = anchorPosition.X; _lastAnchorY = anchorPosition.Y; 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 (!AccessibilityHelpers.OverlayPermitted()) { System.Diagnostics.Debug.WriteLine(">>> Overlay Permission not granted"); Toast.MakeText(this, AppResources.AccessibilityOverlayPermissionAlert, ToastLength.Long).Show(); return; } if (_overlayView != null || _anchorNode != null || _overlayAnchorObserverRunning) { CancelOverlayPrompt(); } if (Java.Lang.JavaSystem.CurrentTimeMillis() - _lastAutoFillTime < 1000) { return; } var uri = AccessibilityHelpers.GetUri(root); if (string.IsNullOrWhiteSpace(uri)) { return; } var layoutParams = AccessibilityHelpers.GetOverlayLayoutParams(); var anchorPosition = AccessibilityHelpers.GetOverlayAnchorPosition(root, e.Source); layoutParams.X = anchorPosition.X; layoutParams.Y = anchorPosition.Y; if (_windowManager == null) { _windowManager = GetSystemService(WindowService).JavaCast <IWindowManager>(); } var intent = new Intent(this, typeof(AccessibilityActivity)); intent.PutExtra("uri", uri); intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.SingleTop | ActivityFlags.ClearTop); _overlayView = AccessibilityHelpers.GetOverlayView(this); _overlayView.Click += (sender, eventArgs) => { CancelOverlayPrompt(); StartActivity(intent); }; _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(); }
private void AdjustOverlayForScroll() { if (_overlayView == null || _anchorNode == null) { CancelOverlayPrompt(); return; } var root = RootInActiveWindow; IEnumerable <AccessibilityWindowInfo> windows = null; if (Build.VERSION.SdkInt > BuildVersionCodes.Kitkat) { windows = Windows; } var anchorPosition = AccessibilityHelpers.GetOverlayAnchorPosition(_anchorNode, root, windows); if (anchorPosition == null) { CancelOverlayPrompt(); return; } else if (anchorPosition.X == -1 && anchorPosition.Y == -1) { if (_overlayView.Visibility != ViewStates.Gone) { _overlayView.Visibility = ViewStates.Gone; } 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(); }
private void OverlayPromptToAutofill(AccessibilityNodeInfo root, AccessibilityEvent e) { if (!AccessibilityHelpers.OverlayPermitted()) { System.Diagnostics.Debug.WriteLine(">>> Overlay Permission not granted"); Toast.MakeText(this, AppResources.AccessibilityOverlayPermissionAlert, ToastLength.Long).Show(); return; } var uri = AccessibilityHelpers.GetUri(root); if (string.IsNullOrWhiteSpace(uri)) { return; } WindowManagerTypes windowManagerType; if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { windowManagerType = WindowManagerTypes.ApplicationOverlay; } else { windowManagerType = WindowManagerTypes.Phone; } var layoutParams = new WindowManagerLayoutParams( ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent, windowManagerType, WindowManagerFlags.NotFocusable | WindowManagerFlags.NotTouchModal, Format.Transparent); var anchorPosition = AccessibilityHelpers.GetOverlayAnchorPosition(root, e); layoutParams.Gravity = GravityFlags.Bottom | GravityFlags.Left; layoutParams.X = anchorPosition.X; layoutParams.Y = anchorPosition.Y; var intent = new Intent(this, typeof(AccessibilityActivity)); intent.PutExtra("uri", uri); intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.SingleTop | ActivityFlags.ClearTop); if (_windowManager == null) { _windowManager = GetSystemService(WindowService).JavaCast <IWindowManager>(); } var updateView = false; if (_overlayView != null) { updateView = true; } _overlayView = AccessibilityHelpers.GetOverlayView(this); _overlayView.Click += (sender, eventArgs) => { CancelOverlayPrompt(); StartActivity(intent); }; _lastNotificationUri = uri; if (updateView) { _windowManager.UpdateViewLayout(_overlayView, layoutParams); } else { _windowManager.AddView(_overlayView, layoutParams); } System.Diagnostics.Debug.WriteLine(">>> Accessibility Overlay View {0} X:{1} Y:{2}", updateView ? "Updated to" : "Added at", layoutParams.X, layoutParams.Y); }