bring over phonelibs minus frida-gum and qsml

This commit is contained in:
George Hotz
2020-01-17 10:37:11 -08:00
parent 6abffe0ede
commit da6863f427
2473 changed files with 759632 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LIBINPUT_IINPUT_FLINGER_H
#define _LIBINPUT_IINPUT_FLINGER_H
#include <stdint.h>
#include <sys/types.h>
#include <binder/IInterface.h>
namespace android {
/*
* This class defines the Binder IPC interface for accessing various
* InputFlinger features.
*/
class IInputFlinger : public IInterface {
public:
DECLARE_META_INTERFACE(InputFlinger);
};
/**
* Binder implementation.
*/
class BnInputFlinger : public BnInterface<IInputFlinger> {
public:
enum {
DO_SOMETHING_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
};
virtual status_t onTransact(uint32_t code, const Parcel& data,
Parcel* reply, uint32_t flags = 0);
};
} // namespace android
#endif // _LIBINPUT_IINPUT_FLINGER_H

View File

@@ -0,0 +1,681 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LIBINPUT_INPUT_H
#define _LIBINPUT_INPUT_H
/**
* Native input event structures.
*/
#include <android/input.h>
#include <utils/BitSet.h>
#include <utils/KeyedVector.h>
#include <utils/RefBase.h>
#include <utils/String8.h>
#include <utils/Timers.h>
#include <utils/Vector.h>
#include <stdint.h>
/*
* Additional private constants not defined in ndk/ui/input.h.
*/
enum {
/* Signifies that the key is being predispatched */
AKEY_EVENT_FLAG_PREDISPATCH = 0x20000000,
/* Private control to determine when an app is tracking a key sequence. */
AKEY_EVENT_FLAG_START_TRACKING = 0x40000000,
/* Key event is inconsistent with previously sent key events. */
AKEY_EVENT_FLAG_TAINTED = 0x80000000,
};
enum {
/**
* This flag indicates that the window that received this motion event is partly
* or wholly obscured by another visible window above it. This flag is set to true
* even if the event did not directly pass through the obscured area.
* A security sensitive application can check this flag to identify situations in which
* a malicious application may have covered up part of its content for the purpose
* of misleading the user or hijacking touches. An appropriate response might be
* to drop the suspect touches or to take additional precautions to confirm the user's
* actual intent.
*/
AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED = 0x2,
/* Motion event is inconsistent with previously sent motion events. */
AMOTION_EVENT_FLAG_TAINTED = 0x80000000,
};
enum {
/* Used when a motion event is not associated with any display.
* Typically used for non-pointer events. */
ADISPLAY_ID_NONE = -1,
/* The default display id. */
ADISPLAY_ID_DEFAULT = 0,
};
enum {
/*
* Indicates that an input device has switches.
* This input source flag is hidden from the API because switches are only used by the system
* and applications have no way to interact with them.
*/
AINPUT_SOURCE_SWITCH = 0x80000000,
};
enum {
/**
* Constants for LEDs. Hidden from the API since we don't actually expose a way to interact
* with LEDs to developers
*
* NOTE: If you add LEDs here, you must also add them to InputEventLabels.h
*/
ALED_NUM_LOCK = 0x00,
ALED_CAPS_LOCK = 0x01,
ALED_SCROLL_LOCK = 0x02,
ALED_COMPOSE = 0x03,
ALED_KANA = 0x04,
ALED_SLEEP = 0x05,
ALED_SUSPEND = 0x06,
ALED_MUTE = 0x07,
ALED_MISC = 0x08,
ALED_MAIL = 0x09,
ALED_CHARGING = 0x0a,
ALED_CONTROLLER_1 = 0x10,
ALED_CONTROLLER_2 = 0x11,
ALED_CONTROLLER_3 = 0x12,
ALED_CONTROLLER_4 = 0x13,
};
/* Maximum number of controller LEDs we support */
#define MAX_CONTROLLER_LEDS 4
/*
* SystemUiVisibility constants from View.
*/
enum {
ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE = 0,
ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN = 0x00000001,
};
/*
* Maximum number of pointers supported per motion event.
* Smallest number of pointers is 1.
* (We want at least 10 but some touch controllers obstensibly configured for 10 pointers
* will occasionally emit 11. There is not much harm making this constant bigger.)
*/
#define MAX_POINTERS 16
/*
* Maximum number of samples supported per motion event.
*/
#define MAX_SAMPLES UINT16_MAX
/*
* Maximum pointer id value supported in a motion event.
* Smallest pointer id is 0.
* (This is limited by our use of BitSet32 to track pointer assignments.)
*/
#define MAX_POINTER_ID 31
/*
* Declare a concrete type for the NDK's input event forward declaration.
*/
struct AInputEvent {
virtual ~AInputEvent() { }
};
/*
* Declare a concrete type for the NDK's input device forward declaration.
*/
struct AInputDevice {
virtual ~AInputDevice() { }
};
namespace android {
#ifdef HAVE_ANDROID_OS
class Parcel;
#endif
/*
* Flags that flow alongside events in the input dispatch system to help with certain
* policy decisions such as waking from device sleep.
*
* These flags are also defined in frameworks/base/core/java/android/view/WindowManagerPolicy.java.
*/
enum {
/* These flags originate in RawEvents and are generally set in the key map.
* NOTE: If you want a flag to be able to set in a keylayout file, then you must add it to
* InputEventLabels.h as well. */
// Indicates that the event should wake the device.
POLICY_FLAG_WAKE = 0x00000001,
// Indicates that the key is virtual, such as a capacitive button, and should
// generate haptic feedback. Virtual keys may be suppressed for some time
// after a recent touch to prevent accidental activation of virtual keys adjacent
// to the touch screen during an edge swipe.
POLICY_FLAG_VIRTUAL = 0x00000002,
// Indicates that the key is the special function modifier.
POLICY_FLAG_FUNCTION = 0x00000004,
// Indicates that the key represents a special gesture that has been detected by
// the touch firmware or driver. Causes touch events from the same device to be canceled.
POLICY_FLAG_GESTURE = 0x00000008,
POLICY_FLAG_RAW_MASK = 0x0000ffff,
/* These flags are set by the input dispatcher. */
// Indicates that the input event was injected.
POLICY_FLAG_INJECTED = 0x01000000,
// Indicates that the input event is from a trusted source such as a directly attached
// input device or an application with system-wide event injection permission.
POLICY_FLAG_TRUSTED = 0x02000000,
// Indicates that the input event has passed through an input filter.
POLICY_FLAG_FILTERED = 0x04000000,
// Disables automatic key repeating behavior.
POLICY_FLAG_DISABLE_KEY_REPEAT = 0x08000000,
/* These flags are set by the input reader policy as it intercepts each event. */
// Indicates that the device was in an interactive state when the
// event was intercepted.
POLICY_FLAG_INTERACTIVE = 0x20000000,
// Indicates that the event should be dispatched to applications.
// The input event should still be sent to the InputDispatcher so that it can see all
// input events received include those that it will not deliver.
POLICY_FLAG_PASS_TO_USER = 0x40000000,
};
/*
* Pointer coordinate data.
*/
struct PointerCoords {
enum { MAX_AXES = 30 }; // 30 so that sizeof(PointerCoords) == 128
// Bitfield of axes that are present in this structure.
uint64_t bits __attribute__((aligned(8)));
// Values of axes that are stored in this structure packed in order by axis id
// for each axis that is present in the structure according to 'bits'.
float values[MAX_AXES];
inline void clear() {
BitSet64::clear(bits);
}
bool isEmpty() const {
return BitSet64::isEmpty(bits);
}
float getAxisValue(int32_t axis) const;
status_t setAxisValue(int32_t axis, float value);
void scale(float scale);
void applyOffset(float xOffset, float yOffset);
inline float getX() const {
return getAxisValue(AMOTION_EVENT_AXIS_X);
}
inline float getY() const {
return getAxisValue(AMOTION_EVENT_AXIS_Y);
}
#ifdef HAVE_ANDROID_OS
status_t readFromParcel(Parcel* parcel);
status_t writeToParcel(Parcel* parcel) const;
#endif
bool operator==(const PointerCoords& other) const;
inline bool operator!=(const PointerCoords& other) const {
return !(*this == other);
}
void copyFrom(const PointerCoords& other);
private:
void tooManyAxes(int axis);
};
/*
* Pointer property data.
*/
struct PointerProperties {
// The id of the pointer.
int32_t id;
// The pointer tool type.
int32_t toolType;
inline void clear() {
id = -1;
toolType = 0;
}
bool operator==(const PointerProperties& other) const;
inline bool operator!=(const PointerProperties& other) const {
return !(*this == other);
}
void copyFrom(const PointerProperties& other);
};
/*
* Input events.
*/
class InputEvent : public AInputEvent {
public:
virtual ~InputEvent() { }
virtual int32_t getType() const = 0;
inline int32_t getDeviceId() const { return mDeviceId; }
inline int32_t getSource() const { return mSource; }
inline void setSource(int32_t source) { mSource = source; }
protected:
void initialize(int32_t deviceId, int32_t source);
void initialize(const InputEvent& from);
int32_t mDeviceId;
int32_t mSource;
};
/*
* Key events.
*/
class KeyEvent : public InputEvent {
public:
virtual ~KeyEvent() { }
virtual int32_t getType() const { return AINPUT_EVENT_TYPE_KEY; }
inline int32_t getAction() const { return mAction; }
inline int32_t getFlags() const { return mFlags; }
inline void setFlags(int32_t flags) { mFlags = flags; }
inline int32_t getKeyCode() const { return mKeyCode; }
inline int32_t getScanCode() const { return mScanCode; }
inline int32_t getMetaState() const { return mMetaState; }
inline int32_t getRepeatCount() const { return mRepeatCount; }
inline nsecs_t getDownTime() const { return mDownTime; }
inline nsecs_t getEventTime() const { return mEventTime; }
static const char* getLabel(int32_t keyCode);
static int32_t getKeyCodeFromLabel(const char* label);
void 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);
void initialize(const KeyEvent& from);
protected:
int32_t mAction;
int32_t mFlags;
int32_t mKeyCode;
int32_t mScanCode;
int32_t mMetaState;
int32_t mRepeatCount;
nsecs_t mDownTime;
nsecs_t mEventTime;
};
/*
* Motion events.
*/
class MotionEvent : public InputEvent {
public:
virtual ~MotionEvent() { }
virtual int32_t getType() const { return AINPUT_EVENT_TYPE_MOTION; }
inline int32_t getAction() const { return mAction; }
inline int32_t getActionMasked() const { return mAction & AMOTION_EVENT_ACTION_MASK; }
inline int32_t getActionIndex() const {
return (mAction & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK)
>> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
}
inline void setAction(int32_t action) { mAction = action; }
inline int32_t getFlags() const { return mFlags; }
inline void setFlags(int32_t flags) { mFlags = flags; }
inline int32_t getEdgeFlags() const { return mEdgeFlags; }
inline void setEdgeFlags(int32_t edgeFlags) { mEdgeFlags = edgeFlags; }
inline int32_t getMetaState() const { return mMetaState; }
inline void setMetaState(int32_t metaState) { mMetaState = metaState; }
inline int32_t getButtonState() const { return mButtonState; }
inline int32_t setButtonState(int32_t buttonState) { mButtonState = buttonState; }
inline int32_t getActionButton() const { return mActionButton; }
inline void setActionButton(int32_t button) { mActionButton = button; }
inline float getXOffset() const { return mXOffset; }
inline float getYOffset() const { return mYOffset; }
inline float getXPrecision() const { return mXPrecision; }
inline float getYPrecision() const { return mYPrecision; }
inline nsecs_t getDownTime() const { return mDownTime; }
inline void setDownTime(nsecs_t downTime) { mDownTime = downTime; }
inline size_t getPointerCount() const { return mPointerProperties.size(); }
inline const PointerProperties* getPointerProperties(size_t pointerIndex) const {
return &mPointerProperties[pointerIndex];
}
inline int32_t getPointerId(size_t pointerIndex) const {
return mPointerProperties[pointerIndex].id;
}
inline int32_t getToolType(size_t pointerIndex) const {
return mPointerProperties[pointerIndex].toolType;
}
inline nsecs_t getEventTime() const { return mSampleEventTimes[getHistorySize()]; }
const PointerCoords* getRawPointerCoords(size_t pointerIndex) const;
float getRawAxisValue(int32_t axis, size_t pointerIndex) const;
inline float getRawX(size_t pointerIndex) const {
return getRawAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex);
}
inline float getRawY(size_t pointerIndex) const {
return getRawAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex);
}
float getAxisValue(int32_t axis, size_t pointerIndex) const;
inline float getX(size_t pointerIndex) const {
return getAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex);
}
inline float getY(size_t pointerIndex) const {
return getAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex);
}
inline float getPressure(size_t pointerIndex) const {
return getAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pointerIndex);
}
inline float getSize(size_t pointerIndex) const {
return getAxisValue(AMOTION_EVENT_AXIS_SIZE, pointerIndex);
}
inline float getTouchMajor(size_t pointerIndex) const {
return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex);
}
inline float getTouchMinor(size_t pointerIndex) const {
return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex);
}
inline float getToolMajor(size_t pointerIndex) const {
return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex);
}
inline float getToolMinor(size_t pointerIndex) const {
return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex);
}
inline float getOrientation(size_t pointerIndex) const {
return getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex);
}
inline size_t getHistorySize() const { return mSampleEventTimes.size() - 1; }
inline nsecs_t getHistoricalEventTime(size_t historicalIndex) const {
return mSampleEventTimes[historicalIndex];
}
const PointerCoords* getHistoricalRawPointerCoords(
size_t pointerIndex, size_t historicalIndex) const;
float getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex,
size_t historicalIndex) const;
inline float getHistoricalRawX(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalRawAxisValue(
AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex);
}
inline float getHistoricalRawY(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalRawAxisValue(
AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex);
}
float getHistoricalAxisValue(int32_t axis, size_t pointerIndex, size_t historicalIndex) const;
inline float getHistoricalX(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalAxisValue(
AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex);
}
inline float getHistoricalY(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalAxisValue(
AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex);
}
inline float getHistoricalPressure(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalAxisValue(
AMOTION_EVENT_AXIS_PRESSURE, pointerIndex, historicalIndex);
}
inline float getHistoricalSize(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalAxisValue(
AMOTION_EVENT_AXIS_SIZE, pointerIndex, historicalIndex);
}
inline float getHistoricalTouchMajor(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalAxisValue(
AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex, historicalIndex);
}
inline float getHistoricalTouchMinor(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalAxisValue(
AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex, historicalIndex);
}
inline float getHistoricalToolMajor(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalAxisValue(
AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex, historicalIndex);
}
inline float getHistoricalToolMinor(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalAxisValue(
AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex, historicalIndex);
}
inline float getHistoricalOrientation(size_t pointerIndex, size_t historicalIndex) const {
return getHistoricalAxisValue(
AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex, historicalIndex);
}
ssize_t findPointerIndex(int32_t pointerId) const;
void initialize(
int32_t deviceId,
int32_t source,
int32_t action,
int32_t actionButton,
int32_t flags,
int32_t edgeFlags,
int32_t metaState,
int32_t buttonState,
float xOffset,
float yOffset,
float xPrecision,
float yPrecision,
nsecs_t downTime,
nsecs_t eventTime,
size_t pointerCount,
const PointerProperties* pointerProperties,
const PointerCoords* pointerCoords);
void copyFrom(const MotionEvent* other, bool keepHistory);
void addSample(
nsecs_t eventTime,
const PointerCoords* pointerCoords);
void offsetLocation(float xOffset, float yOffset);
void scale(float scaleFactor);
// Apply 3x3 perspective matrix transformation.
// Matrix is in row-major form and compatible with SkMatrix.
void transform(const float matrix[9]);
#ifdef HAVE_ANDROID_OS
status_t readFromParcel(Parcel* parcel);
status_t writeToParcel(Parcel* parcel) const;
#endif
static bool isTouchEvent(int32_t source, int32_t action);
inline bool isTouchEvent() const {
return isTouchEvent(mSource, mAction);
}
// Low-level accessors.
inline const PointerProperties* getPointerProperties() const {
return mPointerProperties.array();
}
inline const nsecs_t* getSampleEventTimes() const { return mSampleEventTimes.array(); }
inline const PointerCoords* getSamplePointerCoords() const {
return mSamplePointerCoords.array();
}
static const char* getLabel(int32_t axis);
static int32_t getAxisFromLabel(const char* label);
protected:
int32_t mAction;
int32_t mActionButton;
int32_t mFlags;
int32_t mEdgeFlags;
int32_t mMetaState;
int32_t mButtonState;
float mXOffset;
float mYOffset;
float mXPrecision;
float mYPrecision;
nsecs_t mDownTime;
Vector<PointerProperties> mPointerProperties;
Vector<nsecs_t> mSampleEventTimes;
Vector<PointerCoords> mSamplePointerCoords;
};
/*
* Input event factory.
*/
class InputEventFactoryInterface {
protected:
virtual ~InputEventFactoryInterface() { }
public:
InputEventFactoryInterface() { }
virtual KeyEvent* createKeyEvent() = 0;
virtual MotionEvent* createMotionEvent() = 0;
};
/*
* A simple input event factory implementation that uses a single preallocated instance
* of each type of input event that are reused for each request.
*/
class PreallocatedInputEventFactory : public InputEventFactoryInterface {
public:
PreallocatedInputEventFactory() { }
virtual ~PreallocatedInputEventFactory() { }
virtual KeyEvent* createKeyEvent() { return & mKeyEvent; }
virtual MotionEvent* createMotionEvent() { return & mMotionEvent; }
private:
KeyEvent mKeyEvent;
MotionEvent mMotionEvent;
};
/*
* An input event factory implementation that maintains a pool of input events.
*/
class PooledInputEventFactory : public InputEventFactoryInterface {
public:
PooledInputEventFactory(size_t maxPoolSize = 20);
virtual ~PooledInputEventFactory();
virtual KeyEvent* createKeyEvent();
virtual MotionEvent* createMotionEvent();
void recycle(InputEvent* event);
private:
const size_t mMaxPoolSize;
Vector<KeyEvent*> mKeyEventPool;
Vector<MotionEvent*> mMotionEventPool;
};
} // namespace android
#endif // _LIBINPUT_INPUT_H

