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

Commit 0bc9f9ea authored by Jean Chen's avatar Jean Chen
Browse files

Fix will log triple tap on shortcut temporary glance mode

The long press after the shortcut case and the triple tap and hold case will both call the same function. This caused the shortcut case to be logged as a triple tap event. I added a check to the condition to ensure that the shortcut case was not logged. This fixed the issue and also fixed the incorrect log enable state.

Bug: 296036296
Test: manual
Test: atest FullScreenMagnificationGestureHandlerTest
Change-Id: I10df9d434c31d7f6d043e9f860eb9bbef3af7615
parent 426720b4
Loading
Loading
Loading
Loading
+49 −10
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import static android.view.MotionEvent.ACTION_POINTER_DOWN;
import static android.view.MotionEvent.ACTION_POINTER_UP;
import static android.view.MotionEvent.ACTION_UP;

import static com.android.internal.accessibility.util.AccessibilityStatsLogUtils.logMagnificationTripleTap;
import static com.android.server.accessibility.gestures.GestureUtils.distance;
import static com.android.server.accessibility.gestures.GestureUtils.distanceClosestPointerToPoint;

@@ -65,6 +64,7 @@ import android.view.ScaleGestureDetector.OnScaleGestureListener;
import android.view.ViewConfiguration;

import com.android.internal.R;
import com.android.internal.accessibility.util.AccessibilityStatsLogUtils;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.accessibility.AccessibilityManagerService;
import com.android.server.accessibility.AccessibilityTraceManager;
@@ -143,6 +143,7 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH

    private final ScreenStateReceiver mScreenStateReceiver;
    private final WindowMagnificationPromptController mPromptController;
    @NonNull private final MagnificationLogger mMagnificationLogger;

    @VisibleForTesting State mCurrentState;
    @VisibleForTesting State mPreviousState;
@@ -164,6 +165,10 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
    public @interface OverscrollState {}

    @VisibleForTesting boolean mIsSinglePanningEnabled;

    /**
     * FullScreenMagnificationGestureHandler Constructor.
     */
    public FullScreenMagnificationGestureHandler(@UiContext Context context,
            FullScreenMagnificationController fullScreenMagnificationController,
            AccessibilityTraceManager trace,
@@ -173,6 +178,23 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
            @NonNull WindowMagnificationPromptController promptController,
            int displayId,
            FullScreenMagnificationVibrationHelper fullScreenMagnificationVibrationHelper) {
        this(context, fullScreenMagnificationController, trace, callback, detectTripleTap,
                detectShortcutTrigger, promptController, displayId,
                fullScreenMagnificationVibrationHelper, /* magnificationLogger= */ null);
    }

    /** Constructor for tests. */
    @VisibleForTesting
    FullScreenMagnificationGestureHandler(@UiContext Context context,
            FullScreenMagnificationController fullScreenMagnificationController,
            AccessibilityTraceManager trace,
            Callback callback,
            boolean detectTripleTap,
            boolean detectShortcutTrigger,
            @NonNull WindowMagnificationPromptController promptController,
            int displayId,
            FullScreenMagnificationVibrationHelper fullScreenMagnificationVibrationHelper,
            MagnificationLogger magnificationLogger) {
        super(displayId, detectTripleTap, detectShortcutTrigger, trace, callback);
        if (DEBUG_ALL) {
            Log.i(mLogTag,
@@ -216,6 +238,17 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH

        mPromptController = promptController;

        if (magnificationLogger != null) {
            mMagnificationLogger = magnificationLogger;
        } else {
            mMagnificationLogger = new MagnificationLogger() {
                @Override
                public void logMagnificationTripleTap(boolean enabled) {
                    AccessibilityStatsLogUtils.logMagnificationTripleTap(enabled);
                }
            };
        }

        mDelegatingState = new DelegatingState();
        mDetectingState = new DetectingState(context);
        mViewportDraggingState = new ViewportDraggingState();
@@ -365,6 +398,11 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
        mCurrentState = state;
    }

    /** An interface that allows testing magnification log events. */
    interface MagnificationLogger {
        void logMagnificationTripleTap(boolean enabled);
    }

    interface State {
        void onMotionEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags)
                throws GestureException;
@@ -930,10 +968,10 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
                    && isMultiTap(mPreLastDown, mLastDown)
                    && isMultiTap(mPreLastUp, mLastUp);

            // Only log the triple tap event, use numTaps to filter.
            // Only log the triple tap event, use numTaps to filter
            if (multitapTriggered && numTaps > 2) {
                final boolean enabled = isActivated();
                logMagnificationTripleTap(enabled);
                final boolean enabled = !isActivated();
                mMagnificationLogger.logMagnificationTripleTap(enabled);
            }
            return multitapTriggered;
        }
@@ -1094,16 +1132,17 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH

            if (DEBUG_DETECTING) Slog.i(mLogTag, "onTripleTapAndHold()");
            final boolean shortcutTriggered = mShortcutTriggered;
            clear();

            // Triple tap and hold also belongs to triple tap event.
            // Only log the 3tap and hold event
            if (!shortcutTriggered) {
                // Triple tap and hold also belongs to triple tap event
                final boolean enabled = !isActivated();
            logMagnificationTripleTap(enabled);
                mMagnificationLogger.logMagnificationTripleTap(enabled);
            }
            clear();

            mViewportDraggingState.prepareForZoomInTemporary(shortcutTriggered);

            zoomInTemporary(down.getX(), down.getY(), shortcutTriggered);

            transitionTo(mViewportDraggingState);
        }

