Input system bug fixes, particularly for stylus.

Bug: 5049148

Finished stylus support, including support for indirect stylus
and mouse tools.

Added TILT axis.  When stylus tilt X/Y is available, it is transformed
into an orientation and tilt inclination which is a more convenient
representation and a simpler extension to the exiting API.

Touch devices now only report touch data using a single input
source.  Previously touch devices in pointer mode would report
both absolute touch pad data and cooked pointer gestures.
Now we just pick one.  The touch device switches modes as needed
when the focused application enables/disables pointer gestures.
This change greatly simplifies the code and reduces the load
on the input dispatcher.

Fixed an incorrect assumption that the value of ABS_(MT_)DISTANCE
would be zero whenever the stylus was in direct contact.  It appears
that the correct way to determine whether the stylus is in direct
contact (rather than hovering) is by checking for a non-zero
reported pressure.

Added code to read the initial state of tool buttons and axis values
when the input devices are initialized or reset.  This fixes
problems where the input mapper state might have the wrong initial
state.

Moved responsibility for cancelling pending inputs (keys down,
touches, etc.) to the InputDispatcher by sending it a device reset
notification.  This frees the InputReader from having to synthesize
events during reset, which was cumbersome and somewhat brittle
to begin with.

Consolidated more of the common accumulator logic from
SingleTouchInputMapper and MultiTouchInputMapper into
TouchInputMapper.

Improved the PointerLocation output.

Change-Id: I595d3647f7fd7cb1e3eff8b3c76b85043b5fe2f0
This commit is contained in:
Jeff Brown
2011-08-18 11:20:58 -07:00
parent c0a2222552
commit 65fd251c39
13 changed files with 1761 additions and 928 deletions

View File

