1199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong/*
2199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * Copyright (C) 2010 The Android Open Source Project
3199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong *
4199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * Licensed under the Apache License, Version 2.0 (the "License");
5199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * you may not use this file except in compliance with the License.
6199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * You may obtain a copy of the License at
7199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong *
8199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong *      http://www.apache.org/licenses/LICENSE-2.0
9199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong *
10199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * Unless required by applicable law or agreed to in writing, software
11199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * distributed under the License is distributed on an "AS IS" BASIS,
12199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * See the License for the specific language governing permissions and
14199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong * limitations under the License.
15199d1c131d29b5356f71fbd7826a592c1dd8575fJames Dong */
16c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
17b4ff35df5c04aec71fce7e90a6d6f9ef7180c2adJeff Brown#include "../InputReader.h"
18b4ff35df5c04aec71fce7e90a6d6f9ef7180c2adJeff Brown
19c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown#include <utils/List.h>
20c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown#include <gtest/gtest.h>
21c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown#include <math.h>
22c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
23c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownnamespace android {
24c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
25c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown// An arbitrary time value.
26c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownstatic const nsecs_t ARBITRARY_TIME = 1234;
27c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
28c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown// Arbitrary display properties.
29c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownstatic const int32_t DISPLAY_ID = 0;
30c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownstatic const int32_t DISPLAY_WIDTH = 480;
31c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownstatic const int32_t DISPLAY_HEIGHT = 800;
32c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
33c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown// Error tolerance for floating point assertions.
34c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownstatic const float EPSILON = 0.001f;
35c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
36c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Browntemplate<typename T>
37c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownstatic inline T min(T a, T b) {
38c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    return a < b ? a : b;
39c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown}
40c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
41c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownstatic inline float avg(float x, float y) {
42c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    return (x + y) / 2;
43c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown}
44c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
45c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
4683c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown// --- FakePointerController ---
4783c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown
4883c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brownclass FakePointerController : public PointerControllerInterface {
4983c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown    bool mHaveBounds;
5083c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown    float mMinX, mMinY, mMaxX, mMaxY;
51be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    float mX, mY;
52be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    int32_t mButtonState;
5383c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown
5483c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brownprotected:
5583c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown    virtual ~FakePointerController() { }
5683c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown
5783c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brownpublic:
58b4ff35df5c04aec71fce7e90a6d6f9ef7180c2adJeff Brown    FakePointerController() :
59be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        mHaveBounds(false), mMinX(0), mMinY(0), mMaxX(0), mMaxY(0), mX(0), mY(0),
60be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        mButtonState(0) {
6183c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown    }
6283c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown
6383c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown    void setBounds(float minX, float minY, float maxX, float maxY) {
6483c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown        mHaveBounds = true;
6583c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown        mMinX = minX;
6683c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown        mMinY = minY;
6783c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown        mMaxX = maxX;
6883c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown        mMaxY = maxY;
6983c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown    }
7083c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown
71be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    virtual void setPosition(float x, float y) {
72be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        mX = x;
73be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        mY = y;
7483c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown    }
7583c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown
76fe9f8ab03a63b1037f07dd85799fbea80ec6adaaJeff Brown    virtual void setButtonState(int32_t buttonState) {
77be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        mButtonState = buttonState;
7883c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown    }
7983c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown
80fe9f8ab03a63b1037f07dd85799fbea80ec6adaaJeff Brown    virtual int32_t getButtonState() const {
81be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        return mButtonState;
8283c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown    }
8383c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown
84be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    virtual void getPosition(float* outX, float* outY) const {
85be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        *outX = mX;
86be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        *outY = mY;
8783c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown    }
8883c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown
89be1aa8250cee7819c49741e819e81659d1d03823Jeff Brownprivate:
90be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    virtual bool getBounds(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const {
91be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        *outMinX = mMinX;
92be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        *outMinY = mMinY;
93be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        *outMaxX = mMaxX;
94be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        *outMaxY = mMaxY;
95be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        return mHaveBounds;
96be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    }
97be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown
98be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    virtual void move(float deltaX, float deltaY) {
99be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        mX += deltaX;
100be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        if (mX < mMinX) mX = mMinX;
101be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        if (mX > mMaxX) mX = mMaxX;
102be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        mY += deltaY;
103be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        if (mY < mMinY) mY = mMinY;
104be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        if (mY > mMaxY) mY = mMaxY;
10583c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown    }
10605dc66ada6b61a6bdf806ffaa62617ac5394695dJeff Brown
107538881e18323a0c983bd8809f8c3b1cdeeeab8a6Jeff Brown    virtual void fade(Transition transition) {
10805dc66ada6b61a6bdf806ffaa62617ac5394695dJeff Brown    }
10905dc66ada6b61a6bdf806ffaa62617ac5394695dJeff Brown
110538881e18323a0c983bd8809f8c3b1cdeeeab8a6Jeff Brown    virtual void unfade(Transition transition) {
11105dc66ada6b61a6bdf806ffaa62617ac5394695dJeff Brown    }
1122352b978a3c94cd88f41d0d908f961333fdac1e9Jeff Brown
1132352b978a3c94cd88f41d0d908f961333fdac1e9Jeff Brown    virtual void setPresentation(Presentation presentation) {
1142352b978a3c94cd88f41d0d908f961333fdac1e9Jeff Brown    }
1152352b978a3c94cd88f41d0d908f961333fdac1e9Jeff Brown
1169181a5f40cf5ac7d413d5bc3bd6c15cc6d13705fJeff Brown    virtual void setSpots(const PointerCoords* spotCoords,
1179181a5f40cf5ac7d413d5bc3bd6c15cc6d13705fJeff Brown            const uint32_t* spotIdToIndex, BitSet32 spotIdBits) {
1182352b978a3c94cd88f41d0d908f961333fdac1e9Jeff Brown    }
1192352b978a3c94cd88f41d0d908f961333fdac1e9Jeff Brown
1202352b978a3c94cd88f41d0d908f961333fdac1e9Jeff Brown    virtual void clearSpots() {
1212352b978a3c94cd88f41d0d908f961333fdac1e9Jeff Brown    }
12283c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown};
12383c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown
12483c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown
125c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown// --- FakeInputReaderPolicy ---
126c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
127c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownclass FakeInputReaderPolicy : public InputReaderPolicyInterface {
128214eaf48878bba00cbd5831871bcbd82632b6e34Jeff Brown    InputReaderConfiguration mConfig;
12983c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown    KeyedVector<int32_t, sp<FakePointerController> > mPointerControllers;
130af9e8d38184c6ba4d2d3eb5bde7014a66dd8a78bJeff Brown    Vector<InputDeviceInfo> mInputDevices;
131c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
132c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownprotected:
133c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    virtual ~FakeInputReaderPolicy() { }
134c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
135c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownpublic:
136214eaf48878bba00cbd5831871bcbd82632b6e34Jeff Brown    FakeInputReaderPolicy() {
137c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
138c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
139c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    void setDisplayInfo(int32_t displayId, int32_t width, int32_t height, int32_t orientation) {
14065fd251c3913fc921468a3dad190810db19eb9dfJeff Brown        // Set the size of both the internal and external display at the same time.
141d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown        bool isRotated = (orientation == DISPLAY_ORIENTATION_90
142d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown                || orientation == DISPLAY_ORIENTATION_270);
143d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown        DisplayViewport v;
144d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown        v.displayId = displayId;
145d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown        v.orientation = orientation;
146d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown        v.logicalLeft = 0;
147d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown        v.logicalTop = 0;
148d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown        v.logicalRight = isRotated ? height : width;
149d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown        v.logicalBottom = isRotated ? width : height;
150d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown        v.physicalLeft = 0;
151d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown        v.physicalTop = 0;
152d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown        v.physicalRight = isRotated ? height : width;
153d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown        v.physicalBottom = isRotated ? width : height;
15483d616a9c7b9505153d258511eb5c16b552e268dJeff Brown        v.deviceWidth = isRotated ? height : width;
15583d616a9c7b9505153d258511eb5c16b552e268dJeff Brown        v.deviceHeight = isRotated ? width : height;
156d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown        mConfig.setDisplayInfo(false /*external*/, v);
157d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown        mConfig.setDisplayInfo(true /*external*/, v);
158c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
159c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
160c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    void addExcludedDeviceName(const String8& deviceName) {
161214eaf48878bba00cbd5831871bcbd82632b6e34Jeff Brown        mConfig.excludedDeviceNames.push(deviceName);
162c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
163c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
16483c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown    void setPointerController(int32_t deviceId, const sp<FakePointerController>& controller) {
16583c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown        mPointerControllers.add(deviceId, controller);
16683c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown    }
16783c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown
16865fd251c3913fc921468a3dad190810db19eb9dfJeff Brown    const InputReaderConfiguration* getReaderConfiguration() const {
16965fd251c3913fc921468a3dad190810db19eb9dfJeff Brown        return &mConfig;
170c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
171c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
172af9e8d38184c6ba4d2d3eb5bde7014a66dd8a78bJeff Brown    const Vector<InputDeviceInfo>& getInputDevices() const {
173af9e8d38184c6ba4d2d3eb5bde7014a66dd8a78bJeff Brown        return mInputDevices;
174af9e8d38184c6ba4d2d3eb5bde7014a66dd8a78bJeff Brown    }
175af9e8d38184c6ba4d2d3eb5bde7014a66dd8a78bJeff Brown
17665fd251c3913fc921468a3dad190810db19eb9dfJeff Brownprivate:
177214eaf48878bba00cbd5831871bcbd82632b6e34Jeff Brown    virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) {
178214eaf48878bba00cbd5831871bcbd82632b6e34Jeff Brown        *outConfig = mConfig;
179c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
18083c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown
18183c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown    virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) {
18283c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown        return mPointerControllers.valueFor(deviceId);
18383c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown    }
184af9e8d38184c6ba4d2d3eb5bde7014a66dd8a78bJeff Brown
185af9e8d38184c6ba4d2d3eb5bde7014a66dd8a78bJeff Brown    virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) {
186af9e8d38184c6ba4d2d3eb5bde7014a66dd8a78bJeff Brown        mInputDevices = inputDevices;
187af9e8d38184c6ba4d2d3eb5bde7014a66dd8a78bJeff Brown    }
1886ec6f79e1ac1714e3b837796e99f07ff88f66601Jeff Brown
189426f905b840a710314cc4e91ea4f03bd0c4bcbfbJeff Brown    virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const String8& inputDeviceDescriptor) {
1906ec6f79e1ac1714e3b837796e99f07ff88f66601Jeff Brown        return NULL;
1916ec6f79e1ac1714e3b837796e99f07ff88f66601Jeff Brown    }
1925bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown
1935bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown    virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier) {
1945bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown        return String8::empty();
1955bbd4b4f5fc19302fa017ad6afee6eb2d489d91aJeff Brown    }
196c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown};
197c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
198c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
199be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown// --- FakeInputListener ---
200c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
201be1aa8250cee7819c49741e819e81659d1d03823Jeff Brownclass FakeInputListener : public InputListenerInterface {
202c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownprivate:
203be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    List<NotifyConfigurationChangedArgs> mNotifyConfigurationChangedArgsQueue;
20465fd251c3913fc921468a3dad190810db19eb9dfJeff Brown    List<NotifyDeviceResetArgs> mNotifyDeviceResetArgsQueue;
205be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    List<NotifyKeyArgs> mNotifyKeyArgsQueue;
206be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    List<NotifyMotionArgs> mNotifyMotionArgsQueue;
207be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    List<NotifySwitchArgs> mNotifySwitchArgsQueue;
208c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
209c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownprotected:
210be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    virtual ~FakeInputListener() { }
211c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
212c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownpublic:
213be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    FakeInputListener() {
214c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
215c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
216be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    void assertNotifyConfigurationChangedWasCalled(
217be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown            NotifyConfigurationChangedArgs* outEventArgs = NULL) {
218be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        ASSERT_FALSE(mNotifyConfigurationChangedArgsQueue.empty())
219c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown                << "Expected notifyConfigurationChanged() to have been called.";
220be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        if (outEventArgs) {
221be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown            *outEventArgs = *mNotifyConfigurationChangedArgsQueue.begin();
222c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        }
223be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        mNotifyConfigurationChangedArgsQueue.erase(mNotifyConfigurationChangedArgsQueue.begin());
224c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
225c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
22665fd251c3913fc921468a3dad190810db19eb9dfJeff Brown    void assertNotifyDeviceResetWasCalled(
22765fd251c3913fc921468a3dad190810db19eb9dfJeff Brown            NotifyDeviceResetArgs* outEventArgs = NULL) {
22865fd251c3913fc921468a3dad190810db19eb9dfJeff Brown        ASSERT_FALSE(mNotifyDeviceResetArgsQueue.empty())
22965fd251c3913fc921468a3dad190810db19eb9dfJeff Brown                << "Expected notifyDeviceReset() to have been called.";
23065fd251c3913fc921468a3dad190810db19eb9dfJeff Brown        if (outEventArgs) {
23165fd251c3913fc921468a3dad190810db19eb9dfJeff Brown            *outEventArgs = *mNotifyDeviceResetArgsQueue.begin();
23265fd251c3913fc921468a3dad190810db19eb9dfJeff Brown        }
23365fd251c3913fc921468a3dad190810db19eb9dfJeff Brown        mNotifyDeviceResetArgsQueue.erase(mNotifyDeviceResetArgsQueue.begin());
23465fd251c3913fc921468a3dad190810db19eb9dfJeff Brown    }
23565fd251c3913fc921468a3dad190810db19eb9dfJeff Brown
236be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    void assertNotifyKeyWasCalled(NotifyKeyArgs* outEventArgs = NULL) {
237be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        ASSERT_FALSE(mNotifyKeyArgsQueue.empty())
238c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown                << "Expected notifyKey() to have been called.";
239be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        if (outEventArgs) {
240be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown            *outEventArgs = *mNotifyKeyArgsQueue.begin();
241c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        }
242be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        mNotifyKeyArgsQueue.erase(mNotifyKeyArgsQueue.begin());
243c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
244c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
245c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    void assertNotifyKeyWasNotCalled() {
246be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        ASSERT_TRUE(mNotifyKeyArgsQueue.empty())
247c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown                << "Expected notifyKey() to not have been called.";
248c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
249c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
250be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    void assertNotifyMotionWasCalled(NotifyMotionArgs* outEventArgs = NULL) {
251be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        ASSERT_FALSE(mNotifyMotionArgsQueue.empty())
252c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown                << "Expected notifyMotion() to have been called.";
253be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        if (outEventArgs) {
254be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown            *outEventArgs = *mNotifyMotionArgsQueue.begin();
255c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        }
256be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        mNotifyMotionArgsQueue.erase(mNotifyMotionArgsQueue.begin());
257c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
258c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
259c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    void assertNotifyMotionWasNotCalled() {
260be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        ASSERT_TRUE(mNotifyMotionArgsQueue.empty())
261c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown                << "Expected notifyMotion() to not have been called.";
262c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
263c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
264be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    void assertNotifySwitchWasCalled(NotifySwitchArgs* outEventArgs = NULL) {
265be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        ASSERT_FALSE(mNotifySwitchArgsQueue.empty())
266c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown                << "Expected notifySwitch() to have been called.";
267be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        if (outEventArgs) {
268be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown            *outEventArgs = *mNotifySwitchArgsQueue.begin();
269c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        }
270be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        mNotifySwitchArgsQueue.erase(mNotifySwitchArgsQueue.begin());
271c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
272c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
273c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownprivate:
274be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) {
275be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        mNotifyConfigurationChangedArgsQueue.push_back(*args);
2760029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown    }
2770029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown
27865fd251c3913fc921468a3dad190810db19eb9dfJeff Brown    virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) {
27965fd251c3913fc921468a3dad190810db19eb9dfJeff Brown        mNotifyDeviceResetArgsQueue.push_back(*args);
28065fd251c3913fc921468a3dad190810db19eb9dfJeff Brown    }
28165fd251c3913fc921468a3dad190810db19eb9dfJeff Brown
282be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    virtual void notifyKey(const NotifyKeyArgs* args) {
283be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        mNotifyKeyArgsQueue.push_back(*args);
2847631cbbed41ad3183723e5bc6e082d40549664b9Jeff Brown    }
2857631cbbed41ad3183723e5bc6e082d40549664b9Jeff Brown
286be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    virtual void notifyMotion(const NotifyMotionArgs* args) {
287be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        mNotifyMotionArgsQueue.push_back(*args);
288c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
289c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
290be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    virtual void notifySwitch(const NotifySwitchArgs* args) {
291be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        mNotifySwitchArgsQueue.push_back(*args);
292c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
293c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown};
294c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
295c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
296c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown// --- FakeEventHub ---
297c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
298c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownclass FakeEventHub : public EventHubInterface {
299c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    struct KeyInfo {
300c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        int32_t keyCode;
301c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        uint32_t flags;
302c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    };
303c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
304c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    struct Device {
305e38fdfae9196afd1bdc14c5ec6c12793af1e2550Jeff Brown        InputDeviceIdentifier identifier;
306c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        uint32_t classes;
30747e6b1b5eef8ee99872f278f66bc498c4fcca0d8Jeff Brown        PropertyMap configuration;
308efd3266b719eed5f1b217021c0a9e76e4b274b06Jeff Brown        KeyedVector<int, RawAbsoluteAxisInfo> absoluteAxes;
309efd3266b719eed5f1b217021c0a9e76e4b274b06Jeff Brown        KeyedVector<int, bool> relativeAxes;
310c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        KeyedVector<int32_t, int32_t> keyCodeStates;
311c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        KeyedVector<int32_t, int32_t> scanCodeStates;
312c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        KeyedVector<int32_t, int32_t> switchStates;
3132717eff2ac04bed60e5fd577bcb8ec1ea7c2ccdeJeff Brown        KeyedVector<int32_t, int32_t> absoluteAxisValue;
31449ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown        KeyedVector<int32_t, KeyInfo> keysByScanCode;
31549ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown        KeyedVector<int32_t, KeyInfo> keysByUsageCode;
31651e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown        KeyedVector<int32_t, bool> leds;
3179065504a63d6bf37bf621191fda1d1fe4da76ee3Jeff Brown        Vector<VirtualKeyDefinition> virtualKeys;
318c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
319e38fdfae9196afd1bdc14c5ec6c12793af1e2550Jeff Brown        Device(uint32_t classes) :
320e38fdfae9196afd1bdc14c5ec6c12793af1e2550Jeff Brown                classes(classes) {
321c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        }
322c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    };
323c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
324c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    KeyedVector<int32_t, Device*> mDevices;
325c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    Vector<String8> mExcludedDevices;
326c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    List<RawEvent> mEvents;
327c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
328c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownprotected:
329c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    virtual ~FakeEventHub() {
330c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        for (size_t i = 0; i < mDevices.size(); i++) {
331c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown            delete mDevices.valueAt(i);
332c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        }
333c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
334c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
335c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownpublic:
336c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    FakeEventHub() { }
337c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
338c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    void addDevice(int32_t deviceId, const String8& name, uint32_t classes) {
339e38fdfae9196afd1bdc14c5ec6c12793af1e2550Jeff Brown        Device* device = new Device(classes);
340e38fdfae9196afd1bdc14c5ec6c12793af1e2550Jeff Brown        device->identifier.name = name;
341c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        mDevices.add(deviceId, device);
342c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
34349ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown        enqueueEvent(ARBITRARY_TIME, deviceId, EventHubInterface::DEVICE_ADDED, 0, 0);
344c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
345c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
346c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    void removeDevice(int32_t deviceId) {
347c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        delete mDevices.valueFor(deviceId);
348c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        mDevices.removeItem(deviceId);
349c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
35049ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown        enqueueEvent(ARBITRARY_TIME, deviceId, EventHubInterface::DEVICE_REMOVED, 0, 0);
351c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
352c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
353c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    void finishDeviceScan() {
35449ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown        enqueueEvent(ARBITRARY_TIME, 0, EventHubInterface::FINISHED_DEVICE_SCAN, 0, 0);
355c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
356c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
35747e6b1b5eef8ee99872f278f66bc498c4fcca0d8Jeff Brown    void addConfigurationProperty(int32_t deviceId, const String8& key, const String8& value) {
35847e6b1b5eef8ee99872f278f66bc498c4fcca0d8Jeff Brown        Device* device = getDevice(deviceId);
35947e6b1b5eef8ee99872f278f66bc498c4fcca0d8Jeff Brown        device->configuration.addProperty(key, value);
36047e6b1b5eef8ee99872f278f66bc498c4fcca0d8Jeff Brown    }
36147e6b1b5eef8ee99872f278f66bc498c4fcca0d8Jeff Brown
36283c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown    void addConfigurationMap(int32_t deviceId, const PropertyMap* configuration) {
36383c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown        Device* device = getDevice(deviceId);
36483c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown        device->configuration.addAll(configuration);
36583c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown    }
36683c09685f2e62bc3cf7e71bc61d903f4b9ccaeb4Jeff Brown
367efd3266b719eed5f1b217021c0a9e76e4b274b06Jeff Brown    void addAbsoluteAxis(int32_t deviceId, int axis,
368b3a2d1330716812784aee91b6d6275764b5e4210Jeff Brown            int32_t minValue, int32_t maxValue, int flat, int fuzz, int resolution = 0) {
369c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        Device* device = getDevice(deviceId);
370c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
371c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        RawAbsoluteAxisInfo info;
372c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        info.valid = true;
373c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        info.minValue = minValue;
374c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        info.maxValue = maxValue;
375c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        info.flat = flat;
376c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        info.fuzz = fuzz;
377b3a2d1330716812784aee91b6d6275764b5e4210Jeff Brown        info.resolution = resolution;
378efd3266b719eed5f1b217021c0a9e76e4b274b06Jeff Brown        device->absoluteAxes.add(axis, info);
379efd3266b719eed5f1b217021c0a9e76e4b274b06Jeff Brown    }
380efd3266b719eed5f1b217021c0a9e76e4b274b06Jeff Brown
381efd3266b719eed5f1b217021c0a9e76e4b274b06Jeff Brown    void addRelativeAxis(int32_t deviceId, int32_t axis) {
382efd3266b719eed5f1b217021c0a9e76e4b274b06Jeff Brown        Device* device = getDevice(deviceId);
383efd3266b719eed5f1b217021c0a9e76e4b274b06Jeff Brown        device->relativeAxes.add(axis, true);
384c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
385c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
386c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    void setKeyCodeState(int32_t deviceId, int32_t keyCode, int32_t state) {
387c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        Device* device = getDevice(deviceId);
388c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        device->keyCodeStates.replaceValueFor(keyCode, state);
389c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
390c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
391c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    void setScanCodeState(int32_t deviceId, int32_t scanCode, int32_t state) {
392c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        Device* device = getDevice(deviceId);
393c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        device->scanCodeStates.replaceValueFor(scanCode, state);
394c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
395c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
396c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    void setSwitchState(int32_t deviceId, int32_t switchCode, int32_t state) {
397c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        Device* device = getDevice(deviceId);
398c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        device->switchStates.replaceValueFor(switchCode, state);
399c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
400c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
4012717eff2ac04bed60e5fd577bcb8ec1ea7c2ccdeJeff Brown    void setAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t value) {
4022717eff2ac04bed60e5fd577bcb8ec1ea7c2ccdeJeff Brown        Device* device = getDevice(deviceId);
4032717eff2ac04bed60e5fd577bcb8ec1ea7c2ccdeJeff Brown        device->absoluteAxisValue.replaceValueFor(axis, value);
4042717eff2ac04bed60e5fd577bcb8ec1ea7c2ccdeJeff Brown    }
4052717eff2ac04bed60e5fd577bcb8ec1ea7c2ccdeJeff Brown
40649ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown    void addKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
40749ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown            int32_t keyCode, uint32_t flags) {
408c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        Device* device = getDevice(deviceId);
409c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        KeyInfo info;
410c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        info.keyCode = keyCode;
411c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        info.flags = flags;
41249ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown        if (scanCode) {
41349ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown            device->keysByScanCode.add(scanCode, info);
41449ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown        }
41549ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown        if (usageCode) {
41649ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown            device->keysByUsageCode.add(usageCode, info);
41749ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown        }
418c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
419c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
42051e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown    void addLed(int32_t deviceId, int32_t led, bool initialState) {
42151e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown        Device* device = getDevice(deviceId);
42251e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown        device->leds.add(led, initialState);
42351e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown    }
42451e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown
42551e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown    bool getLedState(int32_t deviceId, int32_t led) {
42651e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown        Device* device = getDevice(deviceId);
42751e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown        return device->leds.valueFor(led);
42851e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown    }
42951e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown
430c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    Vector<String8>& getExcludedDevices() {
431c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        return mExcludedDevices;
432c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
433c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
4349065504a63d6bf37bf621191fda1d1fe4da76ee3Jeff Brown    void addVirtualKeyDefinition(int32_t deviceId, const VirtualKeyDefinition& definition) {
4359065504a63d6bf37bf621191fda1d1fe4da76ee3Jeff Brown        Device* device = getDevice(deviceId);
4369065504a63d6bf37bf621191fda1d1fe4da76ee3Jeff Brown        device->virtualKeys.push(definition);
4379065504a63d6bf37bf621191fda1d1fe4da76ee3Jeff Brown    }
4389065504a63d6bf37bf621191fda1d1fe4da76ee3Jeff Brown
439c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    void enqueueEvent(nsecs_t when, int32_t deviceId, int32_t type,
44049ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown            int32_t code, int32_t value) {
441c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        RawEvent event;
442c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        event.when = when;
443c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        event.deviceId = deviceId;
444c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        event.type = type;
44549ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown        event.code = code;
446c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        event.value = value;
447c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        mEvents.push_back(event);
448be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown
449be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        if (type == EV_ABS) {
45049ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown            setAbsoluteAxisValue(deviceId, code, value);
451be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown        }
452c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
453c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
454c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    void assertQueueIsEmpty() {
455c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        ASSERT_EQ(size_t(0), mEvents.size())
456c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown                << "Expected the event queue to be empty (fully consumed).";
457c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
458c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
459c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownprivate:
460c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    Device* getDevice(int32_t deviceId) const {
461c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        ssize_t index = mDevices.indexOfKey(deviceId);
462c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        return index >= 0 ? mDevices.valueAt(index) : NULL;
463c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
464c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
465c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    virtual uint32_t getDeviceClasses(int32_t deviceId) const {
466c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        Device* device = getDevice(deviceId);
467c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        return device ? device->classes : 0;
468c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
469c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
470e38fdfae9196afd1bdc14c5ec6c12793af1e2550Jeff Brown    virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const {
471c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        Device* device = getDevice(deviceId);
472e38fdfae9196afd1bdc14c5ec6c12793af1e2550Jeff Brown        return device ? device->identifier : InputDeviceIdentifier();
473c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
474c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
47547e6b1b5eef8ee99872f278f66bc498c4fcca0d8Jeff Brown    virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const {
47647e6b1b5eef8ee99872f278f66bc498c4fcca0d8Jeff Brown        Device* device = getDevice(deviceId);
47747e6b1b5eef8ee99872f278f66bc498c4fcca0d8Jeff Brown        if (device) {
47847e6b1b5eef8ee99872f278f66bc498c4fcca0d8Jeff Brown            *outConfiguration = device->configuration;
47947e6b1b5eef8ee99872f278f66bc498c4fcca0d8Jeff Brown        }
48047e6b1b5eef8ee99872f278f66bc498c4fcca0d8Jeff Brown    }
48147e6b1b5eef8ee99872f278f66bc498c4fcca0d8Jeff Brown
482c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
483c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown            RawAbsoluteAxisInfo* outAxisInfo) const {
484c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        Device* device = getDevice(deviceId);
485c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        if (device) {
486efd3266b719eed5f1b217021c0a9e76e4b274b06Jeff Brown            ssize_t index = device->absoluteAxes.indexOfKey(axis);
487c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown            if (index >= 0) {
488efd3266b719eed5f1b217021c0a9e76e4b274b06Jeff Brown                *outAxisInfo = device->absoluteAxes.valueAt(index);
489c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown                return OK;
490c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown            }
491c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        }
49283d616a9c7b9505153d258511eb5c16b552e268dJeff Brown        outAxisInfo->clear();
493c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        return -1;
494c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
495c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
496cc0c159e9b3dd4e0f48da0ce3e33d2c68a651413Jeff Brown    virtual bool hasRelativeAxis(int32_t deviceId, int axis) const {
497efd3266b719eed5f1b217021c0a9e76e4b274b06Jeff Brown        Device* device = getDevice(deviceId);
498efd3266b719eed5f1b217021c0a9e76e4b274b06Jeff Brown        if (device) {
499efd3266b719eed5f1b217021c0a9e76e4b274b06Jeff Brown            return device->relativeAxes.indexOfKey(axis) >= 0;
500efd3266b719eed5f1b217021c0a9e76e4b274b06Jeff Brown        }
501cc0c159e9b3dd4e0f48da0ce3e33d2c68a651413Jeff Brown        return false;
502cc0c159e9b3dd4e0f48da0ce3e33d2c68a651413Jeff Brown    }
503cc0c159e9b3dd4e0f48da0ce3e33d2c68a651413Jeff Brown
50480fd47ce75253dcdc2cfa85d7a3f42634b923a47Jeff Brown    virtual bool hasInputProperty(int32_t deviceId, int property) const {
50580fd47ce75253dcdc2cfa85d7a3f42634b923a47Jeff Brown        return false;
50680fd47ce75253dcdc2cfa85d7a3f42634b923a47Jeff Brown    }
50780fd47ce75253dcdc2cfa85d7a3f42634b923a47Jeff Brown
50849ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown    virtual status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
509c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown            int32_t* outKeycode, uint32_t* outFlags) const {
510c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        Device* device = getDevice(deviceId);
511c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        if (device) {
512cc1169831921d9295b2fc01c1eaf7e9b00836f53Jeff Brown            const KeyInfo* key = getKey(device, scanCode, usageCode);
51349ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown            if (key) {
514c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown                if (outKeycode) {
51549ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown                    *outKeycode = key->keyCode;
516c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown                }
517c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown                if (outFlags) {
51849ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown                    *outFlags = key->flags;
519c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown                }
520c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown                return OK;
521c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown            }
522c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        }
523c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        return NAME_NOT_FOUND;
524c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
525c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
526cc1169831921d9295b2fc01c1eaf7e9b00836f53Jeff Brown    const KeyInfo* getKey(Device* device, int32_t scanCode, int32_t usageCode) const {
527cc1169831921d9295b2fc01c1eaf7e9b00836f53Jeff Brown        if (usageCode) {
528cc1169831921d9295b2fc01c1eaf7e9b00836f53Jeff Brown            ssize_t index = device->keysByUsageCode.indexOfKey(usageCode);
529cc1169831921d9295b2fc01c1eaf7e9b00836f53Jeff Brown            if (index >= 0) {
530cc1169831921d9295b2fc01c1eaf7e9b00836f53Jeff Brown                return &device->keysByUsageCode.valueAt(index);
531cc1169831921d9295b2fc01c1eaf7e9b00836f53Jeff Brown            }
532cc1169831921d9295b2fc01c1eaf7e9b00836f53Jeff Brown        }
533cc1169831921d9295b2fc01c1eaf7e9b00836f53Jeff Brown        if (scanCode) {
534cc1169831921d9295b2fc01c1eaf7e9b00836f53Jeff Brown            ssize_t index = device->keysByScanCode.indexOfKey(scanCode);
535cc1169831921d9295b2fc01c1eaf7e9b00836f53Jeff Brown            if (index >= 0) {
536cc1169831921d9295b2fc01c1eaf7e9b00836f53Jeff Brown                return &device->keysByScanCode.valueAt(index);
537cc1169831921d9295b2fc01c1eaf7e9b00836f53Jeff Brown            }
538cc1169831921d9295b2fc01c1eaf7e9b00836f53Jeff Brown        }
539cc1169831921d9295b2fc01c1eaf7e9b00836f53Jeff Brown        return NULL;
540cc1169831921d9295b2fc01c1eaf7e9b00836f53Jeff Brown    }
541cc1169831921d9295b2fc01c1eaf7e9b00836f53Jeff Brown
54249ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown    virtual status_t mapAxis(int32_t deviceId, int32_t scanCode,
5438529745b27877d98a0c76692295a3fcac238b1e6Jeff Brown            AxisInfo* outAxisInfo) const {
5446f2fba428ca5e77a26d991ad728e346cc47609eeJeff Brown        return NAME_NOT_FOUND;
5456f2fba428ca5e77a26d991ad728e346cc47609eeJeff Brown    }
5466f2fba428ca5e77a26d991ad728e346cc47609eeJeff Brown
5471a84fd1fb7a51f3fe4f8865e1cdd09f3490f696cJeff Brown    virtual void setExcludedDevices(const Vector<String8>& devices) {
5481a84fd1fb7a51f3fe4f8865e1cdd09f3490f696cJeff Brown        mExcludedDevices = devices;
549c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
550c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
551b7198743ab3976b30d4655c1e065ca33e372b6afJeff Brown    virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) {
552c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        if (mEvents.empty()) {
553b7198743ab3976b30d4655c1e065ca33e372b6afJeff Brown            return 0;
554c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        }
555c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
556b7198743ab3976b30d4655c1e065ca33e372b6afJeff Brown        *buffer = *mEvents.begin();
557c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        mEvents.erase(mEvents.begin());
558b7198743ab3976b30d4655c1e065ca33e372b6afJeff Brown        return 1;
559c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
560c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
561c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const {
562c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        Device* device = getDevice(deviceId);
563c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        if (device) {
564c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown            ssize_t index = device->scanCodeStates.indexOfKey(scanCode);
565c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown            if (index >= 0) {
566c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown                return device->scanCodeStates.valueAt(index);
567c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown            }
568c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        }
569c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        return AKEY_STATE_UNKNOWN;
570c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
571c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
572c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const {
573c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        Device* device = getDevice(deviceId);
574c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        if (device) {
575c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown            ssize_t index = device->keyCodeStates.indexOfKey(keyCode);
576c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown            if (index >= 0) {
577c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown                return device->keyCodeStates.valueAt(index);
578c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown            }
579c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        }
580c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        return AKEY_STATE_UNKNOWN;
581c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
582c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
583c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const {
584c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        Device* device = getDevice(deviceId);
585c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        if (device) {
586c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown            ssize_t index = device->switchStates.indexOfKey(sw);
587c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown            if (index >= 0) {
588c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown                return device->switchStates.valueAt(index);
589c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown            }
590c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        }
591c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        return AKEY_STATE_UNKNOWN;
592c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
593c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
5942717eff2ac04bed60e5fd577bcb8ec1ea7c2ccdeJeff Brown    virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis,
5952717eff2ac04bed60e5fd577bcb8ec1ea7c2ccdeJeff Brown            int32_t* outValue) const {
5962717eff2ac04bed60e5fd577bcb8ec1ea7c2ccdeJeff Brown        Device* device = getDevice(deviceId);
5972717eff2ac04bed60e5fd577bcb8ec1ea7c2ccdeJeff Brown        if (device) {
5982717eff2ac04bed60e5fd577bcb8ec1ea7c2ccdeJeff Brown            ssize_t index = device->absoluteAxisValue.indexOfKey(axis);
5992717eff2ac04bed60e5fd577bcb8ec1ea7c2ccdeJeff Brown            if (index >= 0) {
6002717eff2ac04bed60e5fd577bcb8ec1ea7c2ccdeJeff Brown                *outValue = device->absoluteAxisValue.valueAt(index);
6012717eff2ac04bed60e5fd577bcb8ec1ea7c2ccdeJeff Brown                return OK;
6022717eff2ac04bed60e5fd577bcb8ec1ea7c2ccdeJeff Brown            }
6032717eff2ac04bed60e5fd577bcb8ec1ea7c2ccdeJeff Brown        }
6042717eff2ac04bed60e5fd577bcb8ec1ea7c2ccdeJeff Brown        *outValue = 0;
6052717eff2ac04bed60e5fd577bcb8ec1ea7c2ccdeJeff Brown        return -1;
6062717eff2ac04bed60e5fd577bcb8ec1ea7c2ccdeJeff Brown    }
6072717eff2ac04bed60e5fd577bcb8ec1ea7c2ccdeJeff Brown
608c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes,
609c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown            uint8_t* outFlags) const {
610c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        bool result = false;
611c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        Device* device = getDevice(deviceId);
612c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        if (device) {
613c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown            for (size_t i = 0; i < numCodes; i++) {
61449ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown                for (size_t j = 0; j < device->keysByScanCode.size(); j++) {
61549ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown                    if (keyCodes[i] == device->keysByScanCode.valueAt(j).keyCode) {
61649ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown                        outFlags[i] = 1;
61749ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown                        result = true;
61849ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown                    }
61949ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown                }
62049ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown                for (size_t j = 0; j < device->keysByUsageCode.size(); j++) {
62149ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown                    if (keyCodes[i] == device->keysByUsageCode.valueAt(j).keyCode) {
622c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown                        outFlags[i] = 1;
623c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown                        result = true;
624c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown                    }
625c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown                }
626c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown            }
627c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        }
628c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        return result;
629c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
630c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
63149754db5a304d995c1cc108ff6f19e4ba4265572Jeff Brown    virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const {
63249754db5a304d995c1cc108ff6f19e4ba4265572Jeff Brown        Device* device = getDevice(deviceId);
63349754db5a304d995c1cc108ff6f19e4ba4265572Jeff Brown        if (device) {
63449ccac530b5a798e3c4a79b66b51b8546a0deed1Jeff Brown            ssize_t index = device->keysByScanCode.indexOfKey(scanCode);
63549754db5a304d995c1cc108ff6f19e4ba4265572Jeff Brown            return index >= 0;
63649754db5a304d995c1cc108ff6f19e4ba4265572Jeff Brown        }
63749754db5a304d995c1cc108ff6f19e4ba4265572Jeff Brown        return false;
63849754db5a304d995c1cc108ff6f19e4ba4265572Jeff Brown    }
63949754db5a304d995c1cc108ff6f19e4ba4265572Jeff Brown
6407631cbbed41ad3183723e5bc6e082d40549664b9Jeff Brown    virtual bool hasLed(int32_t deviceId, int32_t led) const {
64151e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown        Device* device = getDevice(deviceId);
64251e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown        return device && device->leds.indexOfKey(led) >= 0;
6437631cbbed41ad3183723e5bc6e082d40549664b9Jeff Brown    }
6447631cbbed41ad3183723e5bc6e082d40549664b9Jeff Brown
6457631cbbed41ad3183723e5bc6e082d40549664b9Jeff Brown    virtual void setLedState(int32_t deviceId, int32_t led, bool on) {
64651e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown        Device* device = getDevice(deviceId);
64751e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown        if (device) {
64851e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown            ssize_t index = device->leds.indexOfKey(led);
64951e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown            if (index >= 0) {
65051e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown                device->leds.replaceValueAt(led, on);
65151e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown            } else {
65251e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown                ADD_FAILURE()
65351e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown                        << "Attempted to set the state of an LED that the EventHub declared "
65451e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown                        "was not present.  led=" << led;
65551e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown            }
65651e7fe7545e3509ebb5c31c10440acd31cec89a2Jeff Brown        }
6577631cbbed41ad3183723e5bc6e082d40549664b9Jeff Brown    }
6587631cbbed41ad3183723e5bc6e082d40549664b9Jeff Brown
6599065504a63d6bf37bf621191fda1d1fe4da76ee3Jeff Brown    virtual void getVirtualKeyDefinitions(int32_t deviceId,
6609065504a63d6bf37bf621191fda1d1fe4da76ee3Jeff Brown            Vector<VirtualKeyDefinition>& outVirtualKeys) const {
6619065504a63d6bf37bf621191fda1d1fe4da76ee3Jeff Brown        outVirtualKeys.clear();
6629065504a63d6bf37bf621191fda1d1fe4da76ee3Jeff Brown
6639065504a63d6bf37bf621191fda1d1fe4da76ee3Jeff Brown        Device* device = getDevice(deviceId);
6649065504a63d6bf37bf621191fda1d1fe4da76ee3Jeff Brown        if (device) {
6659065504a63d6bf37bf621191fda1d1fe4da76ee3Jeff Brown            outVirtualKeys.appendVector(device->virtualKeys);
6669065504a63d6bf37bf621191fda1d1fe4da76ee3Jeff Brown        }
6679065504a63d6bf37bf621191fda1d1fe4da76ee3Jeff Brown    }
6689065504a63d6bf37bf621191fda1d1fe4da76ee3Jeff Brown
6699f25b7fdf216c9ef0bd2322cd223eeaf0d60f77fJeff Brown    virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const {
6709f25b7fdf216c9ef0bd2322cd223eeaf0d60f77fJeff Brown        return NULL;
6711e08fe90df18930691b0c2ec22e5db25d7fcb4cfJeff Brown    }
6721e08fe90df18930691b0c2ec22e5db25d7fcb4cfJeff Brown
6736ec6f79e1ac1714e3b837796e99f07ff88f66601Jeff Brown    virtual bool setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map) {
6746ec6f79e1ac1714e3b837796e99f07ff88f66601Jeff Brown        return false;
6756ec6f79e1ac1714e3b837796e99f07ff88f66601Jeff Brown    }
6766ec6f79e1ac1714e3b837796e99f07ff88f66601Jeff Brown
677a47425a13c19f95057df78b8bb65bb25657e8753Jeff Brown    virtual void vibrate(int32_t deviceId, nsecs_t duration) {
678a47425a13c19f95057df78b8bb65bb25657e8753Jeff Brown    }
679a47425a13c19f95057df78b8bb65bb25657e8753Jeff Brown
680a47425a13c19f95057df78b8bb65bb25657e8753Jeff Brown    virtual void cancelVibrate(int32_t deviceId) {
681a47425a13c19f95057df78b8bb65bb25657e8753Jeff Brown    }
682a47425a13c19f95057df78b8bb65bb25657e8753Jeff Brown
68356194ebec6212e229f4ccdaa4b187166d20013efJeff Brown    virtual bool isExternal(int32_t deviceId) const {
68456194ebec6212e229f4ccdaa4b187166d20013efJeff Brown        return false;
68556194ebec6212e229f4ccdaa4b187166d20013efJeff Brown    }
68656194ebec6212e229f4ccdaa4b187166d20013efJeff Brown
687c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    virtual void dump(String8& dump) {
688c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
6891a84fd1fb7a51f3fe4f8865e1cdd09f3490f696cJeff Brown
69089ef0720ee8e0ac6ae1758faa917e4d6c9606fb4Jeff Brown    virtual void monitor() {
69189ef0720ee8e0ac6ae1758faa917e4d6c9606fb4Jeff Brown    }
69289ef0720ee8e0ac6ae1758faa917e4d6c9606fb4Jeff Brown
69393fa9b30b91f75ee161d0791ff17f98d1a603812Jeff Brown    virtual void requestReopenDevices() {
69493fa9b30b91f75ee161d0791ff17f98d1a603812Jeff Brown    }
69593fa9b30b91f75ee161d0791ff17f98d1a603812Jeff Brown
69693fa9b30b91f75ee161d0791ff17f98d1a603812Jeff Brown    virtual void wake() {
6971a84fd1fb7a51f3fe4f8865e1cdd09f3490f696cJeff Brown    }
698c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown};
699c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
700c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
701c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown// --- FakeInputReaderContext ---
702c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
703c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownclass FakeInputReaderContext : public InputReaderContext {
704c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    sp<EventHubInterface> mEventHub;
705c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    sp<InputReaderPolicyInterface> mPolicy;
706be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown    sp<InputListenerInterface> mListener;
707c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    int32_t mGlobalMetaState;
708c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    bool mUpdateGlobalMetaStateWasCalled;
709af9e8d38184c6ba4d2d3eb5bde7014a66dd8a78bJeff Brown    int32_t mGeneration;
710c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
711c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownpublic:
712c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    FakeInputReaderContext(const sp<EventHubInterface>& eventHub,
713c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown            const sp<InputReaderPolicyInterface>& policy,
714be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown            const sp<InputListenerInterface>& listener) :
715be1aa8250cee7819c49741e819e81659d1d03823Jeff Brown            mEventHub(eventHub), mPolicy(policy), mListener(listener),
716c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown            mGlobalMetaState(0) {
717c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
718c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
719c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    virtual ~FakeInputReaderContext() { }
720c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
721c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    void assertUpdateGlobalMetaStateWasCalled() {
722c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        ASSERT_TRUE(mUpdateGlobalMetaStateWasCalled)
723c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown                << "Expected updateGlobalMetaState() to have been called.";
724c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        mUpdateGlobalMetaStateWasCalled = false;
725c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
726c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
727c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    void setGlobalMetaState(int32_t state) {
728c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        mGlobalMetaState = state;
729c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
730c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
731c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brownprivate:
732c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    virtual void updateGlobalMetaState() {
733c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown        mUpdateGlobalMetaStateWasCalled = true;
734c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    }
735c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown
736c3db858de9fa152480b9cf53c8c0cb793a280722Jeff Brown    virtual int32_t getGlobalMetaState() {
737c3db858de9fa152480b9cf53c8c0cb793a280722</