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

Commit 775e283e authored by Daniel Norman's avatar Daniel Norman
Browse files

cleanup: clean up rolled out flags

- prevent_a11y_nontool_from_injecting_into_sensitive_views
- motion_event_injector_cancel_fix

Bug: 284180538
Bug: 384451671
Flag: EXEMPT removing prevent_a11y_nontool_from_injecting_into_sensitive_views
Flag: EXEMPT removing motion_event_injector_cancel_fix
Test: presubmit
Change-Id: Ided740a49ac2205f529d1fae03dd4605e95b38d4
parent 108ab7fc
Loading
Loading
Loading
Loading
+7 −9
Original line number Diff line number Diff line
@@ -16860,7 +16860,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            // Window is obscured, drop this touch.
            return false;
        }
        if (android.view.accessibility.Flags.preventA11yNontoolFromInjectingIntoSensitiveViews()) {
        if (event.isInjectedFromAccessibilityService()
                // If the event came from an Accessibility Service that does *not* declare
                // itself as AccessibilityServiceInfo#isAccessibilityTool and this View is
@@ -16869,7 +16868,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                && !event.isInjectedFromAccessibilityTool() && isAccessibilityDataSensitive()) {
            return false;
        }
        }
        return true;
    }
+0 −10
Original line number Diff line number Diff line
@@ -227,16 +227,6 @@ flag {
    bug: "410601652"
}

flag {
    name: "prevent_a11y_nontool_from_injecting_into_sensitive_views"
    namespace: "accessibility"
    description: "Prevents injected gestures from A11yServices without isAccessibilityTool=true from reaching AccessibilityDataSensitive UI elements"
    bug: "284180538"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "prevent_leaking_viewrootimpl"
    namespace: "accessibility"
+0 −10
Original line number Diff line number Diff line
@@ -216,16 +216,6 @@ flag {
    }
}

flag {
    name: "motion_event_injector_cancel_fix"
    namespace: "accessibility"
    description: "Fix the ACTION_CANCEL logic used in MotionEventInjector to avoid InputDispatcher inconsistency"
    bug: "384451671"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "only_reset_magnification_if_needed_when_destroy_handler"
    namespace: "accessibility"
+9 −29
Original line number Diff line number Diff line
@@ -137,19 +137,8 @@ public class MotionEventInjector extends BaseEventStreamTransformation implement
                && mOpenTouchGestureInProgress) {
            return;
        }
        if (Flags.motionEventInjectorCancelFix()) {
        // Pass this real event down the stream unmodified.
        super.onMotionEvent(event, rawEvent, policyFlags);
        } else {
            cancelAnyPendingInjectedEvents();
            if (!android.view.accessibility.Flags
                    .preventA11yNontoolFromInjectingIntoSensitiveViews()) {
                // Indicate that the input event is injected from accessibility, to let applications
                // distinguish it from events injected by other means.
                policyFlags |= WindowManagerPolicyConstants.FLAG_INJECTED_FROM_ACCESSIBILITY;
            }
            sendMotionEventToNext(event, rawEvent, policyFlags);
        }
    }

    @Override
@@ -189,12 +178,10 @@ public class MotionEventInjector extends BaseEventStreamTransformation implement
        MotionEvent motionEvent = (MotionEvent) message.obj;
        int policyFlags = WindowManagerPolicyConstants.FLAG_PASS_TO_USER
                | WindowManagerPolicyConstants.FLAG_INJECTED_FROM_ACCESSIBILITY;
        if (android.view.accessibility.Flags.preventA11yNontoolFromInjectingIntoSensitiveViews()) {
        boolean fromAccessibilityTool = message.arg2 == 1;
        if (fromAccessibilityTool) {
            policyFlags |= WindowManagerPolicyConstants.FLAG_INJECTED_FROM_ACCESSIBILITY_TOOL;
        }
        }
        sendMotionEventToNext(motionEvent, motionEvent, policyFlags);
        boolean isEndOfSequence = message.arg1 != 0;
        if (isEndOfSequence) {
@@ -234,10 +221,6 @@ public class MotionEventInjector extends BaseEventStreamTransformation implement
        }
        if (!continuingGesture) {
            cancelAnyPendingInjectedEvents();
            if (!Flags.motionEventInjectorCancelFix()) {
                // Injected gestures have been canceled, but real gestures still need cancelling
                cancelInjectedGestureInProgress();
            }
        }
        mServiceInterfaceForCurrentGesture = serviceInterface;