View File

@@ -0,0 +1,170 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LIBINPUT_INPUT_DEVICE_H
#define _LIBINPUT_INPUT_DEVICE_H
#include <input/Input.h>
#include <input/KeyCharacterMap.h>
namespace android {
/*
* Identifies a device.
*/
struct InputDeviceIdentifier {
inline InputDeviceIdentifier() :
bus(0), vendor(0), product(0), version(0) {
}
// Information provided by the kernel.
String8 name;
String8 location;
String8 uniqueId;
uint16_t bus;
uint16_t vendor;
uint16_t product;
uint16_t version;
// A composite input device descriptor string that uniquely identifies the device
// even across reboots or reconnections. The value of this field is used by
// upper layers of the input system to associate settings with individual devices.
// It is hashed from whatever kernel provided information is available.
// Ideally, the way this value is computed should not change between Android releases
// because that would invalidate persistent settings that rely on it.
String8 descriptor;
// A value added to uniquely identify a device in the absence of a unique id. This
// is intended to be a minimum way to distinguish from other active devices and may
// reuse values that are not associated with an input anymore.
uint16_t nonce;
};
/*
* Describes the characteristics and capabilities of an input device.
*/
class InputDeviceInfo {
public:
InputDeviceInfo();
InputDeviceInfo(const InputDeviceInfo& other);
~InputDeviceInfo();
struct MotionRange {
int32_t axis;
uint32_t source;
float min;
float max;
float flat;
float fuzz;
float resolution;
};
void initialize(int32_t id, int32_t generation, int32_t controllerNumber,
const InputDeviceIdentifier& identifier, const String8& alias, bool isExternal,
bool hasMic);
inline int32_t getId() const { return mId; }
inline int32_t getControllerNumber() const { return mControllerNumber; }
inline int32_t getGeneration() const { return mGeneration; }
inline const InputDeviceIdentifier& getIdentifier() const { return mIdentifier; }
inline const String8& getAlias() const { return mAlias; }
inline const String8& getDisplayName() const {
return mAlias.isEmpty() ? mIdentifier.name : mAlias;
}
inline bool isExternal() const { return mIsExternal; }
inline bool hasMic() const { return mHasMic; }
inline uint32_t getSources() const { return mSources; }
const MotionRange* getMotionRange(int32_t axis, uint32_t source) const;
void addSource(uint32_t source);
void addMotionRange(int32_t axis, uint32_t source,
float min, float max, float flat, float fuzz, float resolution);
void addMotionRange(const MotionRange& range);
inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; }
inline int32_t getKeyboardType() const { return mKeyboardType; }
inline void setKeyCharacterMap(const sp<KeyCharacterMap>& value) {
mKeyCharacterMap = value;
}
inline sp<KeyCharacterMap> getKeyCharacterMap() const {
return mKeyCharacterMap;
}
inline void setVibrator(bool hasVibrator) { mHasVibrator = hasVibrator; }
inline bool hasVibrator() const { return mHasVibrator; }
inline void setButtonUnderPad(bool hasButton) { mHasButtonUnderPad = hasButton; }
inline bool hasButtonUnderPad() const { return mHasButtonUnderPad; }
inline const Vector<MotionRange>& getMotionRanges() const {
return mMotionRanges;
}
private:
int32_t mId;
int32_t mGeneration;
int32_t mControllerNumber;
InputDeviceIdentifier mIdentifier;
String8 mAlias;
bool mIsExternal;
bool mHasMic;
uint32_t mSources;
int32_t mKeyboardType;
sp<KeyCharacterMap> mKeyCharacterMap;
bool mHasVibrator;
bool mHasButtonUnderPad;
Vector<MotionRange> mMotionRanges;
};
/* Types of input device configuration files. */
enum InputDeviceConfigurationFileType {
INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION = 0, /* .idc file */
INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_LAYOUT = 1, /* .kl file */
INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_CHARACTER_MAP = 2, /* .kcm file */
};
/*
* Gets the path of an input device configuration file, if one is available.
* Considers both system provided and user installed configuration files.
*
* The device identifier is used to construct several default configuration file
* names to try based on the device name, vendor, product, and version.
*
* Returns an empty string if not found.
*/
extern String8 getInputDeviceConfigurationFilePathByDeviceIdentifier(
const InputDeviceIdentifier& deviceIdentifier,
InputDeviceConfigurationFileType type);
/*
* Gets the path of an input device configuration file, if one is available.
* Considers both system provided and user installed configuration files.
*
* The name is case-sensitive and is used to construct the filename to resolve.
* All characters except 'a'-'z', 'A'-'Z', '0'-'9', '-', and '_' are replaced by underscores.
*
* Returns an empty string if not found.
*/
extern String8 getInputDeviceConfigurationFilePathByName(
const String8& name, InputDeviceConfigurationFileType type);
} // namespace android
#endif // _LIBINPUT_INPUT_DEVICE_H