+69 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
@@ -38,6 +39,7 @@ import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -170,6 +172,8 @@ public class FullScreenMagnificationGestureHandlerTest {
    AccessibilityTraceManager mMockTraceManager;
    @Mock
    FullScreenMagnificationVibrationHelper mMockFullScreenMagnificationVibrationHelper;
    @Mock
    FullScreenMagnificationGestureHandler.MagnificationLogger mMockMagnificationLogger;

    @Rule
    public final TestableContext mContext = new TestableContext(getInstrumentation().getContext());
@@ -253,7 +257,7 @@ public class FullScreenMagnificationGestureHandlerTest {
                mContext, mFullScreenMagnificationController, mMockTraceManager, mMockCallback,
                detectTripleTap, detectShortcutTrigger,
                mWindowMagnificationPromptController, DISPLAY_0,
                mMockFullScreenMagnificationVibrationHelper);
                mMockFullScreenMagnificationVibrationHelper, mMockMagnificationLogger);
        if (isWatch()) {
            h.setSinglePanningEnabled(true);
        } else {
@@ -427,6 +431,70 @@ public class FullScreenMagnificationGestureHandlerTest {
        verify(mMgh.getNext(), times(2)).onMotionEvent(any(), any(), anyInt());
    }

    @Test
    public void testLongTapAfterShortcutTriggered_neverLogMagnificationTripleTap() {
        goFromStateIdleTo(STATE_SHORTCUT_TRIGGERED);

        longTap();

        verify(mMockMagnificationLogger, never()).logMagnificationTripleTap(anyBoolean());
    }

    @Test
    public void testSwipeAndHoldAfterShortcutTriggered_neverLogMagnificationTripleTap() {
        goFromStateIdleTo(STATE_SHORTCUT_TRIGGERED);

        swipeAndHold();

        verify(mMockMagnificationLogger, never()).logMagnificationTripleTap(anyBoolean());
    }

    @Test
    public void testTripleTap_isNotActivated_logMagnificationTripleTapIsEnabled() {
        goFromStateIdleTo(STATE_IDLE);

        tap();
        tap();
        longTap();

        verify(mMockMagnificationLogger).logMagnificationTripleTap(true);
    }

    @Test
    public void testTripleTap_isActivated_logMagnificationTripleTapIsNotEnabled() {
        goFromStateIdleTo(STATE_ACTIVATED);
        reset(mMockMagnificationLogger);

        tap();
        tap();
        longTap();

        verify(mMockMagnificationLogger).logMagnificationTripleTap(false);
    }

    @Test
    public void testTripleTapAndHold_isNotActivated_logMagnificationTripleTapIsEnabled() {
        goFromStateIdleTo(STATE_IDLE);

        tap();
        tap();
        swipeAndHold();

        verify(mMockMagnificationLogger).logMagnificationTripleTap(true);
    }

    @Test
    public void testTripleTapAndHold_isActivated_logMagnificationTripleTapIsNotEnabled() {
        goFromStateIdleTo(STATE_ACTIVATED);
        reset(mMockMagnificationLogger);

        tap();
        tap();
        swipeAndHold();

        verify(mMockMagnificationLogger).logMagnificationTripleTap(false);
    }

    @Test
    public void testTripleTapAndHold_zoomsImmediately() {
        assertZoomsImmediatelyOnSwipeFrom(STATE_2TAPS, STATE_NON_ACTIVATED_ZOOMED_TMP);