@@ -354,13 +337,10 @@ public class MotionEventInjector extends BaseEventStreamTransformation implement
                    obtainMotionEvent(now, now, MotionEvent.ACTION_CANCEL, getLastTouchPoints(), 1);
            int policyFlags = WindowManagerPolicyConstants.FLAG_PASS_TO_USER
                    | WindowManagerPolicyConstants.FLAG_INJECTED_FROM_ACCESSIBILITY;
            if (android.view.accessibility.Flags
                    .preventA11yNontoolFromInjectingIntoSensitiveViews()) {
            // ACTION_CANCEL events are internal system details for event stream state
            // management and not used for performing new actions, so always treat them as
            // originating from an accessibility tool.
            policyFlags |= WindowManagerPolicyConstants.FLAG_INJECTED_FROM_ACCESSIBILITY_TOOL;
            }
            sendMotionEventToNext(cancelEvent, cancelEvent, policyFlags);
            mOpenTouchGestureInProgress = false;
        }
+0 −129
Original line number Diff line number Diff line
@@ -20,14 +20,12 @@ import static android.view.KeyCharacterMap.VIRTUAL_KEYBOARD;
import static android.view.MotionEvent.ACTION_DOWN;
import static android.view.MotionEvent.ACTION_HOVER_MOVE;
import static android.view.MotionEvent.ACTION_UP;
import static android.view.accessibility.Flags.FLAG_PREVENT_A11Y_NONTOOL_FROM_INJECTING_INTO_SENSITIVE_VIEWS;