View File

@@ -0,0 +1,447 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LIBINPUT_INPUT_EVENT_LABELS_H
#define _LIBINPUT_INPUT_EVENT_LABELS_H
#include <input/Input.h>
#include <android/keycodes.h>
#define DEFINE_KEYCODE(key) { #key, AKEYCODE_##key }
#define DEFINE_AXIS(axis) { #axis, AMOTION_EVENT_AXIS_##axis }
#define DEFINE_LED(led) { #led, ALED_##led }
#define DEFINE_FLAG(flag) { #flag, POLICY_FLAG_##flag }
namespace android {
template<typename T, size_t N>
size_t size(T (&)[N]) { return N; }
struct InputEventLabel {
const char *literal;
int value;
};
static const InputEventLabel KEYCODES[] = {
// NOTE: If you add a new keycode here you must also add it to several other files.
// Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list.
DEFINE_KEYCODE(UNKNOWN),
DEFINE_KEYCODE(SOFT_LEFT),
DEFINE_KEYCODE(SOFT_RIGHT),
DEFINE_KEYCODE(HOME),
DEFINE_KEYCODE(BACK),
DEFINE_KEYCODE(CALL),
DEFINE_KEYCODE(ENDCALL),
DEFINE_KEYCODE(0),
DEFINE_KEYCODE(1),
DEFINE_KEYCODE(2),
DEFINE_KEYCODE(3),
DEFINE_KEYCODE(4),
DEFINE_KEYCODE(5),
DEFINE_KEYCODE(6),
DEFINE_KEYCODE(7),
DEFINE_KEYCODE(8),
DEFINE_KEYCODE(9),
DEFINE_KEYCODE(STAR),
DEFINE_KEYCODE(POUND),
DEFINE_KEYCODE(DPAD_UP),
DEFINE_KEYCODE(DPAD_DOWN),
DEFINE_KEYCODE(DPAD_LEFT),
DEFINE_KEYCODE(DPAD_RIGHT),
DEFINE_KEYCODE(DPAD_CENTER),
DEFINE_KEYCODE(VOLUME_UP),
DEFINE_KEYCODE(VOLUME_DOWN),
DEFINE_KEYCODE(POWER),
DEFINE_KEYCODE(CAMERA),
DEFINE_KEYCODE(CLEAR),
DEFINE_KEYCODE(A),
DEFINE_KEYCODE(B),
DEFINE_KEYCODE(C),
DEFINE_KEYCODE(D),
DEFINE_KEYCODE(E),
DEFINE_KEYCODE(F),
DEFINE_KEYCODE(G),
DEFINE_KEYCODE(H),
DEFINE_KEYCODE(I),
DEFINE_KEYCODE(J),
DEFINE_KEYCODE(K),
DEFINE_KEYCODE(L),
DEFINE_KEYCODE(M),
DEFINE_KEYCODE(N),
DEFINE_KEYCODE(O),
DEFINE_KEYCODE(P),
DEFINE_KEYCODE(Q),
DEFINE_KEYCODE(R),
DEFINE_KEYCODE(S),
DEFINE_KEYCODE(T),
DEFINE_KEYCODE(U),
DEFINE_KEYCODE(V),
DEFINE_KEYCODE(W),
DEFINE_KEYCODE(X),
DEFINE_KEYCODE(Y),
DEFINE_KEYCODE(Z),
DEFINE_KEYCODE(COMMA),
DEFINE_KEYCODE(PERIOD),
DEFINE_KEYCODE(ALT_LEFT),
DEFINE_KEYCODE(ALT_RIGHT),
DEFINE_KEYCODE(SHIFT_LEFT),
DEFINE_KEYCODE(SHIFT_RIGHT),
DEFINE_KEYCODE(TAB),
DEFINE_KEYCODE(SPACE),
DEFINE_KEYCODE(SYM),
DEFINE_KEYCODE(EXPLORER),
DEFINE_KEYCODE(ENVELOPE),
DEFINE_KEYCODE(ENTER),
DEFINE_KEYCODE(DEL),
DEFINE_KEYCODE(GRAVE),
DEFINE_KEYCODE(MINUS),
DEFINE_KEYCODE(EQUALS),
DEFINE_KEYCODE(LEFT_BRACKET),
DEFINE_KEYCODE(RIGHT_BRACKET),
DEFINE_KEYCODE(BACKSLASH),
DEFINE_KEYCODE(SEMICOLON),
DEFINE_KEYCODE(APOSTROPHE),
DEFINE_KEYCODE(SLASH),
DEFINE_KEYCODE(AT),
DEFINE_KEYCODE(NUM),
DEFINE_KEYCODE(HEADSETHOOK),
DEFINE_KEYCODE(FOCUS), // *Camera* focus
DEFINE_KEYCODE(PLUS),
DEFINE_KEYCODE(MENU),
DEFINE_KEYCODE(NOTIFICATION),
DEFINE_KEYCODE(SEARCH),
DEFINE_KEYCODE(MEDIA_PLAY_PAUSE),
DEFINE_KEYCODE(MEDIA_STOP),
DEFINE_KEYCODE(MEDIA_NEXT),
DEFINE_KEYCODE(MEDIA_PREVIOUS),
DEFINE_KEYCODE(MEDIA_REWIND),
DEFINE_KEYCODE(MEDIA_FAST_FORWARD),
DEFINE_KEYCODE(MUTE),
DEFINE_KEYCODE(PAGE_UP),
DEFINE_KEYCODE(PAGE_DOWN),
DEFINE_KEYCODE(PICTSYMBOLS),
DEFINE_KEYCODE(SWITCH_CHARSET),
DEFINE_KEYCODE(BUTTON_A),
DEFINE_KEYCODE(BUTTON_B),
DEFINE_KEYCODE(BUTTON_C),
DEFINE_KEYCODE(BUTTON_X),
DEFINE_KEYCODE(BUTTON_Y),
DEFINE_KEYCODE(BUTTON_Z),
DEFINE_KEYCODE(BUTTON_L1),
DEFINE_KEYCODE(BUTTON_R1),
DEFINE_KEYCODE(BUTTON_L2),
DEFINE_KEYCODE(BUTTON_R2),
DEFINE_KEYCODE(BUTTON_THUMBL),
DEFINE_KEYCODE(BUTTON_THUMBR),
DEFINE_KEYCODE(BUTTON_START),
DEFINE_KEYCODE(BUTTON_SELECT),
DEFINE_KEYCODE(BUTTON_MODE),
DEFINE_KEYCODE(ESCAPE),
DEFINE_KEYCODE(FORWARD_DEL),
DEFINE_KEYCODE(CTRL_LEFT),
DEFINE_KEYCODE(CTRL_RIGHT),
DEFINE_KEYCODE(CAPS_LOCK),
DEFINE_KEYCODE(SCROLL_LOCK),
DEFINE_KEYCODE(META_LEFT),
DEFINE_KEYCODE(META_RIGHT),
DEFINE_KEYCODE(FUNCTION),
DEFINE_KEYCODE(SYSRQ),
DEFINE_KEYCODE(BREAK),
DEFINE_KEYCODE(MOVE_HOME),
DEFINE_KEYCODE(MOVE_END),
DEFINE_KEYCODE(INSERT),
DEFINE_KEYCODE(FORWARD),
DEFINE_KEYCODE(MEDIA_PLAY),
DEFINE_KEYCODE(MEDIA_PAUSE),
DEFINE_KEYCODE(MEDIA_CLOSE),
DEFINE_KEYCODE(MEDIA_EJECT),
DEFINE_KEYCODE(MEDIA_RECORD),
DEFINE_KEYCODE(F1),
DEFINE_KEYCODE(F2),
DEFINE_KEYCODE(F3),
DEFINE_KEYCODE(F4),
DEFINE_KEYCODE(F5),
DEFINE_KEYCODE(F6),
DEFINE_KEYCODE(F7),
DEFINE_KEYCODE(F8),
DEFINE_KEYCODE(F9),
DEFINE_KEYCODE(F10),
DEFINE_KEYCODE(F11),
DEFINE_KEYCODE(F12),
DEFINE_KEYCODE(NUM_LOCK),
DEFINE_KEYCODE(NUMPAD_0),
DEFINE_KEYCODE(NUMPAD_1),
DEFINE_KEYCODE(NUMPAD_2),
DEFINE_KEYCODE(NUMPAD_3),
DEFINE_KEYCODE(NUMPAD_4),
DEFINE_KEYCODE(NUMPAD_5),
DEFINE_KEYCODE(NUMPAD_6),
DEFINE_KEYCODE(NUMPAD_7),
DEFINE_KEYCODE(NUMPAD_8),
DEFINE_KEYCODE(NUMPAD_9),
DEFINE_KEYCODE(NUMPAD_DIVIDE),
DEFINE_KEYCODE(NUMPAD_MULTIPLY),
DEFINE_KEYCODE(NUMPAD_SUBTRACT),
DEFINE_KEYCODE(NUMPAD_ADD),
DEFINE_KEYCODE(NUMPAD_DOT),
DEFINE_KEYCODE(NUMPAD_COMMA),
DEFINE_KEYCODE(NUMPAD_ENTER),
DEFINE_KEYCODE(NUMPAD_EQUALS),
DEFINE_KEYCODE(NUMPAD_LEFT_PAREN),
DEFINE_KEYCODE(NUMPAD_RIGHT_PAREN),
DEFINE_KEYCODE(VOLUME_MUTE),
DEFINE_KEYCODE(INFO),
DEFINE_KEYCODE(CHANNEL_UP),
DEFINE_KEYCODE(CHANNEL_DOWN),
DEFINE_KEYCODE(ZOOM_IN),
DEFINE_KEYCODE(ZOOM_OUT),
DEFINE_KEYCODE(TV),
DEFINE_KEYCODE(WINDOW),
DEFINE_KEYCODE(GUIDE),
DEFINE_KEYCODE(DVR),
DEFINE_KEYCODE(BOOKMARK),
DEFINE_KEYCODE(CAPTIONS),
DEFINE_KEYCODE(SETTINGS),
DEFINE_KEYCODE(TV_POWER),
DEFINE_KEYCODE(TV_INPUT),
DEFINE_KEYCODE(STB_POWER),
DEFINE_KEYCODE(STB_INPUT),
DEFINE_KEYCODE(AVR_POWER),
DEFINE_KEYCODE(AVR_INPUT),
DEFINE_KEYCODE(PROG_RED),
DEFINE_KEYCODE(PROG_GREEN),
DEFINE_KEYCODE(PROG_YELLOW),
DEFINE_KEYCODE(PROG_BLUE),
DEFINE_KEYCODE(APP_SWITCH),
DEFINE_KEYCODE(BUTTON_1),
DEFINE_KEYCODE(BUTTON_2),
DEFINE_KEYCODE(BUTTON_3),
DEFINE_KEYCODE(BUTTON_4),
DEFINE_KEYCODE(BUTTON_5),
DEFINE_KEYCODE(BUTTON_6),
DEFINE_KEYCODE(BUTTON_7),
DEFINE_KEYCODE(BUTTON_8),
DEFINE_KEYCODE(BUTTON_9),
DEFINE_KEYCODE(BUTTON_10),
DEFINE_KEYCODE(BUTTON_11),
DEFINE_KEYCODE(BUTTON_12),
DEFINE_KEYCODE(BUTTON_13),
DEFINE_KEYCODE(BUTTON_14),
DEFINE_KEYCODE(BUTTON_15),
DEFINE_KEYCODE(BUTTON_16),
DEFINE_KEYCODE(LANGUAGE_SWITCH),
DEFINE_KEYCODE(MANNER_MODE),
DEFINE_KEYCODE(3D_MODE),
DEFINE_KEYCODE(CONTACTS),
DEFINE_KEYCODE(CALENDAR),
DEFINE_KEYCODE(MUSIC),
DEFINE_KEYCODE(CALCULATOR),
DEFINE_KEYCODE(ZENKAKU_HANKAKU),
DEFINE_KEYCODE(EISU),
DEFINE_KEYCODE(MUHENKAN),
DEFINE_KEYCODE(HENKAN),
DEFINE_KEYCODE(KATAKANA_HIRAGANA),
DEFINE_KEYCODE(YEN),
DEFINE_KEYCODE(RO),
DEFINE_KEYCODE(KANA),
DEFINE_KEYCODE(ASSIST),
DEFINE_KEYCODE(BRIGHTNESS_DOWN),
DEFINE_KEYCODE(BRIGHTNESS_UP),
DEFINE_KEYCODE(MEDIA_AUDIO_TRACK),
DEFINE_KEYCODE(SLEEP),
DEFINE_KEYCODE(WAKEUP),
DEFINE_KEYCODE(PAIRING),
DEFINE_KEYCODE(MEDIA_TOP_MENU),
DEFINE_KEYCODE(11),
DEFINE_KEYCODE(12),
DEFINE_KEYCODE(LAST_CHANNEL),
DEFINE_KEYCODE(TV_DATA_SERVICE),
DEFINE_KEYCODE(VOICE_ASSIST),
DEFINE_KEYCODE(TV_RADIO_SERVICE),
DEFINE_KEYCODE(TV_TELETEXT),
DEFINE_KEYCODE(TV_NUMBER_ENTRY),
DEFINE_KEYCODE(TV_TERRESTRIAL_ANALOG),
DEFINE_KEYCODE(TV_TERRESTRIAL_DIGITAL),
DEFINE_KEYCODE(TV_SATELLITE),
DEFINE_KEYCODE(TV_SATELLITE_BS),
DEFINE_KEYCODE(TV_SATELLITE_CS),
DEFINE_KEYCODE(TV_SATELLITE_SERVICE),
DEFINE_KEYCODE(TV_NETWORK),
DEFINE_KEYCODE(TV_ANTENNA_CABLE),
DEFINE_KEYCODE(TV_INPUT_HDMI_1),
DEFINE_KEYCODE(TV_INPUT_HDMI_2),
DEFINE_KEYCODE(TV_INPUT_HDMI_3),
DEFINE_KEYCODE(TV_INPUT_HDMI_4),
DEFINE_KEYCODE(TV_INPUT_COMPOSITE_1),
DEFINE_KEYCODE(TV_INPUT_COMPOSITE_2),
DEFINE_KEYCODE(TV_INPUT_COMPONENT_1),
DEFINE_KEYCODE(TV_INPUT_COMPONENT_2),
DEFINE_KEYCODE(TV_INPUT_VGA_1),
DEFINE_KEYCODE(TV_AUDIO_DESCRIPTION),
DEFINE_KEYCODE(TV_AUDIO_DESCRIPTION_MIX_UP),
DEFINE_KEYCODE(TV_AUDIO_DESCRIPTION_MIX_DOWN),
DEFINE_KEYCODE(TV_ZOOM_MODE),
DEFINE_KEYCODE(TV_CONTENTS_MENU),
DEFINE_KEYCODE(TV_MEDIA_CONTEXT_MENU),
DEFINE_KEYCODE(TV_TIMER_PROGRAMMING),
DEFINE_KEYCODE(HELP),
DEFINE_KEYCODE(NAVIGATE_PREVIOUS),
DEFINE_KEYCODE(NAVIGATE_NEXT),
DEFINE_KEYCODE(NAVIGATE_IN),
DEFINE_KEYCODE(NAVIGATE_OUT),
DEFINE_KEYCODE(STEM_PRIMARY),
DEFINE_KEYCODE(STEM_1),
DEFINE_KEYCODE(STEM_2),
DEFINE_KEYCODE(STEM_3),
DEFINE_KEYCODE(MEDIA_SKIP_FORWARD),
DEFINE_KEYCODE(MEDIA_SKIP_BACKWARD),
DEFINE_KEYCODE(MEDIA_STEP_FORWARD),
DEFINE_KEYCODE(MEDIA_STEP_BACKWARD),
DEFINE_KEYCODE(SOFT_SLEEP),
{ NULL, 0 }
};
static const InputEventLabel AXES[] = {
DEFINE_AXIS(X),
DEFINE_AXIS(Y),
DEFINE_AXIS(PRESSURE),
DEFINE_AXIS(SIZE),
DEFINE_AXIS(TOUCH_MAJOR),
DEFINE_AXIS(TOUCH_MINOR),
DEFINE_AXIS(TOOL_MAJOR),
DEFINE_AXIS(TOOL_MINOR),
DEFINE_AXIS(ORIENTATION),
DEFINE_AXIS(VSCROLL),
DEFINE_AXIS(HSCROLL),
DEFINE_AXIS(Z),
DEFINE_AXIS(RX),
DEFINE_AXIS(RY),
DEFINE_AXIS(RZ),
DEFINE_AXIS(HAT_X),
DEFINE_AXIS(HAT_Y),
DEFINE_AXIS(LTRIGGER),
DEFINE_AXIS(RTRIGGER),
DEFINE_AXIS(THROTTLE),
DEFINE_AXIS(RUDDER),
DEFINE_AXIS(WHEEL),
DEFINE_AXIS(GAS),
DEFINE_AXIS(BRAKE),
DEFINE_AXIS(DISTANCE),
DEFINE_AXIS(TILT),
DEFINE_AXIS(GENERIC_1),
DEFINE_AXIS(GENERIC_2),
DEFINE_AXIS(GENERIC_3),
DEFINE_AXIS(GENERIC_4),
DEFINE_AXIS(GENERIC_5),
DEFINE_AXIS(GENERIC_6),
DEFINE_AXIS(GENERIC_7),
DEFINE_AXIS(GENERIC_8),
DEFINE_AXIS(GENERIC_9),
DEFINE_AXIS(GENERIC_10),
DEFINE_AXIS(GENERIC_11),
DEFINE_AXIS(GENERIC_12),
DEFINE_AXIS(GENERIC_13),
DEFINE_AXIS(GENERIC_14),
DEFINE_AXIS(GENERIC_15),
DEFINE_AXIS(GENERIC_16),
// NOTE: If you add a new axis here you must also add it to several other files.
// Refer to frameworks/base/core/java/android/view/MotionEvent.java for the full list.
{ NULL, 0 }
};
static const InputEventLabel LEDS[] = {
DEFINE_LED(NUM_LOCK),
DEFINE_LED(CAPS_LOCK),
DEFINE_LED(SCROLL_LOCK),
DEFINE_LED(COMPOSE),
DEFINE_LED(KANA),
DEFINE_LED(SLEEP),
DEFINE_LED(SUSPEND),
DEFINE_LED(MUTE),
DEFINE_LED(MISC),
DEFINE_LED(MAIL),
DEFINE_LED(CHARGING),
DEFINE_LED(CONTROLLER_1),
DEFINE_LED(CONTROLLER_2),
DEFINE_LED(CONTROLLER_3),
DEFINE_LED(CONTROLLER_4),
// NOTE: If you add new LEDs here, you must also add them to Input.h
{ NULL, 0 }
};
static const InputEventLabel FLAGS[] = {
DEFINE_FLAG(WAKE),
DEFINE_FLAG(VIRTUAL),
DEFINE_FLAG(FUNCTION),
DEFINE_FLAG(GESTURE),
{ NULL, 0 }
};
static int lookupValueByLabel(const char* literal, const InputEventLabel *list) {
while (list->literal) {
if (strcmp(literal, list->literal) == 0) {
return list->value;
}
list++;
}
return list->value;
}
static const char* lookupLabelByValue(int value, const InputEventLabel* list) {
while (list->literal) {
if (list->value == value) {
return list->literal;
}
list++;
}
return NULL;
}
static int32_t getKeyCodeByLabel(const char* label) {
return int32_t(lookupValueByLabel(label, KEYCODES));
}
static const char* getLabelByKeyCode(int32_t keyCode) {
if (keyCode >= 0 && keyCode < size(KEYCODES)) {
return KEYCODES[keyCode].literal;
}
return NULL;
}
static uint32_t getKeyFlagByLabel(const char* label) {
return uint32_t(lookupValueByLabel(label, FLAGS));
}
static int32_t getAxisByLabel(const char* label) {
return int32_t(lookupValueByLabel(label, AXES));
}
static const char* getAxisLabel(int32_t axisId) {
return lookupLabelByValue(axisId, AXES);
}
static int32_t getLedByLabel(const char* label) {
return int32_t(lookupValueByLabel(label, LEDS));
}
} // namespace android
#endif // _LIBINPUT_INPUT_EVENT_LABELS_H

