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 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();
        }
예제 #3
0
        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);
        }