Ejemplo n.º 1
0
        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))
                {
                    if (e?.PackageName != "com.android.systemui")
                    {
                        CancelOverlayPrompt();
                    }
                    return;
                }

                // AccessibilityHelpers.PrintTestData(RootInActiveWindow, e);

                AccessibilityNodeInfo root = null;

                switch (e.EventType)
                {
                case EventTypes.ViewFocused:
                case EventTypes.ViewClicked:
                    if (e.Source == null || e.PackageName == BitwardenPackage)
                    {
                        CancelOverlayPrompt();
                        break;
                    }

                    root = RootInActiveWindow;
                    if (root == null || root.PackageName != e.PackageName)
                    {
                        break;
                    }

                    if (!(e.Source?.Password ?? false) && !AccessibilityHelpers.IsUsernameEditText(root, e))
                    {
                        CancelOverlayPrompt();
                        break;
                    }
                    if (ScanAndAutofill(root, e))
                    {
                        CancelOverlayPrompt();
                    }
                    else
                    {
                        OverlayPromptToAutofill(root, e);
                    }
                    break;

                case EventTypes.WindowContentChanged:
                case EventTypes.WindowStateChanged:
                    if (AccessibilityHelpers.LastCredentials == null)
                    {
                        break;
                    }
                    if (e.PackageName == BitwardenPackage)
                    {
                        CancelOverlayPrompt();
                        break;
                    }

                    root = RootInActiveWindow;
                    if (root == null || root.PackageName != e.PackageName)
                    {
                        break;
                    }
                    if (ScanAndAutofill(root, e))
                    {
                        CancelOverlayPrompt();
                    }
                    break;

                default:
                    break;
                }
            }
            // Suppress exceptions so that service doesn't crash.
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(">>> {0}: {1}", ex.GetType(), ex.StackTrace);
            }
        }
Ejemplo n.º 2
0
        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))
                {
                    CancelOverlayPrompt();
                    return;
                }

                var root = RootInActiveWindow;
                if (root == null || root.PackageName != e.PackageName)
                {
                    return;
                }

                // AccessibilityHelpers.PrintTestData(root, e);

                switch (e.EventType)
                {
                case EventTypes.ViewFocused:
                case EventTypes.ViewClicked:
                case EventTypes.ViewScrolled:
                    var isKnownBroswer = AccessibilityHelpers.SupportedBrowsers.ContainsKey(root.PackageName);
                    if (e.EventType == EventTypes.ViewClicked && isKnownBroswer)
                    {
                        break;
                    }
                    if (e.Source == null || e.PackageName == BitwardenPackage)
                    {
                        CancelOverlayPrompt();
                        break;
                    }
                    if (e.EventType == EventTypes.ViewScrolled)
                    {
                        AdjustOverlayForScroll(root, e);
                        break;
                    }
                    else
                    {
                        var isUsernameEditText1 = AccessibilityHelpers.IsUsernameEditText(root, e);
                        var isPasswordEditText1 = e.Source?.Password ?? false;
                        if (!isUsernameEditText1 && !isPasswordEditText1)
                        {
                            CancelOverlayPrompt();
                            break;
                        }
                        if (ScanAndAutofill(root, e))
                        {
                            CancelOverlayPrompt();
                        }
                        else
                        {
                            OverlayPromptToAutofill(root, e);
                        }
                    }
                    break;

                case EventTypes.WindowContentChanged:
                case EventTypes.WindowStateChanged:
                    var isUsernameEditText2 = AccessibilityHelpers.IsUsernameEditText(root, e);
                    var isPasswordEditText2 = e.Source?.Password ?? false;
                    if (e.Source == null || isUsernameEditText2 || isPasswordEditText2)
                    {
                        break;
                    }
                    else if (AccessibilityHelpers.LastCredentials == null)
                    {
                        if (string.IsNullOrWhiteSpace(_lastNotificationUri))
                        {
                            CancelOverlayPrompt();
                            break;
                        }
                        var uri = AccessibilityHelpers.GetUri(root);
                        if (uri != null && uri != _lastNotificationUri)
                        {
                            CancelOverlayPrompt();
                        }
                        else if (uri != null && uri.StartsWith(Constants.AndroidAppProtocol))
                        {
                            CancelOverlayPrompt();
                        }
                        break;
                    }

                    if (e.PackageName == BitwardenPackage)
                    {
                        CancelOverlayPrompt();
                        break;
                    }

                    if (ScanAndAutofill(root, e))
                    {
                        CancelOverlayPrompt();
                    }
                    break;

                default:
                    break;
                }

                root.Dispose();
                e.Dispose();
            }
            // Suppress exceptions so that service doesn't crash.
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(">>> Exception: " + ex.StackTrace);
            }
        }