Added more robust tracking and cancelation of events.
This change fixes several issues where events would be dropped in the
input dispatch pipeline in such a way that the dispatcher could not
accurately track the state of the input device.
Given more robust tracking, we can now also provide robust cancelation
of input events in cases where an application might otherwise become
out of sync with the event stream due to ANR, app switch, policy decisions,
or forced focus transitions.
Pruned some of the input dispatcher log output.
Moved the responsibility for calling intercept*BeforeQueueing into
the input dispatcher instead of the input reader and added support for
early interception of injected events for events coming from trusted
sources. This enables behaviors like injection of media keys while
the screen is off, haptic feedback of injected virtual keys, so injected
events become more "first class" in a way.
Change-Id: Iec6ff1dd21e5f3c7feb80ea4feb5382bd090dbd9
diff --git a/libs/ui/InputReader.cpp b/libs/ui/InputReader.cpp
index 7adc764..0560bb8 100644
--- a/libs/ui/InputReader.cpp
+++ b/libs/ui/InputReader.cpp
@@ -796,10 +796,6 @@
return 0;
}
-bool InputMapper::applyStandardPolicyActions(nsecs_t when, int32_t policyActions) {
- return policyActions & InputReaderPolicyInterface::ACTION_DISPATCH;
-}
-
// --- SwitchInputMapper ---
@@ -823,11 +819,7 @@
}
void SwitchInputMapper::processSwitch(nsecs_t when, int32_t switchCode, int32_t switchValue) {
- uint32_t policyFlags = 0;
- int32_t policyActions = getPolicy()->interceptSwitch(
- when, switchCode, switchValue, policyFlags);
-
- applyStandardPolicyActions(when, policyActions);
+ getDispatcher()->notifySwitch(when, switchCode, switchValue, 0);
}
int32_t SwitchInputMapper::getSwitchState(uint32_t sourceMask, int32_t switchCode) {
@@ -983,29 +975,9 @@
getContext()->updateGlobalMetaState();
}
- applyPolicyAndDispatch(when, policyFlags, down, keyCode, scanCode, newMetaState, downTime);
-}
-
-void KeyboardInputMapper::applyPolicyAndDispatch(nsecs_t when, uint32_t policyFlags, bool down,
- int32_t keyCode, int32_t scanCode, int32_t metaState, nsecs_t downTime) {
- int32_t policyActions = getPolicy()->interceptKey(when,
- getDeviceId(), down, keyCode, scanCode, policyFlags);
-
- if (! applyStandardPolicyActions(when, policyActions)) {
- return; // event dropped
- }
-
- int32_t keyEventAction = down ? AKEY_EVENT_ACTION_DOWN : AKEY_EVENT_ACTION_UP;
- int32_t keyEventFlags = AKEY_EVENT_FLAG_FROM_SYSTEM;
- if (policyFlags & POLICY_FLAG_WOKE_HERE) {
- keyEventFlags |= AKEY_EVENT_FLAG_WOKE_HERE;
- }
- if (policyFlags & POLICY_FLAG_VIRTUAL) {
- keyEventFlags |= AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY;
- }
-
getDispatcher()->notifyKey(when, getDeviceId(), AINPUT_SOURCE_KEYBOARD, policyFlags,
- keyEventAction, keyEventFlags, keyCode, scanCode, metaState, downTime);
+ down ? AKEY_EVENT_ACTION_DOWN : AKEY_EVENT_ACTION_UP,
+ AKEY_EVENT_FLAG_FROM_SYSTEM, keyCode, scanCode, newMetaState, downTime);
}
ssize_t KeyboardInputMapper::findKeyDownLocked(int32_t scanCode) {
@@ -1215,26 +1187,13 @@
}
} // release lock
- applyPolicyAndDispatch(when, motionEventAction, & pointerCoords, downTime);
-
- mAccumulator.clear();
-}
-
-void TrackballInputMapper::applyPolicyAndDispatch(nsecs_t when, int32_t motionEventAction,
- PointerCoords* pointerCoords, nsecs_t downTime) {
- uint32_t policyFlags = 0;
- int32_t policyActions = getPolicy()->interceptGeneric(when, policyFlags);
-
- if (! applyStandardPolicyActions(when, policyActions)) {
- return; // event dropped
- }
-
int32_t metaState = mContext->getGlobalMetaState();
int32_t pointerId = 0;
-
- getDispatcher()->notifyMotion(when, getDeviceId(), AINPUT_SOURCE_TRACKBALL, policyFlags,
+ getDispatcher()->notifyMotion(when, getDeviceId(), AINPUT_SOURCE_TRACKBALL, 0,
motionEventAction, 0, metaState, AMOTION_EVENT_EDGE_FLAG_NONE,
- 1, & pointerId, pointerCoords, mXPrecision, mYPrecision, downTime);
+ 1, &pointerId, &pointerCoords, mXPrecision, mYPrecision, downTime);
+
+ mAccumulator.clear();
}
int32_t TrackballInputMapper::getScanCodeState(uint32_t sourceMask, int32_t scanCode) {
@@ -2012,15 +1971,7 @@
}
void TouchInputMapper::syncTouch(nsecs_t when, bool havePointerIds) {
- // Apply generic policy actions.
-
uint32_t policyFlags = 0;
- int32_t policyActions = getPolicy()->interceptGeneric(when, policyFlags);
-
- if (! applyStandardPolicyActions(when, policyActions)) {
- mLastTouch.clear();
- return; // event dropped
- }
// Preprocess pointer data.
@@ -2160,24 +2111,11 @@
} // release lock
// Dispatch virtual key.
- applyPolicyAndDispatchVirtualKey(when, policyFlags, keyEventAction, keyEventFlags,
- keyCode, scanCode, downTime);
- return touchResult;
-}
-
-void TouchInputMapper::applyPolicyAndDispatchVirtualKey(nsecs_t when, uint32_t policyFlags,
- int32_t keyEventAction, int32_t keyEventFlags,
- int32_t keyCode, int32_t scanCode, nsecs_t downTime) {
int32_t metaState = mContext->getGlobalMetaState();
-
policyFlags |= POLICY_FLAG_VIRTUAL;
- int32_t policyActions = getPolicy()->interceptKey(when, getDeviceId(),
- keyEventAction == AKEY_EVENT_ACTION_DOWN, keyCode, scanCode, policyFlags);
-
- if (applyStandardPolicyActions(when, policyActions)) {
- getDispatcher()->notifyKey(when, getDeviceId(), AINPUT_SOURCE_KEYBOARD, policyFlags,
- keyEventAction, keyEventFlags, keyCode, scanCode, metaState, downTime);
- }
+ getDispatcher()->notifyKey(when, getDeviceId(), AINPUT_SOURCE_KEYBOARD, policyFlags,
+ keyEventAction, keyEventFlags, keyCode, scanCode, metaState, downTime);
+ return touchResult;
}
void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) {