Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ed9fc159 authored by “Longbo's avatar “Longbo
Browse files

autoclick: Fix autoclick scroll panel exit button not reverting to left-click

Problem: Manual click on scroll panel's "Close" button doesn't revert to
left-click when setting is enabled, while hover wait autoclick on exit
button does.

Cause: Manual close only calls hide(), not exitScrollMode() which
contains the revert logic.

Fix: Route both exit paths through exitScrollMode() in controller

Video: http://shortn/_vlg8H26GTB

Bug: b/421211294
Test: atest
Flag: com.android.server.accessibility.enable_autoclick_indicator
Change-Id: I4f24a200da0e7b97ba552750ad10ef002030486d
parent 8dc2dd5d
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -232,6 +232,11 @@ public class AutoclickController extends BaseEventStreamTransformation {
                        stopContinuousScroll();
                    }
                }

                @Override
                public void onExitScrollMode() {
                    exitScrollMode();
                }
            };

    public AutoclickController(Context context, int userId, AccessibilityTraceManager trace) {
+11 −2
Original line number Diff line number Diff line
@@ -95,6 +95,11 @@ public class AutoclickScrollPanel {
         * @param hovered Whether the button is being hovered or not.
         */
        void onHoverButtonChange(@ScrollDirection int direction, boolean hovered);

        /**
         * Called when the scroll panel should be exited.
         */
        void onExitScrollMode();
    }

    public AutoclickScrollPanel(Context context, WindowManager windowManager,
@@ -136,7 +141,11 @@ public class AutoclickScrollPanel {
        setupHoverListenerForButton(mExitButton, DIRECTION_EXIT);

        // Add click listener for exit button.
        mExitButton.setOnClickListener(v -> hide());
        mExitButton.setOnClickListener(v -> {
            if (mScrollPanelController != null) {
                mScrollPanelController.onExitScrollMode();
            }
        });
    }

    /**
+33 −0
Original line number Diff line number Diff line
@@ -1413,6 +1413,39 @@ public class AutoclickControllerTest {
        assertThat(scrollCaptor.eventCount).isEqualTo(countBeforeRunnable);
    }

    @Test
    @EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR)
    public void exitButton_exitsScrollMode() {
        // Initialize the controller.
        injectFakeMouseActionHoverMoveEvent();

        // Set the active click type to scroll.
        mController.clickPanelController.handleAutoclickTypeChange(
                AutoclickTypePanel.AUTOCLICK_TYPE_SCROLL);

        // Enable revert to left click setting.
        Settings.Secure.putIntForUser(mTestableContext.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_AUTOCLICK_REVERT_TO_LEFT_CLICK,
                AccessibilityUtils.State.ON,
                mTestableContext.getUserId());
        mController.onChangeForTesting(/* selfChange= */ true,
                Settings.Secure.getUriFor(
                        Settings.Secure.ACCESSIBILITY_AUTOCLICK_REVERT_TO_LEFT_CLICK));

        // Show the scroll panel and verify it's visible before pause.
        mController.mAutoclickScrollPanel.show();
        assertThat(mController.mAutoclickScrollPanel.isVisible()).isTrue();

        // Simulate exit button click.
        mController.mScrollPanelController.onExitScrollMode();

        // Verify that the scroll panel is hidden.
        assertThat(mController.mAutoclickScrollPanel.isVisible()).isFalse();

        // Verify that the click type is reset to left click.
        assertThat(mController.getActiveClickTypeForTest())
                .isEqualTo(AutoclickTypePanel.AUTOCLICK_TYPE_LEFT_CLICK);
    }
    /**
     * =========================================================================
     * Helper Functions
+3 −3
Original line number Diff line number Diff line
@@ -337,7 +337,7 @@ public class AutoclickScrollPanelTest {
    }

    @Test
    public void exitButton_click_hidesPanel() {
    public void exitButton_click_callsOnExitScrollMode() {
        float cursorX = 300;
        float cursorY = 300;

@@ -347,8 +347,8 @@ public class AutoclickScrollPanelTest {
        // Simulate clicking the exit button.
        mExitButton.performClick();

        // Verify the panel is hidden.
        assertThat(mScrollPanel.isVisible()).isFalse();
        // Verify that the controller's onExitScrollMode was called.
        verify(mMockScrollPanelController).onExitScrollMode();
    }

    // Helper method to simulate a hover event on a view.