Loading core/java/android/view/BatchedInputEventReceiver.java +35 −1 Original line number Diff line number Diff line Loading @@ -78,7 +78,7 @@ public class BatchedInputEventReceiver extends InputEventReceiver { } } void doConsumeBatchedInput(long frameTimeNanos) { protected void doConsumeBatchedInput(long frameTimeNanos) { if (mBatchedInputScheduled) { mBatchedInputScheduled = false; if (consumeBatchedInputEvents(frameTimeNanos) && frameTimeNanos != -1) { Loading Loading @@ -114,4 +114,38 @@ public class BatchedInputEventReceiver extends InputEventReceiver { } } private final BatchedInputRunnable mBatchedInputRunnable = new BatchedInputRunnable(); /** * A {@link BatchedInputEventReceiver} that reports events to an {@link InputEventListener}. * @hide */ public static class SimpleBatchedInputEventReceiver extends BatchedInputEventReceiver { /** @hide */ public interface InputEventListener { /** * Process the input event. * @return handled */ boolean onInputEvent(InputEvent event); } protected InputEventListener mListener; public SimpleBatchedInputEventReceiver(InputChannel inputChannel, Looper looper, Choreographer choreographer, InputEventListener listener) { super(inputChannel, looper, choreographer); mListener = listener; } @Override public void onInputEvent(InputEvent event) { boolean handled = false; try { handled = mListener.onInputEvent(event); } finally { finishInputEvent(event, handled); } } } } services/core/java/com/android/server/wm/TaskPositioner.java +78 −91 Original line number Diff line number Diff line Loading @@ -40,18 +40,17 @@ import android.graphics.Point; import android.graphics.Rect; import android.os.Binder; import android.os.IBinder; import android.os.Looper; import android.os.Process; import android.os.RemoteException; import android.os.Trace; import android.util.DisplayMetrics; import android.util.Slog; import android.view.BatchedInputEventReceiver; import android.view.Choreographer; import android.view.InputApplicationHandle; import android.view.InputChannel; import android.view.InputDevice; import android.view.InputEvent; import android.view.InputEventReceiver; import android.view.InputWindowHandle; import android.view.MotionEvent; import android.view.WindowManager; Loading @@ -73,7 +72,7 @@ class TaskPositioner implements IBinder.DeathRecipient { public static final int RESIZING_HINT_DURATION_MS = 0; private final WindowManagerService mService; private WindowPositionerEventReceiver mInputEventReceiver; private InputEventReceiver mInputEventReceiver; private DisplayContent mDisplayContent; private Rect mTmpRect = new Rect(); private int mMinVisibleWidth; Loading @@ -100,29 +99,25 @@ class TaskPositioner implements IBinder.DeathRecipient { InputApplicationHandle mDragApplicationHandle; InputWindowHandle mDragWindowHandle; private final class WindowPositionerEventReceiver extends BatchedInputEventReceiver { public WindowPositionerEventReceiver( InputChannel inputChannel, Looper looper, Choreographer choreographer) { super(inputChannel, looper, choreographer); /** Use {@link #create(WindowManagerService)} instead. */ @VisibleForTesting TaskPositioner(WindowManagerService service) { mService = service; } @Override public void onInputEvent(InputEvent event) { boolean handled = false; try { private boolean onInputEvent(InputEvent event) { // All returns need to be in the try block to make sure the finishInputEvent is // called correctly. if (!(event instanceof MotionEvent) || (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { return; return false; } final MotionEvent motionEvent = (MotionEvent) event; if (mDragEnded) { // The drag has ended but the clean-up message has not been processed by // window manager. Drop events that occur after this until window manager // has a chance to clean-up the input handle. handled = true; return; return true; } final float newX = motionEvent.getRawX(); Loading @@ -133,7 +128,8 @@ class TaskPositioner implements IBinder.DeathRecipient { if (DEBUG_TASK_POSITIONING) { Slog.w(TAG, "ACTION_DOWN @ {" + newX + ", " + newY + "}"); } } break; } break; case MotionEvent.ACTION_MOVE: { if (DEBUG_TASK_POSITIONING) { Loading @@ -150,21 +146,24 @@ class TaskPositioner implements IBinder.DeathRecipient { mTask.mTaskId, mWindowDragBounds, RESIZE_MODE_USER); Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); } } break; } break; case MotionEvent.ACTION_UP: { if (DEBUG_TASK_POSITIONING) { Slog.w(TAG, "ACTION_UP @ {" + newX + ", " + newY + "}"); } mDragEnded = true; } break; } break; case MotionEvent.ACTION_CANCEL: { if (DEBUG_TASK_POSITIONING) { Slog.w(TAG, "ACTION_CANCEL @ {" + newX + ", " + newY + "}"); } mDragEnded = true; } break; } break; } if (mDragEnded) { Loading @@ -184,19 +183,7 @@ class TaskPositioner implements IBinder.DeathRecipient { // event handler for the last finishInputEvent()! mService.mTaskPositioningController.finishTaskPositioning(); } handled = true; } catch (Exception e) { Slog.e(TAG, "Exception caught by drag handleMotion", e); } finally { finishInputEvent(event, handled); } } } /** Use {@link #create(WindowManagerService)} instead. */ @VisibleForTesting TaskPositioner(WindowManagerService service) { mService = service; return true; } @VisibleForTesting Loading @@ -221,9 +208,9 @@ class TaskPositioner implements IBinder.DeathRecipient { mDisplayContent = displayContent; mClientChannel = mService.mInputManager.createInputChannel(TAG); mInputEventReceiver = new WindowPositionerEventReceiver( mInputEventReceiver = new BatchedInputEventReceiver.SimpleBatchedInputEventReceiver( mClientChannel, mService.mAnimationHandler.getLooper(), mService.mAnimator.getChoreographer()); mService.mAnimator.getChoreographer(), this::onInputEvent); mDragApplicationHandle = new InputApplicationHandle(new Binder(), TAG, DEFAULT_DISPATCHING_TIMEOUT_MILLIS); Loading Loading
core/java/android/view/BatchedInputEventReceiver.java +35 −1 Original line number Diff line number Diff line Loading @@ -78,7 +78,7 @@ public class BatchedInputEventReceiver extends InputEventReceiver { } } void doConsumeBatchedInput(long frameTimeNanos) { protected void doConsumeBatchedInput(long frameTimeNanos) { if (mBatchedInputScheduled) { mBatchedInputScheduled = false; if (consumeBatchedInputEvents(frameTimeNanos) && frameTimeNanos != -1) { Loading Loading @@ -114,4 +114,38 @@ public class BatchedInputEventReceiver extends InputEventReceiver { } } private final BatchedInputRunnable mBatchedInputRunnable = new BatchedInputRunnable(); /** * A {@link BatchedInputEventReceiver} that reports events to an {@link InputEventListener}. * @hide */ public static class SimpleBatchedInputEventReceiver extends BatchedInputEventReceiver { /** @hide */ public interface InputEventListener { /** * Process the input event. * @return handled */ boolean onInputEvent(InputEvent event); } protected InputEventListener mListener; public SimpleBatchedInputEventReceiver(InputChannel inputChannel, Looper looper, Choreographer choreographer, InputEventListener listener) { super(inputChannel, looper, choreographer); mListener = listener; } @Override public void onInputEvent(InputEvent event) { boolean handled = false; try { handled = mListener.onInputEvent(event); } finally { finishInputEvent(event, handled); } } } }
services/core/java/com/android/server/wm/TaskPositioner.java +78 −91 Original line number Diff line number Diff line Loading @@ -40,18 +40,17 @@ import android.graphics.Point; import android.graphics.Rect; import android.os.Binder; import android.os.IBinder; import android.os.Looper; import android.os.Process; import android.os.RemoteException; import android.os.Trace; import android.util.DisplayMetrics; import android.util.Slog; import android.view.BatchedInputEventReceiver; import android.view.Choreographer; import android.view.InputApplicationHandle; import android.view.InputChannel; import android.view.InputDevice; import android.view.InputEvent; import android.view.InputEventReceiver; import android.view.InputWindowHandle; import android.view.MotionEvent; import android.view.WindowManager; Loading @@ -73,7 +72,7 @@ class TaskPositioner implements IBinder.DeathRecipient { public static final int RESIZING_HINT_DURATION_MS = 0; private final WindowManagerService mService; private WindowPositionerEventReceiver mInputEventReceiver; private InputEventReceiver mInputEventReceiver; private DisplayContent mDisplayContent; private Rect mTmpRect = new Rect(); private int mMinVisibleWidth; Loading @@ -100,29 +99,25 @@ class TaskPositioner implements IBinder.DeathRecipient { InputApplicationHandle mDragApplicationHandle; InputWindowHandle mDragWindowHandle; private final class WindowPositionerEventReceiver extends BatchedInputEventReceiver { public WindowPositionerEventReceiver( InputChannel inputChannel, Looper looper, Choreographer choreographer) { super(inputChannel, looper, choreographer); /** Use {@link #create(WindowManagerService)} instead. */ @VisibleForTesting TaskPositioner(WindowManagerService service) { mService = service; } @Override public void onInputEvent(InputEvent event) { boolean handled = false; try { private boolean onInputEvent(InputEvent event) { // All returns need to be in the try block to make sure the finishInputEvent is // called correctly. if (!(event instanceof MotionEvent) || (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { return; return false; } final MotionEvent motionEvent = (MotionEvent) event; if (mDragEnded) { // The drag has ended but the clean-up message has not been processed by // window manager. Drop events that occur after this until window manager // has a chance to clean-up the input handle. handled = true; return; return true; } final float newX = motionEvent.getRawX(); Loading @@ -133,7 +128,8 @@ class TaskPositioner implements IBinder.DeathRecipient { if (DEBUG_TASK_POSITIONING) { Slog.w(TAG, "ACTION_DOWN @ {" + newX + ", " + newY + "}"); } } break; } break; case MotionEvent.ACTION_MOVE: { if (DEBUG_TASK_POSITIONING) { Loading @@ -150,21 +146,24 @@ class TaskPositioner implements IBinder.DeathRecipient { mTask.mTaskId, mWindowDragBounds, RESIZE_MODE_USER); Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); } } break; } break; case MotionEvent.ACTION_UP: { if (DEBUG_TASK_POSITIONING) { Slog.w(TAG, "ACTION_UP @ {" + newX + ", " + newY + "}"); } mDragEnded = true; } break; } break; case MotionEvent.ACTION_CANCEL: { if (DEBUG_TASK_POSITIONING) { Slog.w(TAG, "ACTION_CANCEL @ {" + newX + ", " + newY + "}"); } mDragEnded = true; } break; } break; } if (mDragEnded) { Loading @@ -184,19 +183,7 @@ class TaskPositioner implements IBinder.DeathRecipient { // event handler for the last finishInputEvent()! mService.mTaskPositioningController.finishTaskPositioning(); } handled = true; } catch (Exception e) { Slog.e(TAG, "Exception caught by drag handleMotion", e); } finally { finishInputEvent(event, handled); } } } /** Use {@link #create(WindowManagerService)} instead. */ @VisibleForTesting TaskPositioner(WindowManagerService service) { mService = service; return true; } @VisibleForTesting Loading @@ -221,9 +208,9 @@ class TaskPositioner implements IBinder.DeathRecipient { mDisplayContent = displayContent; mClientChannel = mService.mInputManager.createInputChannel(TAG); mInputEventReceiver = new WindowPositionerEventReceiver( mInputEventReceiver = new BatchedInputEventReceiver.SimpleBatchedInputEventReceiver( mClientChannel, mService.mAnimationHandler.getLooper(), mService.mAnimator.getChoreographer()); mService.mAnimator.getChoreographer(), this::onInputEvent); mDragApplicationHandle = new InputApplicationHandle(new Binder(), TAG, DEFAULT_DISPATCHING_TIMEOUT_MILLIS); Loading