Merge "Fix a11y key event handling from multiple devices." into nyc-dev
am: 4b88bddb12
* commit '4b88bddb12a62ec2d791d45e5b995aab87666a7b':
Fix a11y key event handling from multiple devices.
Change-Id: I8da38100a98ab902033cfc290858a8da13c97ccd
This commit is contained in:
@@ -20,6 +20,7 @@ import android.content.Context;
|
|||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.util.Pools.SimplePool;
|
import android.util.Pools.SimplePool;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
import android.util.SparseBooleanArray;
|
||||||
import android.view.Choreographer;
|
import android.view.Choreographer;
|
||||||
import android.view.InputDevice;
|
import android.view.InputDevice;
|
||||||
import android.view.InputEvent;
|
import android.view.InputEvent;
|
||||||
@@ -637,10 +638,10 @@ class AccessibilityInputFilter extends InputFilter implements EventStreamTransfo
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keeps state of stream of events from a keyboard device.
|
* Keeps state of streams of events from all keyboard devices.
|
||||||
*/
|
*/
|
||||||
private static class KeyboardEventStreamState extends EventStreamState {
|
private static class KeyboardEventStreamState extends EventStreamState {
|
||||||
private boolean mEventSequenceStarted;
|
private SparseBooleanArray mEventSequenceStartedMap = new SparseBooleanArray();
|
||||||
|
|
||||||
public KeyboardEventStreamState() {
|
public KeyboardEventStreamState() {
|
||||||
reset();
|
reset();
|
||||||
@@ -649,17 +650,35 @@ class AccessibilityInputFilter extends InputFilter implements EventStreamTransfo
|
|||||||
@Override
|
@Override
|
||||||
final public void reset() {
|
final public void reset() {
|
||||||
super.reset();
|
super.reset();
|
||||||
mEventSequenceStarted = false;
|
mEventSequenceStartedMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Key events from different devices may be interleaved. For example, the volume up and
|
||||||
|
* down keys can come from different device IDs.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean updateDeviceId(int deviceId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We manage all device ids simultaneously; there is no concept of validity.
|
||||||
|
@Override
|
||||||
|
public boolean deviceIdValid() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
final public boolean shouldProcessKeyEvent(KeyEvent event) {
|
final public boolean shouldProcessKeyEvent(KeyEvent event) {
|
||||||
// Wait for a down key event to start processing.
|
// For each keyboard device, wait for a down event from a device to start processing
|
||||||
if (mEventSequenceStarted) {
|
int deviceId = event.getDeviceId();
|
||||||
|
if (mEventSequenceStartedMap.get(deviceId, false)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
mEventSequenceStarted = event.getAction() == KeyEvent.ACTION_DOWN;
|
boolean shouldProcess = event.getAction() == KeyEvent.ACTION_DOWN;
|
||||||
return mEventSequenceStarted;
|
mEventSequenceStartedMap.put(deviceId, shouldProcess);
|
||||||
|
return shouldProcess;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user