Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
//
|
|
|
|
// Copyright 2010 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// The input dispatcher.
|
|
|
|
//
|
|
|
|
#define LOG_TAG "InputDispatcher"
|
|
|
|
|
|
|
|
//#define LOG_NDEBUG 0
|
|
|
|
|
|
|
|
// Log detailed debug messages about each inbound event notification to the dispatcher.
|
2010-06-22 08:27:15 +00:00
|
|
|
#define DEBUG_INBOUND_EVENT_DETAILS 0
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
|
|
|
// Log detailed debug messages about each outbound event processed by the dispatcher.
|
2010-06-22 08:27:15 +00:00
|
|
|
#define DEBUG_OUTBOUND_EVENT_DETAILS 0
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
|
|
|
// Log debug messages about batching.
|
2010-06-22 08:27:15 +00:00
|
|
|
#define DEBUG_BATCHING 0
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
|
|
|
// Log debug messages about the dispatch cycle.
|
2010-06-22 08:27:15 +00:00
|
|
|
#define DEBUG_DISPATCH_CYCLE 0
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-06-15 08:31:58 +00:00
|
|
|
// Log debug messages about registrations.
|
2010-06-22 08:27:15 +00:00
|
|
|
#define DEBUG_REGISTRATION 0
|
2010-06-15 08:31:58 +00:00
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
// Log debug messages about performance statistics.
|
2010-06-22 08:27:15 +00:00
|
|
|
#define DEBUG_PERFORMANCE_STATISTICS 0
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-06-18 03:52:56 +00:00
|
|
|
// Log debug messages about input event injection.
|
2010-06-22 08:27:15 +00:00
|
|
|
#define DEBUG_INJECTION 0
|
2010-06-18 03:52:56 +00:00
|
|
|
|
2010-08-18 22:51:08 +00:00
|
|
|
// Log debug messages about input event throttling.
|
|
|
|
#define DEBUG_THROTTLING 0
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
// Log debug messages about input focus tracking.
|
|
|
|
#define DEBUG_FOCUS 0
|
|
|
|
|
|
|
|
// Log debug messages about the app switch latency optimization.
|
|
|
|
#define DEBUG_APP_SWITCH 0
|
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
#include <cutils/log.h>
|
|
|
|
#include <ui/InputDispatcher.h>
|
2010-09-08 18:49:43 +00:00
|
|
|
#include <ui/PowerManager.h>
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
2010-10-02 00:46:21 +00:00
|
|
|
#define INDENT " "
|
|
|
|
#define INDENT2 " "
|
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
namespace android {
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
// Default input dispatching timeout if there is no focused application or paused window
|
|
|
|
// from which to determine an appropriate dispatching timeout.
|
|
|
|
const nsecs_t DEFAULT_INPUT_DISPATCHING_TIMEOUT = 5000 * 1000000LL; // 5 sec
|
|
|
|
|
|
|
|
// Amount of time to allow for all pending events to be processed when an app switch
|
|
|
|
// key is on the way. This is used to preempt input dispatch and drop input events
|
|
|
|
// when an application takes too long to respond and the user has pressed an app switch key.
|
|
|
|
const nsecs_t APP_SWITCH_TIMEOUT = 500 * 1000000LL; // 0.5sec
|
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-06-18 03:52:56 +00:00
|
|
|
static inline nsecs_t now() {
|
|
|
|
return systemTime(SYSTEM_TIME_MONOTONIC);
|
|
|
|
}
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
static inline const char* toString(bool value) {
|
|
|
|
return value ? "true" : "false";
|
|
|
|
}
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
static inline int32_t getMotionEventActionPointerIndex(int32_t action) {
|
|
|
|
return (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK)
|
|
|
|
>> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isValidKeyAction(int32_t action) {
|
|
|
|
switch (action) {
|
|
|
|
case AKEY_EVENT_ACTION_DOWN:
|
|
|
|
case AKEY_EVENT_ACTION_UP:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool validateKeyEvent(int32_t action) {
|
|
|
|
if (! isValidKeyAction(action)) {
|
|
|
|
LOGE("Key event has invalid action code 0x%x", action);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-09 05:31:17 +00:00
|
|
|
static bool isValidMotionAction(int32_t action, size_t pointerCount) {
|
2010-09-27 05:20:12 +00:00
|
|
|
switch (action & AMOTION_EVENT_ACTION_MASK) {
|
|
|
|
case AMOTION_EVENT_ACTION_DOWN:
|
|
|
|
case AMOTION_EVENT_ACTION_UP:
|
|
|
|
case AMOTION_EVENT_ACTION_CANCEL:
|
|
|
|
case AMOTION_EVENT_ACTION_MOVE:
|
|
|
|
case AMOTION_EVENT_ACTION_OUTSIDE:
|
|
|
|
return true;
|
2010-10-09 05:31:17 +00:00
|
|
|
case AMOTION_EVENT_ACTION_POINTER_DOWN:
|
|
|
|
case AMOTION_EVENT_ACTION_POINTER_UP: {
|
|
|
|
int32_t index = getMotionEventActionPointerIndex(action);
|
|
|
|
return index >= 0 && size_t(index) < pointerCount;
|
|
|
|
}
|
2010-09-27 05:20:12 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool validateMotionEvent(int32_t action, size_t pointerCount,
|
|
|
|
const int32_t* pointerIds) {
|
2010-10-09 05:31:17 +00:00
|
|
|
if (! isValidMotionAction(action, pointerCount)) {
|
2010-09-27 05:20:12 +00:00
|
|
|
LOGE("Motion event has invalid action code 0x%x", action);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (pointerCount < 1 || pointerCount > MAX_POINTERS) {
|
|
|
|
LOGE("Motion event has invalid pointer count %d; value must be between 1 and %d.",
|
|
|
|
pointerCount, MAX_POINTERS);
|
|
|
|
return false;
|
|
|
|
}
|
2010-10-20 22:33:38 +00:00
|
|
|
BitSet32 pointerIdBits;
|
2010-09-27 05:20:12 +00:00
|
|
|
for (size_t i = 0; i < pointerCount; i++) {
|
2010-10-20 22:33:38 +00:00
|
|
|
int32_t id = pointerIds[i];
|
|
|
|
if (id < 0 || id > MAX_POINTER_ID) {
|
2010-09-27 05:20:12 +00:00
|
|
|
LOGE("Motion event has invalid pointer id %d; value must be between 0 and %d",
|
2010-10-20 22:33:38 +00:00
|
|
|
id, MAX_POINTER_ID);
|
2010-09-27 05:20:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-10-20 22:33:38 +00:00
|
|
|
if (pointerIdBits.hasBit(id)) {
|
|
|
|
LOGE("Motion event has duplicate pointer id %d", id);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
pointerIdBits.markBit(id);
|
2010-09-27 05:20:12 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
|
|
|
|
// --- InputWindow ---
|
|
|
|
|
|
|
|
bool InputWindow::touchableAreaContainsPoint(int32_t x, int32_t y) const {
|
|
|
|
return x >= touchableAreaLeft && x <= touchableAreaRight
|
|
|
|
&& y >= touchableAreaTop && y <= touchableAreaBottom;
|
|
|
|
}
|
|
|
|
|
2010-10-05 19:26:23 +00:00
|
|
|
bool InputWindow::frameContainsPoint(int32_t x, int32_t y) const {
|
|
|
|
return x >= frameLeft && x <= frameRight
|
|
|
|
&& y >= frameTop && y <= frameBottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputWindow::isTrustedOverlay() const {
|
|
|
|
return layoutParamsType == TYPE_INPUT_METHOD
|
2010-10-15 07:54:27 +00:00
|
|
|
|| layoutParamsType == TYPE_INPUT_METHOD_DIALOG
|
|
|
|
|| layoutParamsType == TYPE_SECURE_SYSTEM_OVERLAY;
|
2010-10-05 19:26:23 +00:00
|
|
|
}
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
// --- InputDispatcher ---
|
|
|
|
|
2010-06-15 08:31:58 +00:00
|
|
|
InputDispatcher::InputDispatcher(const sp<InputDispatcherPolicyInterface>& policy) :
|
2010-09-08 18:49:43 +00:00
|
|
|
mPolicy(policy),
|
|
|
|
mPendingEvent(NULL), mAppSwitchDueTime(LONG_LONG_MAX),
|
|
|
|
mDispatchEnabled(true), mDispatchFrozen(false),
|
2010-09-27 05:20:12 +00:00
|
|
|
mFocusedWindow(NULL),
|
2010-09-08 18:49:43 +00:00
|
|
|
mFocusedApplication(NULL),
|
|
|
|
mCurrentInputTargetsValid(false),
|
|
|
|
mInputTargetWaitCause(INPUT_TARGET_WAIT_CAUSE_NONE) {
|
2010-09-14 06:17:30 +00:00
|
|
|
mLooper = new Looper(false);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
mInboundQueue.headSentinel.refCount = -1;
|
|
|
|
mInboundQueue.headSentinel.type = EventEntry::TYPE_SENTINEL;
|
|
|
|
mInboundQueue.headSentinel.eventTime = LONG_LONG_MIN;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
mInboundQueue.tailSentinel.refCount = -1;
|
|
|
|
mInboundQueue.tailSentinel.type = EventEntry::TYPE_SENTINEL;
|
|
|
|
mInboundQueue.tailSentinel.eventTime = LONG_LONG_MAX;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
|
|
|
mKeyRepeatState.lastKeyEntry = NULL;
|
2010-06-15 08:31:58 +00:00
|
|
|
|
2010-08-18 22:51:08 +00:00
|
|
|
int32_t maxEventsPerSecond = policy->getMaxEventsPerSecond();
|
|
|
|
mThrottleState.minTimeBetweenEvents = 1000000000LL / maxEventsPerSecond;
|
|
|
|
mThrottleState.lastDeviceId = -1;
|
|
|
|
|
|
|
|
#if DEBUG_THROTTLING
|
|
|
|
mThrottleState.originalSampleCount = 0;
|
|
|
|
LOGD("Throttling - Max events per second = %d", maxEventsPerSecond);
|
|
|
|
#endif
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InputDispatcher::~InputDispatcher() {
|
2010-09-08 18:49:43 +00:00
|
|
|
{ // acquire lock
|
|
|
|
AutoMutex _l(mLock);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
resetKeyRepeatLocked();
|
2010-09-16 21:07:33 +00:00
|
|
|
releasePendingEventLocked();
|
2010-09-08 18:49:43 +00:00
|
|
|
drainInboundQueueLocked();
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
while (mConnectionsByReceiveFd.size() != 0) {
|
|
|
|
unregisterInputChannel(mConnectionsByReceiveFd.valueAt(0)->inputChannel);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::dispatchOnce() {
|
2010-06-15 08:31:58 +00:00
|
|
|
nsecs_t keyRepeatTimeout = mPolicy->getKeyRepeatTimeout();
|
2010-09-07 17:44:57 +00:00
|
|
|
nsecs_t keyRepeatDelay = mPolicy->getKeyRepeatDelay();
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
|
|
|
nsecs_t nextWakeupTime = LONG_LONG_MAX;
|
|
|
|
{ // acquire lock
|
|
|
|
AutoMutex _l(mLock);
|
2010-09-08 18:49:43 +00:00
|
|
|
dispatchOnceInnerLocked(keyRepeatTimeout, keyRepeatDelay, & nextWakeupTime);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
if (runCommandsLockedInterruptible()) {
|
|
|
|
nextWakeupTime = LONG_LONG_MIN; // force next poll to wake up immediately
|
|
|
|
}
|
|
|
|
} // release lock
|
|
|
|
|
|
|
|
// Wait for callback or timeout or wake. (make sure we round up, not down)
|
|
|
|
nsecs_t currentTime = now();
|
|
|
|
int32_t timeoutMillis;
|
|
|
|
if (nextWakeupTime > currentTime) {
|
|
|
|
uint64_t timeout = uint64_t(nextWakeupTime - currentTime);
|
|
|
|
timeout = (timeout + 999999LL) / 1000000LL;
|
|
|
|
timeoutMillis = timeout > INT_MAX ? -1 : int32_t(timeout);
|
|
|
|
} else {
|
|
|
|
timeoutMillis = 0;
|
|
|
|
}
|
|
|
|
|
2010-09-14 06:17:30 +00:00
|
|
|
mLooper->pollOnce(timeoutMillis);
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::dispatchOnceInnerLocked(nsecs_t keyRepeatTimeout,
|
|
|
|
nsecs_t keyRepeatDelay, nsecs_t* nextWakeupTime) {
|
|
|
|
nsecs_t currentTime = now();
|
|
|
|
|
|
|
|
// Reset the key repeat timer whenever we disallow key events, even if the next event
|
|
|
|
// is not a key. This is to ensure that we abort a key repeat if the device is just coming
|
|
|
|
// out of sleep.
|
|
|
|
if (keyRepeatTimeout < 0) {
|
|
|
|
resetKeyRepeatLocked();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If dispatching is frozen, do not process timeouts or try to deliver any new events.
|
|
|
|
if (mDispatchFrozen) {
|
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("Dispatch frozen. Waiting some more.");
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
// Optimize latency of app switches.
|
|
|
|
// Essentially we start a short timeout when an app switch key (HOME / ENDCALL) has
|
|
|
|
// been pressed. When it expires, we preempt dispatch and drop all other pending events.
|
|
|
|
bool isAppSwitchDue = mAppSwitchDueTime <= currentTime;
|
|
|
|
if (mAppSwitchDueTime < *nextWakeupTime) {
|
|
|
|
*nextWakeupTime = mAppSwitchDueTime;
|
|
|
|
}
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
// Ready to start a new event.
|
|
|
|
// If we don't already have a pending event, go grab one.
|
|
|
|
if (! mPendingEvent) {
|
|
|
|
if (mInboundQueue.isEmpty()) {
|
|
|
|
if (isAppSwitchDue) {
|
|
|
|
// The inbound queue is empty so the app switch key we were waiting
|
|
|
|
// for will never arrive. Stop waiting for it.
|
|
|
|
resetPendingAppSwitchLocked(false);
|
|
|
|
isAppSwitchDue = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Synthesize a key repeat if appropriate.
|
|
|
|
if (mKeyRepeatState.lastKeyEntry) {
|
|
|
|
if (currentTime >= mKeyRepeatState.nextRepeatTime) {
|
|
|
|
mPendingEvent = synthesizeKeyRepeatLocked(currentTime, keyRepeatDelay);
|
|
|
|
} else {
|
|
|
|
if (mKeyRepeatState.nextRepeatTime < *nextWakeupTime) {
|
|
|
|
*nextWakeupTime = mKeyRepeatState.nextRepeatTime;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
if (! mPendingEvent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Inbound queue has at least one entry.
|
|
|
|
EventEntry* entry = mInboundQueue.headSentinel.next;
|
|
|
|
|
|
|
|
// Throttle the entry if it is a move event and there are no
|
|
|
|
// other events behind it in the queue. Due to movement batching, additional
|
|
|
|
// samples may be appended to this event by the time the throttling timeout
|
|
|
|
// expires.
|
|
|
|
// TODO Make this smarter and consider throttling per device independently.
|
2010-10-09 05:31:17 +00:00
|
|
|
if (entry->type == EventEntry::TYPE_MOTION
|
|
|
|
&& !isAppSwitchDue
|
|
|
|
&& mDispatchEnabled
|
|
|
|
&& (entry->policyFlags & POLICY_FLAG_PASS_TO_USER)
|
|
|
|
&& !entry->isInjected()) {
|
2010-09-08 18:49:43 +00:00
|
|
|
MotionEntry* motionEntry = static_cast<MotionEntry*>(entry);
|
|
|
|
int32_t deviceId = motionEntry->deviceId;
|
|
|
|
uint32_t source = motionEntry->source;
|
|
|
|
if (! isAppSwitchDue
|
|
|
|
&& motionEntry->next == & mInboundQueue.tailSentinel // exactly one event
|
|
|
|
&& motionEntry->action == AMOTION_EVENT_ACTION_MOVE
|
|
|
|
&& deviceId == mThrottleState.lastDeviceId
|
|
|
|
&& source == mThrottleState.lastSource) {
|
|
|
|
nsecs_t nextTime = mThrottleState.lastEventTime
|
|
|
|
+ mThrottleState.minTimeBetweenEvents;
|
|
|
|
if (currentTime < nextTime) {
|
|
|
|
// Throttle it!
|
2010-08-18 22:51:08 +00:00
|
|
|
#if DEBUG_THROTTLING
|
2010-09-08 18:49:43 +00:00
|
|
|
LOGD("Throttling - Delaying motion event for "
|
|
|
|
"device 0x%x, source 0x%08x by up to %0.3fms.",
|
|
|
|
deviceId, source, (nextTime - currentTime) * 0.000001);
|
2010-08-18 22:51:08 +00:00
|
|
|
#endif
|
2010-09-08 18:49:43 +00:00
|
|
|
if (nextTime < *nextWakeupTime) {
|
|
|
|
*nextWakeupTime = nextTime;
|
2010-08-18 22:51:08 +00:00
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
if (mThrottleState.originalSampleCount == 0) {
|
|
|
|
mThrottleState.originalSampleCount =
|
|
|
|
motionEntry->countSamples();
|
|
|
|
}
|
|
|
|
return;
|
2010-08-18 22:51:08 +00:00
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
2010-08-18 22:51:08 +00:00
|
|
|
|
|
|
|
#if DEBUG_THROTTLING
|
2010-09-08 18:49:43 +00:00
|
|
|
if (mThrottleState.originalSampleCount != 0) {
|
|
|
|
uint32_t count = motionEntry->countSamples();
|
|
|
|
LOGD("Throttling - Motion event sample count grew by %d from %d to %d.",
|
|
|
|
count - mThrottleState.originalSampleCount,
|
|
|
|
mThrottleState.originalSampleCount, count);
|
|
|
|
mThrottleState.originalSampleCount = 0;
|
|
|
|
}
|
2010-08-18 22:51:08 +00:00
|
|
|
#endif
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
mThrottleState.lastEventTime = entry->eventTime < currentTime
|
|
|
|
? entry->eventTime : currentTime;
|
|
|
|
mThrottleState.lastDeviceId = deviceId;
|
|
|
|
mThrottleState.lastSource = source;
|
|
|
|
}
|
2010-08-18 22:51:08 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
mInboundQueue.dequeue(entry);
|
|
|
|
mPendingEvent = entry;
|
|
|
|
}
|
2010-10-18 20:21:23 +00:00
|
|
|
|
|
|
|
// Poke user activity for this event.
|
|
|
|
if (mPendingEvent->policyFlags & POLICY_FLAG_PASS_TO_USER) {
|
|
|
|
pokeUserActivityLocked(mPendingEvent);
|
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
// Now we have an event to dispatch.
|
|
|
|
assert(mPendingEvent != NULL);
|
2010-09-16 21:07:33 +00:00
|
|
|
bool done = false;
|
2010-10-09 05:31:17 +00:00
|
|
|
DropReason dropReason = DROP_REASON_NOT_DROPPED;
|
|
|
|
if (!(mPendingEvent->policyFlags & POLICY_FLAG_PASS_TO_USER)) {
|
|
|
|
dropReason = DROP_REASON_POLICY;
|
|
|
|
} else if (!mDispatchEnabled) {
|
|
|
|
dropReason = DROP_REASON_DISABLED;
|
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
switch (mPendingEvent->type) {
|
|
|
|
case EventEntry::TYPE_CONFIGURATION_CHANGED: {
|
|
|
|
ConfigurationChangedEntry* typedEntry =
|
|
|
|
static_cast<ConfigurationChangedEntry*>(mPendingEvent);
|
2010-09-16 21:07:33 +00:00
|
|
|
done = dispatchConfigurationChangedLocked(currentTime, typedEntry);
|
2010-10-09 05:31:17 +00:00
|
|
|
dropReason = DROP_REASON_NOT_DROPPED; // configuration changes are never dropped
|
2010-09-08 18:49:43 +00:00
|
|
|
break;
|
|
|
|
}
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
case EventEntry::TYPE_KEY: {
|
|
|
|
KeyEntry* typedEntry = static_cast<KeyEntry*>(mPendingEvent);
|
2010-10-09 05:31:17 +00:00
|
|
|
if (isAppSwitchDue) {
|
|
|
|
if (isAppSwitchKeyEventLocked(typedEntry)) {
|
2010-09-08 18:49:43 +00:00
|
|
|
resetPendingAppSwitchLocked(true);
|
2010-10-09 05:31:17 +00:00
|
|
|
isAppSwitchDue = false;
|
|
|
|
} else if (dropReason == DROP_REASON_NOT_DROPPED) {
|
|
|
|
dropReason = DROP_REASON_APP_SWITCH;
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-09 05:31:17 +00:00
|
|
|
done = dispatchKeyLocked(currentTime, typedEntry, keyRepeatTimeout,
|
2010-10-11 21:20:19 +00:00
|
|
|
&dropReason, nextWakeupTime);
|
2010-09-08 18:49:43 +00:00
|
|
|
break;
|
|
|
|
}
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
case EventEntry::TYPE_MOTION: {
|
|
|
|
MotionEntry* typedEntry = static_cast<MotionEntry*>(mPendingEvent);
|
2010-10-09 05:31:17 +00:00
|
|
|
if (dropReason == DROP_REASON_NOT_DROPPED && isAppSwitchDue) {
|
|
|
|
dropReason = DROP_REASON_APP_SWITCH;
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
2010-10-09 05:31:17 +00:00
|
|
|
done = dispatchMotionLocked(currentTime, typedEntry,
|
2010-10-11 21:20:19 +00:00
|
|
|
&dropReason, nextWakeupTime);
|
2010-09-08 18:49:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-06-15 08:31:58 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
default:
|
|
|
|
assert(false);
|
|
|
|
break;
|
|
|
|
}
|
2010-08-18 22:51:08 +00:00
|
|
|
|
2010-09-16 21:07:33 +00:00
|
|
|
if (done) {
|
2010-10-09 05:31:17 +00:00
|
|
|
if (dropReason != DROP_REASON_NOT_DROPPED) {
|
|
|
|
dropInboundEventLocked(mPendingEvent, dropReason);
|
|
|
|
}
|
|
|
|
|
2010-09-16 21:07:33 +00:00
|
|
|
releasePendingEventLocked();
|
2010-09-08 18:49:43 +00:00
|
|
|
*nextWakeupTime = LONG_LONG_MIN; // force next poll to wake up immediately
|
|
|
|
}
|
|
|
|
}
|
2010-06-15 08:31:58 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
bool InputDispatcher::enqueueInboundEventLocked(EventEntry* entry) {
|
|
|
|
bool needWake = mInboundQueue.isEmpty();
|
|
|
|
mInboundQueue.enqueueAtTail(entry);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
switch (entry->type) {
|
2010-10-09 05:31:17 +00:00
|
|
|
case EventEntry::TYPE_KEY: {
|
|
|
|
KeyEntry* keyEntry = static_cast<KeyEntry*>(entry);
|
|
|
|
if (isAppSwitchKeyEventLocked(keyEntry)) {
|
|
|
|
if (keyEntry->action == AKEY_EVENT_ACTION_DOWN) {
|
|
|
|
mAppSwitchSawKeyDown = true;
|
|
|
|
} else if (keyEntry->action == AKEY_EVENT_ACTION_UP) {
|
|
|
|
if (mAppSwitchSawKeyDown) {
|
|
|
|
#if DEBUG_APP_SWITCH
|
|
|
|
LOGD("App switch is pending!");
|
|
|
|
#endif
|
|
|
|
mAppSwitchDueTime = keyEntry->eventTime + APP_SWITCH_TIMEOUT;
|
|
|
|
mAppSwitchSawKeyDown = false;
|
|
|
|
needWake = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
break;
|
2010-06-15 08:31:58 +00:00
|
|
|
}
|
2010-10-09 05:31:17 +00:00
|
|
|
}
|
2010-06-15 08:31:58 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
return needWake;
|
|
|
|
}
|
|
|
|
|
2010-10-09 05:31:17 +00:00
|
|
|
void InputDispatcher::dropInboundEventLocked(EventEntry* entry, DropReason dropReason) {
|
|
|
|
const char* reason;
|
|
|
|
switch (dropReason) {
|
|
|
|
case DROP_REASON_POLICY:
|
2010-10-11 21:20:19 +00:00
|
|
|
#if DEBUG_INBOUND_EVENT_DETAILS
|
2010-10-12 06:32:49 +00:00
|
|
|
LOGD("Dropped event because policy consumed it.");
|
2010-10-11 21:20:19 +00:00
|
|
|
#endif
|
2010-10-12 06:32:49 +00:00
|
|
|
reason = "inbound event was dropped because the policy consumed it";
|
2010-10-09 05:31:17 +00:00
|
|
|
break;
|
|
|
|
case DROP_REASON_DISABLED:
|
|
|
|
LOGI("Dropped event because input dispatch is disabled.");
|
|
|
|
reason = "inbound event was dropped because input dispatch is disabled";
|
|
|
|
break;
|
|
|
|
case DROP_REASON_APP_SWITCH:
|
|
|
|
LOGI("Dropped event because of pending overdue app switch.");
|
|
|
|
reason = "inbound event was dropped because of pending overdue app switch";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (entry->type) {
|
|
|
|
case EventEntry::TYPE_KEY:
|
|
|
|
synthesizeCancelationEventsForAllConnectionsLocked(
|
|
|
|
InputState::CANCEL_NON_POINTER_EVENTS, reason);
|
|
|
|
break;
|
|
|
|
case EventEntry::TYPE_MOTION: {
|
|
|
|
MotionEntry* motionEntry = static_cast<MotionEntry*>(entry);
|
|
|
|
if (motionEntry->source & AINPUT_SOURCE_CLASS_POINTER) {
|
|
|
|
synthesizeCancelationEventsForAllConnectionsLocked(
|
|
|
|
InputState::CANCEL_POINTER_EVENTS, reason);
|
|
|
|
} else {
|
|
|
|
synthesizeCancelationEventsForAllConnectionsLocked(
|
|
|
|
InputState::CANCEL_NON_POINTER_EVENTS, reason);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputDispatcher::isAppSwitchKeyCode(int32_t keyCode) {
|
2010-09-08 18:49:43 +00:00
|
|
|
return keyCode == AKEYCODE_HOME || keyCode == AKEYCODE_ENDCALL;
|
|
|
|
}
|
|
|
|
|
2010-10-09 05:31:17 +00:00
|
|
|
bool InputDispatcher::isAppSwitchKeyEventLocked(KeyEntry* keyEntry) {
|
|
|
|
return ! (keyEntry->flags & AKEY_EVENT_FLAG_CANCELED)
|
|
|
|
&& isAppSwitchKeyCode(keyEntry->keyCode)
|
2010-10-11 21:20:19 +00:00
|
|
|
&& (keyEntry->policyFlags & POLICY_FLAG_TRUSTED)
|
2010-10-09 05:31:17 +00:00
|
|
|
&& (keyEntry->policyFlags & POLICY_FLAG_PASS_TO_USER);
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
2010-10-09 05:31:17 +00:00
|
|
|
bool InputDispatcher::isAppSwitchPendingLocked() {
|
|
|
|
return mAppSwitchDueTime != LONG_LONG_MAX;
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::resetPendingAppSwitchLocked(bool handled) {
|
|
|
|
mAppSwitchDueTime = LONG_LONG_MAX;
|
|
|
|
|
|
|
|
#if DEBUG_APP_SWITCH
|
|
|
|
if (handled) {
|
|
|
|
LOGD("App switch has arrived.");
|
|
|
|
} else {
|
|
|
|
LOGD("App switch was abandoned.");
|
|
|
|
}
|
|
|
|
#endif
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
2010-06-15 08:31:58 +00:00
|
|
|
bool InputDispatcher::runCommandsLockedInterruptible() {
|
|
|
|
if (mCommandQueue.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
CommandEntry* commandEntry = mCommandQueue.dequeueAtHead();
|
|
|
|
|
|
|
|
Command command = commandEntry->command;
|
|
|
|
(this->*command)(commandEntry); // commands are implicitly 'LockedInterruptible'
|
|
|
|
|
2010-06-18 03:52:56 +00:00
|
|
|
commandEntry->connection.clear();
|
2010-06-15 08:31:58 +00:00
|
|
|
mAllocator.releaseCommandEntry(commandEntry);
|
|
|
|
} while (! mCommandQueue.isEmpty());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
InputDispatcher::CommandEntry* InputDispatcher::postCommandLocked(Command command) {
|
|
|
|
CommandEntry* commandEntry = mAllocator.obtainCommandEntry(command);
|
|
|
|
mCommandQueue.enqueueAtTail(commandEntry);
|
|
|
|
return commandEntry;
|
|
|
|
}
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
void InputDispatcher::drainInboundQueueLocked() {
|
|
|
|
while (! mInboundQueue.isEmpty()) {
|
|
|
|
EventEntry* entry = mInboundQueue.dequeueAtHead();
|
2010-09-16 21:07:33 +00:00
|
|
|
releaseInboundEventLocked(entry);
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-15 08:31:58 +00:00
|
|
|
|
2010-09-16 21:07:33 +00:00
|
|
|
void InputDispatcher::releasePendingEventLocked() {
|
2010-09-08 18:49:43 +00:00
|
|
|
if (mPendingEvent) {
|
2010-09-16 21:07:33 +00:00
|
|
|
releaseInboundEventLocked(mPendingEvent);
|
2010-09-08 18:49:43 +00:00
|
|
|
mPendingEvent = NULL;
|
|
|
|
}
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
2010-09-16 21:07:33 +00:00
|
|
|
void InputDispatcher::releaseInboundEventLocked(EventEntry* entry) {
|
2010-09-27 05:20:12 +00:00
|
|
|
InjectionState* injectionState = entry->injectionState;
|
|
|
|
if (injectionState && injectionState->injectionResult == INPUT_EVENT_INJECTION_PENDING) {
|
2010-09-08 18:49:43 +00:00
|
|
|
#if DEBUG_DISPATCH_CYCLE
|
2010-09-27 05:20:12 +00:00
|
|
|
LOGD("Injected inbound event was dropped.");
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
#endif
|
2010-09-08 18:49:43 +00:00
|
|
|
setInjectionResultLocked(entry, INPUT_EVENT_INJECTION_FAILED);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
mAllocator.releaseEventEntry(entry);
|
|
|
|
}
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
void InputDispatcher::resetKeyRepeatLocked() {
|
|
|
|
if (mKeyRepeatState.lastKeyEntry) {
|
|
|
|
mAllocator.releaseKeyEntry(mKeyRepeatState.lastKeyEntry);
|
|
|
|
mKeyRepeatState.lastKeyEntry = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InputDispatcher::KeyEntry* InputDispatcher::synthesizeKeyRepeatLocked(
|
2010-09-07 17:44:57 +00:00
|
|
|
nsecs_t currentTime, nsecs_t keyRepeatDelay) {
|
2010-06-22 08:27:15 +00:00
|
|
|
KeyEntry* entry = mKeyRepeatState.lastKeyEntry;
|
|
|
|
|
|
|
|
// Reuse the repeated key entry if it is otherwise unreferenced.
|
2010-10-11 21:20:19 +00:00
|
|
|
uint32_t policyFlags = (entry->policyFlags & POLICY_FLAG_RAW_MASK)
|
|
|
|
| POLICY_FLAG_PASS_TO_USER | POLICY_FLAG_TRUSTED;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
if (entry->refCount == 1) {
|
2010-09-27 05:20:12 +00:00
|
|
|
mAllocator.recycleKeyEntry(entry);
|
2010-06-18 03:52:56 +00:00
|
|
|
entry->eventTime = currentTime;
|
|
|
|
entry->policyFlags = policyFlags;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
entry->repeatCount += 1;
|
|
|
|
} else {
|
2010-06-18 03:52:56 +00:00
|
|
|
KeyEntry* newEntry = mAllocator.obtainKeyEntry(currentTime,
|
2010-07-15 01:48:53 +00:00
|
|
|
entry->deviceId, entry->source, policyFlags,
|
2010-06-18 03:52:56 +00:00
|
|
|
entry->action, entry->flags, entry->keyCode, entry->scanCode,
|
2010-07-02 22:37:36 +00:00
|
|
|
entry->metaState, entry->repeatCount + 1, entry->downTime);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
|
|
|
mKeyRepeatState.lastKeyEntry = newEntry;
|
|
|
|
mAllocator.releaseKeyEntry(entry);
|
|
|
|
|
|
|
|
entry = newEntry;
|
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
entry->syntheticRepeat = true;
|
|
|
|
|
|
|
|
// Increment reference count since we keep a reference to the event in
|
|
|
|
// mKeyRepeatState.lastKeyEntry in addition to the one we return.
|
|
|
|
entry->refCount += 1;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-07-02 22:37:36 +00:00
|
|
|
if (entry->repeatCount == 1) {
|
2010-07-15 01:48:53 +00:00
|
|
|
entry->flags |= AKEY_EVENT_FLAG_LONG_PRESS;
|
2010-07-02 22:37:36 +00:00
|
|
|
}
|
|
|
|
|
2010-09-07 17:44:57 +00:00
|
|
|
mKeyRepeatState.nextRepeatTime = currentTime + keyRepeatDelay;
|
2010-09-08 18:49:43 +00:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputDispatcher::dispatchConfigurationChangedLocked(
|
|
|
|
nsecs_t currentTime, ConfigurationChangedEntry* entry) {
|
|
|
|
#if DEBUG_OUTBOUND_EVENT_DETAILS
|
|
|
|
LOGD("dispatchConfigurationChanged - eventTime=%lld", entry->eventTime);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Reset key repeating in case a keyboard device was added or removed or something.
|
|
|
|
resetKeyRepeatLocked();
|
|
|
|
|
|
|
|
// Enqueue a command to run outside the lock to tell the policy that the configuration changed.
|
|
|
|
CommandEntry* commandEntry = postCommandLocked(
|
|
|
|
& InputDispatcher::doNotifyConfigurationChangedInterruptible);
|
|
|
|
commandEntry->eventTime = entry->eventTime;
|
|
|
|
return true;
|
|
|
|
}
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
bool InputDispatcher::dispatchKeyLocked(
|
|
|
|
nsecs_t currentTime, KeyEntry* entry, nsecs_t keyRepeatTimeout,
|
2010-10-11 21:20:19 +00:00
|
|
|
DropReason* dropReason, nsecs_t* nextWakeupTime) {
|
2010-09-08 18:49:43 +00:00
|
|
|
// Preprocessing.
|
|
|
|
if (! entry->dispatchInProgress) {
|
|
|
|
if (entry->repeatCount == 0
|
|
|
|
&& entry->action == AKEY_EVENT_ACTION_DOWN
|
2010-10-11 21:20:19 +00:00
|
|
|
&& (entry->policyFlags & POLICY_FLAG_TRUSTED)
|
|
|
|
&& !entry->isInjected()) {
|
2010-09-08 18:49:43 +00:00
|
|
|
if (mKeyRepeatState.lastKeyEntry
|
|
|
|
&& mKeyRepeatState.lastKeyEntry->keyCode == entry->keyCode) {
|
|
|
|
// We have seen two identical key downs in a row which indicates that the device
|
|
|
|
// driver is automatically generating key repeats itself. We take note of the
|
|
|
|
// repeat here, but we disable our own next key repeat timer since it is clear that
|
|
|
|
// we will not need to synthesize key repeats ourselves.
|
|
|
|
entry->repeatCount = mKeyRepeatState.lastKeyEntry->repeatCount + 1;
|
|
|
|
resetKeyRepeatLocked();
|
|
|
|
mKeyRepeatState.nextRepeatTime = LONG_LONG_MAX; // don't generate repeats ourselves
|
|
|
|
} else {
|
|
|
|
// Not a repeat. Save key down state in case we do see a repeat later.
|
|
|
|
resetKeyRepeatLocked();
|
|
|
|
mKeyRepeatState.nextRepeatTime = entry->eventTime + keyRepeatTimeout;
|
|
|
|
}
|
|
|
|
mKeyRepeatState.lastKeyEntry = entry;
|
|
|
|
entry->refCount += 1;
|
|
|
|
} else if (! entry->syntheticRepeat) {
|
|
|
|
resetKeyRepeatLocked();
|
|
|
|
}
|
|
|
|
|
|
|
|
entry->dispatchInProgress = true;
|
2010-09-16 21:07:33 +00:00
|
|
|
resetTargetsLocked();
|
2010-11-03 00:58:22 +00:00
|
|
|
|
|
|
|
logOutboundKeyDetailsLocked("dispatchKey - ", entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Give the policy a chance to intercept the key.
|
|
|
|
if (entry->interceptKeyResult == KeyEntry::INTERCEPT_KEY_RESULT_UNKNOWN) {
|
|
|
|
if (entry->policyFlags & POLICY_FLAG_PASS_TO_USER) {
|
|
|
|
CommandEntry* commandEntry = postCommandLocked(
|
|
|
|
& InputDispatcher::doInterceptKeyBeforeDispatchingLockedInterruptible);
|
|
|
|
if (mFocusedWindow) {
|
|
|
|
commandEntry->inputChannel = mFocusedWindow->inputChannel;
|
|
|
|
}
|
|
|
|
commandEntry->keyEntry = entry;
|
|
|
|
entry->refCount += 1;
|
|
|
|
return false; // wait for the command to run
|
|
|
|
} else {
|
|
|
|
entry->interceptKeyResult = KeyEntry::INTERCEPT_KEY_RESULT_CONTINUE;
|
|
|
|
}
|
|
|
|
} else if (entry->interceptKeyResult == KeyEntry::INTERCEPT_KEY_RESULT_SKIP) {
|
|
|
|
if (*dropReason == DROP_REASON_NOT_DROPPED) {
|
|
|
|
*dropReason = DROP_REASON_POLICY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up if dropping the event.
|
|
|
|
if (*dropReason != DROP_REASON_NOT_DROPPED) {
|
|
|
|
resetTargetsLocked();
|
|
|
|
setInjectionResultLocked(entry, *dropReason == DROP_REASON_POLICY
|
|
|
|
? INPUT_EVENT_INJECTION_SUCCEEDED : INPUT_EVENT_INJECTION_FAILED);
|
|
|
|
return true;
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Identify targets.
|
|
|
|
if (! mCurrentInputTargetsValid) {
|
2010-09-27 05:20:12 +00:00
|
|
|
int32_t injectionResult = findFocusedWindowTargetsLocked(currentTime,
|
|
|
|
entry, nextWakeupTime);
|
2010-09-08 18:49:43 +00:00
|
|
|
if (injectionResult == INPUT_EVENT_INJECTION_PENDING) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
setInjectionResultLocked(entry, injectionResult);
|
|
|
|
if (injectionResult != INPUT_EVENT_INJECTION_SUCCEEDED) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
addMonitoringTargetsLocked();
|
2010-09-27 05:20:12 +00:00
|
|
|
commitTargetsLocked();
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Dispatch the key.
|
|
|
|
dispatchEventToCurrentInputTargetsLocked(currentTime, entry, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::logOutboundKeyDetailsLocked(const char* prefix, const KeyEntry* entry) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
#if DEBUG_OUTBOUND_EVENT_DETAILS
|
2010-09-08 18:49:43 +00:00
|
|
|
LOGD("%seventTime=%lld, deviceId=0x%x, source=0x%x, policyFlags=0x%x, "
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
"action=0x%x, flags=0x%x, keyCode=0x%x, scanCode=0x%x, metaState=0x%x, "
|
2010-11-03 00:58:22 +00:00
|
|
|
"repeatCount=%d, downTime=%lld",
|
2010-09-08 18:49:43 +00:00
|
|
|
prefix,
|
2010-07-15 01:48:53 +00:00
|
|
|
entry->eventTime, entry->deviceId, entry->source, entry->policyFlags,
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
entry->action, entry->flags, entry->keyCode, entry->scanCode, entry->metaState,
|
2010-11-03 00:58:22 +00:00
|
|
|
entry->repeatCount, entry->downTime);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
#endif
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool InputDispatcher::dispatchMotionLocked(
|
2010-10-11 21:20:19 +00:00
|
|
|
nsecs_t currentTime, MotionEntry* entry, DropReason* dropReason, nsecs_t* nextWakeupTime) {
|
2010-11-03 00:58:22 +00:00
|
|
|
// Preprocessing.
|
|
|
|
if (! entry->dispatchInProgress) {
|
|
|
|
entry->dispatchInProgress = true;
|
|
|
|
resetTargetsLocked();
|
|
|
|
|
|
|
|
logOutboundMotionDetailsLocked("dispatchMotion - ", entry);
|
|
|
|
}
|
|
|
|
|
2010-09-16 21:07:33 +00:00
|
|
|
// Clean up if dropping the event.
|
2010-10-11 21:20:19 +00:00
|
|
|
if (*dropReason != DROP_REASON_NOT_DROPPED) {
|
2010-09-16 21:07:33 +00:00
|
|
|
resetTargetsLocked();
|
2010-10-12 06:32:49 +00:00
|
|
|
setInjectionResultLocked(entry, *dropReason == DROP_REASON_POLICY
|
|
|
|
? INPUT_EVENT_INJECTION_SUCCEEDED : INPUT_EVENT_INJECTION_FAILED);
|
2010-09-16 21:07:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
bool isPointerEvent = entry->source & AINPUT_SOURCE_CLASS_POINTER;
|
|
|
|
|
|
|
|
// Identify targets.
|
|
|
|
if (! mCurrentInputTargetsValid) {
|
|
|
|
int32_t injectionResult;
|
|
|
|
if (isPointerEvent) {
|
|
|
|
// Pointer event. (eg. touchscreen)
|
2010-09-27 05:20:12 +00:00
|
|
|
injectionResult = findTouchedWindowTargetsLocked(currentTime,
|
|
|
|
entry, nextWakeupTime);
|
2010-09-08 18:49:43 +00:00
|
|
|
} else {
|
|
|
|
// Non touch event. (eg. trackball)
|
2010-09-27 05:20:12 +00:00
|
|
|
injectionResult = findFocusedWindowTargetsLocked(currentTime,
|
|
|
|
entry, nextWakeupTime);
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
if (injectionResult == INPUT_EVENT_INJECTION_PENDING) {
|
|
|
|
return false;
|
|
|
|
}
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
setInjectionResultLocked(entry, injectionResult);
|
|
|
|
if (injectionResult != INPUT_EVENT_INJECTION_SUCCEEDED) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
addMonitoringTargetsLocked();
|
2010-09-27 05:20:12 +00:00
|
|
|
commitTargetsLocked();
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Dispatch the motion.
|
|
|
|
dispatchEventToCurrentInputTargetsLocked(currentTime, entry, false);
|
|
|
|
return true;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
|
|
|
|
void InputDispatcher::logOutboundMotionDetailsLocked(const char* prefix, const MotionEntry* entry) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
#if DEBUG_OUTBOUND_EVENT_DETAILS
|
2010-09-08 18:49:43 +00:00
|
|
|
LOGD("%seventTime=%lld, deviceId=0x%x, source=0x%x, policyFlags=0x%x, "
|
2010-09-02 00:01:00 +00:00
|
|
|
"action=0x%x, flags=0x%x, "
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
"metaState=0x%x, edgeFlags=0x%x, xPrecision=%f, yPrecision=%f, downTime=%lld",
|
2010-09-08 18:49:43 +00:00
|
|
|
prefix,
|
2010-09-02 00:01:00 +00:00
|
|
|
entry->eventTime, entry->deviceId, entry->source, entry->policyFlags,
|
|
|
|
entry->action, entry->flags,
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
entry->metaState, entry->edgeFlags, entry->xPrecision, entry->yPrecision,
|
|
|
|
entry->downTime);
|
|
|
|
|
|
|
|
// Print the most recent sample that we have available, this may change due to batching.
|
|
|
|
size_t sampleCount = 1;
|
2010-09-08 18:49:43 +00:00
|
|
|
const MotionSample* sample = & entry->firstSample;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
for (; sample->next != NULL; sample = sample->next) {
|
|
|
|
sampleCount += 1;
|
|
|
|
}
|
|
|
|
for (uint32_t i = 0; i < entry->pointerCount; i++) {
|
2010-08-30 10:02:23 +00:00
|
|
|
LOGD(" Pointer %d: id=%d, x=%f, y=%f, pressure=%f, size=%f, "
|
2010-09-02 00:01:00 +00:00
|
|
|
"touchMajor=%f, touchMinor=%f, toolMajor=%f, toolMinor=%f, "
|
2010-08-30 10:02:23 +00:00
|
|
|
"orientation=%f",
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
i, entry->pointerIds[i],
|
2010-08-30 10:02:23 +00:00
|
|
|
sample->pointerCoords[i].x, sample->pointerCoords[i].y,
|
|
|
|
sample->pointerCoords[i].pressure, sample->pointerCoords[i].size,
|
|
|
|
sample->pointerCoords[i].touchMajor, sample->pointerCoords[i].touchMinor,
|
|
|
|
sample->pointerCoords[i].toolMajor, sample->pointerCoords[i].toolMinor,
|
|
|
|
sample->pointerCoords[i].orientation);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Keep in mind that due to batching, it is possible for the number of samples actually
|
|
|
|
// dispatched to change before the application finally consumed them.
|
2010-07-15 01:48:53 +00:00
|
|
|
if (entry->action == AMOTION_EVENT_ACTION_MOVE) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
LOGD(" ... Total movement samples currently batched %d ...", sampleCount);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
void InputDispatcher::dispatchEventToCurrentInputTargetsLocked(nsecs_t currentTime,
|
|
|
|
EventEntry* eventEntry, bool resumeWithAppendedMotionSample) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
#if DEBUG_DISPATCH_CYCLE
|
2010-09-08 18:49:43 +00:00
|
|
|
LOGD("dispatchEventToCurrentInputTargets - "
|
|
|
|
"resumeWithAppendedMotionSample=%s",
|
|
|
|
toString(resumeWithAppendedMotionSample));
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
#endif
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
assert(eventEntry->dispatchInProgress); // should already have been set to true
|
2010-06-15 08:31:58 +00:00
|
|
|
|
2010-10-18 20:21:23 +00:00
|
|
|
pokeUserActivityLocked(eventEntry);
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
for (size_t i = 0; i < mCurrentInputTargets.size(); i++) {
|
|
|
|
const InputTarget& inputTarget = mCurrentInputTargets.itemAt(i);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-15 22:18:56 +00:00
|
|
|
ssize_t connectionIndex = getConnectionIndexLocked(inputTarget.inputChannel);
|
2010-09-08 18:49:43 +00:00
|
|
|
if (connectionIndex >= 0) {
|
|
|
|
sp<Connection> connection = mConnectionsByReceiveFd.valueAt(connectionIndex);
|
|
|
|
prepareDispatchCycleLocked(currentTime, connection, eventEntry, & inputTarget,
|
|
|
|
resumeWithAppendedMotionSample);
|
|
|
|
} else {
|
2010-10-09 05:31:17 +00:00
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("Dropping event delivery to target with channel '%s' because it "
|
|
|
|
"is no longer registered with the input dispatcher.",
|
2010-09-08 18:49:43 +00:00
|
|
|
inputTarget.inputChannel->getName().string());
|
2010-10-09 05:31:17 +00:00
|
|
|
#endif
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-16 21:07:33 +00:00
|
|
|
void InputDispatcher::resetTargetsLocked() {
|
2010-09-08 18:49:43 +00:00
|
|
|
mCurrentInputTargetsValid = false;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
mCurrentInputTargets.clear();
|
2010-09-08 18:49:43 +00:00
|
|
|
mInputTargetWaitCause = INPUT_TARGET_WAIT_CAUSE_NONE;
|
|
|
|
}
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
void InputDispatcher::commitTargetsLocked() {
|
2010-06-15 08:31:58 +00:00
|
|
|
mCurrentInputTargetsValid = true;
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t InputDispatcher::handleTargetsNotReadyLocked(nsecs_t currentTime,
|
|
|
|
const EventEntry* entry, const InputApplication* application, const InputWindow* window,
|
|
|
|
nsecs_t* nextWakeupTime) {
|
|
|
|
if (application == NULL && window == NULL) {
|
|
|
|
if (mInputTargetWaitCause != INPUT_TARGET_WAIT_CAUSE_SYSTEM_NOT_READY) {
|
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("Waiting for system to become ready for input.");
|
|
|
|
#endif
|
|
|
|
mInputTargetWaitCause = INPUT_TARGET_WAIT_CAUSE_SYSTEM_NOT_READY;
|
|
|
|
mInputTargetWaitStartTime = currentTime;
|
|
|
|
mInputTargetWaitTimeoutTime = LONG_LONG_MAX;
|
|
|
|
mInputTargetWaitTimeoutExpired = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (mInputTargetWaitCause != INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY) {
|
|
|
|
#if DEBUG_FOCUS
|
2010-09-15 22:18:56 +00:00
|
|
|
LOGD("Waiting for application to become ready for input: %s",
|
|
|
|
getApplicationWindowLabelLocked(application, window).string());
|
2010-09-08 18:49:43 +00:00
|
|
|
#endif
|
|
|
|
nsecs_t timeout = window ? window->dispatchingTimeout :
|
|
|
|
application ? application->dispatchingTimeout : DEFAULT_INPUT_DISPATCHING_TIMEOUT;
|
|
|
|
|
|
|
|
mInputTargetWaitCause = INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY;
|
|
|
|
mInputTargetWaitStartTime = currentTime;
|
|
|
|
mInputTargetWaitTimeoutTime = currentTime + timeout;
|
|
|
|
mInputTargetWaitTimeoutExpired = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mInputTargetWaitTimeoutExpired) {
|
|
|
|
return INPUT_EVENT_INJECTION_TIMED_OUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentTime >= mInputTargetWaitTimeoutTime) {
|
2010-09-15 22:18:56 +00:00
|
|
|
onANRLocked(currentTime, application, window, entry->eventTime, mInputTargetWaitStartTime);
|
2010-06-15 08:31:58 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
// Force poll loop to wake up immediately on next iteration once we get the
|
|
|
|
// ANR response back from the policy.
|
|
|
|
*nextWakeupTime = LONG_LONG_MIN;
|
|
|
|
return INPUT_EVENT_INJECTION_PENDING;
|
|
|
|
} else {
|
|
|
|
// Force poll loop to wake up when timeout is due.
|
|
|
|
if (mInputTargetWaitTimeoutTime < *nextWakeupTime) {
|
|
|
|
*nextWakeupTime = mInputTargetWaitTimeoutTime;
|
|
|
|
}
|
|
|
|
return INPUT_EVENT_INJECTION_PENDING;
|
|
|
|
}
|
|
|
|
}
|
2010-06-18 03:52:56 +00:00
|
|
|
|
2010-09-15 22:18:56 +00:00
|
|
|
void InputDispatcher::resumeAfterTargetsNotReadyTimeoutLocked(nsecs_t newTimeout,
|
|
|
|
const sp<InputChannel>& inputChannel) {
|
2010-09-08 18:49:43 +00:00
|
|
|
if (newTimeout > 0) {
|
|
|
|
// Extend the timeout.
|
|
|
|
mInputTargetWaitTimeoutTime = now() + newTimeout;
|
|
|
|
} else {
|
|
|
|
// Give up.
|
|
|
|
mInputTargetWaitTimeoutExpired = true;
|
2010-09-15 22:18:56 +00:00
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
// Release the touch targets.
|
|
|
|
mTouchState.reset();
|
2010-09-16 19:31:46 +00:00
|
|
|
|
2010-09-15 22:18:56 +00:00
|
|
|
// Input state will not be realistic. Mark it out of sync.
|
2010-09-16 18:02:16 +00:00
|
|
|
if (inputChannel.get()) {
|
|
|
|
ssize_t connectionIndex = getConnectionIndexLocked(inputChannel);
|
|
|
|
if (connectionIndex >= 0) {
|
|
|
|
sp<Connection> connection = mConnectionsByReceiveFd.valueAt(connectionIndex);
|
2010-10-09 05:31:17 +00:00
|
|
|
synthesizeCancelationEventsForConnectionLocked(
|
|
|
|
connection, InputState::CANCEL_ALL_EVENTS,
|
|
|
|
"application not responding");
|
2010-09-16 18:02:16 +00:00
|
|
|
}
|
2010-09-15 22:18:56 +00:00
|
|
|
}
|
2010-06-22 08:27:15 +00:00
|
|
|
}
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
2010-09-15 22:18:56 +00:00
|
|
|
nsecs_t InputDispatcher::getTimeSpentWaitingForApplicationLocked(
|
2010-09-08 18:49:43 +00:00
|
|
|
nsecs_t currentTime) {
|
|
|
|
if (mInputTargetWaitCause == INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY) {
|
|
|
|
return currentTime - mInputTargetWaitStartTime;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::resetANRTimeoutsLocked() {
|
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("Resetting ANR timeouts.");
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
#endif
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
// Reset input target wait timeout.
|
|
|
|
mInputTargetWaitCause = INPUT_TARGET_WAIT_CAUSE_NONE;
|
|
|
|
}
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
int32_t InputDispatcher::findFocusedWindowTargetsLocked(nsecs_t currentTime,
|
|
|
|
const EventEntry* entry, nsecs_t* nextWakeupTime) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
mCurrentInputTargets.clear();
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
int32_t injectionResult;
|
2010-06-15 08:31:58 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
// If there is no currently focused window and no focused application
|
|
|
|
// then drop the event.
|
|
|
|
if (! mFocusedWindow) {
|
|
|
|
if (mFocusedApplication) {
|
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("Waiting because there is no focused window but there is a "
|
2010-09-15 22:18:56 +00:00
|
|
|
"focused application that may eventually add a window: %s.",
|
|
|
|
getApplicationWindowLabelLocked(mFocusedApplication, NULL).string());
|
2010-09-08 18:49:43 +00:00
|
|
|
#endif
|
|
|
|
injectionResult = handleTargetsNotReadyLocked(currentTime, entry,
|
|
|
|
mFocusedApplication, NULL, nextWakeupTime);
|
|
|
|
goto Unresponsive;
|
|
|
|
}
|
2010-06-18 03:52:56 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
LOGI("Dropping event because there is no focused window or focused application.");
|
|
|
|
injectionResult = INPUT_EVENT_INJECTION_FAILED;
|
|
|
|
goto Failed;
|
2010-06-22 08:27:15 +00:00
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
|
|
|
|
// Check permissions.
|
2010-09-27 05:20:12 +00:00
|
|
|
if (! checkInjectionPermission(mFocusedWindow, entry->injectionState)) {
|
2010-09-08 18:49:43 +00:00
|
|
|
injectionResult = INPUT_EVENT_INJECTION_PERMISSION_DENIED;
|
|
|
|
goto Failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the currently focused window is paused then keep waiting.
|
|
|
|
if (mFocusedWindow->paused) {
|
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("Waiting because focused window is paused.");
|
|
|
|
#endif
|
|
|
|
injectionResult = handleTargetsNotReadyLocked(currentTime, entry,
|
|
|
|
mFocusedApplication, mFocusedWindow, nextWakeupTime);
|
|
|
|
goto Unresponsive;
|
|
|
|
}
|
|
|
|
|
2010-09-15 22:18:56 +00:00
|
|
|
// If the currently focused window is still working on previous events then keep waiting.
|
|
|
|
if (! isWindowFinishedWithPreviousInputLocked(mFocusedWindow)) {
|
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("Waiting because focused window still processing previous input.");
|
|
|
|
#endif
|
|
|
|
injectionResult = handleTargetsNotReadyLocked(currentTime, entry,
|
|
|
|
mFocusedApplication, mFocusedWindow, nextWakeupTime);
|
|
|
|
goto Unresponsive;
|
|
|
|
}
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
// Success! Output targets.
|
|
|
|
injectionResult = INPUT_EVENT_INJECTION_SUCCEEDED;
|
2010-09-27 05:20:12 +00:00
|
|
|
addWindowTargetLocked(mFocusedWindow, InputTarget::FLAG_FOREGROUND, BitSet32(0));
|
2010-09-08 18:49:43 +00:00
|
|
|
|
|
|
|
// Done.
|
|
|
|
Failed:
|
|
|
|
Unresponsive:
|
2010-09-15 22:18:56 +00:00
|
|
|
nsecs_t timeSpentWaitingForApplication = getTimeSpentWaitingForApplicationLocked(currentTime);
|
|
|
|
updateDispatchStatisticsLocked(currentTime, entry,
|
|
|
|
injectionResult, timeSpentWaitingForApplication);
|
2010-09-08 18:49:43 +00:00
|
|
|
#if DEBUG_FOCUS
|
2010-09-15 22:18:56 +00:00
|
|
|
LOGD("findFocusedWindow finished: injectionResult=%d, "
|
|
|
|
"timeSpendWaitingForApplication=%0.1fms",
|
|
|
|
injectionResult, timeSpentWaitingForApplication / 1000000.0);
|
2010-09-08 18:49:43 +00:00
|
|
|
#endif
|
|
|
|
return injectionResult;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
int32_t InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime,
|
|
|
|
const MotionEntry* entry, nsecs_t* nextWakeupTime) {
|
2010-09-08 18:49:43 +00:00
|
|
|
enum InjectionPermission {
|
|
|
|
INJECTION_PERMISSION_UNKNOWN,
|
|
|
|
INJECTION_PERMISSION_GRANTED,
|
|
|
|
INJECTION_PERMISSION_DENIED
|
|
|
|
};
|
|
|
|
|
|
|
|
mCurrentInputTargets.clear();
|
|
|
|
|
|
|
|
nsecs_t startTime = now();
|
|
|
|
|
|
|
|
// For security reasons, we defer updating the touch state until we are sure that
|
|
|
|
// event injection will be allowed.
|
|
|
|
//
|
|
|
|
// FIXME In the original code, screenWasOff could never be set to true.
|
|
|
|
// The reason is that the POLICY_FLAG_WOKE_HERE
|
|
|
|
// and POLICY_FLAG_BRIGHT_HERE flags were set only when preprocessing raw
|
|
|
|
// EV_KEY, EV_REL and EV_ABS events. As it happens, the touch event was
|
|
|
|
// actually enqueued using the policyFlags that appeared in the final EV_SYN
|
|
|
|
// events upon which no preprocessing took place. So policyFlags was always 0.
|
|
|
|
// In the new native input dispatcher we're a bit more careful about event
|
|
|
|
// preprocessing so the touches we receive can actually have non-zero policyFlags.
|
|
|
|
// Unfortunately we obtain undesirable behavior.
|
|
|
|
//
|
|
|
|
// Here's what happens:
|
|
|
|
//
|
|
|
|
// When the device dims in anticipation of going to sleep, touches
|
|
|
|
// in windows which have FLAG_TOUCHABLE_WHEN_WAKING cause
|
|
|
|
// the device to brighten and reset the user activity timer.
|
|
|
|
// Touches on other windows (such as the launcher window)
|
|
|
|
// are dropped. Then after a moment, the device goes to sleep. Oops.
|
|
|
|
//
|
|
|
|
// Also notice how screenWasOff was being initialized using POLICY_FLAG_BRIGHT_HERE
|
|
|
|
// instead of POLICY_FLAG_WOKE_HERE...
|
|
|
|
//
|
|
|
|
bool screenWasOff = false; // original policy: policyFlags & POLICY_FLAG_BRIGHT_HERE;
|
|
|
|
|
|
|
|
int32_t action = entry->action;
|
2010-09-27 05:20:12 +00:00
|
|
|
int32_t maskedAction = action & AMOTION_EVENT_ACTION_MASK;
|
2010-09-08 18:49:43 +00:00
|
|
|
|
|
|
|
// Update the touch state as needed based on the properties of the touch event.
|
2010-09-27 05:20:12 +00:00
|
|
|
int32_t injectionResult = INPUT_EVENT_INJECTION_PENDING;
|
|
|
|
InjectionPermission injectionPermission = INJECTION_PERMISSION_UNKNOWN;
|
|
|
|
if (maskedAction == AMOTION_EVENT_ACTION_DOWN) {
|
|
|
|
mTempTouchState.reset();
|
|
|
|
mTempTouchState.down = true;
|
|
|
|
} else {
|
|
|
|
mTempTouchState.copyFrom(mTouchState);
|
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
bool isSplit = mTempTouchState.split && mTempTouchState.down;
|
|
|
|
if (maskedAction == AMOTION_EVENT_ACTION_DOWN
|
|
|
|
|| (isSplit && maskedAction == AMOTION_EVENT_ACTION_POINTER_DOWN)) {
|
|
|
|
/* Case 1: New splittable pointer going down. */
|
2010-09-08 18:49:43 +00:00
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
int32_t pointerIndex = getMotionEventActionPointerIndex(action);
|
|
|
|
int32_t x = int32_t(entry->firstSample.pointerCoords[pointerIndex].x);
|
|
|
|
int32_t y = int32_t(entry->firstSample.pointerCoords[pointerIndex].y);
|
|
|
|
const InputWindow* newTouchedWindow = NULL;
|
|
|
|
const InputWindow* topErrorWindow = NULL;
|
2010-09-08 18:49:43 +00:00
|
|
|
|
|
|
|
// Traverse windows from front to back to find touched window and outside targets.
|
|
|
|
size_t numWindows = mWindows.size();
|
|
|
|
for (size_t i = 0; i < numWindows; i++) {
|
2010-09-27 05:20:12 +00:00
|
|
|
const InputWindow* window = & mWindows.editItemAt(i);
|
2010-09-08 18:49:43 +00:00
|
|
|
int32_t flags = window->layoutParamsFlags;
|
|
|
|
|
|
|
|
if (flags & InputWindow::FLAG_SYSTEM_ERROR) {
|
|
|
|
if (! topErrorWindow) {
|
|
|
|
topErrorWindow = window;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->visible) {
|
|
|
|
if (! (flags & InputWindow::FLAG_NOT_TOUCHABLE)) {
|
|
|
|
bool isTouchModal = (flags & (InputWindow::FLAG_NOT_FOCUSABLE
|
|
|
|
| InputWindow::FLAG_NOT_TOUCH_MODAL)) == 0;
|
|
|
|
if (isTouchModal || window->touchableAreaContainsPoint(x, y)) {
|
|
|
|
if (! screenWasOff || flags & InputWindow::FLAG_TOUCHABLE_WHEN_WAKING) {
|
|
|
|
newTouchedWindow = window;
|
|
|
|
}
|
|
|
|
break; // found touched window, exit window loop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
if (maskedAction == AMOTION_EVENT_ACTION_DOWN
|
|
|
|
&& (flags & InputWindow::FLAG_WATCH_OUTSIDE_TOUCH)) {
|
2010-10-05 19:26:23 +00:00
|
|
|
int32_t outsideTargetFlags = InputTarget::FLAG_OUTSIDE;
|
|
|
|
if (isWindowObscuredAtPointLocked(window, x, y)) {
|
|
|
|
outsideTargetFlags |= InputTarget::FLAG_WINDOW_IS_OBSCURED;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTempTouchState.addOrUpdateWindow(window, outsideTargetFlags, BitSet32(0));
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is an error window but it is not taking focus (typically because
|
|
|
|
// it is invisible) then wait for it. Any other focused window may in
|
|
|
|
// fact be in ANR state.
|
|
|
|
if (topErrorWindow && newTouchedWindow != topErrorWindow) {
|
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("Waiting because system error window is pending.");
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
#endif
|
2010-09-08 18:49:43 +00:00
|
|
|
injectionResult = handleTargetsNotReadyLocked(currentTime, entry,
|
|
|
|
NULL, NULL, nextWakeupTime);
|
|
|
|
injectionPermission = INJECTION_PERMISSION_UNKNOWN;
|
|
|
|
goto Unresponsive;
|
|
|
|
}
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
// Figure out whether splitting will be allowed for this window.
|
2010-09-28 20:24:41 +00:00
|
|
|
if (newTouchedWindow
|
|
|
|
&& (newTouchedWindow->layoutParamsFlags & InputWindow::FLAG_SPLIT_TOUCH)) {
|
2010-09-27 05:20:12 +00:00
|
|
|
// New window supports splitting.
|
|
|
|
isSplit = true;
|
|
|
|
} else if (isSplit) {
|
|
|
|
// New window does not support splitting but we have already split events.
|
|
|
|
// Assign the pointer to the first foreground window we find.
|
|
|
|
// (May be NULL which is why we put this code block before the next check.)
|
|
|
|
newTouchedWindow = mTempTouchState.getFirstForegroundWindow();
|
|
|
|
}
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
// If we did not find a touched window then fail.
|
|
|
|
if (! newTouchedWindow) {
|
|
|
|
if (mFocusedApplication) {
|
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("Waiting because there is no touched window but there is a "
|
2010-09-15 22:18:56 +00:00
|
|
|
"focused application that may eventually add a new window: %s.",
|
|
|
|
getApplicationWindowLabelLocked(mFocusedApplication, NULL).string());
|
2010-09-08 18:49:43 +00:00
|
|
|
#endif
|
|
|
|
injectionResult = handleTargetsNotReadyLocked(currentTime, entry,
|
|
|
|
mFocusedApplication, NULL, nextWakeupTime);
|
|
|
|
goto Unresponsive;
|
|
|
|
}
|
2010-06-15 08:31:58 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
LOGI("Dropping event because there is no touched window or focused application.");
|
|
|
|
injectionResult = INPUT_EVENT_INJECTION_FAILED;
|
|
|
|
goto Failed;
|
|
|
|
}
|
|
|
|
|
2010-10-05 19:26:23 +00:00
|
|
|
// Set target flags.
|
|
|
|
int32_t targetFlags = InputTarget::FLAG_FOREGROUND;
|
|
|
|
if (isSplit) {
|
|
|
|
targetFlags |= InputTarget::FLAG_SPLIT;
|
|
|
|
}
|
|
|
|
if (isWindowObscuredAtPointLocked(newTouchedWindow, x, y)) {
|
|
|
|
targetFlags |= InputTarget::FLAG_WINDOW_IS_OBSCURED;
|
|
|
|
}
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
// Update the temporary touch state.
|
|
|
|
BitSet32 pointerIds;
|
|
|
|
if (isSplit) {
|
|
|
|
uint32_t pointerId = entry->pointerIds[pointerIndex];
|
|
|
|
pointerIds.markBit(pointerId);
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
2010-09-27 05:20:12 +00:00
|
|
|
mTempTouchState.addOrUpdateWindow(newTouchedWindow, targetFlags, pointerIds);
|
2010-09-08 18:49:43 +00:00
|
|
|
} else {
|
2010-09-27 05:20:12 +00:00
|
|
|
/* Case 2: Pointer move, up, cancel or non-splittable pointer down. */
|
2010-09-08 18:49:43 +00:00
|
|
|
|
|
|
|
// If the pointer is not currently down, then ignore the event.
|
2010-09-27 05:20:12 +00:00
|
|
|
if (! mTempTouchState.down) {
|
2010-10-26 00:37:46 +00:00
|
|
|
#if DEBUG_INPUT_DISPATCHER_POLICY
|
|
|
|
LOGD("Dropping event because the pointer is not down or we previously "
|
|
|
|
"dropped the pointer down event.");
|
|
|
|
#endif
|
2010-09-08 18:49:43 +00:00
|
|
|
injectionResult = INPUT_EVENT_INJECTION_FAILED;
|
|
|
|
goto Failed;
|
|
|
|
}
|
2010-09-27 05:20:12 +00:00
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
// Check permission to inject into all touched foreground windows and ensure there
|
|
|
|
// is at least one touched foreground window.
|
|
|
|
{
|
|
|
|
bool haveForegroundWindow = false;
|
|
|
|
for (size_t i = 0; i < mTempTouchState.windows.size(); i++) {
|
|
|
|
const TouchedWindow& touchedWindow = mTempTouchState.windows[i];
|
|
|
|
if (touchedWindow.targetFlags & InputTarget::FLAG_FOREGROUND) {
|
|
|
|
haveForegroundWindow = true;
|
|
|
|
if (! checkInjectionPermission(touchedWindow.window, entry->injectionState)) {
|
|
|
|
injectionResult = INPUT_EVENT_INJECTION_PERMISSION_DENIED;
|
|
|
|
injectionPermission = INJECTION_PERMISSION_DENIED;
|
|
|
|
goto Failed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (! haveForegroundWindow) {
|
2010-09-08 18:49:43 +00:00
|
|
|
#if DEBUG_INPUT_DISPATCHER_POLICY
|
2010-09-27 05:20:12 +00:00
|
|
|
LOGD("Dropping event because there is no touched foreground window to receive it.");
|
2010-09-08 18:49:43 +00:00
|
|
|
#endif
|
|
|
|
injectionResult = INPUT_EVENT_INJECTION_FAILED;
|
|
|
|
goto Failed;
|
|
|
|
}
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
// Permission granted to injection into all touched foreground windows.
|
|
|
|
injectionPermission = INJECTION_PERMISSION_GRANTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure all touched foreground windows are ready for new input.
|
|
|
|
for (size_t i = 0; i < mTempTouchState.windows.size(); i++) {
|
|
|
|
const TouchedWindow& touchedWindow = mTempTouchState.windows[i];
|
|
|
|
if (touchedWindow.targetFlags & InputTarget::FLAG_FOREGROUND) {
|
|
|
|
// If the touched window is paused then keep waiting.
|
|
|
|
if (touchedWindow.window->paused) {
|
2010-09-08 18:49:43 +00:00
|
|
|
#if DEBUG_INPUT_DISPATCHER_POLICY
|
2010-09-27 05:20:12 +00:00
|
|
|
LOGD("Waiting because touched window is paused.");
|
2010-09-15 22:18:56 +00:00
|
|
|
#endif
|
2010-09-27 05:20:12 +00:00
|
|
|
injectionResult = handleTargetsNotReadyLocked(currentTime, entry,
|
|
|
|
NULL, touchedWindow.window, nextWakeupTime);
|
|
|
|
goto Unresponsive;
|
|
|
|
}
|
2010-09-15 22:18:56 +00:00
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
// If the touched window is still working on previous events then keep waiting.
|
|
|
|
if (! isWindowFinishedWithPreviousInputLocked(touchedWindow.window)) {
|
2010-09-15 22:18:56 +00:00
|
|
|
#if DEBUG_FOCUS
|
2010-09-27 05:20:12 +00:00
|
|
|
LOGD("Waiting because touched window still processing previous input.");
|
2010-09-08 18:49:43 +00:00
|
|
|
#endif
|
2010-09-27 05:20:12 +00:00
|
|
|
injectionResult = handleTargetsNotReadyLocked(currentTime, entry,
|
|
|
|
NULL, touchedWindow.window, nextWakeupTime);
|
|
|
|
goto Unresponsive;
|
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
// If this is the first pointer going down and the touched window has a wallpaper
|
|
|
|
// then also add the touched wallpaper windows so they are locked in for the duration
|
|
|
|
// of the touch gesture.
|
|
|
|
if (maskedAction == AMOTION_EVENT_ACTION_DOWN) {
|
|
|
|
const InputWindow* foregroundWindow = mTempTouchState.getFirstForegroundWindow();
|
|
|
|
if (foregroundWindow->hasWallpaper) {
|
|
|
|
for (size_t i = 0; i < mWindows.size(); i++) {
|
|
|
|
const InputWindow* window = & mWindows[i];
|
|
|
|
if (window->layoutParamsType == InputWindow::TYPE_WALLPAPER) {
|
2010-10-05 19:26:23 +00:00
|
|
|
mTempTouchState.addOrUpdateWindow(window,
|
|
|
|
InputTarget::FLAG_WINDOW_IS_OBSCURED, BitSet32(0));
|
2010-09-27 05:20:12 +00:00
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-27 05:20:12 +00:00
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
// Success! Output targets.
|
|
|
|
injectionResult = INPUT_EVENT_INJECTION_SUCCEEDED;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < mTempTouchState.windows.size(); i++) {
|
|
|
|
const TouchedWindow& touchedWindow = mTempTouchState.windows.itemAt(i);
|
|
|
|
addWindowTargetLocked(touchedWindow.window, touchedWindow.targetFlags,
|
|
|
|
touchedWindow.pointerIds);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Drop the outside touch window since we will not care about them in the next iteration.
|
|
|
|
mTempTouchState.removeOutsideTouchWindows();
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
Failed:
|
|
|
|
// Check injection permission once and for all.
|
|
|
|
if (injectionPermission == INJECTION_PERMISSION_UNKNOWN) {
|
2010-09-27 05:20:12 +00:00
|
|
|
if (checkInjectionPermission(NULL, entry->injectionState)) {
|
2010-09-08 18:49:43 +00:00
|
|
|
injectionPermission = INJECTION_PERMISSION_GRANTED;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
} else {
|
2010-09-08 18:49:43 +00:00
|
|
|
injectionPermission = INJECTION_PERMISSION_DENIED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update final pieces of touch state if the injector had permission.
|
|
|
|
if (injectionPermission == INJECTION_PERMISSION_GRANTED) {
|
2010-09-27 05:20:12 +00:00
|
|
|
if (maskedAction == AMOTION_EVENT_ACTION_UP
|
|
|
|
|| maskedAction == AMOTION_EVENT_ACTION_CANCEL) {
|
|
|
|
// All pointers up or canceled.
|
|
|
|
mTempTouchState.reset();
|
|
|
|
} else if (maskedAction == AMOTION_EVENT_ACTION_DOWN) {
|
|
|
|
// First pointer went down.
|
|
|
|
if (mTouchState.down) {
|
2010-10-09 05:31:17 +00:00
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("Pointer down received while already down.");
|
|
|
|
#endif
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
2010-09-27 05:20:12 +00:00
|
|
|
} else if (maskedAction == AMOTION_EVENT_ACTION_POINTER_UP) {
|
|
|
|
// One pointer went up.
|
|
|
|
if (isSplit) {
|
|
|
|
int32_t pointerIndex = getMotionEventActionPointerIndex(action);
|
|
|
|
uint32_t pointerId = entry->pointerIds[pointerIndex];
|
|
|
|
|
|
|
|
for (size_t i = 0; i < mTempTouchState.windows.size(); ) {
|
|
|
|
TouchedWindow& touchedWindow = mTempTouchState.windows.editItemAt(i);
|
|
|
|
if (touchedWindow.targetFlags & InputTarget::FLAG_SPLIT) {
|
|
|
|
touchedWindow.pointerIds.clearBit(pointerId);
|
|
|
|
if (touchedWindow.pointerIds.isEmpty()) {
|
|
|
|
mTempTouchState.windows.removeAt(i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i += 1;
|
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-27 05:20:12 +00:00
|
|
|
|
|
|
|
// Save changes to touch state.
|
|
|
|
mTouchState.copyFrom(mTempTouchState);
|
2010-09-08 18:49:43 +00:00
|
|
|
} else {
|
2010-09-27 05:20:12 +00:00
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("Not updating touch focus because injection was denied.");
|
|
|
|
#endif
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Unresponsive:
|
2010-10-28 01:43:51 +00:00
|
|
|
// Reset temporary touch state to ensure we release unnecessary references to input channels.
|
|
|
|
mTempTouchState.reset();
|
|
|
|
|
2010-09-15 22:18:56 +00:00
|
|
|
nsecs_t timeSpentWaitingForApplication = getTimeSpentWaitingForApplicationLocked(currentTime);
|
|
|
|
updateDispatchStatisticsLocked(currentTime, entry,
|
|
|
|
injectionResult, timeSpentWaitingForApplication);
|
2010-09-08 18:49:43 +00:00
|
|
|
#if DEBUG_FOCUS
|
2010-09-27 05:20:12 +00:00
|
|
|
LOGD("findTouchedWindow finished: injectionResult=%d, injectionPermission=%d, "
|
|
|
|
"timeSpentWaitingForApplication=%0.1fms",
|
2010-09-15 22:18:56 +00:00
|
|
|
injectionResult, injectionPermission, timeSpentWaitingForApplication / 1000000.0);
|
2010-09-08 18:49:43 +00:00
|
|
|
#endif
|
|
|
|
return injectionResult;
|
|
|
|
}
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
void InputDispatcher::addWindowTargetLocked(const InputWindow* window, int32_t targetFlags,
|
|
|
|
BitSet32 pointerIds) {
|
2010-09-08 18:49:43 +00:00
|
|
|
mCurrentInputTargets.push();
|
|
|
|
|
|
|
|
InputTarget& target = mCurrentInputTargets.editTop();
|
|
|
|
target.inputChannel = window->inputChannel;
|
|
|
|
target.flags = targetFlags;
|
|
|
|
target.xOffset = - window->frameLeft;
|
|
|
|
target.yOffset = - window->frameTop;
|
2010-09-27 05:20:12 +00:00
|
|
|
target.pointerIds = pointerIds;
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::addMonitoringTargetsLocked() {
|
|
|
|
for (size_t i = 0; i < mMonitoringChannels.size(); i++) {
|
|
|
|
mCurrentInputTargets.push();
|
|
|
|
|
|
|
|
InputTarget& target = mCurrentInputTargets.editTop();
|
|
|
|
target.inputChannel = mMonitoringChannels[i];
|
|
|
|
target.flags = 0;
|
|
|
|
target.xOffset = 0;
|
|
|
|
target.yOffset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputDispatcher::checkInjectionPermission(const InputWindow* window,
|
2010-09-27 05:20:12 +00:00
|
|
|
const InjectionState* injectionState) {
|
|
|
|
if (injectionState
|
2010-10-09 05:31:17 +00:00
|
|
|
&& (window == NULL || window->ownerUid != injectionState->injectorUid)
|
|
|
|
&& !hasInjectionPermission(injectionState->injectorPid, injectionState->injectorUid)) {
|
|
|
|
if (window) {
|
|
|
|
LOGW("Permission denied: injecting event from pid %d uid %d to window "
|
|
|
|
"with input channel %s owned by uid %d",
|
|
|
|
injectionState->injectorPid, injectionState->injectorUid,
|
|
|
|
window->inputChannel->getName().string(),
|
|
|
|
window->ownerUid);
|
|
|
|
} else {
|
|
|
|
LOGW("Permission denied: injecting event from pid %d uid %d",
|
|
|
|
injectionState->injectorPid, injectionState->injectorUid);
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
2010-10-09 05:31:17 +00:00
|
|
|
return false;
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-05 19:26:23 +00:00
|
|
|
bool InputDispatcher::isWindowObscuredAtPointLocked(
|
|
|
|
const InputWindow* window, int32_t x, int32_t y) const {
|
2010-09-08 18:49:43 +00:00
|
|
|
size_t numWindows = mWindows.size();
|
|
|
|
for (size_t i = 0; i < numWindows; i++) {
|
|
|
|
const InputWindow* other = & mWindows.itemAt(i);
|
|
|
|
if (other == window) {
|
|
|
|
break;
|
|
|
|
}
|
2010-10-05 19:26:23 +00:00
|
|
|
if (other->visible && ! other->isTrustedOverlay() && other->frameContainsPoint(x, y)) {
|
2010-09-08 18:49:43 +00:00
|
|
|
return true;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-15 22:18:56 +00:00
|
|
|
bool InputDispatcher::isWindowFinishedWithPreviousInputLocked(const InputWindow* window) {
|
|
|
|
ssize_t connectionIndex = getConnectionIndexLocked(window->inputChannel);
|
|
|
|
if (connectionIndex >= 0) {
|
|
|
|
sp<Connection> connection = mConnectionsByReceiveFd.valueAt(connectionIndex);
|
|
|
|
return connection->outboundQueue.isEmpty();
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String8 InputDispatcher::getApplicationWindowLabelLocked(const InputApplication* application,
|
|
|
|
const InputWindow* window) {
|
|
|
|
if (application) {
|
|
|
|
if (window) {
|
|
|
|
String8 label(application->name);
|
|
|
|
label.append(" - ");
|
|
|
|
label.append(window->name);
|
|
|
|
return label;
|
|
|
|
} else {
|
|
|
|
return application->name;
|
|
|
|
}
|
|
|
|
} else if (window) {
|
|
|
|
return window->name;
|
|
|
|
} else {
|
|
|
|
return String8("<unknown application or window>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-18 20:21:23 +00:00
|
|
|
void InputDispatcher::pokeUserActivityLocked(const EventEntry* eventEntry) {
|
|
|
|
int32_t eventType = POWER_MANAGER_BUTTON_EVENT;
|
2010-10-30 04:50:21 +00:00
|
|
|
switch (eventEntry->type) {
|
|
|
|
case EventEntry::TYPE_MOTION: {
|
2010-10-18 20:21:23 +00:00
|
|
|
const MotionEntry* motionEntry = static_cast<const MotionEntry*>(eventEntry);
|
2010-10-30 04:50:21 +00:00
|
|
|
if (motionEntry->action == AMOTION_EVENT_ACTION_CANCEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-18 20:21:23 +00:00
|
|
|
if (motionEntry->source & AINPUT_SOURCE_CLASS_POINTER) {
|
2010-11-08 17:48:20 +00:00
|
|
|
eventType = POWER_MANAGER_TOUCH_EVENT;
|
2010-09-27 05:20:12 +00:00
|
|
|
}
|
2010-10-30 04:50:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EventEntry::TYPE_KEY: {
|
|
|
|
const KeyEntry* keyEntry = static_cast<const KeyEntry*>(eventEntry);
|
|
|
|
if (keyEntry->flags & AKEY_EVENT_FLAG_CANCELED) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2010-09-27 05:20:12 +00:00
|
|
|
}
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
CommandEntry* commandEntry = postCommandLocked(
|
|
|
|
& InputDispatcher::doPokeUserActivityLockedInterruptible);
|
2010-10-18 20:21:23 +00:00
|
|
|
commandEntry->eventTime = eventEntry->eventTime;
|
2010-09-08 18:49:43 +00:00
|
|
|
commandEntry->userActivityEventType = eventType;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
2010-06-18 03:52:56 +00:00
|
|
|
void InputDispatcher::prepareDispatchCycleLocked(nsecs_t currentTime,
|
|
|
|
const sp<Connection>& connection, EventEntry* eventEntry, const InputTarget* inputTarget,
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
bool resumeWithAppendedMotionSample) {
|
|
|
|
#if DEBUG_DISPATCH_CYCLE
|
2010-09-15 22:18:56 +00:00
|
|
|
LOGD("channel '%s' ~ prepareDispatchCycle - flags=%d, "
|
2010-09-27 05:20:12 +00:00
|
|
|
"xOffset=%f, yOffset=%f, "
|
|
|
|
"windowType=%d, pointerIds=0x%x, "
|
|
|
|
"resumeWithAppendedMotionSample=%s",
|
2010-09-15 22:18:56 +00:00
|
|
|
connection->getInputChannelName(), inputTarget->flags,
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
inputTarget->xOffset, inputTarget->yOffset,
|
2010-09-27 05:20:12 +00:00
|
|
|
inputTarget->windowType, inputTarget->pointerIds.value,
|
2010-09-08 18:49:43 +00:00
|
|
|
toString(resumeWithAppendedMotionSample));
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
#endif
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
// Make sure we are never called for streaming when splitting across multiple windows.
|
|
|
|
bool isSplit = inputTarget->flags & InputTarget::FLAG_SPLIT;
|
|
|
|
assert(! (resumeWithAppendedMotionSample && isSplit));
|
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
// Skip this event if the connection status is not normal.
|
2010-09-15 22:18:56 +00:00
|
|
|
// We don't want to enqueue additional outbound events if the connection is broken.
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
if (connection->status != Connection::STATUS_NORMAL) {
|
2010-10-09 05:31:17 +00:00
|
|
|
#if DEBUG_DISPATCH_CYCLE
|
|
|
|
LOGD("channel '%s' ~ Dropping event because the channel status is %s",
|
2010-09-08 18:49:43 +00:00
|
|
|
connection->getInputChannelName(), connection->getStatusLabel());
|
2010-10-09 05:31:17 +00:00
|
|
|
#endif
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
// Split a motion event if needed.
|
|
|
|
if (isSplit) {
|
|
|
|
assert(eventEntry->type == EventEntry::TYPE_MOTION);
|
|
|
|
|
|
|
|
MotionEntry* originalMotionEntry = static_cast<MotionEntry*>(eventEntry);
|
|
|
|
if (inputTarget->pointerIds.count() != originalMotionEntry->pointerCount) {
|
|
|
|
MotionEntry* splitMotionEntry = splitMotionEvent(
|
|
|
|
originalMotionEntry, inputTarget->pointerIds);
|
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("channel '%s' ~ Split motion event.",
|
|
|
|
connection->getInputChannelName());
|
|
|
|
logOutboundMotionDetailsLocked(" ", splitMotionEntry);
|
|
|
|
#endif
|
|
|
|
eventEntry = splitMotionEntry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
// Resume the dispatch cycle with a freshly appended motion sample.
|
|
|
|
// First we check that the last dispatch entry in the outbound queue is for the same
|
|
|
|
// motion event to which we appended the motion sample. If we find such a dispatch
|
|
|
|
// entry, and if it is currently in progress then we try to stream the new sample.
|
|
|
|
bool wasEmpty = connection->outboundQueue.isEmpty();
|
|
|
|
|
|
|
|
if (! wasEmpty && resumeWithAppendedMotionSample) {
|
|
|
|
DispatchEntry* motionEventDispatchEntry =
|
|
|
|
connection->findQueuedDispatchEntryForEvent(eventEntry);
|
|
|
|
if (motionEventDispatchEntry) {
|
|
|
|
// If the dispatch entry is not in progress, then we must be busy dispatching an
|
|
|
|
// earlier event. Not a problem, the motion event is on the outbound queue and will
|
|
|
|
// be dispatched later.
|
|
|
|
if (! motionEventDispatchEntry->inProgress) {
|
|
|
|
#if DEBUG_BATCHING
|
|
|
|
LOGD("channel '%s' ~ Not streaming because the motion event has "
|
|
|
|
"not yet been dispatched. "
|
|
|
|
"(Waiting for earlier events to be consumed.)",
|
|
|
|
connection->getInputChannelName());
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the dispatch entry is in progress but it already has a tail of pending
|
|
|
|
// motion samples, then it must mean that the shared memory buffer filled up.
|
|
|
|
// Not a problem, when this dispatch cycle is finished, we will eventually start
|
|
|
|
// a new dispatch cycle to process the tail and that tail includes the newly
|
|
|
|
// appended motion sample.
|
|
|
|
if (motionEventDispatchEntry->tailMotionSample) {
|
|
|
|
#if DEBUG_BATCHING
|
|
|
|
LOGD("channel '%s' ~ Not streaming because no new samples can "
|
|
|
|
"be appended to the motion event in this dispatch cycle. "
|
|
|
|
"(Waiting for next dispatch cycle to start.)",
|
|
|
|
connection->getInputChannelName());
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The dispatch entry is in progress and is still potentially open for streaming.
|
|
|
|
// Try to stream the new motion sample. This might fail if the consumer has already
|
|
|
|
// consumed the motion event (or if the channel is broken).
|
2010-09-27 05:20:12 +00:00
|
|
|
MotionEntry* motionEntry = static_cast<MotionEntry*>(eventEntry);
|
|
|
|
MotionSample* appendedMotionSample = motionEntry->lastSample;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
status_t status = connection->inputPublisher.appendMotionSample(
|
|
|
|
appendedMotionSample->eventTime, appendedMotionSample->pointerCoords);
|
|
|
|
if (status == OK) {
|
|
|
|
#if DEBUG_BATCHING
|
|
|
|
LOGD("channel '%s' ~ Successfully streamed new motion sample.",
|
|
|
|
connection->getInputChannelName());
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG_BATCHING
|
|
|
|
if (status == NO_MEMORY) {
|
|
|
|
LOGD("channel '%s' ~ Could not append motion sample to currently "
|
|
|
|
"dispatched move event because the shared memory buffer is full. "
|
|
|
|
"(Waiting for next dispatch cycle to start.)",
|
|
|
|
connection->getInputChannelName());
|
|
|
|
} else if (status == status_t(FAILED_TRANSACTION)) {
|
|
|
|
LOGD("channel '%s' ~ Could not append motion sample to currently "
|
2010-06-22 08:27:15 +00:00
|
|
|
"dispatched move event because the event has already been consumed. "
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
"(Waiting for next dispatch cycle to start.)",
|
|
|
|
connection->getInputChannelName());
|
|
|
|
} else {
|
|
|
|
LOGD("channel '%s' ~ Could not append motion sample to currently "
|
|
|
|
"dispatched move event due to an error, status=%d. "
|
|
|
|
"(Waiting for next dispatch cycle to start.)",
|
|
|
|
connection->getInputChannelName(), status);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// Failed to stream. Start a new tail of pending motion samples to dispatch
|
|
|
|
// in the next cycle.
|
|
|
|
motionEventDispatchEntry->tailMotionSample = appendedMotionSample;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a new event.
|
|
|
|
// Enqueue a new dispatch entry onto the outbound queue for this connection.
|
2010-09-08 18:49:43 +00:00
|
|
|
DispatchEntry* dispatchEntry = mAllocator.obtainDispatchEntry(eventEntry, // increments ref
|
2010-09-15 22:18:56 +00:00
|
|
|
inputTarget->flags, inputTarget->xOffset, inputTarget->yOffset);
|
|
|
|
if (dispatchEntry->hasForegroundTarget()) {
|
2010-09-27 05:20:12 +00:00
|
|
|
incrementPendingForegroundDispatchesLocked(eventEntry);
|
2010-07-28 22:48:59 +00:00
|
|
|
}
|
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
// Handle the case where we could not stream a new motion sample because the consumer has
|
|
|
|
// already consumed the motion event (otherwise the corresponding dispatch entry would
|
|
|
|
// still be in the outbound queue for this connection). We set the head motion sample
|
|
|
|
// to the list starting with the newly appended motion sample.
|
|
|
|
if (resumeWithAppendedMotionSample) {
|
|
|
|
#if DEBUG_BATCHING
|
|
|
|
LOGD("channel '%s' ~ Preparing a new dispatch cycle for additional motion samples "
|
|
|
|
"that cannot be streamed because the motion event has already been consumed.",
|
|
|
|
connection->getInputChannelName());
|
|
|
|
#endif
|
|
|
|
MotionSample* appendedMotionSample = static_cast<MotionEntry*>(eventEntry)->lastSample;
|
|
|
|
dispatchEntry->headMotionSample = appendedMotionSample;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enqueue the dispatch entry.
|
|
|
|
connection->outboundQueue.enqueueAtTail(dispatchEntry);
|
|
|
|
|
|
|
|
// If the outbound queue was previously empty, start the dispatch cycle going.
|
|
|
|
if (wasEmpty) {
|
2010-06-18 03:52:56 +00:00
|
|
|
activateConnectionLocked(connection.get());
|
2010-09-15 22:18:56 +00:00
|
|
|
startDispatchCycleLocked(currentTime, connection);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-18 03:52:56 +00:00
|
|
|
void InputDispatcher::startDispatchCycleLocked(nsecs_t currentTime,
|
2010-09-15 22:18:56 +00:00
|
|
|
const sp<Connection>& connection) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
#if DEBUG_DISPATCH_CYCLE
|
|
|
|
LOGD("channel '%s' ~ startDispatchCycle",
|
|
|
|
connection->getInputChannelName());
|
|
|
|
#endif
|
|
|
|
|
|
|
|
assert(connection->status == Connection::STATUS_NORMAL);
|
|
|
|
assert(! connection->outboundQueue.isEmpty());
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
DispatchEntry* dispatchEntry = connection->outboundQueue.headSentinel.next;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
assert(! dispatchEntry->inProgress);
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
// Mark the dispatch entry as in progress.
|
|
|
|
dispatchEntry->inProgress = true;
|
|
|
|
|
|
|
|
// Update the connection's input state.
|
2010-09-27 05:20:12 +00:00
|
|
|
EventEntry* eventEntry = dispatchEntry->eventEntry;
|
|
|
|
InputState::Consistency consistency = connection->inputState.trackEvent(eventEntry);
|
2010-09-08 18:49:43 +00:00
|
|
|
|
|
|
|
#if FILTER_INPUT_EVENTS
|
|
|
|
// Filter out inconsistent sequences of input events.
|
|
|
|
// The input system may drop or inject events in a way that could violate implicit
|
|
|
|
// invariants on input state and potentially cause an application to crash
|
|
|
|
// or think that a key or pointer is stuck down. Technically we make no guarantees
|
|
|
|
// of consistency but it would be nice to improve on this where possible.
|
|
|
|
// XXX: This code is a proof of concept only. Not ready for prime time.
|
|
|
|
if (consistency == InputState::TOLERABLE) {
|
|
|
|
#if DEBUG_DISPATCH_CYCLE
|
|
|
|
LOGD("channel '%s' ~ Sending an event that is inconsistent with the connection's "
|
|
|
|
"current input state but that is likely to be tolerated by the application.",
|
|
|
|
connection->getInputChannelName());
|
|
|
|
#endif
|
|
|
|
} else if (consistency == InputState::BROKEN) {
|
|
|
|
LOGI("channel '%s' ~ Dropping an event that is inconsistent with the connection's "
|
|
|
|
"current input state and that is likely to cause the application to crash.",
|
|
|
|
connection->getInputChannelName());
|
|
|
|
startNextDispatchCycleLocked(currentTime, connection);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
|
|
|
// Publish the event.
|
|
|
|
status_t status;
|
2010-09-27 05:20:12 +00:00
|
|
|
switch (eventEntry->type) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
case EventEntry::TYPE_KEY: {
|
2010-09-27 05:20:12 +00:00
|
|
|
KeyEntry* keyEntry = static_cast<KeyEntry*>(eventEntry);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
|
|
|
// Apply target flags.
|
|
|
|
int32_t action = keyEntry->action;
|
|
|
|
int32_t flags = keyEntry->flags;
|
|
|
|
|
|
|
|
// Publish the key event.
|
2010-07-15 01:48:53 +00:00
|
|
|
status = connection->inputPublisher.publishKeyEvent(keyEntry->deviceId, keyEntry->source,
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
action, flags, keyEntry->keyCode, keyEntry->scanCode,
|
|
|
|
keyEntry->metaState, keyEntry->repeatCount, keyEntry->downTime,
|
|
|
|
keyEntry->eventTime);
|
|
|
|
|
|
|
|
if (status) {
|
|
|
|
LOGE("channel '%s' ~ Could not publish key event, "
|
|
|
|
"status=%d", connection->getInputChannelName(), status);
|
2010-10-09 05:31:17 +00:00
|
|
|
abortBrokenDispatchCycleLocked(currentTime, connection);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case EventEntry::TYPE_MOTION: {
|
2010-09-27 05:20:12 +00:00
|
|
|
MotionEntry* motionEntry = static_cast<MotionEntry*>(eventEntry);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
|
|
|
// Apply target flags.
|
|
|
|
int32_t action = motionEntry->action;
|
2010-09-02 00:01:00 +00:00
|
|
|
int32_t flags = motionEntry->flags;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
if (dispatchEntry->targetFlags & InputTarget::FLAG_OUTSIDE) {
|
2010-07-15 01:48:53 +00:00
|
|
|
action = AMOTION_EVENT_ACTION_OUTSIDE;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
2010-09-02 00:01:00 +00:00
|
|
|
if (dispatchEntry->targetFlags & InputTarget::FLAG_WINDOW_IS_OBSCURED) {
|
|
|
|
flags |= AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED;
|
|
|
|
}
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
|
|
|
// If headMotionSample is non-NULL, then it points to the first new sample that we
|
|
|
|
// were unable to dispatch during the previous cycle so we resume dispatching from
|
|
|
|
// that point in the list of motion samples.
|
|
|
|
// Otherwise, we just start from the first sample of the motion event.
|
|
|
|
MotionSample* firstMotionSample = dispatchEntry->headMotionSample;
|
|
|
|
if (! firstMotionSample) {
|
|
|
|
firstMotionSample = & motionEntry->firstSample;
|
|
|
|
}
|
|
|
|
|
2010-07-17 00:21:06 +00:00
|
|
|
// Set the X and Y offset depending on the input source.
|
|
|
|
float xOffset, yOffset;
|
|
|
|
if (motionEntry->source & AINPUT_SOURCE_CLASS_POINTER) {
|
|
|
|
xOffset = dispatchEntry->xOffset;
|
|
|
|
yOffset = dispatchEntry->yOffset;
|
|
|
|
} else {
|
|
|
|
xOffset = 0.0f;
|
|
|
|
yOffset = 0.0f;
|
|
|
|
}
|
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
// Publish the motion event and the first motion sample.
|
|
|
|
status = connection->inputPublisher.publishMotionEvent(motionEntry->deviceId,
|
2010-09-02 00:01:00 +00:00
|
|
|
motionEntry->source, action, flags, motionEntry->edgeFlags, motionEntry->metaState,
|
2010-07-17 00:21:06 +00:00
|
|
|
xOffset, yOffset,
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
motionEntry->xPrecision, motionEntry->yPrecision,
|
|
|
|
motionEntry->downTime, firstMotionSample->eventTime,
|
|
|
|
motionEntry->pointerCount, motionEntry->pointerIds,
|
|
|
|
firstMotionSample->pointerCoords);
|
|
|
|
|
|
|
|
if (status) {
|
|
|
|
LOGE("channel '%s' ~ Could not publish motion event, "
|
|
|
|
"status=%d", connection->getInputChannelName(), status);
|
2010-10-09 05:31:17 +00:00
|
|
|
abortBrokenDispatchCycleLocked(currentTime, connection);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append additional motion samples.
|
|
|
|
MotionSample* nextMotionSample = firstMotionSample->next;
|
|
|
|
for (; nextMotionSample != NULL; nextMotionSample = nextMotionSample->next) {
|
|
|
|
status = connection->inputPublisher.appendMotionSample(
|
|
|
|
nextMotionSample->eventTime, nextMotionSample->pointerCoords);
|
|
|
|
if (status == NO_MEMORY) {
|
|
|
|
#if DEBUG_DISPATCH_CYCLE
|
|
|
|
LOGD("channel '%s' ~ Shared memory buffer full. Some motion samples will "
|
|
|
|
"be sent in the next dispatch cycle.",
|
|
|
|
connection->getInputChannelName());
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (status != OK) {
|
|
|
|
LOGE("channel '%s' ~ Could not append motion sample "
|
|
|
|
"for a reason other than out of memory, status=%d",
|
|
|
|
connection->getInputChannelName(), status);
|
2010-10-09 05:31:17 +00:00
|
|
|
abortBrokenDispatchCycleLocked(currentTime, connection);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remember the next motion sample that we could not dispatch, in case we ran out
|
|
|
|
// of space in the shared memory buffer.
|
|
|
|
dispatchEntry->tailMotionSample = nextMotionSample;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default: {
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send the dispatch signal.
|
|
|
|
status = connection->inputPublisher.sendDispatchSignal();
|
|
|
|
if (status) {
|
|
|
|
LOGE("channel '%s' ~ Could not send dispatch signal, status=%d",
|
|
|
|
connection->getInputChannelName(), status);
|
2010-10-09 05:31:17 +00:00
|
|
|
abortBrokenDispatchCycleLocked(currentTime, connection);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Record information about the newly started dispatch cycle.
|
2010-09-27 05:20:12 +00:00
|
|
|
connection->lastEventTime = eventEntry->eventTime;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
connection->lastDispatchTime = currentTime;
|
|
|
|
|
|
|
|
// Notify other system components.
|
|
|
|
onDispatchCycleStartedLocked(currentTime, connection);
|
|
|
|
}
|
|
|
|
|
2010-06-18 03:52:56 +00:00
|
|
|
void InputDispatcher::finishDispatchCycleLocked(nsecs_t currentTime,
|
2010-11-05 22:02:16 +00:00
|
|
|
const sp<Connection>& connection, bool handled) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
#if DEBUG_DISPATCH_CYCLE
|
2010-06-15 08:31:58 +00:00
|
|
|
LOGD("channel '%s' ~ finishDispatchCycle - %01.1fms since event, "
|
2010-11-05 22:02:16 +00:00
|
|
|
"%01.1fms since dispatch, handled=%s",
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
connection->getInputChannelName(),
|
|
|
|
connection->getEventLatencyMillis(currentTime),
|
2010-11-05 22:02:16 +00:00
|
|
|
connection->getDispatchLatencyMillis(currentTime),
|
|
|
|
toString(handled));
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
#endif
|
|
|
|
|
2010-06-15 08:31:58 +00:00
|
|
|
if (connection->status == Connection::STATUS_BROKEN
|
|
|
|
|| connection->status == Connection::STATUS_ZOMBIE) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset the publisher since the event has been consumed.
|
|
|
|
// We do this now so that the publisher can release some of its internal resources
|
|
|
|
// while waiting for the next dispatch cycle to begin.
|
|
|
|
status_t status = connection->inputPublisher.reset();
|
|
|
|
if (status) {
|
|
|
|
LOGE("channel '%s' ~ Could not reset publisher, status=%d",
|
|
|
|
connection->getInputChannelName(), status);
|
2010-10-09 05:31:17 +00:00
|
|
|
abortBrokenDispatchCycleLocked(currentTime, connection);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-05 22:02:16 +00:00
|
|
|
// Notify other system components and prepare to start the next dispatch cycle.
|
|
|
|
onDispatchCycleFinishedLocked(currentTime, connection, handled);
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::startNextDispatchCycleLocked(nsecs_t currentTime,
|
|
|
|
const sp<Connection>& connection) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
// Start the next dispatch cycle for this connection.
|
|
|
|
while (! connection->outboundQueue.isEmpty()) {
|
2010-09-08 18:49:43 +00:00
|
|
|
DispatchEntry* dispatchEntry = connection->outboundQueue.headSentinel.next;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
if (dispatchEntry->inProgress) {
|
|
|
|
// Finish or resume current event in progress.
|
|
|
|
if (dispatchEntry->tailMotionSample) {
|
|
|
|
// We have a tail of undispatched motion samples.
|
|
|
|
// Reuse the same DispatchEntry and start a new cycle.
|
|
|
|
dispatchEntry->inProgress = false;
|
|
|
|
dispatchEntry->headMotionSample = dispatchEntry->tailMotionSample;
|
|
|
|
dispatchEntry->tailMotionSample = NULL;
|
2010-09-15 22:18:56 +00:00
|
|
|
startDispatchCycleLocked(currentTime, connection);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Finished.
|
|
|
|
connection->outboundQueue.dequeueAtHead();
|
2010-09-15 22:18:56 +00:00
|
|
|
if (dispatchEntry->hasForegroundTarget()) {
|
|
|
|
decrementPendingForegroundDispatchesLocked(dispatchEntry->eventEntry);
|
2010-07-28 22:48:59 +00:00
|
|
|
}
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
mAllocator.releaseDispatchEntry(dispatchEntry);
|
|
|
|
} else {
|
|
|
|
// If the head is not in progress, then we must have already dequeued the in
|
2010-09-15 22:18:56 +00:00
|
|
|
// progress event, which means we actually aborted it.
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
// So just start the next event for this connection.
|
2010-09-15 22:18:56 +00:00
|
|
|
startDispatchCycleLocked(currentTime, connection);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Outbound queue is empty, deactivate the connection.
|
2010-06-18 03:52:56 +00:00
|
|
|
deactivateConnectionLocked(connection.get());
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
2010-10-09 05:31:17 +00:00
|
|
|
void InputDispatcher::abortBrokenDispatchCycleLocked(nsecs_t currentTime,
|
|
|
|
const sp<Connection>& connection) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
#if DEBUG_DISPATCH_CYCLE
|
2010-10-09 05:31:17 +00:00
|
|
|
LOGD("channel '%s' ~ abortBrokenDispatchCycle - broken=%s",
|
2010-09-08 18:49:43 +00:00
|
|
|
connection->getInputChannelName(), toString(broken));
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
#endif
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
// Clear the outbound queue.
|
2010-09-15 22:18:56 +00:00
|
|
|
drainOutboundQueueLocked(connection.get());
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-10-09 05:31:17 +00:00
|
|
|
// The connection appears to be unrecoverably broken.
|
2010-06-15 08:31:58 +00:00
|
|
|
// Ignore already broken or zombie connections.
|
2010-10-09 05:31:17 +00:00
|
|
|
if (connection->status == Connection::STATUS_NORMAL) {
|
|
|
|
connection->status = Connection::STATUS_BROKEN;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-10-09 05:31:17 +00:00
|
|
|
// Notify other system components.
|
|
|
|
onDispatchCycleBrokenLocked(currentTime, connection);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-15 22:18:56 +00:00
|
|
|
void InputDispatcher::drainOutboundQueueLocked(Connection* connection) {
|
|
|
|
while (! connection->outboundQueue.isEmpty()) {
|
|
|
|
DispatchEntry* dispatchEntry = connection->outboundQueue.dequeueAtHead();
|
|
|
|
if (dispatchEntry->hasForegroundTarget()) {
|
|
|
|
decrementPendingForegroundDispatchesLocked(dispatchEntry->eventEntry);
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
mAllocator.releaseDispatchEntry(dispatchEntry);
|
|
|
|
}
|
|
|
|
|
2010-09-15 22:18:56 +00:00
|
|
|
deactivateConnectionLocked(connection);
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
2010-09-14 06:17:30 +00:00
|
|
|
int InputDispatcher::handleReceiveCallback(int receiveFd, int events, void* data) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
InputDispatcher* d = static_cast<InputDispatcher*>(data);
|
|
|
|
|
|
|
|
{ // acquire lock
|
|
|
|
AutoMutex _l(d->mLock);
|
|
|
|
|
|
|
|
ssize_t connectionIndex = d->mConnectionsByReceiveFd.indexOfKey(receiveFd);
|
|
|
|
if (connectionIndex < 0) {
|
|
|
|
LOGE("Received spurious receive callback for unknown input channel. "
|
|
|
|
"fd=%d, events=0x%x", receiveFd, events);
|
2010-09-14 06:17:30 +00:00
|
|
|
return 0; // remove the callback
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
2010-06-18 03:52:56 +00:00
|
|
|
nsecs_t currentTime = now();
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
|
|
|
sp<Connection> connection = d->mConnectionsByReceiveFd.valueAt(connectionIndex);
|
2010-09-14 06:17:30 +00:00
|
|
|
if (events & (ALOOPER_EVENT_ERROR | ALOOPER_EVENT_HANGUP)) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
LOGE("channel '%s' ~ Consumer closed input channel or an error occurred. "
|
|
|
|
"events=0x%x", connection->getInputChannelName(), events);
|
2010-10-09 05:31:17 +00:00
|
|
|
d->abortBrokenDispatchCycleLocked(currentTime, connection);
|
2010-06-15 08:31:58 +00:00
|
|
|
d->runCommandsLockedInterruptible();
|
2010-09-14 06:17:30 +00:00
|
|
|
return 0; // remove the callback
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
2010-09-14 06:17:30 +00:00
|
|
|
if (! (events & ALOOPER_EVENT_INPUT)) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
LOGW("channel '%s' ~ Received spurious callback for unhandled poll event. "
|
|
|
|
"events=0x%x", connection->getInputChannelName(), events);
|
2010-09-14 06:17:30 +00:00
|
|
|
return 1;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
2010-11-05 22:02:16 +00:00
|
|
|
bool handled = false;
|
|
|
|
status_t status = connection->inputPublisher.receiveFinishedSignal(handled);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
if (status) {
|
|
|
|
LOGE("channel '%s' ~ Failed to receive finished signal. status=%d",
|
|
|
|
connection->getInputChannelName(), status);
|
2010-10-09 05:31:17 +00:00
|
|
|
d->abortBrokenDispatchCycleLocked(currentTime, connection);
|
2010-06-15 08:31:58 +00:00
|
|
|
d->runCommandsLockedInterruptible();
|
2010-09-14 06:17:30 +00:00
|
|
|
return 0; // remove the callback
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
2010-11-05 22:02:16 +00:00
|
|
|
d->finishDispatchCycleLocked(currentTime, connection, handled);
|
2010-06-15 08:31:58 +00:00
|
|
|
d->runCommandsLockedInterruptible();
|
2010-09-14 06:17:30 +00:00
|
|
|
return 1;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
} // release lock
|
|
|
|
}
|
|
|
|
|
2010-10-09 05:31:17 +00:00
|
|
|
void InputDispatcher::synthesizeCancelationEventsForAllConnectionsLocked(
|
|
|
|
InputState::CancelationOptions options, const char* reason) {
|
|
|
|
for (size_t i = 0; i < mConnectionsByReceiveFd.size(); i++) {
|
|
|
|
synthesizeCancelationEventsForConnectionLocked(
|
|
|
|
mConnectionsByReceiveFd.valueAt(i), options, reason);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::synthesizeCancelationEventsForInputChannelLocked(
|
|
|
|
const sp<InputChannel>& channel, InputState::CancelationOptions options,
|
|
|
|
const char* reason) {
|
|
|
|
ssize_t index = getConnectionIndexLocked(channel);
|
|
|
|
if (index >= 0) {
|
|
|
|
synthesizeCancelationEventsForConnectionLocked(
|
|
|
|
mConnectionsByReceiveFd.valueAt(index), options, reason);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::synthesizeCancelationEventsForConnectionLocked(
|
|
|
|
const sp<Connection>& connection, InputState::CancelationOptions options,
|
|
|
|
const char* reason) {
|
|
|
|
nsecs_t currentTime = now();
|
|
|
|
|
|
|
|
mTempCancelationEvents.clear();
|
|
|
|
connection->inputState.synthesizeCancelationEvents(currentTime, & mAllocator,
|
|
|
|
mTempCancelationEvents, options);
|
|
|
|
|
|
|
|
if (! mTempCancelationEvents.isEmpty()
|
|
|
|
&& connection->status != Connection::STATUS_BROKEN) {
|
|
|
|
#if DEBUG_OUTBOUND_EVENT_DETAILS
|
|
|
|
LOGD("channel '%s' ~ Synthesized %d cancelation events to bring channel back in sync "
|
|
|
|
"with reality: %s, options=%d.",
|
|
|
|
connection->getInputChannelName(), mTempCancelationEvents.size(), reason, options);
|
|
|
|
#endif
|
|
|
|
for (size_t i = 0; i < mTempCancelationEvents.size(); i++) {
|
|
|
|
EventEntry* cancelationEventEntry = mTempCancelationEvents.itemAt(i);
|
|
|
|
switch (cancelationEventEntry->type) {
|
|
|
|
case EventEntry::TYPE_KEY:
|
|
|
|
logOutboundKeyDetailsLocked("cancel - ",
|
|
|
|
static_cast<KeyEntry*>(cancelationEventEntry));
|
|
|
|
break;
|
|
|
|
case EventEntry::TYPE_MOTION:
|
|
|
|
logOutboundMotionDetailsLocked("cancel - ",
|
|
|
|
static_cast<MotionEntry*>(cancelationEventEntry));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t xOffset, yOffset;
|
|
|
|
const InputWindow* window = getWindowLocked(connection->inputChannel);
|
|
|
|
if (window) {
|
|
|
|
xOffset = -window->frameLeft;
|
|
|
|
yOffset = -window->frameTop;
|
|
|
|
} else {
|
|
|
|
xOffset = 0;
|
|
|
|
yOffset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DispatchEntry* cancelationDispatchEntry =
|
|
|
|
mAllocator.obtainDispatchEntry(cancelationEventEntry, // increments ref
|
|
|
|
0, xOffset, yOffset);
|
|
|
|
connection->outboundQueue.enqueueAtTail(cancelationDispatchEntry);
|
|
|
|
|
|
|
|
mAllocator.releaseEventEntry(cancelationEventEntry);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!connection->outboundQueue.headSentinel.next->inProgress) {
|
|
|
|
startDispatchCycleLocked(currentTime, connection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
InputDispatcher::MotionEntry*
|
|
|
|
InputDispatcher::splitMotionEvent(const MotionEntry* originalMotionEntry, BitSet32 pointerIds) {
|
|
|
|
assert(pointerIds.value != 0);
|
|
|
|
|
|
|
|
uint32_t splitPointerIndexMap[MAX_POINTERS];
|
|
|
|
int32_t splitPointerIds[MAX_POINTERS];
|
|
|
|
PointerCoords splitPointerCoords[MAX_POINTERS];
|
|
|
|
|
|
|
|
uint32_t originalPointerCount = originalMotionEntry->pointerCount;
|
|
|
|
uint32_t splitPointerCount = 0;
|
|
|
|
|
|
|
|
for (uint32_t originalPointerIndex = 0; originalPointerIndex < originalPointerCount;
|
|
|
|
originalPointerIndex++) {
|
|
|
|
int32_t pointerId = uint32_t(originalMotionEntry->pointerIds[originalPointerIndex]);
|
|
|
|
if (pointerIds.hasBit(pointerId)) {
|
|
|
|
splitPointerIndexMap[splitPointerCount] = originalPointerIndex;
|
|
|
|
splitPointerIds[splitPointerCount] = pointerId;
|
|
|
|
splitPointerCoords[splitPointerCount] =
|
|
|
|
originalMotionEntry->firstSample.pointerCoords[originalPointerIndex];
|
|
|
|
splitPointerCount += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(splitPointerCount == pointerIds.count());
|
|
|
|
|
|
|
|
int32_t action = originalMotionEntry->action;
|
|
|
|
int32_t maskedAction = action & AMOTION_EVENT_ACTION_MASK;
|
|
|
|
if (maskedAction == AMOTION_EVENT_ACTION_POINTER_DOWN
|
|
|
|
|| maskedAction == AMOTION_EVENT_ACTION_POINTER_UP) {
|
|
|
|
int32_t originalPointerIndex = getMotionEventActionPointerIndex(action);
|
|
|
|
int32_t pointerId = originalMotionEntry->pointerIds[originalPointerIndex];
|
|
|
|
if (pointerIds.hasBit(pointerId)) {
|
|
|
|
if (pointerIds.count() == 1) {
|
|
|
|
// The first/last pointer went down/up.
|
|
|
|
action = maskedAction == AMOTION_EVENT_ACTION_POINTER_DOWN
|
|
|
|
? AMOTION_EVENT_ACTION_DOWN : AMOTION_EVENT_ACTION_UP;
|
2010-09-27 23:35:11 +00:00
|
|
|
} else {
|
|
|
|
// A secondary pointer went down/up.
|
|
|
|
uint32_t splitPointerIndex = 0;
|
|
|
|
while (pointerId != splitPointerIds[splitPointerIndex]) {
|
|
|
|
splitPointerIndex += 1;
|
|
|
|
}
|
|
|
|
action = maskedAction | (splitPointerIndex
|
|
|
|
<< AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
|
2010-09-27 05:20:12 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// An unrelated pointer changed.
|
|
|
|
action = AMOTION_EVENT_ACTION_MOVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MotionEntry* splitMotionEntry = mAllocator.obtainMotionEntry(
|
|
|
|
originalMotionEntry->eventTime,
|
|
|
|
originalMotionEntry->deviceId,
|
|
|
|
originalMotionEntry->source,
|
|
|
|
originalMotionEntry->policyFlags,
|
|
|
|
action,
|
|
|
|
originalMotionEntry->flags,
|
|
|
|
originalMotionEntry->metaState,
|
|
|
|
originalMotionEntry->edgeFlags,
|
|
|
|
originalMotionEntry->xPrecision,
|
|
|
|
originalMotionEntry->yPrecision,
|
|
|
|
originalMotionEntry->downTime,
|
|
|
|
splitPointerCount, splitPointerIds, splitPointerCoords);
|
|
|
|
|
|
|
|
for (MotionSample* originalMotionSample = originalMotionEntry->firstSample.next;
|
|
|
|
originalMotionSample != NULL; originalMotionSample = originalMotionSample->next) {
|
|
|
|
for (uint32_t splitPointerIndex = 0; splitPointerIndex < splitPointerCount;
|
|
|
|
splitPointerIndex++) {
|
|
|
|
uint32_t originalPointerIndex = splitPointerIndexMap[splitPointerIndex];
|
|
|
|
splitPointerCoords[splitPointerIndex] =
|
|
|
|
originalMotionSample->pointerCoords[originalPointerIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
mAllocator.appendMotionSample(splitMotionEntry, originalMotionSample->eventTime,
|
|
|
|
splitPointerCoords);
|
|
|
|
}
|
|
|
|
|
|
|
|
return splitMotionEntry;
|
|
|
|
}
|
|
|
|
|
2010-06-15 08:31:58 +00:00
|
|
|
void InputDispatcher::notifyConfigurationChanged(nsecs_t eventTime) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
#if DEBUG_INBOUND_EVENT_DETAILS
|
2010-06-15 08:31:58 +00:00
|
|
|
LOGD("notifyConfigurationChanged - eventTime=%lld", eventTime);
|
2010-09-08 18:49:43 +00:00
|
|
|
#endif
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
bool needWake;
|
|
|
|
{ // acquire lock
|
|
|
|
AutoMutex _l(mLock);
|
|
|
|
|
|
|
|
ConfigurationChangedEntry* newEntry = mAllocator.obtainConfigurationChangedEntry(eventTime);
|
|
|
|
needWake = enqueueInboundEventLocked(newEntry);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
} // release lock
|
2010-09-08 18:49:43 +00:00
|
|
|
|
|
|
|
if (needWake) {
|
2010-09-14 06:17:30 +00:00
|
|
|
mLooper->wake();
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
2010-07-15 01:48:53 +00:00
|
|
|
void InputDispatcher::notifyKey(nsecs_t eventTime, int32_t deviceId, int32_t source,
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
uint32_t policyFlags, int32_t action, int32_t flags,
|
|
|
|
int32_t keyCode, int32_t scanCode, int32_t metaState, nsecs_t downTime) {
|
|
|
|
#if DEBUG_INBOUND_EVENT_DETAILS
|
2010-07-15 01:48:53 +00:00
|
|
|
LOGD("notifyKey - eventTime=%lld, deviceId=0x%x, source=0x%x, policyFlags=0x%x, action=0x%x, "
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
"flags=0x%x, keyCode=0x%x, scanCode=0x%x, metaState=0x%x, downTime=%lld",
|
2010-07-15 01:48:53 +00:00
|
|
|
eventTime, deviceId, source, policyFlags, action, flags,
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
keyCode, scanCode, metaState, downTime);
|
|
|
|
#endif
|
2010-09-27 05:20:12 +00:00
|
|
|
if (! validateKeyEvent(action)) {
|
|
|
|
return;
|
|
|
|
}
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-10-11 21:20:19 +00:00
|
|
|
policyFlags |= POLICY_FLAG_TRUSTED;
|
2010-10-09 05:31:17 +00:00
|
|
|
mPolicy->interceptKeyBeforeQueueing(eventTime, deviceId, action, /*byref*/ flags,
|
|
|
|
keyCode, scanCode, /*byref*/ policyFlags);
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
bool needWake;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
{ // acquire lock
|
|
|
|
AutoMutex _l(mLock);
|
|
|
|
|
2010-06-18 03:52:56 +00:00
|
|
|
int32_t repeatCount = 0;
|
|
|
|
KeyEntry* newEntry = mAllocator.obtainKeyEntry(eventTime,
|
2010-07-15 01:48:53 +00:00
|
|
|
deviceId, source, policyFlags, action, flags, keyCode, scanCode,
|
2010-06-18 03:52:56 +00:00
|
|
|
metaState, repeatCount, downTime);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
needWake = enqueueInboundEventLocked(newEntry);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
} // release lock
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
if (needWake) {
|
2010-09-14 06:17:30 +00:00
|
|
|
mLooper->wake();
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-15 01:48:53 +00:00
|
|
|
void InputDispatcher::notifyMotion(nsecs_t eventTime, int32_t deviceId, int32_t source,
|
2010-09-02 00:01:00 +00:00
|
|
|
uint32_t policyFlags, int32_t action, int32_t flags, int32_t metaState, int32_t edgeFlags,
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
uint32_t pointerCount, const int32_t* pointerIds, const PointerCoords* pointerCoords,
|
|
|
|
float xPrecision, float yPrecision, nsecs_t downTime) {
|
|
|
|
#if DEBUG_INBOUND_EVENT_DETAILS
|
2010-07-15 01:48:53 +00:00
|
|
|
LOGD("notifyMotion - eventTime=%lld, deviceId=0x%x, source=0x%x, policyFlags=0x%x, "
|
2010-09-02 00:01:00 +00:00
|
|
|
"action=0x%x, flags=0x%x, metaState=0x%x, edgeFlags=0x%x, "
|
|
|
|
"xPrecision=%f, yPrecision=%f, downTime=%lld",
|
|
|
|
eventTime, deviceId, source, policyFlags, action, flags, metaState, edgeFlags,
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
xPrecision, yPrecision, downTime);
|
|
|
|
for (uint32_t i = 0; i < pointerCount; i++) {
|
2010-08-30 10:02:23 +00:00
|
|
|
LOGD(" Pointer %d: id=%d, x=%f, y=%f, pressure=%f, size=%f, "
|
2010-09-02 00:01:00 +00:00
|
|
|
"touchMajor=%f, touchMinor=%f, toolMajor=%f, toolMinor=%f, "
|
2010-08-30 10:02:23 +00:00
|
|
|
"orientation=%f",
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
i, pointerIds[i], pointerCoords[i].x, pointerCoords[i].y,
|
2010-08-30 10:02:23 +00:00
|
|
|
pointerCoords[i].pressure, pointerCoords[i].size,
|
|
|
|
pointerCoords[i].touchMajor, pointerCoords[i].touchMinor,
|
|
|
|
pointerCoords[i].toolMajor, pointerCoords[i].toolMinor,
|
|
|
|
pointerCoords[i].orientation);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
#endif
|
2010-09-27 05:20:12 +00:00
|
|
|
if (! validateMotionEvent(action, pointerCount, pointerIds)) {
|
|
|
|
return;
|
|
|
|
}
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-10-11 21:20:19 +00:00
|
|
|
policyFlags |= POLICY_FLAG_TRUSTED;
|
2010-10-09 05:31:17 +00:00
|
|
|
mPolicy->interceptGenericBeforeQueueing(eventTime, /*byref*/ policyFlags);
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
bool needWake;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
{ // acquire lock
|
|
|
|
AutoMutex _l(mLock);
|
|
|
|
|
|
|
|
// Attempt batching and streaming of move events.
|
2010-07-15 01:48:53 +00:00
|
|
|
if (action == AMOTION_EVENT_ACTION_MOVE) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
// BATCHING CASE
|
|
|
|
//
|
|
|
|
// Try to append a move sample to the tail of the inbound queue for this device.
|
|
|
|
// Give up if we encounter a non-move motion event for this device since that
|
|
|
|
// means we cannot append any new samples until a new motion event has started.
|
2010-09-08 18:49:43 +00:00
|
|
|
for (EventEntry* entry = mInboundQueue.tailSentinel.prev;
|
|
|
|
entry != & mInboundQueue.headSentinel; entry = entry->prev) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
if (entry->type != EventEntry::TYPE_MOTION) {
|
|
|
|
// Keep looking for motion events.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
MotionEntry* motionEntry = static_cast<MotionEntry*>(entry);
|
|
|
|
if (motionEntry->deviceId != deviceId) {
|
|
|
|
// Keep looking for this device.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-07-15 01:48:53 +00:00
|
|
|
if (motionEntry->action != AMOTION_EVENT_ACTION_MOVE
|
2010-06-18 03:52:56 +00:00
|
|
|
|| motionEntry->pointerCount != pointerCount
|
|
|
|
|| motionEntry->isInjected()) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
// Last motion event in the queue for this device is not compatible for
|
|
|
|
// appending new samples. Stop here.
|
|
|
|
goto NoBatchingOrStreaming;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The last motion event is a move and is compatible for appending.
|
2010-06-15 08:31:58 +00:00
|
|
|
// Do the batching magic.
|
2010-06-18 03:52:56 +00:00
|
|
|
mAllocator.appendMotionSample(motionEntry, eventTime, pointerCoords);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
#if DEBUG_BATCHING
|
|
|
|
LOGD("Appended motion sample onto batch for most recent "
|
|
|
|
"motion event for this device in the inbound queue.");
|
|
|
|
#endif
|
2010-06-15 08:31:58 +00:00
|
|
|
return; // done!
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// STREAMING CASE
|
|
|
|
//
|
|
|
|
// There is no pending motion event (of any kind) for this device in the inbound queue.
|
2010-09-15 22:18:56 +00:00
|
|
|
// Search the outbound queue for the current foreground targets to find a dispatched
|
|
|
|
// motion event that is still in progress. If found, then, appen the new sample to
|
|
|
|
// that event and push it out to all current targets. The logic in
|
|
|
|
// prepareDispatchCycleLocked takes care of the case where some targets may
|
|
|
|
// already have consumed the motion event by starting a new dispatch cycle if needed.
|
2010-06-15 08:31:58 +00:00
|
|
|
if (mCurrentInputTargetsValid) {
|
2010-09-15 22:18:56 +00:00
|
|
|
for (size_t i = 0; i < mCurrentInputTargets.size(); i++) {
|
|
|
|
const InputTarget& inputTarget = mCurrentInputTargets[i];
|
|
|
|
if ((inputTarget.flags & InputTarget::FLAG_FOREGROUND) == 0) {
|
|
|
|
// Skip non-foreground targets. We only want to stream if there is at
|
|
|
|
// least one foreground target whose dispatch is still in progress.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t connectionIndex = getConnectionIndexLocked(inputTarget.inputChannel);
|
|
|
|
if (connectionIndex < 0) {
|
|
|
|
// Connection must no longer be valid.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
sp<Connection> connection = mConnectionsByReceiveFd.valueAt(connectionIndex);
|
|
|
|
if (connection->outboundQueue.isEmpty()) {
|
|
|
|
// This foreground target has an empty outbound queue.
|
|
|
|
continue;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
2010-09-15 22:18:56 +00:00
|
|
|
|
|
|
|
DispatchEntry* dispatchEntry = connection->outboundQueue.headSentinel.next;
|
|
|
|
if (! dispatchEntry->inProgress
|
2010-09-27 05:20:12 +00:00
|
|
|
|| dispatchEntry->eventEntry->type != EventEntry::TYPE_MOTION
|
|
|
|
|| dispatchEntry->isSplit()) {
|
|
|
|
// No motion event is being dispatched, or it is being split across
|
|
|
|
// windows in which case we cannot stream.
|
2010-09-15 22:18:56 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
MotionEntry* motionEntry = static_cast<MotionEntry*>(
|
|
|
|
dispatchEntry->eventEntry);
|
|
|
|
if (motionEntry->action != AMOTION_EVENT_ACTION_MOVE
|
|
|
|
|| motionEntry->deviceId != deviceId
|
|
|
|
|| motionEntry->pointerCount != pointerCount
|
|
|
|
|| motionEntry->isInjected()) {
|
|
|
|
// The motion event is not compatible with this move.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hurray! This foreground target is currently dispatching a move event
|
|
|
|
// that we can stream onto. Append the motion sample and resume dispatch.
|
|
|
|
mAllocator.appendMotionSample(motionEntry, eventTime, pointerCoords);
|
|
|
|
#if DEBUG_BATCHING
|
|
|
|
LOGD("Appended motion sample onto batch for most recently dispatched "
|
|
|
|
"motion event for this device in the outbound queues. "
|
|
|
|
"Attempting to stream the motion sample.");
|
|
|
|
#endif
|
|
|
|
nsecs_t currentTime = now();
|
|
|
|
dispatchEventToCurrentInputTargetsLocked(currentTime, motionEntry,
|
|
|
|
true /*resumeWithAppendedMotionSample*/);
|
|
|
|
|
|
|
|
runCommandsLockedInterruptible();
|
|
|
|
return; // done!
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NoBatchingOrStreaming:;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Just enqueue a new motion event.
|
2010-06-18 03:52:56 +00:00
|
|
|
MotionEntry* newEntry = mAllocator.obtainMotionEntry(eventTime,
|
2010-09-02 00:01:00 +00:00
|
|
|
deviceId, source, policyFlags, action, flags, metaState, edgeFlags,
|
2010-06-18 03:52:56 +00:00
|
|
|
xPrecision, yPrecision, downTime,
|
|
|
|
pointerCount, pointerIds, pointerCoords);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
needWake = enqueueInboundEventLocked(newEntry);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
} // release lock
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
if (needWake) {
|
2010-09-14 06:17:30 +00:00
|
|
|
mLooper->wake();
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-09 05:31:17 +00:00
|
|
|
void InputDispatcher::notifySwitch(nsecs_t when, int32_t switchCode, int32_t switchValue,
|
|
|
|
uint32_t policyFlags) {
|
|
|
|
#if DEBUG_INBOUND_EVENT_DETAILS
|
|
|
|
LOGD("notifySwitch - switchCode=%d, switchValue=%d, policyFlags=0x%x",
|
|
|
|
switchCode, switchValue, policyFlags);
|
|
|
|
#endif
|
|
|
|
|
2010-10-11 21:20:19 +00:00
|
|
|
policyFlags |= POLICY_FLAG_TRUSTED;
|
2010-10-09 05:31:17 +00:00
|
|
|
mPolicy->notifySwitch(when, switchCode, switchValue, policyFlags);
|
|
|
|
}
|
|
|
|
|
2010-06-18 03:52:56 +00:00
|
|
|
int32_t InputDispatcher::injectInputEvent(const InputEvent* event,
|
2010-07-28 22:48:59 +00:00
|
|
|
int32_t injectorPid, int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis) {
|
2010-06-18 03:52:56 +00:00
|
|
|
#if DEBUG_INBOUND_EVENT_DETAILS
|
|
|
|
LOGD("injectInputEvent - eventType=%d, injectorPid=%d, injectorUid=%d, "
|
2010-07-28 22:48:59 +00:00
|
|
|
"syncMode=%d, timeoutMillis=%d",
|
|
|
|
event->getType(), injectorPid, injectorUid, syncMode, timeoutMillis);
|
2010-06-18 03:52:56 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
nsecs_t endTime = now() + milliseconds_to_nanoseconds(timeoutMillis);
|
2010-10-11 21:20:19 +00:00
|
|
|
|
|
|
|
uint32_t policyFlags = POLICY_FLAG_INJECTED;
|
|
|
|
if (hasInjectionPermission(injectorPid, injectorUid)) {
|
|
|
|
policyFlags |= POLICY_FLAG_TRUSTED;
|
|
|
|
}
|
2010-06-18 03:52:56 +00:00
|
|
|
|
2010-10-09 05:31:17 +00:00
|
|
|
EventEntry* injectedEntry;
|
|
|
|
switch (event->getType()) {
|
|
|
|
case AINPUT_EVENT_TYPE_KEY: {
|
|
|
|
const KeyEvent* keyEvent = static_cast<const KeyEvent*>(event);
|
|
|
|
int32_t action = keyEvent->getAction();
|
|
|
|
if (! validateKeyEvent(action)) {
|
|
|
|
return INPUT_EVENT_INJECTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsecs_t eventTime = keyEvent->getEventTime();
|
|
|
|
int32_t deviceId = keyEvent->getDeviceId();
|
|
|
|
int32_t flags = keyEvent->getFlags();
|
|
|
|
int32_t keyCode = keyEvent->getKeyCode();
|
|
|
|
int32_t scanCode = keyEvent->getScanCode();
|
2010-10-11 21:20:19 +00:00
|
|
|
mPolicy->interceptKeyBeforeQueueing(eventTime, deviceId, action, /*byref*/ flags,
|
|
|
|
keyCode, scanCode, /*byref*/ policyFlags);
|
2010-06-18 03:52:56 +00:00
|
|
|
|
2010-10-09 05:31:17 +00:00
|
|
|
mLock.lock();
|
|
|
|
injectedEntry = mAllocator.obtainKeyEntry(eventTime, deviceId, keyEvent->getSource(),
|
|
|
|
policyFlags, action, flags, keyCode, scanCode, keyEvent->getMetaState(),
|
|
|
|
keyEvent->getRepeatCount(), keyEvent->getDownTime());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case AINPUT_EVENT_TYPE_MOTION: {
|
|
|
|
const MotionEvent* motionEvent = static_cast<const MotionEvent*>(event);
|
|
|
|
int32_t action = motionEvent->getAction();
|
|
|
|
size_t pointerCount = motionEvent->getPointerCount();
|
|
|
|
const int32_t* pointerIds = motionEvent->getPointerIds();
|
|
|
|
if (! validateMotionEvent(action, pointerCount, pointerIds)) {
|
2010-09-08 18:49:43 +00:00
|
|
|
return INPUT_EVENT_INJECTION_FAILED;
|
|
|
|
}
|
|
|
|
|
2010-10-09 05:31:17 +00:00
|
|
|
nsecs_t eventTime = motionEvent->getEventTime();
|
2010-10-11 21:20:19 +00:00
|
|
|
mPolicy->interceptGenericBeforeQueueing(eventTime, /*byref*/ policyFlags);
|
2010-10-09 05:31:17 +00:00
|
|
|
|
|
|
|
mLock.lock();
|
|
|
|
const nsecs_t* sampleEventTimes = motionEvent->getSampleEventTimes();
|
|
|
|
const PointerCoords* samplePointerCoords = motionEvent->getSamplePointerCoords();
|
|
|
|
MotionEntry* motionEntry = mAllocator.obtainMotionEntry(*sampleEventTimes,
|
|
|
|
motionEvent->getDeviceId(), motionEvent->getSource(), policyFlags,
|
|
|
|
action, motionEvent->getFlags(),
|
|
|
|
motionEvent->getMetaState(), motionEvent->getEdgeFlags(),
|
|
|
|
motionEvent->getXPrecision(), motionEvent->getYPrecision(),
|
|
|
|
motionEvent->getDownTime(), uint32_t(pointerCount),
|
|
|
|
pointerIds, samplePointerCoords);
|
|
|
|
for (size_t i = motionEvent->getHistorySize(); i > 0; i--) {
|
|
|
|
sampleEventTimes += 1;
|
|
|
|
samplePointerCoords += pointerCount;
|
|
|
|
mAllocator.appendMotionSample(motionEntry, *sampleEventTimes, samplePointerCoords);
|
2010-07-28 22:48:59 +00:00
|
|
|
}
|
2010-10-09 05:31:17 +00:00
|
|
|
injectedEntry = motionEntry;
|
|
|
|
break;
|
|
|
|
}
|
2010-07-28 22:48:59 +00:00
|
|
|
|
2010-10-09 05:31:17 +00:00
|
|
|
default:
|
|
|
|
LOGW("Cannot inject event of type %d", event->getType());
|
|
|
|
return INPUT_EVENT_INJECTION_FAILED;
|
|
|
|
}
|
2010-09-27 05:20:12 +00:00
|
|
|
|
2010-10-09 05:31:17 +00:00
|
|
|
InjectionState* injectionState = mAllocator.obtainInjectionState(injectorPid, injectorUid);
|
|
|
|
if (syncMode == INPUT_EVENT_INJECTION_SYNC_NONE) {
|
|
|
|
injectionState->injectionIsAsync = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
injectionState->refCount += 1;
|
|
|
|
injectedEntry->injectionState = injectionState;
|
|
|
|
|
|
|
|
bool needWake = enqueueInboundEventLocked(injectedEntry);
|
|
|
|
mLock.unlock();
|
2010-06-18 03:52:56 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
if (needWake) {
|
2010-09-14 06:17:30 +00:00
|
|
|
mLooper->wake();
|
2010-06-18 03:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t injectionResult;
|
|
|
|
{ // acquire lock
|
|
|
|
AutoMutex _l(mLock);
|
|
|
|
|
2010-07-28 22:48:59 +00:00
|
|
|
if (syncMode == INPUT_EVENT_INJECTION_SYNC_NONE) {
|
|
|
|
injectionResult = INPUT_EVENT_INJECTION_SUCCEEDED;
|
|
|
|
} else {
|
|
|
|
for (;;) {
|
2010-09-27 05:20:12 +00:00
|
|
|
injectionResult = injectionState->injectionResult;
|
2010-07-28 22:48:59 +00:00
|
|
|
if (injectionResult != INPUT_EVENT_INJECTION_PENDING) {
|
|
|
|
break;
|
|
|
|
}
|
2010-06-18 03:52:56 +00:00
|
|
|
|
|
|
|
nsecs_t remainingTimeout = endTime - now();
|
|
|
|
if (remainingTimeout <= 0) {
|
2010-07-28 22:48:59 +00:00
|
|
|
#if DEBUG_INJECTION
|
|
|
|
LOGD("injectInputEvent - Timed out waiting for injection result "
|
|
|
|
"to become available.");
|
|
|
|
#endif
|
2010-06-18 03:52:56 +00:00
|
|
|
injectionResult = INPUT_EVENT_INJECTION_TIMED_OUT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-07-28 22:48:59 +00:00
|
|
|
mInjectionResultAvailableCondition.waitRelative(mLock, remainingTimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (injectionResult == INPUT_EVENT_INJECTION_SUCCEEDED
|
|
|
|
&& syncMode == INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISHED) {
|
2010-09-27 05:20:12 +00:00
|
|
|
while (injectionState->pendingForegroundDispatches != 0) {
|
2010-07-28 22:48:59 +00:00
|
|
|
#if DEBUG_INJECTION
|
2010-09-15 22:18:56 +00:00
|
|
|
LOGD("injectInputEvent - Waiting for %d pending foreground dispatches.",
|
2010-09-27 05:20:12 +00:00
|
|
|
injectionState->pendingForegroundDispatches);
|
2010-07-28 22:48:59 +00:00
|
|
|
#endif
|
|
|
|
nsecs_t remainingTimeout = endTime - now();
|
|
|
|
if (remainingTimeout <= 0) {
|
|
|
|
#if DEBUG_INJECTION
|
2010-09-15 22:18:56 +00:00
|
|
|
LOGD("injectInputEvent - Timed out waiting for pending foreground "
|
2010-07-28 22:48:59 +00:00
|
|
|
"dispatches to finish.");
|
|
|
|
#endif
|
|
|
|
injectionResult = INPUT_EVENT_INJECTION_TIMED_OUT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mInjectionSyncFinishedCondition.waitRelative(mLock, remainingTimeout);
|
|
|
|
}
|
2010-06-18 03:52:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
mAllocator.releaseInjectionState(injectionState);
|
2010-06-18 03:52:56 +00:00
|
|
|
} // release lock
|
|
|
|
|
2010-07-28 22:48:59 +00:00
|
|
|
#if DEBUG_INJECTION
|
|
|
|
LOGD("injectInputEvent - Finished with result %d. "
|
|
|
|
"injectorPid=%d, injectorUid=%d",
|
|
|
|
injectionResult, injectorPid, injectorUid);
|
|
|
|
#endif
|
|
|
|
|
2010-06-18 03:52:56 +00:00
|
|
|
return injectionResult;
|
|
|
|
}
|
|
|
|
|
2010-10-09 05:31:17 +00:00
|
|
|
bool InputDispatcher::hasInjectionPermission(int32_t injectorPid, int32_t injectorUid) {
|
|
|
|
return injectorUid == 0
|
|
|
|
|| mPolicy->checkInjectEventsPermissionNonReentrant(injectorPid, injectorUid);
|
|
|
|
}
|
|
|
|
|
2010-06-18 03:52:56 +00:00
|
|
|
void InputDispatcher::setInjectionResultLocked(EventEntry* entry, int32_t injectionResult) {
|
2010-09-27 05:20:12 +00:00
|
|
|
InjectionState* injectionState = entry->injectionState;
|
|
|
|
if (injectionState) {
|
2010-06-18 03:52:56 +00:00
|
|
|
#if DEBUG_INJECTION
|
|
|
|
LOGD("Setting input event injection result to %d. "
|
|
|
|
"injectorPid=%d, injectorUid=%d",
|
2010-09-27 05:20:12 +00:00
|
|
|
injectionResult, injectionState->injectorPid, injectionState->injectorUid);
|
2010-06-18 03:52:56 +00:00
|
|
|
#endif
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
if (injectionState->injectionIsAsync) {
|
2010-07-28 22:48:59 +00:00
|
|
|
// Log the outcome since the injector did not wait for the injection result.
|
|
|
|
switch (injectionResult) {
|
|
|
|
case INPUT_EVENT_INJECTION_SUCCEEDED:
|
|
|
|
LOGV("Asynchronous input event injection succeeded.");
|
|
|
|
break;
|
|
|
|
case INPUT_EVENT_INJECTION_FAILED:
|
|
|
|
LOGW("Asynchronous input event injection failed.");
|
|
|
|
break;
|
|
|
|
case INPUT_EVENT_INJECTION_PERMISSION_DENIED:
|
|
|
|
LOGW("Asynchronous input event injection permission denied.");
|
|
|
|
break;
|
|
|
|
case INPUT_EVENT_INJECTION_TIMED_OUT:
|
|
|
|
LOGW("Asynchronous input event injection timed out.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
injectionState->injectionResult = injectionResult;
|
2010-06-18 03:52:56 +00:00
|
|
|
mInjectionResultAvailableCondition.broadcast();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
void InputDispatcher::incrementPendingForegroundDispatchesLocked(EventEntry* entry) {
|
|
|
|
InjectionState* injectionState = entry->injectionState;
|
|
|
|
if (injectionState) {
|
|
|
|
injectionState->pendingForegroundDispatches += 1;
|
2010-07-28 22:48:59 +00:00
|
|
|
}
|
2010-06-18 03:52:56 +00:00
|
|
|
}
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
void InputDispatcher::decrementPendingForegroundDispatchesLocked(EventEntry* entry) {
|
|
|
|
InjectionState* injectionState = entry->injectionState;
|
|
|
|
if (injectionState) {
|
|
|
|
injectionState->pendingForegroundDispatches -= 1;
|
2010-09-08 18:49:43 +00:00
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
if (injectionState->pendingForegroundDispatches == 0) {
|
|
|
|
mInjectionSyncFinishedCondition.broadcast();
|
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
const InputWindow* InputDispatcher::getWindowLocked(const sp<InputChannel>& inputChannel) {
|
|
|
|
for (size_t i = 0; i < mWindows.size(); i++) {
|
|
|
|
const InputWindow* window = & mWindows[i];
|
|
|
|
if (window->inputChannel == inputChannel) {
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
void InputDispatcher::setInputWindows(const Vector<InputWindow>& inputWindows) {
|
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("setInputWindows");
|
|
|
|
#endif
|
|
|
|
{ // acquire lock
|
|
|
|
AutoMutex _l(mLock);
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
// Clear old window pointers.
|
2010-10-09 05:31:17 +00:00
|
|
|
sp<InputChannel> oldFocusedWindowChannel;
|
|
|
|
if (mFocusedWindow) {
|
|
|
|
oldFocusedWindowChannel = mFocusedWindow->inputChannel;
|
|
|
|
mFocusedWindow = NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
mWindows.clear();
|
2010-09-16 19:31:46 +00:00
|
|
|
|
|
|
|
// Loop over new windows and rebuild the necessary window pointers for
|
|
|
|
// tracking focus and touch.
|
2010-09-08 18:49:43 +00:00
|
|
|
mWindows.appendVector(inputWindows);
|
|
|
|
|
|
|
|
size_t numWindows = mWindows.size();
|
|
|
|
for (size_t i = 0; i < numWindows; i++) {
|
2010-09-27 05:20:12 +00:00
|
|
|
const InputWindow* window = & mWindows.itemAt(i);
|
2010-09-08 18:49:43 +00:00
|
|
|
if (window->hasFocus) {
|
|
|
|
mFocusedWindow = window;
|
2010-09-27 05:20:12 +00:00
|
|
|
break;
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
2010-09-27 05:20:12 +00:00
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
|
2010-10-09 05:31:17 +00:00
|
|
|
if (oldFocusedWindowChannel != NULL) {
|
|
|
|
if (!mFocusedWindow || oldFocusedWindowChannel != mFocusedWindow->inputChannel) {
|
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("Focus left window: %s",
|
|
|
|
oldFocusedWindowChannel->getName().string());
|
|
|
|
#endif
|
|
|
|
synthesizeCancelationEventsForInputChannelLocked(oldFocusedWindowChannel,
|
|
|
|
InputState::CANCEL_NON_POINTER_EVENTS, "focus left window");
|
|
|
|
oldFocusedWindowChannel.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mFocusedWindow && oldFocusedWindowChannel == NULL) {
|
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("Focus entered window: %s",
|
|
|
|
mFocusedWindow->inputChannel->getName().string());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
for (size_t i = 0; i < mTouchState.windows.size(); ) {
|
|
|
|
TouchedWindow& touchedWindow = mTouchState.windows.editItemAt(i);
|
|
|
|
const InputWindow* window = getWindowLocked(touchedWindow.channel);
|
|
|
|
if (window) {
|
|
|
|
touchedWindow.window = window;
|
|
|
|
i += 1;
|
|
|
|
} else {
|
2010-10-09 05:31:17 +00:00
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("Touched window was removed: %s", touchedWindow.channel->getName().string());
|
|
|
|
#endif
|
|
|
|
synthesizeCancelationEventsForInputChannelLocked(touchedWindow.channel,
|
|
|
|
InputState::CANCEL_POINTER_EVENTS, "touched window was removed");
|
2010-10-15 23:20:51 +00:00
|
|
|
mTouchState.windows.removeAt(i);
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG_FOCUS
|
2010-10-09 05:31:17 +00:00
|
|
|
//logDispatchStateLocked();
|
2010-09-08 18:49:43 +00:00
|
|
|
#endif
|
|
|
|
} // release lock
|
|
|
|
|
|
|
|
// Wake up poll loop since it may need to make new input dispatching choices.
|
2010-09-14 06:17:30 +00:00
|
|
|
mLooper->wake();
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::setFocusedApplication(const InputApplication* inputApplication) {
|
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("setFocusedApplication");
|
|
|
|
#endif
|
|
|
|
{ // acquire lock
|
|
|
|
AutoMutex _l(mLock);
|
|
|
|
|
|
|
|
releaseFocusedApplicationLocked();
|
|
|
|
|
|
|
|
if (inputApplication) {
|
|
|
|
mFocusedApplicationStorage = *inputApplication;
|
|
|
|
mFocusedApplication = & mFocusedApplicationStorage;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG_FOCUS
|
2010-10-09 05:31:17 +00:00
|
|
|
//logDispatchStateLocked();
|
2010-09-08 18:49:43 +00:00
|
|
|
#endif
|
|
|
|
} // release lock
|
|
|
|
|
|
|
|
// Wake up poll loop since it may need to make new input dispatching choices.
|
2010-09-14 06:17:30 +00:00
|
|
|
mLooper->wake();
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::releaseFocusedApplicationLocked() {
|
|
|
|
if (mFocusedApplication) {
|
|
|
|
mFocusedApplication = NULL;
|
|
|
|
mFocusedApplicationStorage.handle.clear();
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
void InputDispatcher::setInputDispatchMode(bool enabled, bool frozen) {
|
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("setInputDispatchMode: enabled=%d, frozen=%d", enabled, frozen);
|
2010-06-22 08:27:15 +00:00
|
|
|
#endif
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
bool changed;
|
2010-06-22 08:27:15 +00:00
|
|
|
{ // acquire lock
|
|
|
|
AutoMutex _l(mLock);
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
if (mDispatchEnabled != enabled || mDispatchFrozen != frozen) {
|
2010-10-28 01:43:51 +00:00
|
|
|
if (mDispatchFrozen && !frozen) {
|
2010-09-08 18:49:43 +00:00
|
|
|
resetANRTimeoutsLocked();
|
2010-06-22 08:27:15 +00:00
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
|
2010-10-28 01:43:51 +00:00
|
|
|
if (mDispatchEnabled && !enabled) {
|
|
|
|
resetAndDropEverythingLocked("dispatcher is being disabled");
|
|
|
|
}
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
mDispatchEnabled = enabled;
|
|
|
|
mDispatchFrozen = frozen;
|
|
|
|
changed = true;
|
|
|
|
} else {
|
|
|
|
changed = false;
|
2010-06-22 08:27:15 +00:00
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
|
|
|
|
#if DEBUG_FOCUS
|
2010-10-09 05:31:17 +00:00
|
|
|
//logDispatchStateLocked();
|
2010-09-08 18:49:43 +00:00
|
|
|
#endif
|
|
|
|
} // release lock
|
|
|
|
|
|
|
|
if (changed) {
|
|
|
|
// Wake up poll loop since it may need to make new input dispatching choices.
|
2010-09-14 06:17:30 +00:00
|
|
|
mLooper->wake();
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-27 21:52:15 +00:00
|
|
|
bool InputDispatcher::transferTouchFocus(const sp<InputChannel>& fromChannel,
|
|
|
|
const sp<InputChannel>& toChannel) {
|
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("transferTouchFocus: fromChannel=%s, toChannel=%s",
|
|
|
|
fromChannel->getName().string(), toChannel->getName().string());
|
|
|
|
#endif
|
|
|
|
{ // acquire lock
|
|
|
|
AutoMutex _l(mLock);
|
|
|
|
|
|
|
|
const InputWindow* fromWindow = getWindowLocked(fromChannel);
|
|
|
|
const InputWindow* toWindow = getWindowLocked(toChannel);
|
|
|
|
if (! fromWindow || ! toWindow) {
|
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("Cannot transfer focus because from or to window not found.");
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (fromWindow == toWindow) {
|
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("Trivial transfer to same window.");
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
for (size_t i = 0; i < mTouchState.windows.size(); i++) {
|
|
|
|
const TouchedWindow& touchedWindow = mTouchState.windows[i];
|
|
|
|
if (touchedWindow.window == fromWindow) {
|
|
|
|
int32_t oldTargetFlags = touchedWindow.targetFlags;
|
|
|
|
BitSet32 pointerIds = touchedWindow.pointerIds;
|
|
|
|
|
|
|
|
mTouchState.windows.removeAt(i);
|
|
|
|
|
|
|
|
int32_t newTargetFlags = 0;
|
|
|
|
if (oldTargetFlags & InputTarget::FLAG_FOREGROUND) {
|
|
|
|
newTargetFlags |= InputTarget::FLAG_FOREGROUND;
|
|
|
|
if (toWindow->layoutParamsFlags & InputWindow::FLAG_SPLIT_TOUCH) {
|
|
|
|
newTargetFlags |= InputTarget::FLAG_SPLIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mTouchState.addOrUpdateWindow(toWindow, newTargetFlags, pointerIds);
|
|
|
|
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! found) {
|
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("Focus transfer failed because from window did not have focus.");
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-10-12 01:32:20 +00:00
|
|
|
ssize_t fromConnectionIndex = getConnectionIndexLocked(fromChannel);
|
|
|
|
ssize_t toConnectionIndex = getConnectionIndexLocked(toChannel);
|
|
|
|
if (fromConnectionIndex >= 0 && toConnectionIndex >= 0) {
|
|
|
|
sp<Connection> fromConnection = mConnectionsByReceiveFd.valueAt(fromConnectionIndex);
|
|
|
|
sp<Connection> toConnection = mConnectionsByReceiveFd.valueAt(toConnectionIndex);
|
|
|
|
|
|
|
|
fromConnection->inputState.copyPointerStateTo(toConnection->inputState);
|
|
|
|
synthesizeCancelationEventsForConnectionLocked(fromConnection,
|
|
|
|
InputState::CANCEL_POINTER_EVENTS,
|
|
|
|
"transferring touch focus from this window to another window");
|
|
|
|
}
|
|
|
|
|
2010-09-27 21:52:15 +00:00
|
|
|
#if DEBUG_FOCUS
|
|
|
|
logDispatchStateLocked();
|
|
|
|
#endif
|
|
|
|
} // release lock
|
|
|
|
|
|
|
|
// Wake up poll loop since it may need to make new input dispatching choices.
|
|
|
|
mLooper->wake();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-28 01:43:51 +00:00
|
|
|
void InputDispatcher::resetAndDropEverythingLocked(const char* reason) {
|
|
|
|
#if DEBUG_FOCUS
|
|
|
|
LOGD("Resetting and dropping all events (%s).", reason);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
synthesizeCancelationEventsForAllConnectionsLocked(InputState::CANCEL_ALL_EVENTS, reason);
|
|
|
|
|
|
|
|
resetKeyRepeatLocked();
|
|
|
|
releasePendingEventLocked();
|
|
|
|
drainInboundQueueLocked();
|
|
|
|
resetTargetsLocked();
|
|
|
|
|
|
|
|
mTouchState.reset();
|
|
|
|
}
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
void InputDispatcher::logDispatchStateLocked() {
|
|
|
|
String8 dump;
|
|
|
|
dumpDispatchStateLocked(dump);
|
2010-09-16 19:31:46 +00:00
|
|
|
|
|
|
|
char* text = dump.lockBuffer(dump.size());
|
|
|
|
char* start = text;
|
|
|
|
while (*start != '\0') {
|
|
|
|
char* end = strchr(start, '\n');
|
|
|
|
if (*end == '\n') {
|
|
|
|
*(end++) = '\0';
|
|
|
|
}
|
|
|
|
LOGD("%s", start);
|
|
|
|
start = end;
|
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::dumpDispatchStateLocked(String8& dump) {
|
2010-10-02 00:46:21 +00:00
|
|
|
dump.appendFormat(INDENT "DispatchEnabled: %d\n", mDispatchEnabled);
|
|
|
|
dump.appendFormat(INDENT "DispatchFrozen: %d\n", mDispatchFrozen);
|
2010-09-08 18:49:43 +00:00
|
|
|
|
|
|
|
if (mFocusedApplication) {
|
2010-10-02 00:46:21 +00:00
|
|
|
dump.appendFormat(INDENT "FocusedApplication: name='%s', dispatchingTimeout=%0.3fms\n",
|
2010-09-08 18:49:43 +00:00
|
|
|
mFocusedApplication->name.string(),
|
|
|
|
mFocusedApplication->dispatchingTimeout / 1000000.0);
|
|
|
|
} else {
|
2010-10-02 00:46:21 +00:00
|
|
|
dump.append(INDENT "FocusedApplication: <null>\n");
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
2010-10-02 00:46:21 +00:00
|
|
|
dump.appendFormat(INDENT "FocusedWindow: name='%s'\n",
|
2010-09-16 19:31:46 +00:00
|
|
|
mFocusedWindow != NULL ? mFocusedWindow->name.string() : "<null>");
|
2010-10-02 00:46:21 +00:00
|
|
|
|
|
|
|
dump.appendFormat(INDENT "TouchDown: %s\n", toString(mTouchState.down));
|
|
|
|
dump.appendFormat(INDENT "TouchSplit: %s\n", toString(mTouchState.split));
|
|
|
|
if (!mTouchState.windows.isEmpty()) {
|
|
|
|
dump.append(INDENT "TouchedWindows:\n");
|
|
|
|
for (size_t i = 0; i < mTouchState.windows.size(); i++) {
|
|
|
|
const TouchedWindow& touchedWindow = mTouchState.windows[i];
|
|
|
|
dump.appendFormat(INDENT2 "%d: name='%s', pointerIds=0x%0x, targetFlags=0x%x\n",
|
|
|
|
i, touchedWindow.window->name.string(), touchedWindow.pointerIds.value,
|
|
|
|
touchedWindow.targetFlags);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dump.append(INDENT "TouchedWindows: <none>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mWindows.isEmpty()) {
|
|
|
|
dump.append(INDENT "Windows:\n");
|
|
|
|
for (size_t i = 0; i < mWindows.size(); i++) {
|
|
|
|
const InputWindow& window = mWindows[i];
|
|
|
|
dump.appendFormat(INDENT2 "%d: name='%s', paused=%s, hasFocus=%s, hasWallpaper=%s, "
|
|
|
|
"visible=%s, canReceiveKeys=%s, flags=0x%08x, type=0x%08x, layer=%d, "
|
|
|
|
"frame=[%d,%d][%d,%d], "
|
|
|
|
"visibleFrame=[%d,%d][%d,%d], "
|
|
|
|
"touchableArea=[%d,%d][%d,%d], "
|
|
|
|
"ownerPid=%d, ownerUid=%d, dispatchingTimeout=%0.3fms\n",
|
|
|
|
i, window.name.string(),
|
|
|
|
toString(window.paused),
|
|
|
|
toString(window.hasFocus),
|
|
|
|
toString(window.hasWallpaper),
|
|
|
|
toString(window.visible),
|
|
|
|
toString(window.canReceiveKeys),
|
|
|
|
window.layoutParamsFlags, window.layoutParamsType,
|
|
|
|
window.layer,
|
|
|
|
window.frameLeft, window.frameTop,
|
|
|
|
window.frameRight, window.frameBottom,
|
|
|
|
window.visibleFrameLeft, window.visibleFrameTop,
|
|
|
|
window.visibleFrameRight, window.visibleFrameBottom,
|
|
|
|
window.touchableAreaLeft, window.touchableAreaTop,
|
|
|
|
window.touchableAreaRight, window.touchableAreaBottom,
|
|
|
|
window.ownerPid, window.ownerUid,
|
|
|
|
window.dispatchingTimeout / 1000000.0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dump.append(INDENT "Windows: <none>\n");
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
2010-10-02 00:46:21 +00:00
|
|
|
if (!mMonitoringChannels.isEmpty()) {
|
|
|
|
dump.append(INDENT "MonitoringChannels:\n");
|
|
|
|
for (size_t i = 0; i < mMonitoringChannels.size(); i++) {
|
|
|
|
const sp<InputChannel>& channel = mMonitoringChannels[i];
|
|
|
|
dump.appendFormat(INDENT2 "%d: '%s'\n", i, channel->getName().string());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dump.append(INDENT "MonitoringChannels: <none>\n");
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
2010-10-02 00:46:21 +00:00
|
|
|
dump.appendFormat(INDENT "InboundQueue: length=%u\n", mInboundQueue.count());
|
2010-09-15 22:18:56 +00:00
|
|
|
|
2010-10-02 00:46:21 +00:00
|
|
|
if (!mActiveConnections.isEmpty()) {
|
|
|
|
dump.append(INDENT "ActiveConnections:\n");
|
|
|
|
for (size_t i = 0; i < mActiveConnections.size(); i++) {
|
|
|
|
const Connection* connection = mActiveConnections[i];
|
2010-10-26 00:37:46 +00:00
|
|
|
dump.appendFormat(INDENT2 "%d: '%s', status=%s, outboundQueueLength=%u, "
|
2010-10-09 05:31:17 +00:00
|
|
|
"inputState.isNeutral=%s\n",
|
2010-10-02 00:46:21 +00:00
|
|
|
i, connection->getInputChannelName(), connection->getStatusLabel(),
|
|
|
|
connection->outboundQueue.count(),
|
2010-10-09 05:31:17 +00:00
|
|
|
toString(connection->inputState.isNeutral()));
|
2010-10-02 00:46:21 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dump.append(INDENT "ActiveConnections: <none>\n");
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isAppSwitchPendingLocked()) {
|
2010-10-02 00:46:21 +00:00
|
|
|
dump.appendFormat(INDENT "AppSwitch: pending, due in %01.1fms\n",
|
2010-09-08 18:49:43 +00:00
|
|
|
(mAppSwitchDueTime - now()) / 1000000.0);
|
|
|
|
} else {
|
2010-10-02 00:46:21 +00:00
|
|
|
dump.append(INDENT "AppSwitch: not pending\n");
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t InputDispatcher::registerInputChannel(const sp<InputChannel>& inputChannel, bool monitor) {
|
2010-06-15 08:31:58 +00:00
|
|
|
#if DEBUG_REGISTRATION
|
2010-09-08 18:49:43 +00:00
|
|
|
LOGD("channel '%s' ~ registerInputChannel - monitor=%s", inputChannel->getName().string(),
|
|
|
|
toString(monitor));
|
2010-06-15 08:31:58 +00:00
|
|
|
#endif
|
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
{ // acquire lock
|
|
|
|
AutoMutex _l(mLock);
|
|
|
|
|
2010-09-15 22:18:56 +00:00
|
|
|
if (getConnectionIndexLocked(inputChannel) >= 0) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
LOGW("Attempted to register already registered input channel '%s'",
|
|
|
|
inputChannel->getName().string());
|
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
sp<Connection> connection = new Connection(inputChannel);
|
|
|
|
status_t status = connection->initialize();
|
|
|
|
if (status) {
|
|
|
|
LOGE("Failed to initialize input publisher for input channel '%s', status=%d",
|
|
|
|
inputChannel->getName().string(), status);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2010-08-17 22:59:26 +00:00
|
|
|
int32_t receiveFd = inputChannel->getReceivePipeFd();
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
mConnectionsByReceiveFd.add(receiveFd, connection);
|
2010-06-15 08:31:58 +00:00
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
if (monitor) {
|
|
|
|
mMonitoringChannels.push(inputChannel);
|
|
|
|
}
|
|
|
|
|
2010-09-14 06:17:30 +00:00
|
|
|
mLooper->addFd(receiveFd, 0, ALOOPER_EVENT_INPUT, handleReceiveCallback, this);
|
2010-08-17 22:59:26 +00:00
|
|
|
|
2010-06-15 08:31:58 +00:00
|
|
|
runCommandsLockedInterruptible();
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
} // release lock
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t InputDispatcher::unregisterInputChannel(const sp<InputChannel>& inputChannel) {
|
2010-06-15 08:31:58 +00:00
|
|
|
#if DEBUG_REGISTRATION
|
2010-06-22 08:27:15 +00:00
|
|
|
LOGD("channel '%s' ~ unregisterInputChannel", inputChannel->getName().string());
|
2010-06-15 08:31:58 +00:00
|
|
|
#endif
|
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
{ // acquire lock
|
|
|
|
AutoMutex _l(mLock);
|
|
|
|
|
2010-09-15 22:18:56 +00:00
|
|
|
ssize_t connectionIndex = getConnectionIndexLocked(inputChannel);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
if (connectionIndex < 0) {
|
|
|
|
LOGW("Attempted to unregister already unregistered input channel '%s'",
|
|
|
|
inputChannel->getName().string());
|
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
sp<Connection> connection = mConnectionsByReceiveFd.valueAt(connectionIndex);
|
|
|
|
mConnectionsByReceiveFd.removeItemsAt(connectionIndex);
|
|
|
|
|
|
|
|
connection->status = Connection::STATUS_ZOMBIE;
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
for (size_t i = 0; i < mMonitoringChannels.size(); i++) {
|
|
|
|
if (mMonitoringChannels[i] == inputChannel) {
|
|
|
|
mMonitoringChannels.removeAt(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-14 06:17:30 +00:00
|
|
|
mLooper->removeFd(inputChannel->getReceivePipeFd());
|
2010-08-17 22:59:26 +00:00
|
|
|
|
2010-06-18 03:52:56 +00:00
|
|
|
nsecs_t currentTime = now();
|
2010-10-09 05:31:17 +00:00
|
|
|
abortBrokenDispatchCycleLocked(currentTime, connection);
|
2010-06-15 08:31:58 +00:00
|
|
|
|
|
|
|
runCommandsLockedInterruptible();
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
} // release lock
|
|
|
|
|
|
|
|
// Wake the poll loop because removing the connection may have changed the current
|
|
|
|
// synchronization state.
|
2010-09-14 06:17:30 +00:00
|
|
|
mLooper->wake();
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2010-09-15 22:18:56 +00:00
|
|
|
ssize_t InputDispatcher::getConnectionIndexLocked(const sp<InputChannel>& inputChannel) {
|
2010-08-17 22:59:26 +00:00
|
|
|
ssize_t connectionIndex = mConnectionsByReceiveFd.indexOfKey(inputChannel->getReceivePipeFd());
|
|
|
|
if (connectionIndex >= 0) {
|
|
|
|
sp<Connection> connection = mConnectionsByReceiveFd.valueAt(connectionIndex);
|
|
|
|
if (connection->inputChannel.get() == inputChannel.get()) {
|
|
|
|
return connectionIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
void InputDispatcher::activateConnectionLocked(Connection* connection) {
|
|
|
|
for (size_t i = 0; i < mActiveConnections.size(); i++) {
|
|
|
|
if (mActiveConnections.itemAt(i) == connection) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mActiveConnections.add(connection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::deactivateConnectionLocked(Connection* connection) {
|
|
|
|
for (size_t i = 0; i < mActiveConnections.size(); i++) {
|
|
|
|
if (mActiveConnections.itemAt(i) == connection) {
|
|
|
|
mActiveConnections.removeAt(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-15 08:31:58 +00:00
|
|
|
void InputDispatcher::onDispatchCycleStartedLocked(
|
2010-06-18 03:52:56 +00:00
|
|
|
nsecs_t currentTime, const sp<Connection>& connection) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
2010-06-15 08:31:58 +00:00
|
|
|
void InputDispatcher::onDispatchCycleFinishedLocked(
|
2010-11-05 22:02:16 +00:00
|
|
|
nsecs_t currentTime, const sp<Connection>& connection, bool handled) {
|
|
|
|
CommandEntry* commandEntry = postCommandLocked(
|
|
|
|
& InputDispatcher::doDispatchCycleFinishedLockedInterruptible);
|
|
|
|
commandEntry->connection = connection;
|
|
|
|
commandEntry->handled = handled;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
2010-06-15 08:31:58 +00:00
|
|
|
void InputDispatcher::onDispatchCycleBrokenLocked(
|
2010-06-18 03:52:56 +00:00
|
|
|
nsecs_t currentTime, const sp<Connection>& connection) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
LOGE("channel '%s' ~ Channel is unrecoverably broken and will be disposed!",
|
|
|
|
connection->getInputChannelName());
|
|
|
|
|
2010-06-15 08:31:58 +00:00
|
|
|
CommandEntry* commandEntry = postCommandLocked(
|
|
|
|
& InputDispatcher::doNotifyInputChannelBrokenLockedInterruptible);
|
2010-06-18 03:52:56 +00:00
|
|
|
commandEntry->connection = connection;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
2010-09-15 22:18:56 +00:00
|
|
|
void InputDispatcher::onANRLocked(
|
|
|
|
nsecs_t currentTime, const InputApplication* application, const InputWindow* window,
|
|
|
|
nsecs_t eventTime, nsecs_t waitStartTime) {
|
|
|
|
LOGI("Application is not responding: %s. "
|
|
|
|
"%01.1fms since event, %01.1fms since wait started",
|
|
|
|
getApplicationWindowLabelLocked(application, window).string(),
|
|
|
|
(currentTime - eventTime) / 1000000.0,
|
|
|
|
(currentTime - waitStartTime) / 1000000.0);
|
|
|
|
|
|
|
|
CommandEntry* commandEntry = postCommandLocked(
|
|
|
|
& InputDispatcher::doNotifyANRLockedInterruptible);
|
|
|
|
if (application) {
|
|
|
|
commandEntry->inputApplicationHandle = application->handle;
|
|
|
|
}
|
|
|
|
if (window) {
|
|
|
|
commandEntry->inputChannel = window->inputChannel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
void InputDispatcher::doNotifyConfigurationChangedInterruptible(
|
|
|
|
CommandEntry* commandEntry) {
|
|
|
|
mLock.unlock();
|
|
|
|
|
|
|
|
mPolicy->notifyConfigurationChanged(commandEntry->eventTime);
|
|
|
|
|
|
|
|
mLock.lock();
|
|
|
|
}
|
|
|
|
|
2010-06-15 08:31:58 +00:00
|
|
|
void InputDispatcher::doNotifyInputChannelBrokenLockedInterruptible(
|
|
|
|
CommandEntry* commandEntry) {
|
2010-06-18 03:52:56 +00:00
|
|
|
sp<Connection> connection = commandEntry->connection;
|
2010-06-15 08:31:58 +00:00
|
|
|
|
2010-06-18 03:52:56 +00:00
|
|
|
if (connection->status != Connection::STATUS_ZOMBIE) {
|
|
|
|
mLock.unlock();
|
2010-06-15 08:31:58 +00:00
|
|
|
|
2010-06-18 03:52:56 +00:00
|
|
|
mPolicy->notifyInputChannelBroken(connection->inputChannel);
|
|
|
|
|
|
|
|
mLock.lock();
|
|
|
|
}
|
2010-06-15 08:31:58 +00:00
|
|
|
}
|
|
|
|
|
2010-09-15 22:18:56 +00:00
|
|
|
void InputDispatcher::doNotifyANRLockedInterruptible(
|
2010-06-15 08:31:58 +00:00
|
|
|
CommandEntry* commandEntry) {
|
2010-09-15 22:18:56 +00:00
|
|
|
mLock.unlock();
|
2010-06-15 08:31:58 +00:00
|
|
|
|
2010-09-15 22:18:56 +00:00
|
|
|
nsecs_t newTimeout = mPolicy->notifyANR(
|
|
|
|
commandEntry->inputApplicationHandle, commandEntry->inputChannel);
|
2010-06-15 08:31:58 +00:00
|
|
|
|
2010-09-15 22:18:56 +00:00
|
|
|
mLock.lock();
|
2010-06-18 03:52:56 +00:00
|
|
|
|
2010-09-15 22:18:56 +00:00
|
|
|
resumeAfterTargetsNotReadyTimeoutLocked(newTimeout, commandEntry->inputChannel);
|
2010-06-15 08:31:58 +00:00
|
|
|
}
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
void InputDispatcher::doInterceptKeyBeforeDispatchingLockedInterruptible(
|
|
|
|
CommandEntry* commandEntry) {
|
|
|
|
KeyEntry* entry = commandEntry->keyEntry;
|
2010-11-05 22:02:16 +00:00
|
|
|
initializeKeyEvent(&mReusableKeyEvent, entry);
|
2010-09-08 18:49:43 +00:00
|
|
|
|
|
|
|
mLock.unlock();
|
|
|
|
|
|
|
|
bool consumed = mPolicy->interceptKeyBeforeDispatching(commandEntry->inputChannel,
|
|
|
|
& mReusableKeyEvent, entry->policyFlags);
|
|
|
|
|
|
|
|
mLock.lock();
|
|
|
|
|
|
|
|
entry->interceptKeyResult = consumed
|
|
|
|
? KeyEntry::INTERCEPT_KEY_RESULT_SKIP
|
|
|
|
: KeyEntry::INTERCEPT_KEY_RESULT_CONTINUE;
|
|
|
|
mAllocator.releaseKeyEntry(entry);
|
|
|
|
}
|
|
|
|
|
2010-11-05 22:02:16 +00:00
|
|
|
void InputDispatcher::doDispatchCycleFinishedLockedInterruptible(
|
|
|
|
CommandEntry* commandEntry) {
|
|
|
|
sp<Connection> connection = commandEntry->connection;
|
|
|
|
bool handled = commandEntry->handled;
|
|
|
|
|
|
|
|
if (!handled && !connection->outboundQueue.isEmpty()) {
|
|
|
|
DispatchEntry* dispatchEntry = connection->outboundQueue.headSentinel.next;
|
|
|
|
if (dispatchEntry->inProgress
|
|
|
|
&& dispatchEntry->hasForegroundTarget()
|
|
|
|
&& dispatchEntry->eventEntry->type == EventEntry::TYPE_KEY) {
|
|
|
|
KeyEntry* keyEntry = static_cast<KeyEntry*>(dispatchEntry->eventEntry);
|
|
|
|
initializeKeyEvent(&mReusableKeyEvent, keyEntry);
|
|
|
|
|
|
|
|
mLock.unlock();
|
|
|
|
|
|
|
|
mPolicy->dispatchUnhandledKey(connection->inputChannel,
|
|
|
|
& mReusableKeyEvent, keyEntry->policyFlags);
|
|
|
|
|
|
|
|
mLock.lock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
startNextDispatchCycleLocked(now(), connection);
|
|
|
|
}
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
void InputDispatcher::doPokeUserActivityLockedInterruptible(CommandEntry* commandEntry) {
|
|
|
|
mLock.unlock();
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
mPolicy->pokeUserActivity(commandEntry->eventTime, commandEntry->userActivityEventType);
|
2010-09-08 18:49:43 +00:00
|
|
|
|
|
|
|
mLock.lock();
|
|
|
|
}
|
|
|
|
|
2010-11-05 22:02:16 +00:00
|
|
|
void InputDispatcher::initializeKeyEvent(KeyEvent* event, const KeyEntry* entry) {
|
|
|
|
event->initialize(entry->deviceId, entry->source, entry->action, entry->flags,
|
|
|
|
entry->keyCode, entry->scanCode, entry->metaState, entry->repeatCount,
|
|
|
|
entry->downTime, entry->eventTime);
|
|
|
|
}
|
|
|
|
|
2010-09-15 22:18:56 +00:00
|
|
|
void InputDispatcher::updateDispatchStatisticsLocked(nsecs_t currentTime, const EventEntry* entry,
|
|
|
|
int32_t injectionResult, nsecs_t timeSpentWaitingForApplication) {
|
|
|
|
// TODO Write some statistics about how long we spend waiting.
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::dump(String8& dump) {
|
2010-10-02 00:46:21 +00:00
|
|
|
dump.append("Input Dispatcher State:\n");
|
2010-09-08 18:49:43 +00:00
|
|
|
dumpDispatchStateLocked(dump);
|
|
|
|
}
|
|
|
|
|
2010-06-15 08:31:58 +00:00
|
|
|
|
2010-09-15 22:18:56 +00:00
|
|
|
// --- InputDispatcher::Queue ---
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
uint32_t InputDispatcher::Queue<T>::count() const {
|
|
|
|
uint32_t result = 0;
|
|
|
|
for (const T* entry = headSentinel.next; entry != & tailSentinel; entry = entry->next) {
|
|
|
|
result += 1;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
// --- InputDispatcher::Allocator ---
|
|
|
|
|
|
|
|
InputDispatcher::Allocator::Allocator() {
|
|
|
|
}
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
InputDispatcher::InjectionState*
|
|
|
|
InputDispatcher::Allocator::obtainInjectionState(int32_t injectorPid, int32_t injectorUid) {
|
|
|
|
InjectionState* injectionState = mInjectionStatePool.alloc();
|
|
|
|
injectionState->refCount = 1;
|
|
|
|
injectionState->injectorPid = injectorPid;
|
|
|
|
injectionState->injectorUid = injectorUid;
|
|
|
|
injectionState->injectionIsAsync = false;
|
|
|
|
injectionState->injectionResult = INPUT_EVENT_INJECTION_PENDING;
|
|
|
|
injectionState->pendingForegroundDispatches = 0;
|
|
|
|
return injectionState;
|
|
|
|
}
|
|
|
|
|
2010-06-18 03:52:56 +00:00
|
|
|
void InputDispatcher::Allocator::initializeEventEntry(EventEntry* entry, int32_t type,
|
2010-10-09 05:31:17 +00:00
|
|
|
nsecs_t eventTime, uint32_t policyFlags) {
|
2010-06-18 03:52:56 +00:00
|
|
|
entry->type = type;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
entry->refCount = 1;
|
2010-06-15 08:31:58 +00:00
|
|
|
entry->dispatchInProgress = false;
|
2010-06-23 23:50:30 +00:00
|
|
|
entry->eventTime = eventTime;
|
2010-10-09 05:31:17 +00:00
|
|
|
entry->policyFlags = policyFlags;
|
2010-09-27 05:20:12 +00:00
|
|
|
entry->injectionState = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::Allocator::releaseEventEntryInjectionState(EventEntry* entry) {
|
|
|
|
if (entry->injectionState) {
|
|
|
|
releaseInjectionState(entry->injectionState);
|
|
|
|
entry->injectionState = NULL;
|
|
|
|
}
|
2010-06-18 03:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InputDispatcher::ConfigurationChangedEntry*
|
|
|
|
InputDispatcher::Allocator::obtainConfigurationChangedEntry(nsecs_t eventTime) {
|
|
|
|
ConfigurationChangedEntry* entry = mConfigurationChangeEntryPool.alloc();
|
2010-10-09 05:31:17 +00:00
|
|
|
initializeEventEntry(entry, EventEntry::TYPE_CONFIGURATION_CHANGED, eventTime, 0);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2010-06-18 03:52:56 +00:00
|
|
|
InputDispatcher::KeyEntry* InputDispatcher::Allocator::obtainKeyEntry(nsecs_t eventTime,
|
2010-07-15 01:48:53 +00:00
|
|
|
int32_t deviceId, int32_t source, uint32_t policyFlags, int32_t action,
|
2010-06-18 03:52:56 +00:00
|
|
|
int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState,
|
|
|
|
int32_t repeatCount, nsecs_t downTime) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
KeyEntry* entry = mKeyEntryPool.alloc();
|
2010-10-09 05:31:17 +00:00
|
|
|
initializeEventEntry(entry, EventEntry::TYPE_KEY, eventTime, policyFlags);
|
2010-06-18 03:52:56 +00:00
|
|
|
|
|
|
|
entry->deviceId = deviceId;
|
2010-07-15 01:48:53 +00:00
|
|
|
entry->source = source;
|
2010-06-18 03:52:56 +00:00
|
|
|
entry->action = action;
|
|
|
|
entry->flags = flags;
|
|
|
|
entry->keyCode = keyCode;
|
|
|
|
entry->scanCode = scanCode;
|
|
|
|
entry->metaState = metaState;
|
|
|
|
entry->repeatCount = repeatCount;
|
|
|
|
entry->downTime = downTime;
|
2010-09-08 18:49:43 +00:00
|
|
|
entry->syntheticRepeat = false;
|
|
|
|
entry->interceptKeyResult = KeyEntry::INTERCEPT_KEY_RESULT_UNKNOWN;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2010-06-18 03:52:56 +00:00
|
|
|
InputDispatcher::MotionEntry* InputDispatcher::Allocator::obtainMotionEntry(nsecs_t eventTime,
|
2010-09-02 00:01:00 +00:00
|
|
|
int32_t deviceId, int32_t source, uint32_t policyFlags, int32_t action, int32_t flags,
|
2010-06-18 03:52:56 +00:00
|
|
|
int32_t metaState, int32_t edgeFlags, float xPrecision, float yPrecision,
|
|
|
|
nsecs_t downTime, uint32_t pointerCount,
|
|
|
|
const int32_t* pointerIds, const PointerCoords* pointerCoords) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
MotionEntry* entry = mMotionEntryPool.alloc();
|
2010-10-09 05:31:17 +00:00
|
|
|
initializeEventEntry(entry, EventEntry::TYPE_MOTION, eventTime, policyFlags);
|
2010-06-18 03:52:56 +00:00
|
|
|
|
|
|
|
entry->eventTime = eventTime;
|
|
|
|
entry->deviceId = deviceId;
|
2010-07-15 01:48:53 +00:00
|
|
|
entry->source = source;
|
2010-06-18 03:52:56 +00:00
|
|
|
entry->action = action;
|
2010-09-02 00:01:00 +00:00
|
|
|
entry->flags = flags;
|
2010-06-18 03:52:56 +00:00
|
|
|
entry->metaState = metaState;
|
|
|
|
entry->edgeFlags = edgeFlags;
|
|
|
|
entry->xPrecision = xPrecision;
|
|
|
|
entry->yPrecision = yPrecision;
|
|
|
|
entry->downTime = downTime;
|
|
|
|
entry->pointerCount = pointerCount;
|
|
|
|
entry->firstSample.eventTime = eventTime;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
entry->firstSample.next = NULL;
|
2010-06-18 03:52:56 +00:00
|
|
|
entry->lastSample = & entry->firstSample;
|
|
|
|
for (uint32_t i = 0; i < pointerCount; i++) {
|
|
|
|
entry->pointerIds[i] = pointerIds[i];
|
|
|
|
entry->firstSample.pointerCoords[i] = pointerCoords[i];
|
|
|
|
}
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
InputDispatcher::DispatchEntry* InputDispatcher::Allocator::obtainDispatchEntry(
|
2010-09-08 18:49:43 +00:00
|
|
|
EventEntry* eventEntry,
|
2010-09-15 22:18:56 +00:00
|
|
|
int32_t targetFlags, float xOffset, float yOffset) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
DispatchEntry* entry = mDispatchEntryPool.alloc();
|
|
|
|
entry->eventEntry = eventEntry;
|
|
|
|
eventEntry->refCount += 1;
|
2010-09-08 18:49:43 +00:00
|
|
|
entry->targetFlags = targetFlags;
|
|
|
|
entry->xOffset = xOffset;
|
|
|
|
entry->yOffset = yOffset;
|
|
|
|
entry->inProgress = false;
|
|
|
|
entry->headMotionSample = NULL;
|
|
|
|
entry->tailMotionSample = NULL;
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2010-06-15 08:31:58 +00:00
|
|
|
InputDispatcher::CommandEntry* InputDispatcher::Allocator::obtainCommandEntry(Command command) {
|
|
|
|
CommandEntry* entry = mCommandEntryPool.alloc();
|
|
|
|
entry->command = command;
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
void InputDispatcher::Allocator::releaseInjectionState(InjectionState* injectionState) {
|
|
|
|
injectionState->refCount -= 1;
|
|
|
|
if (injectionState->refCount == 0) {
|
|
|
|
mInjectionStatePool.free(injectionState);
|
|
|
|
} else {
|
|
|
|
assert(injectionState->refCount > 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
void InputDispatcher::Allocator::releaseEventEntry(EventEntry* entry) {
|
|
|
|
switch (entry->type) {
|
|
|
|
case EventEntry::TYPE_CONFIGURATION_CHANGED:
|
|
|
|
releaseConfigurationChangedEntry(static_cast<ConfigurationChangedEntry*>(entry));
|
|
|
|
break;
|
|
|
|
case EventEntry::TYPE_KEY:
|
|
|
|
releaseKeyEntry(static_cast<KeyEntry*>(entry));
|
|
|
|
break;
|
|
|
|
case EventEntry::TYPE_MOTION:
|
|
|
|
releaseMotionEntry(static_cast<MotionEntry*>(entry));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::Allocator::releaseConfigurationChangedEntry(
|
|
|
|
ConfigurationChangedEntry* entry) {
|
|
|
|
entry->refCount -= 1;
|
|
|
|
if (entry->refCount == 0) {
|
2010-09-27 05:20:12 +00:00
|
|
|
releaseEventEntryInjectionState(entry);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
mConfigurationChangeEntryPool.free(entry);
|
|
|
|
} else {
|
|
|
|
assert(entry->refCount > 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::Allocator::releaseKeyEntry(KeyEntry* entry) {
|
|
|
|
entry->refCount -= 1;
|
|
|
|
if (entry->refCount == 0) {
|
2010-09-27 05:20:12 +00:00
|
|
|
releaseEventEntryInjectionState(entry);
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
mKeyEntryPool.free(entry);
|
|
|
|
} else {
|
|
|
|
assert(entry->refCount > 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::Allocator::releaseMotionEntry(MotionEntry* entry) {
|
|
|
|
entry->refCount -= 1;
|
|
|
|
if (entry->refCount == 0) {
|
2010-09-27 05:20:12 +00:00
|
|
|
releaseEventEntryInjectionState(entry);
|
2010-06-15 08:31:58 +00:00
|
|
|
for (MotionSample* sample = entry->firstSample.next; sample != NULL; ) {
|
|
|
|
MotionSample* next = sample->next;
|
|
|
|
mMotionSamplePool.free(sample);
|
|
|
|
sample = next;
|
|
|
|
}
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
mMotionEntryPool.free(entry);
|
|
|
|
} else {
|
|
|
|
assert(entry->refCount > 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::Allocator::releaseDispatchEntry(DispatchEntry* entry) {
|
|
|
|
releaseEventEntry(entry->eventEntry);
|
|
|
|
mDispatchEntryPool.free(entry);
|
|
|
|
}
|
|
|
|
|
2010-06-15 08:31:58 +00:00
|
|
|
void InputDispatcher::Allocator::releaseCommandEntry(CommandEntry* entry) {
|
|
|
|
mCommandEntryPool.free(entry);
|
|
|
|
}
|
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
void InputDispatcher::Allocator::appendMotionSample(MotionEntry* motionEntry,
|
2010-06-18 03:52:56 +00:00
|
|
|
nsecs_t eventTime, const PointerCoords* pointerCoords) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
MotionSample* sample = mMotionSamplePool.alloc();
|
|
|
|
sample->eventTime = eventTime;
|
2010-06-18 03:52:56 +00:00
|
|
|
uint32_t pointerCount = motionEntry->pointerCount;
|
|
|
|
for (uint32_t i = 0; i < pointerCount; i++) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
sample->pointerCoords[i] = pointerCoords[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
sample->next = NULL;
|
|
|
|
motionEntry->lastSample->next = sample;
|
|
|
|
motionEntry->lastSample = sample;
|
|
|
|
}
|
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
void InputDispatcher::Allocator::recycleKeyEntry(KeyEntry* keyEntry) {
|
|
|
|
releaseEventEntryInjectionState(keyEntry);
|
2010-09-08 18:49:43 +00:00
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
keyEntry->dispatchInProgress = false;
|
|
|
|
keyEntry->syntheticRepeat = false;
|
|
|
|
keyEntry->interceptKeyResult = KeyEntry::INTERCEPT_KEY_RESULT_UNKNOWN;
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-18 22:51:08 +00:00
|
|
|
// --- InputDispatcher::MotionEntry ---
|
|
|
|
|
|
|
|
uint32_t InputDispatcher::MotionEntry::countSamples() const {
|
|
|
|
uint32_t count = 1;
|
|
|
|
for (MotionSample* sample = firstSample.next; sample != NULL; sample = sample->next) {
|
|
|
|
count += 1;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
|
|
|
|
// --- InputDispatcher::InputState ---
|
|
|
|
|
2010-10-09 05:31:17 +00:00
|
|
|
InputDispatcher::InputState::InputState() {
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InputDispatcher::InputState::~InputState() {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputDispatcher::InputState::isNeutral() const {
|
|
|
|
return mKeyMementos.isEmpty() && mMotionMementos.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
InputDispatcher::InputState::Consistency InputDispatcher::InputState::trackEvent(
|
|
|
|
const EventEntry* entry) {
|
|
|
|
switch (entry->type) {
|
|
|
|
case EventEntry::TYPE_KEY:
|
|
|
|
return trackKey(static_cast<const KeyEntry*>(entry));
|
|
|
|
|
|
|
|
case EventEntry::TYPE_MOTION:
|
|
|
|
return trackMotion(static_cast<const MotionEntry*>(entry));
|
|
|
|
|
|
|
|
default:
|
|
|
|
return CONSISTENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InputDispatcher::InputState::Consistency InputDispatcher::InputState::trackKey(
|
|
|
|
const KeyEntry* entry) {
|
|
|
|
int32_t action = entry->action;
|
|
|
|
for (size_t i = 0; i < mKeyMementos.size(); i++) {
|
|
|
|
KeyMemento& memento = mKeyMementos.editItemAt(i);
|
|
|
|
if (memento.deviceId == entry->deviceId
|
|
|
|
&& memento.source == entry->source
|
|
|
|
&& memento.keyCode == entry->keyCode
|
|
|
|
&& memento.scanCode == entry->scanCode) {
|
|
|
|
switch (action) {
|
|
|
|
case AKEY_EVENT_ACTION_UP:
|
|
|
|
mKeyMementos.removeAt(i);
|
|
|
|
return CONSISTENT;
|
|
|
|
|
|
|
|
case AKEY_EVENT_ACTION_DOWN:
|
|
|
|
return TOLERABLE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return BROKEN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
case AKEY_EVENT_ACTION_DOWN: {
|
|
|
|
mKeyMementos.push();
|
|
|
|
KeyMemento& memento = mKeyMementos.editTop();
|
|
|
|
memento.deviceId = entry->deviceId;
|
|
|
|
memento.source = entry->source;
|
|
|
|
memento.keyCode = entry->keyCode;
|
|
|
|
memento.scanCode = entry->scanCode;
|
|
|
|
memento.downTime = entry->downTime;
|
|
|
|
return CONSISTENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return BROKEN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InputDispatcher::InputState::Consistency InputDispatcher::InputState::trackMotion(
|
|
|
|
const MotionEntry* entry) {
|
|
|
|
int32_t action = entry->action & AMOTION_EVENT_ACTION_MASK;
|
|
|
|
for (size_t i = 0; i < mMotionMementos.size(); i++) {
|
|
|
|
MotionMemento& memento = mMotionMementos.editItemAt(i);
|
|
|
|
if (memento.deviceId == entry->deviceId
|
|
|
|
&& memento.source == entry->source) {
|
|
|
|
switch (action) {
|
|
|
|
case AMOTION_EVENT_ACTION_UP:
|
|
|
|
case AMOTION_EVENT_ACTION_CANCEL:
|
|
|
|
mMotionMementos.removeAt(i);
|
|
|
|
return CONSISTENT;
|
|
|
|
|
|
|
|
case AMOTION_EVENT_ACTION_DOWN:
|
|
|
|
return TOLERABLE;
|
|
|
|
|
|
|
|
case AMOTION_EVENT_ACTION_POINTER_DOWN:
|
|
|
|
if (entry->pointerCount == memento.pointerCount + 1) {
|
|
|
|
memento.setPointers(entry);
|
|
|
|
return CONSISTENT;
|
|
|
|
}
|
|
|
|
return BROKEN;
|
|
|
|
|
|
|
|
case AMOTION_EVENT_ACTION_POINTER_UP:
|
|
|
|
if (entry->pointerCount == memento.pointerCount - 1) {
|
|
|
|
memento.setPointers(entry);
|
|
|
|
return CONSISTENT;
|
|
|
|
}
|
|
|
|
return BROKEN;
|
|
|
|
|
|
|
|
case AMOTION_EVENT_ACTION_MOVE:
|
|
|
|
if (entry->pointerCount == memento.pointerCount) {
|
|
|
|
return CONSISTENT;
|
|
|
|
}
|
|
|
|
return BROKEN;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return BROKEN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
case AMOTION_EVENT_ACTION_DOWN: {
|
|
|
|
mMotionMementos.push();
|
|
|
|
MotionMemento& memento = mMotionMementos.editTop();
|
|
|
|
memento.deviceId = entry->deviceId;
|
|
|
|
memento.source = entry->source;
|
|
|
|
memento.xPrecision = entry->xPrecision;
|
|
|
|
memento.yPrecision = entry->yPrecision;
|
|
|
|
memento.downTime = entry->downTime;
|
|
|
|
memento.setPointers(entry);
|
|
|
|
return CONSISTENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return BROKEN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::InputState::MotionMemento::setPointers(const MotionEntry* entry) {
|
|
|
|
pointerCount = entry->pointerCount;
|
|
|
|
for (uint32_t i = 0; i < entry->pointerCount; i++) {
|
|
|
|
pointerIds[i] = entry->pointerIds[i];
|
|
|
|
pointerCoords[i] = entry->lastSample->pointerCoords[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-09 05:31:17 +00:00
|
|
|
void InputDispatcher::InputState::synthesizeCancelationEvents(nsecs_t currentTime,
|
|
|
|
Allocator* allocator, Vector<EventEntry*>& outEvents,
|
|
|
|
CancelationOptions options) {
|
|
|
|
for (size_t i = 0; i < mKeyMementos.size(); ) {
|
2010-09-08 18:49:43 +00:00
|
|
|
const KeyMemento& memento = mKeyMementos.itemAt(i);
|
2010-10-09 05:31:17 +00:00
|
|
|
if (shouldCancelEvent(memento.source, options)) {
|
|
|
|
outEvents.push(allocator->obtainKeyEntry(currentTime,
|
|
|
|
memento.deviceId, memento.source, 0,
|
|
|
|
AKEY_EVENT_ACTION_UP, AKEY_EVENT_FLAG_CANCELED,
|
|
|
|
memento.keyCode, memento.scanCode, 0, 0, memento.downTime));
|
|
|
|
mKeyMementos.removeAt(i);
|
|
|
|
} else {
|
|
|
|
i += 1;
|
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 01:22:53 +00:00
|
|
|
for (size_t i = 0; i < mMotionMementos.size(); ) {
|
2010-09-08 18:49:43 +00:00
|
|
|
const MotionMemento& memento = mMotionMementos.itemAt(i);
|
2010-10-09 05:31:17 +00:00
|
|
|
if (shouldCancelEvent(memento.source, options)) {
|
|
|
|
outEvents.push(allocator->obtainMotionEntry(currentTime,
|
|
|
|
memento.deviceId, memento.source, 0,
|
|
|
|
AMOTION_EVENT_ACTION_CANCEL, 0, 0, 0,
|
|
|
|
memento.xPrecision, memento.yPrecision, memento.downTime,
|
|
|
|
memento.pointerCount, memento.pointerIds, memento.pointerCoords));
|
|
|
|
mMotionMementos.removeAt(i);
|
|
|
|
} else {
|
|
|
|
i += 1;
|
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::InputState::clear() {
|
|
|
|
mKeyMementos.clear();
|
|
|
|
mMotionMementos.clear();
|
2010-10-09 05:31:17 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 01:32:20 +00:00
|
|
|
void InputDispatcher::InputState::copyPointerStateTo(InputState& other) const {
|
|
|
|
for (size_t i = 0; i < mMotionMementos.size(); i++) {
|
|
|
|
const MotionMemento& memento = mMotionMementos.itemAt(i);
|
|
|
|
if (memento.source & AINPUT_SOURCE_CLASS_POINTER) {
|
|
|
|
for (size_t j = 0; j < other.mMotionMementos.size(); ) {
|
|
|
|
const MotionMemento& otherMemento = other.mMotionMementos.itemAt(j);
|
|
|
|
if (memento.deviceId == otherMemento.deviceId
|
|
|
|
&& memento.source == otherMemento.source) {
|
|
|
|
other.mMotionMementos.removeAt(j);
|
|
|
|
} else {
|
|
|
|
j += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
other.mMotionMementos.push(memento);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-09 05:31:17 +00:00
|
|
|
bool InputDispatcher::InputState::shouldCancelEvent(int32_t eventSource,
|
|
|
|
CancelationOptions options) {
|
|
|
|
switch (options) {
|
|
|
|
case CANCEL_POINTER_EVENTS:
|
|
|
|
return eventSource & AINPUT_SOURCE_CLASS_POINTER;
|
|
|
|
case CANCEL_NON_POINTER_EVENTS:
|
|
|
|
return !(eventSource & AINPUT_SOURCE_CLASS_POINTER);
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
2010-09-08 18:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
// --- InputDispatcher::Connection ---
|
|
|
|
|
|
|
|
InputDispatcher::Connection::Connection(const sp<InputChannel>& inputChannel) :
|
|
|
|
status(STATUS_NORMAL), inputChannel(inputChannel), inputPublisher(inputChannel),
|
2010-09-15 22:18:56 +00:00
|
|
|
lastEventTime(LONG_LONG_MAX), lastDispatchTime(LONG_LONG_MAX) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InputDispatcher::Connection::~Connection() {
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t InputDispatcher::Connection::initialize() {
|
|
|
|
return inputPublisher.initialize();
|
|
|
|
}
|
|
|
|
|
2010-06-15 08:31:58 +00:00
|
|
|
const char* InputDispatcher::Connection::getStatusLabel() const {
|
|
|
|
switch (status) {
|
|
|
|
case STATUS_NORMAL:
|
|
|
|
return "NORMAL";
|
|
|
|
|
|
|
|
case STATUS_BROKEN:
|
|
|
|
return "BROKEN";
|
|
|
|
|
|
|
|
case STATUS_ZOMBIE:
|
|
|
|
return "ZOMBIE";
|
|
|
|
|
|
|
|
default:
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
InputDispatcher::DispatchEntry* InputDispatcher::Connection::findQueuedDispatchEntryForEvent(
|
|
|
|
const EventEntry* eventEntry) const {
|
2010-09-08 18:49:43 +00:00
|
|
|
for (DispatchEntry* dispatchEntry = outboundQueue.tailSentinel.prev;
|
|
|
|
dispatchEntry != & outboundQueue.headSentinel; dispatchEntry = dispatchEntry->prev) {
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
if (dispatchEntry->eventEntry == eventEntry) {
|
|
|
|
return dispatchEntry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
|
2010-06-15 08:31:58 +00:00
|
|
|
// --- InputDispatcher::CommandEntry ---
|
|
|
|
|
2010-09-08 18:49:43 +00:00
|
|
|
InputDispatcher::CommandEntry::CommandEntry() :
|
|
|
|
keyEntry(NULL) {
|
2010-06-15 08:31:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InputDispatcher::CommandEntry::~CommandEntry() {
|
|
|
|
}
|
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
|
2010-09-27 05:20:12 +00:00
|
|
|
// --- InputDispatcher::TouchState ---
|
|
|
|
|
|
|
|
InputDispatcher::TouchState::TouchState() :
|
|
|
|
down(false), split(false) {
|
|
|
|
}
|
|
|
|
|
|
|
|
InputDispatcher::TouchState::~TouchState() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::TouchState::reset() {
|
|
|
|
down = false;
|
|
|
|
split = false;
|
|
|
|
windows.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::TouchState::copyFrom(const TouchState& other) {
|
|
|
|
down = other.down;
|
|
|
|
split = other.split;
|
|
|
|
windows.clear();
|
|
|
|
windows.appendVector(other.windows);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::TouchState::addOrUpdateWindow(const InputWindow* window,
|
|
|
|
int32_t targetFlags, BitSet32 pointerIds) {
|
|
|
|
if (targetFlags & InputTarget::FLAG_SPLIT) {
|
|
|
|
split = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < windows.size(); i++) {
|
|
|
|
TouchedWindow& touchedWindow = windows.editItemAt(i);
|
|
|
|
if (touchedWindow.window == window) {
|
|
|
|
touchedWindow.targetFlags |= targetFlags;
|
|
|
|
touchedWindow.pointerIds.value |= pointerIds.value;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
windows.push();
|
|
|
|
|
|
|
|
TouchedWindow& touchedWindow = windows.editTop();
|
|
|
|
touchedWindow.window = window;
|
|
|
|
touchedWindow.targetFlags = targetFlags;
|
|
|
|
touchedWindow.pointerIds = pointerIds;
|
|
|
|
touchedWindow.channel = window->inputChannel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputDispatcher::TouchState::removeOutsideTouchWindows() {
|
|
|
|
for (size_t i = 0 ; i < windows.size(); ) {
|
|
|
|
if (windows[i].targetFlags & InputTarget::FLAG_OUTSIDE) {
|
|
|
|
windows.removeAt(i);
|
|
|
|
} else {
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const InputWindow* InputDispatcher::TouchState::getFirstForegroundWindow() {
|
|
|
|
for (size_t i = 0; i < windows.size(); i++) {
|
|
|
|
if (windows[i].targetFlags & InputTarget::FLAG_FOREGROUND) {
|
|
|
|
return windows[i].window;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Native input dispatch rewrite work in progress.
The old dispatch mechanism has been left in place and continues to
be used by default for now. To enable native input dispatch,
edit the ENABLE_NATIVE_DISPATCH constant in WindowManagerPolicy.
Includes part of the new input event NDK API. Some details TBD.
To wire up input dispatch, as the ViewRoot adds a window to the
window session it receives an InputChannel object as an output
argument. The InputChannel encapsulates the file descriptors for a
shared memory region and two pipe end-points. The ViewRoot then
provides the InputChannel to the InputQueue. Behind the
scenes, InputQueue simply attaches handlers to the native PollLoop object
that underlies the MessageQueue. This way MessageQueue doesn't need
to know anything about input dispatch per-se, it just exposes (in native
code) a PollLoop that other components can use to monitor file descriptor
state changes.
There can be zero or more targets for any given input event. Each
input target is specified by its input channel and some parameters
including flags, an X/Y coordinate offset, and the dispatch timeout.
An input target can request either synchronous dispatch (for foreground apps)
or asynchronous dispatch (fire-and-forget for wallpapers and "outside"
targets). Currently, finding the appropriate input targets for an event
requires a call back into the WindowManagerServer from native code.
In the future this will be refactored to avoid most of these callbacks
except as required to handle pending focus transitions.
End-to-end event dispatch mostly works!
To do: event injection, rate limiting, ANRs, testing, optimization, etc.
Change-Id: I8c36b2b9e0a2d27392040ecda0f51b636456de25
2010-04-23 01:58:52 +00:00
|
|
|
// --- InputDispatcherThread ---
|
|
|
|
|
|
|
|
InputDispatcherThread::InputDispatcherThread(const sp<InputDispatcherInterface>& dispatcher) :
|
|
|
|
Thread(/*canCallJava*/ true), mDispatcher(dispatcher) {
|
|
|
|
}
|
|
|
|
|
|
|
|
InputDispatcherThread::~InputDispatcherThread() {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputDispatcherThread::threadLoop() {
|
|
|
|
mDispatcher->dispatchOnce();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace android
|