e57e895080
Refactored the input reader so that each raw input protocol is handled by a separate subclass of the new InputMapper type. This way, behaviors pertaining to keyboard, trackballs, touchscreens, switches and other devices are clearly distinguished for improved maintainability. Added partial support for describing capabilities of input devices (incomplete and untested for now, will be fleshed out in later commits). Simplified EventHub interface somewhat since InputReader is taking over more of the work. Cleaned up some of the interactions between InputManager and WindowManagerService related to reading input state. Fixed swiping finger from screen edge into display area. Added logging of device information to 'dumpsys window'. Change-Id: I17faffc33e3aec3a0f33f0b37e81a70609378612
231 lines
5.7 KiB
C++
231 lines
5.7 KiB
C++
//
|
|
// Copyright 2010 The Android Open Source Project
|
|
//
|
|
// Provides a pipe-based transport for native events in the NDK.
|
|
//
|
|
#define LOG_TAG "Input"
|
|
|
|
//#define LOG_NDEBUG 0
|
|
|
|
#include <ui/Input.h>
|
|
|
|
namespace android {
|
|
|
|
// class InputEvent
|
|
|
|
void InputEvent::initialize(int32_t deviceId, int32_t source) {
|
|
mDeviceId = deviceId;
|
|
mSource = source;
|
|
}
|
|
|
|
void InputEvent::initialize(const InputEvent& from) {
|
|
mDeviceId = from.mDeviceId;
|
|
mSource = from.mSource;
|
|
}
|
|
|
|
// class KeyEvent
|
|
|
|
bool KeyEvent::hasDefaultAction(int32_t keyCode) {
|
|
switch (keyCode) {
|
|
case AKEYCODE_HOME:
|
|
case AKEYCODE_BACK:
|
|
case AKEYCODE_CALL:
|
|
case AKEYCODE_ENDCALL:
|
|
case AKEYCODE_VOLUME_UP:
|
|
case AKEYCODE_VOLUME_DOWN:
|
|
case AKEYCODE_POWER:
|
|
case AKEYCODE_CAMERA:
|
|
case AKEYCODE_HEADSETHOOK:
|
|
case AKEYCODE_MENU:
|
|
case AKEYCODE_NOTIFICATION:
|
|
case AKEYCODE_FOCUS:
|
|
case AKEYCODE_SEARCH:
|
|
case AKEYCODE_MEDIA_PLAY_PAUSE:
|
|
case AKEYCODE_MEDIA_STOP:
|
|
case AKEYCODE_MEDIA_NEXT:
|
|
case AKEYCODE_MEDIA_PREVIOUS:
|
|
case AKEYCODE_MEDIA_REWIND:
|
|
case AKEYCODE_MEDIA_FAST_FORWARD:
|
|
case AKEYCODE_MUTE:
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool KeyEvent::hasDefaultAction() const {
|
|
return hasDefaultAction(getKeyCode());
|
|
}
|
|
|
|
bool KeyEvent::isSystemKey(int32_t keyCode) {
|
|
switch (keyCode) {
|
|
case AKEYCODE_MENU:
|
|
case AKEYCODE_SOFT_RIGHT:
|
|
case AKEYCODE_HOME:
|
|
case AKEYCODE_BACK:
|
|
case AKEYCODE_CALL:
|
|
case AKEYCODE_ENDCALL:
|
|
case AKEYCODE_VOLUME_UP:
|
|
case AKEYCODE_VOLUME_DOWN:
|
|
case AKEYCODE_MUTE:
|
|
case AKEYCODE_POWER:
|
|
case AKEYCODE_HEADSETHOOK:
|
|
case AKEYCODE_MEDIA_PLAY_PAUSE:
|
|
case AKEYCODE_MEDIA_STOP:
|
|
case AKEYCODE_MEDIA_NEXT:
|
|
case AKEYCODE_MEDIA_PREVIOUS:
|
|
case AKEYCODE_MEDIA_REWIND:
|
|
case AKEYCODE_MEDIA_FAST_FORWARD:
|
|
case AKEYCODE_CAMERA:
|
|
case AKEYCODE_FOCUS:
|
|
case AKEYCODE_SEARCH:
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool KeyEvent::isSystemKey() const {
|
|
return isSystemKey(getKeyCode());
|
|
}
|
|
|
|
void KeyEvent::initialize(
|
|
int32_t deviceId,
|
|
int32_t source,
|
|
int32_t action,
|
|
int32_t flags,
|
|
int32_t keyCode,
|
|
int32_t scanCode,
|
|
int32_t metaState,
|
|
int32_t repeatCount,
|
|
nsecs_t downTime,
|
|
nsecs_t eventTime) {
|
|
InputEvent::initialize(deviceId, source);
|
|
mAction = action;
|
|
mFlags = flags;
|
|
mKeyCode = keyCode;
|
|
mScanCode = scanCode;
|
|
mMetaState = metaState;
|
|
mRepeatCount = repeatCount;
|
|
mDownTime = downTime;
|
|
mEventTime = eventTime;
|
|
}
|
|
|
|
void KeyEvent::initialize(const KeyEvent& from) {
|
|
InputEvent::initialize(from);
|
|
mAction = from.mAction;
|
|
mFlags = from.mFlags;
|
|
mKeyCode = from.mKeyCode;
|
|
mScanCode = from.mScanCode;
|
|
mMetaState = from.mMetaState;
|
|
mRepeatCount = from.mRepeatCount;
|
|
mDownTime = from.mDownTime;
|
|
mEventTime = from.mEventTime;
|
|
}
|
|
|
|
// class MotionEvent
|
|
|
|
void MotionEvent::initialize(
|
|
int32_t deviceId,
|
|
int32_t source,
|
|
int32_t action,
|
|
int32_t edgeFlags,
|
|
int32_t metaState,
|
|
float xOffset,
|
|
float yOffset,
|
|
float xPrecision,
|
|
float yPrecision,
|
|
nsecs_t downTime,
|
|
nsecs_t eventTime,
|
|
size_t pointerCount,
|
|
const int32_t* pointerIds,
|
|
const PointerCoords* pointerCoords) {
|
|
InputEvent::initialize(deviceId, source);
|
|
mAction = action;
|
|
mEdgeFlags = edgeFlags;
|
|
mMetaState = metaState;
|
|
mXOffset = xOffset;
|
|
mYOffset = yOffset;
|
|
mXPrecision = xPrecision;
|
|
mYPrecision = yPrecision;
|
|
mDownTime = downTime;
|
|
mPointerIds.clear();
|
|
mPointerIds.appendArray(pointerIds, pointerCount);
|
|
mSampleEventTimes.clear();
|
|
mSamplePointerCoords.clear();
|
|
addSample(eventTime, pointerCoords);
|
|
}
|
|
|
|
void MotionEvent::addSample(
|
|
int64_t eventTime,
|
|
const PointerCoords* pointerCoords) {
|
|
mSampleEventTimes.push(eventTime);
|
|
mSamplePointerCoords.appendArray(pointerCoords, getPointerCount());
|
|
}
|
|
|
|
void MotionEvent::offsetLocation(float xOffset, float yOffset) {
|
|
mXOffset += xOffset;
|
|
mYOffset += yOffset;
|
|
}
|
|
|
|
// class InputDeviceInfo
|
|
|
|
InputDeviceInfo::InputDeviceInfo() {
|
|
initialize(-1, String8("uninitialized device info"));
|
|
}
|
|
|
|
InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other) :
|
|
mId(other.mId), mName(other.mName), mSources(other.mSources),
|
|
mKeyboardType(other.mKeyboardType),
|
|
mMotionRanges(other.mMotionRanges) {
|
|
}
|
|
|
|
InputDeviceInfo::~InputDeviceInfo() {
|
|
}
|
|
|
|
void InputDeviceInfo::initialize(int32_t id, const String8& name) {
|
|
mId = id;
|
|
mName = name;
|
|
mSources = 0;
|
|
mKeyboardType = AINPUT_KEYBOARD_TYPE_NONE;
|
|
mMotionRanges.clear();
|
|
}
|
|
|
|
const InputDeviceInfo::MotionRange* InputDeviceInfo::getMotionRange(int32_t rangeType) const {
|
|
ssize_t index = mMotionRanges.indexOfKey(rangeType);
|
|
return index >= 0 ? & mMotionRanges.valueAt(index) : NULL;
|
|
}
|
|
|
|
void InputDeviceInfo::addSource(uint32_t source) {
|
|
mSources |= source;
|
|
}
|
|
|
|
void InputDeviceInfo::addMotionRange(int32_t rangeType, float min, float max,
|
|
float flat, float fuzz) {
|
|
MotionRange range = { min, max, flat, fuzz };
|
|
addMotionRange(rangeType, range);
|
|
}
|
|
|
|
void InputDeviceInfo::addMotionRange(int32_t rangeType, const MotionRange& range) {
|
|
mMotionRanges.add(rangeType, range);
|
|
}
|
|
|
|
// class InputDeviceProxy
|
|
|
|
InputDeviceProxy::InputDeviceProxy() {
|
|
}
|
|
|
|
InputDeviceProxy::~InputDeviceProxy() {
|
|
}
|
|
|
|
void InputDeviceProxy::getDeviceIds(Vector<int32_t>& outIds) {
|
|
// TODO use Binder
|
|
}
|
|
|
|
sp<InputDeviceProxy> InputDeviceProxy::getDevice(int32_t id) {
|
|
// TODO use Binder
|
|
return NULL;
|
|
}
|
|
|
|
} // namespace android
|