View File

@@ -0,0 +1,453 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LIBINPUT_INPUT_TRANSPORT_H
#define _LIBINPUT_INPUT_TRANSPORT_H
/**
* Native input transport.
*
* The InputChannel provides a mechanism for exchanging InputMessage structures across processes.
*
* The InputPublisher and InputConsumer each handle one end-point of an input channel.
* The InputPublisher is used by the input dispatcher to send events to the application.
* The InputConsumer is used by the application to receive events from the input dispatcher.
*/
#include <input/Input.h>
#include <utils/Errors.h>
#include <utils/Timers.h>
#include <utils/RefBase.h>
#include <utils/String8.h>
#include <utils/Vector.h>
#include <utils/BitSet.h>
namespace android {
/*
* Intermediate representation used to send input events and related signals.
*
* Note that this structure is used for IPCs so its layout must be identical
* on 64 and 32 bit processes. This is tested in StructLayout_test.cpp.
*/
struct InputMessage {
enum {
TYPE_KEY = 1,
TYPE_MOTION = 2,
TYPE_FINISHED = 3,
};
struct Header {
uint32_t type;
// We don't need this field in order to align the body below but we
// leave it here because InputMessage::size() and other functions
// compute the size of this structure as sizeof(Header) + sizeof(Body).
uint32_t padding;
} header;
// Body *must* be 8 byte aligned.
union Body {
struct Key {
uint32_t seq;
nsecs_t eventTime __attribute__((aligned(8)));
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 __attribute__((aligned(8)));
inline size_t size() const {
return sizeof(Key);
}
} key;
struct Motion {
uint32_t seq;
nsecs_t eventTime __attribute__((aligned(8)));
int32_t deviceId;
int32_t source;
int32_t action;
int32_t actionButton;
int32_t flags;
int32_t metaState;
int32_t buttonState;
int32_t edgeFlags;
nsecs_t downTime __attribute__((aligned(8)));
float xOffset;
float yOffset;
float xPrecision;
float yPrecision;
uint32_t pointerCount;
// Note that PointerCoords requires 8 byte alignment.
struct Pointer {
PointerProperties properties;
PointerCoords coords;
} pointers[MAX_POINTERS];
int32_t getActionId() const {
uint32_t index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK)
>> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
return pointers[index].properties.id;
}
inline size_t size() const {
return sizeof(Motion) - sizeof(Pointer) * MAX_POINTERS
+ sizeof(Pointer) * pointerCount;
}
} motion;
struct Finished {
uint32_t seq;
bool handled;
inline size_t size() const {
return sizeof(Finished);
}
} finished;
} __attribute__((aligned(8))) body;
bool isValid(size_t actualSize) const;
size_t size() const;
};
/*
* An input channel consists of a local unix domain socket used to send and receive
* input messages across processes. Each channel has a descriptive name for debugging purposes.
*
* Each endpoint has its own InputChannel object that specifies its file descriptor.
*
* The input channel is closed when all references to it are released.
*/
class InputChannel : public RefBase {
protected:
virtual ~InputChannel();
public:
InputChannel(const String8& name, int fd);
/* Creates a pair of input channels.
*
* Returns OK on success.
*/
static status_t openInputChannelPair(const String8& name,
sp<InputChannel>& outServerChannel, sp<InputChannel>& outClientChannel);
inline String8 getName() const { return mName; }
inline int getFd() const { return mFd; }
/* Sends a message to the other endpoint.
*
* If the channel is full then the message is guaranteed not to have been sent at all.
* Try again after the consumer has sent a finished signal indicating that it has
* consumed some of the pending messages from the channel.
*
* Returns OK on success.
* Returns WOULD_BLOCK if the channel is full.
* Returns DEAD_OBJECT if the channel's peer has been closed.
* Other errors probably indicate that the channel is broken.
*/
status_t sendMessage(const InputMessage* msg);
/* Receives a message sent by the other endpoint.
*
* If there is no message present, try again after poll() indicates that the fd
* is readable.
*
* Returns OK on success.
* Returns WOULD_BLOCK if there is no message present.
* Returns DEAD_OBJECT if the channel's peer has been closed.
* Other errors probably indicate that the channel is broken.
*/
status_t receiveMessage(InputMessage* msg);
/* Returns a new object that has a duplicate of this channel's fd. */
sp<InputChannel> dup() const;
private:
String8 mName;
int mFd;
};
/*
* Publishes input events to an input channel.
*/
class InputPublisher {
public:
/* Creates a publisher associated with an input channel. */
explicit InputPublisher(const sp<InputChannel>& channel);
/* Destroys the publisher and releases its input channel. */
~InputPublisher();
/* Gets the underlying input channel. */
inline sp<InputChannel> getChannel() { return mChannel; }
/* Publishes a key event to the input channel.
*
* Returns OK on success.
* Returns WOULD_BLOCK if the channel is full.
* Returns DEAD_OBJECT if the channel's peer has been closed.
* Returns BAD_VALUE if seq is 0.
* Other errors probably indicate that the channel is broken.
*/
status_t publishKeyEvent(
uint32_t seq,
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);
/* Publishes a motion event to the input channel.
*
* Returns OK on success.
* Returns WOULD_BLOCK if the channel is full.
* Returns DEAD_OBJECT if the channel's peer has been closed.
* Returns BAD_VALUE if seq is 0 or if pointerCount is less than 1 or greater than MAX_POINTERS.
* Other errors probably indicate that the channel is broken.
*/
status_t publishMotionEvent(
uint32_t seq,
int32_t deviceId,
int32_t source,
int32_t action,
int32_t actionButton,
int32_t flags,
int32_t edgeFlags,
int32_t metaState,
int32_t buttonState,
float xOffset,
float yOffset,
float xPrecision,
float yPrecision,
nsecs_t downTime,
nsecs_t eventTime,
uint32_t pointerCount,
const PointerProperties* pointerProperties,
const PointerCoords* pointerCoords);
/* Receives the finished signal from the consumer in reply to the original dispatch signal.
* If a signal was received, returns the message sequence number,
* and whether the consumer handled the message.
*
* The returned sequence number is never 0 unless the operation failed.
*
* Returns OK on success.
* Returns WOULD_BLOCK if there is no signal present.
* Returns DEAD_OBJECT if the channel's peer has been closed.
* Other errors probably indicate that the channel is broken.
*/
status_t receiveFinishedSignal(uint32_t* outSeq, bool* outHandled);
private:
sp<InputChannel> mChannel;
};
/*
* Consumes input events from an input channel.
*/
class InputConsumer {
public:
/* Creates a consumer associated with an input channel. */
explicit InputConsumer(const sp<InputChannel>& channel);
/* Destroys the consumer and releases its input channel. */
~InputConsumer();
/* Gets the underlying input channel. */
inline sp<InputChannel> getChannel() { return mChannel; }
/* Consumes an input event from the input channel and copies its contents into
* an InputEvent object created using the specified factory.
*
* Tries to combine a series of move events into larger batches whenever possible.
*
* If consumeBatches is false, then defers consuming pending batched events if it
* is possible for additional samples to be added to them later. Call hasPendingBatch()
* to determine whether a pending batch is available to be consumed.
*
* If consumeBatches is true, then events are still batched but they are consumed
* immediately as soon as the input channel is exhausted.
*
* The frameTime parameter specifies the time when the current display frame started
* rendering in the CLOCK_MONOTONIC time base, or -1 if unknown.
*
* The returned sequence number is never 0 unless the operation failed.
*
* Returns OK on success.
* Returns WOULD_BLOCK if there is no event present.
* Returns DEAD_OBJECT if the channel's peer has been closed.
* Returns NO_MEMORY if the event could not be created.
* Other errors probably indicate that the channel is broken.
*/
status_t consume(InputEventFactoryInterface* factory, bool consumeBatches,
nsecs_t frameTime, uint32_t* outSeq, InputEvent** outEvent);
/* Sends a finished signal to the publisher to inform it that the message
* with the specified sequence number has finished being process and whether
* the message was handled by the consumer.
*
* Returns OK on success.
* Returns BAD_VALUE if seq is 0.
* Other errors probably indicate that the channel is broken.
*/
status_t sendFinishedSignal(uint32_t seq, bool handled);
/* Returns true if there is a deferred event waiting.
*
* Should be called after calling consume() to determine whether the consumer
* has a deferred event to be processed. Deferred events are somewhat special in
* that they have already been removed from the input channel. If the input channel
* becomes empty, the client may need to do extra work to ensure that it processes
* the deferred event despite the fact that the input channel's file descriptor
* is not readable.
*
* One option is simply to call consume() in a loop until it returns WOULD_BLOCK.
* This guarantees that all deferred events will be processed.
*
* Alternately, the caller can call hasDeferredEvent() to determine whether there is
* a deferred event waiting and then ensure that its event loop wakes up at least
* one more time to consume the deferred event.
*/
bool hasDeferredEvent() const;
/* Returns true if there is a pending batch.
*
* Should be called after calling consume() with consumeBatches == false to determine
* whether consume() should be called again later on with consumeBatches == true.
*/
bool hasPendingBatch() const;
private:
// True if touch resampling is enabled.
const bool mResampleTouch;
// The input channel.
sp<InputChannel> mChannel;
// The current input message.
InputMessage mMsg;
// True if mMsg contains a valid input message that was deferred from the previous
// call to consume and that still needs to be handled.
bool mMsgDeferred;
// Batched motion events per device and source.
struct Batch {
Vector<InputMessage> samples;
};
Vector<Batch> mBatches;
// Touch state per device and source, only for sources of class pointer.
struct History {
nsecs_t eventTime;
BitSet32 idBits;
int32_t idToIndex[MAX_POINTER_ID + 1];
PointerCoords pointers[MAX_POINTERS];
void initializeFrom(const InputMessage* msg) {
eventTime = msg->body.motion.eventTime;
idBits.clear();
for (uint32_t i = 0; i < msg->body.motion.pointerCount; i++) {
uint32_t id = msg->body.motion.pointers[i].properties.id;
idBits.markBit(id);
idToIndex[id] = i;
pointers[i].copyFrom(msg->body.motion.pointers[i].coords);
}
}
const PointerCoords& getPointerById(uint32_t id) const {
return pointers[idToIndex[id]];
}
};
struct TouchState {
int32_t deviceId;
int32_t source;
size_t historyCurrent;
size_t historySize;
History history[2];
History lastResample;
void initialize(int32_t deviceId, int32_t source) {
this->deviceId = deviceId;
this->source = source;
historyCurrent = 0;
historySize = 0;
lastResample.eventTime = 0;
lastResample.idBits.clear();
}
void addHistory(const InputMessage* msg) {
historyCurrent ^= 1;
if (historySize < 2) {
historySize += 1;
}
history[historyCurrent].initializeFrom(msg);
}
const History* getHistory(size_t index) const {
return &history[(historyCurrent + index) & 1];
}
};
Vector<TouchState> mTouchStates;
// Chain of batched sequence numbers. When multiple input messages are combined into
// a batch, we append a record here that associates the last sequence number in the
// batch with the previous one. When the finished signal is sent, we traverse the
// chain to individually finish all input messages that were part of the batch.
struct SeqChain {
uint32_t seq; // sequence number of batched input message
uint32_t chain; // sequence number of previous batched input message
};
Vector<SeqChain> mSeqChains;
status_t consumeBatch(InputEventFactoryInterface* factory,
nsecs_t frameTime, uint32_t* outSeq, InputEvent** outEvent);
status_t consumeSamples(InputEventFactoryInterface* factory,
Batch& batch, size_t count, uint32_t* outSeq, InputEvent** outEvent);
void updateTouchState(InputMessage* msg);
void rewriteMessage(const TouchState& state, InputMessage* msg);
void resampleTouchState(nsecs_t frameTime, MotionEvent* event,
const InputMessage *next);
ssize_t findBatch(int32_t deviceId, int32_t source) const;
ssize_t findTouchState(int32_t deviceId, int32_t source) const;
status_t sendUnchainedFinishedSignal(uint32_t seq, bool handled);
static void initializeKeyEvent(KeyEvent* event, const InputMessage* msg);
static void initializeMotionEvent(MotionEvent* event, const InputMessage* msg);
static void addSample(MotionEvent* event, const InputMessage* msg);
static bool canAddSample(const Batch& batch, const InputMessage* msg);
static ssize_t findSampleNoLaterThan(const Batch& batch, nsecs_t time);
static bool shouldResampleTool(int32_t toolType);
static bool isTouchResamplingEnabled();
};
} // namespace android
#endif // _LIBINPUT_INPUT_TRANSPORT_H