@@ -22315,6 +22315,7 @@ package android.view {
field public static final int AXIS_RZ = 14; // 0xe
field public static final int AXIS_SIZE = 3; // 0x3
field public static final int AXIS_THROTTLE = 19; // 0x13
field public static final int AXIS_TILT = 25; // 0x19
field public static final int AXIS_TOOL_MAJOR = 6; // 0x6
field public static final int AXIS_TOOL_MINOR = 7; // 0x7
field public static final int AXIS_TOUCH_MAJOR = 4; // 0x4

View File

@@ -619,6 +619,11 @@ public final class MotionEvent extends InputEvent implements Parcelable {
* indicates that the major axis of contact is oriented to the left.
* The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
* (finger pointing fully right).
* <li>For a stylus, the orientation indicates the direction in which the stylus
* is pointing in relation to the vertical axis of the current orientation of the screen.
* The range is from -PI radians to PI radians, where 0 is pointing up,
* -PI/2 radians is pointing left, -PI or PI radians is pointing down, and PI/2 radians
* is pointing right. See also {@link #AXIS_TILT}.
* </ul>
* </p>
*
@@ -883,8 +888,8 @@ public final class MotionEvent extends InputEvent implements Parcelable {
* <p>
* <ul>
* <li>For a stylus, reports the distance of the stylus from the screen.
* The value is nominally measured in millimeters where 0.0 indicates direct contact
* and larger values indicate increasing distance from the surface.
* A value of 0.0 indicates direct contact and larger values indicate increasing
* distance from the surface.
* </ul>
* </p>
*
@@ -895,6 +900,24 @@ public final class MotionEvent extends InputEvent implements Parcelable {
*/
public static final int AXIS_DISTANCE = 24;
/**
* Axis constant: Tilt axis of a motion event.
* <p>
* <ul>
* <li>For a stylus, reports the tilt angle of the stylus in radians where
* 0 radians indicates that the stylus is being held perpendicular to the
* surface, and PI/2 radians indicates that the stylus is being held flat
* against the surface.
* </ul>
* </p>
*
* @see #getAxisValue(int, int)
* @see #getHistoricalAxisValue(int, int, int)
* @see MotionEvent.PointerCoords#getAxisValue(int, int)
* @see InputDevice#getMotionRange
*/
public static final int AXIS_TILT = 25;
/**
* Axis constant: Generic 1 axis of a motion event.
* The interpretation of a generic axis is device-specific.
@@ -1104,6 +1127,7 @@ public final class MotionEvent extends InputEvent implements Parcelable {
names.append(AXIS_GAS, "AXIS_GAS");
names.append(AXIS_BRAKE, "AXIS_BRAKE");
names.append(AXIS_DISTANCE, "AXIS_DISTANCE");
names.append(AXIS_TILT, "AXIS_TILT");
names.append(AXIS_GENERIC_1, "AXIS_GENERIC_1");
names.append(AXIS_GENERIC_2, "AXIS_GENERIC_2");
names.append(AXIS_GENERIC_3, "AXIS_GENERIC_3");

View File

@@ -46,6 +46,7 @@ public class PointerLocationView extends View {
// Most recent coordinates.
private PointerCoords mCoords = new PointerCoords();
private int mToolType;
// Most recent velocity.
private float mXVelocity;
@@ -88,7 +89,7 @@ public class PointerLocationView extends View {
private int mMaxNumPointers;
private int mActivePointerId;
private final ArrayList<PointerState> mPointers = new ArrayList<PointerState>();
private final PointerCoords mHoverCoords = new PointerCoords();
private final PointerCoords mTempCoords = new PointerCoords();
private final VelocityTracker mVelocity;
@@ -306,22 +307,66 @@ public class PointerLocationView extends View {
ps.mCoords.toolMinor, ps.mCoords.orientation, mPaint);
// Draw the orientation arrow.
float arrowSize = ps.mCoords.toolMajor * 0.7f;
if (arrowSize < 20) {
arrowSize = 20;
}
mPaint.setARGB(255, pressureLevel, 255, 0);
float orientationVectorX = (float) (Math.sin(-ps.mCoords.orientation)
* ps.mCoords.toolMajor * 0.7);
float orientationVectorY = (float) (Math.cos(-ps.mCoords.orientation)
* ps.mCoords.toolMajor * 0.7);
canvas.drawLine(
ps.mCoords.x - orientationVectorX, ps.mCoords.y - orientationVectorY,
ps.mCoords.x + orientationVectorX, ps.mCoords.y + orientationVectorY,
mPaint);
float orientationVectorX = (float) (Math.sin(ps.mCoords.orientation)
* arrowSize);
float orientationVectorY = (float) (-Math.cos(ps.mCoords.orientation)
* arrowSize);
if (ps.mToolType == MotionEvent.TOOL_TYPE_STYLUS
|| ps.mToolType == MotionEvent.TOOL_TYPE_ERASER) {
// Show full circle orientation.
canvas.drawLine(ps.mCoords.x, ps.mCoords.y,
ps.mCoords.x + orientationVectorX,
ps.mCoords.y + orientationVectorY,
mPaint);
} else {
// Show half circle orientation.
canvas.drawLine(
ps.mCoords.x - orientationVectorX,
ps.mCoords.y - orientationVectorY,
ps.mCoords.x + orientationVectorX,
ps.mCoords.y + orientationVectorY,
mPaint);
}
// Draw the tilt point along the orientation arrow.
float tiltScale = (float) Math.sin(
ps.mCoords.getAxisValue(MotionEvent.AXIS_TILT));
canvas.drawCircle(
ps.mCoords.x + orientationVectorX * tiltScale,
ps.mCoords.y + orientationVectorY * tiltScale,
3.0f, mPaint);
}
}
}
}
private void logPointerCoords(int action, int index, MotionEvent.PointerCoords coords, int id,
int toolType, int buttonState) {
private void logMotionEvent(String type, MotionEvent event) {
final int action = event.getAction();
final int N = event.getHistorySize();
final int NI = event.getPointerCount();
for (int historyPos = 0; historyPos < N; historyPos++) {
for (int i = 0; i < NI; i++) {
final int id = event.getPointerId(i);
event.getHistoricalPointerCoords(i, historyPos, mTempCoords);
logCoords(type, action, i, mTempCoords, id,
event.getToolType(i), event.getButtonState());
}
}
for (int i = 0; i < NI; i++) {
final int id = event.getPointerId(i);
event.getPointerCoords(i, mTempCoords);
logCoords(type, action, i, mTempCoords, id,
event.getToolType(i), event.getButtonState());
}
}
private void logCoords(String type, int action, int index,
MotionEvent.PointerCoords coords, int id, int toolType, int buttonState) {
final String prefix;
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
@@ -373,7 +418,7 @@ public class PointerLocationView extends View {
}
Log.i(TAG, mText.clear()
.append("Pointer ").append(id + 1)
.append(type).append(" id ").append(id + 1)
.append(": ")
.append(prefix)
.append(" (").append(coords.x, 3).append(", ").append(coords.y, 3)
@@ -385,6 +430,9 @@ public class PointerLocationView extends View {
.append(" ToolMinor=").append(coords.toolMinor, 3)
.append(" Orientation=").append((float)(coords.orientation * 180 / Math.PI), 1)
.append("deg")
.append(" Tilt=").append((float)(
coords.getAxisValue(MotionEvent.AXIS_TILT) * 180 / Math.PI), 1)
.append("deg")
.append(" Distance=").append(coords.getAxisValue(MotionEvent.AXIS_DISTANCE), 1)
.append(" VScroll=").append(coords.getAxisValue(MotionEvent.AXIS_VSCROLL), 1)
.append(" HScroll=").append(coords.getAxisValue(MotionEvent.AXIS_HSCROLL), 1)
@@ -445,10 +493,10 @@ public class PointerLocationView extends View {
for (int i = 0; i < NI; i++) {
final int id = event.getPointerId(i);
final PointerState ps = mCurDown ? mPointers.get(id) : null;
final PointerCoords coords = ps != null ? ps.mCoords : mHoverCoords;
final PointerCoords coords = ps != null ? ps.mCoords : mTempCoords;
event.getHistoricalPointerCoords(i, historyPos, coords);
if (mPrintCoords) {
logPointerCoords(action, i, coords, id,
logCoords("Pointer", action, i, coords, id,
event.getToolType(i), event.getButtonState());
}
if (ps != null) {
@@ -459,16 +507,17 @@ public class PointerLocationView extends View {
for (int i = 0; i < NI; i++) {
final int id = event.getPointerId(i);
final PointerState ps = mCurDown ? mPointers.get(id) : null;
final PointerCoords coords = ps != null ? ps.mCoords : mHoverCoords;
final PointerCoords coords = ps != null ? ps.mCoords : mTempCoords;
event.getPointerCoords(i, coords);
if (mPrintCoords) {
logPointerCoords(action, i, coords, id,
logCoords("Pointer", action, i, coords, id,
event.getToolType(i), event.getButtonState());
}
if (ps != null) {
ps.addTrace(coords.x, coords.y);
ps.mXVelocity = mVelocity.getXVelocity(id);
ps.mYVelocity = mVelocity.getYVelocity(id);
ps.mToolType = event.getToolType(i);
}
}
@@ -515,11 +564,11 @@ public class PointerLocationView extends View {
if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) {
addPointerEvent(event);
} else if ((source & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
Log.i(TAG, "Joystick: " + event);
logMotionEvent("Joystick", event);
} else if ((source & InputDevice.SOURCE_CLASS_POSITION) != 0) {
Log.i(TAG, "Position: " + event);
logMotionEvent("Position", event);
} else {
Log.i(TAG, "Generic: " + event);
logMotionEvent("Generic", event);
}
return true;
}
@@ -563,7 +612,7 @@ public class PointerLocationView extends View {
@Override
public boolean onTrackballEvent(MotionEvent event) {
Log.i(TAG, "Trackball: " + event);
logMotionEvent("Trackball", event);
return true;
}

View File

@@ -278,6 +278,8 @@ static const KeycodeLabel AXES[] = {
{ "WHEEL", 21 },
{ "GAS", 22 },
{ "BRAKE", 23 },
{ "DISTANCE", 24 },
{ "TILT", 25 },
{ "GENERIC_1", 32 },
{ "GENERIC_2", 33 },
{ "GENERIC_3", 34 },

View File

@@ -373,6 +373,7 @@ enum {
AMOTION_EVENT_AXIS_GAS = 22,
AMOTION_EVENT_AXIS_BRAKE = 23,
AMOTION_EVENT_AXIS_DISTANCE = 24,
AMOTION_EVENT_AXIS_TILT = 25,
AMOTION_EVENT_AXIS_GENERIC_1 = 32,
AMOTION_EVENT_AXIS_GENERIC_2 = 33,
AMOTION_EVENT_AXIS_GENERIC_3 = 34,

View File

@@ -401,6 +401,14 @@ void InputDispatcher::dispatchOnceInnerLocked(nsecs_t* nextWakeupTime) {
break;
}
case EventEntry::TYPE_DEVICE_RESET: {
DeviceResetEntry* typedEntry =
static_cast<DeviceResetEntry*>(mPendingEvent);
done = dispatchDeviceResetLocked(currentTime, typedEntry);
dropReason = DROP_REASON_NOT_DROPPED; // device resets are never dropped
break;
}
case EventEntry::TYPE_KEY: {
KeyEntry* typedEntry = static_cast<KeyEntry*>(mPendingEvent);
if (isAppSwitchDue) {
@@ -727,6 +735,19 @@ bool InputDispatcher::dispatchConfigurationChangedLocked(
return true;
}
bool InputDispatcher::dispatchDeviceResetLocked(
nsecs_t currentTime, DeviceResetEntry* entry) {
#if DEBUG_OUTBOUND_EVENT_DETAILS
LOGD("dispatchDeviceReset - eventTime=%lld, deviceId=%d", entry->eventTime, entry->deviceId);
#endif
CancelationOptions options(CancelationOptions::CANCEL_ALL_EVENTS,
"device was reset");
options.deviceId = entry->deviceId;
synthesizeCancelationEventsForAllConnectionsLocked(options);
return true;
}
bool InputDispatcher::dispatchKeyLocked(nsecs_t currentTime, KeyEntry* entry,
DropReason* dropReason, nsecs_t* nextWakeupTime) {
// Preprocessing.
@@ -2921,6 +2942,25 @@ void InputDispatcher::notifySwitch(const NotifySwitchArgs* args) {
args->switchCode, args->switchValue, policyFlags);
}
void InputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs* args) {
#if DEBUG_INBOUND_EVENT_DETAILS
LOGD("notifyDeviceReset - eventTime=%lld, deviceId=%d",
args->eventTime, args->deviceId);
#endif
bool needWake;
{ // acquire lock
AutoMutex _l(mLock);
DeviceResetEntry* newEntry = new DeviceResetEntry(args->eventTime, args->deviceId);
needWake = enqueueInboundEventLocked(newEntry);
} // release lock
if (needWake) {
mLooper->wake();
}
}
int32_t InputDispatcher::injectInputEvent(const InputEvent* event,
int32_t injectorPid, int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis,
uint32_t policyFlags) {
@@ -4016,6 +4056,17 @@ InputDispatcher::ConfigurationChangedEntry::~ConfigurationChangedEntry() {
}
// --- InputDispatcher::DeviceResetEntry ---
InputDispatcher::DeviceResetEntry::DeviceResetEntry(nsecs_t eventTime, int32_t deviceId) :
EventEntry(TYPE_DEVICE_RESET, eventTime, 0),
deviceId(deviceId) {
}
InputDispatcher::DeviceResetEntry::~DeviceResetEntry() {
}
// --- InputDispatcher::KeyEntry ---
InputDispatcher::KeyEntry::KeyEntry(nsecs_t eventTime,
@@ -4407,6 +4458,10 @@ bool InputDispatcher::InputState::shouldCancelKey(const KeyMemento& memento,
return false;
}
if (options.deviceId != -1 && memento.deviceId != options.deviceId) {
return false;
}
switch (options.mode) {
case CancelationOptions::CANCEL_ALL_EVENTS:
case CancelationOptions::CANCEL_NON_POINTER_EVENTS:
@@ -4420,6 +4475,10 @@ bool InputDispatcher::InputState::shouldCancelKey(const KeyMemento& memento,
bool InputDispatcher::InputState::shouldCancelMotion(const MotionMemento& memento,
const CancelationOptions& options) {
if (options.deviceId != -1 && memento.deviceId != options.deviceId) {
return false;
}
switch (options.mode) {
case CancelationOptions::CANCEL_ALL_EVENTS:
return true;

View File

@@ -381,6 +381,7 @@ public:
virtual void notifyKey(const NotifyKeyArgs* args);
virtual void notifyMotion(const NotifyMotionArgs* args);
virtual void notifySwitch(const NotifySwitchArgs* args);
virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args);
virtual int32_t injectInputEvent(const InputEvent* event,
int32_t injectorPid, int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis,
@@ -424,6 +425,7 @@ private:
struct EventEntry : Link<EventEntry> {
enum {
TYPE_CONFIGURATION_CHANGED,
TYPE_DEVICE_RESET,
TYPE_KEY,
TYPE_MOTION
};
@@ -453,6 +455,15 @@ private:
virtual ~ConfigurationChangedEntry();
};
struct DeviceResetEntry : EventEntry {
int32_t deviceId;
DeviceResetEntry(nsecs_t eventTime, int32_t deviceId);
protected:
virtual ~DeviceResetEntry();
};
struct KeyEntry : EventEntry {
int32_t deviceId;
uint32_t source;
@@ -688,8 +699,11 @@ private:
// The specific keycode of the key event to cancel, or -1 to cancel any key event.
int32_t keyCode;
// The specific device id of events to cancel, or -1 to cancel events from any device.
int32_t deviceId;
CancelationOptions(Mode mode, const char* reason) :
mode(mode), reason(reason), keyCode(-1) { }
mode(mode), reason(reason), keyCode(-1), deviceId(-1) { }
};
/* Tracks dispatched key and motion event state so that cancelation events can be
@@ -982,6 +996,8 @@ private:
// Dispatch inbound events.
bool dispatchConfigurationChangedLocked(
nsecs_t currentTime, ConfigurationChangedEntry* entry);
bool dispatchDeviceResetLocked(
nsecs_t currentTime, DeviceResetEntry* entry);
bool dispatchKeyLocked(
nsecs_t currentTime, KeyEntry* entry,
DropReason* dropReason, nsecs_t* nextWakeupTime);

View File

@@ -118,6 +118,21 @@ void NotifySwitchArgs::notify(const sp<InputListenerInterface>& listener) const
}
// --- NotifyDeviceResetArgs ---
NotifyDeviceResetArgs::NotifyDeviceResetArgs(nsecs_t eventTime, int32_t deviceId) :
eventTime(eventTime), deviceId(deviceId) {
}
NotifyDeviceResetArgs::NotifyDeviceResetArgs(const NotifyDeviceResetArgs& other) :
eventTime(other.eventTime), deviceId(other.deviceId) {
}
void NotifyDeviceResetArgs::notify(const sp<InputListenerInterface>& listener) const {
listener->notifyDeviceReset(this);
}
// --- QueuedInputListener ---
QueuedInputListener::QueuedInputListener(const sp<InputListenerInterface>& innerListener) :
@@ -148,6 +163,10 @@ void QueuedInputListener::notifySwitch(const NotifySwitchArgs* args) {
mArgsQueue.push(new NotifySwitchArgs(*args));
}
void QueuedInputListener::notifyDeviceReset(const NotifyDeviceResetArgs* args) {
mArgsQueue.push(new NotifyDeviceResetArgs(*args));
}
void QueuedInputListener::flush() {
size_t count = mArgsQueue.size();
for (size_t i = 0; i < count; i++) {

View File

@@ -131,6 +131,24 @@ struct NotifySwitchArgs : public NotifyArgs {
};
/* Describes a device reset event, such as when a device is added,
* reconfigured, or removed. */
struct NotifyDeviceResetArgs : public NotifyArgs {
nsecs_t eventTime;
int32_t deviceId;
inline NotifyDeviceResetArgs() { }
NotifyDeviceResetArgs(nsecs_t eventTime, int32_t deviceId);
NotifyDeviceResetArgs(const NotifyDeviceResetArgs& other);
virtual ~NotifyDeviceResetArgs() { }
virtual void notify(const sp<InputListenerInterface>& listener) const;
};
/*
* The interface used by the InputReader to notify the InputListener about input events.
*/
@@ -144,6 +162,7 @@ public:
virtual void notifyKey(const NotifyKeyArgs* args) = 0;
virtual void notifyMotion(const NotifyMotionArgs* args) = 0;
virtual void notifySwitch(const NotifySwitchArgs* args) = 0;
virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) = 0;
};
@@ -162,6 +181,7 @@ public:
virtual void notifyKey(const NotifyKeyArgs* args);
virtual void notifyMotion(const NotifyMotionArgs* args);
virtual void notifySwitch(const NotifySwitchArgs* args);
virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args);
void flush();

File diff suppressed because it is too large Load Diff

View File

@@ -53,6 +53,9 @@ struct InputReaderConfiguration {
// The pointer gesture control changed.
CHANGE_POINTER_GESTURE_ENABLEMENT = 1 << 1,
// The display size or orientation changed.
CHANGE_DISPLAY_INFO = 1 << 2,
// All devices must be reopened.
CHANGE_MUST_REOPEN = 1 << 31,
};
@@ -153,6 +156,26 @@ struct InputReaderConfiguration {
pointerGestureSwipeMaxWidthRatio(0.25f),
pointerGestureMovementSpeedRatio(0.8f),
pointerGestureZoomSpeedRatio(0.3f) { }
bool getDisplayInfo(int32_t displayId, bool external,
int32_t* width, int32_t* height, int32_t* orientation) const;
void setDisplayInfo(int32_t displayId, bool external,
int32_t width, int32_t height, int32_t orientation);
private:
struct DisplayInfo {
int32_t width;
int32_t height;
int32_t orientation;
DisplayInfo() :
width(-1), height(-1), orientation(DISPLAY_ORIENTATION_0) {
}
};
DisplayInfo mInternalDisplay;
DisplayInfo mExternalDisplay;
};
@@ -174,22 +197,6 @@ protected:
virtual ~InputReaderPolicyInterface() { }
public:
/* Display orientations. */
enum {
ROTATION_0 = 0,
ROTATION_90 = 1,
ROTATION_180 = 2,
ROTATION_270 = 3
};
/* Gets information about the display with the specified id.
* If external is true, returns the size of the external mirrored
* counterpart of the specified display.
* Returns true if the display info is available, false otherwise.
*/
virtual bool getDisplayInfo(int32_t displayId, bool external,
int32_t* width, int32_t* height, int32_t* orientation) = 0;
/* Gets the input reader configuration. */
virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) = 0;
@@ -364,8 +371,8 @@ private:
// low-level input event decoding and device management
void processEventsLocked(const RawEvent* rawEvents, size_t count);
void addDeviceLocked(int32_t deviceId);
void removeDeviceLocked(int32_t deviceId);
void addDeviceLocked(nsecs_t when, int32_t deviceId);
void removeDeviceLocked(nsecs_t when, int32_t deviceId);
void processEventsForDeviceLocked(int32_t deviceId, const RawEvent* rawEvents, size_t count);
void timeoutExpiredLocked(nsecs_t when);
@@ -431,8 +438,8 @@ public:
void dump(String8& dump);
void addMapper(InputMapper* mapper);
void configure(const InputReaderConfiguration* config, uint32_t changes);
void reset();
void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
void reset(nsecs_t when);
void process(const RawEvent* rawEvents, size_t count);
void timeoutExpired(nsecs_t when);
@@ -447,9 +454,25 @@ public:
void fadePointer();
void notifyReset(nsecs_t when);
inline const PropertyMap& getConfiguration() { return mConfiguration; }
inline EventHubInterface* getEventHub() { return mContext->getEventHub(); }
bool hasKey(int32_t code) {
return getEventHub()->hasScanCode(mId, code);
}
bool isKeyPressed(int32_t code) {
return getEventHub()->getScanCodeState(mId, code) == AKEY_STATE_DOWN;
}
int32_t getAbsoluteAxisValue(int32_t code) {
int32_t value;
getEventHub()->getAbsoluteAxisValue(mId, code, &value);
return value;
}
private:
InputReaderContext* mContext;
int32_t mId;
@@ -472,8 +495,8 @@ private:
class CursorButtonAccumulator {
public:
CursorButtonAccumulator();
void reset(InputDevice* device);
void clearButtons();
void process(const RawEvent* rawEvent);
uint32_t getButtonState() const;
@@ -487,6 +510,8 @@ private:
bool mBtnForward;
bool mBtnExtra;
bool mBtnTask;
void clearButtons();
};
@@ -495,10 +520,32 @@ private:
class CursorMotionAccumulator {
public:
CursorMotionAccumulator();
void configure(InputDevice* device);
void reset(InputDevice* device);
void process(const RawEvent* rawEvent);
void finishSync();
inline int32_t getRelativeX() const { return mRelX; }
inline int32_t getRelativeY() const { return mRelY; }
private:
int32_t mRelX;
int32_t mRelY;
void clearRelativeAxes();
};
/* Keeps track of cursor scrolling motions. */
class CursorScrollAccumulator {
public:
CursorScrollAccumulator();
void configure(InputDevice* device);
void reset(InputDevice* device);
void process(const RawEvent* rawEvent);
void finishSync();
inline bool haveRelativeVWheel() const { return mHaveRelWheel; }
inline bool haveRelativeHWheel() const { return mHaveRelHWheel; }
@@ -516,6 +563,8 @@ private:
int32_t mRelY;
int32_t mRelWheel;
int32_t mRelHWheel;
void clearRelativeAxes();
};
@@ -524,8 +573,8 @@ class TouchButtonAccumulator {
public:
TouchButtonAccumulator();
void configure(InputDevice* device);
void reset(InputDevice* device);
void clearButtons();
void process(const RawEvent* rawEvent);
uint32_t getButtonState() const;
@@ -542,6 +591,13 @@ private:
bool mBtnToolFinger;
bool mBtnToolPen;
bool mBtnToolRubber;
bool mBtnToolBrush;
bool mBtnToolPencil;
bool mBtnToolAirbrush;
bool mBtnToolMouse;
bool mBtnToolLens;
void clearButtons();
};
@@ -556,6 +612,8 @@ struct RawPointerAxes {
RawAbsoluteAxisInfo toolMinor;
RawAbsoluteAxisInfo orientation;
RawAbsoluteAxisInfo distance;
RawAbsoluteAxisInfo tiltX;
RawAbsoluteAxisInfo tiltY;
RawAbsoluteAxisInfo trackingId;
RawAbsoluteAxisInfo slot;
@@ -577,6 +635,8 @@ struct RawPointerData {
int32_t toolMinor;
int32_t orientation;
int32_t distance;
int32_t tiltX;
int32_t tiltY;
int32_t toolType; // a fully decoded AMOTION_EVENT_TOOL_TYPE constant
bool isHovering;
};
@@ -637,14 +697,16 @@ class SingleTouchMotionAccumulator {
public:
SingleTouchMotionAccumulator();
void clearAbsoluteAxes();
void process(const RawEvent* rawEvent);
void reset(InputDevice* device);
inline int32_t getAbsoluteX() const { return mAbsX; }
inline int32_t getAbsoluteY() const { return mAbsY; }
inline int32_t getAbsolutePressure() const { return mAbsPressure; }
inline int32_t getAbsoluteToolWidth() const { return mAbsToolWidth; }
inline int32_t getAbsoluteDistance() const { return mAbsDistance; }
inline int32_t getAbsoluteTiltX() const { return mAbsTiltX; }
inline int32_t getAbsoluteTiltY() const { return mAbsTiltY; }
private:
int32_t mAbsX;
@@ -652,6 +714,10 @@ private:
int32_t mAbsPressure;
int32_t mAbsToolWidth;
int32_t mAbsDistance;
int32_t mAbsTiltX;
int32_t mAbsTiltY;
void clearAbsoluteAxes();
};
@@ -703,11 +769,10 @@ public:
~MultiTouchMotionAccumulator();
void configure(size_t slotCount, bool usingSlotsProtocol);
void reset(InputDevice* device);
void process(const RawEvent* rawEvent);
void finishSync();
void clearSlots(int32_t initialSlot);
inline bool isUsingSlotsProtocol() const { return mUsingSlotsProtocol; }
inline size_t getSlotCount() const { return mSlotCount; }
inline const Slot* getSlot(size_t index) const { return &mSlots[index]; }
@@ -716,12 +781,22 @@ private:
Slot* mSlots;
size_t mSlotCount;
bool mUsingSlotsProtocol;
void clearSlots(int32_t initialSlot);
};
/* An input mapper transforms raw input events into cooked event data.
* A single input device can have multiple associated input mappers in order to interpret
* different classes of events.
*
* InputMapper lifecycle:
* - create
* - configure with 0 changes
* - reset
* - process, process, process (may occasionally reconfigure with non-zero changes or reset)
* - reset
* - destroy
*/
class InputMapper {
public:
@@ -739,8 +814,8 @@ public:
virtual uint32_t getSources() = 0;
virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
virtual void dump(String8& dump);
virtual void configure(const InputReaderConfiguration* config, uint32_t changes);
virtual void reset();
virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
virtual void reset(nsecs_t when);
virtual void process(const RawEvent* rawEvent) = 0;
virtual void timeoutExpired(nsecs_t when);
@@ -788,8 +863,8 @@ public:
virtual uint32_t getSources();
virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
virtual void dump(String8& dump);
virtual void configure(const InputReaderConfiguration* config, uint32_t changes);
virtual void reset();
virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
virtual void reset(nsecs_t when);
virtual void process(const RawEvent* rawEvent);
virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
@@ -800,8 +875,6 @@ public:
virtual int32_t getMetaState();
private:
Mutex mLock;
struct KeyDown {
int32_t keyCode;
int32_t scanCode;
@@ -810,6 +883,8 @@ private:
uint32_t mSource;
int32_t mKeyboardType;
int32_t mOrientation; // orientation for dpad keys
Vector<KeyDown> mKeyDowns; // keys that are down
int32_t mMetaState;
nsecs_t mDownTime; // time of most recent key down
@@ -828,8 +903,6 @@ private:
bool orientationAware;
} mParameters;
void initialize();
void configureParameters();
void dumpParameters(String8& dump);
@@ -856,8 +929,8 @@ public:
virtual uint32_t getSources();
virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
virtual void dump(String8& dump);
virtual void configure(const InputReaderConfiguration* config, uint32_t changes);
virtual void reset();
virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
virtual void reset(nsecs_t when);
virtual void process(const RawEvent* rawEvent);
virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
@@ -882,6 +955,7 @@ private:
CursorButtonAccumulator mCursorButtonAccumulator;
CursorMotionAccumulator mCursorMotionAccumulator;
CursorScrollAccumulator mCursorScrollAccumulator;
int32_t mSource;
float mXScale;
@@ -898,13 +972,13 @@ private:
VelocityControl mWheelXVelocityControl;
VelocityControl mWheelYVelocityControl;
int32_t mOrientation;
sp<PointerControllerInterface> mPointerController;
int32_t mButtonState;
nsecs_t mDownTime;
void initialize();
void configureParameters();
void dumpParameters(String8& dump);
@@ -920,8 +994,9 @@ public:
virtual uint32_t getSources();
virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
virtual void dump(String8& dump);
virtual void configure(const InputReaderConfiguration* config, uint32_t changes);
virtual void reset();
virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
virtual void reset(nsecs_t when);
virtual void process(const RawEvent* rawEvent);
virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
@@ -932,6 +1007,10 @@ public:
virtual void timeoutExpired(nsecs_t when);
protected:
CursorButtonAccumulator mCursorButtonAccumulator;
CursorScrollAccumulator mCursorScrollAccumulator;
TouchButtonAccumulator mTouchButtonAccumulator;
struct VirtualKey {
int32_t keyCode;
int32_t scanCode;
@@ -948,9 +1027,16 @@ protected:
}
};
// Input sources supported by the device.
uint32_t mTouchSource; // sources when reporting touch data
uint32_t mPointerSource; // sources when reporting pointer gestures
// Input sources and device mode.
uint32_t mSource;
enum DeviceMode {
DEVICE_MODE_DISABLED, // input is disabled
DEVICE_MODE_DIRECT, // direct mapping (touchscreen)
DEVICE_MODE_UNSCALED, // unscaled mapping (touchpad)
DEVICE_MODE_POINTER, // pointer mapping (pointer)
};
DeviceMode mDeviceMode;
// The reader's configuration.
InputReaderConfiguration mConfig;
@@ -1053,6 +1139,18 @@ protected:
int32_t mCurrentButtonState;
int32_t mLastButtonState;
// Scroll state.
int32_t mCurrentRawVScroll;
int32_t mCurrentRawHScroll;
// Id bits used to differentiate fingers, stylus and mouse tools.
BitSet32 mCurrentFingerIdBits; // finger or unknown
BitSet32 mLastFingerIdBits;
BitSet32 mCurrentStylusIdBits; // stylus or eraser
BitSet32 mLastStylusIdBits;
BitSet32 mCurrentMouseIdBits; // mouse or lens
BitSet32 mLastMouseIdBits;
// True if we sent a HOVER_ENTER event.
bool mSentHoverEnter;
@@ -1068,7 +1166,7 @@ protected:
virtual void dumpParameters(String8& dump);
virtual void configureRawPointerAxes();
virtual void dumpRawPointerAxes(String8& dump);
virtual bool configureSurface();
virtual void configureSurface(nsecs_t when, bool* outResetNeeded);
virtual void dumpSurface(String8& dump);
virtual void configureVirtualKeys();
virtual void dumpVirtualKeys(String8& dump);
@@ -1076,7 +1174,7 @@ protected:
virtual void resolveCalibration();
virtual void dumpCalibration(String8& dump);
void syncTouch(nsecs_t when, bool havePointerIds);
virtual void syncTouch(nsecs_t when, bool* outHavePointerIds) = 0;
private:
// The surface orientation and width and height set by configureSurface().
@@ -1102,16 +1200,21 @@ private:
float mSizeScale;
float mOrientationCenter;
float mOrientationScale;
float mDistanceScale;
bool mHaveTilt;
float mTiltXCenter;
float mTiltXScale;
float mTiltYCenter;
float mTiltYScale;
// Oriented motion ranges for input device info.
struct OrientedRanges {
InputDeviceInfo::MotionRange x;
InputDeviceInfo::MotionRange y;
bool havePressure;
InputDeviceInfo::MotionRange pressure;
bool haveSize;
@@ -1130,6 +1233,22 @@ private:
bool haveDistance;
InputDeviceInfo::MotionRange distance;
bool haveTilt;
InputDeviceInfo::MotionRange tilt;
OrientedRanges() {
clear();
}
void clear() {
haveSize = false;
haveTouchSize = false;
haveToolSize = false;
haveOrientation = false;
haveDistance = false;
haveTilt = false;
}
} mOrientedRanges;
// Oriented dimensions and precision.
@@ -1146,13 +1265,13 @@ private:
int32_t scanCode;
} mCurrentVirtualKey;
// Scale factor for gesture based pointer movements.
float mPointerGestureXMovementScale;
float mPointerGestureYMovementScale;
// Scale factor for gesture or mouse based pointer movements.
float mPointerXMovementScale;
float mPointerYMovementScale;
// Scale factor for gesture based zooming and other freeform motions.
float mPointerGestureXZoomScale;
float mPointerGestureYZoomScale;
float mPointerXZoomScale;
float mPointerYZoomScale;
// The maximum swipe width.
float mPointerGestureMaxSwipeWidth;
@@ -1163,6 +1282,14 @@ private:
uint64_t distance : 48; // squared distance
};
enum PointerUsage {
POINTER_USAGE_NONE,
POINTER_USAGE_GESTURES,
POINTER_USAGE_STYLUS,
POINTER_USAGE_MOUSE,
};
PointerUsage mPointerUsage;
struct PointerGesture {
enum Mode {
// No fingers, button is not pressed.
@@ -1273,9 +1400,6 @@ private:
// A velocity tracker for determining whether to switch active pointers during drags.
VelocityTracker velocityTracker;
// Velocity control for pointer movements.
VelocityControl pointerVelocityControl;
void reset() {
firstTouchTime = LLONG_MIN;
activeTouchId = -1;
@@ -1288,7 +1412,6 @@ private:
velocityTracker.clear();
resetTap();
resetQuietTime();
pointerVelocityControl.reset();
}
void resetTap() {
@@ -1301,7 +1424,38 @@ private:
}
} mPointerGesture;
void initialize();
struct PointerSimple {
PointerCoords currentCoords;
PointerProperties currentProperties;
PointerCoords lastCoords;
PointerProperties lastProperties;
// True if the pointer is down.
bool down;
// True if the pointer is hovering.
bool hovering;
// Time the pointer last went down.
nsecs_t downTime;
void reset() {
currentCoords.clear();
currentProperties.clear();
lastCoords.clear();
lastProperties.clear();
down = false;
hovering = false;
downTime = 0;
}
} mPointerSimple;
// The pointer and scroll velocity controls.
VelocityControl mPointerVelocityControl;
VelocityControl mWheelXVelocityControl;
VelocityControl mWheelYVelocityControl;
void sync(nsecs_t when);
bool consumeRawTouches(nsecs_t when, uint32_t policyFlags);
void dispatchVirtualKey(nsecs_t when, uint32_t policyFlags,
@@ -1312,9 +1466,24 @@ private:
void dispatchHoverEnterAndMove(nsecs_t when, uint32_t policyFlags);
void cookPointerData();
void dispatchPointerUsage(nsecs_t when, uint32_t policyFlags, PointerUsage pointerUsage);
void abortPointerUsage(nsecs_t when, uint32_t policyFlags);
void dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, bool isTimeout);
void abortPointerGestures(nsecs_t when, uint32_t policyFlags);
bool preparePointerGestures(nsecs_t when,
bool* outCancelPreviousGesture, bool* outFinishPreviousGesture, bool isTimeout);
bool* outCancelPreviousGesture, bool* outFinishPreviousGesture,
bool isTimeout);
void dispatchPointerStylus(nsecs_t when, uint32_t policyFlags);
void abortPointerStylus(nsecs_t when, uint32_t policyFlags);
void dispatchPointerMouse(nsecs_t when, uint32_t policyFlags);
void abortPointerMouse(nsecs_t when, uint32_t policyFlags);
void dispatchPointerSimple(nsecs_t when, uint32_t policyFlags,
bool down, bool hovering);
void abortPointerSimple(nsecs_t when, uint32_t policyFlags);
// Dispatches a motion event.
// If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the
@@ -1346,20 +1515,15 @@ public:
SingleTouchInputMapper(InputDevice* device);
virtual ~SingleTouchInputMapper();
virtual void reset();
virtual void reset(nsecs_t when);
virtual void process(const RawEvent* rawEvent);
protected:
virtual void syncTouch(nsecs_t when, bool* outHavePointerIds);
virtual void configureRawPointerAxes();
private:
CursorButtonAccumulator mCursorButtonAccumulator;
TouchButtonAccumulator mTouchButtonAccumulator;
SingleTouchMotionAccumulator mSingleTouchMotionAccumulator;
void clearState();
void sync(nsecs_t when);
};
@@ -1368,24 +1532,19 @@ public:
MultiTouchInputMapper(InputDevice* device);
virtual ~MultiTouchInputMapper();
virtual void reset();
virtual void reset(nsecs_t when);
virtual void process(const RawEvent* rawEvent);
protected:
virtual void syncTouch(nsecs_t when, bool* outHavePointerIds);
virtual void configureRawPointerAxes();
private:
CursorButtonAccumulator mCursorButtonAccumulator;
TouchButtonAccumulator mTouchButtonAccumulator;
MultiTouchMotionAccumulator mMultiTouchMotionAccumulator;
// Specifies the pointer id bits that are in use, and their associated tracking id.
BitSet32 mPointerIdBits;
int32_t mPointerTrackingIdMap[MAX_POINTER_ID + 1];
void clearState();
void sync(nsecs_t when);
};
@@ -1397,8 +1556,8 @@ public:
virtual uint32_t getSources();
virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
virtual void dump(String8& dump);
virtual void configure(const InputReaderConfiguration* config, uint32_t changes);
virtual void reset();
virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
virtual void reset(nsecs_t when);
virtual void process(const RawEvent* rawEvent);
private:

View File

@@ -125,13 +125,6 @@ private:
// --- FakeInputReaderPolicy ---
class FakeInputReaderPolicy : public InputReaderPolicyInterface {
struct DisplayInfo {
int32_t width;
int32_t height;
int32_t orientation;
};
KeyedVector<int32_t, DisplayInfo> mDisplayInfos;
InputReaderConfiguration mConfig;
KeyedVector<int32_t, sp<FakePointerController> > mPointerControllers;
@@ -142,18 +135,10 @@ public:
FakeInputReaderPolicy() {
}
void removeDisplayInfo(int32_t displayId) {
mDisplayInfos.removeItem(displayId);
}
void setDisplayInfo(int32_t displayId, int32_t width, int32_t height, int32_t orientation) {
removeDisplayInfo(displayId);
DisplayInfo info;
info.width = width;
info.height = height;
info.orientation = orientation;
mDisplayInfos.add(displayId, info);
// Set the size of both the internal and external display at the same time.
mConfig.setDisplayInfo(displayId, false /*external*/, width, height, orientation);
mConfig.setDisplayInfo(displayId, true /*external*/, width, height, orientation);
}
virtual nsecs_t getVirtualKeyQuietTime() {
@@ -168,26 +153,11 @@ public:
mPointerControllers.add(deviceId, controller);
}
private:
virtual bool getDisplayInfo(int32_t displayId, bool external /*currently ignored*/,
int32_t* width, int32_t* height, int32_t* orientation) {
ssize_t index = mDisplayInfos.indexOfKey(displayId);
if (index >= 0) {
const DisplayInfo& info = mDisplayInfos.valueAt(index);
if (width) {
*width = info.width;
}
if (height) {
*height = info.height;
}
if (orientation) {
*orientation = info.orientation;
}
return true;
}
return false;
const InputReaderConfiguration* getReaderConfiguration() const {
return &mConfig;
}
private:
virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) {
*outConfig = mConfig;
}
@@ -203,6 +173,7 @@ private:
class FakeInputListener : public InputListenerInterface {
private:
List<NotifyConfigurationChangedArgs> mNotifyConfigurationChangedArgsQueue;
List<NotifyDeviceResetArgs> mNotifyDeviceResetArgsQueue;
List<NotifyKeyArgs> mNotifyKeyArgsQueue;
List<NotifyMotionArgs> mNotifyMotionArgsQueue;
List<NotifySwitchArgs> mNotifySwitchArgsQueue;
@@ -224,6 +195,16 @@ public:
mNotifyConfigurationChangedArgsQueue.erase(mNotifyConfigurationChangedArgsQueue.begin());
}
void assertNotifyDeviceResetWasCalled(
NotifyDeviceResetArgs* outEventArgs = NULL) {
ASSERT_FALSE(mNotifyDeviceResetArgsQueue.empty())
<< "Expected notifyDeviceReset() to have been called.";
if (outEventArgs) {
*outEventArgs = *mNotifyDeviceResetArgsQueue.begin();
}
mNotifyDeviceResetArgsQueue.erase(mNotifyDeviceResetArgsQueue.begin());
}
void assertNotifyKeyWasCalled(NotifyKeyArgs* outEventArgs = NULL) {
ASSERT_FALSE(mNotifyKeyArgsQueue.empty())
<< "Expected notifyKey() to have been called.";
@@ -266,6 +247,10 @@ private:
mNotifyConfigurationChangedArgsQueue.push_back(*args);
}
virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) {
mNotifyDeviceResetArgsQueue.push_back(*args);
}
virtual void notifyKey(const NotifyKeyArgs* args) {
mNotifyKeyArgsQueue.push_back(*args);
}
@@ -792,11 +777,12 @@ private:
}
}
virtual void configure(const InputReaderConfiguration* config, uint32_t changes) {
virtual void configure(nsecs_t when,
const InputReaderConfiguration* config, uint32_t changes) {
mConfigureWasCalled = true;
}
virtual void reset() {
virtual void reset(nsecs_t when) {
mResetWasCalled = true;
}
@@ -913,6 +899,7 @@ protected:
void addDevice(int32_t deviceId, const String8& name, uint32_t classes,
const PropertyMap* configuration) {
mFakeEventHub->addDevice(deviceId, name, classes);
if (configuration) {
mFakeEventHub->addConfigurationMap(deviceId, configuration);
}
@@ -1263,7 +1250,15 @@ TEST_F(InputDeviceTest, ImmutableProperties) {
TEST_F(InputDeviceTest, WhenNoMappersAreRegistered_DeviceIsIgnored) {
// Configuration.
InputReaderConfiguration config;
mDevice->configure(&config, 0);
mDevice->configure(ARBITRARY_TIME, &config, 0);
// Reset.
mDevice->reset(ARBITRARY_TIME);
NotifyDeviceResetArgs resetArgs;
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled(&resetArgs));
ASSERT_EQ(ARBITRARY_TIME, resetArgs.eventTime);
ASSERT_EQ(DEVICE_ID, resetArgs.deviceId);
// Metadata.
ASSERT_TRUE(mDevice->isIgnored());
@@ -1292,9 +1287,6 @@ TEST_F(InputDeviceTest, WhenNoMappersAreRegistered_DeviceIsIgnored) {
<< "Ignored device should never mark any key codes.";
ASSERT_EQ(0, flags[0]) << "Flag for unsupported key should be unchanged.";
ASSERT_EQ(1, flags[1]) << "Flag for unsupported key should be unchanged.";
// Reset.
mDevice->reset();
}
TEST_F(InputDeviceTest, WhenMappersAreRegistered_DeviceIsNotIgnoredAndForwardsRequestsToMappers) {
@@ -1318,7 +1310,7 @@ TEST_F(InputDeviceTest, WhenMappersAreRegistered_DeviceIsNotIgnoredAndForwardsRe
mDevice->addMapper(mapper2);
InputReaderConfiguration config;
mDevice->configure(&config, 0);
mDevice->configure(ARBITRARY_TIME, &config, 0);
String8 propertyValue;
ASSERT_TRUE(mDevice->getConfiguration().tryGetProperty(String8("key"), propertyValue))
@@ -1328,6 +1320,16 @@ TEST_F(InputDeviceTest, WhenMappersAreRegistered_DeviceIsNotIgnoredAndForwardsRe
ASSERT_NO_FATAL_FAILURE(mapper1->assertConfigureWasCalled());
ASSERT_NO_FATAL_FAILURE(mapper2->assertConfigureWasCalled());
// Reset
mDevice->reset(ARBITRARY_TIME);
ASSERT_NO_FATAL_FAILURE(mapper1->assertResetWasCalled());
ASSERT_NO_FATAL_FAILURE(mapper2->assertResetWasCalled());
NotifyDeviceResetArgs resetArgs;
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled(&resetArgs));
ASSERT_EQ(ARBITRARY_TIME, resetArgs.eventTime);
ASSERT_EQ(DEVICE_ID, resetArgs.deviceId);
// Metadata.
ASSERT_FALSE(mDevice->isIgnored());
ASSERT_EQ(uint32_t(AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TOUCHSCREEN), mDevice->getSources());
@@ -1379,12 +1381,6 @@ TEST_F(InputDeviceTest, WhenMappersAreRegistered_DeviceIsNotIgnoredAndForwardsRe
ASSERT_NO_FATAL_FAILURE(mapper1->assertProcessWasCalled());
ASSERT_NO_FATAL_FAILURE(mapper2->assertProcessWasCalled());
// Reset.
mDevice->reset();
ASSERT_NO_FATAL_FAILURE(mapper1->assertResetWasCalled());
ASSERT_NO_FATAL_FAILURE(mapper2->assertResetWasCalled());
}
@@ -1424,10 +1420,16 @@ protected:
}
void addMapperAndConfigure(InputMapper* mapper) {
InputReaderConfiguration config;
mDevice->addMapper(mapper);
mDevice->configure(&config, 0);
mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), 0);
mDevice->reset(ARBITRARY_TIME);
}
void setDisplayInfoAndReconfigure(int32_t displayId, int32_t width, int32_t height,
int32_t orientation) {
mFakePolicy->setDisplayInfo(displayId, width, height, orientation);
mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
InputReaderConfiguration::CHANGE_DISPLAY_INFO);
}
static void process(InputMapper* mapper, nsecs_t when, int32_t deviceId, int32_t type,
@@ -1593,71 +1595,6 @@ TEST_F(KeyboardInputMapperTest, Process_SimpleKeyPress) {
ASSERT_EQ(ARBITRARY_TIME, args.downTime);
}
TEST_F(KeyboardInputMapperTest, Reset_WhenKeysAreNotDown_DoesNotSynthesizeKeyUp) {
KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
addMapperAndConfigure(mapper);
// Key down.
process(mapper, ARBITRARY_TIME, DEVICE_ID,
EV_KEY, KEY_HOME, AKEYCODE_HOME, 1, POLICY_FLAG_WAKE);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled());
// Key up.
process(mapper, ARBITRARY_TIME, DEVICE_ID,
EV_KEY, KEY_HOME, AKEYCODE_HOME, 0, POLICY_FLAG_WAKE);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled());
// Reset. Since no keys still down, should not synthesize any key ups.
mapper->reset();
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled());
}
TEST_F(KeyboardInputMapperTest, Reset_WhenKeysAreDown_SynthesizesKeyUps) {
KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
addMapperAndConfigure(mapper);
// Metakey down.
process(mapper, ARBITRARY_TIME, DEVICE_ID,
EV_KEY, KEY_LEFTSHIFT, AKEYCODE_SHIFT_LEFT, 1, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled());
// Key down.
process(mapper, ARBITRARY_TIME + 1, DEVICE_ID,
EV_KEY, KEY_A, AKEYCODE_A, 1, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled());
// Reset. Since two keys are still down, should synthesize two key ups in reverse order.
mapper->reset();
NotifyKeyArgs args;
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(DEVICE_ID, args.deviceId);
ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action);
ASSERT_EQ(AKEYCODE_A, args.keyCode);
ASSERT_EQ(KEY_A, args.scanCode);
ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState);
ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags);
ASSERT_EQ(uint32_t(0), args.policyFlags);
ASSERT_EQ(ARBITRARY_TIME + 1, args.downTime);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
ASSERT_EQ(DEVICE_ID, args.deviceId);
ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action);
ASSERT_EQ(AKEYCODE_SHIFT_LEFT, args.keyCode);
ASSERT_EQ(KEY_LEFTSHIFT, args.scanCode);
ASSERT_EQ(AMETA_NONE, args.metaState);
ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags);
ASSERT_EQ(uint32_t(0), args.policyFlags);
ASSERT_EQ(ARBITRARY_TIME + 1, args.downTime);
// And that's it.
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled());
}
TEST_F(KeyboardInputMapperTest, Process_ShouldUpdateMetaState) {
KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
@@ -1703,7 +1640,7 @@ TEST_F(KeyboardInputMapperTest, Process_WhenNotOrientationAware_ShouldNotRotateD
AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
addMapperAndConfigure(mapper);
mFakePolicy->setDisplayInfo(DISPLAY_ID,
setDisplayInfoAndReconfigure(DISPLAY_ID,
DISPLAY_WIDTH, DISPLAY_HEIGHT,
DISPLAY_ORIENTATION_90);
ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
@@ -1722,7 +1659,7 @@ TEST_F(KeyboardInputMapperTest, Process_WhenOrientationAware_ShouldRotateDPad) {
addConfigurationProperty("keyboard.orientationAware", "1");
addMapperAndConfigure(mapper);
mFakePolicy->setDisplayInfo(DISPLAY_ID,
setDisplayInfoAndReconfigure(DISPLAY_ID,
DISPLAY_WIDTH, DISPLAY_HEIGHT,
DISPLAY_ORIENTATION_0);
ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
@@ -1734,7 +1671,7 @@ TEST_F(KeyboardInputMapperTest, Process_WhenOrientationAware_ShouldRotateDPad) {
ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_LEFT));
mFakePolicy->setDisplayInfo(DISPLAY_ID,
setDisplayInfoAndReconfigure(DISPLAY_ID,
DISPLAY_WIDTH, DISPLAY_HEIGHT,
DISPLAY_ORIENTATION_90);
ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
@@ -1746,7 +1683,7 @@ TEST_F(KeyboardInputMapperTest, Process_WhenOrientationAware_ShouldRotateDPad) {
ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN));
mFakePolicy->setDisplayInfo(DISPLAY_ID,
setDisplayInfoAndReconfigure(DISPLAY_ID,
DISPLAY_WIDTH, DISPLAY_HEIGHT,
DISPLAY_ORIENTATION_180);
ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
@@ -1758,7 +1695,7 @@ TEST_F(KeyboardInputMapperTest, Process_WhenOrientationAware_ShouldRotateDPad) {
ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_RIGHT));
mFakePolicy->setDisplayInfo(DISPLAY_ID,
setDisplayInfoAndReconfigure(DISPLAY_ID,
DISPLAY_WIDTH, DISPLAY_HEIGHT,
DISPLAY_ORIENTATION_270);
ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
@@ -1774,7 +1711,7 @@ TEST_F(KeyboardInputMapperTest, Process_WhenOrientationAware_ShouldRotateDPad) {
// in the key up as we did in the key down.
NotifyKeyArgs args;
mFakePolicy->setDisplayInfo(DISPLAY_ID,
setDisplayInfoAndReconfigure(DISPLAY_ID,
DISPLAY_WIDTH, DISPLAY_HEIGHT,
DISPLAY_ORIENTATION_270);
process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, KEY_UP, AKEYCODE_DPAD_UP, 1, 0);
@@ -1783,7 +1720,7 @@ TEST_F(KeyboardInputMapperTest, Process_WhenOrientationAware_ShouldRotateDPad) {
ASSERT_EQ(KEY_UP, args.scanCode);
ASSERT_EQ(AKEYCODE_DPAD_RIGHT, args.keyCode);
mFakePolicy->setDisplayInfo(DISPLAY_ID,
setDisplayInfoAndReconfigure(DISPLAY_ID,
DISPLAY_WIDTH, DISPLAY_HEIGHT,
DISPLAY_ORIENTATION_180);
process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, KEY_UP, AKEYCODE_DPAD_UP, 0, 0);
@@ -2149,58 +2086,12 @@ TEST_F(CursorInputMapperTest, Process_ShouldHandleCombinedXYAndButtonUpdates) {
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
}
TEST_F(CursorInputMapperTest, Reset_WhenButtonIsNotDown_ShouldNotSynthesizeButtonUp) {
CursorInputMapper* mapper = new CursorInputMapper(mDevice);
addConfigurationProperty("cursor.mode", "navigation");
addMapperAndConfigure(mapper);
NotifyMotionArgs args;
// Button press.
process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 0, 1, 0);
process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0, 0, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action);
// Button release.
process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 0, 0, 0);
process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0, 0, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action);
// Reset. Should not synthesize button up since button is not pressed.
mapper->reset();
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
}
TEST_F(CursorInputMapperTest, Reset_WhenButtonIsDown_ShouldSynthesizeButtonUp) {
CursorInputMapper* mapper = new CursorInputMapper(mDevice);
addConfigurationProperty("cursor.mode", "navigation");
addMapperAndConfigure(mapper);
NotifyMotionArgs args;
// Button press.
process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 0, 1, 0);
process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0, 0, 0);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
// Reset. Should synthesize button up.
mapper->reset();
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
}
TEST_F(CursorInputMapperTest, Process_WhenNotOrientationAware_ShouldNotRotateMotions) {
CursorInputMapper* mapper = new CursorInputMapper(mDevice);
addConfigurationProperty("cursor.mode", "navigation");
addMapperAndConfigure(mapper);
mFakePolicy->setDisplayInfo(DISPLAY_ID,
setDisplayInfoAndReconfigure(DISPLAY_ID,
DISPLAY_WIDTH, DISPLAY_HEIGHT,
DISPLAY_ORIENTATION_90);
ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, 1, 0, 1));
@@ -2219,7 +2110,7 @@ TEST_F(CursorInputMapperTest, Process_WhenOrientationAware_ShouldRotateMotions)
addConfigurationProperty("cursor.orientationAware", "1");
addMapperAndConfigure(mapper);
mFakePolicy->setDisplayInfo(DISPLAY_ID,
setDisplayInfoAndReconfigure(DISPLAY_ID,
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_0);
ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, 1, 0, 1));
ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 1, 1, 1));
@@ -2230,7 +2121,7 @@ TEST_F(CursorInputMapperTest, Process_WhenOrientationAware_ShouldRotateMotions)
ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 0, -1, 0));
ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 1, -1, 1));
mFakePolicy->setDisplayInfo(DISPLAY_ID,
setDisplayInfoAndReconfigure(DISPLAY_ID,
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_90);
ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, 1, 1, 0));
ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 1, 1, -1));
@@ -2241,7 +2132,7 @@ TEST_F(CursorInputMapperTest, Process_WhenOrientationAware_ShouldRotateMotions)
ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 0, 0, 1));
ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 1, 1, 1));
mFakePolicy->setDisplayInfo(DISPLAY_ID,
setDisplayInfoAndReconfigure(DISPLAY_ID,
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_180);
ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, 1, 0, -1));
ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 1, -1, -1));
@@ -2252,7 +2143,7 @@ TEST_F(CursorInputMapperTest, Process_WhenOrientationAware_ShouldRotateMotions)
ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 0, 1, 0));
ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 1, 1, -1));
mFakePolicy->setDisplayInfo(DISPLAY_ID,
setDisplayInfoAndReconfigure(DISPLAY_ID,
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_270);
ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, 1, -1, 0));
ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 1, -1, 1));
@@ -2480,6 +2371,8 @@ protected:
static const int32_t RAW_ORIENTATION_MAX;
static const int32_t RAW_DISTANCE_MIN;
static const int32_t RAW_DISTANCE_MAX;
static const int32_t RAW_TILT_MIN;
static const int32_t RAW_TILT_MAX;
static const int32_t RAW_ID_MIN;
static const int32_t RAW_ID_MAX;
static const int32_t RAW_SLOT_MIN;
@@ -2500,8 +2393,9 @@ protected:
MINOR = 1 << 5,
ID = 1 << 6,
DISTANCE = 1 << 7,
SLOT = 1 << 8,
TOOL_TYPE = 1 << 9,
TILT = 1 << 8,
SLOT = 1 << 9,
TOOL_TYPE = 1 << 10,
};
void prepareDisplay(int32_t orientation);
@@ -2526,6 +2420,8 @@ const int32_t TouchInputMapperTest::RAW_ORIENTATION_MIN = -7;
const int32_t TouchInputMapperTest::RAW_ORIENTATION_MAX = 7;
const int32_t TouchInputMapperTest::RAW_DISTANCE_MIN = 0;
const int32_t TouchInputMapperTest::RAW_DISTANCE_MAX = 7;
const int32_t TouchInputMapperTest::RAW_TILT_MIN = 0;
const int32_t TouchInputMapperTest::RAW_TILT_MAX = 150;
const int32_t TouchInputMapperTest::RAW_ID_MIN = 0;
const int32_t TouchInputMapperTest::RAW_ID_MAX = 9;
const int32_t TouchInputMapperTest::RAW_SLOT_MIN = 0;
@@ -2543,7 +2439,7 @@ const VirtualKeyDefinition TouchInputMapperTest::VIRTUAL_KEYS[2] = {
};
void TouchInputMapperTest::prepareDisplay(int32_t orientation) {
mFakePolicy->setDisplayInfo(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, orientation);
setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, orientation);
}
void TouchInputMapperTest::prepareVirtualKeys() {
@@ -2583,6 +2479,7 @@ protected:
void processPressure(SingleTouchInputMapper* mapper, int32_t pressure);
void processToolMajor(SingleTouchInputMapper* mapper, int32_t toolMajor);
void processDistance(SingleTouchInputMapper* mapper, int32_t distance);
void processTilt(SingleTouchInputMapper* mapper, int32_t tiltX, int32_t tiltY);
void processKey(SingleTouchInputMapper* mapper, int32_t code, int32_t value);
void processSync(SingleTouchInputMapper* mapper);
};
@@ -2610,6 +2507,12 @@ void SingleTouchInputMapperTest::prepareAxes(int axes) {
mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_DISTANCE,
RAW_DISTANCE_MIN, RAW_DISTANCE_MAX, 0, 0);
}
if (axes & TILT) {
mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_TILT_X,
RAW_TILT_MIN, RAW_TILT_MAX, 0, 0);
mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_TILT_Y,
RAW_TILT_MIN, RAW_TILT_MAX, 0, 0);
}
}
void SingleTouchInputMapperTest::processDown(SingleTouchInputMapper* mapper, int32_t x, int32_t y) {
@@ -2642,6 +2545,12 @@ void SingleTouchInputMapperTest::processDistance(
process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_DISTANCE, 0, distance, 0);
}
void SingleTouchInputMapperTest::processTilt(
SingleTouchInputMapper* mapper, int32_t tiltX, int32_t tiltY) {
process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_TILT_X, 0, tiltX, 0);
process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_TILT_Y, 0, tiltY, 0);
}
void SingleTouchInputMapperTest::processKey(
SingleTouchInputMapper* mapper, int32_t code, int32_t value) {
process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, code, 0, value, 0);
@@ -2658,7 +2567,7 @@ TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsNotSpecifiedAndNot
prepareAxes(POSITION);
addMapperAndConfigure(mapper);
ASSERT_EQ(AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD, mapper->getSources());
ASSERT_EQ(AINPUT_SOURCE_MOUSE, mapper->getSources());
}
TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsNotSpecifiedAndIsACursor_ReturnsTouchPad) {
@@ -2766,71 +2675,6 @@ TEST_F(SingleTouchInputMapperTest, MarkSupportedKeyCodes) {
ASSERT_FALSE(flags[1]);
}
TEST_F(SingleTouchInputMapperTest, Reset_WhenVirtualKeysAreDown_SendsUp) {
// Note: Ideally we should send cancels but the implementation is more straightforward
// with up and this will only happen if a device is forcibly removed.
SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
addConfigurationProperty("touch.deviceType", "touchScreen");
prepareDisplay(DISPLAY_ORIENTATION_0);
prepareButtons();
prepareAxes(POSITION);
prepareVirtualKeys();
addMapperAndConfigure(mapper);
mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
// Press virtual key.
int32_t x = toRawX(VIRTUAL_KEYS[0].centerX);
int32_t y = toRawY(VIRTUAL_KEYS[0].centerY);
processDown(mapper, x, y);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled());
// Reset. Since key is down, synthesize key up.
mapper->reset();
NotifyKeyArgs args;
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
//ASSERT_EQ(ARBITRARY_TIME, args.eventTime);
ASSERT_EQ(DEVICE_ID, args.deviceId);
ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
ASSERT_EQ(POLICY_FLAG_VIRTUAL, args.policyFlags);
ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action);
ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY, args.flags);
ASSERT_EQ(AKEYCODE_HOME, args.keyCode);
ASSERT_EQ(KEY_HOME, args.scanCode);
ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState);
ASSERT_EQ(ARBITRARY_TIME, args.downTime);
}
TEST_F(SingleTouchInputMapperTest, Reset_WhenNothingIsPressed_NothingMuchHappens) {
SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
addConfigurationProperty("touch.deviceType", "touchScreen");
prepareDisplay(DISPLAY_ORIENTATION_0);
prepareButtons();
prepareAxes(POSITION);
prepareVirtualKeys();
addMapperAndConfigure(mapper);
// Press virtual key.
int32_t x = toRawX(VIRTUAL_KEYS[0].centerX);
int32_t y = toRawY(VIRTUAL_KEYS[0].centerY);
processDown(mapper, x, y);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled());
// Release virtual key.
processUp(mapper);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled());
// Reset. Since no key is down, nothing happens.
mapper->reset();
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled());
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
}
TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndReleasedNormally_SendsKeyDownAndKeyUp) {
SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
addConfigurationProperty("touch.deviceType", "touchScreen");
@@ -3260,7 +3104,7 @@ TEST_F(SingleTouchInputMapperTest, Process_AllAxes_DefaultCalibration) {
addConfigurationProperty("touch.deviceType", "touchScreen");
prepareDisplay(DISPLAY_ORIENTATION_0);
prepareButtons();
prepareAxes(POSITION | PRESSURE | TOOL | DISTANCE);
prepareAxes(POSITION | PRESSURE | TOOL | DISTANCE | TILT);
addMapperAndConfigure(mapper);
// These calculations are based on the input device calibration documentation.
@@ -3268,7 +3112,9 @@ TEST_F(SingleTouchInputMapperTest, Process_AllAxes_DefaultCalibration) {
int32_t rawY = 200;
int32_t rawPressure = 10;
int32_t rawToolMajor = 12;
int32_t rawDistance = 0;
int32_t rawDistance = 2;
int32_t rawTiltX = 30;
int32_t rawTiltY = 110;
float x = toDisplayX(rawX);
float y = toDisplayY(rawY);
@@ -3277,16 +3123,25 @@ TEST_F(SingleTouchInputMapperTest, Process_AllAxes_DefaultCalibration) {
float tool = float(rawToolMajor) * GEOMETRIC_SCALE;
float distance = float(rawDistance);
float tiltCenter = (RAW_TILT_MAX + RAW_TILT_MIN) * 0.5f;
float tiltScale = M_PI / 180;
float tiltXAngle = (rawTiltX - tiltCenter) * tiltScale;
float tiltYAngle = (rawTiltY - tiltCenter) * tiltScale;
float orientation = atan2f(-sinf(tiltXAngle), sinf(tiltYAngle));
float tilt = acosf(cosf(tiltXAngle) * cosf(tiltYAngle));
processDown(mapper, rawX, rawY);
processPressure(mapper, rawPressure);
processToolMajor(mapper, rawToolMajor);
processDistance(mapper, rawDistance);
processTilt(mapper, rawTiltX, rawTiltY);
processSync(mapper);
NotifyMotionArgs args;
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
x, y, pressure, size, tool, tool, tool, tool, 0, distance));
x, y, pressure, size, tool, tool, tool, tool, orientation, distance));
ASSERT_EQ(tilt, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_TILT));
}
TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllButtons) {
@@ -3482,8 +3337,48 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) {
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
// finger
// brush
processKey(mapper, BTN_TOOL_PEN, 0);
processKey(mapper, BTN_TOOL_BRUSH, 1);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
// pencil
processKey(mapper, BTN_TOOL_BRUSH, 0);
processKey(mapper, BTN_TOOL_PENCIL, 1);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
// airbrush
processKey(mapper, BTN_TOOL_PENCIL, 0);
processKey(mapper, BTN_TOOL_AIRBRUSH, 1);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
// mouse
processKey(mapper, BTN_TOOL_AIRBRUSH, 0);
processKey(mapper, BTN_TOOL_MOUSE, 1);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType);
// lens
processKey(mapper, BTN_TOOL_MOUSE, 0);
processKey(mapper, BTN_TOOL_LENS, 1);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType);
// finger
processKey(mapper, BTN_TOOL_LENS, 0);
processKey(mapper, BTN_TOOL_FINGER, 1);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
@@ -3504,7 +3399,15 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) {
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType);
// mouse trumps eraser
processKey(mapper, BTN_TOOL_MOUSE, 1);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType);
// back to default tool type
processKey(mapper, BTN_TOOL_MOUSE, 0);
processKey(mapper, BTN_TOOL_RUBBER, 0);
processKey(mapper, BTN_TOOL_PEN, 0);
processKey(mapper, BTN_TOOL_FINGER, 0);
@@ -3587,29 +3490,29 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenBtnTouchPresent_HoversIfItsValueI
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
}
TEST_F(SingleTouchInputMapperTest, Process_WhenAbsDistanceIsPresent_HoversIfItsValueIsGreaterThanZero) {
TEST_F(SingleTouchInputMapperTest, Process_WhenAbsPressureIsPresent_HoversIfItsValueIsZero) {
SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
addConfigurationProperty("touch.deviceType", "touchScreen");
prepareDisplay(DISPLAY_ORIENTATION_0);
prepareButtons();
prepareAxes(POSITION | DISTANCE);
prepareAxes(POSITION | PRESSURE);
addMapperAndConfigure(mapper);
NotifyMotionArgs motionArgs;
// initially hovering because distance is 1, pressure defaults to 0
// initially hovering because pressure is 0
processDown(mapper, 100, 200);
processDistance(mapper, 1);
processPressure(mapper, 0);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 1));
toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 1));
toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0));
// move a little
processMove(mapper, 150, 250);
@@ -3617,23 +3520,23 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenAbsDistanceIsPresent_HoversIfItsV
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 1));
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
// down when distance goes to 0, pressure defaults to 1
processDistance(mapper, 0);
// down when pressure is non-zero
processPressure(mapper, RAW_PRESSURE_MAX);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 1));
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0));
// up when distance goes to 1, hover restored
processDistance(mapper, 1);
// up when pressure becomes 0, hover restored
processPressure(mapper, 0);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
@@ -3643,12 +3546,12 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenAbsDistanceIsPresent_HoversIfItsV
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 1));
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 1));
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
// exit hover when pointer goes away
processUp(mapper);
@@ -3656,7 +3559,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenAbsDistanceIsPresent_HoversIfItsV
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 1));
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
}
@@ -4823,8 +4726,48 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) {
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
// finger
// brush
processKey(mapper, BTN_TOOL_PEN, 0);
processKey(mapper, BTN_TOOL_BRUSH, 1);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
// pencil
processKey(mapper, BTN_TOOL_BRUSH, 0);
processKey(mapper, BTN_TOOL_PENCIL, 1);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
// airbrush
processKey(mapper, BTN_TOOL_PENCIL, 0);
processKey(mapper, BTN_TOOL_AIRBRUSH, 1);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
// mouse
processKey(mapper, BTN_TOOL_AIRBRUSH, 0);
processKey(mapper, BTN_TOOL_MOUSE, 1);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType);
// lens
processKey(mapper, BTN_TOOL_MOUSE, 0);
processKey(mapper, BTN_TOOL_LENS, 1);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType);
// finger
processKey(mapper, BTN_TOOL_LENS, 0);
processKey(mapper, BTN_TOOL_FINGER, 1);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
@@ -4845,6 +4788,13 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) {
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType);
// mouse trumps eraser
processKey(mapper, BTN_TOOL_MOUSE, 1);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType);
// MT tool type trumps BTN tool types: MT_TOOL_FINGER
processToolType(mapper, MT_TOOL_FINGER); // this is the first time we send MT_TOOL_TYPE
processSync(mapper);
@@ -4861,6 +4811,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) {
// back to default tool type
processToolType(mapper, -1); // use a deliberately undefined tool type, for testing
processKey(mapper, BTN_TOOL_MOUSE, 0);
processKey(mapper, BTN_TOOL_RUBBER, 0);
processKey(mapper, BTN_TOOL_PEN, 0);
processKey(mapper, BTN_TOOL_FINGER, 0);
@@ -4942,29 +4893,29 @@ TEST_F(MultiTouchInputMapperTest, Process_WhenBtnTouchPresent_HoversIfItsValueIs
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
}
TEST_F(MultiTouchInputMapperTest, Process_WhenAbsMTDistanceIsPresent_HoversIfItsValueIsGreaterThanZero) {
TEST_F(MultiTouchInputMapperTest, Process_WhenAbsMTPressureIsPresent_HoversIfItsValueIsZero) {
MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
addConfigurationProperty("touch.deviceType", "touchScreen");
prepareDisplay(DISPLAY_ORIENTATION_0);
prepareAxes(POSITION | ID | SLOT | DISTANCE);
prepareAxes(POSITION | ID | SLOT | PRESSURE);
addMapperAndConfigure(mapper);
NotifyMotionArgs motionArgs;
// initially hovering because distance is 1, pressure defaults to 0
// initially hovering because pressure is 0
processId(mapper, 1);
processPosition(mapper, 100, 200);
processDistance(mapper, 1);
processPressure(mapper, 0);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 1));
toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 1));
toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0));
// move a little
processPosition(mapper, 150, 250);
@@ -4972,23 +4923,23 @@ TEST_F(MultiTouchInputMapperTest, Process_WhenAbsMTDistanceIsPresent_HoversIfIts
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 1));
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
// down when distance goes to 0, pressure defaults to 1
processDistance(mapper, 0);
// down when pressure becomes non-zero
processPressure(mapper, RAW_PRESSURE_MAX);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 1));
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0));
// up when distance goes to 1, hover restored
processDistance(mapper, 1);
// up when pressure becomes 0, hover restored
processPressure(mapper, 0);
processSync(mapper);
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
@@ -4998,12 +4949,12 @@ TEST_F(MultiTouchInputMapperTest, Process_WhenAbsMTDistanceIsPresent_HoversIfIts
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 1));
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 1));
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
// exit hover when pointer goes away
processId(mapper, -1);
@@ -5011,7 +4962,7 @@ TEST_F(MultiTouchInputMapperTest, Process_WhenAbsMTDistanceIsPresent_HoversIfIts
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action);
ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 1));
toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
}

