2011-03-17 11:48:13 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
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-22 18:58:52 -07:00
|
|
|
|
2011-01-02 16:37:43 -08:00
|
|
|
#include "../InputDispatcher.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-22 18:58:52 -07:00
|
|
|
#include <gtest/gtest.h>
|
2010-10-20 15:33:38 -07:00
|
|
|
#include <linux/input.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-22 18:58:52 -07:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
2010-10-20 15:33:38 -07:00
|
|
|
// An arbitrary time value.
|
|
|
|
static const nsecs_t ARBITRARY_TIME = 1234;
|
|
|
|
|
|
|
|
// An arbitrary device id.
|
|
|
|
static const int32_t DEVICE_ID = 1;
|
|
|
|
|
|
|
|
// An arbitrary injector pid / uid pair that has permission to inject events.
|
|
|
|
static const int32_t INJECTOR_PID = 999;
|
|
|
|
static const int32_t INJECTOR_UID = 1001;
|
|
|
|
|
|
|
|
|
|
|
|
// --- FakeInputDispatcherPolicy ---
|
|
|
|
|
|
|
|
class FakeInputDispatcherPolicy : public InputDispatcherPolicyInterface {
|
2011-05-26 19:17:02 -07:00
|
|
|
InputDispatcherConfiguration mConfig;
|
|
|
|
|
2010-10-20 15:33:38 -07:00
|
|
|
protected:
|
|
|
|
virtual ~FakeInputDispatcherPolicy() {
|
|
|
|
}
|
|
|
|
|
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-22 18:58:52 -07:00
|
|
|
public:
|
2010-10-20 15:33:38 -07:00
|
|
|
FakeInputDispatcherPolicy() {
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual void notifyConfigurationChanged(nsecs_t when) {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
|
2013-09-10 16:44:24 -07:00
|
|
|
const sp<InputWindowHandle>& inputWindowHandle,
|
|
|
|
const String8& reason) {
|
2010-10-20 15:33:38 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-10 11:17:36 -08:00
|
|
|
virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
|
2010-10-20 15:33:38 -07:00
|
|
|
}
|
|
|
|
|
2011-05-26 19:17:02 -07:00
|
|
|
virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
|
|
|
|
*outConfig = mConfig;
|
2010-10-20 15:33:38 -07:00
|
|
|
}
|
|
|
|
|
2011-05-26 19:17:02 -07:00
|
|
|
virtual bool isKeyRepeatEnabled() {
|
|
|
|
return true;
|
2010-10-20 15:33:38 -07:00
|
|
|
}
|
|
|
|
|
2011-03-30 02:25:18 -07:00
|
|
|
virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-18 20:53:46 -08:00
|
|
|
virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags) {
|
2010-10-20 15:33:38 -07:00
|
|
|
}
|
|
|
|
|
2011-03-02 19:23:13 -08:00
|
|
|
virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
|
2010-10-20 15:33:38 -07:00
|
|
|
}
|
|
|
|
|
2011-10-12 13:57:59 -07:00
|
|
|
virtual nsecs_t interceptKeyBeforeDispatching(const sp<InputWindowHandle>& inputWindowHandle,
|
2010-10-20 15:33:38 -07:00
|
|
|
const KeyEvent* keyEvent, uint32_t policyFlags) {
|
2011-10-12 13:57:59 -07:00
|
|
|
return 0;
|
2010-10-20 15:33:38 -07:00
|
|
|
}
|
|
|
|
|
2011-01-10 11:17:36 -08:00
|
|
|
virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
|
2010-12-06 17:13:33 -08:00
|
|
|
const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
|
2010-11-05 15:02:16 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-10-20 15:33:38 -07:00
|
|
|
virtual void notifySwitch(nsecs_t when,
|
2012-09-27 20:46:43 -07:00
|
|
|
uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) {
|
2010-10-20 15:33:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool checkInjectEventsPermissionNonReentrant(
|
|
|
|
int32_t injectorPid, int32_t injectorUid) {
|
|
|
|
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-22 18:58:52 -07:00
|
|
|
};
|
|
|
|
|
2010-10-20 15:33:38 -07:00
|
|
|
|
|
|
|
// --- InputDispatcherTest ---
|
|
|
|
|
|
|
|
class InputDispatcherTest : public testing::Test {
|
|
|
|
protected:
|
|
|
|
sp<FakeInputDispatcherPolicy> mFakePolicy;
|
|
|
|
sp<InputDispatcher> mDispatcher;
|
|
|
|
|
|
|
|
virtual void SetUp() {
|
|
|
|
mFakePolicy = new FakeInputDispatcherPolicy();
|
|
|
|
mDispatcher = new InputDispatcher(mFakePolicy);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void TearDown() {
|
|
|
|
mFakePolicy.clear();
|
|
|
|
mDispatcher.clear();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InputDispatcherTest, InjectInputEvent_ValidatesKeyEvents) {
|
|
|
|
KeyEvent event;
|
|
|
|
|
|
|
|
// Rejects undefined key actions.
|
|
|
|
event.initialize(DEVICE_ID, AINPUT_SOURCE_KEYBOARD,
|
|
|
|
/*action*/ -1, 0,
|
|
|
|
AKEYCODE_A, KEY_A, AMETA_NONE, 0, ARBITRARY_TIME, ARBITRARY_TIME);
|
|
|
|
ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
|
2011-03-30 02:25:18 -07:00
|
|
|
INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
|
2010-10-20 15:33:38 -07:00
|
|
|
<< "Should reject key events with undefined action.";
|
|
|
|
|
|
|
|
// Rejects ACTION_MULTIPLE since it is not supported despite being defined in the API.
|
|
|
|
event.initialize(DEVICE_ID, AINPUT_SOURCE_KEYBOARD,
|
|
|
|
AKEY_EVENT_ACTION_MULTIPLE, 0,
|
|
|
|
AKEYCODE_A, KEY_A, AMETA_NONE, 0, ARBITRARY_TIME, ARBITRARY_TIME);
|
|
|
|
ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
|
2011-03-30 02:25:18 -07:00
|
|
|
INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
|
2010-10-20 15:33:38 -07:00
|
|
|
<< "Should reject key events with ACTION_MULTIPLE.";
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(InputDispatcherTest, InjectInputEvent_ValidatesMotionEvents) {
|
|
|
|
MotionEvent event;
|
2011-05-06 18:20:01 -07:00
|
|
|
PointerProperties pointerProperties[MAX_POINTERS + 1];
|
2010-10-20 15:33:38 -07:00
|
|
|
PointerCoords pointerCoords[MAX_POINTERS + 1];
|
|
|
|
for (int i = 0; i <= MAX_POINTERS; i++) {
|
2011-05-06 18:20:01 -07:00
|
|
|
pointerProperties[i].clear();
|
|
|
|
pointerProperties[i].id = i;
|
|
|
|
pointerCoords[i].clear();
|
2010-10-20 15:33:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Rejects undefined motion actions.
|
|
|
|
event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
|
2011-05-06 18:20:01 -07:00
|
|
|
/*action*/ -1, 0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
|
2010-10-20 15:33:38 -07:00
|
|
|
ARBITRARY_TIME, ARBITRARY_TIME,
|
2011-05-06 18:20:01 -07:00
|
|
|
/*pointerCount*/ 1, pointerProperties, pointerCoords);
|
2010-10-20 15:33:38 -07:00
|
|
|
ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
|
2011-03-30 02:25:18 -07:00
|
|
|
INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
|
2010-10-20 15:33:38 -07:00
|
|
|
<< "Should reject motion events with undefined action.";
|
|
|
|
|
|
|
|
// Rejects pointer down with invalid index.
|
|
|
|
event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
|
|
|
|
AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
|
2011-05-06 18:20:01 -07:00
|
|
|
0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
|
2010-10-20 15:33:38 -07:00
|
|
|
ARBITRARY_TIME, ARBITRARY_TIME,
|
2011-05-06 18:20:01 -07:00
|
|
|
/*pointerCount*/ 1, pointerProperties, pointerCoords);
|
2010-10-20 15:33:38 -07:00
|
|
|
ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
|
2011-03-30 02:25:18 -07:00
|
|
|
INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
|
2010-10-20 15:33:38 -07:00
|
|
|
<< "Should reject motion events with pointer down index too large.";
|
|
|
|
|
|
|
|
event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
|
|
|
|
AMOTION_EVENT_ACTION_POINTER_DOWN | (-1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
|
2011-05-06 18:20:01 -07:00
|
|
|
0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
|
2010-10-20 15:33:38 -07:00
|
|
|
ARBITRARY_TIME, ARBITRARY_TIME,
|
2011-05-06 18:20:01 -07:00
|
|
|
/*pointerCount*/ 1, pointerProperties, pointerCoords);
|
2010-10-20 15:33:38 -07:00
|
|
|
ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
|
2011-03-30 02:25:18 -07:00
|
|
|
INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
|
2010-10-20 15:33:38 -07:00
|
|
|
<< "Should reject motion events with pointer down index too small.";
|
|
|
|
|
|
|
|
// Rejects pointer up with invalid index.
|
|
|
|
event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
|
|
|
|
AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
|
2011-05-06 18:20:01 -07:00
|
|
|
0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
|
2010-10-20 15:33:38 -07:00
|
|
|
ARBITRARY_TIME, ARBITRARY_TIME,
|
2011-05-06 18:20:01 -07:00
|
|
|
/*pointerCount*/ 1, pointerProperties, pointerCoords);
|
2010-10-20 15:33:38 -07:00
|
|
|
ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
|
2011-03-30 02:25:18 -07:00
|
|
|
INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
|
2010-10-20 15:33:38 -07:00
|
|
|
<< "Should reject motion events with pointer up index too large.";
|
|
|
|
|
|
|
|
event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
|
|
|
|
AMOTION_EVENT_ACTION_POINTER_UP | (-1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
|
2011-05-06 18:20:01 -07:00
|
|
|
0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
|
2010-10-20 15:33:38 -07:00
|
|
|
ARBITRARY_TIME, ARBITRARY_TIME,
|
2011-05-06 18:20:01 -07:00
|
|
|
/*pointerCount*/ 1, pointerProperties, pointerCoords);
|
2010-10-20 15:33:38 -07:00
|
|
|
ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
|
2011-03-30 02:25:18 -07:00
|
|
|
INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
|
2010-10-20 15:33:38 -07:00
|
|
|
<< "Should reject motion events with pointer up index too small.";
|
|
|
|
|
|
|
|
// Rejects motion events with invalid number of pointers.
|
|
|
|
event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
|
2011-05-06 18:20:01 -07:00
|
|
|
AMOTION_EVENT_ACTION_DOWN, 0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
|
2010-10-20 15:33:38 -07:00
|
|
|
ARBITRARY_TIME, ARBITRARY_TIME,
|
2011-05-06 18:20:01 -07:00
|
|
|
/*pointerCount*/ 0, pointerProperties, pointerCoords);
|
2010-10-20 15:33:38 -07:00
|
|
|
ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
|
2011-03-30 02:25:18 -07:00
|
|
|
INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
|
2010-10-20 15:33:38 -07:00
|
|
|
<< "Should reject motion events with 0 pointers.";
|
|
|
|
|
|
|
|
event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
|
2011-05-06 18:20:01 -07:00
|
|
|
AMOTION_EVENT_ACTION_DOWN, 0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
|
2010-10-20 15:33:38 -07:00
|
|
|
ARBITRARY_TIME, ARBITRARY_TIME,
|
2011-05-06 18:20:01 -07:00
|
|
|
/*pointerCount*/ MAX_POINTERS + 1, pointerProperties, pointerCoords);
|
2010-10-20 15:33:38 -07:00
|
|
|
ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
|
2011-03-30 02:25:18 -07:00
|
|
|
INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
|
2010-10-20 15:33:38 -07:00
|
|
|
<< "Should reject motion events with more than MAX_POINTERS pointers.";
|
|
|
|
|
|
|
|
// Rejects motion events with invalid pointer ids.
|
2011-05-06 18:20:01 -07:00
|
|
|
pointerProperties[0].id = -1;
|
2010-10-20 15:33:38 -07:00
|
|
|
event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
|
2011-05-06 18:20:01 -07:00
|
|
|
AMOTION_EVENT_ACTION_DOWN, 0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
|
2010-10-20 15:33:38 -07:00
|
|
|
ARBITRARY_TIME, ARBITRARY_TIME,
|
2011-05-06 18:20:01 -07:00
|
|
|
/*pointerCount*/ 1, pointerProperties, pointerCoords);
|
2010-10-20 15:33:38 -07:00
|
|
|
ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
|
2011-03-30 02:25:18 -07:00
|
|
|
INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
|
2010-10-20 15:33:38 -07:00
|
|
|
<< "Should reject motion events with pointer ids less than 0.";
|
|
|
|
|
2011-05-06 18:20:01 -07:00
|
|
|
pointerProperties[0].id = MAX_POINTER_ID + 1;
|
2010-10-20 15:33:38 -07:00
|
|
|
event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
|
2011-05-06 18:20:01 -07:00
|
|
|
AMOTION_EVENT_ACTION_DOWN, 0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
|
2010-10-20 15:33:38 -07:00
|
|
|
ARBITRARY_TIME, ARBITRARY_TIME,
|
2011-05-06 18:20:01 -07:00
|
|
|
/*pointerCount*/ 1, pointerProperties, pointerCoords);
|
2010-10-20 15:33:38 -07:00
|
|
|
ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
|
2011-03-30 02:25:18 -07:00
|
|
|
INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
|
2010-10-20 15:33:38 -07:00
|
|
|
<< "Should reject motion events with pointer ids greater than MAX_POINTER_ID.";
|
|
|
|
|
|
|
|
// Rejects motion events with duplicate pointer ids.
|
2011-05-06 18:20:01 -07:00
|
|
|
pointerProperties[0].id = 1;
|
|
|
|
pointerProperties[1].id = 1;
|
2010-10-20 15:33:38 -07:00
|
|
|
event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
|
2011-05-06 18:20:01 -07:00
|
|
|
AMOTION_EVENT_ACTION_DOWN, 0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
|
2010-10-20 15:33:38 -07:00
|
|
|
ARBITRARY_TIME, ARBITRARY_TIME,
|
2011-05-06 18:20:01 -07:00
|
|
|
/*pointerCount*/ 2, pointerProperties, pointerCoords);
|
2010-10-20 15:33:38 -07:00
|
|
|
ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
|
2011-03-30 02:25:18 -07:00
|
|
|
INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
|
2010-10-20 15:33:38 -07:00
|
|
|
<< "Should reject motion events with duplicate pointer ids.";
|
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-22 18:58:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace android
|