View File

@@ -0,0 +1,265 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LIBINPUT_KEY_CHARACTER_MAP_H
#define _LIBINPUT_KEY_CHARACTER_MAP_H
#include <stdint.h>
#if HAVE_ANDROID_OS
#include <binder/IBinder.h>
#endif
#include <input/Input.h>
#include <utils/Errors.h>
#include <utils/KeyedVector.h>
#include <utils/Tokenizer.h>
#include <utils/String8.h>
#include <utils/Unicode.h>
#include <utils/RefBase.h>
namespace android {
/**
* Describes a mapping from Android key codes to characters.
* Also specifies other functions of the keyboard such as the keyboard type
* and key modifier semantics.
*
* This object is immutable after it has been loaded.
*/
class KeyCharacterMap : public RefBase {
public:
enum KeyboardType {
KEYBOARD_TYPE_UNKNOWN = 0,
KEYBOARD_TYPE_NUMERIC = 1,
KEYBOARD_TYPE_PREDICTIVE = 2,
KEYBOARD_TYPE_ALPHA = 3,
KEYBOARD_TYPE_FULL = 4,
KEYBOARD_TYPE_SPECIAL_FUNCTION = 5,
KEYBOARD_TYPE_OVERLAY = 6,
};
enum Format {
// Base keyboard layout, may contain device-specific options, such as "type" declaration.
FORMAT_BASE = 0,
// Overlay keyboard layout, more restrictive, may be published by applications,
// cannot override device-specific options.
FORMAT_OVERLAY = 1,
// Either base or overlay layout ok.
FORMAT_ANY = 2,
};
// Substitute key code and meta state for fallback action.
struct FallbackAction {
int32_t keyCode;
int32_t metaState;
};
/* Loads a key character map from a file. */
static status_t load(const String8& filename, Format format, sp<KeyCharacterMap>* outMap);
/* Loads a key character map from its string contents. */
static status_t loadContents(const String8& filename,
const char* contents, Format format, sp<KeyCharacterMap>* outMap);
/* Combines a base key character map and an overlay. */
static sp<KeyCharacterMap> combine(const sp<KeyCharacterMap>& base,
const sp<KeyCharacterMap>& overlay);
/* Returns an empty key character map. */
static sp<KeyCharacterMap> empty();
/* Gets the keyboard type. */
int32_t getKeyboardType() const;
/* Gets the primary character for this key as in the label physically printed on it.
* Returns 0 if none (eg. for non-printing keys). */
char16_t getDisplayLabel(int32_t keyCode) const;
/* Gets the Unicode character for the number or symbol generated by the key
* when the keyboard is used as a dialing pad.
* Returns 0 if no number or symbol is generated.
*/
char16_t getNumber(int32_t keyCode) const;
/* Gets the Unicode character generated by the key and meta key modifiers.
* Returns 0 if no character is generated.
*/
char16_t getCharacter(int32_t keyCode, int32_t metaState) const;
/* Gets the fallback action to use by default if the application does not
* handle the specified key.
* Returns true if an action was available, false if none.
*/
bool getFallbackAction(int32_t keyCode, int32_t metaState,
FallbackAction* outFallbackAction) const;
/* Gets the first matching Unicode character that can be generated by the key,
* preferring the one with the specified meta key modifiers.
* Returns 0 if no matching character is generated.
*/
char16_t getMatch(int32_t keyCode, const char16_t* chars,
size_t numChars, int32_t metaState) const;
/* Gets a sequence of key events that could plausibly generate the specified
* character sequence. Returns false if some of the characters cannot be generated.
*/
bool getEvents(int32_t deviceId, const char16_t* chars, size_t numChars,
Vector<KeyEvent>& outEvents) const;
/* Maps a scan code and usage code to a key code, in case this key map overrides
* the mapping in some way. */
status_t mapKey(int32_t scanCode, int32_t usageCode, int32_t* outKeyCode) const;
/* Tries to find a replacement key code for a given key code and meta state
* in character map. */
void tryRemapKey(int32_t scanCode, int32_t metaState,
int32_t* outKeyCode, int32_t* outMetaState) const;
#if HAVE_ANDROID_OS
/* Reads a key map from a parcel. */
static sp<KeyCharacterMap> readFromParcel(Parcel* parcel);
/* Writes a key map to a parcel. */
void writeToParcel(Parcel* parcel) const;
#endif
protected:
virtual ~KeyCharacterMap();
private:
struct Behavior {
Behavior();
Behavior(const Behavior& other);
/* The next behavior in the list, or NULL if none. */
Behavior* next;
/* The meta key modifiers for this behavior. */
int32_t metaState;
/* The character to insert. */
char16_t character;
/* The fallback keycode if the key is not handled. */
int32_t fallbackKeyCode;
/* The replacement keycode if the key has to be replaced outright. */
int32_t replacementKeyCode;
};
struct Key {
Key();
Key(const Key& other);
~Key();
/* The single character label printed on the key, or 0 if none. */
char16_t label;
/* The number or symbol character generated by the key, or 0 if none. */
char16_t number;
/* The list of key behaviors sorted from most specific to least specific
* meta key binding. */
Behavior* firstBehavior;
};
class Parser {
enum State {
STATE_TOP = 0,
STATE_KEY = 1,
};
enum {
PROPERTY_LABEL = 1,
PROPERTY_NUMBER = 2,
PROPERTY_META = 3,
};
struct Property {
inline Property(int32_t property = 0, int32_t metaState = 0) :
property(property), metaState(metaState) { }
int32_t property;
int32_t metaState;
};
KeyCharacterMap* mMap;
Tokenizer* mTokenizer;
Format mFormat;
State mState;
int32_t mKeyCode;
public:
Parser(KeyCharacterMap* map, Tokenizer* tokenizer, Format format);
~Parser();
status_t parse();
private:
status_t parseType();
status_t parseMap();
status_t parseMapKey();
status_t parseKey();
status_t parseKeyProperty();
status_t finishKey(Key* key);
status_t parseModifier(const String8& token, int32_t* outMetaState);
status_t parseCharacterLiteral(char16_t* outCharacter);
};
static sp<KeyCharacterMap> sEmpty;
KeyedVector<int32_t, Key*> mKeys;
int mType;
KeyedVector<int32_t, int32_t> mKeysByScanCode;
KeyedVector<int32_t, int32_t> mKeysByUsageCode;
KeyCharacterMap();
KeyCharacterMap(const KeyCharacterMap& other);
bool getKey(int32_t keyCode, const Key** outKey) const;
bool getKeyBehavior(int32_t keyCode, int32_t metaState,
const Key** outKey, const Behavior** outBehavior) const;
static bool matchesMetaState(int32_t eventMetaState, int32_t behaviorMetaState);
bool findKey(char16_t ch, int32_t* outKeyCode, int32_t* outMetaState) const;
static status_t load(Tokenizer* tokenizer, Format format, sp<KeyCharacterMap>* outMap);
static void addKey(Vector<KeyEvent>& outEvents,
int32_t deviceId, int32_t keyCode, int32_t metaState, bool down, nsecs_t time);
static void addMetaKeys(Vector<KeyEvent>& outEvents,
int32_t deviceId, int32_t metaState, bool down, nsecs_t time,
int32_t* currentMetaState);
static bool addSingleEphemeralMetaKey(Vector<KeyEvent>& outEvents,
int32_t deviceId, int32_t metaState, bool down, nsecs_t time,
int32_t keyCode, int32_t keyMetaState,
int32_t* currentMetaState);
static void addDoubleEphemeralMetaKey(Vector<KeyEvent>& outEvents,
int32_t deviceId, int32_t metaState, bool down, nsecs_t time,
int32_t leftKeyCode, int32_t leftKeyMetaState,
int32_t rightKeyCode, int32_t rightKeyMetaState,
int32_t eitherKeyMetaState,
int32_t* currentMetaState);
static void addLockedMetaKey(Vector<KeyEvent>& outEvents,
int32_t deviceId, int32_t metaState, nsecs_t time,
int32_t keyCode, int32_t keyMetaState,
int32_t* currentMetaState);
};
} // namespace android
#endif // _LIBINPUT_KEY_CHARACTER_MAP_H

