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

Commit 8f07ee15 authored by Eugene Susla's avatar Eugene Susla
Browse files

Fix magnification button toggle off

Fixes: b/69307379
Test: Ensure attached bug no longer reproduces.
Ensure magnification using a11y button otherwise works as expected
Change-Id: Ie4e966eb8cfcc9d3f37ae7252b951381ef1fb7c7
parent f80ebafa
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -202,7 +202,8 @@ public class Handler {
        mLooper = Looper.myLooper();
        if (mLooper == null) {
            throw new RuntimeException(
                "Can't create handler inside thread that has not called Looper.prepare()");
                "Can't create handler inside thread " + Thread.currentThread()
                        + " that has not called Looper.prepare()");
        }
        mQueue = mLooper.mQueue;
        mCallback = callback;
+16 −4
Original line number Diff line number Diff line
@@ -37,7 +37,9 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.util.MathUtils;
import android.util.Slog;
import android.util.TypedValue;
@@ -154,6 +156,12 @@ class MagnificationGestureHandler extends BaseEventStreamTransformation {
            MagnificationController magnificationController,
            boolean detectTripleTap,
            boolean detectShortcutTrigger) {
        if (DEBUG_ALL) {
            Log.i(LOG_TAG,
                    "MagnificationGestureHandler(detectTripleTap = " + detectTripleTap
                            + ", detectShortcutTrigger = " + detectShortcutTrigger + ")");
        }

        mMagnificationController = magnificationController;

        mDelegatingState = new DelegatingState();
@@ -581,7 +589,7 @@ class MagnificationGestureHandler extends BaseEventStreamTransformation {

        @VisibleForTesting boolean mShortcutTriggered;

        Handler mHandler = new Handler(this);
        @VisibleForTesting Handler mHandler = new Handler(this);

        public DetectingState(Context context) {
            mLongTapMinDelay = ViewConfiguration.getLongPressTimeout();
@@ -756,11 +764,14 @@ class MagnificationGestureHandler extends BaseEventStreamTransformation {
        @Override
        public void clear() {
            setShortcutTriggered(false);
            mHandler.removeMessages(MESSAGE_ON_TRIPLE_TAP_AND_HOLD);
            mHandler.removeMessages(MESSAGE_TRANSITION_TO_DELEGATING_STATE);
            removePendingDelayedMessages();
            clearDelayedMotionEvents();
        }

        private void removePendingDelayedMessages() {
            mHandler.removeMessages(MESSAGE_ON_TRIPLE_TAP_AND_HOLD);
            mHandler.removeMessages(MESSAGE_TRANSITION_TO_DELEGATING_STATE);
        }

        private void cacheDelayedMotionEvent(MotionEvent event, MotionEvent rawEvent,
                int policyFlags) {
@@ -811,7 +822,7 @@ class MagnificationGestureHandler extends BaseEventStreamTransformation {
        void transitionToDelegatingStateAndClear() {
            transitionTo(mDelegatingState);
            sendDelayedMotionEvents();
            clear();
            removePendingDelayedMessages();
        }

        private void onTripleTap(MotionEvent up) {
@@ -860,6 +871,7 @@ class MagnificationGestureHandler extends BaseEventStreamTransformation {
            if (mShortcutTriggered == state) {
                return;
            }
            if (DEBUG_DETECTING) Slog.i(LOG_TAG, "setShortcutTriggered(" + state + ")");

            mShortcutTriggered = state;
            mMagnificationController.setForceShowMagnifiableBounds(state);
+27 −6
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import static android.view.MotionEvent.ACTION_POINTER_UP;

import static com.android.server.testutils.TestUtils.strictMock;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
@@ -32,6 +34,7 @@ import static org.mockito.Mockito.verify;

import android.annotation.NonNull;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
@@ -46,7 +49,9 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.concurrent.CompletableFuture;
import java.util.function.IntConsumer;
import java.util.function.Supplier;


/**
@@ -130,7 +135,7 @@ public class MagnificationGestureHandlerTest {
    }

    @NonNull
    public MagnificationGestureHandler newInstance(boolean detectTripleTap,
    private MagnificationGestureHandler newInstance(boolean detectTripleTap,
            boolean detectShortcutTrigger) {
        MagnificationGestureHandler h = new MagnificationGestureHandler(
                mContext, mMagnificationController,
@@ -192,6 +197,16 @@ public class MagnificationGestureHandlerTest {
        });
    }

    @Test
    public void testTransitionToDelegatingStateAndClear_preservesShortcutTriggeredState() {
        mMgh.mDetectingState.transitionToDelegatingStateAndClear();
        assertFalse(mMgh.mDetectingState.mShortcutTriggered);

        goFromStateIdleTo(STATE_SHORTCUT_TRIGGERED);
        mMgh.mDetectingState.transitionToDelegatingStateAndClear();
        assertTrue(mMgh.mDetectingState.mShortcutTriggered);
    }

    /**
     * Covers edges of the graph not covered by "canonical" transitions specified in
     * {@link #goFromStateIdleTo} and {@link #returnToNormalFrom}
@@ -510,14 +525,20 @@ public class MagnificationGestureHandlerTest {
        fastForward(1);
    }

    private static MotionEvent fromTouchscreen(MotionEvent ev) {
        ev.setSource(InputDevice.SOURCE_TOUCHSCREEN);
        return ev;
    }

    private MotionEvent moveEvent(float x, float y) {
        return MotionEvent.obtain(mLastDownTime, mClock.now(), ACTION_MOVE, x, y, 0);
        return fromTouchscreen(
        	    MotionEvent.obtain(mLastDownTime, mClock.now(), ACTION_MOVE, x, y, 0));
    }

    private MotionEvent downEvent() {
        mLastDownTime = mClock.now();
        return MotionEvent.obtain(mLastDownTime, mLastDownTime,
                ACTION_DOWN, DEFAULT_X, DEFAULT_Y, 0);
        return fromTouchscreen(MotionEvent.obtain(mLastDownTime, mLastDownTime,
                ACTION_DOWN, DEFAULT_X, DEFAULT_Y, 0));
    }

    private MotionEvent upEvent() {
@@ -525,8 +546,8 @@ public class MagnificationGestureHandlerTest {
    }

    private MotionEvent upEvent(long downTime) {
        return MotionEvent.obtain(downTime, mClock.now(),
                MotionEvent.ACTION_UP, DEFAULT_X, DEFAULT_Y, 0);
        return fromTouchscreen(MotionEvent.obtain(downTime, mClock.now(),
                MotionEvent.ACTION_UP, DEFAULT_X, DEFAULT_Y, 0));
    }

    private MotionEvent pointerEvent(int action, float x, float y) {