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

Commit d9b9d038 authored by Winson Chung's avatar Winson Chung Committed by Android (Google) Code Review
Browse files

Merge "Allow enabling/disabling batching in BatchedInputEventReceiver"

parents 7266e1fa 0e32990c
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -24,7 +24,8 @@ import android.os.Looper;
 * @hide
 */
public class BatchedInputEventReceiver extends InputEventReceiver {
    Choreographer mChoreographer;
    private Choreographer mChoreographer;
    private boolean mBatchingEnabled;
    private boolean mBatchedInputScheduled;

    @UnsupportedAppUsage
@@ -32,19 +33,37 @@ public class BatchedInputEventReceiver extends InputEventReceiver {
            InputChannel inputChannel, Looper looper, Choreographer choreographer) {
        super(inputChannel, looper);
        mChoreographer = choreographer;
        mBatchingEnabled = true;
    }

    @Override
    public void onBatchedInputEventPending(int source) {
        if (mBatchingEnabled) {
            scheduleBatchedInput();
        } else {
            consumeBatchedInputEvents(-1);
        }
    }

    @Override
    public void dispose() {
        unscheduleBatchedInput();
        consumeBatchedInputEvents(-1);
        super.dispose();
    }

    /**
     * Sets whether to enable batching on this input event receiver.
     * @hide
     */
    public void setBatchingEnabled(boolean batchingEnabled) {
        mBatchingEnabled = batchingEnabled;
        if (!batchingEnabled) {
            unscheduleBatchedInput();
            consumeBatchedInputEvents(-1);
        }
    }

    void doConsumeBatchedInput(long frameTimeNanos) {
        if (mBatchedInputScheduled) {
            mBatchedInputScheduled = false;
+5 −40
Original line number Diff line number Diff line
@@ -40,16 +40,6 @@ public class InputChannelCompat {
        void onInputEvent(InputEvent ev);
    }

    /**
     * Creates a dispatcher from the extras received as part on onInitialize
     */
    public static InputEventReceiver fromBundle(Bundle params, String key,
            Looper looper, Choreographer choreographer, InputEventListener listener) {

        InputChannel channel = params.getParcelable(key);
        return new InputEventReceiver(channel, looper, choreographer, listener);
    }

    /**
     * Version of addBatch method which preserves time accuracy in nanoseconds instead of
     * converting the time to milliseconds.
@@ -69,11 +59,9 @@ public class InputChannelCompat {
    public static class InputEventReceiver {

        private final BatchedInputEventReceiver mReceiver;
        private final InputChannel mInputChannel;

        public InputEventReceiver(InputChannel inputChannel, Looper looper,
                Choreographer choreographer, final InputEventListener listener) {
            mInputChannel = inputChannel;
            mReceiver = new BatchedInputEventReceiver(inputChannel, looper, choreographer) {

                @Override
@@ -85,40 +73,17 @@ public class InputChannelCompat {
        }

        /**
         * @see BatchedInputEventReceiver#dispose()
         * @see BatchedInputEventReceiver#setBatchingEnabled()
         */
        public void dispose() {
            mReceiver.dispose();
            mInputChannel.dispose();
        }
        public void setBatchingEnabled(boolean batchingEnabled) {
            mReceiver.setBatchingEnabled(batchingEnabled);
        }

        /**
     * @see InputEventSender
     */
    public static class InputEventDispatcher {

        private final InputChannel mInputChannel;
        private final InputEventSender mSender;

        public InputEventDispatcher(InputChannel inputChannel, Looper looper) {
            mInputChannel = inputChannel;
            mSender = new InputEventSender(inputChannel, looper) { };
        }

        /**
         * @see InputEventSender#sendInputEvent(int, InputEvent)
         */
        public void dispatch(InputEvent ev) {
            mSender.sendInputEvent(ev.getSequenceNumber(), ev);
        }

        /**
         * @see InputEventSender#dispose()
         * @see BatchedInputEventReceiver#dispose()
         */
        public void dispose() {
            mSender.dispose();
            mInputChannel.dispose();
            mReceiver.dispose();
        }
    }
}
+8 −15
Original line number Diff line number Diff line
@@ -38,11 +38,11 @@ import android.provider.DeviceConfig;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.Choreographer;
import android.view.ISystemGestureExclusionListener;
import android.view.InputChannel;
import android.view.InputDevice;
import android.view.InputEvent;
import android.view.InputEventReceiver;
import android.view.InputMonitor;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
@@ -67,6 +67,7 @@ import com.android.systemui.recents.OverviewProxyService;
import com.android.systemui.settings.CurrentUserTracker;
import com.android.systemui.shared.plugins.PluginManager;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.InputChannelCompat;
import com.android.systemui.shared.system.QuickStepContract;
import com.android.systemui.shared.system.SysUiStatsLog;
import com.android.systemui.shared.system.TaskStackChangeListener;
@@ -169,7 +170,7 @@ public class EdgeBackGestureHandler extends CurrentUserTracker implements Displa
    private boolean mGestureBlockingActivityRunning;

    private InputMonitor mInputMonitor;
    private InputEventReceiver mInputEventReceiver;
    private InputChannelCompat.InputEventReceiver mInputEventReceiver;

    private NavigationEdgeBackPlugin mEdgeBackPlugin;
    private int mLeftInset;
@@ -383,8 +384,9 @@ public class EdgeBackGestureHandler extends CurrentUserTracker implements Displa
            // Register input event receiver
            mInputMonitor = InputManager.getInstance().monitorGestureInput(
                    "edge-swipe", mDisplayId);
            mInputEventReceiver = new SysUiInputEventReceiver(
                    mInputMonitor.getInputChannel(), Looper.getMainLooper());
            mInputEventReceiver = new InputChannelCompat.InputEventReceiver(
                    mInputMonitor.getInputChannel(), Looper.getMainLooper(),
                    Choreographer.getInstance(), this::onInputEvent);

            // Add a nav bar panel window
            setEdgeBackPlugin(new NavigationBarEdgePanel(mContext));
@@ -520,6 +522,7 @@ public class EdgeBackGestureHandler extends CurrentUserTracker implements Displa
        if (action == MotionEvent.ACTION_DOWN) {
            // Verify if this is in within the touch region and we aren't in immersive mode, and
            // either the bouncer is showing or the notification panel is hidden
            mInputEventReceiver.setBatchingEnabled(false);
            mIsOnLeftEdge = ev.getX() <= mEdgeWidthLeft + mLeftInset;
            mLogGesture = false;
            mInRejectedExclusion = false;
@@ -571,6 +574,7 @@ public class EdgeBackGestureHandler extends CurrentUserTracker implements Displa
                            mThresholdCrossed = true;
                            // Capture inputs
                            mInputMonitor.pilferPointers();
                            mInputEventReceiver.setBatchingEnabled(true);
                        } else {
                            logGesture(SysUiStatsLog.BACK_GESTURE__TYPE__INCOMPLETE_FAR_FROM_EDGE);
                        }
@@ -672,15 +676,4 @@ public class EdgeBackGestureHandler extends CurrentUserTracker implements Displa
        }
        proto.edgeBackGestureHandler.allowGesture = mAllowGesture;
    }

    class SysUiInputEventReceiver extends InputEventReceiver {
        SysUiInputEventReceiver(InputChannel channel, Looper looper) {
            super(channel, looper);
        }

        public void onInputEvent(InputEvent event) {
            EdgeBackGestureHandler.this.onInputEvent(event);
            finishInputEvent(event, true);
        }
    }
}