View File

@@ -0,0 +1,117 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LIBINPUT_KEY_LAYOUT_MAP_H
#define _LIBINPUT_KEY_LAYOUT_MAP_H
#include <stdint.h>
#include <utils/Errors.h>
#include <utils/KeyedVector.h>
#include <utils/Tokenizer.h>
#include <utils/RefBase.h>
namespace android {
struct AxisInfo {
enum Mode {
// Axis value is reported directly.
MODE_NORMAL = 0,
// Axis value should be inverted before reporting.
MODE_INVERT = 1,
// Axis value should be split into two axes
MODE_SPLIT = 2,
};
// Axis mode.
Mode mode;
// Axis id.
// When split, this is the axis used for values smaller than the split position.
int32_t axis;
// When split, this is the axis used for values after higher than the split position.
int32_t highAxis;
// The split value, or 0 if not split.
int32_t splitValue;
// The flat value, or -1 if none.
int32_t flatOverride;
AxisInfo() : mode(MODE_NORMAL), axis(-1), highAxis(-1), splitValue(0), flatOverride(-1) {
}
};
/**
* Describes a mapping from keyboard scan codes and joystick axes to Android key codes and axes.
*
* This object is immutable after it has been loaded.
*/
class KeyLayoutMap : public RefBase {
public:
static status_t load(const String8& filename, sp<KeyLayoutMap>* outMap);
status_t mapKey(int32_t scanCode, int32_t usageCode,
int32_t* outKeyCode, uint32_t* outFlags) const;
status_t findScanCodesForKey(int32_t keyCode, Vector<int32_t>* outScanCodes) const;
status_t findScanCodeForLed(int32_t ledCode, int32_t* outScanCode) const;
status_t findUsageCodeForLed(int32_t ledCode, int32_t* outUsageCode) const;
status_t mapAxis(int32_t scanCode, AxisInfo* outAxisInfo) const;
protected:
virtual ~KeyLayoutMap();
private:
struct Key {
int32_t keyCode;
uint32_t flags;
};
struct Led {
int32_t ledCode;
};
KeyedVector<int32_t, Key> mKeysByScanCode;
KeyedVector<int32_t, Key> mKeysByUsageCode;
KeyedVector<int32_t, AxisInfo> mAxes;
KeyedVector<int32_t, Led> mLedsByScanCode;
KeyedVector<int32_t, Led> mLedsByUsageCode;
KeyLayoutMap();
const Key* getKey(int32_t scanCode, int32_t usageCode) const;
class Parser {
KeyLayoutMap* mMap;
Tokenizer* mTokenizer;
public:
Parser(KeyLayoutMap* map, Tokenizer* tokenizer);
~Parser();
status_t parse();
private:
status_t parseKey();
status_t parseAxis();
status_t parseLed();
};
};
} // namespace android
#endif // _LIBINPUT_KEY_LAYOUT_MAP_H