View File

@@ -182,8 +182,6 @@ public:
/* --- InputReaderPolicyInterface implementation --- */
virtual bool getDisplayInfo(int32_t displayId, bool external,
int32_t* width, int32_t* height, int32_t* orientation);
virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
@@ -273,7 +271,7 @@ NativeInputManager::NativeInputManager(jobject contextObj,
mLocked.displayHeight = -1;
mLocked.displayExternalWidth = -1;
mLocked.displayExternalHeight = -1;
mLocked.displayOrientation = ROTATION_0;
mLocked.displayOrientation = DISPLAY_ORIENTATION_0;
mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
mLocked.pointerSpeed = 0;
@@ -311,31 +309,42 @@ bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const c
void NativeInputManager::setDisplaySize(int32_t displayId, int32_t width, int32_t height,
int32_t externalWidth, int32_t externalHeight) {
bool changed = false;
if (displayId == 0) {
{ // acquire lock
AutoMutex _l(mLock);
AutoMutex _l(mLock);
if (mLocked.displayWidth != width || mLocked.displayHeight != height) {
mLocked.displayWidth = width;
mLocked.displayHeight = height;
if (mLocked.displayWidth != width || mLocked.displayHeight != height) {
changed = true;
mLocked.displayWidth = width;
mLocked.displayHeight = height;
sp<PointerController> controller = mLocked.pointerController.promote();
if (controller != NULL) {
controller->setDisplaySize(width, height);
}
sp<PointerController> controller = mLocked.pointerController.promote();
if (controller != NULL) {
controller->setDisplaySize(width, height);
}
}
if (mLocked.displayExternalWidth != externalWidth
|| mLocked.displayExternalHeight != externalHeight) {
changed = true;
mLocked.displayExternalWidth = externalWidth;
mLocked.displayExternalHeight = externalHeight;
} // release lock
}
}
if (changed) {
mInputManager->getReader()->requestRefreshConfiguration(
InputReaderConfiguration::CHANGE_DISPLAY_INFO);
}
}
void NativeInputManager::setDisplayOrientation(int32_t displayId, int32_t orientation) {
bool changed = false;
if (displayId == 0) {
AutoMutex _l(mLock);
if (mLocked.displayOrientation != orientation) {
changed = true;
mLocked.displayOrientation = orientation;
sp<PointerController> controller = mLocked.pointerController.promote();
@@ -344,6 +353,11 @@ void NativeInputManager::setDisplayOrientation(int32_t displayId, int32_t orient
}
}
}
if (changed) {
mInputManager->getReader()->requestRefreshConfiguration(
InputReaderConfiguration::CHANGE_DISPLAY_INFO);
}
}
status_t NativeInputManager::registerInputChannel(JNIEnv* env,
@@ -358,28 +372,6 @@ status_t NativeInputManager::unregisterInputChannel(JNIEnv* env,
return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel);
}
bool NativeInputManager::getDisplayInfo(int32_t displayId, bool external,
int32_t* width, int32_t* height, int32_t* orientation) {
bool result = false;
if (displayId == 0) {
AutoMutex _l(mLock);
if (mLocked.displayWidth > 0 && mLocked.displayHeight > 0) {
if (width) {
*width = external ? mLocked.displayExternalWidth : mLocked.displayWidth;
}
if (height) {
*height = external ? mLocked.displayExternalHeight : mLocked.displayHeight;
}
if (orientation) {
*orientation = mLocked.displayOrientation;
}
result = true;
}
}
return result;
}
void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outConfig) {
JNIEnv* env = jniEnv();
@@ -438,6 +430,12 @@ void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outCon
outConfig->pointerVelocityControlParameters.scale = exp2f(mLocked.pointerSpeed
* POINTER_SPEED_EXPONENT);
outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;
outConfig->setDisplayInfo(0, false /*external*/,
mLocked.displayWidth, mLocked.displayHeight, mLocked.displayOrientation);
outConfig->setDisplayInfo(0, true /*external*/,
mLocked.displayExternalWidth, mLocked.displayExternalHeight,
mLocked.displayOrientation);
} // release lock
}