2009-03-04 03:31:44 +00:00
|
|
|
//
|
|
|
|
// Copyright 2005 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// Handle events, like key input and vsync.
|
|
|
|
//
|
|
|
|
// The goal is to provide an optimized solution for Linux, not an
|
|
|
|
// implementation that works well across all platforms. We expect
|
|
|
|
// events to arrive on file descriptors, so that we can use a select()
|
|
|
|
// select() call to sleep.
|
|
|
|
//
|
|
|
|
// We can't select() on anything but network sockets in Windows, so we
|
|
|
|
// provide an alternative implementation of waitEvent for that platform.
|
|
|
|
//
|
|
|
|
#define LOG_TAG "EventHub"
|
|
|
|
|
|
|
|
//#define LOG_NDEBUG 0
|
|
|
|
|
|
|
|
#include <ui/EventHub.h>
|
2009-08-04 12:49:43 +00:00
|
|
|
#include <ui/KeycodeLabels.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
#include <hardware_legacy/power.h>
|
|
|
|
|
|
|
|
#include <cutils/properties.h>
|
|
|
|
#include <utils/Log.h>
|
|
|
|
#include <utils/Timers.h>
|
2009-06-01 02:13:00 +00:00
|
|
|
#include <utils/threads.h>
|
|
|
|
#include <utils/Errors.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <memory.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "KeyLayoutMap.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#ifdef HAVE_INOTIFY
|
|
|
|
# include <sys/inotify.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ANDROID_OS
|
|
|
|
# include <sys/limits.h> /* not part of Linux */
|
|
|
|
#endif
|
|
|
|
#include <sys/poll.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
/* this macro is used to tell if "bit" is set in "array"
|
|
|
|
* it selects a byte from the array, and does a boolean AND
|
|
|
|
* operation with a byte that only has the relevant bit set.
|
|
|
|
* eg. to check for the 12th bit, we do (array[1] & 1<<4)
|
|
|
|
*/
|
|
|
|
#define test_bit(bit, array) (array[bit/8] & (1<<(bit%8)))
|
|
|
|
|
2010-06-30 23:10:35 +00:00
|
|
|
/* this macro computes the number of bytes needed to represent a bit array of the specified size */
|
|
|
|
#define sizeof_bit_array(bits) ((bits + 7) / 8)
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
#define ID_MASK 0x0000ffff
|
|
|
|
#define SEQ_MASK 0x7fff0000
|
|
|
|
#define SEQ_SHIFT 16
|
|
|
|
|
2009-08-04 12:49:43 +00:00
|
|
|
#ifndef ABS_MT_TOUCH_MAJOR
|
|
|
|
#define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ABS_MT_POSITION_X
|
|
|
|
#define ABS_MT_POSITION_X 0x35 /* Center X ellipse position */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ABS_MT_POSITION_Y
|
|
|
|
#define ABS_MT_POSITION_Y 0x36 /* Center Y ellipse position */
|
|
|
|
#endif
|
|
|
|
|
2010-10-02 00:46:21 +00:00
|
|
|
#define INDENT " "
|
|
|
|
#define INDENT2 " "
|
|
|
|
#define INDENT3 " "
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
namespace android {
|
|
|
|
|
|
|
|
static const char *WAKE_LOCK_ID = "KeyEvents";
|
|
|
|
static const char *device_path = "/dev/input";
|
|
|
|
|
|
|
|
/* return the larger integer */
|
|
|
|
static inline int max(int v1, int v2)
|
|
|
|
{
|
|
|
|
return (v1 > v2) ? v1 : v2;
|
|
|
|
}
|
|
|
|
|
2010-10-02 00:46:21 +00:00
|
|
|
static inline const char* toString(bool value) {
|
|
|
|
return value ? "true" : "false";
|
|
|
|
}
|
|
|
|
|
2009-08-06 21:50:08 +00:00
|
|
|
EventHub::device_t::device_t(int32_t _id, const char* _path, const char* name)
|
|
|
|
: id(_id), path(_path), name(name), classes(0)
|
2010-09-13 00:55:08 +00:00
|
|
|
, keyBitmask(NULL), layoutMap(new KeyLayoutMap()), defaultKeyMap(false), fd(-1), next(NULL) {
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EventHub::device_t::~device_t() {
|
|
|
|
delete [] keyBitmask;
|
|
|
|
delete layoutMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventHub::EventHub(void)
|
2010-09-13 00:55:08 +00:00
|
|
|
: mError(NO_INIT), mHaveFirstKeyboard(false), mFirstKeyboardId(-1)
|
2009-03-04 03:31:44 +00:00
|
|
|
, mDevicesById(0), mNumDevicesById(0)
|
|
|
|
, mOpeningDevices(0), mClosingDevices(0)
|
2010-10-02 01:55:43 +00:00
|
|
|
, mDevices(0), mFDs(0), mFDCount(0), mOpened(false), mNeedToSendFinishedDeviceScan(false)
|
2010-08-17 23:48:25 +00:00
|
|
|
, mInputBufferIndex(0), mInputBufferCount(0), mInputDeviceIndex(0)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
|
|
|
acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID);
|
|
|
|
#ifdef EV_SW
|
|
|
|
memset(mSwitches, 0, sizeof(mSwitches));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clean up.
|
|
|
|
*/
|
|
|
|
EventHub::~EventHub(void)
|
|
|
|
{
|
|
|
|
release_wake_lock(WAKE_LOCK_ID);
|
|
|
|
// we should free stuff here...
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t EventHub::errorCheck() const
|
|
|
|
{
|
|
|
|
return mError;
|
|
|
|
}
|
|
|
|
|
|
|
|
String8 EventHub::getDeviceName(int32_t deviceId) const
|
|
|
|
{
|
|
|
|
AutoMutex _l(mLock);
|
2010-10-02 00:46:21 +00:00
|
|
|
device_t* device = getDeviceLocked(deviceId);
|
2009-03-04 03:31:44 +00:00
|
|
|
if (device == NULL) return String8();
|
|
|
|
return device->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t EventHub::getDeviceClasses(int32_t deviceId) const
|
|
|
|
{
|
|
|
|
AutoMutex _l(mLock);
|
2010-10-02 00:46:21 +00:00
|
|
|
device_t* device = getDeviceLocked(deviceId);
|
2009-03-04 03:31:44 +00:00
|
|
|
if (device == NULL) return 0;
|
|
|
|
return device->classes;
|
|
|
|
}
|
|
|
|
|
2010-07-24 04:28:06 +00:00
|
|
|
status_t EventHub::getAbsoluteAxisInfo(int32_t deviceId, int axis,
|
|
|
|
RawAbsoluteAxisInfo* outAxisInfo) const {
|
2010-08-30 10:02:23 +00:00
|
|
|
outAxisInfo->clear();
|
2010-07-24 04:28:06 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
AutoMutex _l(mLock);
|
2010-10-02 00:46:21 +00:00
|
|
|
device_t* device = getDeviceLocked(deviceId);
|
2009-03-04 03:31:44 +00:00
|
|
|
if (device == NULL) return -1;
|
|
|
|
|
|
|
|
struct input_absinfo info;
|
|
|
|
|
2010-06-22 20:21:57 +00:00
|
|
|
if(ioctl(device->fd, EVIOCGABS(axis), &info)) {
|
2010-07-24 04:28:06 +00:00
|
|
|
LOGW("Error reading absolute controller %d for device %s fd %d\n",
|
2010-06-22 20:21:57 +00:00
|
|
|
axis, device->name.string(), device->fd);
|
2010-07-24 04:28:06 +00:00
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info.minimum != info.maximum) {
|
|
|
|
outAxisInfo->valid = true;
|
|
|
|
outAxisInfo->minValue = info.minimum;
|
|
|
|
outAxisInfo->maxValue = info.maximum;
|
|
|
|
outAxisInfo->flat = info.flat;
|
|
|
|
outAxisInfo->fuzz = info.fuzz;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2010-07-24 04:28:06 +00:00
|
|
|
return OK;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2010-07-24 04:28:06 +00:00
|
|
|
int32_t EventHub::getScanCodeState(int32_t deviceId, int32_t scanCode) const {
|
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 (scanCode >= 0 && scanCode <= KEY_MAX) {
|
|
|
|
AutoMutex _l(mLock);
|
|
|
|
|
2010-10-02 00:46:21 +00:00
|
|
|
device_t* device = getDeviceLocked(deviceId);
|
2010-07-24 04:28:06 +00:00
|
|
|
if (device != NULL) {
|
|
|
|
return getScanCodeStateLocked(device, scanCode);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
2010-07-15 01:48:53 +00:00
|
|
|
return AKEY_STATE_UNKNOWN;
|
2009-03-04 03:31:44 +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
|
|
|
int32_t EventHub::getScanCodeStateLocked(device_t* device, int32_t scanCode) const {
|
2010-06-30 23:10:35 +00:00
|
|
|
uint8_t key_bitmask[sizeof_bit_array(KEY_MAX + 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
|
|
|
memset(key_bitmask, 0, sizeof(key_bitmask));
|
2010-06-22 20:21:57 +00:00
|
|
|
if (ioctl(device->fd,
|
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
|
|
|
EVIOCGKEY(sizeof(key_bitmask)), key_bitmask) >= 0) {
|
2010-07-15 01:48:53 +00:00
|
|
|
return test_bit(scanCode, key_bitmask) ? AKEY_STATE_DOWN : AKEY_STATE_UP;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2010-07-15 01:48:53 +00:00
|
|
|
return AKEY_STATE_UNKNOWN;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2010-07-24 04:28:06 +00:00
|
|
|
int32_t EventHub::getKeyCodeState(int32_t deviceId, int32_t keyCode) const {
|
|
|
|
AutoMutex _l(mLock);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-10-02 00:46:21 +00:00
|
|
|
device_t* device = getDeviceLocked(deviceId);
|
2010-07-24 04:28:06 +00:00
|
|
|
if (device != NULL) {
|
|
|
|
return getKeyCodeStateLocked(device, keyCode);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2010-07-15 01:48:53 +00:00
|
|
|
return AKEY_STATE_UNKNOWN;
|
2009-03-04 03:31:44 +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
|
|
|
int32_t EventHub::getKeyCodeStateLocked(device_t* device, int32_t keyCode) const {
|
2009-03-04 03:31:44 +00:00
|
|
|
Vector<int32_t> scanCodes;
|
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
|
|
|
device->layoutMap->findScancodes(keyCode, &scanCodes);
|
|
|
|
|
2010-06-30 23:10:35 +00:00
|
|
|
uint8_t key_bitmask[sizeof_bit_array(KEY_MAX + 1)];
|
2009-03-04 03:31:44 +00:00
|
|
|
memset(key_bitmask, 0, sizeof(key_bitmask));
|
2010-06-22 20:21:57 +00:00
|
|
|
if (ioctl(device->fd, EVIOCGKEY(sizeof(key_bitmask)), key_bitmask) >= 0) {
|
2009-03-04 03:31:44 +00:00
|
|
|
#if 0
|
|
|
|
for (size_t i=0; i<=KEY_MAX; i++) {
|
|
|
|
LOGI("(Scan code %d: down=%d)", i, test_bit(i, key_bitmask));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
const size_t N = scanCodes.size();
|
|
|
|
for (size_t i=0; i<N && i<=KEY_MAX; i++) {
|
|
|
|
int32_t sc = scanCodes.itemAt(i);
|
|
|
|
//LOGI("Code %d: down=%d", sc, test_bit(sc, key_bitmask));
|
|
|
|
if (sc >= 0 && sc <= KEY_MAX && test_bit(sc, key_bitmask)) {
|
2010-07-15 01:48:53 +00:00
|
|
|
return AKEY_STATE_DOWN;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
2010-07-15 01:48:53 +00:00
|
|
|
return AKEY_STATE_UP;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2010-07-15 01:48:53 +00:00
|
|
|
return AKEY_STATE_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
|
|
|
}
|
|
|
|
|
2010-07-24 04:28:06 +00:00
|
|
|
int32_t EventHub::getSwitchState(int32_t deviceId, int32_t sw) const {
|
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
|
|
|
#ifdef EV_SW
|
|
|
|
if (sw >= 0 && sw <= SW_MAX) {
|
|
|
|
AutoMutex _l(mLock);
|
|
|
|
|
2010-10-02 00:46:21 +00:00
|
|
|
device_t* device = getDeviceLocked(deviceId);
|
2010-07-24 04:28:06 +00:00
|
|
|
if (device != NULL) {
|
|
|
|
return getSwitchStateLocked(device, sw);
|
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-07-15 01:48:53 +00:00
|
|
|
return AKEY_STATE_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
|
|
|
}
|
|
|
|
|
|
|
|
int32_t EventHub::getSwitchStateLocked(device_t* device, int32_t sw) const {
|
2010-06-30 23:10:35 +00:00
|
|
|
uint8_t sw_bitmask[sizeof_bit_array(SW_MAX + 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
|
|
|
memset(sw_bitmask, 0, sizeof(sw_bitmask));
|
2010-06-22 20:21:57 +00:00
|
|
|
if (ioctl(device->fd,
|
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
|
|
|
EVIOCGSW(sizeof(sw_bitmask)), sw_bitmask) >= 0) {
|
2010-07-15 01:48:53 +00:00
|
|
|
return test_bit(sw, sw_bitmask) ? AKEY_STATE_DOWN : AKEY_STATE_UP;
|
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
|
|
|
return AKEY_STATE_UNKNOWN;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2010-07-24 04:28:06 +00:00
|
|
|
bool EventHub::markSupportedKeyCodes(int32_t deviceId, size_t numCodes,
|
|
|
|
const int32_t* keyCodes, uint8_t* outFlags) const {
|
|
|
|
AutoMutex _l(mLock);
|
|
|
|
|
2010-10-02 00:46:21 +00:00
|
|
|
device_t* device = getDeviceLocked(deviceId);
|
2010-07-24 04:28:06 +00:00
|
|
|
if (device != NULL) {
|
|
|
|
return markSupportedKeyCodesLocked(device, numCodes, keyCodes, outFlags);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EventHub::markSupportedKeyCodesLocked(device_t* device, size_t numCodes,
|
|
|
|
const int32_t* keyCodes, uint8_t* outFlags) const {
|
|
|
|
if (device->layoutMap == NULL || device->keyBitmask == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<int32_t> scanCodes;
|
|
|
|
for (size_t codeIndex = 0; codeIndex < numCodes; codeIndex++) {
|
|
|
|
scanCodes.clear();
|
|
|
|
|
|
|
|
status_t err = device->layoutMap->findScancodes(keyCodes[codeIndex], &scanCodes);
|
|
|
|
if (! err) {
|
|
|
|
// check the possible scan codes identified by the layout map against the
|
|
|
|
// map of codes actually emitted by the driver
|
|
|
|
for (size_t sc = 0; sc < scanCodes.size(); sc++) {
|
|
|
|
if (test_bit(scanCodes[sc], device->keyBitmask)) {
|
|
|
|
outFlags[codeIndex] = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-07-14 19:06:54 +00:00
|
|
|
status_t EventHub::scancodeToKeycode(int32_t deviceId, int scancode,
|
|
|
|
int32_t* outKeycode, uint32_t* outFlags) const
|
|
|
|
{
|
|
|
|
AutoMutex _l(mLock);
|
2010-10-02 00:46:21 +00:00
|
|
|
device_t* device = getDeviceLocked(deviceId);
|
2009-07-14 19:06:54 +00:00
|
|
|
|
|
|
|
if (device != NULL && device->layoutMap != NULL) {
|
|
|
|
status_t err = device->layoutMap->map(scancode, outKeycode, outFlags);
|
|
|
|
if (err == NO_ERROR) {
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mHaveFirstKeyboard) {
|
2010-10-02 00:46:21 +00:00
|
|
|
device = getDeviceLocked(mFirstKeyboardId);
|
2009-07-14 19:06:54 +00:00
|
|
|
|
|
|
|
if (device != NULL && device->layoutMap != NULL) {
|
|
|
|
status_t err = device->layoutMap->map(scancode, outKeycode, outFlags);
|
|
|
|
if (err == NO_ERROR) {
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*outKeycode = 0;
|
|
|
|
*outFlags = 0;
|
|
|
|
return NAME_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2009-07-16 15:11:18 +00:00
|
|
|
void EventHub::addExcludedDevice(const char* deviceName)
|
|
|
|
{
|
2010-10-02 00:46:21 +00:00
|
|
|
AutoMutex _l(mLock);
|
|
|
|
|
2009-07-16 15:11:18 +00:00
|
|
|
String8 name(deviceName);
|
|
|
|
mExcludedDevices.push_back(name);
|
|
|
|
}
|
|
|
|
|
2010-09-13 00:55:08 +00:00
|
|
|
bool EventHub::hasLed(int32_t deviceId, int32_t led) const {
|
|
|
|
AutoMutex _l(mLock);
|
|
|
|
device_t* device = getDeviceLocked(deviceId);
|
|
|
|
if (device) {
|
|
|
|
uint8_t bitmask[sizeof_bit_array(LED_MAX + 1)];
|
|
|
|
memset(bitmask, 0, sizeof(bitmask));
|
|
|
|
if (ioctl(device->fd, EVIOCGBIT(EV_LED, sizeof(bitmask)), bitmask) >= 0) {
|
|
|
|
if (test_bit(led, bitmask)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventHub::setLedState(int32_t deviceId, int32_t led, bool on) {
|
|
|
|
AutoMutex _l(mLock);
|
|
|
|
device_t* device = getDeviceLocked(deviceId);
|
|
|
|
if (device) {
|
|
|
|
struct input_event ev;
|
|
|
|
ev.time.tv_sec = 0;
|
|
|
|
ev.time.tv_usec = 0;
|
|
|
|
ev.type = EV_LED;
|
|
|
|
ev.code = led;
|
|
|
|
ev.value = on ? 1 : 0;
|
|
|
|
|
|
|
|
ssize_t nWrite;
|
|
|
|
do {
|
|
|
|
nWrite = write(device->fd, &ev, sizeof(struct input_event));
|
|
|
|
} while (nWrite == -1 && errno == EINTR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-02 00:46:21 +00:00
|
|
|
EventHub::device_t* EventHub::getDeviceLocked(int32_t deviceId) const
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
|
|
|
if (deviceId == 0) deviceId = mFirstKeyboardId;
|
|
|
|
int32_t id = deviceId & ID_MASK;
|
|
|
|
if (id >= mNumDevicesById || id < 0) return NULL;
|
|
|
|
device_t* dev = mDevicesById[id].device;
|
2009-03-25 23:21:55 +00:00
|
|
|
if (dev == NULL) return NULL;
|
2009-03-04 03:31:44 +00:00
|
|
|
if (dev->id == deviceId) {
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-07-24 04:28:06 +00:00
|
|
|
bool EventHub::getEvent(RawEvent* outEvent)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2010-07-24 04:28:06 +00:00
|
|
|
outEvent->deviceId = 0;
|
|
|
|
outEvent->type = 0;
|
|
|
|
outEvent->scanCode = 0;
|
|
|
|
outEvent->keyCode = 0;
|
|
|
|
outEvent->flags = 0;
|
|
|
|
outEvent->value = 0;
|
|
|
|
outEvent->when = 0;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
// Note that we only allow one caller to getEvent(), so don't need
|
|
|
|
// to do locking here... only when adding/removing devices.
|
2009-07-16 15:11:18 +00:00
|
|
|
|
|
|
|
if (!mOpened) {
|
|
|
|
mError = openPlatformInput() ? NO_ERROR : UNKNOWN_ERROR;
|
|
|
|
mOpened = true;
|
2010-10-02 01:55:43 +00:00
|
|
|
mNeedToSendFinishedDeviceScan = true;
|
2009-07-16 15:11:18 +00:00
|
|
|
}
|
|
|
|
|
2010-08-17 23:48:25 +00:00
|
|
|
for (;;) {
|
|
|
|
// Report any devices that had last been added/removed.
|
2009-03-04 03:31:44 +00:00
|
|
|
if (mClosingDevices != NULL) {
|
|
|
|
device_t* device = mClosingDevices;
|
|
|
|
LOGV("Reporting device closed: id=0x%x, name=%s\n",
|
|
|
|
device->id, device->path.string());
|
|
|
|
mClosingDevices = device->next;
|
2010-07-24 04:28:06 +00:00
|
|
|
if (device->id == mFirstKeyboardId) {
|
|
|
|
outEvent->deviceId = 0;
|
|
|
|
} else {
|
|
|
|
outEvent->deviceId = device->id;
|
|
|
|
}
|
|
|
|
outEvent->type = DEVICE_REMOVED;
|
2009-03-04 03:31:44 +00:00
|
|
|
delete device;
|
2010-10-02 01:55:43 +00:00
|
|
|
mNeedToSendFinishedDeviceScan = true;
|
2009-03-04 03:31:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-07-24 04:28:06 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
if (mOpeningDevices != NULL) {
|
|
|
|
device_t* device = mOpeningDevices;
|
|
|
|
LOGV("Reporting device opened: id=0x%x, name=%s\n",
|
|
|
|
device->id, device->path.string());
|
|
|
|
mOpeningDevices = device->next;
|
2010-07-24 04:28:06 +00:00
|
|
|
if (device->id == mFirstKeyboardId) {
|
|
|
|
outEvent->deviceId = 0;
|
|
|
|
} else {
|
|
|
|
outEvent->deviceId = device->id;
|
|
|
|
}
|
|
|
|
outEvent->type = DEVICE_ADDED;
|
2010-10-02 01:55:43 +00:00
|
|
|
mNeedToSendFinishedDeviceScan = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mNeedToSendFinishedDeviceScan) {
|
|
|
|
mNeedToSendFinishedDeviceScan = false;
|
|
|
|
outEvent->type = FINISHED_DEVICE_SCAN;
|
2009-03-04 03:31:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-17 23:48:25 +00:00
|
|
|
// Grab the next input event.
|
|
|
|
for (;;) {
|
|
|
|
// Consume buffered input events, if any.
|
|
|
|
if (mInputBufferIndex < mInputBufferCount) {
|
|
|
|
const struct input_event& iev = mInputBufferData[mInputBufferIndex++];
|
|
|
|
const device_t* device = mDevices[mInputDeviceIndex];
|
|
|
|
|
|
|
|
LOGV("%s got: t0=%d, t1=%d, type=%d, code=%d, v=%d", device->path.string(),
|
|
|
|
(int) iev.time.tv_sec, (int) iev.time.tv_usec, iev.type, iev.code, iev.value);
|
|
|
|
if (device->id == mFirstKeyboardId) {
|
|
|
|
outEvent->deviceId = 0;
|
|
|
|
} else {
|
|
|
|
outEvent->deviceId = device->id;
|
|
|
|
}
|
|
|
|
outEvent->type = iev.type;
|
|
|
|
outEvent->scanCode = iev.code;
|
|
|
|
if (iev.type == EV_KEY) {
|
|
|
|
status_t err = device->layoutMap->map(iev.code,
|
|
|
|
& outEvent->keyCode, & outEvent->flags);
|
|
|
|
LOGV("iev.code=%d keyCode=%d flags=0x%08x err=%d\n",
|
|
|
|
iev.code, outEvent->keyCode, outEvent->flags, err);
|
|
|
|
if (err != 0) {
|
|
|
|
outEvent->keyCode = AKEYCODE_UNKNOWN;
|
|
|
|
outEvent->flags = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
outEvent->keyCode = iev.code;
|
|
|
|
}
|
|
|
|
outEvent->value = iev.value;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-08-17 23:48:25 +00:00
|
|
|
// Use an event timestamp in the same timebase as
|
|
|
|
// java.lang.System.nanoTime() and android.os.SystemClock.uptimeMillis()
|
|
|
|
// as expected by the rest of the system.
|
|
|
|
outEvent->when = systemTime(SYSTEM_TIME_MONOTONIC);
|
|
|
|
return true;
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-08-17 23:48:25 +00:00
|
|
|
// Finish reading all events from devices identified in previous poll().
|
|
|
|
// This code assumes that mInputDeviceIndex is initially 0 and that the
|
|
|
|
// revents member of pollfd is initialized to 0 when the device is first added.
|
|
|
|
// Since mFDs[0] is used for inotify, we process regular events starting at index 1.
|
|
|
|
mInputDeviceIndex += 1;
|
|
|
|
if (mInputDeviceIndex >= mFDCount) {
|
|
|
|
break;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2010-10-14 09:23:43 +00:00
|
|
|
const struct pollfd& pfd = mFDs[mInputDeviceIndex];
|
2010-08-17 23:48:25 +00:00
|
|
|
if (pfd.revents & POLLIN) {
|
|
|
|
int32_t readSize = read(pfd.fd, mInputBufferData,
|
|
|
|
sizeof(struct input_event) * INPUT_BUFFER_SIZE);
|
|
|
|
if (readSize < 0) {
|
|
|
|
if (errno != EAGAIN && errno != EINTR) {
|
|
|
|
LOGW("could not get event (errno=%d)", errno);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2010-08-17 23:48:25 +00:00
|
|
|
} else if ((readSize % sizeof(struct input_event)) != 0) {
|
|
|
|
LOGE("could not get event (wrong size: %d)", readSize);
|
|
|
|
} else {
|
|
|
|
mInputBufferCount = readSize / sizeof(struct input_event);
|
|
|
|
mInputBufferIndex = 0;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-17 23:48:25 +00:00
|
|
|
|
2010-10-14 09:23:43 +00:00
|
|
|
#if HAVE_INOTIFY
|
2010-10-02 01:55:43 +00:00
|
|
|
// readNotify() will modify mFDs and mFDCount, so this must be done after
|
2009-03-04 03:31:44 +00:00
|
|
|
// processing all other events.
|
|
|
|
if(mFDs[0].revents & POLLIN) {
|
2010-10-02 01:55:43 +00:00
|
|
|
readNotify(mFDs[0].fd);
|
2010-10-14 09:23:43 +00:00
|
|
|
mFDs[0].revents = 0;
|
|
|
|
continue; // report added or removed devices immediately
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2010-10-14 09:23:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
mInputDeviceIndex = 0;
|
2010-08-17 23:48:25 +00:00
|
|
|
|
|
|
|
// Poll for events. Mind the wake lock dance!
|
|
|
|
// We hold a wake lock at all times except during poll(). This works due to some
|
|
|
|
// subtle choreography. When a device driver has pending (unread) events, it acquires
|
|
|
|
// a kernel wake lock. However, once the last pending event has been read, the device
|
|
|
|
// driver will release the kernel wake lock. To prevent the system from going to sleep
|
|
|
|
// when this happens, the EventHub holds onto its own user wake lock while the client
|
|
|
|
// is processing events. Thus the system can only sleep if there are no events
|
|
|
|
// pending or currently being processed.
|
|
|
|
release_wake_lock(WAKE_LOCK_ID);
|
|
|
|
|
|
|
|
int pollResult = poll(mFDs, mFDCount, -1);
|
|
|
|
|
|
|
|
acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID);
|
|
|
|
|
|
|
|
if (pollResult <= 0) {
|
|
|
|
if (errno != EINTR) {
|
2010-10-14 09:23:43 +00:00
|
|
|
LOGW("poll failed (errno=%d)\n", errno);
|
2010-08-17 23:48:25 +00:00
|
|
|
usleep(100000);
|
|
|
|
}
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open the platform-specific input device.
|
|
|
|
*/
|
|
|
|
bool EventHub::openPlatformInput(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Open platform-specific input device(s).
|
|
|
|
*/
|
|
|
|
int res;
|
|
|
|
|
|
|
|
mFDCount = 1;
|
|
|
|
mFDs = (pollfd *)calloc(1, sizeof(mFDs[0]));
|
|
|
|
mDevices = (device_t **)calloc(1, sizeof(mDevices[0]));
|
|
|
|
mFDs[0].events = POLLIN;
|
2010-08-17 23:48:25 +00:00
|
|
|
mFDs[0].revents = 0;
|
2009-03-04 03:31:44 +00:00
|
|
|
mDevices[0] = NULL;
|
|
|
|
#ifdef HAVE_INOTIFY
|
|
|
|
mFDs[0].fd = inotify_init();
|
|
|
|
res = inotify_add_watch(mFDs[0].fd, device_path, IN_DELETE | IN_CREATE);
|
|
|
|
if(res < 0) {
|
|
|
|
LOGE("could not add watch for %s, %s\n", device_path, strerror(errno));
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* The code in EventHub::getEvent assumes that mFDs[0] is an inotify fd.
|
|
|
|
* We allocate space for it and set it to something invalid.
|
|
|
|
*/
|
|
|
|
mFDs[0].fd = -1;
|
|
|
|
#endif
|
|
|
|
|
2010-10-02 01:55:43 +00:00
|
|
|
res = scanDir(device_path);
|
2009-03-04 03:31:44 +00:00
|
|
|
if(res < 0) {
|
|
|
|
LOGE("scan dir failed for %s\n", device_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2010-06-30 23:10:35 +00:00
|
|
|
static bool containsNonZeroByte(const uint8_t* array, uint32_t startIndex, uint32_t endIndex) {
|
|
|
|
const uint8_t* end = array + endIndex;
|
|
|
|
array += startIndex;
|
|
|
|
while (array != end) {
|
|
|
|
if (*(array++) != 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const int32_t GAMEPAD_KEYCODES[] = {
|
|
|
|
AKEYCODE_BUTTON_A, AKEYCODE_BUTTON_B, AKEYCODE_BUTTON_C,
|
|
|
|
AKEYCODE_BUTTON_X, AKEYCODE_BUTTON_Y, AKEYCODE_BUTTON_Z,
|
|
|
|
AKEYCODE_BUTTON_L1, AKEYCODE_BUTTON_R1,
|
|
|
|
AKEYCODE_BUTTON_L2, AKEYCODE_BUTTON_R2,
|
|
|
|
AKEYCODE_BUTTON_THUMBL, AKEYCODE_BUTTON_THUMBR,
|
|
|
|
AKEYCODE_BUTTON_START, AKEYCODE_BUTTON_SELECT, AKEYCODE_BUTTON_MODE
|
|
|
|
};
|
|
|
|
|
2010-10-02 01:55:43 +00:00
|
|
|
int EventHub::openDevice(const char *deviceName) {
|
2009-03-04 03:31:44 +00:00
|
|
|
int version;
|
|
|
|
int fd;
|
|
|
|
struct pollfd *new_mFDs;
|
|
|
|
device_t **new_devices;
|
|
|
|
char **new_device_names;
|
|
|
|
char name[80];
|
|
|
|
char location[80];
|
|
|
|
char idstr[80];
|
|
|
|
struct input_id id;
|
|
|
|
|
|
|
|
LOGV("Opening device: %s", deviceName);
|
|
|
|
|
|
|
|
AutoMutex _l(mLock);
|
2010-01-21 03:36:49 +00:00
|
|
|
|
2010-01-26 18:27:15 +00:00
|
|
|
fd = open(deviceName, O_RDWR);
|
2009-03-04 03:31:44 +00:00
|
|
|
if(fd < 0) {
|
|
|
|
LOGE("could not open %s, %s\n", deviceName, strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ioctl(fd, EVIOCGVERSION, &version)) {
|
|
|
|
LOGE("could not get driver version for %s, %s\n", deviceName, strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if(ioctl(fd, EVIOCGID, &id)) {
|
|
|
|
LOGE("could not get driver id for %s, %s\n", deviceName, strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
name[sizeof(name) - 1] = '\0';
|
|
|
|
location[sizeof(location) - 1] = '\0';
|
|
|
|
idstr[sizeof(idstr) - 1] = '\0';
|
|
|
|
if(ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) {
|
|
|
|
//fprintf(stderr, "could not get device name for %s, %s\n", deviceName, strerror(errno));
|
|
|
|
name[0] = '\0';
|
|
|
|
}
|
|
|
|
|
2009-07-16 15:11:18 +00:00
|
|
|
// check to see if the device is on our excluded list
|
|
|
|
List<String8>::iterator iter = mExcludedDevices.begin();
|
|
|
|
List<String8>::iterator end = mExcludedDevices.end();
|
|
|
|
for ( ; iter != end; iter++) {
|
2009-07-17 04:10:10 +00:00
|
|
|
const char* test = *iter;
|
|
|
|
if (strcmp(name, test) == 0) {
|
|
|
|
LOGI("ignoring event id %s driver %s\n", deviceName, test);
|
2009-07-16 15:11:18 +00:00
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-17 04:10:10 +00:00
|
|
|
if(ioctl(fd, EVIOCGPHYS(sizeof(location) - 1), &location) < 1) {
|
|
|
|
//fprintf(stderr, "could not get location for %s, %s\n", deviceName, strerror(errno));
|
|
|
|
location[0] = '\0';
|
|
|
|
}
|
|
|
|
if(ioctl(fd, EVIOCGUNIQ(sizeof(idstr) - 1), &idstr) < 1) {
|
|
|
|
//fprintf(stderr, "could not get idstring for %s, %s\n", deviceName, strerror(errno));
|
|
|
|
idstr[0] = '\0';
|
|
|
|
}
|
|
|
|
|
2010-08-17 23:48:25 +00:00
|
|
|
if (fcntl(fd, F_SETFL, O_NONBLOCK)) {
|
|
|
|
LOGE("Error %d making device file descriptor non-blocking.", errno);
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
int devid = 0;
|
|
|
|
while (devid < mNumDevicesById) {
|
|
|
|
if (mDevicesById[devid].device == NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
devid++;
|
|
|
|
}
|
|
|
|
if (devid >= mNumDevicesById) {
|
|
|
|
device_ent* new_devids = (device_ent*)realloc(mDevicesById,
|
|
|
|
sizeof(mDevicesById[0]) * (devid + 1));
|
|
|
|
if (new_devids == NULL) {
|
|
|
|
LOGE("out of memory");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
mDevicesById = new_devids;
|
|
|
|
mNumDevicesById = devid+1;
|
|
|
|
mDevicesById[devid].device = NULL;
|
|
|
|
mDevicesById[devid].seq = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDevicesById[devid].seq = (mDevicesById[devid].seq+(1<<SEQ_SHIFT))&SEQ_MASK;
|
|
|
|
if (mDevicesById[devid].seq == 0) {
|
|
|
|
mDevicesById[devid].seq = 1<<SEQ_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_mFDs = (pollfd*)realloc(mFDs, sizeof(mFDs[0]) * (mFDCount + 1));
|
|
|
|
new_devices = (device_t**)realloc(mDevices, sizeof(mDevices[0]) * (mFDCount + 1));
|
|
|
|
if (new_mFDs == NULL || new_devices == NULL) {
|
|
|
|
LOGE("out of memory");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
mFDs = new_mFDs;
|
|
|
|
mDevices = new_devices;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
LOGI("add device %d: %s\n", mFDCount, deviceName);
|
|
|
|
LOGI(" bus: %04x\n"
|
|
|
|
" vendor %04x\n"
|
|
|
|
" product %04x\n"
|
|
|
|
" version %04x\n",
|
|
|
|
id.bustype, id.vendor, id.product, id.version);
|
|
|
|
LOGI(" name: \"%s\"\n", name);
|
|
|
|
LOGI(" location: \"%s\"\n"
|
|
|
|
" id: \"%s\"\n", location, idstr);
|
|
|
|
LOGI(" version: %d.%d.%d\n",
|
|
|
|
version >> 16, (version >> 8) & 0xff, version & 0xff);
|
|
|
|
#endif
|
|
|
|
|
2009-08-06 21:50:08 +00:00
|
|
|
device_t* device = new device_t(devid|mDevicesById[devid].seq, deviceName, name);
|
2009-03-04 03:31:44 +00:00
|
|
|
if (device == NULL) {
|
|
|
|
LOGE("out of memory");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-06-22 20:21:57 +00:00
|
|
|
device->fd = fd;
|
2009-03-04 03:31:44 +00:00
|
|
|
mFDs[mFDCount].fd = fd;
|
|
|
|
mFDs[mFDCount].events = POLLIN;
|
2010-08-17 23:48:25 +00:00
|
|
|
mFDs[mFDCount].revents = 0;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-06-30 23:10:35 +00:00
|
|
|
// Figure out the kinds of events the device reports.
|
2009-08-04 12:49:43 +00:00
|
|
|
|
2010-06-30 23:10:35 +00:00
|
|
|
uint8_t key_bitmask[sizeof_bit_array(KEY_MAX + 1)];
|
2009-03-04 03:31:44 +00:00
|
|
|
memset(key_bitmask, 0, sizeof(key_bitmask));
|
2010-06-30 23:10:35 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
LOGV("Getting keys...");
|
|
|
|
if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bitmask)), key_bitmask) >= 0) {
|
|
|
|
//LOGI("MAP\n");
|
2010-06-30 23:10:35 +00:00
|
|
|
//for (int i = 0; i < sizeof(key_bitmask); i++) {
|
2009-03-04 03:31:44 +00:00
|
|
|
// LOGI("%d: 0x%02x\n", i, key_bitmask[i]);
|
|
|
|
//}
|
2010-06-30 23:10:35 +00:00
|
|
|
|
|
|
|
// See if this is a keyboard. Ignore everything in the button range except for
|
|
|
|
// gamepads which are also considered keyboards.
|
|
|
|
if (containsNonZeroByte(key_bitmask, 0, sizeof_bit_array(BTN_MISC))
|
|
|
|
|| containsNonZeroByte(key_bitmask, sizeof_bit_array(BTN_GAMEPAD),
|
|
|
|
sizeof_bit_array(BTN_DIGI))
|
|
|
|
|| containsNonZeroByte(key_bitmask, sizeof_bit_array(KEY_OK),
|
|
|
|
sizeof_bit_array(KEY_MAX + 1))) {
|
|
|
|
device->classes |= INPUT_DEVICE_CLASS_KEYBOARD;
|
|
|
|
|
2009-08-04 12:49:43 +00:00
|
|
|
device->keyBitmask = new uint8_t[sizeof(key_bitmask)];
|
2009-03-04 03:31:44 +00:00
|
|
|
if (device->keyBitmask != NULL) {
|
|
|
|
memcpy(device->keyBitmask, key_bitmask, sizeof(key_bitmask));
|
|
|
|
} else {
|
|
|
|
delete device;
|
|
|
|
LOGE("out of memory allocating key bitmask");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-08-04 12:49:43 +00:00
|
|
|
|
2010-06-30 23:10:35 +00:00
|
|
|
// See if this is a trackball (or mouse).
|
2009-03-04 03:31:44 +00:00
|
|
|
if (test_bit(BTN_MOUSE, key_bitmask)) {
|
2010-06-30 23:10:35 +00:00
|
|
|
uint8_t rel_bitmask[sizeof_bit_array(REL_MAX + 1)];
|
2009-03-04 03:31:44 +00:00
|
|
|
memset(rel_bitmask, 0, sizeof(rel_bitmask));
|
|
|
|
LOGV("Getting relative controllers...");
|
2010-06-30 23:10:35 +00:00
|
|
|
if (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(rel_bitmask)), rel_bitmask) >= 0) {
|
2009-03-04 03:31:44 +00:00
|
|
|
if (test_bit(REL_X, rel_bitmask) && test_bit(REL_Y, rel_bitmask)) {
|
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
|
|
|
device->classes |= INPUT_DEVICE_CLASS_TRACKBALL;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-30 23:10:35 +00:00
|
|
|
|
|
|
|
// See if this is a touch pad.
|
|
|
|
uint8_t abs_bitmask[sizeof_bit_array(ABS_MAX + 1)];
|
2009-08-04 12:49:43 +00:00
|
|
|
memset(abs_bitmask, 0, sizeof(abs_bitmask));
|
|
|
|
LOGV("Getting absolute controllers...");
|
2010-06-30 23:10:35 +00:00
|
|
|
if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(abs_bitmask)), abs_bitmask) >= 0) {
|
|
|
|
// Is this a new modern multi-touch driver?
|
2010-08-30 10:02:23 +00:00
|
|
|
if (test_bit(ABS_MT_POSITION_X, abs_bitmask)
|
2010-06-30 23:10:35 +00:00
|
|
|
&& test_bit(ABS_MT_POSITION_Y, abs_bitmask)) {
|
|
|
|
device->classes |= INPUT_DEVICE_CLASS_TOUCHSCREEN | INPUT_DEVICE_CLASS_TOUCHSCREEN_MT;
|
|
|
|
|
|
|
|
// Is this an old style single-touch driver?
|
|
|
|
} else if (test_bit(BTN_TOUCH, key_bitmask)
|
|
|
|
&& test_bit(ABS_X, abs_bitmask) && test_bit(ABS_Y, abs_bitmask)) {
|
|
|
|
device->classes |= INPUT_DEVICE_CLASS_TOUCHSCREEN;
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef EV_SW
|
|
|
|
// figure out the switches this device reports
|
2010-06-30 23:10:35 +00:00
|
|
|
uint8_t sw_bitmask[sizeof_bit_array(SW_MAX + 1)];
|
2009-03-04 03:31:44 +00:00
|
|
|
memset(sw_bitmask, 0, sizeof(sw_bitmask));
|
2010-07-24 04:28:06 +00:00
|
|
|
bool hasSwitches = false;
|
2009-03-04 03:31:44 +00:00
|
|
|
if (ioctl(fd, EVIOCGBIT(EV_SW, sizeof(sw_bitmask)), sw_bitmask) >= 0) {
|
|
|
|
for (int i=0; i<EV_SW; i++) {
|
|
|
|
//LOGI("Device 0x%x sw %d: has=%d", device->id, i, test_bit(i, sw_bitmask));
|
|
|
|
if (test_bit(i, sw_bitmask)) {
|
2010-07-24 04:28:06 +00:00
|
|
|
hasSwitches = true;
|
2009-03-04 03:31:44 +00:00
|
|
|
if (mSwitches[i] == 0) {
|
|
|
|
mSwitches[i] = device->id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-07-24 04:28:06 +00:00
|
|
|
if (hasSwitches) {
|
|
|
|
device->classes |= INPUT_DEVICE_CLASS_SWITCH;
|
|
|
|
}
|
2009-03-04 03:31:44 +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
|
|
|
if ((device->classes & INPUT_DEVICE_CLASS_KEYBOARD) != 0) {
|
2009-03-04 03:31:44 +00:00
|
|
|
// a more descriptive name
|
2009-08-06 21:50:08 +00:00
|
|
|
device->name = name;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-09-13 00:55:08 +00:00
|
|
|
// Configure the keymap for the device.
|
|
|
|
configureKeyMap(device);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-09-13 00:55:08 +00:00
|
|
|
// Tell the world about the devname (the descriptive name)
|
|
|
|
if (!mHaveFirstKeyboard && !device->defaultKeyMap && strstr(name, "-keypad")) {
|
2009-03-04 03:31:44 +00:00
|
|
|
// the built-in keyboard has a well-known device ID of 0,
|
|
|
|
// this device better not go away.
|
|
|
|
mHaveFirstKeyboard = true;
|
|
|
|
mFirstKeyboardId = device->id;
|
2010-09-13 00:55:08 +00:00
|
|
|
setKeyboardProperties(device, true);
|
2009-03-04 03:31:44 +00:00
|
|
|
} else {
|
|
|
|
// ensure mFirstKeyboardId is set to -something-.
|
2010-09-13 00:55:08 +00:00
|
|
|
if (mFirstKeyboardId == -1) {
|
2009-03-04 03:31:44 +00:00
|
|
|
mFirstKeyboardId = device->id;
|
2010-09-13 00:55:08 +00:00
|
|
|
setKeyboardProperties(device, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setKeyboardProperties(device, false);
|
|
|
|
|
|
|
|
// Load the keylayout.
|
|
|
|
if (!device->keyLayoutFilename.isEmpty()) {
|
|
|
|
status_t status = device->layoutMap->load(device->keyLayoutFilename);
|
|
|
|
if (status) {
|
|
|
|
LOGE("Error %d loading key layout file '%s'.", status,
|
|
|
|
device->keyLayoutFilename.string());
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-04 12:49:43 +00:00
|
|
|
// 'Q' key support = cheap test of whether this is an alpha-capable kbd
|
2010-10-02 00:46:21 +00:00
|
|
|
if (hasKeycodeLocked(device, AKEYCODE_Q)) {
|
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
|
|
|
device->classes |= INPUT_DEVICE_CLASS_ALPHAKEY;
|
2009-08-04 12:49:43 +00:00
|
|
|
}
|
2010-09-13 00:55:08 +00:00
|
|
|
|
2010-06-30 23:10:35 +00:00
|
|
|
// See if this device has a DPAD.
|
2010-10-02 00:46:21 +00:00
|
|
|
if (hasKeycodeLocked(device, AKEYCODE_DPAD_UP) &&
|
|
|
|
hasKeycodeLocked(device, AKEYCODE_DPAD_DOWN) &&
|
|
|
|
hasKeycodeLocked(device, AKEYCODE_DPAD_LEFT) &&
|
|
|
|
hasKeycodeLocked(device, AKEYCODE_DPAD_RIGHT) &&
|
|
|
|
hasKeycodeLocked(device, AKEYCODE_DPAD_CENTER)) {
|
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
|
|
|
device->classes |= INPUT_DEVICE_CLASS_DPAD;
|
2009-08-04 12:49:43 +00:00
|
|
|
}
|
2010-09-13 00:55:08 +00:00
|
|
|
|
2010-06-30 23:10:35 +00:00
|
|
|
// See if this device has a gamepad.
|
2010-10-21 22:46:03 +00:00
|
|
|
for (size_t i = 0; i < sizeof(GAMEPAD_KEYCODES)/sizeof(GAMEPAD_KEYCODES[0]); i++) {
|
2010-10-02 00:46:21 +00:00
|
|
|
if (hasKeycodeLocked(device, GAMEPAD_KEYCODES[i])) {
|
2010-06-30 23:10:35 +00:00
|
|
|
device->classes |= INPUT_DEVICE_CLASS_GAMEPAD;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-13 00:55:08 +00:00
|
|
|
LOGI("New keyboard: device->id=0x%x devname='%s' keylayout='%s' keycharactermap='%s'\n",
|
|
|
|
device->id, name,
|
|
|
|
device->keyLayoutFilename.string(), device->keyCharacterMapFilename.string());
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2010-06-23 09:00:37 +00:00
|
|
|
// If the device isn't recognized as something we handle, don't monitor it.
|
|
|
|
if (device->classes == 0) {
|
|
|
|
LOGV("Dropping device %s %p, id = %d\n", deviceName, device, devid);
|
|
|
|
close(fd);
|
|
|
|
delete device;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-08-04 12:49:43 +00:00
|
|
|
LOGI("New device: path=%s name=%s id=0x%x (of 0x%x) index=%d fd=%d classes=0x%x\n",
|
|
|
|
deviceName, name, device->id, mNumDevicesById, mFDCount, fd, device->classes);
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
LOGV("Adding device %s %p at %d, id = %d, classes = 0x%x\n",
|
|
|
|
deviceName, device, mFDCount, devid, device->classes);
|
|
|
|
|
|
|
|
mDevicesById[devid].device = device;
|
|
|
|
device->next = mOpeningDevices;
|
|
|
|
mOpeningDevices = device;
|
|
|
|
mDevices[mFDCount] = device;
|
|
|
|
|
|
|
|
mFDCount++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-13 00:55:08 +00:00
|
|
|
void EventHub::configureKeyMap(device_t* device) {
|
|
|
|
// As an initial key map name, try using the device name.
|
|
|
|
String8 keyMapName(device->name);
|
|
|
|
char* p = keyMapName.lockBuffer(keyMapName.size());
|
|
|
|
while (*p) {
|
|
|
|
if (*p == ' ') *p = '_';
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
keyMapName.unlockBuffer();
|
|
|
|
|
|
|
|
if (probeKeyMap(device, keyMapName, false)) return;
|
|
|
|
|
|
|
|
// TODO Consider allowing the user to configure a specific key map somehow.
|
|
|
|
|
|
|
|
// Try the Generic key map.
|
|
|
|
// TODO Apply some additional heuristics here to figure out what kind of
|
|
|
|
// generic key map to use (US English, etc.).
|
|
|
|
keyMapName.setTo("Generic");
|
|
|
|
if (probeKeyMap(device, keyMapName, true)) return;
|
|
|
|
|
|
|
|
// Fall back on the old style catchall qwerty key map.
|
|
|
|
keyMapName.setTo("qwerty");
|
|
|
|
if (probeKeyMap(device, keyMapName, true)) return;
|
|
|
|
|
|
|
|
// Give up!
|
|
|
|
keyMapName.setTo("unknown");
|
|
|
|
selectKeyMap(device, keyMapName, true);
|
|
|
|
LOGE("Could not determine key map for device '%s'.", device->name.string());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EventHub::probeKeyMap(device_t* device, const String8& keyMapName, bool defaultKeyMap) {
|
|
|
|
const char* root = getenv("ANDROID_ROOT");
|
|
|
|
|
|
|
|
// TODO Consider also looking somewhere in a writeable partition like /data for a
|
|
|
|
// custom keymap supplied by the user for this device.
|
|
|
|
bool haveKeyLayout = !device->keyLayoutFilename.isEmpty();
|
|
|
|
if (!haveKeyLayout) {
|
|
|
|
device->keyLayoutFilename.setTo(root);
|
|
|
|
device->keyLayoutFilename.append("/usr/keylayout/");
|
|
|
|
device->keyLayoutFilename.append(keyMapName);
|
|
|
|
device->keyLayoutFilename.append(".kl");
|
|
|
|
if (access(device->keyLayoutFilename.string(), R_OK)) {
|
|
|
|
device->keyLayoutFilename.clear();
|
|
|
|
} else {
|
|
|
|
haveKeyLayout = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool haveKeyCharacterMap = !device->keyCharacterMapFilename.isEmpty();
|
|
|
|
if (!haveKeyCharacterMap) {
|
|
|
|
device->keyCharacterMapFilename.setTo(root);
|
|
|
|
device->keyCharacterMapFilename.append("/usr/keychars/");
|
|
|
|
device->keyCharacterMapFilename.append(keyMapName);
|
|
|
|
device->keyCharacterMapFilename.append(".kcm.bin");
|
|
|
|
if (access(device->keyCharacterMapFilename.string(), R_OK)) {
|
|
|
|
device->keyCharacterMapFilename.clear();
|
|
|
|
} else {
|
|
|
|
haveKeyCharacterMap = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (haveKeyLayout || haveKeyCharacterMap) {
|
|
|
|
selectKeyMap(device, keyMapName, defaultKeyMap);
|
|
|
|
}
|
|
|
|
return haveKeyLayout && haveKeyCharacterMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventHub::selectKeyMap(device_t* device,
|
|
|
|
const String8& keyMapName, bool defaultKeyMap) {
|
|
|
|
if (device->keyMapName.isEmpty()) {
|
|
|
|
device->keyMapName.setTo(keyMapName);
|
|
|
|
device->defaultKeyMap = defaultKeyMap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventHub::setKeyboardProperties(device_t* device, bool firstKeyboard) {
|
|
|
|
int32_t id = firstKeyboard ? 0 : device->id;
|
|
|
|
|
|
|
|
char propName[100];
|
|
|
|
sprintf(propName, "hw.keyboards.%u.devname", id);
|
|
|
|
property_set(propName, device->name.string());
|
|
|
|
sprintf(propName, "hw.keyboards.%u.keymap", id);
|
|
|
|
property_set(propName, device->keyMapName.string());
|
|
|
|
sprintf(propName, "hw.keyboards.%u.klfile", id);
|
|
|
|
property_set(propName, device->keyLayoutFilename.string());
|
|
|
|
sprintf(propName, "hw.keyboards.%u.kcmfile", id);
|
|
|
|
property_set(propName, device->keyCharacterMapFilename.string());
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventHub::clearKeyboardProperties(device_t* device, bool firstKeyboard) {
|
|
|
|
int32_t id = firstKeyboard ? 0 : device->id;
|
|
|
|
|
|
|
|
char propName[100];
|
|
|
|
sprintf(propName, "hw.keyboards.%u.devname", id);
|
|
|
|
property_set(propName, "");
|
|
|
|
sprintf(propName, "hw.keyboards.%u.keymap", id);
|
|
|
|
property_set(propName, "");
|
|
|
|
sprintf(propName, "hw.keyboards.%u.klfile", id);
|
|
|
|
property_set(propName, "");
|
|
|
|
sprintf(propName, "hw.keyboards.%u.kcmfile", id);
|
|
|
|
property_set(propName, "");
|
|
|
|
}
|
|
|
|
|
2010-10-02 00:46:21 +00:00
|
|
|
bool EventHub::hasKeycodeLocked(device_t* device, int keycode) const
|
2009-08-04 12:49:43 +00:00
|
|
|
{
|
|
|
|
if (device->keyBitmask == NULL || device->layoutMap == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<int32_t> scanCodes;
|
|
|
|
device->layoutMap->findScancodes(keycode, &scanCodes);
|
|
|
|
const size_t N = scanCodes.size();
|
|
|
|
for (size_t i=0; i<N && i<=KEY_MAX; i++) {
|
|
|
|
int32_t sc = scanCodes.itemAt(i);
|
|
|
|
if (sc >= 0 && sc <= KEY_MAX && test_bit(sc, device->keyBitmask)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-10-02 01:55:43 +00:00
|
|
|
int EventHub::closeDevice(const char *deviceName) {
|
2009-03-04 03:31:44 +00:00
|
|
|
AutoMutex _l(mLock);
|
2010-10-02 01:55:43 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
int i;
|
|
|
|
for(i = 1; i < mFDCount; i++) {
|
|
|
|
if(strcmp(mDevices[i]->path.string(), deviceName) == 0) {
|
|
|
|
//LOGD("remove device %d: %s\n", i, deviceName);
|
|
|
|
device_t* device = mDevices[i];
|
Work on issue #2079167: Flickering issue across multiple UI
This addresses a few parts of the bug:
- There was a small issue in the window manager where we could show a window
too early before the transition animation starts, which was introduced
by the recent wallpaper work. This was the cause of the flicker when
starting the dialer for the first time.
- There was a much larger problem that has existing forever where moving
an application token to the front or back was not synchronized with the
application animation transaction. This was the cause of the flicker
when hanging up (now that the in-call screen moves to the back instead
of closing and we always have a wallpaper visible). The approach to
solving this is to have the window manager go ahead and move the app
tokens (it must in order to keep in sync with the activity manager), but
to delay the actual window movement: perform the movement to front when
the animation starts, and to back when it ends. Actually, when the
animation ends, we just go and completely rebuild the window list to
ensure it is correct, because there can be ways people can add windows
while in this intermediate state where they could end up at the wrong
place once we do the delayed movement to the front or back. And it is
simply reasuring to know that every time we finish a full app transition,
we re-evaluate the world and put everything in its proper place.
Also included in this change are a few little tweaks to the input system,
to perform better logging, and completely ignore input devices that do not
have any of our input classes. There is also a little cleanup of evaluating
configuration changes to not do more work than needed when an input
devices appears or disappears, and to only log a config change message when
the config is truly changing.
Change-Id: Ifb2db77f8867435121722a6abeb946ec7c3ea9d3
2009-09-02 02:01:50 +00:00
|
|
|
|
|
|
|
LOGI("Removed device: path=%s name=%s id=0x%x (of 0x%x) index=%d fd=%d classes=0x%x\n",
|
|
|
|
device->path.string(), device->name.string(), device->id,
|
|
|
|
mNumDevicesById, mFDCount, mFDs[i].fd, device->classes);
|
|
|
|
|
|
|
|
// Clear this device's entry.
|
2009-03-04 03:31:44 +00:00
|
|
|
int index = (device->id&ID_MASK);
|
|
|
|
mDevicesById[index].device = NULL;
|
Work on issue #2079167: Flickering issue across multiple UI
This addresses a few parts of the bug:
- There was a small issue in the window manager where we could show a window
too early before the transition animation starts, which was introduced
by the recent wallpaper work. This was the cause of the flicker when
starting the dialer for the first time.
- There was a much larger problem that has existing forever where moving
an application token to the front or back was not synchronized with the
application animation transaction. This was the cause of the flicker
when hanging up (now that the in-call screen moves to the back instead
of closing and we always have a wallpaper visible). The approach to
solving this is to have the window manager go ahead and move the app
tokens (it must in order to keep in sync with the activity manager), but
to delay the actual window movement: perform the movement to front when
the animation starts, and to back when it ends. Actually, when the
animation ends, we just go and completely rebuild the window list to
ensure it is correct, because there can be ways people can add windows
while in this intermediate state where they could end up at the wrong
place once we do the delayed movement to the front or back. And it is
simply reasuring to know that every time we finish a full app transition,
we re-evaluate the world and put everything in its proper place.
Also included in this change are a few little tweaks to the input system,
to perform better logging, and completely ignore input devices that do not
have any of our input classes. There is also a little cleanup of evaluating
configuration changes to not do more work than needed when an input
devices appears or disappears, and to only log a config change message when
the config is truly changing.
Change-Id: Ifb2db77f8867435121722a6abeb946ec7c3ea9d3
2009-09-02 02:01:50 +00:00
|
|
|
|
|
|
|
// Close the file descriptor and compact the fd array.
|
2009-08-28 20:29:06 +00:00
|
|
|
close(mFDs[i].fd);
|
Work on issue #2079167: Flickering issue across multiple UI
This addresses a few parts of the bug:
- There was a small issue in the window manager where we could show a window
too early before the transition animation starts, which was introduced
by the recent wallpaper work. This was the cause of the flicker when
starting the dialer for the first time.
- There was a much larger problem that has existing forever where moving
an application token to the front or back was not synchronized with the
application animation transaction. This was the cause of the flicker
when hanging up (now that the in-call screen moves to the back instead
of closing and we always have a wallpaper visible). The approach to
solving this is to have the window manager go ahead and move the app
tokens (it must in order to keep in sync with the activity manager), but
to delay the actual window movement: perform the movement to front when
the animation starts, and to back when it ends. Actually, when the
animation ends, we just go and completely rebuild the window list to
ensure it is correct, because there can be ways people can add windows
while in this intermediate state where they could end up at the wrong
place once we do the delayed movement to the front or back. And it is
simply reasuring to know that every time we finish a full app transition,
we re-evaluate the world and put everything in its proper place.
Also included in this change are a few little tweaks to the input system,
to perform better logging, and completely ignore input devices that do not
have any of our input classes. There is also a little cleanup of evaluating
configuration changes to not do more work than needed when an input
devices appears or disappears, and to only log a config change message when
the config is truly changing.
Change-Id: Ifb2db77f8867435121722a6abeb946ec7c3ea9d3
2009-09-02 02:01:50 +00:00
|
|
|
int count = mFDCount - i - 1;
|
2009-03-04 03:31:44 +00:00
|
|
|
memmove(mDevices + i, mDevices + i + 1, sizeof(mDevices[0]) * count);
|
|
|
|
memmove(mFDs + i, mFDs + i + 1, sizeof(mFDs[0]) * count);
|
Work on issue #2079167: Flickering issue across multiple UI
This addresses a few parts of the bug:
- There was a small issue in the window manager where we could show a window
too early before the transition animation starts, which was introduced
by the recent wallpaper work. This was the cause of the flicker when
starting the dialer for the first time.
- There was a much larger problem that has existing forever where moving
an application token to the front or back was not synchronized with the
application animation transaction. This was the cause of the flicker
when hanging up (now that the in-call screen moves to the back instead
of closing and we always have a wallpaper visible). The approach to
solving this is to have the window manager go ahead and move the app
tokens (it must in order to keep in sync with the activity manager), but
to delay the actual window movement: perform the movement to front when
the animation starts, and to back when it ends. Actually, when the
animation ends, we just go and completely rebuild the window list to
ensure it is correct, because there can be ways people can add windows
while in this intermediate state where they could end up at the wrong
place once we do the delayed movement to the front or back. And it is
simply reasuring to know that every time we finish a full app transition,
we re-evaluate the world and put everything in its proper place.
Also included in this change are a few little tweaks to the input system,
to perform better logging, and completely ignore input devices that do not
have any of our input classes. There is also a little cleanup of evaluating
configuration changes to not do more work than needed when an input
devices appears or disappears, and to only log a config change message when
the config is truly changing.
Change-Id: Ifb2db77f8867435121722a6abeb946ec7c3ea9d3
2009-09-02 02:01:50 +00:00
|
|
|
mFDCount--;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
#ifdef EV_SW
|
|
|
|
for (int j=0; j<EV_SW; j++) {
|
|
|
|
if (mSwitches[j] == device->id) {
|
|
|
|
mSwitches[j] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
device->next = mClosingDevices;
|
|
|
|
mClosingDevices = device;
|
|
|
|
|
|
|
|
if (device->id == mFirstKeyboardId) {
|
|
|
|
LOGW("built-in keyboard device %s (id=%d) is closing! the apps will not like this",
|
|
|
|
device->path.string(), mFirstKeyboardId);
|
2010-09-13 00:55:08 +00:00
|
|
|
mFirstKeyboardId = -1;
|
|
|
|
clearKeyboardProperties(device, true);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2010-09-13 00:55:08 +00:00
|
|
|
clearKeyboardProperties(device, false);
|
2009-03-04 03:31:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
Work on issue #2079167: Flickering issue across multiple UI
This addresses a few parts of the bug:
- There was a small issue in the window manager where we could show a window
too early before the transition animation starts, which was introduced
by the recent wallpaper work. This was the cause of the flicker when
starting the dialer for the first time.
- There was a much larger problem that has existing forever where moving
an application token to the front or back was not synchronized with the
application animation transaction. This was the cause of the flicker
when hanging up (now that the in-call screen moves to the back instead
of closing and we always have a wallpaper visible). The approach to
solving this is to have the window manager go ahead and move the app
tokens (it must in order to keep in sync with the activity manager), but
to delay the actual window movement: perform the movement to front when
the animation starts, and to back when it ends. Actually, when the
animation ends, we just go and completely rebuild the window list to
ensure it is correct, because there can be ways people can add windows
while in this intermediate state where they could end up at the wrong
place once we do the delayed movement to the front or back. And it is
simply reasuring to know that every time we finish a full app transition,
we re-evaluate the world and put everything in its proper place.
Also included in this change are a few little tweaks to the input system,
to perform better logging, and completely ignore input devices that do not
have any of our input classes. There is also a little cleanup of evaluating
configuration changes to not do more work than needed when an input
devices appears or disappears, and to only log a config change message when
the config is truly changing.
Change-Id: Ifb2db77f8867435121722a6abeb946ec7c3ea9d3
2009-09-02 02:01:50 +00:00
|
|
|
LOGE("remove device: %s not found\n", deviceName);
|
2009-03-04 03:31:44 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-10-02 01:55:43 +00:00
|
|
|
int EventHub::readNotify(int nfd) {
|
2009-03-04 03:31:44 +00:00
|
|
|
#ifdef HAVE_INOTIFY
|
|
|
|
int res;
|
|
|
|
char devname[PATH_MAX];
|
|
|
|
char *filename;
|
|
|
|
char event_buf[512];
|
|
|
|
int event_size;
|
|
|
|
int event_pos = 0;
|
|
|
|
struct inotify_event *event;
|
|
|
|
|
2010-10-02 01:55:43 +00:00
|
|
|
LOGV("EventHub::readNotify nfd: %d\n", nfd);
|
2009-03-04 03:31:44 +00:00
|
|
|
res = read(nfd, event_buf, sizeof(event_buf));
|
|
|
|
if(res < (int)sizeof(*event)) {
|
|
|
|
if(errno == EINTR)
|
|
|
|
return 0;
|
|
|
|
LOGW("could not get event, %s\n", strerror(errno));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
//printf("got %d bytes of event information\n", res);
|
|
|
|
|
|
|
|
strcpy(devname, device_path);
|
|
|
|
filename = devname + strlen(devname);
|
|
|
|
*filename++ = '/';
|
|
|
|
|
|
|
|
while(res >= (int)sizeof(*event)) {
|
|
|
|
event = (struct inotify_event *)(event_buf + event_pos);
|
|
|
|
//printf("%d: %08x \"%s\"\n", event->wd, event->mask, event->len ? event->name : "");
|
|
|
|
if(event->len) {
|
|
|
|
strcpy(filename, event->name);
|
|
|
|
if(event->mask & IN_CREATE) {
|
2010-10-02 01:55:43 +00:00
|
|
|
openDevice(devname);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-10-02 01:55:43 +00:00
|
|
|
closeDevice(devname);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
event_size = sizeof(*event) + event->len;
|
|
|
|
res -= event_size;
|
|
|
|
event_pos += event_size;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-02 01:55:43 +00:00
|
|
|
int EventHub::scanDir(const char *dirname)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
|
|
|
char devname[PATH_MAX];
|
|
|
|
char *filename;
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *de;
|
|
|
|
dir = opendir(dirname);
|
|
|
|
if(dir == NULL)
|
|
|
|
return -1;
|
|
|
|
strcpy(devname, dirname);
|
|
|
|
filename = devname + strlen(devname);
|
|
|
|
*filename++ = '/';
|
|
|
|
while((de = readdir(dir))) {
|
|
|
|
if(de->d_name[0] == '.' &&
|
|
|
|
(de->d_name[1] == '\0' ||
|
|
|
|
(de->d_name[1] == '.' && de->d_name[2] == '\0')))
|
|
|
|
continue;
|
|
|
|
strcpy(filename, de->d_name);
|
2010-10-02 01:55:43 +00:00
|
|
|
openDevice(devname);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-10-02 00:46:21 +00:00
|
|
|
void EventHub::dump(String8& dump) {
|
|
|
|
dump.append("Event Hub State:\n");
|
|
|
|
|
|
|
|
{ // acquire lock
|
|
|
|
AutoMutex _l(mLock);
|
|
|
|
|
|
|
|
dump.appendFormat(INDENT "HaveFirstKeyboard: %s\n", toString(mHaveFirstKeyboard));
|
|
|
|
dump.appendFormat(INDENT "FirstKeyboardId: 0x%x\n", mFirstKeyboardId);
|
|
|
|
|
|
|
|
dump.append(INDENT "Devices:\n");
|
|
|
|
|
|
|
|
for (int i = 0; i < mNumDevicesById; i++) {
|
|
|
|
const device_t* device = mDevicesById[i].device;
|
|
|
|
if (device) {
|
|
|
|
if (mFirstKeyboardId == device->id) {
|
|
|
|
dump.appendFormat(INDENT2 "0x%x: %s (aka device 0 - first keyboard)\n",
|
|
|
|
device->id, device->name.string());
|
|
|
|
} else {
|
|
|
|
dump.appendFormat(INDENT2 "0x%x: %s\n", device->id, device->name.string());
|
|
|
|
}
|
|
|
|
dump.appendFormat(INDENT3 "Classes: 0x%08x\n", device->classes);
|
|
|
|
dump.appendFormat(INDENT3 "Path: %s\n", device->path.string());
|
2010-09-13 00:55:08 +00:00
|
|
|
dump.appendFormat(INDENT3 "KeyMapName: %s\n", device->keyMapName.string());
|
|
|
|
dump.appendFormat(INDENT3 "KeyLayoutFilename: %s\n",
|
|
|
|
device->keyLayoutFilename.string());
|
|
|
|
dump.appendFormat(INDENT3 "KeyCharacterMapFilename: %s\n",
|
|
|
|
device->keyCharacterMapFilename.string());
|
2010-10-02 00:46:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // release lock
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
}; // namespace android
|