Loading core/java/android/os/Handler.java +2 −1 Original line number Diff line number Diff line Loading @@ -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; Loading services/accessibility/java/com/android/server/accessibility/MagnificationGestureHandler.java +16 −4 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); Loading Loading @@ -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(); Loading Loading @@ -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) { Loading Loading @@ -811,7 +822,7 @@ class MagnificationGestureHandler extends BaseEventStreamTransformation { void transitionToDelegatingStateAndClear() { transitionTo(mDelegatingState); sendDelayedMotionEvents(); clear(); removePendingDelayedMessages(); } private void onTripleTap(MotionEvent up) { Loading Loading @@ -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); Loading services/tests/servicestests/src/com/android/server/accessibility/MagnificationGestureHandlerTest.java +27 −6 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; /** Loading Loading @@ -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, Loading Loading @@ -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} Loading Loading @@ -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() { Loading @@ -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) { Loading Loading
core/java/android/os/Handler.java +2 −1 Original line number Diff line number Diff line Loading @@ -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; Loading
services/accessibility/java/com/android/server/accessibility/MagnificationGestureHandler.java +16 −4 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); Loading Loading @@ -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(); Loading Loading @@ -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) { Loading Loading @@ -811,7 +822,7 @@ class MagnificationGestureHandler extends BaseEventStreamTransformation { void transitionToDelegatingStateAndClear() { transitionTo(mDelegatingState); sendDelayedMotionEvents(); clear(); removePendingDelayedMessages(); } private void onTripleTap(MotionEvent up) { Loading Loading @@ -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); Loading
services/tests/servicestests/src/com/android/server/accessibility/MagnificationGestureHandlerTest.java +27 −6 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; /** Loading Loading @@ -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, Loading Loading @@ -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} Loading Loading @@ -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() { Loading @@ -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) { Loading