Allow enabling/disabling batching in BatchedInputEventReceiver
- Use the batched receiver when handling back only after the gesture is recognized (fewer updates) - Remove some unused code Bug: 167732711 Test: Back gesture still works Change-Id: I2b12574a4d6c7f997a8cdc70825ef1bd03669fd8
This commit is contained in:
@@ -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) {
|
||||
scheduleBatchedInput();
|
||||
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;
|
||||
|
||||
@@ -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
|
||||
@@ -84,41 +72,18 @@ public class InputChannelCompat {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BatchedInputEventReceiver#setBatchingEnabled()
|
||||
*/
|
||||
public void setBatchingEnabled(boolean batchingEnabled) {
|
||||
mReceiver.setBatchingEnabled(batchingEnabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BatchedInputEventReceiver#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
mReceiver.dispose();
|
||||
mInputChannel.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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()
|
||||
*/
|
||||
public void dispose() {
|
||||
mSender.dispose();
|
||||
mInputChannel.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user