View File

@@ -0,0 +1,104 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LIBINPUT_KEYBOARD_H
#define _LIBINPUT_KEYBOARD_H
#include <input/Input.h>
#include <input/InputDevice.h>
#include <input/InputEventLabels.h>
#include <utils/Errors.h>
#include <utils/String8.h>
#include <utils/PropertyMap.h>
namespace android {
enum {
/* Device id of the built in keyboard. */
DEVICE_ID_BUILT_IN_KEYBOARD = 0,
/* Device id of a generic virtual keyboard with a full layout that can be used
* to synthesize key events. */
DEVICE_ID_VIRTUAL_KEYBOARD = -1,
};
class KeyLayoutMap;
class KeyCharacterMap;
/**
* Loads the key layout map and key character map for a keyboard device.
*/
class KeyMap {
public:
String8 keyLayoutFile;
sp<KeyLayoutMap> keyLayoutMap;
String8 keyCharacterMapFile;
sp<KeyCharacterMap> keyCharacterMap;
KeyMap();
~KeyMap();
status_t load(const InputDeviceIdentifier& deviceIdenfier,
const PropertyMap* deviceConfiguration);
inline bool haveKeyLayout() const {
return !keyLayoutFile.isEmpty();
}
inline bool haveKeyCharacterMap() const {
return !keyCharacterMapFile.isEmpty();
}
inline bool isComplete() const {
return haveKeyLayout() && haveKeyCharacterMap();
}
private:
bool probeKeyMap(const InputDeviceIdentifier& deviceIdentifier, const String8& name);
status_t loadKeyLayout(const InputDeviceIdentifier& deviceIdentifier, const String8& name);
status_t loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifier,
const String8& name);
String8 getPath(const InputDeviceIdentifier& deviceIdentifier,
const String8& name, InputDeviceConfigurationFileType type);
};
/**
* Returns true if the keyboard is eligible for use as a built-in keyboard.
*/
extern bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier,
const PropertyMap* deviceConfiguration, const KeyMap* keyMap);
/**
* Updates a meta state field when a key is pressed or released.
*/
extern int32_t updateMetaState(int32_t keyCode, bool down, int32_t oldMetaState);
/**
* Normalizes the meta state such that if either the left or right modifier
* meta state bits are set then the result will also include the universal
* bit for that modifier.
*/
extern int32_t normalizeMetaState(int32_t oldMetaState);
/**
* Returns true if a key is a meta key like ALT or CAPS_LOCK.
*/
extern bool isMetaKey(int32_t keyCode);
} // namespace android
#endif // _LIBINPUT_KEYBOARD_H

View File

@@ -0,0 +1,107 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LIBINPUT_VELOCITY_CONTROL_H
#define _LIBINPUT_VELOCITY_CONTROL_H
#include <input/Input.h>
#include <input/VelocityTracker.h>
#include <utils/Timers.h>
namespace android {
/*
* Specifies parameters that govern pointer or wheel acceleration.
*/
struct VelocityControlParameters {
// A scale factor that is multiplied with the raw velocity deltas
// prior to applying any other velocity control factors. The scale
// factor should be used to adapt the input device resolution
// (eg. counts per inch) to the output device resolution (eg. pixels per inch).
//
// Must be a positive value.
// Default is 1.0 (no scaling).
float scale;
// The scaled speed at which acceleration begins to be applied.
// This value establishes the upper bound of a low speed regime for
// small precise motions that are performed without any acceleration.
//
// Must be a non-negative value.
// Default is 0.0 (no low threshold).
float lowThreshold;
// The scaled speed at which maximum acceleration is applied.
// The difference between highThreshold and lowThreshold controls
// the range of speeds over which the acceleration factor is interpolated.
// The wider the range, the smoother the acceleration.
//
// Must be a non-negative value greater than or equal to lowThreshold.
// Default is 0.0 (no high threshold).
float highThreshold;
// The acceleration factor.
// When the speed is above the low speed threshold, the velocity will scaled
// by an interpolated value between 1.0 and this amount.
//
// Must be a positive greater than or equal to 1.0.
// Default is 1.0 (no acceleration).
float acceleration;
VelocityControlParameters() :
scale(1.0f), lowThreshold(0.0f), highThreshold(0.0f), acceleration(1.0f) {
}
VelocityControlParameters(float scale, float lowThreshold,
float highThreshold, float acceleration) :
scale(scale), lowThreshold(lowThreshold),
highThreshold(highThreshold), acceleration(acceleration) {
}
};
/*
* Implements mouse pointer and wheel speed control and acceleration.
*/
class VelocityControl {
public:
VelocityControl();
/* Sets the various parameters. */
void setParameters(const VelocityControlParameters& parameters);
/* Resets the current movement counters to zero.
* This has the effect of nullifying any acceleration. */
void reset();
/* Translates a raw movement delta into an appropriately
* scaled / accelerated delta based on the current velocity. */
void move(nsecs_t eventTime, float* deltaX, float* deltaY);
private:
// If no movements are received within this amount of time,
// we assume the movement has stopped and reset the movement counters.
static const nsecs_t STOP_TIME = 500 * 1000000; // 500 ms
VelocityControlParameters mParameters;
nsecs_t mLastMovementTime;
VelocityTracker::Position mRawPosition;
VelocityTracker mVelocityTracker;
};
} // namespace android
#endif // _LIBINPUT_VELOCITY_CONTROL_H