import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.everyItem;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -46,8 +44,6 @@ import android.graphics.Point;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.view.Display;
import android.view.InputDevice;
@@ -234,7 +230,6 @@ public class MotionEventInjectorTest {
    }

    @Test
    @EnableFlags(FLAG_PREVENT_A11Y_NONTOOL_FROM_INJECTING_INTO_SENSITIVE_VIEWS)
    public void testInjectEvents_fromAccessibilityTool_providesToolPolicyFlag() {
        EventStreamTransformation next = attachMockNext(mMotionEventInjector);
        injectEventsSync(mLineList, mServiceInterface, LINE_SEQUENCE,
@@ -273,25 +268,6 @@ public class MotionEventInjectorTest {
    }

    @Test
    @DisableFlags({
            FLAG_PREVENT_A11Y_NONTOOL_FROM_INJECTING_INTO_SENSITIVE_VIEWS,
            Flags.FLAG_MOTION_EVENT_INJECTOR_CANCEL_FIX
    })
    public void testRegularEvent_afterGestureComplete_shouldPassToNext_withFlagInjectedFromA11y() {
        EventStreamTransformation next = attachMockNext(mMotionEventInjector);
        injectEventsSync(mLineList, mServiceInterface, LINE_SEQUENCE);
        mMessageCapturingHandler.sendAllMessages(); // Send all motion events
        reset(next);
        mMotionEventInjector.onMotionEvent(mClickDownEvent, mClickDownEvent, 0);
        verify(next).onMotionEvent(argThat(mIsClickDown), argThat(mIsClickDown),
                eq(WindowManagerPolicyConstants.FLAG_INJECTED_FROM_ACCESSIBILITY));
    }

    @Test
    @EnableFlags({
            FLAG_PREVENT_A11Y_NONTOOL_FROM_INJECTING_INTO_SENSITIVE_VIEWS,
            Flags.FLAG_MOTION_EVENT_INJECTOR_CANCEL_FIX
    })
    public void testRegularEvent_afterGestureComplete_shouldPassToNext_withNoPolicyFlagChanges() {
        EventStreamTransformation next = attachMockNext(mMotionEventInjector);
        injectEventsSync(mLineList, mServiceInterface, LINE_SEQUENCE);
@@ -304,26 +280,6 @@ public class MotionEventInjectorTest {
    }

    @Test
    @DisableFlags(Flags.FLAG_MOTION_EVENT_INJECTOR_CANCEL_FIX)
    public void testInjectEvents_withRealGestureUnderway_shouldCancelRealAndPassInjected() {
        EventStreamTransformation next = attachMockNext(mMotionEventInjector);
        mMotionEventInjector.onMotionEvent(mClickDownEvent, mClickDownEvent, 0);
        injectEventsSync(mLineList, mServiceInterface, LINE_SEQUENCE);

        verify(next, times(2)).onMotionEvent(mCaptor1.capture(), mCaptor2.capture(), anyInt());
        assertThat(mCaptor1.getAllValues().get(0), mIsClickDown);
        assertThat(mCaptor1.getAllValues().get(1), IS_ACTION_CANCEL);
        reset(next);

        mMessageCapturingHandler.sendOneMessage(); // Send a motion event
        verify(next).onMotionEvent(
                argThat(mIsLineStart), argThat(mIsLineStart),
                eq(WindowManagerPolicyConstants.FLAG_PASS_TO_USER
                        | WindowManagerPolicyConstants.FLAG_INJECTED_FROM_ACCESSIBILITY));
    }

    @Test
    @EnableFlags(Flags.FLAG_MOTION_EVENT_INJECTOR_CANCEL_FIX)
    public void testInjectEvents_withRealGestureUnderway_shouldNotCancelReal_ShouldPassInjected() {
        EventStreamTransformation next = attachMockNext(mMotionEventInjector);
        mMotionEventInjector.onMotionEvent(mClickDownEvent, mClickDownEvent, 0);
@@ -378,23 +334,6 @@ public class MotionEventInjectorTest {
    }

    @Test
    @DisableFlags(Flags.FLAG_MOTION_EVENT_INJECTOR_CANCEL_FIX)
    public void testOnMotionEvents_openInjectedGestureInProgress_shouldCancelAndNotifyAndPassReal()
            throws RemoteException {
        EventStreamTransformation next = attachMockNext(mMotionEventInjector);
        injectEventsSync(mLineList, mServiceInterface, LINE_SEQUENCE);
        mMessageCapturingHandler.sendOneMessage(); // Send a motion event
        mMotionEventInjector.onMotionEvent(mClickDownEvent, mClickDownEvent, 0);

        verify(next, times(3)).onMotionEvent(mCaptor1.capture(), mCaptor2.capture(), anyInt());
        assertThat(mCaptor1.getAllValues().get(0), mIsLineStart);
        assertThat(mCaptor1.getAllValues().get(1), IS_ACTION_CANCEL);
        assertThat(mCaptor1.getAllValues().get(2), mIsClickDown);
        verify(mServiceInterface).onPerformGestureResult(LINE_SEQUENCE, false);
    }

    @Test
    @EnableFlags(Flags.FLAG_MOTION_EVENT_INJECTOR_CANCEL_FIX)
    public void testOnMotionEvents_openInjectedGestureInProgress_shouldNotCancel_shouldPassReal()
            throws RemoteException {
        EventStreamTransformation next = attachMockNext(mMotionEventInjector);
@@ -428,36 +367,6 @@ public class MotionEventInjectorTest {
        verify(mServiceInterface).onPerformGestureResult(LINE_SEQUENCE, true);
    }

    @Test
    @DisableFlags(Flags.FLAG_MOTION_EVENT_INJECTOR_CANCEL_FIX)
    public void testOnMotionEvents_closedInjectedGestureInProgress_shouldOnlyNotifyAndPassReal()
            throws RemoteException {
        EventStreamTransformation next = attachMockNext(mMotionEventInjector);
        // Tack a click down to the end of the line
        TouchPoint clickTouchPoint = new TouchPoint();
        clickTouchPoint.mIsStartOfPath = true;
        clickTouchPoint.mX = CLICK_POINT.x;
        clickTouchPoint.mY = CLICK_POINT.y;
        mLineList.add(new GestureStep(0, 1, new TouchPoint[] {clickTouchPoint}));

        injectEventsSync(mLineList, mServiceInterface, LINE_SEQUENCE);

        // Send 3 motion events, leaving the extra down in the queue
        mMessageCapturingHandler.sendOneMessage();
        mMessageCapturingHandler.sendOneMessage();
        mMessageCapturingHandler.sendOneMessage();

        mMotionEventInjector.onMotionEvent(mClickDownEvent, mClickDownEvent, 0);

        verify(next, times(4)).onMotionEvent(mCaptor1.capture(), mCaptor2.capture(), anyInt());
        assertThat(mCaptor1.getAllValues().get(0), mIsLineStart);
        assertThat(mCaptor1.getAllValues().get(1), mIsLineMiddle);
        assertThat(mCaptor1.getAllValues().get(2), mIsLineEnd);
        assertThat(mCaptor1.getAllValues().get(3), mIsClickDown);
        verify(mServiceInterface).onPerformGestureResult(LINE_SEQUENCE, false);
        assertFalse(mMessageCapturingHandler.hasMessages());
    }

    @Test
    public void testInjectEvents_openInjectedGestureInProgress_shouldCancelAndNotifyAndPassNew()
            throws RemoteException {
@@ -719,28 +628,6 @@ public class MotionEventInjectorTest {
        assertThat(events.get(1), IS_ACTION_CANCEL);
    }

    @Test
    @DisableFlags(Flags.FLAG_MOTION_EVENT_INJECTOR_CANCEL_FIX)
    public void testContinuedGesture_realGestureArrivesInBetween_getsCanceled()
            throws Exception {
        EventStreamTransformation next = attachMockNext(mMotionEventInjector);
        injectEventsSync(mContinuedLineList1, mServiceInterface, CONTINUED_LINE_SEQUENCE_1);
        mMessageCapturingHandler.sendAllMessages(); // Send all motion events
        verify(mServiceInterface).onPerformGestureResult(CONTINUED_LINE_SEQUENCE_1, true);

        mMotionEventInjector.onMotionEvent(mClickDownEvent, mClickDownEvent, 0);

        injectEventsSync(mContinuedLineList2, mServiceInterface, CONTINUED_LINE_SEQUENCE_2);
        mMessageCapturingHandler.sendAllMessages(); // Send all motion events
        verify(mServiceInterface).onPerformGestureResult(CONTINUED_LINE_SEQUENCE_2, false);
        verify(next, times(4)).onMotionEvent(mCaptor1.capture(), mCaptor2.capture(), anyInt());
        List<MotionEvent> events = mCaptor1.getAllValues();
        assertThat(events.get(0), allOf(isAtPoint(CONTINUED_LINE_START), IS_ACTION_DOWN));
        assertThat(events.get(1), allOf(isAtPoint(CONTINUED_LINE_MID1), IS_ACTION_MOVE));
        assertThat(events.get(2), IS_ACTION_CANCEL);
        assertThat(events.get(3), allOf(isAtPoint(CLICK_POINT), IS_ACTION_DOWN));
    }

    @Test
    public void testClearEvents_realGestureInProgress_shouldForgetAboutGesture() {
        EventStreamTransformation next = attachMockNext(mMotionEventInjector);
@@ -755,22 +642,6 @@ public class MotionEventInjectorTest {
    }

    @Test
    @DisableFlags(Flags.FLAG_MOTION_EVENT_INJECTOR_CANCEL_FIX)
    public void testClearEventsOnOtherSource_realGestureInProgress_shouldNotForgetAboutGesture() {
        EventStreamTransformation next = attachMockNext(mMotionEventInjector);
        mMotionEventInjector.onMotionEvent(mClickDownEvent, mClickDownEvent, 0);
        mMotionEventInjector.clearEvents(OTHER_EVENT_SOURCE);
        injectEventsSync(mLineList, mServiceInterface, LINE_SEQUENCE);
        mMessageCapturingHandler.sendOneMessage(); // Send a motion event

        verify(next, times(3)).onMotionEvent(mCaptor1.capture(), mCaptor2.capture(), anyInt());
        assertThat(mCaptor1.getAllValues().get(0), mIsClickDown);
        assertThat(mCaptor1.getAllValues().get(1), IS_ACTION_CANCEL);
        assertThat(mCaptor1.getAllValues().get(2), mIsLineStart);
    }

    @Test
    @EnableFlags(Flags.FLAG_MOTION_EVENT_INJECTOR_CANCEL_FIX)
    public void testClearEventsOnOtherSource_shouldNotCancelRealOrInjectedGesture() {
        EventStreamTransformation next = attachMockNext(mMotionEventInjector);
        mMotionEventInjector.onMotionEvent(mClickDownEvent, mClickDownEvent, 0);