View File

@@ -0,0 +1,269 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LIBINPUT_VELOCITY_TRACKER_H
#define _LIBINPUT_VELOCITY_TRACKER_H
#include <input/Input.h>
#include <utils/Timers.h>
#include <utils/BitSet.h>
namespace android {
class VelocityTrackerStrategy;
/*
* Calculates the velocity of pointer movements over time.
*/
class VelocityTracker {
public:
struct Position {
float x, y;
};
struct Estimator {
static const size_t MAX_DEGREE = 4;
// Estimator time base.
nsecs_t time;
// Polynomial coefficients describing motion in X and Y.
float xCoeff[MAX_DEGREE + 1], yCoeff[MAX_DEGREE + 1];
// Polynomial degree (number of coefficients), or zero if no information is
// available.
uint32_t degree;
// Confidence (coefficient of determination), between 0 (no fit) and 1 (perfect fit).
float confidence;
inline void clear() {
time = 0;
degree = 0;
confidence = 0;
for (size_t i = 0; i <= MAX_DEGREE; i++) {
xCoeff[i] = 0;
yCoeff[i] = 0;
}
}
};
// Creates a velocity tracker using the specified strategy.
// If strategy is NULL, uses the default strategy for the platform.
VelocityTracker(const char* strategy = NULL);
~VelocityTracker();
// Resets the velocity tracker state.
void clear();
// Resets the velocity tracker state for specific pointers.
// Call this method when some pointers have changed and may be reusing
// an id that was assigned to a different pointer earlier.
void clearPointers(BitSet32 idBits);
// Adds movement information for a set of pointers.
// The idBits bitfield specifies the pointer ids of the pointers whose positions
// are included in the movement.
// The positions array contains position information for each pointer in order by
// increasing id. Its size should be equal to the number of one bits in idBits.
void addMovement(nsecs_t eventTime, BitSet32 idBits, const Position* positions);
// Adds movement information for all pointers in a MotionEvent, including historical samples.
void addMovement(const MotionEvent* event);
// Gets the velocity of the specified pointer id in position units per second.
// Returns false and sets the velocity components to zero if there is
// insufficient movement information for the pointer.
bool getVelocity(uint32_t id, float* outVx, float* outVy) const;
// Gets an estimator for the recent movements of the specified pointer id.
// Returns false and clears the estimator if there is no information available
// about the pointer.
bool getEstimator(uint32_t id, Estimator* outEstimator) const;
// Gets the active pointer id, or -1 if none.
inline int32_t getActivePointerId() const { return mActivePointerId; }
// Gets a bitset containing all pointer ids from the most recent movement.
inline BitSet32 getCurrentPointerIdBits() const { return mCurrentPointerIdBits; }
private:
static const char* DEFAULT_STRATEGY;
nsecs_t mLastEventTime;
BitSet32 mCurrentPointerIdBits;
int32_t mActivePointerId;
VelocityTrackerStrategy* mStrategy;
bool configureStrategy(const char* strategy);
static VelocityTrackerStrategy* createStrategy(const char* strategy);
};
/*
* Implements a particular velocity tracker algorithm.
*/
class VelocityTrackerStrategy {
protected:
VelocityTrackerStrategy() { }
public:
virtual ~VelocityTrackerStrategy() { }
virtual void clear() = 0;
virtual void clearPointers(BitSet32 idBits) = 0;
virtual void addMovement(nsecs_t eventTime, BitSet32 idBits,
const VelocityTracker::Position* positions) = 0;
virtual bool getEstimator(uint32_t id, VelocityTracker::Estimator* outEstimator) const = 0;
};
/*
* Velocity tracker algorithm based on least-squares linear regression.
*/
class LeastSquaresVelocityTrackerStrategy : public VelocityTrackerStrategy {
public:
enum Weighting {
// No weights applied. All data points are equally reliable.
WEIGHTING_NONE,
// Weight by time delta. Data points clustered together are weighted less.
WEIGHTING_DELTA,
// Weight such that points within a certain horizon are weighed more than those
// outside of that horizon.
WEIGHTING_CENTRAL,
// Weight such that points older than a certain amount are weighed less.
WEIGHTING_RECENT,
};
// Degree must be no greater than Estimator::MAX_DEGREE.
LeastSquaresVelocityTrackerStrategy(uint32_t degree, Weighting weighting = WEIGHTING_NONE);
virtual ~LeastSquaresVelocityTrackerStrategy();
virtual void clear();
virtual void clearPointers(BitSet32 idBits);
virtual void addMovement(nsecs_t eventTime, BitSet32 idBits,
const VelocityTracker::Position* positions);
virtual bool getEstimator(uint32_t id, VelocityTracker::Estimator* outEstimator) const;
private:
// Sample horizon.
// We don't use too much history by default since we want to react to quick
// changes in direction.
static const nsecs_t HORIZON = 100 * 1000000; // 100 ms
// Number of samples to keep.
static const uint32_t HISTORY_SIZE = 20;
struct Movement {
nsecs_t eventTime;
BitSet32 idBits;
VelocityTracker::Position positions[MAX_POINTERS];
inline const VelocityTracker::Position& getPosition(uint32_t id) const {
return positions[idBits.getIndexOfBit(id)];
}
};
float chooseWeight(uint32_t index) const;
const uint32_t mDegree;
const Weighting mWeighting;
uint32_t mIndex;
Movement mMovements[HISTORY_SIZE];
};
/*
* Velocity tracker algorithm that uses an IIR filter.
*/
class IntegratingVelocityTrackerStrategy : public VelocityTrackerStrategy {
public:
// Degree must be 1 or 2.
IntegratingVelocityTrackerStrategy(uint32_t degree);
~IntegratingVelocityTrackerStrategy();
virtual void clear();
virtual void clearPointers(BitSet32 idBits);
virtual void addMovement(nsecs_t eventTime, BitSet32 idBits,
const VelocityTracker::Position* positions);
virtual bool getEstimator(uint32_t id, VelocityTracker::Estimator* outEstimator) const;
private:
// Current state estimate for a particular pointer.
struct State {
nsecs_t updateTime;
uint32_t degree;
float xpos, xvel, xaccel;
float ypos, yvel, yaccel;
};
const uint32_t mDegree;
BitSet32 mPointerIdBits;
State mPointerState[MAX_POINTER_ID + 1];
void initState(State& state, nsecs_t eventTime, float xpos, float ypos) const;
void updateState(State& state, nsecs_t eventTime, float xpos, float ypos) const;
void populateEstimator(const State& state, VelocityTracker::Estimator* outEstimator) const;
};
/*
* Velocity tracker strategy used prior to ICS.
*/
class LegacyVelocityTrackerStrategy : public VelocityTrackerStrategy {
public:
LegacyVelocityTrackerStrategy();
virtual ~LegacyVelocityTrackerStrategy();
virtual void clear();
virtual void clearPointers(BitSet32 idBits);
virtual void addMovement(nsecs_t eventTime, BitSet32 idBits,
const VelocityTracker::Position* positions);
virtual bool getEstimator(uint32_t id, VelocityTracker::Estimator* outEstimator) const;
private:
// Oldest sample to consider when calculating the velocity.
static const nsecs_t HORIZON = 200 * 1000000; // 100 ms
// Number of samples to keep.
static const uint32_t HISTORY_SIZE = 20;
// The minimum duration between samples when estimating velocity.
static const nsecs_t MIN_DURATION = 10 * 1000000; // 10 ms
struct Movement {
nsecs_t eventTime;
BitSet32 idBits;
VelocityTracker::Position positions[MAX_POINTERS];
inline const VelocityTracker::Position& getPosition(uint32_t id) const {
return positions[idBits.getIndexOfBit(id)];
}
};
uint32_t mIndex;
Movement mMovements[HISTORY_SIZE];
};
} // namespace android
#endif // _LIBINPUT_VELOCITY_TRACKER_H

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LIBINPUT_VIRTUAL_KEY_MAP_H
#define _LIBINPUT_VIRTUAL_KEY_MAP_H
#include <stdint.h>
#include <input/Input.h>
#include <utils/Errors.h>
#include <utils/KeyedVector.h>
#include <utils/Tokenizer.h>
#include <utils/String8.h>
#include <utils/Unicode.h>
namespace android {
/* Describes a virtual key. */
struct VirtualKeyDefinition {
int32_t scanCode;
// configured position data, specified in display coords
int32_t centerX;
int32_t centerY;
int32_t width;
int32_t height;
};
/**
* Describes a collection of virtual keys on a touch screen in terms of
* virtual scan codes and hit rectangles.
*
* This object is immutable after it has been loaded.
*/
class VirtualKeyMap {
public:
~VirtualKeyMap();
static status_t load(const String8& filename, VirtualKeyMap** outMap);
inline const Vector<VirtualKeyDefinition>& getVirtualKeys() const {
return mVirtualKeys;
}
private:
class Parser {
VirtualKeyMap* mMap;
Tokenizer* mTokenizer;
public:
Parser(VirtualKeyMap* map, Tokenizer* tokenizer);
~Parser();
status_t parse();
private:
bool consumeFieldDelimiterAndSkipWhitespace();
bool parseNextIntField(int32_t* outValue);
};
Vector<VirtualKeyDefinition> mVirtualKeys;
VirtualKeyMap();
};
} // namespace android
#endif // _LIBINPUT_KEY_CHARACTER_MAP_H